Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Referring to the docs got add_meta_box,

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

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')) 
    return;
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.

1 Answer 1

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' ) ) 
        return;
}
share|improve this answer

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