让我们用你的第二个选择来解决这个问题。因此,如果要限制用户编辑已发布的帖子,可以将其添加到主题中functions.php
文件(请阅读添加的注释):
function restrict_editing_old_posts( $allcaps, $cap, $args ) { // Restrict users from editing post based on the age of post
// Bail out if we\'re not asking to edit or delete a post ...
if( ( \'edit_post\' != $args[0] && \'delete_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] );
// Bail out if the post isn\'t published:
if( \'publish\' != $post->post_status )
return $allcaps;
$post_date = strtotime( $post->post_date );
//if post is older than 10 days ...
if( $post_date < strtotime( \'-10 days\' )
// ... or if older than 1 days and user is not Editor
|| ( empty($allcaps[\'moderate_comments\']) && $post_date < strtotime(\'-1 days\') ) ) {
$allcaps[$cap[0]] = FALSE;
}
return $allcaps;
}
add_filter( \'user_has_cap\', \'restrict_editing_old_posts\', 10, 3 );
使用上述代码,您将:
限制none编辑器删除超过1天的已发布帖子重新限制编辑删除超过10天的已发布帖子然后,为了改进界面,您可能需要删除垃圾链接。可以通过添加以下代码来执行此操作:
// START access to Trash folder where users can delete posts permanently
function remove_trash_link( $views )
{
if( !current_user_can( \'manage_options\' ) )
unset( $views[\'trash\'] );
return $views;
}
function block_trash_access()
{
global $current_screen;
if(
\'post\' != $current_screen->post_type
|| \'trash\' != $_GET[\'post_status\']
)
return;
if( !current_user_can( \'manage_options\' ) )
{
wp_redirect( admin_url() . \'edit.php\' );
exit;
}
}
add_filter( \'views_edit-post\', \'remove_trash_link\' );
add_action( \'admin_head-edit.php\', \'block_trash_access\' );
// END access to Trash folder
这应该涵盖你的问题。作为请求,请根据指导原则设置您的问题的格式,以便其他用户阅读和查找。