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

Hide Specific User Page

I’m assuming you want to hide the author page on the site itself (and not in wp-admin). To do that, just create a new template file called author-{$id}.php, where {$id} is replaced by the ID of the author you want to hide. So if the author ID is 6, the template file should be called … Read more

Prevent custom user role to add new pages

Post types in WordPress have a list of capabilities that govern permissions surrounding them. These are: edit_post read_post delete_post edit_posts edit_others_posts publish_posts read_private_posts read delete_posts delete_private_posts delete_published_posts delete_others_posts edit_private_posts edit_published_posts create_posts Internally each post type matches these to the actual capabilities that can be given in WordPress. Most of the time these have the exact … Read more

Users Role and Access

What you need first is to understand User Roles in WordPress. Then a plugin to manage custom user roles, like User Role Editor or Members. In the administrative menu Settings > General, set the default role when a user registers to your custom role: The plugin Members has more advanced features, but case you were … Read more

How to Orderby User Role?

This one’s a little difficult, as there’s no default user role meta key or post data. The only thing we got is the user ID. // Get the posts $posts_by_author_ID = get_posts( array( ‘post_type’ => ‘post’ ,’post_status’ => ‘publish’ ,’orderby’ => ‘post_author’ ,’order’ => ‘DESC’ ) ); foreach ( $posts_by_author_ID as $post ) { static … Read more

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