Created
January 7, 2016 13:16
-
-
Save lewayotte/2cb20a6dc9021931e069 to your computer and use it in GitHub Desktop.
Automatically remove all revisions with a "bad" word and revert to the last revision without the bad word - used for cleaning up spam injected content.
This file contains 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 | |
function post_revision_menu_page() { | |
add_menu_page( 'Revisions', 'Revisions', 'manage_options', 'revision', 'post_revision_page' ); | |
} | |
//add_action( 'admin_menu', 'post_revision_menu_page' ); | |
function post_revision_page() { | |
/* | |
//Time Check | |
$good_time = strtotime( '2015-02-01 00:00:00' ); | |
$args = array( | |
'numberposts' => -1, | |
'post_type' => array( 'post', 'page' ), | |
); | |
$posts = get_posts( $args ); | |
foreach( $posts as $post ) { | |
$revisions = wp_get_post_revisions( $post->ID ); | |
foreach( $revisions as $revision ) { | |
$revision_time = strtotime( $revision->post_date_gmt ); | |
if ( $revision_time > $good_time ) { | |
wp_delete_post_revision( $revision->ID ); | |
} else { | |
wp_restore_post_revision( $revision->ID ); | |
break; | |
} | |
} | |
} | |
/**/ | |
//Word Check | |
$bad_word = 'display: none'; | |
$args = array( | |
'numberposts' => -1, | |
'post_type' => array( 'post', 'page' ), | |
); | |
$posts = get_posts( $args ); | |
foreach( $posts as $post ) { | |
if ( false !== stripos( $post->post_content, $bad_word ) ) { | |
$revisions = wp_get_post_revisions( $post->ID ); | |
foreach( $revisions as $revision ) { | |
if ( false !== stripos( $revision->post_content, $bad_word ) ) { | |
wp_delete_post_revision( $revision->ID ); | |
} else { | |
wp_restore_post_revision( $revision->ID ); | |
break; | |
} | |
} | |
} | |
} | |
/**/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment