
删除 WordPress
Managing WordPress website with multiple authors can be complicated sometimes. There are plugins to 管理编辑工作流程, but you may come across situations where you need specific solutions for better control of your WordPress site. Recently, we helped a user find such a solution. They wanted to block WordPress post updates and deletion after a set period of time for all users (including editors) after a set period of time. For example, if a published post is 30 days or older, then it cannot be edited or deleted by editors. Only administrators can modify that post. In this article, we will show you how to block post edit, updates, and deletion after a set period of time in WordPress.
由多个作者管理WordPress网站有时会很复杂。 有一些插件可以管理编辑工作流程 ,但是您可能会遇到需要特定解决方案以更好地控制WordPress网站的情况。 最近,我们帮助用户找到了这样的解决方案。 他们希望在设定的时间段之后阻止所有用户(包括编辑器)在WordPress上的帖子更新和删除。 例如,如果已发布的帖子已超过30天,则编辑者将无法对其进行编辑或删除。 只有管理员可以修改该帖子。 在本文中,我们将向您展示如何在WordPress设置的一段时间后阻止帖子的编辑,更新和删除。

All you need to do is add the following code in your theme’s functions.php file or in a 特定于站点的插件.
您所需要做的就是在主题的functions.php文件或具体的于在网站的插件中添加以下代码。
function wpbeginner_restrict_editing( $allcaps, $cap, $args ) {
// 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;
//if post is older than 30 days. Change it to meet your needs
if( strtotime( $post->post_date ) < strtotime( '-30 day' ) ) {
//Then disallow editing.
$allcaps[$cap[0]] = FALSE;
}
return $allcaps;
}
add_filter( 'user_has_cap', 'wpbeginner_restrict_editing', 10, 3 );
此功能检查用户是否具有编辑或删除帖子的能力。之后它会检查帖子状态。如果发布的帖子超过 30 天,则用户编辑和删除该帖子的能力将被剥夺。如果发布的帖子超过 30 天,则用户编辑和删除该帖子的能力将被剥夺。帖子已发布,但不超过 30 天,则具有编辑帖子能力的用户仍然可以对其进行编辑。注意:管理员可以随时编辑和删除帖子。
此功能检查用户是否能够编辑或删除帖子。之后,它将检查发布状态。如果帖子发布时间超过 30 天,用户编辑和删除该帖子的权限将被撤销。如果帖子已发布但发布时间不到 30 天,具有编辑帖子能力的用户仍然可以对其进行编辑。注意:如有必要,管理员可以随时编辑和删除帖子。
我们希望这篇文章能够帮助任何想要在一段时间后阻止 WordPress 中的帖子编辑、更新和删除的人。您会在您的网站上这样做吗?对于这样的事情,您能看到哪些用例?请在下面的评论中告诉我们。
我们希望这篇文章对想要在特定时间段后阻止 WordPress 中的帖子编辑、更新和删除的每个人有所帮助。您会在您的网站上这样做吗?您会看到哪些用例?请在下面的评论中告诉我们。
来源:斯米克
资源: 斯米克
删除 WordPress