最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览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?

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.

发布评论

评论列表(0)

  1. 暂无评论