'Both', 'ajax_comments_spy_password' => 'false', 'ajax_comments_spy_fetch_items' => '10', 'ajax_comments_spy_update' => '60', 'ajax_comments_spy_widget_title' => 'LIVE Comments', ); foreach($options as $option => $value) { update_option($option, $value); } $sql = 'ALTER TABLE ' . $wpdb->comments . ' ADD acs_approval_date VARCHAR (255) DEFAULT "00000" NOT NULL;'; $wpdb->query($sql); } /** * Implementation of register_deactivation_hook() * Delete options and acs_approval_date column when the plugin is deactivated */ function ajax_comments_spy_deactivate() { global $wpdb; $options = array( 'ajax_comments_spy_type', 'ajax_comments_spy_password', 'ajax_comments_spy_fetch_items', 'ajax_comments_spy_update', 'ajax_comments_spy_widget_title', ); foreach($options as $key => $option) { delete_option($option); } $sql = 'ALTER TABLE ' . $wpdb->comments . ' DROP acs_approval_date;'; $wpdb->query($sql); } /** * Implementation of comment_post() hook * Copies date from comment_date_gmt field to acs_approval_date when comment is posted */ function ajax_comments_spy_comment_post($comment_ID) { global $wpdb; $sql = 'SELECT comment_date_gmt FROM ' . $wpdb->comments . ' WHERE comment_ID = ' . $comment_ID; $comment_date = $wpdb->get_col($sql); $sql = 'UPDATE '. $wpdb->comments . ' SET acs_approval_date = "' . strtotime($comment_date[0]) . '" WHERE comment_ID = "' . $comment_ID . '"'; $wpdb->query($sql); } /** * Implementation of wp_set_comment_status() hook * Sets current date to acs_approval_date when comment is approved * Sets comment_date_gmt to acs_approval_date when comment is on hold */ function ajax_comments_spy_comment_status($comment_ID) { global $wpdb; $comment_status = wp_get_comment_status($comment_ID); if($comment_status == 'unapproved') { $date = date('Y-m-d H:i:s'); $sql = 'UPDATE '. $wpdb->comments . ' SET acs_approval_date = "' . strtotime($date) . '" WHERE comment_ID = "' . $comment_ID . '"'; } elseif($comment_status == 'approved') { $sql = 'SELECT comment_date_gmt FROM ' . $wpdb->comments . ' WHERE comment_ID = ' . $comment_ID; $comment_date = $wpdb->get_col($sql); $sql = 'UPDATE '. $wpdb->comments . ' SET acs_approval_date = "' . strtotime($comment_date[0]) . '" WHERE comment_ID = "' . $comment_ID . '"'; } $query = $wpdb->query($sql); // mail('isharis@gmail.com', $comment_ID . ' ' . $comment_status, $sql . ' ' . $query); debug via email } /** * Implementation of wp_head action. * Includes javascript libraries to the header. */ function ajax_comments_head() { // jQuery library $output = "\n" . '' . "\n"; // Ajax comments spy javascript $output .= '' . "\n"; echo $output; } /** * Implementation of plugins_loaded function * Widgetize the plugin * @ingroup themeable */ function ajax_comments_spy_widget($args) { extract($args); $title = get_option('ajax_comments_spy_widget_title'); $before_widget = '
' . __('ERROR: Fetch items per request should be greater than 0. Your settings are reverted. Refresh!') . '
' . __('ERROR: Update interval should be greater than 0. Your settings are reverted. Refresh!') . '
'. __('Settings saved.') . '