How to disable revisions in WordPress? How to disable and remove all revisions in WordPress Disable revisions.

How to disable revisions in WordPress? How to disable and remove all revisions in WordPress Disable revisions.

21.01.2022

Revisions (or revisions) in WordPress have been around for a long time. They allow you to save a backup copy of a post or page every time you change it, and then view all versions with the ability to restore any of them.

Despite this useful functionality, each revision is actually a copy of the entry itself, which is also stored in the database. On large sites with a lot of content, revisions can significantly increase the size of the MySQL database.

In this short article, we will look at several methods for limiting the maximum number of revisions per post, as well as removing all revisions from the WordPress database.

Limiting the number of revisions

By default, WordPress stores all revisions for posts and pages. This can easily be changed with the wp_revisions_to_keep filter in your plugin, or with the WP_POST_REVISIONS constant in the wp-config.php configuration file. For example, if we only want to save the 5 latest versions of posts and pages, our plugin would look like this:

/** * Plugin Name: My Revisions Config */ function my_revisions_to_keep($revisions) ( return 5; ) add_filter("wp_revisions_to_keep", "my_revisions_to_keep");

Using the filter, you can also restrict revisions depending on the type of record. For example, if we need 10 revisions for pages and only 5 revisions for posts (and other types), then our plugin will look like this:

Function my_revisions_to_keep($revisions, $post) ( if ("page" == $post->post_type) return 10; else return 5; ) add_filter("wp_revisions_to_keep", "my_revisions_to_keep", 10, 2);

You can also set a limit using the WP_POST_REVISIONS directive in the WordPress configuration file wp-config.php , but splitting into post types using this method will no longer be possible:

Define("WP_POST_REVISIONS", 5);

How to disable revisions

Using the same methods, you can completely disable revisions in WordPress. To do this, you need to set a zero limit:

Function my_revisions_to_keep($revisions) ( return 0; ) add_filter("wp_revisions_to_keep", "my_revisions_to_keep");

Or using the wp-config.php file:

Define("WP_POST_REVISIONS", 0);

Note that such disabled revisions will not affect already existing revisions. All revisions that existed before the shutdown will remain available, and new revisions will not be created when saved. It is also worth noting that autosaves in WordPress are also revisions and the methods described above do not disable them.

How to remove all revisions

After you have disabled revisions in WordPress, you will most likely want to delete all previously created revisions from the WordPress database. This is easy to do with a couple of queries to MySQL through the command line or the phpMyAdmin interface.

Before you delete all revisions, you must delete their metadata and taxonomy, if any. You can do this with a query:

DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = "revision" AND post_name LIKE "%revision%");

A similar query for deleting a taxonomy:

DELETE FROM wp_term_relationships WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type = "revision" AND post_name LIKE "%revision%");

And finally, remove the revisions themselves:

DELETE FROM wp_posts WHERE post_type = "revision" AND post_name LIKE "%revision%";

This query will remove all revisions from the WordPress database except for autosaves. Before executing any such queries, we recommend that you back up your MySQL database.

We also recommend that you consider the Revision Control plugin, which allows you to view and delete revisions in WordPress, and also provides an interface for setting a limit on the number of revisions for posts and pages.

If you have any problems or questions when managing revisions in WordPress, leave a comment and we will be happy to answer you.

Hello everyone, my dear readers of the site. Not so long ago we analyzed the theme on wordpress. But just the other day I had to add another way to this article. Extremely effective when you have been blogging for a long time, provided that you did not know this chip.

These so-called revisions or in other words editions have existed since the old versions of wordpress cms.

Why are post revisions needed?

Revisions of posts and pages are needed only in theory. The fact is that they save a backup copy of your article in the database. Moreover, saving occurs with each of your changes.

It turns out that in the process of writing an article, when you click the “Save” button, you create a copy of your article with your changes. And at any time you can view a list of these copies and choose the most suitable one and restore it.

In all my practice, I have had to restore a copy from such reserves only once. But nonetheless.

On the face of it, this seems to be a very useful feature. However, one must understand that each such save is an extra load on the database, because. all copies are stored in it.

