function spam_comment($comment_id, $remote_addr, $reason)
 {
     wp_spam_comment($comment_id);
     $blacklist = get_option("blacklist_keys");
     update_option("blacklist_keys", $blacklist . "\n" . $remote_addr);
     mail(get_option("admin_email"), "spam " . home_url(), $reason . "\n" . $_POST['email'] . "\n" . $_POST['url'] . "\n" . $_POST['comment']);
     wp_die($reason);
 }
示例#2
0
function spec_comment_spam_comment($comment_id)
{
    wp_spam_comment($comment_id);
}
 public static function cron_recheck()
 {
     global $wpdb;
     $api_key = self::get_api_key();
     $status = self::verify_key($api_key);
     if (get_option('akismet_alert_code') || $status == 'invalid') {
         // since there is currently a problem with the key, reschedule a check for 6 hours hence
         wp_schedule_single_event(time() + 21600, 'akismet_schedule_cron_recheck');
         do_action('akismet_scheduled_recheck', 'key-problem-' . get_option('akismet_alert_code') . '-' . $status);
         return false;
     }
     delete_option('akismet_available_servers');
     $comment_errors = $wpdb->get_col("SELECT comment_id FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error'\tLIMIT 100");
     load_plugin_textdomain('akismet');
     foreach ((array) $comment_errors as $comment_id) {
         // if the comment no longer exists, or is too old, remove the meta entry from the queue to avoid getting stuck
         $comment = get_comment($comment_id);
         if (!$comment || strtotime($comment->comment_date_gmt) < strtotime("-15 days")) {
             delete_comment_meta($comment_id, 'akismet_error');
             delete_comment_meta($comment_id, 'akismet_delayed_moderation_email');
             continue;
         }
         add_comment_meta($comment_id, 'akismet_rechecking', true);
         $status = self::check_db_comment($comment_id, 'retry');
         $event = '';
         if ($status == 'true') {
             $event = 'cron-retry-spam';
         } elseif ($status == 'false') {
             $event = 'cron-retry-ham';
         }
         // If we got back a legit response then update the comment history
         // other wise just bail now and try again later.  No point in
         // re-trying all the comments once we hit one failure.
         if (!empty($event)) {
             delete_comment_meta($comment_id, 'akismet_error');
             self::update_comment_history($comment_id, '', $event);
             update_comment_meta($comment_id, 'akismet_result', $status);
             // make sure the comment status is still pending.  if it isn't, that means the user has already moved it elsewhere.
             $comment = get_comment($comment_id);
             if ($comment && 'unapproved' == wp_get_comment_status($comment_id)) {
                 if ($status == 'true') {
                     wp_spam_comment($comment_id);
                 } elseif ($status == 'false') {
                     // comment is good, but it's still in the pending queue.  depending on the moderation settings
                     // we may need to change it to approved.
                     if (check_comment($comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent, $comment->comment_type)) {
                         wp_set_comment_status($comment_id, 1);
                     } else {
                         if (get_comment_meta($comment_id, 'akismet_delayed_moderation_email', true)) {
                             wp_notify_moderator($comment_id);
                         }
                     }
                 }
             }
             delete_comment_meta($comment_id, 'akismet_delayed_moderation_email');
         } else {
             // If this comment has been pending moderation for longer than MAX_DELAY_BEFORE_MODERATION_EMAIL,
             // send a moderation email now.
             if (intval(gmdate('U')) - strtotime($comment->comment_date_gmt) < self::MAX_DELAY_BEFORE_MODERATION_EMAIL) {
                 delete_comment_meta($comment_id, 'akismet_delayed_moderation_email');
                 wp_notify_moderator($comment_id);
             }
             delete_comment_meta($comment_id, 'akismet_rechecking');
             wp_schedule_single_event(time() + 1200, 'akismet_schedule_cron_recheck');
             do_action('akismet_scheduled_recheck', 'check-db-comment-' . $status);
             return;
         }
         delete_comment_meta($comment_id, 'akismet_rechecking');
     }
     $remaining = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error'");
     if ($remaining && !wp_next_scheduled('akismet_schedule_cron_recheck')) {
         wp_schedule_single_event(time() + 1200, 'akismet_schedule_cron_recheck');
         do_action('akismet_scheduled_recheck', 'remaining');
     }
 }
