metabox - edit_page or edit-pages for current_user_can()?

The more I read Wordpress Codex the more often I wonder if tutorials you can find on the net are actually correct. I

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?

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?

Share Improve this question asked May 7, 2018 at 10:14 DanielDaniel 1931 silver badge13 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745100226a4611228.html

相关推荐

  • metabox - edit_page or edit-pages for current_user_can()?

    The more I read Wordpress Codex the more often I wonder if tutorials you can find on the net are actually correct. I

    13小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信