You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I was wondering how can I load admin CSS on specific user roles only.
For example, I have a custom user role called LatePoint Agent and I only want to load the CSS to users associated with that role.
The text was updated successfully, but these errors were encountered:
Hi @rijotech. There isn't direct support for limiting the custom CSS to certain users, but it's definitely something I'll consider adding in a future release. I'll leave this issue open as a reminder; I'll follow-up once it gets implemented or if I decide to pass on the idea.
In the meantime, you could achieve this in a fashion. The c2c_add_admin_css filter can be used to customize the CSS that gets output by the plugin in the admin. You could hook that and return an empty string if the current user has (or doesn't have) a given role.
For example:
// Don't output CSS from Add Admin CSS unless the current user// has a particular role.add_filter( 'c2c_add_admin_css', function( $css ) {
if ( ! current_user_can( 'latepoint_agent' ) ) {
$css = '';
}
return$css;
} );
If you're linking out to standalone CSS files, you'll have to do the same via the c2c_add_admin_css_files filter. (Otherwise this isn't necessary.)
// Don't link to CSS files from Add Admin CSS unless the current user// has a particular role.add_filter( '`c2c_add_admin_css_files`', function( $files ) {
if ( ! current_user_can( 'latepoint_agent' ) ) {
$files = [];
}
return$files;
} );
Obviously, customize the criteria to your particular situation.
Hi, I was wondering how can I load admin CSS on specific user roles only.
For example, I have a custom user role called LatePoint Agent and I only want to load the CSS to users associated with that role.
The text was updated successfully, but these errors were encountered: