function update_comment($comment_id)
 {
     $comment = get_comment($comment_id);
     delete_comment_meta($comment_id, $this->meta_key);
     $terms = $this->update_comment_terms($comment_id, $comment);
     foreach ($terms as $term) {
         add_comment_meta($comment_id, $this->meta_key, $term);
     }
     $this->update_terms($comment->comment_post_ID);
 }
Beispiel #2
0
 /**
  * Loaded, check request
  */
 public function loaded()
 {
     // check to delete att
     if (isset($_GET['deleteAtt']) && $_GET['deleteAtt'] == '1') {
         if (isset($_GET['c']) && is_numeric($_GET['c'])) {
             WPLMS_Assignments::deleteAttachment($_GET['c']);
             delete_comment_meta($_GET['c'], 'attachmentId');
             add_action('admin_notices', array($this, 'mynotice'));
         }
     }
 }
Beispiel #3
0
 function update_comment($comment_id)
 {
     if (!$this->should_process_terms()) {
         return;
     }
     $comment = get_comment($comment_id);
     delete_comment_meta($comment_id, $this->meta_key);
     $terms = $this->update_comment_terms($comment_id, $comment);
     foreach ($terms as $term) {
         add_comment_meta($comment_id, $this->meta_key, $term);
     }
     $this->update_terms($comment->comment_post_ID);
 }
 /**
  * Loaded, check request
  */
 public function loaded()
 {
     // check to delete att
     if (isset($_GET['deleteAtt']) && $_GET['deleteAtt'] == '1') {
         if (isset($_GET['c']) && is_numeric($_GET['c'])) {
             wpCommentAttachment::deleteAttachment($_GET['c']);
             delete_comment_meta($_GET['c'], 'attachmentId');
             add_action('admin_notices', function () {
                 echo "<div class='updated'><p>Comment Attachment deleted.</p></div>";
             });
         }
     }
 }
 function wp_set_comment_status($comment_id, $status)
 {
     global $wpdb;
     if ($status != '1' && $status != 'approve') {
         return;
     }
     if (!empty($_POST['probation'])) {
         update_comment_meta($comment_id, self::meta_key, '1');
     } else {
         $commentdata = get_comment($comment_id);
         $comment_ids = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_author = %s AND comment_author_email = %s AND comment_approved = '1'", $commentdata->comment_author, $commentdata->comment_author_email));
         foreach ($comment_ids as $comment_id) {
             delete_comment_meta($comment_id, self::meta_key);
         }
     }
 }
/**
 * When a post is trashed, remove each comment's associated activity meta.
 *
 * When a post is trashed and later untrashed, we currently don't reinstate
 * activity items for these comments since their activity entries are already
 * deleted when initially trashed.
 *
 * Since these activity entries are deleted, we need to remove the deleted
 * activity comment IDs from each comment's meta when a post is trashed.
 *
 * @since BuddyPress (2.0.0)
 *
 * @param int $post_id The post ID
 * @param array $comments Array of comment statuses. The key is comment ID, the
 *        value is the $comment->comment_approved value.
 */
function bp_blogs_remove_activity_meta_for_trashed_comments( $post_id = 0, $comments = array() ) {
	if ( ! empty( $comments ) ) {
		foreach ( array_keys( $comments ) as $comment_id ) {
			delete_comment_meta( $comment_id, 'bp_activity_comment_id' );
		}
	}
}
Beispiel #7
0
 /**
  * Save a comment meta
  *
  * @param int $id Comment ID
  * @param array $comment_meta (optional) All meta to be saved (set value to null to delete)
  * @param bool $strict (optional) Whether to delete previously saved meta not in $comment_meta
  * @param array $fields (optional) The array of fields and their options, for further processing with
  *
  * @return int Comment ID
  *
  * @since 2.0
  */
 public function save_comment_meta($id, $comment_meta = null, $strict = false, $fields = array())
 {
     $simple_tableless_objects = PodsForm::simple_tableless_objects();
     $conflicted = pods_no_conflict_check('comment');
     if (!$conflicted) {
         pods_no_conflict_on('comment');
     }
     if (!is_array($comment_meta)) {
         $comment_meta = array();
     }
     $id = (int) $id;
     $meta = get_comment_meta($id);
     foreach ($comment_meta as $meta_key => $meta_value) {
         if (null === $meta_value) {
             $old_meta_value = '';
             if (isset($meta[$meta_key])) {
                 $old_meta_value = $meta[$meta_key];
             }
             delete_comment_meta($id, $meta_key, $old_meta_value);
         } else {
             $simple = false;
             if (isset($fields[$meta_key])) {
                 $field_data = $fields[$meta_key];
                 $simple = 'pick' == $field_data['type'] && in_array(pods_var('pick_object', $field_data), $simple_tableless_objects);
             }
             if ($simple) {
                 delete_comment_meta($id, $meta_key);
                 if (!is_array($meta_value)) {
                     $meta_value = array($meta_value);
                 }
                 foreach ($meta_value as $value) {
                     add_comment_meta($id, $meta_key, $value);
                 }
             } else {
                 update_comment_meta($id, $meta_key, $meta_value);
             }
         }
     }
     if ($strict) {
         foreach ($meta as $meta_key => $meta_value) {
             if (!isset($comment_meta[$meta_key])) {
                 delete_comment_meta((int) $id, $meta_key, $comment_meta[$meta_key]);
             }
         }
     }
     if (!$conflicted) {
         pods_no_conflict_off('comment');
     }
     return $id;
 }
Beispiel #8
0
/**
 * Permanently delete comments or posts of any type that have held a status
 * of 'trash' for the number of days defined in EMPTY_TRASH_DAYS.
 *
 * The default value of `EMPTY_TRASH_DAYS` is 30 (days).
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb
 */
