Shortcode for Listing Users from Meta Value?

It’s a small coding mistake.. It’s not displaying anything because when there are results, the end output is always a </ul> because you’re always overwriting the $results and not appending output to the variable: $results=”<ul>”; foreach ($users as $user){ $results=”<li>” . $user->display_name . ‘</li>’; } $results=”</ul>”; So the proper code is: $results=”<ul>”; foreach ($users as … Read more

load CSS only for administrators on backend

This is what I use, tested and works… function wpse_admin_styles(){ $user = wp_get_current_user(); if( !empty($user) && count(array_intersect([“administrator”], (array) $user->roles ))) { wp_enqueue_style( ‘admin_css’, get_stylesheet_directory_uri() . ‘/css/admin-styles.css’, array(), filemtime( get_stylesheet_directory() . ‘/css/admin-styles.css’) ); } } add_action(‘admin_enqueue_scripts’, ‘wpse_admin_styles’);

User roles not displaying

You can’t see any roles printed, because the ->roles field is an Array, so you can’t print it using echo. User print_r instead. You also have an error in this line: $user = get_userdata(userID); There is no such thing like userID – it should be $userID.

Fix ‘Add Role’ Option not there in wordpress 5.2.2

“Add Role” isn’t an option in WordPress, and never has been. If you want to add a role you’ll need a plugin like User Role Editor or Members. If you want to add a role with code, you can do this with the add_role() function: add_role( ‘member’, ‘Member’, [ ‘edit_posts’ => true, ] ); Just … Read more

Hide Users by user role in Worpress

you could use wp_list_authors for list your authors in your user page. Put a look here: https://codex.wordpress.org/Function_Reference/wp_list_authors Does it help you? EDIT: According to our communications: $users_array = array(); $users = get_users(‘role=author’); if(count($users) > 0){ foreach($users as $user){ $users_array[] = $user->ID; } } add $users_array instead of array(1, 3, 5) …

What’s the correct way to add capabilites to user roles?

The best place to add this would be in the plugin’s activation hook. You can either call the dynamic activate_{$plugin} hook, or better yet use the provided register_activation_hook method. Using your code example above – something like this would be what you’re looking for: register_activation_hook( __FILE__, function() { $role = get_role( ‘editor’ ); $role->add_cap( ‘edit_booked_appointments’, … Read more

WooCommerce which roles and capabilities control user login re-direct to Woo Account Page?

WooCommerce will only show the admin bar and give dashboard access to users who have the edit_posts or manage_woocommerce capabilities. If you don’t want to give users one of those capabilities, you can use the woocommerce_disable_admin_bar filter to give access and show the admin bar: add_filter( ‘woocommerce_disable_admin_bar’, function( $disable_admin_bar ) { if ( current_user_can( ‘my_capability’ … Read more

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