WordPress Database Cleaner Version: 1.3 Author: Manish Kumar Agarwal Author URI: http://www.youngtechleads.com Author Emailid: manishkrag@yahoo.co.in/skype:mfsi_manish */ /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ if ( ! defined( 'ABSPATH' ) ) exit; add_action( 'wordpress_spam_cleaner', 'wordpress_spam_cleaner_now' ); function wsc_start_cron( $schedule, $spam_delete_time = null ) { if ( $spam_delete_time != null ) { $time_arr = explode( ':', $spam_delete_time); date_default_timezone_set( 'GMT' ); $time = mktime( $time_arr[0], $time_arr[1], 0); } else { $time = time(); } wp_schedule_event( $time, $schedule, 'wordpress_spam_cleaner' ); } function wordpress_spam_cleaner_now() { global $wpdb; $spam_comments_id_arr = $wpdb->get_col( "SELECT comment_id FROM {$wpdb->comments} WHERE comment_approved = 'spam'" ) ; if ( !empty( $spam_comments_id_arr ) ) { $spam_comments_ids = implode( ', ', array_map('intval', $spam_comments_id_arr) ); $wpdb->query("DELETE FROM {$wpdb->comments} WHERE comment_id IN ( $spam_comments_ids )"); $wpdb->query("DELETE FROM {$wpdb->commentmeta} WHERE comment_id IN ( $spam_comments_ids )"); $wpdb->query( "OPTIMIZE TABLE $wpdb->comments" ); $wpdb->query( "OPTIMIZE TABLE $wpdb->commentmeta" ); } } function show_spam_count() { global $wpdb; echo $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved='spam'" ); } function reschedule_delete_spam() { wp_reschedule_event( (time()+60), 'daily', 'wordpress_spam_cleaner' ); } function scc_admin_css() { wp_enqueue_style( 'scc-style-css', plugin_dir_url( __FILE__ ) . '/spam-comments-cleaner.css' ); } add_action( 'admin_menu', 'wsc_menu' ); function wsc_menu() { $scc_page_hook = add_options_page( 'WordPress Spam Cleaner', 'WordPress Spam Cleaner', 'manage_options', 'wsc-options', 'wsc_options' ); add_action( "admin_print_scripts-$scc_page_hook", 'scc_admin_css' ); } function wsc_options() { if (!current_user_can('manage_options')) wp_die( __('You do not have sufficient permissions to access this page.') ); $nonce = isset( $_REQUEST['_wpnonce'] ) ? $_REQUEST['_wpnonce'] : ''; $valid_nonce = wp_verify_nonce( $nonce, 'wordpress_spam_cleaner' ); if ( $valid_nonce ) { if ( isset( $_POST['delete_spam_now_button'] ) ) wordpress_spam_cleaner_now(); else if ( isset( $_POST['delete_spam_daily_button'] ) ) wsc_start_cron( 'daily' ); else if ( isset( $_POST['stop_deleting_spam_button'] ) ) wsc_stop_schedule(); else if ( isset( $_POST['reschedule_delete_spam_button'] ) ) reschedule_delete_spam(); else if ( isset( $_POST['delete_spam_hourly_button'] ) ) wsc_start_cron( 'hourly' ); else if ( isset( $_POST['delete_spam_twice_button'] ) ) wsc_start_cron( 'twicedaily' ); else if ( isset( $_POST['delete_spam_weekly'] ) ) wsc_start_cron( 'weekly' ); else if ( isset( $_POST['delete_spam_twiceweekly'] ) ) wsc_start_cron( 'twiceweekly' ); else if ( isset( $_POST['delete_spam_monthly'] ) ) wsc_start_cron( 'monthly' ); else if ( isset( $_POST['custom_delete_spam_time'] ) ) wsc_start_cron( 'daily', $_POST['spam_delete_time'] ); } ?>
Rate Now If this plugin really helps you, please do consider providing rating which can help others to find this plugin easily.