如何在WordPress中限制或禁用自动清空垃圾箱

In WordPress, when delete a post or comment, it goes into trash. By default, trashed posts and comments remain in your database for 30 days giving you enough time to restore them if needed. After 30 days, WordPress automatically deletes all trash content permanently. In this article, we will show you how to limit or disable automatic WordPress empty trash feature.

在WordPress中,删除帖子或评论时,它会变成垃圾。 默认情况下,垃圾邮件和评论会在您的数据库中保留30天,以便您有足够的时间还原它们(如果需要)。 30天后,WordPress会自动永久删除所有垃圾内容。 在本文中,我们将向您展示如何限制或禁用自动WordPress空垃圾桶功能。

WordPress Automatically Empty Trash
WordPress中的垃圾桶是什么? (What is Trash in WordPress?)

When you delete a post, page, or a comment in WordPress, it is marked as trash.

当您在WordPress中删除帖子,页面或评论时,该帖子,页面或评论被标记为垃圾桶

Trash links on Posts screen

You can see the trashed posts or comments by clicking on the Trash link when viewing posts, pages, or comments.

您可以在查看帖子,页面或评论时单击“垃圾箱”链接来查看已删除帖子或评论。

By default, these items will remain there for 30 days. After that, WordPress will automatically delete them permanently.

默认情况下,这些项目将在此保留30天。 之后,WordPress将自动将其永久删除。

You can override the automatic process by going to trash and deleting the items manually by clicking on the delete permanently link.

您可以通过删除垃圾箱并单击永久删除链接来手动删除项目,从而覆盖自动过程。

Deleting an item permanently from trash

But what if you don’t want WordPress to delete items from trash? Or maybe you want WordPress to automatically delete items sooner or later than 30 days.

但是,如果您不希望WordPress从垃圾箱中删除项目怎么办? 或者,也许您希望WordPress早于30天自动删除项目。

Let’s take a look at how to limit or disable automatic WordPress empty trash feature.

让我们看一下如何限制或禁用自动WordPress空废纸feature功能。

阻止WordPress自动清空垃圾箱 (Stopping WordPress from Automatically Emptying Trash)

Do you want to stop WordPress from automatically deleting items from trash? Here is what you need to do.

您要阻止WordPress自动删除垃圾桶中的项目吗? 这是您需要做的。

Simply add this little code snippet in your theme’s functions.php file or a site-specific plugin.

只需在主题的functions.php文件或特定站点的插件中添加此小代码段即可。



function wpb_remove_schedule_delete() {
    remove_action( 'wp_scheduled_delete', 'wp_scheduled_delete' );
}
add_action( 'init', 'wpb_remove_schedule_delete' );


This code simply removes the action that deletes trashed items when their time is up.

此代码只是删除了已用完的项目时删除已删除项目的操作。

Now when you send an item to trash, it will remain there until you go to trash and manually empty the trash.

现在,当您将项目发送到垃圾箱时,它将保留在那里,直到您进入垃圾箱并手动清空垃圾箱为止。

在WordPress中更改何时清空垃圾箱 (Changing When to Empty Trash in WordPress)

As we mentioned earlier, WordPress automatically empty trash after 30 days. You can change this to any number of days you want.

如前所述,WordPress在30天后自动清空垃圾箱。 您可以将其更改为任意天数。

Simply add the following line of code in your wp-config.php file just before the line that says ‘That’s all, stop editing! Happy blogging.’

只需在您的wp-config.php文件中添加以下代码行,即可在“这就是所有,停止编辑! 祝您博客愉快。”



define('EMPTY_TRASH_DAYS', 7);


This line changes the trash emptying schedule to 7 days. You can change 7 to any number of days that you want.

该行将垃圾清空时间表更改为7天。 您可以将7更改为任意天数。

在WordPress中禁用垃圾桶功能 (Disabling The Trash Feature in WordPress)

We don’t recommend disabling the trash functionality in WordPress. It is a great feature that comes in handy when you accidentally delete a post, page, or a comment.

我们不建议在WordPress中禁用垃圾箱功能。 当您意外删除帖子,页面或评论时,此功能非常有用。

However, if you really feel that you don’t need this functionality, and you would rather delete things permanently, then here is what you need to do.

但是,如果您确实感觉到不需要此功能,而宁愿永久删除它们,那么这里就是您需要做的。

Simply add this line of code in your wp-config.php file just before the line that says ‘That’s all, stop editing! Happy blogging.’

只需将这行代码添加到您的wp-config.php文件中,然后在显示仅此而已,请停止编辑! 祝您博客愉快。”



define('EMPTY_TRASH_DAYS', 0);


Adding this line will disable the WordPress trash feature completely. On your posts and pages, custom post types, and comments pages, you will see Delete Permanently link instead of Trash.

添加此行将完全禁用WordPress垃圾回收功能。 在您的帖子和页面自定义帖子类型和评论页面上,您将看到“永久删除”链接,而不是“已删除邮件”。

Trash feature disabled in WordPress

That’s all, we hope this article helped you learn how to limit or disable automatic empty trash feature in WordPress. You may also want to see our list of 21 plugins to efficiently manage WordPress multi-author blogs.

仅此而已,我们希望本文能帮助您学习如何限制或禁用WordPress中的自动清空垃圾桶功能。 您可能还希望查看我们的21个插件列表, 以有效管理WordPress多作者博客

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在TwitterFacebook上找到我们。

翻译自: https://www.wpbeginner.com/beginners-guide/how-to-limit-or-disable-automatic-empty-trash-in-wordpress/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值