警告通知由函数发出wp_check_post_lock
. 如果其他人正在编辑,下面会将用户重定向回post listing屏幕。
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();
}
}
并且为了指示帖子被锁定,即被其他用户编辑,可以在行操作中添加一个小的红色标志。
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;">••• LOCKED %s •••</span>\',
strtoupper( $post->post_type )
);
}
return $actions;
}