Last active
August 29, 2015 14:24
-
-
Save lgedeon/bafe380038e5573e2c36 to your computer and use it in GitHub Desktop.
Quickly kill all spam and pending comments in WordPress (caveat emptor)
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
function kill_pending_and_spam() { | |
$currentScreen = get_current_screen(); | |
if ( 'edit-comments' == $currentScreen->id ) { | |
global $wpdb; | |
$query = $wpdb->prepare( "DELETE FROM $wpdb->comments WHERE comment_approved = 0", '' ); | |
$wpdb->query( $query ); | |
$query = $wpdb->prepare( "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'", '' ); | |
$wpdb->query( $query ); | |
} | |
} | |
add_action( 'current_screen', 'kill_pending_and_spam' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment