Created
November 5, 2012 13:21
-
-
Save bueltge/4017151 to your computer and use it in GitHub Desktop.
WordPress SE 71248: Delete revisions on post publish
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: WPSE71248 Delete Revions on Publish Posts | |
* Plugin URI: http://wordpress.stackexchange.com/questions/71248/ | |
* Description: | |
* Version: 1.0.0 | |
* Author: Frank Bültge | |
* Author URI: http://bueltge.de | |
* License: GPLv3 | |
*/ | |
! defined( 'ABSPATH' ) and exit; | |
add_action( 'publish_post', 'fb_remove_revisions' ); | |
function fb_remove_revisions( $post_id = FALSE ) { | |
$post_id = (int) $post_id; | |
$revisions = ''; | |
// Get the revisions | |
$revisions = new WP_Query( array( | |
'post_status' => 'inherit', | |
'post_type' => 'revision', | |
'showposts' => -1, | |
'posts_per_page' => -1, | |
'post_parent' => $post_id | |
) ); | |
if ( empty( $revisions ) ) | |
return $post_id; | |
// Remove the revisions the non-core-way | |
global $wpdb; | |
foreach ( $revisions->posts as $revision ) { | |
$query = $wpdb->prepare( | |
" | |
DELETE FROM $wpdb->posts | |
WHERE ID = %d | |
AND post_parent = %d | |
", | |
$revision->ID, | |
$post_id | |
); | |
$wpdb->query( $query ); | |
} | |
return $post_id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment