Is there a function to set WP_POST_REVISIONS from a plugin instead of having to do it in config.php? I was thinking of doing this:

runkit_constant_redefine( 'WP_POST_REVISIONS', 0 );

but that puts a dependency on runkit being compiled in with PHP which I'm not sure is usual/typical.

I want to turn revisions off completely and I'd like my (narrow use, special purpose) plugin to be as "turnkey" as possible; not requiring other tweaks or manual adjustments.

  • Did you ever solve your problem? – jgraup Dec 11 '15 at 11:37
  • @jgraup I ended up sticking with my delete_revisions function for now. I'm working on another part of the system but will loop back to your suggestion at some point...thanks! – C C Dec 11 '15 at 15:03
  1. Create a no-revs.php
  2. Set the contents to <?php defined('WP_POST_REVISIONS') or define ('WP_POST_REVISIONS', false);
  3. Place it in the Must Use Plugins Folder located at wp-content/mu-plugins.

Be warned; It is recommended that you to have at least 3 post revisions to avoid any loss of data.

  • Doesn't core already define the constant and that logic will never get past the 'or' ? – C C Dec 8 '15 at 2:39
  • It worked when I tested it. I'd give it a shot and let me know if it doesn't work for you. I'm on the latest WP and I can check again w/ the 4.4 release tomorrow. – jgraup Dec 8 '15 at 2:51
  • ok thanks...in the meantime I coded a simple function that cleans up revisions, hooked to 'shutdown'. – C C Dec 8 '15 at 3:01

You can try the wp_revisions_to_keep filter to override the value of the WP_POST_REVISIONS constant:

 * Turn off revisions
add_filter( 'wp_revisions_to_keep', function( $num, $post )
    // Adjust the $num to your needs
    if ( post_type_supports( $post->post_type, 'revisions' ) )
        $num = 0;

    return $num;

}, PHP_INT_MAX, 2 );

If $num is -1 then we keep all revisions. If $num is 0 then we don't keep them.

To turn it off we could also try to remove the revisions support with remove_post_type_support():

 * Remove revisions support for posts
add_action( 'init', function()
    remove_post_type_support( $post_type = 'post', $supports = 'revisions' );
} );
  • very cool, thank you. I'll have to experiment with this. I need it to work on post_type='page' -- and I want to keep the single autosave revision around (in case the user left the editor without saving). The cleanup function I wrote is working this way but it would be good to stop it at the onset rather than clean up, later. I wonder if the hook / function you cited above will leave 'autosave' alone or if they will turn that off, too (since autosave is technically a type of revision) (?) – C C Dec 8 '15 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.