您可以尝试以下操作:
/**
* Post Update Locker For Authors
* If an administrator has updated the post, then lock it for author updates.
* @see http://wordpress.stackexchange.com/a/168578/26350
*/
add_action( \'pre_post_update\', function( $post_ID, $data ) {
// Target only authors:
if( ! current_user_can( \'edit_post\' ) || current_user_can( \'edit_others_posts\' ) )
return;
// Target only \'post\' post types:
if( get_post_type( $post_ID ) !== \'post\' )
return;
// Fetch all administrators:
$admins_ids = get_users(
array(
\'role\' => \'administrator\',
\'fields\' => \'ID\'
)
);
// or hardcoded if needed:
// $admins_ids = array( 1 );
// Check if administrators have modified the current post, by checking the revisions:
$posts = get_posts(
array(
\'no_found_rows\' => true,
\'update_post_meta_cache\' => false,
\'update_post_term_cache\' => false,
\'posts_per_page\' => -1,
\'fields\' => \'ids\',
\'post_parent\' => $post_ID,
\'post_type\' => \'revision\',
\'post_status\' => \'any\',
\'author__in \' => $admin_ids,
)
);
// Halt if an administrator has modified the post:
if( count( $posts ) > 0 )
wp_die( __( "Sorry, you can\'t modify this post, it\'s already been modified by an administrator! " ) );
}, 10, 2 );
您可能需要对此进行调整并进行进一步测试。
更新:
下面是一个如何删除
submitdiv
无法更新当前帖子的作者的metabox:
/**
* Hide the publish metabox for authors if an administrator has updated the post.
* @see http://wordpress.stackexchange.com/a/168578/26350
*/
add_action( \'admin_menu\', function() {
add_action( \'load-post.php\', \'wpse_author_update_locking\' );
});
function wpse_author_update_locking()
{
// Setup - Modify this to your needs:
$admin_ids = array( 1 );
$cpt = \'post\';
// User input:
$_pid = filter_input( INPUT_GET, \'post\', FILTER_SANITIZE_NUMBER_INT );
// Target only $cpt post types:
if( get_post_type( $_pid ) !== $cpt )
return;
// Target only authors:
if( ! current_user_can( \'edit_post\' ) || current_user_can( \'edit_others_posts\' ) )
return;
if( $_pid > 0 )
{
// Check if administrators have modified the current post,
// by checking the revisions:
$posts = get_posts(
array(
\'no_found_rows\' => true,
\'update_post_meta_cache\' => false,
\'update_post_term_cache\' => false,
\'posts_per_page\' => -1,
\'fields\' => \'ids\',
\'post_parent\' => $_pid,
\'post_type\' => \'revision\',
\'post_status\' => \'any\',
\'author__in \' => $admin_ids,
)
);
// Halt if an administrator has modified the post:
if( count( $posts ) > 0 )
{
remove_meta_box( \'submitdiv\', $cpt , \'side\' );
add_meta_box(
\'submitdivmod\',
__( \'Publish\' ),
\'wpse_post_submit_meta_box\',
$cpt,
\'side\',
\'core\'
);
}
}
}
function wpse_post_submit_meta_box()
{
_e("Sorry, you can\'t modify this post, it\'s already been modified by an administrator!");
}
然后,代替此元数据库:
作者认为: