I am adding a new class to my body tag if the logged in user is subscriber, need help

Please try this code instead- add_filter( ‘body_class’, ‘wpse_268176_body_class’ ); function wpse_268176_body_class( $classes ) { $user = wp_get_current_user(); if ( in_array( ‘subscriber’, $user->roles ) ) { $classes[] = ‘class-name’; // your custom class name } return $classes; } Place this in your active theme’s functions.php file. [Thanks Dave Romsey for your suggestion.]

similar to Editor can create any new user except administrator

Simple all you need to do is edit this part of the code : function editable_roles( $roles ){ if( isset( $roles[‘administrator’] ) && !current_user_can(‘administrator’) ){ unset( $roles[‘administrator’]); } return $roles; } and change it to function editable_roles( $roles ){ //don’t change anything if current user is admin if (current_user_can(‘administrator’)) { return; }else{ if( isset( $roles[‘administrator’] … Read more

Add Role inherits?

You must set to true for them to take affect. If you do not specify true they all default to NULL which in turn basically makes them false. So to create a roll that allows pages only: add_role(‘page_editor’, ‘Page Editor’, array( ‘read’ => true, ‘edit_others_pages’ => true, ‘edit_pages’ => true, ‘edit_published_pages’ => true, ‘delete_pages’ => … Read more

Can’t manage to make translate_user_role() work

I think your function nesting is slightly muddled; call ucfirst after translating, like so: esc_html( ucfirst( translate_user_role( $user->roles[0] ) ) ); My bad, completely skipped a beat there. You should instead be using: translate_user_role( $GLOBALS[‘wp_roles’]->role_names[ $user->roles[0] ] ); It’s unreliable to assume that all role display names are simply ucfirst( $role key ). If that … Read more

Get (echo) all role names assigned to user

I assume you need a foreach loop and echo each roles name separately. Here’s how to do it: global $wp_roles; $user_role = get_userdata($user->ID)->roles; // Check if there is any role for this user if( $user_role ) { foreach ( $user_role as $key => $role ) { echo $wp_roles->role_names[ $role ]; // Add a seperator except … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)