Ordering users of a specific role by last name

There is apparently an open ticket about this bug. Here is a workaround that I tested: $args = array( ‘meta_key’ => ‘last_name’, ‘role’ => ‘guest-teacher’ ); $wp_user_query = new WP_User_Query($args); $wp_user_query->query_orderby = str_replace( ‘user_login’, ‘wp_usermeta.meta_value’, $wp_user_query->query_orderby ); $wp_user_query->query(); $authors = $wp_user_query->get_results(); Problem with this is that it runs the query twice.

Do custom user roles have any default capabilities?

I’ve found that the WordPress has_cap() function, which is relied on by functions like user_can() and current_user_can, explicitly returns false for empty capabilities. Example: If a capability is passed as an argument using current_user_can(), this function will pass the capability to has_cap() and return the results: return call_user_func_array( array( $current_user, ‘has_cap’ ), $args has_cap() will … Read more

How to let the Contributor role preview unpublished posts?

Unfortunately, WordPress doesn’t use a separate capability for previewing posts. A user needs the ability to edit a post in order to preview it. As seen in the WP_Query::get_posts() method: // User must have edit permissions on the draft to preview. if ( ! current_user_can($edit_cap, $this->posts[0]->ID) ) { $this->posts = array(); } What you could … Read more

How can I change a user role upon visiting a page?

EDIT I updated the function to check for role for which we want to make changes for, if the current user role is not within our roles_to_change array then the function exits. Note that I haven’t tested for bugs, so if you find any, just report them here. @Malisa’s answer is a good approach. However, … Read more

How to filter the role selector?

The UI select element On user-edit.php, you see the drop-down in the UI. The drop down <select> wrapper is hard coded. Then the admin interface does a nifty thing 1) according to the inline comment: // Get the highest/primary role for this user. In fact it is getting the first role, that was assigned to … Read more

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