wordpress页面_如何控制WordPress中的页面和帖子修订

wordpress页面

Control of Page and Post Revisions in WordPress

This article is part of a series created in partnership with SiteGround. Thank you for supporting the partners who make SitePoint possible.

本文是与SiteGround合作创建的系列文章的一部分。 感谢您支持使SitePoint成为可能的合作伙伴。

WordPress provides a revisions system which records a full copy of every page and post when it’s saved. The advantage: you can revert to an earlier version of the document at any time and make comparisons. Or you could discover who’s to blame for spolling and errors grammatical.

WordPress提供了一个修订系统,该系统可以记录每页的完整副本并在保存时发布。 优点:您可以随时还原到文档的早期版本并进行比较。 否则,您可能会发现谁应该为语法错误和错误承担责任。

By default, there is no limit to the number of revisions stored per page or post. (Note only a single auto-save is made per post per editor — the most recent auto-save overwrites the previous one.) Every revision requires a separate row in WordPress’s posts table and perhaps multiple entries in the postmeta and term_relationships tables. That’s rarely a problem for smaller sites but it could affect the performance and efficiency of larger installations. Tables eventually become filled with redundant data which will never be used.

默认情况下,每页或每个帖子存储的修订数量没有限制。 (请注意,每个编辑者每个帖子仅进行一次自动保存-最新的自动保存会覆盖前一个自动保存。)每个修订都需要WordPress的posts表中的单独一行,以及postmetaterm_relationships表中的多个条目。 对于较小的站点来说,这几乎不是问题,但可能会影响较大安装的性能和效率。 最终,表中充满了永远不会使用的冗余数据。

限制修订 (Limiting Revisions)

The number of revisions can be set in WordPress’s wp-config.php file. If you’re not aware of that file, I recommend you seek further guidance from a developer. Make a copy of wp-config.php before editing because the smallest error could break your WordPress site.

可以在WordPress的wp-config.php文件中设置修订数量。 如果您不知道该文件,建议您向开发人员寻求进一步的指导。 在编辑之前制作wp-config.php的副本,因为最小的错误可能会破坏您的WordPress网站。

To disable revisions entirely, add the following line to wp-config.php:

要完全禁用修订,请将以下行添加到wp-config.php

define('WP_POST_REVISIONS', 0);

To limit revisions, change the number to a positive integer, e.g. for no more than ten revisions per page/post:

要限制修订版本,请将数字更改为正整数,例如,每页/每页不超过十个修订版本:

define('WP_POST_REVISIONS', 10);

To revert back to unlimited revisions, remove the line or change the value to -1:

要恢复为无限制的修订,请删除行或将值更改为-1

define('WP_POST_REVISIONS', -1);

修订插件 (Revision Plugins)

If file editing feels a little too hardcore, there are several plugins to control revisions. For example, WP Revisions Limit sets the revision limit in an identical way.

如果觉得文件编辑有点过于刻板,可以使用几个插件来控制修订 。 例如,“ WP版本限制 ”以相同的方式设置版本限制。

以编程方式限制修订 (Programmatically Limiting Revisions)

The wp_revisions_to_keep filter allows plugins or your theme’s functions.php file to control how many revisions are retained for a given post.

wp_revisions_to_keep过滤器允许插件或主题的functions.php文件控制为给定帖子保留多少修订。

The filter’s function is passed two arguments:

过滤器的函数传递了两个参数:

  • the default number of revisions to keep

    要保留的默认修订数量
  • the WP_Post object of the current post

    当前帖子的WP_Post对象

and must return the number of permitted revisions.

并且必须返回允许的修订版本数。

The following example sets a limit of five revisions for posts with the type “custom_post”:

以下示例为“ custom_post”类型的帖子设置了五个修订版本的限制:

add_filter( 'wp_revisions_to_keep', 'control_revisions', 10, 2 );

function control_revisions($num, $post) {

  if('custom_post' == $post->post_type) $num = 5;
  return $num;

}

You can also use the WordPress REST API to list, retrieve and delete revisions.

您还可以使用WordPress REST API 列出,检索和删除修订

如何删除旧版本 (How to Remove Old Revisions)

The methods above activate immediately so, ideally, you should set WP_POST_REVISIONS shortly after installing WordPress. However, the setting will not remove old revisions from your MySQL database. It is possible to clean the old data but please be aware of the danger. Before taking any action, remember to…

上面的方法会立即激活,因此,理想情况下,您应该在安装WordPress之后不久设置WP_POST_REVISIONS 。 但是,该设置不会从MySQL数据库中删除旧版本。 可以清除旧数据,但是请注意危险。 在采取任何行动之前,请记住……

BACK UP YOUR DATABASE!

备份您的数据库!

The easiest option is to use a plugin such as WP-Optimize which cleans your WordPress database by removing revisions as well as other optimizations. You can run it once or set a regular schedule.

最简单的选择是使用诸如WP-Optimize之类的插件,该插件通过删除修订和其他优化来清除WordPress数据库。 您可以运行一次或设置定期计划。

Alternatively, you can live dangerously and run a SQL command to clean revisions. First, find your WordPress table prefix — it is specified in wp-config.php, e.g.

另外,您可能会过着危险的生活,并运行SQL命令来清理修订版。 首先,找到您的WordPress表前缀-它在wp-config.php中指定,例如

$table_prefix = 'wp_';

wp_ is the default. We’ll assume wp_ has been specified for the following code but change the references if necessary. To delete all revisions for all pages and posts, start a MySQL administration tool such as phpMyAdmin and run the following SQL command:

wp_是默认值。 我们假定为以下代码指定了wp_ ,但如有必要,请更改引用。 要删除所有页面和帖子的所有修订,请启动MySQL管理工具(例如phpMyAdmin)并运行以下SQL命令:

DELETE a,b,c
FROM wp_posts a
LEFT JOIN wp_term_relationships b ON ( a.ID = b.object_id )
LEFT JOIN wp_postmeta c ON ( a.ID = c.post_id )
LEFT JOIN wp_term_taxonomy d ON ( b.term_taxonomy_id = d.term_taxonomy_id )
WHERE a.post_type = 'revision'
AND d.taxonomy != 'link_category';

Thanks to Michael Ambrosio for providing this fix when my original code, ahem, broke some stuff!

感谢Michael Ambrosio在我的原始代码ahem破坏了某些内容时提供了此修复程序

All going well, you’ll have a sparkling clean database and WordPress will be noticeably faster. Alternatively, WordPress won’t start and you’ve lost a decade-worth of amazing posts. But you did back-up first, of course…

一切顺利,您将拥有一个闪亮的干净数据库,而WordPress将明显更快。 另外,WordPress无法启动,您已经失去了十年之久的精彩帖子。 但是您当然要先备份...

翻译自: https://www.sitepoint.com/wordpress-post-revision-control/

wordpress页面

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值