Here is an example from life. I had an average of 4-5 revisions of each article on my blog. Imagine when you have hundreds of articles written, and perhaps thousands of articles - by deleting revisions (editions) of posts - you will thereby speed up your blog 5 times.

But what if you do not have 5 editions, but 10 for each post? By the way, how much do you have, if not a secret? Write about it in the comments plz.

By the way, the most interesting thing is that when you don’t even click on the “Save” button, your post revisions are created automatically. This is called autosave.

How can I limit the number of post revisions?

We already know that all revisions are stored in the database. To change their number, we need a standard “filter”, which is called wp_revisions_to_keep , or using the WP_POST_REVISIONS directive in the wp-config.php file.

By the way, for some reason, the directive in the wp-config file did not work for me. Write for whom it works in new versions of WordPress?

So, let's say we want to leave the ability to save revisions, but leave, say, only 3 revisions. To do this, we need to write the following:

Function my_revisions_to_keep($revisions) ( return 3; ) add_filter("wp_revisions_to_keep", "my_revisions_to_keep");

Using wp_revisions_to_keep, you can also limit the number of copies in different types of posts. More precisely, in one type - one number of revisions, in another - another.

Well, for example, let's say you need 5 revisions for pages and 3 revisions for articles (posts) and other post types.

Function my_revisions_to_keep($revisions, $post) ( if ("page" == $post->post_type) return 5; else return 3; ) add_filter("wp_revisions_to_keep", "my_revisions_to_keep", 5, 2);

You can also try using WP_POST_REVISIONS in your wp-config.php file, but this method doesn't give you the ability to split into post types.

define("WP_POST_REVISIONS", 3);

How to disable and/or remove revisions in wordpress

In the same way, you can refuse revisions altogether. You just need to put the number 0 in the restrictions.

Function my_revisions_to_keep($revisions) ( return 0; ) add_filter("wp_revisions_to_keep", "my_revisions_to_keep");

Or with the wp-config.php file:

Define("WP_POST_REVISIONS", 0);

The most important thing. Disabling revisions - will not affect their existence (already existing ones) in any way. those. if you had 3-5 revisions for each article and you turned off the revisions, the old copies of the posts will still remain. They need to be deleted by hand through the database.

How to delete all revisions, revisions

So, we turned off revisions. We already know that simply disabling editions is not enough. It is necessary to uproot them, delete them manually via MySQL.

Let's start, perhaps. But, before deleting something, make a backup. It is better to make a backup of the entire site.

DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = "revision" AND post_name LIKE "%revision%");

Do something similar for taxonomies

DELETE FROM wp_term_relationships WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type = "revision" AND post_name LIKE "%revision%");

And of course, we delete the revisions (revisions) themselves.

DELETE FROM wp_posts WHERE post_type = "revision" AND post_name LIKE "%revision%";

This query in MySQL will remove all the revisions that are in your database. Except for autosaves.

Autosave - also considered a revision, but they are not deleted or disabled !! Therefore, in order to have as few of them as possible - write the texts in advance in the Word, and then just paste them into the admin panel!

A little reminder on how to work with MySQL

If suddenly forgotten.

I work with adminvps hosting, I even explained why with it in this article. So, I will show everything on it.

Login to phpMyAdmin in your hosting control panel.

Enter login and password.

We chose the database we needed and pressed the SQL button, which is located on top.

And we see a large field for writing SQL queries. For the entire database.

There we enter all requests in order.

Don't worry if you see null values, you just haven't used left post types or taxonomies.

And here is what I got using the last query.

See how my blog got faster after that. This is just a fairy tale!

I'm sure you have the same! Check it out and let me know about it later.

Plugin for editing posts

I can also recommend the Revision Control plugin, it allows you to do the same thing that I described, only in a more comfortable mode for you. Right in the admin.

If you still have questions - ask, I will be happy to help you. That's all for now. Thank you for your attention.

Most WordPress users are not even aware of the concept of “WordPress revisions”, however it is useful to have an idea of ​​what it is, and in some rare cases it is desirable to know how to disable these revisions.

