How can I allow user to select minimum privilege smartly

You are using the right WP function but unfortunately not passing the right parameter to make this work for you. current_user_can() accepts capabilities as well as roles as parameters. In the above you are using roles and not capabilities. You can use capabilities to make it work. For example, if you want the minimum privilege … Read more

How can I have different groups of editors only allowed to edit certain parent+subpages?

UPDATE – this is easy to do with the press permit plugin, I recommend it for any setup like this To get this working I had to do a couple of things: Default all pages/posts/categories ‘revisor’ (via Revisionary plugin) users to be restricted to ‘WP_Administrators’ Create a “User Group” for each department ie: ‘Conference Services … Read more

How to stop contributors editing post type but allowing them to edit a custom post type?

Add the capabilities to the role. Replace ‘cpt’ with the name of your custom post type: $role = get_role( ‘contributor’ ); $role->add_cap( ‘delete_published_cpt’ ); $role->add_cap( ‘delete_others_cpt’ ); $role->add_cap( ‘delete_cpt’ ); $role->add_cap( ‘edit_others_cpt’ ); $role->add_cap( ‘edit_published_cpt’ ); $role->add_cap( ‘edit_cpt’ ); $role->add_cap( ‘publish_cpt’ ); But you shouldn’t add or remove caps on every page load. That’s why … Read more

Let new user role to ‘edit_others_posts’ of other user role, not of its own type

First add capabilities to the roles like this add_action( ‘after_setup_theme’, ‘add_caps_to_custom_roles’ ); function add_caps_to_custom_roles() { $caps = array( ‘read_cpt’, ‘edit_cpt’, ‘edit_others_cpt’, ); $roles = array( get_role( ‘third_party’ ), get_role( ‘data_entry_operator’ ), ); foreach ($roles as $role) { foreach ($caps as $cap) { $role->add_cap( $cap ); } } } THEN /** * Helper function getting roles … Read more

Making shortcode of filtered number of comments by user role

The code below adds the counts for user roles. It’s commented pretty well to explain what’s happening. It should give you a good starting point for further customization (maybe you want to hide 0 counts, change the HTML output, etc.). function comments_shortcode($atts) { $current_user = wp_get_current_user(); extract( shortcode_atts( array( ‘id’ => ” ), $atts ) … Read more