'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 = '
  • '; $after_widget = '
  • '; if(empty($before_title)) { $before_title = '

    '; } if(empty($after_title)) { $after_title = '

    '; } echo "\n"; echo $before_widget . "\n" . $before_title . $title . $after_title . "\n" . $after_widget; echo "\n"; } /** * Implementation of admin_menu() action. * Adds configuration menu to wordpress admin panel. * The menu is located under options menu. */ function ajax_comments_spy_admin_menu() { add_options_page(__('Ajax Comments Spy'), __('Ajax Comments Spy'), 8, __FILE__, 'ajax_comments_spy_admin'); } /** * Options menu page callback for Options > Ajax Comments Spy * Admin view for editing ajax comments spy settings * @ingroup forms */ function ajax_comments_spy_admin() { global $plugin_page; // Read existing configurations from the database $options = array( 'spy_type' => get_option('ajax_comments_spy_type'), 'spy_password' => get_option('ajax_comments_spy_password'), 'spy_fetch_items' => get_option('ajax_comments_spy_fetch_items'), 'spy_update' => get_option('ajax_comments_spy_update'), 'spy_widget_title' => get_option('ajax_comments_spy_widget_title'), ); /* * Checks if the form has been posted * Update database to the post values on form submission */ if(isset($_POST['submit'])) { $options = array( 'spy_type' => $_POST['spy_type'], 'spy_password' => $_POST['spy_password'], 'spy_widget_title' => $_POST['spy_widget_title'], ); // Validate update interval if($_POST['spy_fetch_items'] <= 0) { $output .= '

    ' . __('ERROR: Fetch items per request should be greater than 0. Your settings are reverted. Refresh!') . '

    '; } else { $options['spy_fetch_items'] = (int) $_POST['spy_fetch_items']; } // Validate update interval if((int) $_POST['spy_update'] <= 0) { $output .= '

    ' . __('ERROR: Update interval should be greater than 0. Your settings are reverted. Refresh!') . '

    '; } else { $options['spy_update'] = (int) $_POST['spy_update'] * 60; } // Save the posted value to the database foreach($options as $option => $value) { update_option('ajax_comments_' . $option, $value); } // Notify user their settings were saved $output .= '

    '. __('Settings saved.') . '

    '; } $output .= '
    ' . "\n"; $output .= '

    '. __('General Settings') . '

    ' . "\n"; $output .= '
    ' . "\n"; $output .= '

    ' . "\n"; $output .= ' ' . "\n"; $output .= '

    ' . "\n"; $output .= '

    ' . __('(leave blank for no title)') . '

    ' . "\n"; $output .= '

    ' . __(' items per request') . '

    ' . "\n"; $output .= '

    ' . __(' (in minutes)') . '

    ' . "\n"; $output .= '

    ' . __('Permission Settings') . '

    ' . "\n"; $output .= '

    ' . __('Spy comments from password protected pages and posts?') . '

    ' . "\n"; $output .= '

    ' . __('This part of the configuration depends on spy type.') . '

    ' . "\n"; $output .= '

    ' . "\n"; $output .= '

    ' . "\n"; $output .= '

    '."\n"; $output .= '
    ' . "\n"; $output .= '
    ' . "\n"; echo $output; }