admin管理员组

文章数量:1134247

Is there a way to temporarily disable revisions.... I have noticed that wp_update_post is very slow and creates revisions I don't need. The fix could be to disable revisions before issuing wp_update_post and re-enable the feature once done....

Is there a way to temporarily disable revisions.... I have noticed that wp_update_post is very slow and creates revisions I don't need. The fix could be to disable revisions before issuing wp_update_post and re-enable the feature once done....

Share Improve this question asked Oct 28, 2010 at 16:07 RiccardoRiccardo 9711 gold badge18 silver badges37 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 2

To keep posts updated, I am working with WordPress 4.4 and to enable/disable post revisions programmatically use:

remove_action( 'post_updated', 'wp_save_post_revision' );
$post_id = wp_update_post( $arg );
add_action( 'post_updated', 'wp_save_post_revision' );

Seems this will do the job:

remove_action('pre_post_update', 'wp_save_post_revision');// stop revisions

and

add_action('pre_post_update', 'wp_save_post_revision');//  enable revisions again

You can use the wp_revisions_to_keep filter and return 0 to effectively disable revisions, specify a maximum number of revisions to keep, or return -1 for the default of unlimited revisions. You can add the post parameter to the filter if you would like to adjust for post type.

function my_disable_revisions( $num ) { 
    return 0; 
}
add_filter( 'wp_revisions_to_keep', 'my_disable_revisions' );

Easiest way is to set WP_POST_REVISIONS contant to false, additional information about post revision management

本文标签: phpEnabledisable post revisions programmatically