WordPress as a web app – always auto-save post and meta data

Is is possible to make WordPress auto-save revisiona more often and have the auto-save version always be the most recent version – Like the way google docs works. This would mean the update button is not necessary. you visit a post or custom post type, make your change, then click to another part of the admin, and your changes are always saved. Saving all the custom fields during auto-save would be essential. (maybe we’ll see this in wordpress version 5.0 😉

Here is my problem: i want to insert helpful links in post meta boxes linking to other areas of the admin, but I can’t without putting a big warning beside each link telling the user to save first! any suggestions?

Related posts

Leave a Reply

1 comment

  1. Set custom autosave interval

    Just define it in your wp-config.php file

    // Allow revisions
    define( 'WP_POST_REVISIONS', true);
    // Set number of ms
    define( 'AUTOSAVE_INTERVAL', 300 );
    

    Note that this means that you’ll get a lot of queries and post revisions. Therefore you should also add a max. number of revisions to not fill your posts table with stuff you don’t need.

    // You need to calculate this very precise.
    // If someone needs a long time to write the document, old revisions get trashed
    define( 'WP_POST_REVISIONS', 20 );
    

    Query the ‘revision’ post status

    You’ll have to do this via a custom plugin that hooks into 'plugins_loaded' to intercept the main query posts clauses.

    function intercept_post_clauses( $pieces, $class )
    {
        $pieces['where'] = str_replace( ".post_status = 'publish'", ".post_status = 'revision'", $pieces['where'] );
    
        return $pieces;
    }
    function mod_post_clauses()
    {
        add_filter( 'posts_clauses', 'intercept_post_clauses', 20, 2 );
    }
    add_action( 'plugins_loaded', 'mod_post_clauses' );
    

    Note: This code is not tested, but written directly in here.


    Note: I don’t think that this is an good idea. The problem is that there won’t be any real revision system left. When setting the number of revisions too high, the post table will instantly have hundreds of redundant posts. When setting it too low, there’ll be no real revision left, as you loose your old revision after

    XY ms × # of revisions.

    So if someone stays longer on a post edit screen than the calculated time, the revisions will simply be lost.