示例#4
0
	switch ( $action ) {
		case 'deletecomment' :
			wp_delete_comment( $comment_id );
			$redir = add_query_arg( array('deleted' => '1'), $redir );
			break;
		case 'trashcomment' :
			wp_trash_comment($comment_id);
			$redir = add_query_arg( array('trashed' => '1', 'ids' => $comment_id), $redir );
			break;
		case 'untrashcomment' :
			wp_untrash_comment($comment_id);
			$redir = add_query_arg( array('untrashed' => '1'), $redir );
			break;
		case 'spamcomment' :
			wp_spam_comment($comment_id);
			$redir = add_query_arg( array('spammed' => '1', 'ids' => $comment_id), $redir );
			break;
		case 'unspamcomment' :
			wp_unspam_comment($comment_id);
			$redir = add_query_arg( array('unspammed' => '1'), $redir );
			break;
		case 'approvecomment' :
			wp_set_comment_status( $comment_id, 'approve' );
			$redir = add_query_arg( array( 'approved' => 1 ), $redir );
			break;
		case 'unapprovecomment' :
			wp_set_comment_status( $comment_id, 'hold' );
			$redir = add_query_arg( array( 'unapproved' => 1 ), $redir );
			break;
	}
 public function test_wp_spam_comment()
 {
     wp_spam_comment($this->comment->comment_ID);
     $this->client->do_sync();
     $this->assertEquals(0, $this->server_replica_storage->comment_count('approve'));
     $this->assertEquals(1, $this->server_replica_storage->comment_count('spam'));
 }
 function update_comment($path, $blog_id, $comment_id)
 {
     $comment = get_comment($comment_id);
     if (!$comment || is_wp_error($comment)) {
         return new WP_Error('unknown_comment', 'Unknown comment', 404);
     }
     if (!current_user_can('edit_comment', $comment->comment_ID)) {
         return new WP_Error('unauthorized', 'User cannot edit comment', 403);
     }
     $args = $this->query_args();
     $input = $this->input(false);
     if (!is_array($input) || !$input) {
         return new WP_Error('invalid_input', 'Invalid request input', 400);
     }
     $update = array();
     foreach ($input as $key => $value) {
         $update["comment_{$key}"] = $value;
     }
     $comment_status = wp_get_comment_status($comment->comment_ID);
     if ($comment_status !== $update['status'] && !current_user_can('moderate_comments')) {
         return new WP_Error('unauthorized', 'User cannot moderate comments', 403);
     }
     if (isset($update['comment_status'])) {
         switch ($update['comment_status']) {
             case 'approved':
                 if ('approve' !== $comment_status) {
                     wp_set_comment_status($comment->comment_ID, 'approve');
                 }
                 break;
             case 'unapproved':
                 if ('hold' !== $comment_status) {
                     wp_set_comment_status($comment->comment_ID, 'hold');
                 }
                 break;
             case 'spam':
                 if ('spam' !== $comment_status) {
                     wp_spam_comment($comment->comment_ID);
                 }
                 break;
             case 'unspam':
                 if ('spam' === $comment_status) {
                     wp_unspam_comment($comment->comment_ID);
                 }
                 break;
             case 'trash':
                 if (!EMPTY_TRASH_DAYS) {
                     return new WP_Error('trash_disabled', 'Cannot trash comment', 403);
                 }
                 if ('trash' !== $comment_status) {
                     wp_trash_comment($comment_id);
                 }
                 break;
             case 'untrash':
                 if ('trash' === $comment_status) {
                     wp_untrash_comment($comment->comment_ID);
                 }
                 break;
             default:
                 $update['comment_approved'] = 1;
                 break;
         }
         unset($update['comment_status']);
     }
     if (!empty($update)) {
         $update['comment_ID'] = $comment->comment_ID;
         wp_update_comment(add_magic_quotes($update));
     }
     $return = $this->get_comment($comment->comment_ID, $args['context']);
     if (!$return || is_wp_error($return)) {
         return $return;
     }
     do_action('wpcom_json_api_objects', 'comments');
     return $return;
 }
示例#7
0
 $status = wp_get_comment_status($comment->comment_ID);
 if (isset($_POST['trash']) && 1 == $_POST['trash']) {
     if ('trash' == $status) {
         die((string) time());
     }
     $r = wp_trash_comment($comment->comment_ID);
 } elseif (isset($_POST['untrash']) && 1 == $_POST['untrash']) {
     if ('trash' != $status) {
         die((string) time());
     }
     $r = wp_untrash_comment($comment->comment_ID);
 } elseif (isset($_POST['spam']) && 1 == $_POST['spam']) {
     if ('spam' == $status) {
         die((string) time());
     }
     $r = wp_spam_comment($comment->comment_ID);
 } elseif (isset($_POST['unspam']) && 1 == $_POST['unspam']) {
     if ('spam' != $status) {
         die((string) time());
     }
     $r = wp_unspam_comment($comment->comment_ID);
 } elseif (isset($_POST['delete']) && 1 == $_POST['delete']) {
     $r = wp_delete_comment($comment->comment_ID);
 } else {
     die('-1');
 }
 if ($r) {
     // Decide if we need to send back '1' or a more complicated response including page links and comment counts
     _wp_ajax_delete_comment_response($comment->comment_ID);
 }
 die('0');
示例#8
0
 $redir = remove_query_arg(array('spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids', 'approved', 'unapproved'), $redir);
 switch ($action) {
     case 'deletecomment':
         wp_delete_comment($comment);
         $redir = add_query_arg(array('deleted' => '1'), $redir);
         break;
     case 'trashcomment':
         wp_trash_comment($comment);
         $redir = add_query_arg(array('trashed' => '1', 'ids' => $comment_id), $redir);
         break;
     case 'untrashcomment':
         wp_untrash_comment($comment);
         $redir = add_query_arg(array('untrashed' => '1'), $redir);
         break;
     case 'spamcomment':
         wp_spam_comment($comment);
         $redir = add_query_arg(array('spammed' => '1', 'ids' => $comment_id), $redir);
         break;
     case 'unspamcomment':
         wp_unspam_comment($comment);
         $redir = add_query_arg(array('unspammed' => '1'), $redir);
         break;
     case 'approvecomment':
         wp_set_comment_status($comment, 'approve');
         $redir = add_query_arg(array('approved' => 1), $redir);
         break;
     case 'unapprovecomment':
         wp_set_comment_status($comment, 'hold');
         $redir = add_query_arg(array('unapproved' => 1), $redir);
         break;
 }