So, revisions (or revisions) are copies of your posts that are created every time you save or autosave a page when it changes. This is done in case you want to return to some previous edition of the text or in case of an unexpected failure in the computer or communication.

I believe that if you do not have any problems in the operation of the site, it does not have a large database that you would like to reduce and there are no comments on the speed of page formation, you should not worry about the presence of editions on the site.

You can see the generated revisions (in terms of Russian WordPress) under the editing window.

Navigating to any of the text revisions in the list will return the text to a state that corresponds to the time that revision was saved.

As we can see, there can be many revisions for each entry, and for a site with a large number of entries, they can take up a significant amount of disk space, which can eventually lead to problems in its work.

For small sites this is irrelevant, but if you have thousands of records and each is presented in several editions, this can significantly increase the size of the database. Firstly, it slows down the work with the database, secondly, these records take up space on the hosting, and thirdly, which, for example, was relevant for me, it can interfere with the automatic backup of your data. I have site data regularly automatically archived by the plugin and sent to a specific e-mail. If the archive exceeds the size limit for e-mail, this technology stops working.

Revision setup

How do you remove wordpress editions? First, you can specify the following statement in the wp-config.php file (located in the root folder of your site):

define("WP_POST_REVISIONS", 0);

which means keeping only the last three revisions.

You can delete revisions that have already accumulated in the database in at least two ways.

1. Deleting directly in the database

We go into phpMyAdmin then to the desired database. Then in the top menu, go to the tab - "SQL". A window will appear in which you need to enter the SQL command:

And press the button below - "OK" (or "Forward"). All editions removed.

Today's article will be about WordPress revisions.

WordPress revisions are auto-save posts when editing. On the one hand, this is a great feature: for example, you have been writing an article for more than one hour, when suddenly the electricity in the apartment was turned off, or the browser freezes, or the tab was accidentally closed ... When this happened to me for the first time, thoughts immediately came to my mind about how I'll have to re-type text, align images, in general, do everything all over again, but no such luck! WordPress automatically saved my entire post! You will not believe how much I was grateful to the developers for such a feature.

But there is also the other side of the coin. Default, WordPress revisions are made every 60 seconds, and each revision is written to the database. Now calculate how many revisions per post you have on average and multiply by the number of blog posts. Lots of wild! The size of the database can be half of the revisions. That's exactly what I had. See how the size of the database has decreased after deleting all revisions. Twice!

How to Disable WordPress Revisions

For disabling WordPress revisions open the wp-config.php file, it lies at the root of your site.

We go into it and add the following lines:

define("WP_POST_REVISIONS", 0);

The number in parentheses indicates how many revisions are allowed per entry. You can also specify the autosave interval in seconds (default 60).

When writing and editing posts in WordPress, they are automatically saved - a backup copy of the post (revision) is made. With the help of revisions, you can restore an article by going a few steps back. To restore an article, you only need to select the required revision.

However, revisions are not always good. Additional server resources are required to store backup copies of posts and articles. Revisions litter the database, so it's worth considering whether they are needed at all. How often do we use revisions when editing WordPress posts? If not, then they can be disabled.

Disabling Revisions in WordPress

To disable revisions in WordPress up to version 3.0.3 you need to navigate to the "config.php" configuration file and open it with a text editor such as Notepad++. After that, you need to find the line:

define("WP_POST_REVISIONS",0);

In case we have WordPress version 3.0.3 or newer - revisions are disabled in the "default-constants.php" file (located in the "wp-includes" folder). Looking for the line:

define("WP_POST_REVISIONS", true);

After that, change true to false as shown below:

define("WP_POST_REVISIONS", false);

We save the file "default-constants.php". This way revisions will be disabled.

All created revisions in WordPress can be easily deleted. In order to delete old revisions, you need to go phpMyAdmin and select a database. Then you need to go to the tab SQL and in the window that opens, in the input field, insert the line:

DELETE FROM wp_posts WHERE post_type = "revision";

An example is shown in the figure:

Then we press the "OK" button and all previously saved revisions will be deleted. This method of deleting revisions is suitable for all versions of the WordPress engine.

© 2022 hecc.ru - Computer technology news