Getting a user role from the user login name

You’ll want to use get_user_by(), which will return a WP_USER object which contains roles and capabilities. More info here. $user = get_user_by( ‘login’, ‘username’); $roles = $user->roles // this will contain an array of the roles the user is in

How to make an author archive only for certain user role and show related CPT

You can display user posts using user’s ID. This code might provide a quick sample on how to do it (I have not tested the code). $user_id = $_GET[‘author_id’]; //The Query query_posts(“author={$user_id}”); //The Loop if ( have_posts() ) : while ( have_posts() ) : the_post(); the_title(); echo “<br>”; endwhile; else: echo “No Posts!”; endif; //Reset … Read more

Contributors missing from author dropdown

My advice is to read the Codex regarding user roles and capabilities. Contributors cannot publish posts. Edit: I am able to successfully add new users with the ‘contributor’ role, and select them from the dropdown as the author of a post, which is what I now realize you’re having issues with. So something is definitely … Read more

Shold I manually add ‘cap’ to admin role ?

A new capability has to be explicitly added to either a role or a user. In your case if you want all administrators to have ‘cap’ capability you will add it to ‘administrator’ role: $role = get_role( ‘administrator’ ); $role->add_cap( ‘cap’ ); If you want a specific administrator only to have ‘cap’ capability then you … Read more

Email notification for editors only

Use get_users() function. Reference function notify_editors( $post_id ) { $post = get_post( $post_id ); // Get all editors $editors = get_users( [ ‘role__in’ => [ ‘editor’] ] ); foreach ( $editors as $editor ) { // Setup email $subject = “Post Published: ” . $post->post_title; $message=” Hi ” . $editor->display_name . ‘, Your post, “‘ … Read more

List total number of users that are authors

count_users() should give you an array of all the required user counts. You can use it like this. $user_counts = count_users(); $authors = $user_counts[‘avail_roles’][‘author’]; //Get the author count $subscribers = $user_counts[‘avail_roles’][‘subscriber’]; //Get the subscriber count echo $authors. ‘ Authors so far’; echo $subscribers. ‘ Subscribers so far’;

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