How do I code access to the built-in UI of a CPT when it’s placed as submenu of another CPT that is protected by role?

From the codex The function which is hooked in to handle the output of the page must check that the user has the required ‘capability’ as well. What it fails to mention is that the check for subpages iterates upwards to its parent. If a user is not capable of accessing TEACHERS, it will not … Read more

How can I get the last posts by user role?

I would try the following (not tested) <?php $friends = get_users( array( ‘role’ => ‘friends’ ) ); $friend_ids = array(); foreach( $friends as $friend ) $friend_ids[] = $friend->ID; $news = new WP_Query( array( ‘author’ => implode( ‘,’, $friend_ids ), ‘post_type’ => ‘news’, ‘paged’ => get_query_var(‘paged’) ) ); ?> Note: ‘friends’ is the role ID, not … Read more

How to reload the role specific registration form on validation errors?

You can either user session or cookies to setup the user for the desired role e.g: /** * register_roles_with_cookies */ class register_roles_with_cookies { function __construct($args = array()){ //create a hidden field for role and extra fields needed add_action(‘register_form’,array($this,’add_hidden_role_field’)); //validate add_action(‘register_post’,array($this,’my_user_fields_validation’),10,3); //save the role add_action(‘user_register’, array($this,’update_role’)); } public function setCookie($name,$val,$time = false){ if(false === $time) $time … Read more

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 can I let users to access plugin functions based on roles?

You can check if current user is an Author (WP-Codex) $current_user_is_allowed_to_edit = false; if ( current_user_can(‘delete_posts’) ) { $current_user_is_allowed_to_edit = true; } And use it in the if-statement at the point where you implement the Live Edit function. Here is the whole code (for user roles): http://pastebin.com/fY7UPcB1 EDIT: Here is the new code (check for … Read more

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

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