1

I am developing a Wordpress site with Edit Flow plugin, so I can create custom post statuses to manage author and contributor posts more easily.

So I have created custom post status and I've got following filter to restrict edit capabilities to that post. It is working fine, but the problem is that users (except admin) can't preview the post. Other users can still see the "Preview" link in dashboard post list, but if they click on it and go to post preview page (../post-with-custom-status/?preview=true) it says that post can't be found.

function restrict_edit_custom_status_posts( $allcaps, $cap, $args ) {

    // Bail out if we're not asking to edit a post ...
    if( 'edit_post' != $args[0]
        // ... or user is admin
        || !empty( $allcaps['manage_options'] )
        // ... or user already cannot edit the post
        || empty( $allcaps['edit_posts'] ))
        return $allcaps;

    // Load the post data:
    $post = get_post( $args[2] );

    // If post have custom status
    if( 'my_custom_status' == $post->post_status ) {
    // Then disallow editing
    $allcaps["edit_posts"] = FALSE;
        return $allcaps;
    }

    return $allcaps;
}
add_filter( 'user_has_cap', restrict_edit_custom_status_posts10, 3 );

So is there any way that I can restrict edit capability, but allow preview?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.