function wp_scheduled_delete()
{
    global $wpdb;
    $delete_timestamp = time() - DAY_IN_SECONDS * EMPTY_TRASH_DAYS;
    $posts_to_delete = $wpdb->get_results($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_wp_trash_meta_time' AND meta_value < '%d'", $delete_timestamp), ARRAY_A);
    foreach ((array) $posts_to_delete as $post) {
        $post_id = (int) $post['post_id'];
        if (!$post_id) {
            continue;
        }
        $del_post = get_post($post_id);
        if (!$del_post || 'trash' != $del_post->post_status) {
            delete_post_meta($post_id, '_wp_trash_meta_status');
            delete_post_meta($post_id, '_wp_trash_meta_time');
        } else {
            wp_delete_post($post_id);
        }
    }
    $comments_to_delete = $wpdb->get_results($wpdb->prepare("SELECT comment_id FROM {$wpdb->commentmeta} WHERE meta_key = '_wp_trash_meta_time' AND meta_value < '%d'", $delete_timestamp), ARRAY_A);
    foreach ((array) $comments_to_delete as $comment) {
        $comment_id = (int) $comment['comment_id'];
        if (!$comment_id) {
            continue;
        }
        $del_comment = get_comment($comment_id);
        if (!$del_comment || 'trash' != $del_comment->comment_approved) {
            delete_comment_meta($comment_id, '_wp_trash_meta_time');
            delete_comment_meta($comment_id, '_wp_trash_meta_status');
        } else {
            wp_delete_comment($del_comment);
        }
    }
}
 /**
  * delete notification of a comment perticular commnet
  * @param   int     $comment_id
  */
 function remove_comment_notification($comment_id)
 {
     $comment_notification_id = (int) get_comment_meta($comment_id, 'comment_notification_id', true);
     BP_Notifications_Notification::delete(array('id' => $comment_notification_id));
     delete_comment_meta($comment_id, 'comment_notification_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');
     }
 }
Beispiel #11
0
/**
 * Removes a comment from the Spam
 *
 * @since 0.0.1
 *
 * @param int $comment_id Comment ID.
 * @return bool True on success, false on failure.
 */
function hq_unspam_comment($comment_id)
{
    if (!(int) $comment_id) {
        return false;
    }
    /**
     * Fires immediately before a comment is unmarked as Spam.
     *
     * @since 0.0.1
     *
     * @param int $comment_id The comment ID.
     */
    do_action('unspam_comment', $comment_id);
    $status = (string) get_comment_meta($comment_id, '_hq_trash_meta_status', true);
    if (empty($status)) {
        $status = '0';
    }
    if (hq_set_comment_status($comment_id, $status)) {
        delete_comment_meta($comment_id, '_hq_trash_meta_status');
        /**
         * Fires immediately after a comment is unmarked as Spam.
         *
         * @since 0.0.1
         *
         * @param int $comment_id The comment ID.
         */
        do_action('unspammed_comment', $comment_id);
        return true;
    }
    return false;
}
Beispiel #12
0
 /**
  * Sets the comment to be approved.
  *
  * @wp-action  wp_set_comment_status
  * @param  int     $comment_id
  * @param  string  $comment_status
  * @return void
  */
 public function wp_set_comment_status($comment_id, $comment_status)
 {
     if ($comment_status == 'approve') {
         global $wpdb;
         $results = $wpdb->get_results($wpdb->prepare("\n\t\t\t\tSELECT user_id, m.meta_value\n\t\t\t\t  FROM {$wpdb->commentmeta} AS m\n\t\t\t\t  JOIN {$wpdb->comments} AS c\n\t\t\t\t    ON m.comment_id = c.comment_ID\n\t\t\t\t WHERE m.meta_key = %s\n\t\t\t\t   AND m.comment_id = %s\n\t\t\t", 'social_to_broadcast', $comment_id));
         if (!empty($results)) {
             $result = reset($results);
             $accounts = get_user_meta($result->user_id, 'social_accounts', true);
             if (!empty($accounts)) {
                 foreach ($accounts as $service => $accounts) {
                     $service = $this->service($service);
                     if ($service !== false) {
                         $account = null;
                         if (!$service->account_exists($result->meta_value)) {
                             foreach ($accounts as $id => $account) {
                                 if ($id == $result->meta_value) {
                                     $class = 'Social_Service_' . $service->key() . '_Account';
                                     $account = new $class($account);
                                     break;
                                 }
                             }
                         } else {
                             $account = $service->account($result->meta_value);
                         }
                         if ($account !== null) {
                             Social::log(sprintf(__('Broadcasting comment #%s to %s using account #%s.', 'social'), $comment_id, $service->title(), $account->id()));
                             $comment = get_comment($comment_id);
                             $in_reply_to_status_id = get_comment_meta($comment_id, 'social_in_reply_to_status_id', true);
                             $args = array();
                             if (!empty($in_reply_to_status_id)) {
                                 $args['in_reply_to_status_id'] = $in_reply_to_status_id;
                                 delete_comment_meta($comment_id, 'social_in_reply_to_status_id');
                             }
                             $output = $service->format_comment_content($comment, Social::option('comment_broadcast_format'));
                             $response = $service->broadcast($account, $output, $args, null, $comment_id);
                             if ($response === false || $response->body()->result !== 'success') {
                                 wp_delete_comment($comment_id);
                                 Social::log(sprintf(__('Error: Broadcast comment #%s to %s using account #%s, please go back and try again.', 'social'), $comment_id, $service->title(), $account->id()));
                             }
                             $wpdb->query($wpdb->prepare("\n\t\t\t\t\t\t\t\t\tUPDATE {$wpdb->comments}\n\t\t\t\t\t\t\t\t\t   SET comment_type = %s\n\t\t\t\t\t\t\t\t\t WHERE comment_ID = %s\n\t\t\t\t\t\t\t\t", 'social-' . $service->key(), $comment_id));
                             $this->set_comment_aggregated_id($comment_id, $service->key(), $response->body()->response);
                             // Feed posts return id with property, comment posts return raw id
                             if (isset($response->body()->response->id)) {
                                 add_comment_meta($comment_ID, 'social_status_id', addslashes_deep($response->body()->response->id), true);
                             } else {
                                 add_comment_meta($comment_ID, 'social_status_id', addslashes_deep($response->body()->response), true);
                             }
                             update_comment_meta($comment_id, 'social_raw_data', addslashes_deep(base64_encode(json_encode($response->body()->response))));
                             Social::log(sprintf(__('Broadcasting comment #%s to %s using account #%s COMPLETE.', 'social'), $comment_id, $service->title(), $account->id()));
                         }
                     }
                 }
             }
             delete_comment_meta($comment_id, 'social_to_broadcast');
         }
     }
 }
