0

The more I read Wordpress Codex the more often I wonder if tutorials you can find on the net are actually correct. I've found several tutorials about creating metaboxes where user capabilities (when saving the matabox) are being checked like this:

if ( 'page' === $_POST['post_type'] ) {

    if ( ! current_user_can( 'edit_page', $post_id ) ) {

       return $post_id;

    }

} elseif ( ! current_user_can( 'edit_post', $post_id ) ) {

    return $post_id;

}

When I was browsing through Codex page on WP Capabilities I couldn't find edit_post or edit_page capability. There were edit_posts and edit_pages capabilities mentioned on that page. Why there is edit_post instead of edit_posts used in the bit of code I pasted?

1

You can find list of capabilities here: Roles and Capabilities

There is no capability called edit_post nor edit_page. But...

There is also something called Meta Capabilities.

The capabilities listed on the Capabilities list are global capabilities. So they're saying that user can edit posts or pages. But it doesn't mean that given user can edit given post (for example editors can edit only own posts). This is where meta capabilities are used.

| improve this answer | |
  • In other words: Can I use Meta Capability with current_user_can() then? – Daniel May 7 '18 at 10:34
  • Yes. Just take a look at description for second param of current_user_can: "Recommended when checking meta capabilities such as the capabilities defined in the map_meta_cap function i.e 'edit_post', 'edit_others_posts', 'read_post' etc." – Krzysiek Dróżdż May 7 '18 at 10:35
  • 1
    Ah, true! I must have missed that! Thanks for your effort! – Daniel May 7 '18 at 10:36
  • The editor level can edit all posts by default. Author and below can only edit their own with the default capabilities set. – squarecandy Oct 8 '19 at 1:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.