示例#9
0
 /**
  * Handles group's moderating actions about ideas
  *
  * @package WP Idea Stream
  * @subpackage buddypress/groups
  *
  * @since  2.0.0
  *
  * @uses bp_is_group() to check a group is displayed
  * @uses bp_is_current_action() to check the group's current action
  * @uses wp_idea_stream_root_slug() to get the IdeaStream root slug
  * @uses wp_idea_stream_action_get_slug() to get the IdeaStream's action slug
  * @uses bp_action_variable() to get a specific action variable
  * @uses groups_get_current_group() to get the current group's object
  * @uses WP_Idea_Stream_Group->group_ideas_archive_url() to get the group's IdeaStream archive page
  * @uses check_admin_referer() to check the request was made on the site
  * @uses wp_idea_stream_user_can() to check user's capability
  * @uses WP_Idea_Stream_Group->remove_from_group() to remove one or more ideas from a group
  * @uses wp_get_referer() to get the url the user came from
  * @uses wp_spam_comment() to spam a comment made on an idea
  * @uses wp_trash_comment() to trash a comment made on an idea
  * @uses wp_idea_stream_add_message() to add a feedback to display to the user once redirected
  * @uses bp_core_redirect() to safely redirect the user
  */
 public function group_actions()
 {
     if (!bp_is_group()) {
         return;
     }
     $group = groups_get_current_group();
     // This part is to catch the group status before it might be updated
     if ('group-settings' == bp_get_group_current_admin_tab() && bp_is_item_admin()) {
         $this->group_update_ideas_stati = $group;
         if (!empty($_POST['group-status']) && in_array($_POST['group-status'], array('public', 'private', 'hidden'))) {
             $this->group_update_ideas_stati->new_status = $_POST['group-status'];
         }
     }
     // This part is for ideastream moderation actions.
     if (!(bp_is_current_action(wp_idea_stream_root_slug()) && wp_idea_stream_action_get_slug() == bp_action_variable(0) && bp_action_variable(1))) {
         return;
     }
     $feedback = array();
     // Default to group's home
     $redirect = $this->group_ideas_archive_url($group, true);
     switch (bp_action_variable(1)) {
         case 'remove-idea':
             check_admin_referer('group-remove-idea');
             if (!bp_action_variable(2)) {
                 $feedback['type'] = 'error';
                 $feedback['content'] = __('Removing the idea failed.', 'wp-idea-stream');
                 break;
             }
             $idea_id = absint(bp_action_variable(2));
             if (!wp_idea_stream_user_can('remove_group_ideas')) {
                 $feedback['type'] = 'error';
                 $feedback['content'] = __('Removing the idea failed. You do not have the capability to remove ideas.', 'wp-idea-stream');
                 break;
             }
             if (false === $this->remove_from_group($idea_id, $group->id)) {
                 $feedback['type'] = 'error';
                 $feedback['content'] = __('Removing the idea failed.', 'wp-idea-stream');
                 $redirect = wp_get_referer();
             } else {
                 $feedback['type'] = 'success';
                 $feedback['content'] = __('The idea was successfully removed.', 'wp-idea-stream');
             }
             break;
         case 'spam-comment':
             check_admin_referer('group-spam-comment');
             $redirect = wp_get_referer();
             if (!bp_action_variable(2)) {
                 $feedback['type'] = 'error';
                 $feedback['content'] = __('Spamming the comment failed.', 'wp-idea-stream');
                 break;
             }
             $comment_id = absint(bp_action_variable(2));
             if (!wp_idea_stream_user_can('spam_group_idea_comments')) {
                 $feedback['type'] = 'error';
                 $feedback['content'] = __('Spamming the comment failed. You do not have the capability to spam comments.', 'wp-idea-stream');
                 break;
             }
             if (false === wp_spam_comment($comment_id)) {
                 $feedback['type'] = 'error';
                 $feedback['content'] = __('Spamming the comment failed.', 'wp-idea-stream');
             } else {
                 $feedback['type'] = 'success';
                 $feedback['content'] = __('The comment was successfully marked as spam.', 'wp-idea-stream');
             }
             break;
         case 'trash-comment':
             check_admin_referer('group-trash-comment');
             $redirect = wp_get_referer();
             if (!bp_action_variable(2)) {
                 $feedback['type'] = 'error';
                 $feedback['content'] = __('Deleting the comment failed.', 'wp-idea-stream');
                 break;
             }
             $comment_id = absint(bp_action_variable(2));
             if (!wp_idea_stream_user_can('trash_group_idea_comments')) {
                 $feedback['type'] = 'error';
                 $feedback['content'] = __('Deleting the comment failed. You do not have the capability to delete comments.', 'wp-idea-stream');
                 break;
             }
             if (false === wp_trash_comment($comment_id)) {
                 $feedback['type'] = 'error';
                 $feedback['content'] = __('Deleting the comment failed.', 'wp-idea-stream');
             } else {
                 $feedback['type'] = 'success';
                 $feedback['content'] = __('The comment was successfully deleted.', 'wp-idea-stream');
             }
             break;
     }
     if (!empty($feedback)) {
         wp_idea_stream_add_message($feedback);
         bp_core_redirect($redirect);
     }
 }
示例#10
0
 private function spam_comment($id)
 {
     return wp_spam_comment($id);
 }