Beispiel #13
0
	/**
	 * Deletes all (meta) checked states for the current/given comment.
	 *
	 * @param int $comment_id (optional)
	 */
	function delete_all_item_data( $comment_id = 0 ) {
		$comment_id = $this->get_object_id( $comment_id );

		$task_id_meta_keys = $this->get_all_item_data( $comment_id );
		foreach ( $task_id_meta_keys as $task_id_meta_key ) {
			delete_comment_meta( $comment_id, $task_id_meta_key );
		}
	}
Beispiel #14
0
 /**
  * Delete the Sensei user data for the given key, Sensei post type and user combination.
  *
  * @param int $data_key
  * @param int $post_id
  * @param int $user_id
  *
  * @return bool $deleted
  */
 public static function delete_user_data($data_key, $post_id, $user_id)
 {
     $deleted = true;
     if (!($user_id > 0)) {
         $user_id = get_current_user_id();
     }
     $supported_post_types = array('course', 'lesson');
     $post_type = get_post_type($post_id);
     if (empty($post_id) || empty($data_key) || !is_int($post_id) || !(intval($post_id) > 0) || !(intval($user_id) > 0) || !get_userdata($user_id) || !in_array($post_type, $supported_post_types)) {
         return false;
     }
     // check if there and existing Sensei status on this post type if not create it
     // and get the  activity ID
     $status_function = 'user_' . $post_type . '_status';
     $sensei_user_status = self::$status_function($post_id, $user_id);
     if (!isset($sensei_user_status->comment_ID)) {
         return false;
     }
     $sensei_user_activity_id = $sensei_user_status->comment_ID;
     $deleted = delete_comment_meta($sensei_user_activity_id, $data_key);
     return $deleted;
 }
Beispiel #15
0
 /**
 Action subscribe requests made on comment forms when comments are approved
 */
 function comment_status($comment_ID = 0)
 {
     global $wpdb;
     // get meta data
     $subscribe = get_comment_meta($comment_ID, 's2_comment_request', true);
     if ($subscribe != '1') {
         return $comment_ID;
     }
     // Retrieve the information about the comment
     $sql = $wpdb->prepare("SELECT comment_author_email, comment_approved FROM {$wpdb->comments} WHERE comment_ID=%s LIMIT 1", $comment_ID);
     $comment = $wpdb->get_row($sql, OBJECT);
     if (empty($comment)) {
         return $comment_ID;
     }
     switch ($comment->comment_approved) {
         case '0':
             // Unapproved
             break;
         case '1':
             // Approved
             $is_public = $this->is_public($comment->comment_author_email);
             if ($is_public == 0) {
                 $this->toggle($comment->comment_author_email);
             }
             $is_registered = $this->is_registered($comment->comment_author_email);
             if (!$is_public && !$is_registered) {
                 $this->add($comment->comment_author_email, true);
             }
             delete_comment_meta($comment_ID, 's2_comment_request');
             break;
         default:
             // post is trash, spam or deleted
             delete_comment_meta($comment_ID, 's2_comment_request');
             break;
     }
     return $comment_ID;
 }
