• Hi,

    I wanted to disable Post Revisions and Auto Save functionality and used the following code as plugin

    define(‘WP_POST_REVISIONS’, false);
    function disable_autosave() {
    wp_deregister_script(‘autosave’);
    }
    add_action( ‘wp_print_scripts’, ‘disable_autosave’ );

    It works fine for the Admin User. But when I add new posts as Contributor and Author, it creates extra rows in database as Auto-Draft which is very irritating for me.

    Please give me solution for this.

Viewing 2 replies - 1 through 2 (of 2 total)
  • you could try

    define('AUTOSAVE_INTERVAL', 8640000 ); // seconds

    this defines the autosave interval as 100 days.

    Ron Strilaeff

    (@ronstrilaeff)

    Just so everyone is clear… auto-save, post revisions and auto-draft are three separate things. There are way too many posts about this but I just decided to write here since this is a recent thread.

    The wp-config.php defines of

    define( 'AUTOSAVE_INTERVAL', 86400 );  // in seconds: 86400 = 1 day
    define( 'WP_POST_REVISIONS', false); // false means turn off saving of revisions

    takes care of the the first two, but the auto-draft post_status should be ignored and does not need fixing.

    The auto-draft post_status was put in there as background housekeeping for all the random ways a post/page can get edited or attached to before saving as draft or published so nothing gets lost.

    It is your invisible friend.

    The good news is that it looks like wordpress core now has a built in function to daily, automatically remove posts with post_status = ‘auto-draft’ that are over a week old. The code below is in post.php:

    /**
     * Deletes auto-drafts for new posts that are > 7 days old
     *
     * @since 3.4.0
     */
    function wp_delete_auto_drafts() {
    	global $wpdb;
    
    	// Cleanup old auto-drafts more than 7 days old
    	$old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );
    	foreach ( (array) $old_posts as $delete )
    		wp_delete_post( $delete, true ); // Force delete
    }

    Alos, in the file post-new.php there is this code:

    // Schedule auto-draft cleanup
    if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) )
    	wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' );

    I’m not quite sure how they are connected, but I’m betting all those ‘auto-draft’ posts are fairly recent and will get purged with no sweat on our part.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Auto Draft for Contributor, Author, Editor’ is closed to new replies.