示例#11
0
 public function test_unspammed_comment_should_invalidate_query_cache()
 {
     global $wpdb;
     $c = self::factory()->comment->create(array('comment_post_ID' => self::$post_id, 'comment_approved' => '1'));
     wp_spam_comment($c);
     $q = new WP_Comment_Query(array('post_id' => self::$post_id, 'fields' => 'ids'));
     wp_unspam_comment($c);
     $num_queries = $wpdb->num_queries;
     $q = new WP_Comment_Query(array('post_id' => self::$post_id, 'fields' => 'ids'));
     $num_queries++;
     $this->assertSame($num_queries, $wpdb->num_queries);
     $this->assertEqualSets(array($c), $q->comments);
 }
 private function bulk_comments($doaction, $comment_ids)
 {
     global $wpdb;
     $approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0;
     foreach ((array) $comment_ids as $comment_id) {
         // Check the permissions on each
         $_post_id = (int) $wpdb->get_var($wpdb->prepare("SELECT comment_post_ID FROM {$wpdb->comments} WHERE comment_ID = %d", $comment_id));
         if (!current_user_can('edit_post', $_post_id)) {
             continue;
         }
         switch ($doaction) {
             case 'approve':
                 wp_set_comment_status($comment_id, 'approve');
                 $approved++;
                 break;
             case 'unapprove':
                 wp_set_comment_status($comment_id, 'hold');
                 $unapproved++;
                 break;
             case 'spam':
             case 'markspam':
                 if (function_exists('wp_spam_coment')) {
                     wp_spam_comment($comment_id);
                 } else {
                     wp_set_comment_status($comment_id, 'spam');
                 }
                 $spammed++;
                 break;
             case 'unspam':
                 if (function_exists('wp_unspam_comment')) {
                     wp_unspam_comment($comment_id);
                     $unspammed++;
                 }
                 break;
             case 'trash':
                 if (function_exists('wp_trash_comment')) {
                     wp_trash_comment($comment_id);
                     $trashed++;
                 }
                 break;
             case 'untrash':
                 if (function_exists('wp_untrash_comment')) {
                     wp_untrash_comment($comment_id);
                     $untrashed++;
                 }
                 break;
             case 'delete':
                 if (function_exists('wp_delete_comment')) {
                     wp_delete_comment($comment_id);
                 } else {
                     wp_set_comment_status($comment_id, 'delete');
                 }
                 $deleted++;
                 break;
         }
     }
     $redirect_to = $this->referer;
     if (false === strpos($redirect_to, 'edit-comments.php')) {
         $redirect_to = 'edit-comments.php';
     }
     if ($approved) {
         $redirect_to = add_query_arg('approved', $approved, $redirect_to);
     }
     if ($unapproved) {
         $redirect_to = add_query_arg('unapproved', $unapproved, $redirect_to);
     }
     if ($spammed) {
         $redirect_to = add_query_arg('spammed', $spammed, $redirect_to);
     }
     if ($unspammed) {
         $redirect_to = add_query_arg('unspammed', $unspammed, $redirect_to);
     }
     if ($trashed) {
         $redirect_to = add_query_arg('trashed', $trashed, $redirect_to);
     }
     if ($untrashed) {
         $redirect_to = add_query_arg('untrashed', $untrashed, $redirect_to);
     }
     if ($deleted) {
         $redirect_to = add_query_arg('deleted', $deleted, $redirect_to);
     }
     if ($trashed || $spammed) {
         $redirect_to = add_query_arg('ids', join(',', $comment_ids), $redirect_to);
     }
     if ($this->post_id > 0) {
         $redirect_to = add_query_arg('p', $this->post_id, $redirect_to);
     }
     if (isset($_REQUEST['apage'])) {
         $redirect_to = add_query_arg('apage', abs(intval($_REQUEST['apage'])), $redirect_to);
     }
     if (!empty($_REQUEST['mode'])) {
         $redirect_to = add_query_arg('mode', $_REQUEST['mode'], $redirect_to);
     }
     if (!empty($_REQUEST['comment_status'])) {
         $redirect_to = add_query_arg('comment_status', $_REQUEST['comment_status'], $redirect_to);
     }
     if (!empty($_REQUEST['s'])) {
         $redirect_to = add_query_arg('s', $_REQUEST['s'], $redirect_to);
     }
     $this->admin->redirect($redirect_to);
 }
/**
 * Review Rating comment ajax actions.
 *
 * @since 1.0.0
 * @package GeoDirectory_Review_Rating_Manager
 *
 * @param $request
 * @return bool
 */
function geodir_reviewrating_comment_action($request)
{
    global $wpdb;
    $comment_ids = array();
    if (isset($request['comment_ids']) && $request['comment_ids'] != '') {
        $comment_ids = explode(',', $request['comment_ids']);
    }
    if (!empty($comment_ids) && $request['comment_ids'] != '') {
        if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'geodir_review_action_nonce')) {
            return false;
        }
        foreach ($comment_ids as $comment_id) {
            if ($comment_id != '') {
                switch ($request['comment_action']) {
                    case 'deletecomment':
                        wp_delete_comment($comment_id);
                        break;
                    case 'trashcomment':
                        wp_trash_comment($comment_id);
                        break;
                    case 'untrashcomment':
                        wp_untrash_comment($comment_id);
                        break;
                    case 'spamcomment':
                        wp_spam_comment($comment_id);
                        break;
                    case 'unspamcomment':
                        wp_unspam_comment($comment_id);
                        break;
                    case 'approvecomment':
                        wp_set_comment_status($comment_id, 'approve');
                        break;
                    case 'unapprovecomment':
                        wp_set_comment_status($comment_id, 'hold');
                        break;
                }
            }
        }
        if (isset($request['geodir_comment_search'])) {
            $geodir_commentsearch = $request['geodir_comment_search'];
        }
        if (isset($request['geodir_comment_posttype'])) {
            $post_type = $request['geodir_comment_posttype'];
        }
        $status = $request['subtab'];
        $orderby = 'comment_date_gmt';
        $order = 'DESC';
        if (isset($request['geodir_comment_sort'])) {
            if ($request['geodir_comment_sort'] == 'oldest') {
                $orderby = 'comment_date_gmt';
                $order = 'ASC';
            }
        }
        if (isset($request['paged']) && $request['paged'] != '') {
            $paged = $request['paged'];
        } else {
            $paged = 1;
        }
        $show_post = $request['show_post'];
        $defaults = array('paged' => $paged, 'show_post' => $show_post, 'orderby' => $orderby, 'order' => $order, 'post_type' => $post_type, 'comment_approved' => $status, 'user_id' => '', 'search' => $geodir_commentsearch);
        $comments = geodir_reviewrating_get_comments($defaults);
        geodir_reviewrating_show_comments($comments['comments']);
    }
    if (isset($request['gd_tab_head'])) {
        geodir_reviewrating_show_tab_head($request['gd_tab_head']);
    }
    exit;
}
 /**
  * @ticket 11334
  */
 public function test_cache_should_be_invalidated_when_comment_is_spammed()
 {
     $p = self::factory()->post->create();
     $c = self::factory()->comment->create(array('comment_post_ID' => $p));
     // Prime cache.
     $page_1 = get_page_of_comment($c, array('per_page' => 3));
     // Spam comment.
     wp_spam_comment($c);
     $this->assertFalse(wp_cache_get($c, 'comment_pages'));
 }