Beispiel #16
0
function akismet_recheck_queue()
{
    global $wpdb, $akismet_api_host, $akismet_api_port;
    akismet_fix_scheduled_recheck();
    if (!(isset($_GET['recheckqueue']) || isset($_REQUEST['action']) && 'akismet_recheck_queue' == $_REQUEST['action'])) {
        return;
    }
    $moderation = $wpdb->get_results("SELECT * FROM {$wpdb->comments} WHERE comment_approved = '0'", ARRAY_A);
    foreach ((array) $moderation as $c) {
        $c['user_ip'] = $c['comment_author_IP'];
        $c['user_agent'] = $c['comment_agent'];
        $c['referrer'] = '';
        $c['blog'] = get_bloginfo('url');
        $c['blog_lang'] = get_locale();
        $c['blog_charset'] = get_option('blog_charset');
        $c['permalink'] = get_permalink($c['comment_post_ID']);
        $c['user_role'] = '';
        if (isset($c['user_ID'])) {
            $c['user_role'] = akismet_get_user_roles($c['user_ID']);
        }
        if (akismet_test_mode()) {
            $c['is_test'] = 'true';
        }
        $id = (int) $c['comment_ID'];
        $query_string = '';
        foreach ($c as $key => $data) {
            $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&';
        }
        add_comment_meta($c['comment_ID'], 'akismet_rechecking', true);
        $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
        if ('true' == $response[1]) {
            wp_set_comment_status($c['comment_ID'], 'spam');
            update_comment_meta($c['comment_ID'], 'akismet_result', 'true');
            delete_comment_meta($c['comment_ID'], 'akismet_error');
            akismet_update_comment_history($c['comment_ID'], __('Akismet re-checked and caught this comment as spam'), 'check-spam');
        } elseif ('false' == $response[1]) {
            update_comment_meta($c['comment_ID'], 'akismet_result', 'false');
            delete_comment_meta($c['comment_ID'], 'akismet_error');
            akismet_update_comment_history($c['comment_ID'], __('Akismet re-checked and cleared this comment'), 'check-ham');
            // abnormal result: error
        } else {
            update_comment_meta($c['comment_ID'], 'akismet_result', 'error');
            akismet_update_comment_history($c['comment_ID'], sprintf(__('Akismet was unable to re-check this comment (response: %s)'), substr($response[1], 0, 50)), 'check-error');
        }
        delete_comment_meta($c['comment_ID'], 'akismet_rechecking');
    }
    $redirect_to = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : admin_url('edit-comments.php');
    wp_safe_redirect($redirect_to);
    exit;
}
 protected function post_process_comments($todo)
 {
     foreach ($todo as $comment_id => $_) {
         $data = array();
         $parent_id = get_comment_meta($comment_id, '_wxr_import_parent', true);
         if (!empty($parent_id)) {
             // Have we imported the parent now?
             if (isset($this->mapping['comment'][$parent_id])) {
                 $data['comment_parent'] = $this->mapping['comment'][$parent_id];
             } else {
                 $this->logger->warning(sprintf(__('Could not find the comment parent for comment #%d', 'wordpress-importer'), $comment_id));
                 $this->logger->debug(sprintf(__('Comment %d was imported with parent %d, but could not be found', 'wordpress-importer'), $comment_id, $parent_id));
             }
         }
         $author_id = get_comment_meta($comment_id, '_wxr_import_user', true);
         if (!empty($author_id)) {
             // Have we imported the user now?
             if (isset($this->mapping['user'][$author_id])) {
                 $data['user_id'] = $this->mapping['user'][$author_id];
             } else {
                 $this->logger->warning(sprintf(__('Could not find the author for comment #%d', 'wordpress-importer'), $comment_id));
                 $this->logger->debug(sprintf(__('Comment %d was imported with author %d, but could not be found', 'wordpress-importer'), $comment_id, $author_id));
             }
         }
         // Do we have updates to make?
         if (empty($data)) {
             continue;
         }
         // Run the update
         $data['comment_ID'] = $comment_ID;
         $result = wp_update_comment(wp_slash($data));
         if (empty($result)) {
             $this->logger->warning(sprintf(__('Could not update comment #%d with mapped data', 'wordpress-importer'), $comment_id));
             continue;
         }
         // Clear out our temporary meta keys
         delete_comment_meta($comment_id, '_wxr_import_parent');
         delete_comment_meta($comment_id, '_wxr_import_user');
     }
 }
Beispiel #18
0
function kt_comment_edit_metafields($comment_id)
{
    if (!isset($_POST['extend_comment_update']) || !wp_verify_nonce($_POST['extend_comment_update'], 'extend_comment_update')) {
        return;
    }
    if (isset($_POST['rating']) && $_POST['rating'] != '') {
        $rating = wp_filter_nohtml_kses($_POST['rating']);
        update_comment_meta($comment_id, '_kt_rating', $rating);
    } else {
        delete_comment_meta($comment_id, '_kt_rating');
    }
}
/**
 * Update comment meta data from comment edit screen
*/
function smittenkitchen_comment_edit_metafields($comment_id)
{
    if (!isset($_POST['sk_comment_update']) || !wp_verify_nonce($_POST['sk_comment_update'], 'sk_comment_update')) {
        return;
    }
    if (isset($_POST['sk_madethis']) && '' != $_POST['sk_madethis']) {
        $sk_madethis = wp_filter_nohtml_kses($_POST['sk_madethis']);
        update_comment_meta($comment_id, 'sk_madethis', $sk_madethis);
    } else {
        delete_comment_meta($comment_id, 'sk_madethis');
    }
    if (isset($_POST['sk_question']) && '' != $_POST['sk_question']) {
        $sk_question = wp_filter_nohtml_kses($_POST['sk_question']);
        update_comment_meta($comment_id, 'sk_question', $sk_question);
    } else {
        delete_comment_meta($comment_id, 'sk_question');
    }
}
 /**
  * Update entity custom fields
  */
 public function deleteCustomFields($identifier)
 {
     global $wpdb;
     $likebtn_entities = _likebtn_get_entities(true, true);
     list($entity_name, $entity_id) = $this->parseIdentifier($identifier);
     $entity_updated = false;
     if (array_key_exists($entity_name, $likebtn_entities) && is_numeric($entity_id)) {
         // set Custom fields
         switch ($entity_name) {
             case LIKEBTN_ENTITY_COMMENT:
                 // Comment
                 $comment = get_comment($entity_id);
                 // check if post exists and is not revision
                 if (!empty($comment) && $comment->comment_type != 'revision') {
                     delete_comment_meta($entity_id, LIKEBTN_META_KEY_LIKES);
                     delete_comment_meta($entity_id, LIKEBTN_META_KEY_DISLIKES);
                     delete_comment_meta($entity_id, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES);
                     $entity_updated = true;
                 }
                 break;
             case LIKEBTN_ENTITY_BP_ACTIVITY_POST:
             case LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE:
             case LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT:
             case LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC:
                 if (!_likebtn_is_bp_active()) {
                     break;
                 }
                 $bp_activity = $wpdb->get_row("\n                        SELECT id\n                        FROM " . $wpdb->prefix . "bp_activity\n                        WHERE id = {$entity_id}\n                    ");
                 if (!empty($bp_activity)) {
                     bp_activity_delete_meta($entity_id, LIKEBTN_META_KEY_LIKES);
                     bp_activity_delete_meta($entity_id, LIKEBTN_META_KEY_DISLIKES);
                     bp_activity_delete_meta($entity_id, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES);
                     $entity_updated = true;
                 }
                 break;
             case LIKEBTN_ENTITY_BP_MEMBER:
                 // BuddyPress Member Profile
                 _likebtn_delete_bp_member_votes($entity_id);
                 $entity_updated = true;
                 break;
             case LIKEBTN_ENTITY_BBP_USER:
                 // bbPress Member Profile
                 _likebtn_delete_user_votes($entity_id);
                 $entity_updated = true;
                 break;
             case LIKEBTN_ENTITY_USER:
                 // BuddyPress Member Profile
                 $entity_updated = _likebtn_delete_bp_member_votes($entity_id);
                 // General user and bbPress Member Profile
                 $entity_updated = $entity_updated || _likebtn_delete_user_votes($entity_id);
                 break;
             default:
                 // Post
                 $post = get_post($entity_id);
                 // check if post exists and is not revision
                 if (!empty($post) && !empty($post->post_type) && $post->post_type != 'revision') {
                     delete_post_meta($entity_id, LIKEBTN_META_KEY_LIKES);
                     delete_post_meta($entity_id, LIKEBTN_META_KEY_DISLIKES);
                     delete_post_meta($entity_id, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES);
                     $entity_updated = true;
                 }
                 break;
         }
     }
     // Check custom item
     $item_db = $wpdb->get_row($wpdb->prepare("SELECT likes, dislikes\n                FROM " . $wpdb->prefix . LIKEBTN_TABLE_ITEM . "\n                WHERE identifier = %s", $identifier));
     // Custom identifier
     if ($item_db || !$entity_updated) {
         $where = array('identifier' => $identifier);
         $result = $wpdb->delete($wpdb->prefix . LIKEBTN_TABLE_ITEM, $where);
         if ($result) {
             $entity_updated = true;
         }
     }
     return $entity_updated;
 }
 /**
  * Delete Comment Meta.
  *
  * @static
  * @since  5.4
  * @param array   $delete_options Options for deleting
  * @return int                   Number of comments that were deleted
  */
 public static function delete_comment_meta($delete_options)
 {
     $count = 0;
     $post_type = $delete_options['post_type'];
     $limit_to = $delete_options['limit_to'];
     $meta_key = $delete_options['meta_key'];
     $use_value = $delete_options['use_value'];
     $restrict = $delete_options['restrict'];
     $days = $delete_options['days'];
     $op = $delete_options['op'];
     $options = array('post_type' => $post_type);
     if ($limit_to > 0) {
         $options['number'] = $limit_to;
     }
     if ($restrict) {
         $options['date_query'] = array(array('column' => 'comment_date', $op => "{$days} day ago"));
     }
     if ($use_value) {
         $options['meta_query'] = apply_filters('bd_delete_comment_meta_query', array(), $delete_options);
     } else {
         $options['meta_key'] = $meta_key;
     }
     $comments = get_comments($options);
     foreach ($comments as $comment) {
         if (delete_comment_meta($comment->comment_ID, $meta_key)) {
             $count++;
         }
     }
     return $count;
 }
