Add role that restricts user to post in specific category

You can use the get_terms hook to find all categories and restrict access to them by ID or slug, if the current user is not an admin, or in this specific case if the user doesn’t have the role assigned by you. add_filter(‘get_terms’, ‘restrict_categories’); function restrict_categories($categories) { $onPostPage = (strpos($_SERVER[‘PHP_SELF’], ‘post.php’) || strpos($_SERVER[‘PHP_SELF’], ‘post-new.php’)); // … Read more

Do not allow users to create new posts and pages

Use remove_cap for this. function remove_proofreader_create_posts(){ global $wp_roles; $wp_roles->remove_cap( ‘proof_reader’, ‘create_posts’ ); $wp_roles->remove_cap( ‘proof_reader’, ‘create_pages’ ); } NOTE: This is not a global function, but a method of the WP_Roles, WP_Role and WP_User classes. It must be called using an instance of one of these classes, as shown in the examples. ALSO: You’ll want to … Read more

How do I allow a specific Role in WordPress 3+ to only see certain plugins?

Add your plugin with a capability argument. So, if your plugin entry point is an admin page menu, you can use something like this: add_menu_page(page_title, menu_title, capability, handle, [function], [icon_url]) You can set the “capability” to “upload_files”. that function sees that capability argument as “The minimum capability required to display and use this menu page”. … Read more

Allow authors to edit only certain users

I did not test the following code, but it should do what you want (or point you in the right direction, at least). function captains_user_row_actions($actions, $user) { // remove the ability to edit a non-team-member $cap_team_id = get_user_meta(wp_get_current_user()->ID, ‘team-meta’, true); $user_team_id = get_user_meta($user->ID, ‘team-meta’, true); if (‘users.php’ === $GLOBALS[‘pagenow’] && $cap_team_id !== $user_team_id) unset($actions[‘edit’]); return … Read more

WordPress Capabilities: edit_user vs edit_users

I found a few references to edit_user as a capability, one of which is this: // Allow user to edit itself if ( ‘edit_user’ == $cap && isset( $args[0] ) && $user_id == $args[0] ) break; http://core.trac.wordpress.org/browser/tags/3.5.2/wp-includes/capabilities.php#L1005 I believe the comment in that block of code answers this question. Per @PatJ, it looks like map_meta_cap … Read more

Add role across network in multisite

This is my experience. I had to add role for each site in WordPress, I developed an add page in dashboard so the site administrator can add the self-defined role/capabilities. But I found the $wp_roles->add_role, add_cap only works the subsite. So I did some fix, I’ve made a plugin, the super-admin(not site administrator but the … Read more

Hide specific admin users’ posts

Try this – rather than redo all the hard work that WordPress does for the view links, just calculate all the posts for the admin you want to “hide” and subtract from the existing post counts: function wpse_229427_get_hidden_admin_id() { return 3; // You could make this a setting or return a value conditionally } function … Read more

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