/**
 * Updates the blog comment when the associated activity comment is edited.
 *
 * @since 2.0.0
 *
 * @param BP_Activity_Activity $activity The activity object.
 */
function bp_blogs_sync_activity_edit_to_post_comment(BP_Activity_Activity $activity)
{
    // This is a new entry, so stop!
    // We only want edits!
    if (empty($activity->id) || bp_disable_blogforum_comments()) {
        return;
    }
    // fetch parent activity item
    $parent_activity = new BP_Activity_Activity($activity->item_id);
    // if parent activity isn't a post type having the buddypress-activity support for comments, stop now!
    if (!bp_activity_type_supports($parent_activity->type, 'post-type-comment-tracking')) {
        return;
    }
    $post_type = bp_activity_post_type_get_tracking_arg($parent_activity->type, 'post_type');
    // No associated post type for this activity comment, stop.
    if (!$post_type) {
        return;
    }
    // Try to see if a corresponding blog comment exists.
    $post_comment_id = bp_activity_get_meta($activity->id, "bp_blogs_{$post_type}_comment_id");
    if (empty($post_comment_id)) {
        return;
    }
    // Handle multisite.
    switch_to_blog($parent_activity->item_id);
    // Get the comment status
    $post_comment_status = wp_get_comment_status($post_comment_id);
    $old_comment_status = $post_comment_status;
    // No need to edit the activity, as it's the activity who's updating the comment
    remove_action('transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10, 3);
    remove_action('bp_activity_post_type_comment', 'bp_blogs_comment_sync_activity_comment', 10, 4);
    if (1 === (int) $activity->is_spam && 'spam' !== $post_comment_status) {
        wp_spam_comment($post_comment_id);
    } elseif (!$activity->is_spam) {
        if ('spam' === $post_comment_status) {
            wp_unspam_comment($post_comment_id);
        } elseif ('trash' === $post_comment_status) {
            wp_untrash_comment($post_comment_id);
        } else {
            // Update the blog post comment.
            wp_update_comment(array('comment_ID' => $post_comment_id, 'comment_content' => $activity->content));
        }
    }
    // Restore actions
    add_action('transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10, 3);
    add_action('bp_activity_post_type_comment', 'bp_blogs_comment_sync_activity_comment', 10, 4);
    restore_current_blog();
}
 /**
  * approve/unapprove/spam/unspam a comment via an admin-ajax.php endpoint
  */
 public function ajax_comment_status()
 {
     $comment_id = absint($_GET['comment_id']);
     $direction = $_GET['direction'];
     if (!current_user_can('edit_comment', $comment_id)) {
         return wp_send_json_error();
     }
     // END if
     if (!check_ajax_referer('bsocial-comment-status', 'bsocial-nonce')) {
         return wp_send_json_error();
     }
     // END if
     $allowed_directions = array('approve', 'unapprove', 'spam', 'unspam', 'trash', 'untrash');
     if (!in_array($direction, $allowed_directions)) {
         return wp_send_json_error();
     }
     // END if
     if (!($comment = get_comment($comment_id))) {
         return wp_send_json_error();
     }
     //end if
     $data = array();
     switch ($direction) {
         case 'approve':
             $data = array('success' => wp_set_comment_status($comment->comment_ID, 'approve'), 'link' => $this->get_status_link($comment->comment_ID, 'approve'), 'state' => 'approved');
             break;
         case 'unapprove':
             $data = array('success' => wp_set_comment_status($comment->comment_ID, 'hold'), 'link' => $this->get_status_link($comment->comment_ID, 'approve'), 'state' => 'unapproved');
             break;
         case 'spam':
             $data = array('success' => wp_spam_comment($comment->comment_ID), 'link' => $this->get_status_link($comment->comment_ID, 'spam'), 'state' => 'spammed');
             break;
         case 'unspam':
             $data = array('success' => wp_unspam_comment($comment->comment_ID), 'link' => $this->get_status_link($comment->comment_ID, 'spam'), 'state' => 'unspammed');
             break;
         case 'trash':
             $data = array('success' => wp_trash_comment($comment->comment_ID), 'link' => $this->get_status_link($comment->comment_ID, 'trash'), 'state' => 'trashed');
             break;
         case 'untrash':
             $data = array('success' => wp_untrash_comment($comment->comment_ID), 'link' => $this->get_status_link($comment->comment_ID, 'trash'), 'state' => 'untrashed');
             break;
     }
     // END switch
     wp_send_json($data);
     die;
 }
/**
 * Check if the honeypot field has been filled
 */
function wdhb_honeypot_check_field($comment_id, $comment_approved)
{
    if (isset($_POST['wdhb_honeypot']) && $_POST['wdhb_honeypot'] !== "") {
        wp_spam_comment($comment_id);
    }
}
 /**
  * Set the comment_status of a given comment object when creating or updating a comment.
  *
  * @param string|int $new_status
  * @param object     $comment
  * @return boolean   $changed
  */
 protected function handle_status_param($new_status, $comment)
 {
     $old_status = wp_get_comment_status($comment->comment_ID);
     if ($new_status === $old_status) {
         return false;
     }
     switch ($new_status) {
         case 'approved':
         case 'approve':
         case '1':
             $changed = wp_set_comment_status($comment->comment_ID, 'approve');
             break;
         case 'hold':
         case '0':
             $changed = wp_set_comment_status($comment->comment_ID, 'hold');
             break;
         case 'spam':
             $changed = wp_spam_comment($comment->comment_ID);
             break;
         case 'unspam':
             $changed = wp_unspam_comment($comment->comment_ID);
             break;
         case 'trash':
             $changed = wp_trash_comment($comment->comment_ID);
             break;
         case 'untrash':
             $changed = wp_untrash_comment($comment->comment_ID);
             break;
         default:
             $changed = false;
             break;
     }
     return $changed;
 }
 public function test_wp_count_comments_cache()
 {
     $post_id = self::factory()->post->create(array('post_status' => 'publish'));
     $comment_id = self::factory()->comment->create(array('comment_approved' => '1', 'comment_post_ID' => $post_id));
     $count1 = wp_count_comments($post_id);
     $this->assertEquals(1, $count1->approved);
     $this->assertEquals(0, $count1->moderated);
     $this->assertEquals(0, $count1->spam);
     $this->assertEquals(0, $count1->trash);
     $this->assertEquals(0, $count1->{'post-trashed'});
     $this->assertEquals(1, $count1->total_comments);
     $this->assertEquals(1, $count1->all);
     $all_count1 = wp_count_comments();
     $this->assertEquals(1, $all_count1->approved);
     $this->assertEquals(0, $all_count1->moderated);
     $this->assertEquals(0, $all_count1->spam);
     $this->assertEquals(0, $all_count1->trash);
     $this->assertEquals(0, $all_count1->{'post-trashed'});
     $this->assertEquals(1, $all_count1->total_comments);
     $this->assertEquals(1, $all_count1->all);
     wp_spam_comment($comment_id);
     $count2 = wp_count_comments($post_id);
     $this->assertEquals(0, $count2->approved);
     $this->assertEquals(0, $count2->moderated);
     $this->assertEquals(1, $count2->spam);
     $this->assertEquals(0, $count2->trash);
     $this->assertEquals(0, $count2->{'post-trashed'});
     $this->assertEquals(1, $count2->total_comments);
     $this->assertEquals(0, $count2->all);
     $all_count2 = wp_count_comments();
     $this->assertEquals(0, $all_count2->approved);
     $this->assertEquals(0, $all_count2->moderated);
     $this->assertEquals(1, $all_count2->spam);
     $this->assertEquals(0, $all_count2->trash);
     $this->assertEquals(0, $all_count2->{'post-trashed'});
     $this->assertEquals(1, $all_count2->total_comments);
     $this->assertEquals(0, $all_count2->all);
     wp_trash_comment($comment_id);
     $count3 = wp_count_comments($post_id);
     $this->assertEquals(0, $count3->approved);
     $this->assertEquals(0, $count3->moderated);
     $this->assertEquals(0, $count3->spam);
     $this->assertEquals(1, $count3->trash);
     $this->assertEquals(0, $count3->{'post-trashed'});
     $this->assertEquals(0, $count3->total_comments);
     $this->assertEquals(0, $count3->all);
     $all_count3 = wp_count_comments();
     $this->assertEquals(0, $all_count3->approved);
     $this->assertEquals(0, $all_count3->moderated);
     $this->assertEquals(0, $all_count3->spam);
     $this->assertEquals(1, $all_count3->trash);
     $this->assertEquals(0, $all_count3->{'post-trashed'});
     $this->assertEquals(0, $all_count3->total_comments);
     $this->assertEquals(0, $all_count3->all);
     wp_untrash_comment($comment_id);
     $count4 = wp_count_comments($post_id);
     $this->assertEquals(0, $count4->approved);
     $this->assertEquals(0, $count4->moderated);
     $this->assertEquals(1, $count4->spam);
     $this->assertEquals(0, $count4->trash);
     $this->assertEquals(0, $count4->{'post-trashed'});
     $this->assertEquals(1, $count4->total_comments);
     $this->assertEquals(0, $count4->all);
     $all_count4 = wp_count_comments();
     $this->assertEquals(0, $all_count4->approved);
     $this->assertEquals(0, $all_count4->moderated);
     $this->assertEquals(1, $all_count4->spam);
     $this->assertEquals(0, $all_count4->trash);
     $this->assertEquals(0, $all_count4->{'post-trashed'});
     $this->assertEquals(1, $all_count4->total_comments);
     $this->assertEquals(0, $all_count4->all);
 }
 private function delete_comment($action)
 {
     $comment_id = intval($_REQUEST['c']);
     check_admin_referer('delete-comment_' . $comment_id);
     $noredir = isset($_REQUEST['noredir']);
     if (!($comment = get_comment($comment_id))) {
         $this->base->ks_die(__('Oops, no comment with this ID.') . sprintf(' <a href="%s">' . __('Go back') . '</a>!', 'edit-comments.php'), '', false);
         //exit;
     }
     if (!current_user_can('edit_post', $comment->comment_post_ID)) {
         $this->base->ks_die(__('You are not allowed to edit comments on this post.'));
     }
     $redir = $this->referer;
     if (empty($redir) || $noredir || false !== strpos($redir, 'comment.php')) {
         $redir = 'edit-comments.php';
     }
     switch ($action) {
         case 'deletecomment':
             wp_delete_comment($comment_id);
             $redir = add_query_arg(array('deleted' => 1), $redir);
             break;
         case 'trashcomment':
             if (function_exists('wp_trash_comment')) {
                 wp_trash_comment($comment_id);
                 $redir = add_query_arg(array('trashed' => '1', 'ids' => $comment_id), $redir);
             }
             break;
         case 'untrashcomment':
             if (function_exists('wp_untrash_comment')) {
                 wp_untrash_comment($comment_id);
                 $redir = add_query_arg(array('untrashed' => '1'), $redir);
             }
             break;
         case 'spamcomment':
             if (function_exists('wp_spam_comment')) {
                 wp_spam_comment($comment_id);
             } else {
                 wp_set_comment_status($comment_id, 'spam');
             }
             $redir = add_query_arg(array('spammed' => '1', 'ids' => $comment_id), $redir);
             break;
         case 'unspamcomment':
             if (function_exists('wp_spam_comment')) {
                 wp_unspam_comment($comment_id);
                 $redir = add_query_arg(array('unspammed' => '1'), $redir);
             }
             break;
     }
     $this->admin->redirect($redir);
     exit;
 }
示例#21
0
/**
 * Process a spammed user
 *
 * @package WP Idea Stream
 * @subpackage buddypress/functions
 *
 * @since  2.0.0
 *
 * @param  int $user_id the user ID
 * @uses   add_filter() to avoid ideas to be permanently deleted
 * @uses   wp_idea_stream_users_delete_user_data() to remove user's IdeaStream Data.
 * @uses   get_comments() to get user's comment
 * @uses   wp_idea_stream_get_post_type() to get the ideas post type identifier
 * @uses   wp_spam_comment() to spam user's comments
 */
function wp_idea_stream_buddypress_spam_user($user_id = 0)
{
    if (empty($user_id)) {
        return;
    }
    // Let's trash ideas instead of completely removed them.
    add_filter('wp_idea_stream_users_delete_user_force_delete', '__return_false');
    // Remove IdeaStream Data
    wp_idea_stream_users_delete_user_data($user_id);
    // Spam approved comments about ideas
    $comments = get_comments(array('fields' => 'ids', 'user_id' => $user_id, 'post_type' => wp_idea_stream_get_post_type(), 'status' => 'approve'));
    if (!empty($comments)) {
        foreach ($comments as $comment) {
            wp_spam_comment($comment);
        }
    }
}
示例#22
0
 function comment_bulk_action()
 {
     //Read form data
     $action = $_POST['action'];
     $commentIds = explode(',', $_POST['ids']);
     $information['success'] = 0;
     foreach ($commentIds as $commentId) {
         if ($commentId) {
             $information['success']++;
             if ('approve' === $action) {
                 wp_set_comment_status($commentId, 'approve');
             } else {
                 if ('unapprove' === $action) {
                     wp_set_comment_status($commentId, 'hold');
                 } else {
                     if ('spam' === $action) {
                         wp_spam_comment($commentId);
                     } else {
                         if ('unspam' === $action) {
                             wp_unspam_comment($commentId);
                         } else {
                             if ('trash' === $action) {
                                 wp_trash_comment($commentId);
                             } else {
                                 if ('restore' === $action) {
                                     wp_untrash_comment($commentId);
                                 } else {
                                     if ('delete' === $action) {
                                         wp_delete_comment($commentId, true);
                                     } else {
                                         $information['success']--;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     MainWP_Helper::write($information);
 }
 public function spam_comment($comment_id)
 {
     wp_spam_comment($comment_id);
 }
示例#24
0
 public function test_unspam_should_invalidate_comment_cache()
 {
     global $wpdb;
     $c = self::factory()->comment->create();
     wp_spam_comment($c);
     $comment = get_comment($c);
     $this->assertSame('spam', $comment->comment_approved);
     wp_unspam_comment($c);
     $comment = get_comment($c);
     $this->assertSame('1', $comment->comment_approved);
 }
示例#25
0
function akismet_cron_recheck( $data ) {
	global $wpdb;

	delete_option('akismet_available_servers');

	$comment_errors = $wpdb->get_col( "
		SELECT comment_id
		FROM {$wpdb->prefix}commentmeta
		WHERE meta_key = 'akismet_error'
	" );

	foreach ( (array) $comment_errors as $comment_id ) {
		add_comment_meta( $comment_id, 'akismet_rechecking', true );
		$status = akismet_check_db_comment( $comment_id, 'retry' );

		$msg = '';
		if ( $status == 'true' ) {
			$msg = __( 'Akismet caught this comment as spam during an automatic retry.' );
		} elseif ( $status == 'false' ) {
			$msg = __( 'Akismet cleared this comment during an automatic retry.' );
		}
		
		// If we got back a legit response then update the comment history
		// other wise just bail now and try again later.  No point in
		// re-trying all the comments once we hit one failure.
		if ( !empty( $msg ) ) {
			delete_comment_meta( $comment_id, 'akismet_error' );
			akismet_update_comment_history( $comment_id, $msg, 'cron-retry' );
			update_comment_meta( $comment_id, 'akismet_result', $status );
			// make sure the comment status is still pending.  if it isn't, that means the user has already moved it elsewhere.
			$comment = get_comment( $comment_id );
			if ( $comment && 'unapproved' == wp_get_comment_status( $comment_id ) ) {
				if ( $status == 'true' ) {
					wp_spam_comment( $comment_id );
				} elseif ( $status == 'false' ) {
					// comment is good, but it's still in the pending queue.  depending on the moderation settings
					// we may need to change it to approved.
					if ( check_comment($comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent, $comment->comment_type) )
						wp_set_comment_status( $comment_id, 1 );
				}
			}
		} else {
			delete_comment_meta( $comment_id, 'akismet_rechecking' );
			wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
			return;
		}
	}
}
示例#26
0
function akismet_cron_recheck()
{
    global $wpdb;
    $status = akismet_verify_key(akismet_get_key());
    if (get_option('akismet_alert_code') || $status == 'invalid') {
        // since there is currently a problem with the key, reschedule a check for 6 hours hence
        wp_schedule_single_event(time() + 21600, 'akismet_schedule_cron_recheck');
        return false;
    }
    delete_option('akismet_available_servers');
    $comment_errors = $wpdb->get_col("\n\t\tSELECT comment_id\n\t\tFROM {$wpdb->prefix}commentmeta\n\t\tWHERE meta_key = 'akismet_error'\n\t\tLIMIT 100\n\t");
    foreach ((array) $comment_errors as $comment_id) {
        // if the comment no longer exists, or is too old, remove the meta entry from the queue to avoid getting stuck
        $comment = get_comment($comment_id);
        if (!$comment || strtotime($comment->comment_date_gmt) < strtotime("-15 days")) {
            delete_comment_meta($comment_id, 'akismet_error');
            continue;
        }
        add_comment_meta($comment_id, 'akismet_rechecking', true);
        $status = akismet_check_db_comment($comment_id, 'retry');
        $msg = '';
        if ($status == 'true') {
            $msg = __('Akismet caught this comment as spam during an automatic retry.');
        } elseif ($status == 'false') {
            $msg = __('Akismet cleared this comment during an automatic retry.');
        }
        // If we got back a legit response then update the comment history
        // other wise just bail now and try again later.  No point in
        // re-trying all the comments once we hit one failure.
        if (!empty($msg)) {
            delete_comment_meta($comment_id, 'akismet_error');
            akismet_update_comment_history($comment_id, $msg, 'cron-retry');
            update_comment_meta($comment_id, 'akismet_result', $status);
            // make sure the comment status is still pending.  if it isn't, that means the user has already moved it elsewhere.
            $comment = get_comment($comment_id);
            if ($comment && 'unapproved' == wp_get_comment_status($comment_id)) {
                if ($status == 'true') {
                    wp_spam_comment($comment_id);
                } elseif ($status == 'false') {
                    // comment is good, but it's still in the pending queue.  depending on the moderation settings
                    // we may need to change it to approved.
                    if (check_comment($comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent, $comment->comment_type)) {
                        wp_set_comment_status($comment_id, 1);
                    }
                }
            }
        } else {
            delete_comment_meta($comment_id, 'akismet_rechecking');
            wp_schedule_single_event(time() + 1200, 'akismet_schedule_cron_recheck');
            return;
        }
        delete_comment_meta($comment_id, 'akismet_rechecking');
    }
    $remaining = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error'");
    if ($remaining && !wp_next_scheduled('akismet_schedule_cron_recheck')) {
        wp_schedule_single_event(time() + 1200, 'akismet_schedule_cron_recheck');
    }
}
示例#27
0
 public function spamPost($postIdArray)
 {
     global $wpdb;
     $commentIdArray = $wpdb->get_col("SELECT comment_ID FROM {$wpdb->commentmeta} WHERE meta_key = 'duoshuo_post_id' AND meta_value IN ('" . implode("', '", $postIdArray) . "')");
     if (count($commentIdArray)) {
         $commentIdArray = $wpdb->get_col("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_ID IN ('" . implode("', '", $commentIdArray) . "')");
         foreach ($commentIdArray as $commentId) {
             wp_spam_comment($commentId);
         }
     }
     return array();
 }
示例#28
0
/**
 * Ajax handler for deleting a comment.
 *
 * @since 3.1.0
 */
function wp_ajax_delete_comment()
{
    $id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
    if (!($comment = get_comment($id))) {
        wp_die(time());
    }
    if (!current_user_can('edit_comment', $comment->comment_ID)) {
        wp_die(-1);
    }
    check_ajax_referer("delete-comment_{$id}");
    $status = wp_get_comment_status($comment);
    $delta = -1;
    if (isset($_POST['trash']) && 1 == $_POST['trash']) {
        if ('trash' == $status) {
            wp_die(time());
        }
        $r = wp_trash_comment($comment);
    } elseif (isset($_POST['untrash']) && 1 == $_POST['untrash']) {
        if ('trash' != $status) {
            wp_die(time());
        }
        $r = wp_untrash_comment($comment);
        if (!isset($_POST['comment_status']) || $_POST['comment_status'] != 'trash') {
            // undo trash, not in trash
            $delta = 1;
        }
    } elseif (isset($_POST['spam']) && 1 == $_POST['spam']) {
        if ('spam' == $status) {
            wp_die(time());
        }
        $r = wp_spam_comment($comment);
    } elseif (isset($_POST['unspam']) && 1 == $_POST['unspam']) {
        if ('spam' != $status) {
            wp_die(time());
        }
        $r = wp_unspam_comment($comment);
        if (!isset($_POST['comment_status']) || $_POST['comment_status'] != 'spam') {
            // undo spam, not in spam
            $delta = 1;
        }
    } elseif (isset($_POST['delete']) && 1 == $_POST['delete']) {
        $r = wp_delete_comment($comment);
    } else {
        wp_die(-1);
    }
    if ($r) {
        // Decide if we need to send back '1' or a more complicated response including page links and comment counts
        _wp_ajax_delete_comment_response($comment->comment_ID, $delta);
    }
    wp_die(0);
}
示例#29
0
 /**
  * Spam a comment
  *
  * Example: wp comment spam 15
  *
  * @param array $args}
  * @param array $assoc_args
  */
 public function spam($args, $assoc_args)
 {
     $comment_id = WP_CLI::get_numeric_arg($args, 0, "Comment ID");
     if (wp_spam_comment($comment_id)) {
         WP_CLI::success("Spammed comment {$comment_id}.");
     } else {
         WP_CLI::error("Failed spamming comment {$comment_id}");
     }
 }