/**
 * Removes a comment from the Spam
 *
 * @since 2.9.0
 * @uses do_action() on 'unspam_comment' before unspamming
 * @uses do_action() on 'unspammed_comment' after unspamming
 *
 * @param int $comment_id Comment ID.
 * @return bool True on success, false on failure.
 */
function wp_unspam_comment($comment_id)
{
    if (!(int) $comment_id) {
        return false;
    }
    do_action('unspam_comment', $comment_id);
    $status = (string) get_comment_meta($comment_id, '_wp_trash_meta_status', true);
    if (empty($status)) {
        $status = '0';
    }
    if (wp_set_comment_status($comment_id, $status)) {
        delete_comment_meta($comment_id, '_wp_trash_meta_status');
        do_action('unspammed_comment', $comment_id);
        return true;
    }
    return false;
}
Beispiel #23
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');
    }
}
 /**
  * Save the comment meta data along with comment
  *
  * @param $comment_id
  */
 public function _action_save_meta_box_edit_feedback($comment_id)
 {
     if (!isset($_POST['fw_ext_feedback_stars']) || !wp_verify_nonce($_POST['fw_ext_feedback_stars'], 'fw_ext_feedback_stars')) {
         return;
     }
     if (isset($_POST[$this->field_name]) && $_POST[$this->field_name] != '') {
         $rating = wp_filter_nohtml_kses($_POST[$this->field_name]);
         update_comment_meta($comment_id, $this->field_name, $rating);
     } else {
         delete_comment_meta($comment_id, $this->field_name);
     }
 }
 public static function recheck_queue()
 {
     global $wpdb;
     Akismet::fix_scheduled_recheck();
     if (!(isset($_GET['recheckqueue']) || isset($_REQUEST['action']) && 'akismet_recheck_queue' == $_REQUEST['action'])) {
         return;
     }
     $paginate = '';
     if (isset($_POST['limit']) && isset($_POST['offset'])) {
         $paginate = $wpdb->prepare(" LIMIT %d OFFSET %d", array($_POST['limit'], $_POST['offset']));
     }
     $moderation = $wpdb->get_results("SELECT * FROM {$wpdb->comments} WHERE comment_approved = '0'{$paginate}", ARRAY_A);
     foreach ((array) $moderation as $c) {
         $c['user_ip'] = $c['comment_author_IP'];
         $c['user_agent'] = $c['comment_agent'];
         $c['referrer'] = '';
         $c['blog'] = get_bloginfo('url');
         $c['blog_lang'] = get_locale();
         $c['blog_charset'] = get_option('blog_charset');
         $c['permalink'] = get_permalink($c['comment_post_ID']);
         $c['user_role'] = '';
         if (isset($c['user_ID'])) {
             $c['user_role'] = Akismet::get_user_roles($c['user_ID']);
         }
         if (Akismet::is_test_mode()) {
             $c['is_test'] = 'true';
         }
         add_comment_meta($c['comment_ID'], 'akismet_rechecking', true);
         $response = Akismet::http_post(http_build_query($c), 'comment-check');
         if ('true' == $response[1]) {
             wp_set_comment_status($c['comment_ID'], 'spam');
             update_comment_meta($c['comment_ID'], 'akismet_result', 'true');
             delete_comment_meta($c['comment_ID'], 'akismet_error');
             delete_comment_meta($c['comment_ID'], 'akismet_delayed_moderation_email');
             Akismet::update_comment_history($c['comment_ID'], __('Akismet re-checked and caught this comment as spam', 'akismet'), 'check-spam');
         } elseif ('false' == $response[1]) {
             update_comment_meta($c['comment_ID'], 'akismet_result', 'false');
             delete_comment_meta($c['comment_ID'], 'akismet_error');
             delete_comment_meta($c['comment_ID'], 'akismet_delayed_moderation_email');
             Akismet::update_comment_history($c['comment_ID'], __('Akismet re-checked and cleared this comment', 'akismet'), 'check-ham');
             // abnormal result: error
         } else {
             update_comment_meta($c['comment_ID'], 'akismet_result', 'error');
             Akismet::update_comment_history($c['comment_ID'], sprintf(__('Akismet was unable to re-check this comment (response: %s)', 'akismet'), substr($response[1], 0, 50)), 'check-error');
         }
         delete_comment_meta($c['comment_ID'], 'akismet_rechecking');
     }
     if (defined('DOING_AJAX') && DOING_AJAX) {
         wp_send_json(array('processed' => count((array) $moderation)));
     } else {
         $redirect_to = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : admin_url('edit-comments.php');
         wp_safe_redirect($redirect_to);
         exit;
     }
 }
 /**
  * Does the sweeping/cleaning up
  *
  * @since 1.0.0
  *
  * @access public
  * @param string $name
  * @return string Processed message
  */
 public function sweep($name)
 {
     global $wpdb;
     $message = '';
     switch ($name) {
         case 'revisions':
             $query = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s", 'revision'));
             if ($query) {
                 foreach ($query as $id) {
                     wp_delete_post_revision(intval($id));
                 }
                 $message = sprintf(__('%s Revisions Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
             }
             break;
         case 'auto_drafts':
             $query = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_status = %s", 'auto-draft'));
             if ($query) {
                 foreach ($query as $id) {
                     wp_delete_post(intval($id), true);
                 }
                 $message = sprintf(__('%s Auto Drafts Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
             }
             break;
         case 'deleted_posts':
             $query = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_status = %s", 'trash'));
             if ($query) {
                 foreach ($query as $id) {
                     wp_delete_post($id, true);
                 }
                 $message = sprintf(__('%s Deleted Posts Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
             }
             break;
         case 'unapproved_comments':
             $query = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_approved = %s", '0'));
             if ($query) {
                 foreach ($query as $id) {
                     wp_delete_comment(intval($id), true);
                 }
                 $message = sprintf(__('%s Unapproved Comments Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
             }
             break;
         case 'spam_comments':
             $query = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_approved = %s", 'spam'));
             if ($query) {
                 foreach ($query as $id) {
                     wp_delete_comment(intval($id), true);
                 }
                 $message = sprintf(__('%s Spam Comments Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
             }
             break;
         case 'deleted_comments':
             $query = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE (comment_approved = %s OR comment_approved = %s)", 'trash', 'post-trashed'));
             if ($query) {
                 foreach ($query as $id) {
                     wp_delete_comment(intval($id), true);
                 }
                 $message = sprintf(__('%s Trash Comments Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
             }
             break;
         case 'transient_options':
             $query = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE(%s)", '%_transient_%'));
             if ($query) {
                 foreach ($query as $option_name) {
                     if (strpos($option_name, '_site_transient_') !== false) {
                         delete_site_transient(str_replace('_site_transient_', '', $option_name));
                     } else {
                         delete_transient(str_replace('_transient_', '', $option_name));
                     }
                 }
                 $message = sprintf(__('%s Transient Options Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
             }
             break;
         case 'orphan_postmeta':
             $query = $wpdb->get_results("SELECT post_id, meta_key FROM {$wpdb->postmeta} WHERE post_id NOT IN (SELECT ID FROM {$wpdb->posts})");
             if ($query) {
                 foreach ($query as $meta) {
                     $post_id = intval($meta->post_id);
                     if ($post_id === 0) {
                         $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = %s", $post_id, $meta->meta_key));
                     } else {
                         delete_post_meta($post_id, $meta->meta_key);
                     }
                 }
                 $message = sprintf(__('%s Orphaned Post Meta Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
             }
             break;
         case 'orphan_commentmeta':
             $query = $wpdb->get_results("SELECT comment_id, meta_key FROM {$wpdb->commentmeta} WHERE comment_id NOT IN (SELECT comment_ID FROM {$wpdb->comments})");
             if ($query) {
                 foreach ($query as $meta) {
                     $comment_id = intval($meta->comment_id);
                     if ($comment_id === 0) {
                         $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->commentmeta} WHERE comment_id = %d AND meta_key = %s", $comment_id, $meta->meta_key));
                     } else {
                         delete_comment_meta($comment_id, $meta->meta_key);
                     }
                 }
                 $message = sprintf(__('%s Orphaned Comment Meta Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
             }
             break;
         case 'orphan_usermeta':
             $query = $wpdb->get_results("SELECT user_id, meta_key FROM {$wpdb->usermeta} WHERE user_id NOT IN (SELECT ID FROM {$wpdb->users})");
             if ($query) {
                 foreach ($query as $meta) {
                     $user_id = intval($meta->user_id);
                     if ($user_id === 0) {
                         $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id = %d AND meta_key = %s", $user_id, $meta->meta_key));
                     } else {
                         delete_user_meta($user_id, $meta->meta_key);
                     }
                 }
                 $message = sprintf(__('%s Orphaned User Meta Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
             }
             break;
         case 'orphan_termmeta':
             $query = $wpdb->get_results("SELECT term_id, meta_key FROM {$wpdb->termmeta} WHERE term_id NOT IN (SELECT term_id FROM {$wpdb->terms})");
             if ($query) {
                 foreach ($query as $meta) {
                     $term_id = intval($meta->term_id);
                     if ($term_id === 0) {
                         $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->termmeta} WHERE term_id = %d AND meta_key = %s", $term_id, $meta->meta_key));
                     } else {
                         delete_term_meta($term_id, $meta->meta_key);
                     }
                 }
                 $message = sprintf(__('%s Orphaned Term Meta Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
             }
             break;
         case 'orphan_term_relationships':
             $query = $wpdb->get_results("SELECT tr.object_id, tr.term_taxonomy_id, tt.term_id, tt.taxonomy FROM {$wpdb->term_relationships} AS tr INNER JOIN {$wpdb->term_taxonomy} AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy NOT IN ('" . implode('\',\'', $this->get_excluded_taxonomies()) . "') AND tr.object_id NOT IN (SELECT ID FROM {$wpdb->posts})");
             if ($query) {
                 foreach ($query as $tax) {
                     $wp_remove_object_terms = wp_remove_object_terms(intval($tax->object_id), intval($tax->term_id), $tax->taxonomy);
                     if ($wp_remove_object_terms !== true) {
                         $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id = %d", $tax->object_id, $tax->term_taxonomy_id));
                     }
                 }
                 $message = sprintf(__('%s Orphaned Term Relationships Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
             }
             break;
         case 'unused_terms':
             $query = $wpdb->get_results($wpdb->prepare("SELECT tt.term_taxonomy_id, t.term_id, tt.taxonomy FROM {$wpdb->terms} AS t INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id WHERE tt.count = %d AND t.term_id NOT IN (" . implode(',', $this->get_excluded_termids()) . ")", 0));
             if ($query) {
                 $check_wp_terms = false;
                 foreach ($query as $tax) {
                     if (taxonomy_exists($tax->taxonomy)) {
                         wp_delete_term(intval($tax->term_id), $tax->taxonomy);
                     } else {
                         $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_taxonomy} WHERE term_taxonomy_id = %d", intval($tax->term_taxonomy_id)));
                         $check_wp_terms = true;
                     }
                 }
                 // We need this for invalid taxonomies
                 if ($check_wp_terms) {
                     $wpdb->get_results("DELETE FROM {$wpdb->terms} WHERE term_id NOT IN (SELECT term_id FROM {$wpdb->term_taxonomy})");
                 }
                 $message = sprintf(__('%s Unused Terms Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
             }
             break;
         case 'duplicated_postmeta':
             $query = $wpdb->get_results($wpdb->prepare("SELECT GROUP_CONCAT(meta_id ORDER BY meta_id DESC) AS ids, post_id, COUNT(*) AS count FROM {$wpdb->postmeta} GROUP BY post_id, meta_key, meta_value HAVING count > %d", 1));
             if ($query) {
                 foreach ($query as $meta) {
                     $ids = array_map('intval', explode(',', $meta->ids));
                     array_pop($ids);
                     $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_id IN (" . implode(',', $ids) . ") AND post_id = %d", intval($meta->post_id)));
                 }
                 $message = sprintf(__('%s Duplicated Post Meta Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
             }
             break;
         case 'duplicated_commentmeta':
             $query = $wpdb->get_results($wpdb->prepare("SELECT GROUP_CONCAT(meta_id ORDER BY meta_id DESC) AS ids, comment_id, COUNT(*) AS count FROM {$wpdb->commentmeta} GROUP BY comment_id, meta_key, meta_value HAVING count > %d", 1));
             if ($query) {
                 foreach ($query as $meta) {
                     $ids = array_map('intval', explode(',', $meta->ids));
                     array_pop($ids);
                     $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->commentmeta} WHERE meta_id IN (" . implode(',', $ids) . ") AND comment_id = %d", intval($meta->comment_id)));
                 }
                 $message = sprintf(__('%s Duplicated Comment Meta Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
             }
             break;
         case 'duplicated_usermeta':
             $query = $wpdb->get_results($wpdb->prepare("SELECT GROUP_CONCAT(umeta_id ORDER BY umeta_id DESC) AS ids, user_id, COUNT(*) AS count FROM {$wpdb->usermeta} GROUP BY user_id, meta_key, meta_value HAVING count > %d", 1));
             if ($query) {
                 foreach ($query as $meta) {
                     $ids = array_map('intval', explode(',', $meta->ids));
                     array_pop($ids);
                     $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE umeta_id IN (" . implode(',', $ids) . ") AND user_id = %d", intval($meta->user_id)));
                 }
                 $message = sprintf(__('%s Duplicated User Meta Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
             }
             break;
         case 'duplicated_termmeta':
             $query = $wpdb->get_results($wpdb->prepare("SELECT GROUP_CONCAT(meta_id ORDER BY meta_id DESC) AS ids, term_id, COUNT(*) AS count FROM {$wpdb->termmeta} GROUP BY term_id, meta_key, meta_value HAVING count > %d", 1));
             if ($query) {
                 foreach ($query as $meta) {
                     $ids = array_map('intval', explode(',', $meta->ids));
                     array_pop($ids);
                     $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->termmeta} WHERE meta_id IN (" . implode(',', $ids) . ") AND term_id = %d", intval($meta->term_id)));
                 }
                 $message = sprintf(__('%s Duplicated Term Meta Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
             }
             break;
         case 'optimize_database':
             $query = $wpdb->get_col('SHOW TABLES');
             if ($query) {
                 $tables = implode(',', $query);
                 $wpdb->query("OPTIMIZE TABLE {$tables}");
                 $message = sprintf(__('%s Tables Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
             }
             break;
         case 'oembed_postmeta':
             $query = $wpdb->get_results($wpdb->prepare("SELECT post_id, meta_key FROM {$wpdb->postmeta} WHERE meta_key LIKE(%s)", '%_oembed_%'));
             if ($query) {
                 foreach ($query as $meta) {
                     $post_id = intval($meta->post_id);
                     if ($post_id === 0) {
                         $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = %s", $post_id, $meta->meta_key));
                     } else {
                         delete_post_meta($post_id, $meta->meta_key);
                     }
                 }
                 $message = sprintf(__('%s oEmbed Caches In Post Meta Processed', 'wp-sweep'), number_format_i18n(sizeof($query)));
             }
             break;
     }
     return apply_filters('wp_sweep_sweep', $message, $name);
 }
/**
 * Removes a comment from the Spam
 *
 * @since 2.9.0
 *
 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object.
 * @return bool True on success, false on failure.
 */
function wp_unspam_comment($comment_id)
{
    $comment = get_comment($comment_id);
    if (!$comment) {
        return false;
    }
    /**
     * Fires immediately before a comment is unmarked as Spam.
     *
     * @since 2.9.0
     *
     * @param int $comment_id The comment ID.
     */
    do_action('unspam_comment', $comment->comment_ID);
    $status = (string) get_comment_meta($comment->comment_ID, '_wp_trash_meta_status', true);
    if (empty($status)) {
        $status = '0';
    }
    if (wp_set_comment_status($comment, $status)) {
        delete_comment_meta($comment->comment_ID, '_wp_trash_meta_status');
        delete_comment_meta($comment->comment_ID, '_wp_trash_meta_time');
        /**
         * Fires immediately after a comment is unmarked as Spam.
         *
         * @since 2.9.0
         *
         * @param int $comment_id The comment ID.
         */
        do_action('unspammed_comment', $comment->comment_ID);
        return true;
    }
    return false;
}
Beispiel #28
0
/**
 * 
 * Faz a apuração dos votos e toma as devidas ações:
 *    Empate: Mais prazo;
 *    Vencedor: Marco com resolucao e marca o encaminhamento.
 * @param interger $postID
 * @param array $votos
 */
function delibera_computa_votos($postID, $votos = null)
{
    if (is_null($votos)) {
        $votos = delibera_get_comments_votacoes($postID);
    }
    $encaminhamentos = delibera_get_comments_encaminhamentos($postID);
    $encaminhamentos_votos = array();
    foreach ($encaminhamentos as $encaminhamento) {
        $encaminhamentos_votos[$encaminhamento->comment_ID] = 0;
    }
    foreach ($votos as $voto_comment) {
        $voto = get_comment_meta($voto_comment->comment_ID, 'delibera_votos', true);
        foreach ($voto as $voto_para) {
            $encaminhamentos_votos[$voto_para]++;
        }
    }
    $maisvotado = array(-1, -1);
    $iguais = array();
    foreach ($encaminhamentos_votos as $encaminhamentos_voto_key => $encaminhamentos_voto_valor) {
        if ($encaminhamentos_voto_valor > $maisvotado[1]) {
            $maisvotado[0] = $encaminhamentos_voto_key;
            $maisvotado[1] = $encaminhamentos_voto_valor;
            $iguais = array();
        } elseif ($encaminhamentos_voto_valor == $maisvotado[1]) {
            $iguais[] = $encaminhamentos_voto_key;
        }
        delete_comment_meta($encaminhamentos_voto_key, 'delibera_comment_numero_votos');
        add_comment_meta($encaminhamentos_voto_key, 'delibera_comment_numero_votos', $encaminhamentos_voto_valor, true);
    }
    // nao finaliza a votacao caso haja um empate, exceto quando o administrador clicar no botão "Forçar fim do prazo"
    if (count($iguais) > 0 && !(isset($_REQUEST['action']) && $_REQUEST['action'] == 'delibera_forca_fim_prazo_action')) {
        delibera_novo_prazo($postID);
    } else {
        wp_set_object_terms($postID, 'comresolucao', 'situacao', false);
        update_comment_meta($maisvotado[0], 'delibera_comment_tipo', 'resolucao');
        add_post_meta($postID, 'data_resolucao', date('d/m/Y H:i:s'), true);
        ////delibera_notificar_situacao($postID);
        if (has_action('votacao_concluida')) {
            do_action('votacao_concluida', $post);
        }
    }
}
function sf_extend_comment_edit_metafields($comment_id)
{
    if (!isset($_POST['extend_comment_update']) || !wp_verify_nonce($_POST['extend_comment_update'], 'extend_comment_update')) {
        return;
    }
    if (isset($_POST['title']) && $_POST['title'] != '') {
        $title = wp_filter_nohtml_kses($_POST['title']);
        update_comment_meta($comment_id, 'title', $title);
    } else {
        delete_comment_meta($comment_id, 'title');
    }
}
Beispiel #30
0
function extend_comment_edit_metafields($comment_id)
{
    if (!isset($_POST['extend_comment_update']) || !wp_verify_nonce($_POST['extend_comment_update'], 'extend_comment_update')) {
        return;
    }
    if (isset($_POST['class']) && $_POST['class'] != '') {
        $class = wp_filter_nohtml_kses($_POST['class']);
        update_comment_meta($comment_id, 'class', $class);
    } else {
        delete_comment_meta($comment_id, 'class');
    }
    if (isset($_POST['relationship']) && $_POST['relationship'] != '') {
        $relationship = wp_filter_nohtml_kses($_POST['relationship']);
        update_comment_meta($comment_id, 'relationship', $relationship);
    } else {
        delete_comment_meta($comment_id, 'relationship');
    }
}