/** * Whether to defer comment counting. * * When setting $defer to true, all post comment counts will not be updated * until $defer is set to false. When $defer is set to false, then all * previously deferred updated post comment counts will then be automatically * updated without having to call wp_update_comment_count() after. * * @since 2.5.0 * @staticvar bool $_defer * * @param bool $defer * @return bool */ function wp_defer_comment_counting($defer = null) { static $_defer = false; if (is_bool($defer)) { $_defer = $defer; // flush any deferred counts if (!$defer) { wp_update_comment_count(null, true); } } return $_defer; }
/** * Recount the comment_count value for one or more posts. * * ## OPTIONS * * <id>... * : IDs for one or more posts to update. * * ## EXAMPLES * * $ wp comment recount 123 * Updated post 123 comment count to 67. */ public function recount($args) { foreach ($args as $id) { wp_update_comment_count($id); $post = get_post($id); if ($post) { WP_CLI::log(sprintf("Updated post %d comment count to %d.", $post->ID, $post->comment_count)); } else { WP_CLI::warning(sprintf("Post %d doesn't exist.", $post->ID)); } } }
function wp_update_comment($commentarr) { global $wpdb; // First, get all of the original fields $comment = get_comment($commentarr['comment_ID'], ARRAY_A); // Escape data pulled from DB. foreach ( (array) $comment as $key => $value ) $comment[$key] = $wpdb->escape($value); // Merge old and new fields with new fields overwriting old ones. $commentarr = array_merge($comment, $commentarr); $commentarr = wp_filter_comment( $commentarr ); // Now extract the merged array. extract($commentarr); $comment_content = apply_filters('comment_save_pre', $comment_content); $comment_date_gmt = get_gmt_from_date($comment_date); $result = $wpdb->query( "UPDATE $wpdb->comments SET comment_content = '$comment_content', comment_author = '$comment_author', comment_author_email = '$comment_author_email', comment_approved = '$comment_approved', comment_author_url = '$comment_author_url', comment_date = '$comment_date', comment_date_gmt = '$comment_date_gmt' WHERE comment_ID = $comment_ID" ); $rval = $wpdb->rows_affected; wp_update_comment_count($comment_post_ID); do_action('edit_comment', $comment_ID); return $rval; }
/** * @param $post_ids */ private function update_comments_count($post_ids) { foreach ($post_ids as $post_id) { wp_update_comment_count($post_id); } }
/** * Hook to wp_set_comment_status action and correctly update the status if necessary * * @param $comment_id (int) The id of the comment */ public function wp_set_comment_status($comment_id) { // Make sure we are working with a comment we have data for if (!isset($this->current_comment->status) || $this->current_comment->comment_ID != $comment_id) { return; } // END if $comment_status = $this->current_comment->status; // Set $this->current_comment back to NULL now that we're finished $this->current_comment = NULL; global $wpdb; // Update comment status with the CORRECT value for this comment $wpdb->update($wpdb->comments, array('comment_approved' => $comment_status), array('comment_ID' => $comment_id)); // We've changed stuff so the cache needs to be cleared again clean_comment_cache($comment_id); // The rest of this is aping default WP behavior to make sure things fire correctly based on the status change do_action('wp_set_comment_status', $comment_id, $comment_status); $comment = get_comment($comment_id); $comment_old = clone get_comment($comment_id); wp_transition_comment_status($comment_status, $comment_old->comment_approved, $comment); wp_update_comment_count($comment->comment_post_ID); }
public function upsert_comment($comment) { global $wpdb, $wp_version; if (version_compare($wp_version, '4.4', '<')) { $comment = (array) $comment; } else { // WP 4.4 introduced the WP_Comment Class $comment = $comment->to_array(); } // filter by fields on comment table $comment_fields_whitelist = array('comment_ID', 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id'); foreach ($comment as $key => $value) { if (!in_array($key, $comment_fields_whitelist)) { unset($comment[$key]); } } $exists = $wpdb->get_var($wpdb->prepare("SELECT EXISTS( SELECT 1 FROM {$wpdb->comments} WHERE comment_ID = %d )", $comment['comment_ID'])); if ($exists) { $wpdb->update($wpdb->comments, $comment, array('comment_ID' => $comment['comment_ID'])); } else { $wpdb->insert($wpdb->comments, $comment); } wp_update_comment_count($comment['comment_post_ID']); }
function moderate($comment_id = 0) { global $wpdb; if (empty($comment_id)) { return false; } // put comment in moderation queue $query = $wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved = '0' WHERE comment_ID = %d", $comment_id); $wpdb->query($query); // recount comment total $comment_data = get_comment($comment_id); wp_update_comment_count($comment_data->comment_post_ID); // email admin about comment $this->notify($comment_id); }
/** * Given a comment construct from the Graph API, make sure that any * comments that we haven't seen before get written into the WP database. * @param stdClass $post A WP post object * @param stdClass $comment A comment construct, sometimes containing replies construct * @param string $parent_id When called recursively (for writing replies to the DB),t his * argument is used to relate the reply to its parent comment. */ private function update_fb_comment($post, $comment, $parent_id = null) { $wp_comment_id = $this->get_wp_comment_for_fb($post->ID, $comment->id); if (!$wp_comment_id) { if (preg_match('/((\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d))T((\\d\\d):(\\d\\d):(\\d\\d))/', $comment->created_time, $matches)) { $gmdate = "{$matches[1]} {$matches[5]}"; } else { $gmdate = gmdate('Y-m-d H:i:s'); } $comment_data = array('comment_post_ID' => $post->ID, 'comment_author' => $comment->from->name, 'comment_content' => $comment->message, 'comment_date' => get_date_from_gmt($gmdate), 'comment_date_gmt' => $gmdate, 'comment_approved' => '1', 'comment_type' => 'facebook', 'comment_author_url' => 'http://facebook.com/profile.php?id=' . $comment->from->id); if (!is_null($parent_id)) { $comment_data['comment_parent'] = $parent_id; } $wp_comment_id = $this->wp_new_comment($comment_data); if ($wp_comment_id && !is_wp_error($wp_comment_id)) { wp_update_comment_count($post->ID); update_comment_meta($wp_comment_id, 'fb_comment', $comment); update_comment_meta($wp_comment_id, 'fb_comment_id', $comment->id); update_comment_meta($wp_comment_id, 'fb_commenter_id', $comment->from->id); } else { // print_r($wp_comment_id); } } if ($comment->comments) { foreach ($comment->comments->data as $reply) { $this->update_fb_comment($post, $reply, $wp_comment_id); } } }
public function insert_content($data) { /** * insert post */ $post = get_page_by_title($data['post_title'], 'OBJECT', 'post'); if (empty($post)) { // insert $data_post = array('post_title' => $data['post_title'], 'post_content' => $data['post_content']); $post_id = wp_insert_post($data_post); // map category / post wp_set_object_terms($post_id, $data['post_category'], 'category'); } else { // update $data_post = array('ID' => $post->ID, 'post_content' => $data['post_content']); wp_update_post($data_post); // map category / post wp_set_object_terms($post->ID, $data['post_category'], 'category'); $comments = get_comments(['post_id' => $post->ID]); global $wpdb; // remove comment $wpdb->delete($wpdb->comments, ['comment_post_ID' => $post->ID]); // remove meta comment foreach ($comments as $comment) { $wpdb->delete($wpdb->commentmeta, ['comment_id' => $comment->comment_ID]); } } /** * insert comment */ foreach ($data['post_comment'] as $comment) { $data_comment = array('comment_post_ID' => $post->ID, 'comment_author' => $comment['author'], 'comment_author_email' => '', 'comment_author_url' => $comment['author_url'], 'comment_content' => $comment['content'], 'comment_type' => '', 'comment_parent' => 0, 'user_id' => 1, 'comment_author_IP' => '127.0.0.1', 'comment_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)', 'comment_date' => $comment['time'], 'comment_approved' => 1); $wpdb->insert($wpdb->comments, $data_comment); } wp_update_comment_count($post->ID); return get_permalink($post->ID); }
/** * Calls BackType API and parses response * * @uses btc_db_comment_counts() * @uses btc_db_dupe_comment() * @uses btc_db_add_comment_type() * @uses btc_db_add_own_blog_comment() * @uses btc_db_add_retweet() * @uses btc_db_set_comment_counts() * @uses btc_db_update_post() * @uses _btc_akismet_check_comment() * @uses _btc_comment_desc() * @uses _btc_filter_content() * @uses _btc_get_filters() * @uses _btc_url_open() * @uses _btc_xml_unserialize() * * @param object $btc_post Post to call API for * @return array Status */ function _btc_import(&$btc_post) { $filters = _btc_get_filters(); $page = 1; $processed = false; $error = 0; $url = get_permalink($btc_post->ID); $itemsperpage = '25'; $params = array('identifier' => 'btc', 'url' => $url, 'key' => get_option(BTC_API_KEY_OPTION), 'page' => '1', 'sort' => '1', 'itemsperpage' => $itemsperpage); do { btc_log('Fetching: ' . BTC_API_CONNECT_URL . '?' . http_build_query($params, null, '&'), 'debug'); if (!($contents = _btc_url_open(BTC_API_CONNECT_URL . '?' . http_build_query($params, null, '&')))) { btc_log('Failed opening url: ' . BTC_API_CONNECT_URL . '?' . http_build_query($params, null, '&'), 'error'); $error = 1; break; } $xml = _btc_xml_unserialize($contents['body']); unset($contents); if (class_exists('SimpleXMLElement')) { if (!$xml || !empty($xml->errorCode) || empty($xml->comments)) { if (!empty($xml->errorCode) && $xml->errorCode == 'related-conversations-not-found' || (int) $xml->totalresults == 0) { $btc_post->last_import_date_gmt = gmdate('Y-m-d H:i:s'); $btc_post->misses = (int) $btc_post->misses + 1; btc_db_update_post($btc_post); btc_log('No related conversations.', 'error'); $error = 2; } else { if ($xml && empty($xml->comments->entry) && (int) $xml->startindex > (int) $xml->totalresults) { btc_log('Paginated too far.', 'error'); //.. } else { btc_log('Unknown XML error.', 'error'); $error = 3; } } break; } if (empty($xml->comments->entry) || !count($xml->comments->entry)) { btc_log('No comments.', 'debug'); break; } require_once BTC_DIR . '/db.php'; $new = 0; btc_log('Comments received: ' . count($xml->comments->entry), 'debug'); $comments = array(); $ignore_own_blog = get_option(BTC_IGNORE_OWN_BLOG_OPTION); $ignore_retweets = get_option(BTC_IGNORE_RETWEETS_OPTION); $siteurl = get_option('siteurl'); $site_pieces = parse_url($siteurl); $site_domain = isset($site_pieces['host']) ? trim($site_pieces['host'], '/') : ''; $site_path = isset($site_pieces['path']) ? trim($site_pieces['path'], '/') : ''; foreach ($xml->comments->entry as $entry) { if ($entry['type'] == 'comment') { $entry_pieces = parse_url($entry->blog->url); $entry_domain = isset($entry_pieces['host']) ? trim($entry_pieces['host'], '/') : ''; $entry_path = isset($entry_pieces['path']) ? trim($entry_pieces['path'], '/') : ''; $is_own_blog = $site_domain == $entry_domain && $site_path == $entry_path ? 1 : 0; $is_retweet = 0; $commentdata = array('comment_post_ID' => $btc_post->ID, 'comment_author' => $entry->author->name ? trim($entry->author->name) : 'Anonymous', 'comment_author_email' => '', 'comment_author_url' => trim($entry->author->url), 'comment_author_IP' => '', 'comment_date' => date('Y-m-d H:i:s', strtotime(trim($entry->comment->date)) + get_option('gmt_offset') * 3600), 'comment_date_gmt' => date('Y-m-d H:i:s', strtotime(trim($entry->comment->date))), 'comment_content' => _btc_filter_content($entry->comment->content), 'comment_approved' => $ignore_own_blog && $is_own_blog ? 'ignored' : (get_option(BTC_MODERATION_OPTION) ? '0' : '1'), 'comment_agent' => 'btc_' . $entry['src'], 'comment_type' => '', 'comment_parent' => ''); $desc = array('comment_src' => $entry['src'], 'site_url' => trim($entry->blog->url), 'site_title' => trim($entry->blog->title), 'post_url' => trim($entry->post->url), 'post_title' => $entry->post->title ? trim($entry->post->title) : trim($entry->blog->title), 'comment_url' => trim($entry->comment->url)); } elseif ($entry['type'] == 'tweet') { $is_own_blog = 0; $is_retweet = substr(strtolower($entry->tweet_text), 0, 2) == 'rt' ? 1 : 0; $commentdata = array('comment_post_ID' => $btc_post->ID, 'comment_author' => trim($entry->tweet_from_user), 'comment_author_email' => '', 'comment_author_url' => 'http://twitter.com/' . trim($entry->tweet_from_user), 'comment_author_IP' => '', 'comment_date' => date('Y-m-d H:i:s', strtotime(trim($entry->tweet_created_at)) + get_option('gmt_offset') * 3600), 'comment_date_gmt' => date('Y-m-d H:i:s', strtotime(trim($entry->tweet_created_at))), 'comment_content' => _btc_filter_content($entry->tweet_text), 'comment_approved' => $ignore_retweets && $is_retweet ? 'ignored' : (get_option(BTC_MODERATION_OPTION) ? '0' : '1'), 'comment_agent' => 'btc_twitter', 'comment_type' => '', 'comment_parent' => ''); $desc = array('comment_src' => 'twitter', 'site_url' => 'http://twitter.com/', 'site_title' => 'Twitter', 'post_url' => 'http://twitter.com/' . trim($entry->tweet_from_user) . '/statuses/' . $entry->tweet_id, 'post_title' => trim($entry->tweet_text), 'comment_url' => 'http://twitter.com/' . trim($entry->tweet_from_user) . '/statuses/' . $entry->tweet_id); } $commentdata['comment_content'] .= _btc_comment_desc($desc); if (!btc_db_dupe_comment($commentdata)) { if (get_option(BTC_AKISMET_OPTION) && function_exists('akismet_auto_check_comment')) { $commentdata = _btc_akismet_check_comment($commentdata); } if (in_array($desc['comment_src'], $filters['srcs'])) { $commentdata['comment_approved'] = 'd_' . $commentdata['comment_approved']; } if ($comment_ID = wp_insert_comment($commentdata)) { $dupes = btc_db_dupe_clean($comment_ID); if (count($dupes) > 0) { btc_db_delete_dupe_comment($comment_ID); continue; } if ($is_own_blog) { btc_db_add_own_blog_comment($btc_post->ID, $comment_ID); } elseif ($is_retweet) { btc_db_add_retweet($btc_post->ID, $comment_ID); } btc_db_add_comment_type($btc_post->ID, $commentdata['comment_agent'], $comment_ID); $new++; } } } btc_log('Inserted ' . $new . ' new comments.', 'debug'); // paginate if ($new) { $btc_post->last_import_date_gmt = gmdate('Y-m-d H:i:s'); $btc_post->hits = (int) $btc_post->hits + $new; btc_db_update_post($btc_post); if ($new == (int) $itemsperpage && isset($xml->next_page)) { $params['page'] = (int) $xml->next_page; } else { $btc_counts = btc_db_comment_counts($btc_post->ID); btc_db_set_comment_counts($btc_post->ID, $btc_counts); if (function_exists('wp_update_comment_count')) { wp_update_comment_count($btc_post->ID); } $btc_summary = btc_db_comment_summary($btc_post->ID); btc_db_set_comment_summary($btc_post->ID, $btc_summary); $processed = true; } } else { $btc_post->last_import_date_gmt = gmdate('Y-m-d H:i:s'); $btc_post->misses = (int) $btc_post->misses + 1; btc_db_update_post($btc_post); $processed = true; } } else { if (!$xml || !empty($xml['error']['errorCode']) || empty($xml['feed']['comments'])) { if (!empty($xml['error']['errorCode']) && $xml['error']['errorCode'] == 'related-conversations-not-found') { $btc_post->last_import_date_gmt = gmdate('Y-m-d H:i:s'); $btc_post->misses = (int) $btc_post->misses + 1; btc_db_update_post($btc_post); btc_log('No related conversations.', 'error'); $error = 2; } else { if ($xml && empty($xml['feed']['comments']['entry']) && (int) $xml['feed']['startindex'] > (int) $xml['feed']['totalresults']) { btc_log('Paginated too far.', 'error'); //.. } else { btc_log('Unknown XML error.', 'error'); $error = 3; } } break; } if (empty($xml['feed']['comments']['entry']) || !count($xml['feed']['comments']['entry'])) { btc_log('No comments.', 'debug'); break; } require_once BTC_DIR . '/db.php'; $new = 0; btc_log('Comments received: ' . count($xml['feed']['comments']['entry']), 'debug'); $comments = array(); $ignore_own_blog = get_option(BTC_IGNORE_OWN_BLOG_OPTION); $ignore_retweets = get_option(BTC_IGNORE_RETWEETS_OPTION); $siteurl = get_option('siteurl'); $site_pieces = parse_url($siteurl); $site_domain = isset($site_pieces['host']) ? trim($site_pieces['host'], '/') : ''; $site_path = isset($site_pieces['path']) ? trim($site_pieces['path'], '/') : ''; foreach ($xml['feed']['comments']['entry'] as $key => $value) { if (is_int($key)) { $entry = $value; $entry['type'] = $type; $entry['src'] = $src; } else { $type = $value['type']; $src = isset($value['src']) ? $value['src'] : ''; continue; } if ($entry['type'] == 'comment') { $entry_pieces = parse_url($entry['blog']['url']); $entry_domain = isset($entry_pieces['host']) ? trim($entry_pieces['host'], '/') : ''; $entry_path = isset($entry_pieces['path']) ? trim($entry_pieces['path'], '/') : ''; $is_own_blog = $site_domain == $entry_domain && $site_path == $entry_path ? 1 : 0; $is_retweet = 0; $commentdata = array('comment_post_ID' => $btc_post->ID, 'comment_author' => $entry['author']['name'] ? trim($entry['author']['name']) : 'Anonymous', 'comment_author_email' => '', 'comment_author_url' => trim($entry['author']['url']), 'comment_author_IP' => '', 'comment_date' => date('Y-m-d H:i:s', strtotime(trim($entry['comment']['date'])) + get_option('gmt_offset') * 3600), 'comment_date_gmt' => date('Y-m-d H:i:s', strtotime(trim($entry['comment']['date']))), 'comment_content' => _btc_filter_content($entry['comment']['content']), 'comment_approved' => $ignore_own_blog && $is_own_blog ? 'ignored' : (get_option(BTC_MODERATION_OPTION) ? '0' : '1'), 'comment_agent' => 'btc_' . $entry['src'], 'comment_type' => '', 'comment_parent' => ''); $desc = array('comment_src' => $entry['src'], 'site_url' => trim($entry['blog']['url']), 'site_title' => trim($entry['blog']['title']), 'post_url' => trim($entry['post']['url']), 'post_title' => $entry['post']['title'] ? trim($entry['post']['title']) : trim($entry['blog']['title']), 'comment_url' => trim($entry['comment']['url'])); } elseif ($entry['type'] == 'tweet') { $is_own_blog = 0; $is_retweet = substr(strtolower($entry['tweet_text']), 0, 2) == 'rt' ? 1 : 0; $commentdata = array('comment_post_ID' => $btc_post->ID, 'comment_author' => trim($entry['tweet_from_user']), 'comment_author_email' => '', 'comment_author_url' => 'http://twitter.com/' . trim($entry['tweet_from_user']), 'comment_author_IP' => '', 'comment_date' => date('Y-m-d H:i:s', strtotime(trim($entry['tweet_created_at'])) + get_option('gmt_offset') * 3600), 'comment_date_gmt' => date('Y-m-d H:i:s', strtotime(trim($entry['tweet_created_at']))), 'comment_content' => _btc_filter_content($entry['tweet_text']), 'comment_approved' => $ignore_retweets && $is_retweet ? 'ignored' : (get_option(BTC_MODERATION_OPTION) ? '0' : '1'), 'comment_agent' => 'btc_twitter', 'comment_type' => '', 'comment_parent' => ''); $desc = array('comment_src' => 'twitter', 'site_url' => 'http://twitter.com/', 'site_title' => 'Twitter', 'post_url' => 'http://twitter.com/' . trim($entry['tweet_from_user']) . '/statuses/' . $entry['tweet_id'], 'post_title' => trim($entry['tweet_text']), 'comment_url' => 'http://twitter.com/' . trim($entry['tweet_from_user']) . '/statuses/' . $entry['tweet_id']); } $commentdata['comment_content'] .= _btc_comment_desc($desc); if (!btc_db_dupe_comment($commentdata)) { if (get_option(BTC_AKISMET_OPTION) && function_exists('akismet_auto_check_comment')) { $commentdata = _btc_akismet_check_comment($commentdata); } if (in_array($desc['comment_src'], $filters['srcs'])) { $commentdata['comment_approved'] = 'd_' . $commentdata['comment_approved']; } if ($comment_ID = wp_insert_comment($commentdata)) { $dupes = btc_db_dupe_comment($commentdata); if (count($dupes) > 1 && $comment_ID > min($dupes)) { btc_db_delete_dupe_comment($comment_ID); continue; } if ($is_own_blog) { btc_db_add_own_blog_comment($btc_post->ID, $comment_ID); } elseif ($is_retweet) { btc_db_add_retweet($btc_post->ID, $comment_ID); } btc_db_add_comment_type($btc_post->ID, $commentdata['comment_agent'], $comment_ID); $new++; } } } btc_log('Inserted ' . $new . ' new comments.', 'debug'); // paginate if ($new) { $btc_post->last_import_date_gmt = gmdate('Y-m-d H:i:s'); $btc_post->hits = (int) $btc_post->hits + $new; btc_db_update_post($btc_post); if ($new == (int) $itemsperpage && isset($xml['feed']['next_page'])) { $params['page'] = (int) $xml['feed']['next_page']; } else { $btc_counts = btc_db_comment_counts($btc_post->ID); btc_db_set_comment_counts($btc_post->ID, $btc_counts); if (function_exists('wp_update_comment_count')) { wp_update_comment_count($btc_post->ID); } $btc_summary = btc_db_comment_summary($btc_post->ID); btc_db_set_comment_summary($btc_post->ID, $btc_summary); $processed = true; } } else { $btc_post->last_import_date_gmt = gmdate('Y-m-d H:i:s'); $btc_post->misses = (int) $btc_post->misses + 1; btc_db_update_post($btc_post); $processed = true; } } } while (!$processed && !$error); if (!$error) { return array('success' => 1); } else { if ($error == 1) { if ($page == 1) { return array('success' => 0, 'message' => 'Could not open the URL.'); } else { return array('success' => 0, 'message' => 'Could not open some of the URLs.'); } } else { if ($error == 2) { return array('success' => 0, 'message' => 'No related conversations were found.'); } else { return array('success' => 0, 'message' => 'An unknown error occurred.'); } } } }
$comment_author_url = !isset($data['comment_author_url']) ? '' : $data['comment_author_url']; $comment_author_IP = !isset($data['comment_author_IP']) ? '' : $data['comment_author_IP']; $comment_date = !isset($data['comment_date']) ? current_time('mysql') : $data['comment_date']; $comment_date_gmt = !isset($data['comment_date_gmt']) ? get_gmt_from_date($comment_date) : $data['comment_date_gmt']; $comment_post_ID = $data['comment_post_ID']; $comment_content = htmlspecialchars($data['comment_content']); $comment_karma = !isset($data['comment_karma']) ? 0 : $data['comment_karma']; $comment_approved = !isset($data['comment_approved']) ? 1 : $data['comment_approved']; $comment_agent = !isset($data['comment_agent']) ? '' : $data['comment_agent']; $comment_type = !isset($data['comment_type']) ? '' : $data['comment_type']; $comment_parent = !isset($data['comment_parent']) ? 0 : $data['comment_parent']; $user_id = !isset($data['user_id']) ? 0 : $data['user_id']; $compacted = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id'); if (!$wpdb->insert($wpdb->comments, $compacted)) { $result['status_msg'] = "数据库响应出错,请联系网站管理人员"; echo json_encode($result); exit(0); } $id = (int) $wpdb->insert_id; if ($comment_approved == 1) { wp_update_comment_count($comment_post_ID); } $comment = get_comment($id); // If metadata is provided, store it. if (isset($commentdata['comment_meta']) && is_array($commentdata['comment_meta'])) { foreach ($commentdata['comment_meta'] as $meta_key => $meta_value) { add_comment_meta($comment->comment_ID, $meta_key, $meta_value, true); } } $result['status_msg'] = '完成,没有错误'; echo json_encode($result);
public function saveContent($content) { global $wpdb; if ($content == $this->comment->comment_content) { return true; } else { $this->comment->comment_content = $content; $rval = $wpdb->update($wpdb->comments, (array) $this->comment, array('comment_ID' => $this->getId())); clean_comment_cache($this->getId()); wp_update_comment_count($this->getThreadId()); return $rval; } }
/** * Clear cached comment counts * * @uses btc_db_get_post_IDs() * * @param int $ID Post ID */ function btc_db_clear_comment_counts($ID = null, $wp_update = true) { if ($ID == null) { $posts = btc_db_get_post_IDs(); foreach ($posts as $post_ID) { delete_post_meta($post_ID, 'btc_comment_counts'); if (function_exists('wp_update_comment_count') && $wp_update) { wp_update_comment_count($post_ID); } } } else { delete_post_meta($ID, 'btc_comment_counts'); if (function_exists('wp_update_comment_count') && $wp_update) { wp_update_comment_count($ID); } } }