Hide posts from users with a specific role
Use WP_User_Query to build a list of suspended authors` ids, then use that list with minuses for inversion as author parameter in query.
Use WP_User_Query to build a list of suspended authors` ids, then use that list with minuses for inversion as author parameter in query.
Ok, in case anyone else experiences a similar issue in defining a custom user role, it seems I’ve managed to sort the issue by following these instructions in the WordPress Codex: If you are defining a custom role, and adding capabilities to the role using add_role(), be aware that modifying the capabilities array and re-executing … Read more
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
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
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
Custom Post Types will be much easier to set up, and you won’t have to code your own solution to check in the Editor whether the current user has permission to create a new page or edit something. You can set up the CPT archives at whatever URL you like. So, in your example, you … Read more
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
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
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
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