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?
1 Answer
Reset to default 1You 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
评论列表(0条)