How to disable auto-save drafts/disable revisions for WordPress articles?

WordPress's auto-save, auto-draft, and revisions features have always been affected byInternet marketingstaff criticism.

However, WordPress is the most popular website program in the world:

  • WordPress is very powerful;
  • Plusunlimitedscalability;
  • So WordPress is very popular among personal and business customers.

What is the WordPress auto-save feature for?

WordPress auto-save prevents the editor from closing unexpectedly and causing loss of post content.

  • For example, sudden network disconnection, sudden power outage, etc…
  • Editing articles is difficult, and articles have disappeared…
  • At this moment, it is very unexpected!

However, this feature can bloat the database and add a lot of useless junk for no reason.

Fortunately, there is aWordPress plugin "Easy WP Cleaner" can delete this garbage.

The problem is that this "weight loss process" is very painful, and this article will share the best way to solve this problem.

How to disable auto-save drafts/disable revisions for WordPress articles?

What is the difference between WordPress auto-save and auto-draft?

Another very annoying feature of WordPress is auto-drafting.

  • Auto-draft is similar to auto-save, which is when you write an article.
  • Articles will be automatically backed up and written to the database according to time intervals.
  • Auto-draft is new when you click "Write an article".

Even if you quit the editor, the data is written to the database, whether you type it or not.

What is the WordPress revision feature useful for?

Actually WordPress' revision feature is very useful, users can check changes and perform version control.

There are always two sides to things, just like the auto-save feature, ignoring these changes can unnecessarily burden the database.

  • If you write a large paragraph when editing a long article, remember to manually click Save.
  • or notepad for computersoftware, edit it first, then copy it to the WordPress editor and then publish it (which can effectively avoid data loss during the process of entering the article into the database).

Modify WordPress Configuration File (Method 1 Recommended)

In fact, there are many hidden functions in WordPress, which can be disabled or enabled according to the configuration through the function of the wp-config.php file in the root directory of the WordPress installation.

a lot of useWordPress websiteof friends, all want to disable WordPress auto-draft, not auto-save.

The following code solves the problem.

Due to the mechanism of WordPress, it is not possible to completely disable auto-save, but you can achieve a similar effect by setting a longer interval, such as ▼

define( 'AUTOSAVE_INTERVAL', 3600 ); // 默认是 60,3600秒表示自动保存间隔1小时

What is the maximum number of WordPress revisions allowed?

// WordPress设置自动保存间隔/秒
define('AUTOSAVE_INTERVAL', 3600);
// WordPress设置修订版本最多允许几个
define('WP_POST_REVISIONS', 3);

You can add the following definitions to your WordPress site wp-config.php in file▼

define( 'AUTOSAVE_INTERVAL', 3600 ); // 3600秒表示自动保存间隔1小时
define( 'EMPTY_TRASH_DAYS', 7 ); // 在 7 天后被删除
define( 'DISABLE_WP_CRON', true ); // 禁用内部Wp-Cron函数
define('WP_POST_REVISIONS', false ); // 禁用文章修订版本
  • Auto-drafts are automatically deleted after 7 days of inactivity.
  • They are basically cleaned up by automatic functions, no need to worry about them.
  • Tested set to define( 'AUTOSAVE_INTERVAL', 86400 ); The auto save interval does not take effect after 24 hours.
  • It is recommended to set the auto save interval to 3600 (1 hour).

    Disable WordPress Revisions (Method 2)

    If method 1's disabling post revisions doesn't work, you need to use the following WordPress code to disable revisions for all post types.

    Please add the WordPress theme template filefunctions.php, add the following disabling article revision code▼

    // WordPress禁用所有文章类型的修订版本
    add_filter( 'wp_revisions_to_keep', 'cwl_wp_revisions_to_keep', 10, 2 );
    function cwl_wp_revisions_to_keep( $num, $post ) { return 0;}

    WordPress code to disable revisions for a certain post type▼

    // WordPress禁用某种文章类型的修订版本
    add_filter( 'wp_revisions_to_keep', 'cwl_wp_revisions_to_keep', 10, 2 );
    function cwl_wp_revisions_to_keep( $num, $post ) {
    if ( 'post_type' == $post->post_type ) { //引号中post_type改为你想禁用修订版本的文章类型
    return 0;
    }
    return $num;
    }

    As for WordPress auto-drafts, you can't disable them for an important reason.

    Samuel 'Otto' Wood, a tech ninja at Audrey Capital (Matt Mullenweg's angel investment firm), said:

    Auto-drafts exist because multiple users can create new posts at the same time.If two people go to post-new at about the same time, and then their first autosave happens at about the same time, there is a race condition that could cause one of them to get back the wrong post id, which would cause the post to be overwritten/ Lost, when they continue editing the post.

    Auto-Draft creates the post and gets the ID of the new post before showing the edit screen, preventing two simultaneous authors from accidentally having the same post ID in the browser's data.

    Andrew Ozz, responsible for TinyMCE integration for WordPress, said:

    This also makes it possible to upload images before saving the first draft, and they will be accurately appended to new posts.

    For those using WordPress 5.0+ with Gutenberg editor, the code snippet below can disable auto draft/save▼

    /**
     * 禁用古腾堡编辑器自动保存 (间隔 3600秒)
     */
    add_filter( 'block_editor_settings', 'cwl_block_editor_settings', 10, 2 );
    function cwl_block_editor_settings( $editor_settings, $post ) {
        $editor_settings['autosaveInterval'] = 3600;
        return $editor_settings;
    }

     

    Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "How to disable auto-save drafts/disable revisions for WordPress articles? , to help you.

    Welcome to share the link of this article:https://www.chenweiliang.com/cwl-1580.html

    Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!

    🔔 Be the first to get the valuable "ChatGPT Content Marketing AI Tool Usage Guide" in the channel top directory! 🌟
    📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
    Share and like if you like!
    Your sharing and likes are our continuous motivation!

     

    Comment

    Your email address will not be published. Required fields * Callout

    scroll to top