Skip to content

Instantly share code, notes, and snippets.

@lgedeon
Last active August 29, 2015 14:24
Show Gist options
  • Save lgedeon/bafe380038e5573e2c36 to your computer and use it in GitHub Desktop.
Save lgedeon/bafe380038e5573e2c36 to your computer and use it in GitHub Desktop.
Quickly kill all spam and pending comments in WordPress (caveat emptor)
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