50 if ( $max_links =
get_option(
'comment_max_links' ) ) {
51 $num_links = preg_match_all(
'/<a [^>]*href/i', $comment,
$out );
53 if ( $num_links >= $max_links )
57 $mod_keys = trim(
get_option(
'moderation_keys'));
58 if ( !empty($mod_keys) ) {
59 $words = explode(
"\n", $mod_keys );
61 foreach ( (array) $words as $word) {
70 $word = preg_quote($word,
'#');
72 $pattern =
"#$word#i";
73 if ( preg_match($pattern, $author) )
return false;
74 if ( preg_match($pattern, $email) )
return false;
75 if ( preg_match($pattern,
$url) )
return false;
76 if ( preg_match($pattern, $comment) )
return false;
77 if ( preg_match($pattern, $user_ip) )
return false;
78 if ( preg_match($pattern, $user_agent) )
return false;
86 $ok_to_comment = $wpdb->get_var(
"SELECT comment_approved FROM $wpdb->comments WHERE comment_author = '$author' AND comment_author_email = '$email' and comment_approved = '1' LIMIT 1");
87 if ( ( 1 == $ok_to_comment ) &&
88 ( empty($mod_keys) ||
false === strpos( $email, $mod_keys) ) )
110 return $wpdb->get_results($wpdb->prepare(
"SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' ORDER BY comment_date",
$post_id));
134 if ( empty($comment) ) {
139 }
elseif ( is_object($comment) ) {
140 wp_cache_add($comment->comment_ID, $comment,
'comment');
141 $_comment = $comment;
146 $_comment = $wpdb->get_row($wpdb->prepare(
"SELECT * FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment));
149 wp_cache_add($_comment->comment_ID, $_comment,
'comment');
155 if ( $output ==
OBJECT ) {
158 $__comment = get_object_vars($_comment);
161 $__comment = array_values(get_object_vars($_comment));
214 'author_email' =>
'',
245 $this->meta_query->parse_query_vars( $this->query_vars );
248 extract( $this->query_vars, EXTR_SKIP );
251 $key = md5( serialize( compact(array_keys($defaults)) ) );
252 $last_changed =
wp_cache_get(
'last_changed',
'comment' );
253 if ( ! $last_changed )
254 $last_changed =
wp_cache_set(
'last_changed', 1,
'comment' );
255 $cache_key =
"get_comments:$key:$last_changed";
263 $approved =
"comment_approved = '0'";
265 $approved =
"comment_approved = '1'";
267 $approved = $wpdb->prepare(
"comment_approved = %s",
$status );
269 $approved =
"( comment_approved = '0' OR comment_approved = '1' )";
271 $order = (
'ASC' == strtoupper($order) ) ?
'ASC' :
'DESC';
273 if ( ! empty( $orderby ) ) {
274 $ordersby = is_array($orderby) ? $orderby : preg_split(
'/[,\s]/', $orderby);
275 $allowed_keys = array(
279 'comment_author_email',
281 'comment_author_url',
292 if ( ! empty( $this->query_vars[
'meta_key'] ) ) {
293 $allowed_keys[] = $this->query_vars[
'meta_key'];
294 $allowed_keys[] =
'meta_value';
295 $allowed_keys[] =
'meta_value_num';
297 $ordersby = array_intersect( $ordersby, $allowed_keys );
298 foreach ( $ordersby as
$key => $value ) {
299 if ( $value == $this->query_vars[
'meta_key'] || $value ==
'meta_value' ) {
300 $ordersby[
$key ] =
"$wpdb->commentmeta.meta_value";
301 }
elseif ( $value ==
'meta_value_num' ) {
302 $ordersby[
$key ] =
"$wpdb->commentmeta.meta_value+0";
305 $orderby = empty( $ordersby ) ?
'comment_date_gmt' : implode(
', ', $ordersby);
307 $orderby =
'comment_date_gmt';
310 $number =
absint($number);
311 $offset =
absint($offset);
313 if ( !empty($number) ) {
315 $limits =
'LIMIT ' . $offset .
',' . $number;
317 $limits =
'LIMIT ' . $number;
323 $fields =
'COUNT(*)';
331 $where .= $wpdb->prepare(
' AND comment_post_ID = %d',
$post_id );
332 if (
'' !== $author_email )
333 $where .= $wpdb->prepare(
' AND comment_author_email = %s', $author_email );
335 $where .= $wpdb->prepare(
' AND comment_karma = %d', $karma );
336 if (
'comment' ==
$type ) {
337 $where .=
" AND comment_type = ''";
339 $where .=
' AND comment_type IN ("pingback", "trackback")';
341 $where .= $wpdb->prepare(
' AND comment_type = %s',
$type );
343 if (
'' !== $parent )
344 $where .= $wpdb->prepare(
' AND comment_parent = %d', $parent );
346 $where .= $wpdb->prepare(
' AND user_id = %d',
$user_id );
347 if (
'' !== $search )
348 $where .= $this->
get_search_sql( $search, array(
'comment_author',
'comment_author_email',
'comment_author_url',
'comment_author_IP',
'comment_content' ) );
350 $post_fields = array_filter( compact( array(
'post_author',
'post_name',
'post_parent',
'post_status',
'post_type', ) ) );
351 if ( ! empty( $post_fields ) ) {
352 $join =
"JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID";
353 foreach( $post_fields as $field_name => $field_value )
354 $where .= $wpdb->prepare(
" AND {$wpdb->posts}.{$field_name} = %s", $field_value );
357 if ( ! empty( $this->meta_query->queries ) ) {
358 $clauses = $this->meta_query->get_sql(
'comment', $wpdb->comments,
'comment_ID', $this );
359 $join .= $clauses[
'join'];
360 $where .= $clauses[
'where'];
361 $groupby =
"{$wpdb->comments}.comment_ID";
364 $pieces = array(
'fields',
'join',
'where',
'orderby',
'order',
'limits',
'groupby' );
366 foreach ( $pieces as $piece )
367 $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] :
'';
370 $groupby =
'GROUP BY ' . $groupby;
372 $query =
"SELECT $fields FROM $wpdb->comments $join WHERE $where $groupby ORDER BY $orderby $order $limits";
375 return $wpdb->get_var( $query );
377 $comments = $wpdb->get_results( $query );
399 foreach (
$cols as $col )
400 $searches[] =
"$col LIKE '%$string%'";
402 return ' AND (' . implode(
' OR ', $searches) .
')';
420 'hold' =>
__(
'Unapproved'),
422 'approve' =>
_x(
'Approved',
'adjective'),
424 'spam' =>
_x(
'Spam',
'adjective'),
442 static $cache_lastcommentmodified = array();
444 if ( isset($cache_lastcommentmodified[$timezone]) )
445 return $cache_lastcommentmodified[$timezone];
447 $add_seconds_server = date(
'Z');
449 switch ( strtolower($timezone)) {
451 $lastcommentmodified = $wpdb->get_var(
"SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1");
454 $lastcommentmodified = $wpdb->get_var(
"SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1");
457 $lastcommentmodified = $wpdb->get_var($wpdb->prepare(
"SELECT DATE_ADD(comment_date_gmt, INTERVAL %s SECOND) FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1", $add_seconds_server));
461 $cache_lastcommentmodified[$timezone] = $lastcommentmodified;
463 return $lastcommentmodified;
486 $where = $wpdb->prepare(
"WHERE comment_post_ID = %d",
$post_id);
489 $totals = (array) $wpdb->get_results(
"
490 SELECT comment_approved, COUNT( * ) AS total
491 FROM {$wpdb->comments}
493 GROUP BY comment_approved
496 $comment_count = array(
498 "awaiting_moderation" => 0,
500 "total_comments" => 0
504 switch ( $row[
'comment_approved'] ) {
506 $comment_count[
'spam'] = $row[
'total'];
507 $comment_count[
"total_comments"] += $row[
'total'];
510 $comment_count[
'approved'] = $row[
'total'];
511 $comment_count[
'total_comments'] += $row[
'total'];
514 $comment_count[
'awaiting_moderation'] = $row[
'total'];
515 $comment_count[
'total_comments'] += $row[
'total'];
522 return $comment_count;
543 return add_metadata(
'comment', $comment_id, $meta_key, $meta_value, $unique);
563 return delete_metadata(
'comment', $comment_id, $meta_key, $meta_value);
602 return update_metadata(
'comment', $comment_id, $meta_key, $meta_value, $prev_value);
615 if (
$user->exists() )
618 $comment_cookie_lifetime =
apply_filters(
'comment_cookie_lifetime', 30000000);
619 setcookie(
'comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH,
COOKIE_DOMAIN);
620 setcookie(
'comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH,
COOKIE_DOMAIN);
621 setcookie(
'comment_author_url_' . COOKIEHASH,
esc_url($comment->comment_author_url), time() + $comment_cookie_lifetime, COOKIEPATH,
COOKIE_DOMAIN);
633 if ( isset(
$_COOKIE[
'comment_author_'.COOKIEHASH]) ) {
640 if ( isset(
$_COOKIE[
'comment_author_email_'.COOKIEHASH]) ) {
647 if ( isset(
$_COOKIE[
'comment_author_url_'.COOKIEHASH]) ) {
668 extract($commentdata, EXTR_SKIP);
672 $dupe =
"SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND comment_parent = '$comment_parent' AND comment_approved != 'trash' AND ( comment_author = '$comment_author' ";
674 $dupe .=
"OR comment_author_email = '$comment_author_email' ";
675 $dupe .=
") AND comment_content = '$comment_content' LIMIT 1";
676 if ( $wpdb->get_var($dupe) ) {
677 do_action(
'comment_duplicate_trigger', $commentdata );
678 if ( defined(
'DOING_AJAX') )
679 die(
__(
'Duplicate comment detected; it looks as though you’ve already said that!') );
681 wp_die(
__(
'Duplicate comment detected; it looks as though you’ve already said that!') );
688 $post_author = $wpdb->get_var($wpdb->prepare(
"SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1",
$comment_post_ID));
691 if ( isset(
$user ) && (
$user_id == $post_author ||
$user->has_cap(
'moderate_comments' ) ) ) {
704 $approved =
apply_filters(
'pre_comment_approved', $approved, $commentdata );
729 $hour_ago = gmdate(
'Y-m-d H:i:s', time() - HOUR_IN_SECONDS );
730 if ( $lasttime = $wpdb->get_var( $wpdb->prepare(
"SELECT `comment_date_gmt` FROM `$wpdb->comments` WHERE `comment_date_gmt` >= %s AND ( `comment_author_IP` = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1", $hour_ago, $ip, $email ) ) ) {
731 $time_lastcomment =
mysql2date(
'U', $lasttime,
false);
733 $flood_die =
apply_filters(
'comment_flood_filter',
false, $time_lastcomment, $time_newcomment);
735 do_action(
'comment_flood_trigger', $time_lastcomment, $time_newcomment);
737 if ( defined(
'DOING_AJAX') )
738 die(
__(
'You are posting comments too quickly. Slow down.') );
740 wp_die(
__(
'You are posting comments too quickly. Slow down.'),
'', array(
'response' => 403) );
754 $comments_by_type = array(
'comment' => array(),
'trackback' => array(),
'pingback' => array(),
'pings' => array());
761 if (
'trackback' ==
$type ||
'pingback' ==
$type )
765 return $comments_by_type;
784 if (
null ===
$comments &&
null === $per_page &&
null === $threaded && !empty($wp_query->max_num_comment_pages) )
785 return $wp_query->max_num_comment_pages;
793 if ( !isset($per_page) )
795 if ( 0 === $per_page )
796 $per_page = (int)
get_option(
'comments_per_page');
797 if ( 0 === $per_page )
800 if ( !isset($threaded) )
805 $count = ceil( $walker->get_number_of_root_elements(
$comments ) / $per_page );
831 $defaults = array(
'type' =>
'all',
'page' =>
'',
'per_page' =>
'',
'max_depth' =>
'' );
836 if ( empty(
$args[
'per_page']) ) {
837 $args[
'per_page'] = 0;
840 if (
$args[
'per_page'] < 1 )
843 if (
'' ===
$args[
'max_depth'] ) {
847 $args[
'max_depth'] = -1;
851 if (
$args[
'max_depth'] > 1 && 0 != $comment->comment_parent )
854 $allowedtypes = array(
856 'pingback' =>
'pingback',
857 'trackback' =>
'trackback',
860 $comtypewhere = (
'all' !=
$args[
'type'] && isset($allowedtypes[
$args[
'type']]) ) ?
" AND comment_type = '" . $allowedtypes[$args[
'type']] .
"'" :
'';
863 $oldercoms = $wpdb->get_var( $wpdb->prepare(
"SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_approved = '1' AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ) );
866 if ( 0 == $oldercoms )
870 return ceil( ( $oldercoms + 1 ) / $args[
'per_page'] );
888 do_action(
'wp_blacklist_check', $author, $email,
$url, $comment, $user_ip, $user_agent);
890 $mod_keys = trim(
get_option(
'blacklist_keys') );
891 if (
'' == $mod_keys )
893 $words = explode(
"\n", $mod_keys );
895 foreach ( (array) $words as $word ) {
899 if ( empty($word) ) {
continue; }
903 $word = preg_quote($word,
'#');
905 $pattern =
"#$word#i";
907 preg_match($pattern, $author)
908 || preg_match($pattern, $email)
909 || preg_match($pattern,
$url)
910 || preg_match($pattern, $comment)
911 || preg_match($pattern, $user_ip)
912 || preg_match($pattern, $user_agent)
941 if ( !empty($stats) )
951 $where = $wpdb->prepare(
"WHERE comment_post_ID = %d",
$post_id );
953 $count = $wpdb->get_results(
"SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved",
ARRAY_A );
956 $approved = array(
'0' =>
'moderated',
'1' =>
'approved',
'spam' =>
'spam',
'trash' =>
'trash',
'post-trashed' =>
'post-trashed');
957 foreach ( (array)
$count as $row ) {
959 if (
'post-trashed' != $row[
'comment_approved'] &&
'trash' != $row[
'comment_approved'] )
960 $total += $row[
'num_comments'];
961 if ( isset( $approved[$row[
'comment_approved']] ) )
962 $stats[$approved[$row[
'comment_approved']]] = $row[
'num_comments'];
965 $stats[
'total_comments'] =
$total;
966 foreach ( $approved as
$key ) {
967 if ( empty($stats[$key]) )
971 $stats = (object) $stats;
1002 if ( !$force_delete && EMPTY_TRASH_DAYS && !in_array(
wp_get_comment_status($comment_id), array(
'trash',
'spam' ) ) )
1005 do_action(
'delete_comment', $comment_id);
1008 $children = $wpdb->get_col( $wpdb->prepare(
"SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = %d", $comment_id) );
1009 if ( !empty($children) ) {
1010 $wpdb->update($wpdb->comments, array(
'comment_parent' => $comment->comment_parent), array(
'comment_parent' => $comment_id));
1015 $meta_ids = $wpdb->get_col( $wpdb->prepare(
"SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment_id ) );
1016 foreach ( $meta_ids as $mid )
1019 if ( ! $wpdb->delete( $wpdb->comments, array(
'comment_ID' => $comment_id ) ) )
1021 do_action(
'deleted_comment', $comment_id);
1023 $post_id = $comment->comment_post_ID;
1024 if (
$post_id && $comment->comment_approved == 1 )
1029 do_action(
'wp_set_comment_status', $comment_id,
'delete');
1048 if ( !EMPTY_TRASH_DAYS )
1054 do_action(
'trash_comment', $comment_id);
1057 add_comment_meta($comment_id,
'_wp_trash_meta_status', $comment->comment_approved);
1059 do_action(
'trashed_comment', $comment_id);
1077 if ( ! (
int)$comment_id )
1080 do_action(
'untrash_comment', $comment_id);
1089 do_action(
'untrashed_comment', $comment_id);
1113 add_comment_meta($comment_id,
'_wp_trash_meta_status', $comment->comment_approved);
1114 do_action(
'spammed_comment', $comment_id);
1132 if ( ! (
int)$comment_id )
1135 do_action(
'unspam_comment', $comment_id);
1143 do_action(
'unspammed_comment', $comment_id);
1163 $approved = $comment->comment_approved;
1165 if ( $approved ==
null )
1167 elseif ( $approved ==
'1' )
1169 elseif ( $approved ==
'0' )
1170 return 'unapproved';
1171 elseif ( $approved ==
'spam' )
1173 elseif ( $approved ==
'trash' )
1202 $comment_statuses = array(
1204 'hold' =>
'unapproved',
1206 'approve' =>
'approved',
1208 if ( isset($comment_statuses[$new_status]) ) $new_status = $comment_statuses[$new_status];
1209 if ( isset($comment_statuses[$old_status]) ) $old_status = $comment_statuses[$old_status];
1212 if ( $new_status != $old_status ) {
1213 do_action(
'transition_comment_status', $new_status, $old_status, $comment);
1214 do_action(
"comment_{$old_status}_to_{$new_status}", $comment);
1216 do_action(
"comment_{$new_status}_{$comment->comment_type}", $comment->comment_ID, $comment);
1235 if ( isset(
$_COOKIE[
'comment_author_'.COOKIEHASH]) )
1239 if ( isset(
$_COOKIE[
'comment_author_email_'.COOKIEHASH]) )
1243 if ( isset(
$_COOKIE[
'comment_author_url_'.COOKIEHASH]) )
1246 return apply_filters(
'wp_get_current_commenter', compact(
'comment_author',
'comment_author_email',
'comment_author_url'));
1265 if ( ! isset($comment_author_IP) )
1266 $comment_author_IP =
'';
1267 if ( ! isset($comment_date) )
1269 if ( ! isset($comment_date_gmt) )
1271 if ( ! isset($comment_parent) )
1272 $comment_parent = 0;
1273 if ( ! isset($comment_approved) )
1274 $comment_approved = 1;
1275 if ( ! isset($comment_karma) )
1282 $data = 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');
1283 $wpdb->insert($wpdb->comments, $data);
1285 $id = (int) $wpdb->insert_id;
1287 if ( $comment_approved == 1 )
1293 if ( function_exists(
'wp_cache_incr' ) ) {
1296 $last_changed =
wp_cache_get(
'last_changed',
'comment' );
1297 wp_cache_set(
'last_changed', $last_changed + 1,
'comment' );
1323 if ( isset($commentdata[
'user_ID']) )
1324 $commentdata[
'user_id'] =
apply_filters(
'pre_user_id', $commentdata[
'user_ID']);
1325 elseif ( isset($commentdata[
'user_id']) )
1326 $commentdata[
'user_id'] =
apply_filters(
'pre_user_id', $commentdata[
'user_id']);
1327 $commentdata[
'comment_agent'] =
apply_filters(
'pre_comment_user_agent', ( isset( $commentdata[
'comment_agent'] ) ? $commentdata[
'comment_agent'] :
'' ) );
1328 $commentdata[
'comment_author'] =
apply_filters(
'pre_comment_author_name', $commentdata[
'comment_author']);
1329 $commentdata[
'comment_content'] =
apply_filters(
'pre_comment_content', $commentdata[
'comment_content']);
1330 $commentdata[
'comment_author_IP'] =
apply_filters(
'pre_comment_user_ip', $commentdata[
'comment_author_IP']);
1331 $commentdata[
'comment_author_url'] =
apply_filters(
'pre_comment_author_url', $commentdata[
'comment_author_url']);
1332 $commentdata[
'comment_author_email'] =
apply_filters(
'pre_comment_author_email', $commentdata[
'comment_author_email']);
1333 $commentdata[
'filtered'] =
true;
1334 return $commentdata;
1350 if ( ($time_newcomment - $time_lastcomment) < 15 )
1378 $commentdata =
apply_filters(
'preprocess_comment', $commentdata);
1380 $commentdata[
'comment_post_ID'] = (int) $commentdata[
'comment_post_ID'];
1381 if ( isset($commentdata[
'user_ID']) )
1382 $commentdata[
'user_id'] = $commentdata[
'user_ID'] = (
int) $commentdata[
'user_ID'];
1383 elseif ( isset($commentdata[
'user_id']) )
1384 $commentdata[
'user_id'] = (int) $commentdata[
'user_id'];
1386 $commentdata[
'comment_parent'] = isset($commentdata[
'comment_parent']) ?
absint($commentdata[
'comment_parent']) : 0;
1387 $parent_status = ( 0 < $commentdata[
'comment_parent'] ) ?
wp_get_comment_status($commentdata[
'comment_parent']) :
'';
1388 $commentdata[
'comment_parent'] = (
'approved' == $parent_status ||
'unapproved' == $parent_status ) ? $commentdata[
'comment_parent'] : 0;
1390 $commentdata[
'comment_author_IP'] = preg_replace(
'/[^0-9a-fA-F:., ]/',
'',
$_SERVER[
'REMOTE_ADDR'] );
1391 $commentdata[
'comment_agent'] = substr(
$_SERVER[
'HTTP_USER_AGENT'], 0, 254);
1394 $commentdata[
'comment_date_gmt'] =
current_time(
'mysql', 1);
1402 do_action(
'comment_post', $comment_ID, $commentdata[
'comment_approved']);
1404 if (
'spam' !== $commentdata[
'comment_approved'] ) {
1405 if (
'0' == $commentdata[
'comment_approved'] )
1406 wp_notify_moderator($comment_ID);
1410 if (
get_option(
'comments_notify') && $commentdata[
'comment_approved'] && ( ! isset( $commentdata[
'user_id'] ) ||
$post->post_author != $commentdata[
'user_id'] ) )
1411 wp_notify_postauthor($comment_ID, isset( $commentdata[
'comment_type'] ) ? $commentdata[
'comment_type'] :
'' );
1435 switch ( $comment_status ) {
1445 wp_notify_postauthor($comment_id, $comment->comment_type);
1460 if ( !$wpdb->update( $wpdb->comments, array(
'comment_approved' =>
$status), array(
'comment_ID' => $comment_id) ) ) {
1462 return new WP_Error(
'db_update_error',
__(
'Could not update comment status'), $wpdb->last_error);
1471 do_action(
'wp_set_comment_status', $comment_id, $comment_status);
1500 $old_status = $comment[
'comment_approved'];
1503 $commentarr = array_merge($comment, $commentarr);
1514 if ( !isset($comment_approved) )
1515 $comment_approved = 1;
1516 else if (
'hold' == $comment_approved )
1517 $comment_approved = 0;
1518 else if (
'approve' == $comment_approved )
1519 $comment_approved = 1;
1521 $data = compact(
'comment_content',
'comment_author',
'comment_author_email',
'comment_approved',
'comment_karma',
'comment_author_url',
'comment_date',
'comment_date_gmt',
'comment_parent' );
1522 $rval = $wpdb->update( $wpdb->comments, $data, compact(
'comment_ID' ) );
1547 static $_defer =
false;
1549 if ( is_bool($defer) ) {
1578 static $_deferred = array();
1580 if ( $do_deferred ) {
1581 $_deferred = array_unique($_deferred);
1582 foreach ( $_deferred as
$i => $_post_id ) {
1584 unset( $_deferred[
$i] );
1617 $old = (int)
$post->comment_count;
1618 $new = (
int) $wpdb->get_var( $wpdb->prepare(
"SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'",
$post_id) );
1619 $wpdb->update( $wpdb->posts, array(
'comment_count' => $new), array(
'ID' =>
$post_id) );
1647 if ( !empty( $deprecated ) )
1650 $pingback_str_dquote =
'rel="pingback"';
1651 $pingback_str_squote =
'rel=\'pingback\'';
1654 $parsed_url = parse_url(
$url);
1656 if ( ! isset( $parsed_url[
'host'] ) )
1661 if ( 0 === strpos(
$url, $uploads_dir[
'baseurl']) )
1677 $response =
wp_remote_get(
$url, array(
'timeout' => 2,
'httpversion' =>
'1.0' ) );
1684 $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);
1685 $pingback_link_offset_squote = strpos($contents, $pingback_str_squote);
1686 if ( $pingback_link_offset_dquote || $pingback_link_offset_squote ) {
1687 $quote = ($pingback_link_offset_dquote) ?
'"' :
'\'';
1688 $pingback_link_offset = ($quote==
'"') ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
1689 $pingback_href_pos = @strpos($contents,
'href=', $pingback_link_offset);
1690 $pingback_href_start = $pingback_href_pos+6;
1691 $pingback_href_end = @strpos($contents, $quote, $pingback_href_start);
1692 $pingback_server_url_len = $pingback_href_end - $pingback_href_start;
1693 $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len);
1696 if ( $pingback_server_url_len > 0 ) {
1697 return $pingback_server_url;
1714 while ($ping = $wpdb->get_row(
"SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) {
1716 pingback( $ping->post_content, $ping->ID );
1720 while ($enclosure = $wpdb->get_row(
"SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) {
1722 do_enclose( $enclosure->post_content, $enclosure->ID );
1726 $trackbacks = $wpdb->get_col(
"SELECT ID FROM $wpdb->posts WHERE to_ping <> '' AND post_status = 'publish'");
1727 if ( is_array($trackbacks) )
1728 foreach ( $trackbacks as $trackback )
1749 if ( empty($to_ping) ) {
1750 $wpdb->update($wpdb->posts, array(
'to_ping' =>
''), array(
'ID' =>
$post_id) );
1754 if ( empty(
$post->post_excerpt) )
1765 foreach ( (array) $to_ping as $tb_ping ) {
1766 $tb_ping = trim($tb_ping);
1767 if ( !in_array($tb_ping, $pinged) ) {
1769 $pinged[] = $tb_ping;
1771 $wpdb->query( $wpdb->prepare(
"UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $tb_ping,
$post_id) );
1788 $services = explode(
"\n", $services);
1789 foreach ( (array) $services as $service ) {
1790 $service = trim($service);
1791 if (
'' != $service )
1811 include_once(
ABSPATH . WPINC .
'/class-wp-http-ixr-client.php');
1814 $post_links = array();
1820 $gunk =
'/#~:.?+=&%@!\-';
1822 $any = $ltrs . $gunk . $punc;
1828 preg_match_all(
"{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x",
$content, $post_links_temp);
1839 foreach ( (array) $post_links_temp[0] as $link_test ) :
1842 if ( $test = @parse_url($link_test) ) {
1843 if ( isset($test[
'query']) )
1844 $post_links[] = $link_test;
1845 elseif ( isset( $test[
'path'] ) && ( $test[
'path'] !=
'/' ) && ( $test[
'path'] !=
'' ) )
1846 $post_links[] = $link_test;
1853 foreach ( (array) $post_links as $pagelinkedto ) {
1856 if ( $pingback_server_url ) {
1857 @ set_time_limit( 60 );
1863 $client->timeout = 3;
1864 $client->useragent =
apply_filters(
'pingback_useragent', $client->useragent .
' -- WordPress/' . $wp_version, $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom);
1866 $client->debug =
false;
1868 if ( $client->query(
'pingback.ping', $pagelinkedfrom, $pagelinkedto) || ( isset($client->error->code) && 48 == $client->error->code ) )
1906 if ( empty($trackback_url) )
1923 $wpdb->query( $wpdb->prepare(
"UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', %s) WHERE ID = %d", $trackback_url,
$ID) );
1924 return $wpdb->query( $wpdb->prepare(
"UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $trackback_url,
$ID) );
1940 include_once(
ABSPATH . WPINC .
'/class-wp-http-ixr-client.php');
1944 $client->timeout = 3;
1945 $client->useragent .=
' -- WordPress/'.$wp_version;
1948 $client->debug =
false;
1950 if ( !$client->query(
'weblogUpdates.extendedPing',
get_option(
'blogname'), $home,
get_bloginfo(
'rss2_url') ) )
1951 $client->query(
'weblogUpdates.ping',
get_option(
'blogname'), $home);
1963 $uri =
esc_url_raw( $source_uri, array(
'http',
'https' ) );
1967 $parsed_url = @parse_url( $uri );
1968 if ( ! $parsed_url )
1971 if ( isset( $parsed_url[
'user'] ) || isset( $parsed_url[
'pass'] ) )
1974 if (
false !== strpos( $parsed_url[
'host'],
':' ) )
1977 $parsed_home = @parse_url(
get_option(
'home' ) );
1979 $same_host = strtolower( $parsed_home[
'host'] ) === strtolower( $parsed_url[
'host'] );
1981 if ( ! $same_host ) {
1982 $host = trim( $parsed_url[
'host'],
'.' );
1983 if ( preg_match(
'#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host ) ) {
1986 $ip = gethostbyname( $host );
1987 if ( $ip === $host )
1991 if (
'127.0.0.1' === $ip )
1993 $parts = array_map(
'intval', explode(
'.', $ip ) );
1994 if ( 10 === $parts[0] )
1996 if ( 172 === $parts[0] && 16 <= $parts[1] && 31 >= $parts[1] )
1998 if ( 192 === $parts[0] && 168 === $parts[1] )
2003 if ( empty( $parsed_url[
'port'] ) )
2006 $port = $parsed_url[
'port'];
2007 if ( 80 === $port || 443 === $port || 8080 === $port )
2010 if ( $parsed_home && $same_host && $parsed_home[
'port'] === $port )
2029 if ( $ixr_error->code === 48 )
2048 foreach ( (array) $ids as
$id )
2051 if ( function_exists(
'wp_cache_incr' ) ) {
2054 $last_changed =
wp_cache_get(
'last_changed',
'comment' );
2055 wp_cache_set(
'last_changed', $last_changed + 1,
'comment' );
2073 foreach ( (array)
$comments as $comment )
2074 wp_cache_add($comment->comment_ID, $comment,
'comment');
2092 if ( empty( $posts ) || ! $query->is_singular() || !
get_option(
'close_comments_for_old_posts' ) )
2095 $post_types =
apply_filters(
'close_comments_for_post_types', array(
'post' ) );
2096 if ( ! in_array( $posts[0]->post_type, $post_types ) )
2099 $days_old = (int)
get_option(
'close_comments_days_old' );
2103 if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) {
2104 $posts[0]->comment_status =
'closed';
2105 $posts[0]->ping_status =
'closed';
2125 if ( !
get_option(
'close_comments_for_old_posts') )
2128 $days_old = (int)
get_option(
'close_comments_days_old');
2134 $post_types =
apply_filters(
'close_comments_for_post_types', array(
'post' ) );
2135 if ( ! in_array(
$post->post_type, $post_types ) )
2138 if ( time() - strtotime(
$post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) )