WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Referring to the docs got add_meta_box,

// Check permissions
if ( 'page' == $_POST['post_type'] ) {
    if ( !current_user_can( 'edit_page', $post_id ) )
    } else {
    if ( !current_user_can( 'edit_post', $post_id ) )

If I want to authenticate a user for editing a custom post type "portfolio", do I do something like

if ($_POST['post_type'] != 'portfolio' || !current_user_can_for_blog($post_id, 'edit_post')) 
share|improve this question

closed as not a real question by toscho Jul 8 '12 at 22:12

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

No, the function current_user_can_for_blog expects a blog ID to be passed to it, not a post ID. I would change it to be like this:

if( isset( $_POST['post_type'] ) && $_POST['post_type'] != 'portfolio' ) {
    if ( !current_user_can( $post_id, 'edit_post' ) ) 
share|improve this answer

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