Articles of add cap

Why cannot author edit pages?

I have this in my functions.php (child theme) //Add capabilities to author, so he/she can edit… function add_theme_caps() { // gets the author role $role = get_role( ‘author’ ); $role->add_cap( ‘edit_pages’ ); $role->add_cap( ‘edit_published_pages’ ); $role->add_cap( ‘edit_posts’ ); $role->add_cap( ‘edit_others_posts’ ); $role->add_cap( ‘publish_posts’ ); $role->add_cap( ‘publish_pages’ ); $role->add_cap( ‘edit_published_posts’ ); $role->add_cap( ‘edit_published_pages’ ); } add_action( […]

remove other tabs in new wordpress media gallery

I recently updated my WordPress site into the latest WordPress version, and i added a code to my functions.php that would add a capability to subscriber to upload using WordPress media upload. I successfully remove the media library tabs on the later version of WordPress but when I updated the version it seems like the […]

Purpose of Adding Capability to Role But Not Grant?

I am attempting to create a custom role upon activation of my plugin. Along with that role, I wanted to add new capability to that role to access later. Now, after reading the Codex, I am totally confused. What is the purpose of the grant parameter? What good would it do to add a capability […]

upload_files cap to not loggen in users – add_cap to not logged in users

When not logged in users upload files to the media endpoint, the return message is: “Sorry, you are not allowed to create posts as this user.” I would like to allow not logged in users to be able to upload files. I was looking for of the 3 solutions, but did not found any direction […]

How to assign capabilities to user NOT to User Role

Is there any way to assign custom capabilities to user, I’m NOT talking about User Role. I’m running a multi author blog where I assigned user role of “Author” to all of my authors. But I need a plugin or function.php snippet that remove a capability(not the role) from USER-ID NOTE – I dont want […]

Adding an additional role to an Administrator

User 19 is a WP Admin. $user = new WP_user( 19 ); $user->add_role( ‘custom_role’ ); The above code works and adds the custom_role role. However, when I run the same code on the personal_options_update and edit_user_profile_update hook it does not. I have added a checkbox to the user profile page. The function called from both […]

add_cap only adding the first two in array

After numerous days of trying to track down a problem in code, it turns out that the add_cap is only taking the first two in an array. The first one (editor) will only add delete_others_pages and delete_others_posts to the database. If I use the second method of repeating add_cap then I can get all of […]

How can I grant capabilities directly to users (not roles) in wp-admin?

I want to create dynamic capabilities using WP_Role::add_cap(), something like $author_role = get_role(‘author’); foreach ($sections as $section) { $author_role->add_cap( “edit_{$section}_pages”, /* grant= */ false ); } and then let administrators grant certain of those capabilities to certain authors only (e.g., Jane can edit_school_pages) in wp-admin (not programmatically, via WP_User::add_cap()). I assume a plugin can help […]

Remove upload_files capability from a role but allow role to manage an avatar image

I have a site with 1 admin, 11 editors, and 4000+ authors. I need to prevent the authors from adding media to the server and using up all the storage. Initially I tried function removemediabuttons() { if($user->wp_user_level >= 1) { remove_action( ‘media_buttons’, ‘media_buttons’ ); global $menu; unset($menu[10]); } } add_action(‘admin_head’,’removemediabuttons’); This does remove the Add […]

How to 301 private posts rather than 404?

How do I 301 redirect private pages, rather than 404 them? If a post is private, WordPress filters it out in the SQL query, so there are no $post variables to work with. I’d like for this code to work, but doesn’t: add_action(‘wp’,’redirect_stuffs’, 0); function redirect_stuffs(){ global $post; if ( $post->post_status == “private” && !is_admin() […]