本文整理汇总了PHP中wp_update_comment_count函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_update_comment_count函数的具体用法?PHP wp_update_comment_count怎么用?PHP wp_update_comment_count使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_update_comment_count函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wp_defer_comment_counting
/**
* 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;
}
示例2: recount
/**
* 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));
}
}
}
示例3: wp_update_comment
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;
}
示例4: update_comments_count
/**
* @param $post_ids
*/
private function update_comments_count($post_ids)
{
foreach ($post_ids as $post_id) {
wp_update_comment_count($post_id);
}
}
示例5: wp_set_comment_status
/**
* 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);
}
示例6: upsert_comment
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']);
}
示例7: moderate
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);
}
示例8: update_fb_comment
/**
* 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);
}
}
}
示例9: insert_content
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);
}
示例10: _btc_import
//.........这里部分代码省略.........
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'])) {
示例11: current_time
$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);
示例12: saveContent
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;
}
}
示例13: btc_db_clear_comment_counts
/**
* 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);
}
}
}