3

On a platform with many Editors, the problem that I am experiencing is that two editors proofread the same post simultaneously (and disregarding the warning notice about someone else currently editing the post).

Is there a solution where I can restrict access to a post if it is currently being edited by a different user? Maybe by disabling the post's edit link on the post list? This should only take effect on editors if they are not the author of the post (we don't want them to be locked out of their own post) and admins should be excluded from any restriction.

  • Btw, post forking is in too early stages: wordpress.org/support/plugin/post-forking – Christine Cooper Apr 13 '13 at 15:49
  • Curious: what happens if an editor is editing a post, and then the post's author or admin wants to go and modify it? – montrealist Apr 13 '13 at 16:00
  • Editors are only allowed to edit pending posts, so the conflict happens between editors themselves and occasionally admins. So if two editors proofread the same post, then one of them wasted time. Do you get my drift? – Christine Cooper Apr 13 '13 at 16:03
  • 1
    Not that it's of any help at the moment, but it looks like they are working on a solution for this in 3.6 make.wordpress.org/core/2013/01/07/… – Hoshts Apr 13 '13 at 16:33
  • 1
    It really needed as WP evolved into a nice CMS. Still I hope it will be permission based and not something that users need to activate them selfs. – Hoshts Apr 13 '13 at 18:14
2

The warning notice gets dispatched by the function wp_check_post_lock. The following redirects the user back to the post listing screen if someone else is editing it.

add_action( 'load-post.php', 'redirect_locked_post_wpse_95718' );

function redirect_locked_post_wpse_95718()
{
    if( isset($_GET['post'] ) && wp_check_post_lock( $_GET['post'] ) )
    {
        global $typenow;
        $goto = ( 'post' == $typenow ) ? '' : "?post_type=$typenow";
        wp_redirect( admin_url( "edit.php$goto" ) );
        exit();
    }
}

And to indicate that a post is locked, ie, being edited by other user, a small red sign can be added to the row actions.

locked post

foreach( array( 'post', 'page' ) as $hook )
    add_filter( "{$hook}_row_actions", 'locked_post_notice_wpse_95718', 10, 2 );

function locked_post_notice_wpse_95718( $actions, $post ) 
{
    if( wp_check_post_lock( $post->ID ) )
    {
        $actions['locked'] = sprintf(
            '<span style="color:#f00;font-weight:bolder;">&#149;&#149;&#149; LOCKED %s &#149;&#149;&#149;</span>',
            strtoupper( $post->post_type )
        );
    }
    return $actions; 
}
  • Two questions before I start testing this stellar answer. Is admins excluded from this lockout? And if someone is editing a post, can the author of the post still access it? – Christine Cooper Apr 13 '13 at 18:51
  • No, no user/role is being considered. It's just a base that needs refinement :) - You'd have to check against current user and post_author. – brasofilo Apr 13 '13 at 18:58
  • 1
    And it is a great base indeed, thank you brasofilo! Exactly what I needed. Particularly the indicator solution. I will test this and report back if there are any issues. – Christine Cooper Apr 13 '13 at 19:00
  • Would it be possible to add the Locked note at the beginning of the post title instead? Like this for instance: i.imgur.com/bmzwUMI.png – Christine Cooper Apr 14 '13 at 17:08
  • 1
    Interesting filter (get_edit_post_link) in this Answer. – brasofilo Apr 14 '13 at 20:30

Your Answer

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

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