WordPress.org

Ready to get started?Download WordPress

Forums

how to disable autosave in WP3.3 ? (11 posts)

  1. aljuk
    Member
    Posted 2 years ago #

    I've always used this:

    function disableAutoSave(){
    wp_deregister_script('autosave');
    }
    add_action( 'wp_print_scripts', 'disableAutoSave' );

    but in WP 3.3 (Debug On) it throws:

    Notice: Undefined index: autosave in /{path}/wp-includes/class.wp-scripts.php on line 158

    Notice: Trying to get property of non-object in /{path}/wp-includes/class.wp-scripts.php on line 158

    What's the correct implementation?

  2. Dale Sattler
    Member
    Posted 2 years ago #

    Workaround it with?

    define('AUTOSAVE_INTERVAL', SOME_LONG_TIME_PERIOD);

  3. aljuk
    Member
    Posted 2 years ago #

    Thanks but no. I wish to disable it.

  4. Mark / t31os
    Moderator
    Posted 2 years ago #

    Not sure if this method still works, but it did last time i tried it.

    function hacky_autosave_disabler( $src, $handle ) {
        if( 'autosave' != $handle )
            return $src;
        return '';
    }
    add_filter( 'script_loader_src', 'hacky_autosave_disabler', 10, 2 );

    Simply wipes out the src value for the autosave script, which in essence stops the auto saves(or did last time i tested it in 3.0).

  5. aljuk
    Member
    Posted 2 years ago #

    Many thanks, I'll give it a go.

  6. Egill R. Erlendsson
    Member
    Posted 2 years ago #

    Throw this in your functions.php

    add_action( 'admin_init', 'disable_autosave' );
    function disable_autosave() {
            wp_deregister_script( 'autosave' );
    }
  7. FlashUK
    Member
    Posted 1 year ago #

    Word of warning: You should never disable the 'autosave' function like this.

    Because it will 'break' the preview function for posts.

    Instead edit your wp-config.php to contain the following:

    define('AUTOSAVE_INTERVAL', 86400 ); // seconds (Default: 1 day)

    Put the interval time as long as you want.

  8. Seth Carstens
    Member
    Posted 1 year ago #

    i disagree, if you disable autosave and then click preview it still creates a revision... the purpose for me is to completely eliminate revisions from getting created on my custom post type. but thats Egill for the disable script.

  9. WebDev22
    Member
    Posted 1 year ago #

    @sethmatics - Are you agreeing with Egill's solution? We need to turn off autosave due to users who open up tabs and tabs of the same edit page and causing confusion.

  10. Seth Carstens
    Member
    Posted 1 year ago #

    well, for 1 I thought that the edit lock solves your problem. you may want to research the post edit lock functionality in wordpress.

    next, I am agreeing that Egill's solution properly disables the autosave feature. I am, however, only adding the disable script when on edit pages of my custom post types. FlashUK is correct when he says that disabling autosave also disables the "preview" functionality, so if you need to be able to preview your changes before you publish, then you need to define a long term interval as he suggests.

    The the answer is, depends on what you need. Sounds like FlashUK's solution is better for you.

  11. WebDev22
    Member
    Posted 1 year ago #

    Thanks. It worked.

Topic Closed

This topic has been closed to new replies.

About this Topic