Array to string conversion error in PHP 7.2 when returning user role as class

This code works and is perfectly valid, running on 7.3, except when your user has two roles: add_filter( ‘body_class’, function( $classes=”” ) { $current_user = new \WP_User(get_current_user_id()); $user_role = [‘administrator’, ‘moderator’]; //just a test, but this is what it’ll look like if it had 2 roles. $classes = []; $classes[] = ‘role-‘ . $user_role; return … Read more

Block user roles from accessing the WordPress dashboard

You can make an array of the roles that need to be blocked, and use array_intersect() to check if the current user is in any of those roles. function wpse66094_no_admin_access() { $redirect = isset( $_SERVER[‘HTTP_REFERER’] ) ? $_SERVER[‘HTTP_REFERER’] : home_url( “https://wordpress.stackexchange.com/” ); global $current_user; $blocked_roles = array( ‘shopkeeper’, ‘block-this-role’, ‘block-this-role-too’ ); $user_roles = $current_user->roles; // … Read more

Allow admins to login as other users

You’ll need to find out what specific capabilities Admin users are missing. Once you know the full list, you can use add_cap() to add those capabilities to the Admin users and enable them to do whatever the other roles are doing. From Shold I manually add ‘cap’ to admin role ? – $role = get_role( … Read more

Adding additional roles on registration

You check the role not for the created user, only the currently logged in user. Try this way: add_action( ‘user_register’, ‘se333727_additional_roles’ ); function se333727_additional_roles( $user_id ) { $new_user = get_user_by( ‘ID’, $user_id ); if ( in_array( ‘um_dueling-pianist’, (array)$new_user->roles ) ) { $new_user->add_role(‘pianist’); } }

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