wordpress  4.5.3
About: WordPress is a blogging system that has evolved to a full content management system.
  Fossies Dox: wordpress-4.5.3.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

comment.php
Go to the documentation of this file.
1 <?php
39 function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) {
40  global $wpdb;
41 
42  // If manual moderation is enabled, skip all checks and return false.
43  if ( 1 == get_option('comment_moderation') )
44  return false;
45 
47  $comment = apply_filters( 'comment_text', $comment );
48 
49  // Check for the number of external links if a max allowed number is set.
50  if ( $max_links = get_option( 'comment_max_links' ) ) {
51  $num_links = preg_match_all( '/<a [^>]*href/i', $comment, $out );
52 
61  $num_links = apply_filters( 'comment_max_links_url', $num_links, $url );
62 
63  /*
64  * If the number of links in the comment exceeds the allowed amount,
65  * fail the check by returning false.
66  */
67  if ( $num_links >= $max_links )
68  return false;
69  }
70 
71  $mod_keys = trim(get_option('moderation_keys'));
72 
73  // If moderation 'keys' (keywords) are set, process them.
74  if ( !empty($mod_keys) ) {
75  $words = explode("\n", $mod_keys );
76 
77  foreach ( (array) $words as $word) {
78  $word = trim($word);
79 
80  // Skip empty lines.
81  if ( empty($word) )
82  continue;
83 
84  /*
85  * Do some escaping magic so that '#' (number of) characters in the spam
86  * words don't break things:
87  */
88  $word = preg_quote($word, '#');
89 
90  /*
91  * Check the comment fields for moderation keywords. If any are found,
92  * fail the check for the given field by returning false.
93  */
94  $pattern = "#$word#i";
95  if ( preg_match($pattern, $author) ) return false;
96  if ( preg_match($pattern, $email) ) return false;
97  if ( preg_match($pattern, $url) ) return false;
98  if ( preg_match($pattern, $comment) ) return false;
99  if ( preg_match($pattern, $user_ip) ) return false;
100  if ( preg_match($pattern, $user_agent) ) return false;
101  }
102  }
103 
104  /*
105  * Check if the option to approve comments by previously-approved authors is enabled.
106  *
107  * If it is enabled, check whether the comment author has a previously-approved comment,
108  * as well as whether there are any moderation keywords (if set) present in the author
109  * email address. If both checks pass, return true. Otherwise, return false.
110  */
111  if ( 1 == get_option('comment_whitelist')) {
112  if ( 'trackback' != $comment_type && 'pingback' != $comment_type && $author != '' && $email != '' ) {
113  // expected_slashed ($author, $email)
114  $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");
115  if ( ( 1 == $ok_to_comment ) &&
116  ( empty($mod_keys) || false === strpos( $email, $mod_keys) ) )
117  return true;
118  else
119  return false;
120  } else {
121  return false;
122  }
123  }
124  return true;
125 }
126 
139 function get_approved_comments( $post_id, $args = array() ) {
140  if ( ! $post_id ) {
141  return array();
142  }
143 
144  $defaults = array(
145  'status' => 1,
146  'post_id' => $post_id,
147  'order' => 'ASC',
148  );
149  $r = wp_parse_args( $args, $defaults );
150 
151  $query = new WP_Comment_Query;
152  return $query->query( $r );
153 }
154 
170 function get_comment( &$comment = null, $output = OBJECT ) {
171  if ( empty( $comment ) && isset( $GLOBALS['comment'] ) ) {
172  $comment = $GLOBALS['comment'];
173  }
174 
175  if ( $comment instanceof WP_Comment ) {
176  $_comment = $comment;
177  } elseif ( is_object( $comment ) ) {
178  $_comment = new WP_Comment( $comment );
179  } else {
180  $_comment = WP_Comment::get_instance( $comment );
181  }
182 
183  if ( ! $_comment ) {
184  return null;
185  }
186 
194  $_comment = apply_filters( 'get_comment', $_comment );
195 
196  if ( $output == OBJECT ) {
197  return $_comment;
198  } elseif ( $output == ARRAY_A ) {
199  return $_comment->to_array();
200  } elseif ( $output == ARRAY_N ) {
201  return array_values( $_comment->to_array() );
202  }
203  return $_comment;
204 }
205 
217 function get_comments( $args = '' ) {
218  $query = new WP_Comment_Query;
219  return $query->query( $args );
220 }
221 
233  $status = array(
234  'hold' => __( 'Unapproved' ),
235  'approve' => _x( 'Approved', 'comment status' ),
236  'spam' => _x( 'Spam', 'comment status' ),
237  'trash' => _x( 'Trash', 'comment status' ),
238  );
239 
240  return $status;
241 }
242 
252 function get_default_comment_status( $post_type = 'post', $comment_type = 'comment' ) {
253  switch ( $comment_type ) {
254  case 'pingback' :
255  case 'trackback' :
256  $supports = 'trackbacks';
257  $option = 'ping';
258  break;
259  default :
260  $supports = 'comments';
261  $option = 'comment';
262  }
263 
264  // Set the status.
265  if ( 'page' === $post_type ) {
266  $status = 'closed';
267  } elseif ( post_type_supports( $post_type, $supports ) ) {
268  $status = get_option( "default_{$option}_status" );
269  } else {
270  $status = 'closed';
271  }
272 
283  return apply_filters( 'get_default_comment_status' , $status, $post_type, $comment_type );
284 }
285 
298 function get_lastcommentmodified($timezone = 'server') {
299  global $wpdb;
300  static $cache_lastcommentmodified = array();
301 
302  if ( isset($cache_lastcommentmodified[$timezone]) )
303  return $cache_lastcommentmodified[$timezone];
304 
305  $add_seconds_server = date('Z');
306 
307  switch ( strtolower($timezone)) {
308  case 'gmt':
309  $lastcommentmodified = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1");
310  break;
311  case 'blog':
312  $lastcommentmodified = $wpdb->get_var("SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1");
313  break;
314  case 'server':
315  $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));
316  break;
317  }
318 
319  $cache_lastcommentmodified[$timezone] = $lastcommentmodified;
320 
321  return $lastcommentmodified;
322 }
323 
338 function get_comment_count( $post_id = 0 ) {
339  global $wpdb;
340 
341  $post_id = (int) $post_id;
342 
343  $where = '';
344  if ( $post_id > 0 ) {
345  $where = $wpdb->prepare("WHERE comment_post_ID = %d", $post_id);
346  }
347 
348  $totals = (array) $wpdb->get_results("
349  SELECT comment_approved, COUNT( * ) AS total
350  FROM {$wpdb->comments}
351  {$where}
352  GROUP BY comment_approved
353  ", ARRAY_A);
354 
355  $comment_count = array(
356  'approved' => 0,
357  'awaiting_moderation' => 0,
358  'spam' => 0,
359  'trash' => 0,
360  'post-trashed' => 0,
361  'total_comments' => 0,
362  'all' => 0,
363  );
364 
365  foreach ( $totals as $row ) {
366  switch ( $row['comment_approved'] ) {
367  case 'trash':
368  $comment_count['trash'] = $row['total'];
369  break;
370  case 'post-trashed':
371  $comment_count['post-trashed'] = $row['total'];
372  break;
373  case 'spam':
374  $comment_count['spam'] = $row['total'];
375  $comment_count['total_comments'] += $row['total'];
376  break;
377  case '1':
378  $comment_count['approved'] = $row['total'];
379  $comment_count['total_comments'] += $row['total'];
380  $comment_count['all'] += $row['total'];
381  break;
382  case '0':
383  $comment_count['awaiting_moderation'] = $row['total'];
384  $comment_count['total_comments'] += $row['total'];
385  $comment_count['all'] += $row['total'];
386  break;
387  default:
388  break;
389  }
390  }
391 
392  return $comment_count;
393 }
394 
395 //
396 // Comment meta functions
397 //
398 
411 function add_comment_meta($comment_id, $meta_key, $meta_value, $unique = false) {
412  return add_metadata('comment', $comment_id, $meta_key, $meta_value, $unique);
413 }
414 
430 function delete_comment_meta($comment_id, $meta_key, $meta_value = '') {
431  return delete_metadata('comment', $comment_id, $meta_key, $meta_value);
432 }
433 
446 function get_comment_meta($comment_id, $key = '', $single = false) {
447  return get_metadata('comment', $comment_id, $key, $single);
448 }
449 
467 function update_comment_meta($comment_id, $meta_key, $meta_value, $prev_value = '') {
468  return update_metadata('comment', $comment_id, $meta_key, $meta_value, $prev_value);
469 }
470 
479  // Don't use `wp_list_pluck()` to avoid by-reference manipulation.
480  $comment_ids = array();
481  if ( is_array( $comments ) ) {
482  foreach ( $comments as $comment ) {
483  if ( $comment instanceof WP_Comment ) {
484  $comment_ids[] = $comment->comment_ID;
485  }
486  }
487  }
488 
489  if ( $comment_ids ) {
490  $lazyloader = wp_metadata_lazyloader();
491  $lazyloader->queue_objects( 'comment', $comment_ids );
492  }
493 }
494 
505  if ( $user->exists() )
506  return;
507 
515  $comment_cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 );
516  $secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );
517  setcookie( 'comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure );
518  setcookie( 'comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure );
519  setcookie( 'comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure );
520 }
521 
531  if ( isset( $_COOKIE['comment_author_' . COOKIEHASH] ) ) {
542  $comment_author = apply_filters( 'pre_comment_author_name', $_COOKIE['comment_author_' . COOKIEHASH] );
543  $comment_author = wp_unslash($comment_author);
544  $comment_author = esc_attr($comment_author);
545  $_COOKIE['comment_author_' . COOKIEHASH] = $comment_author;
546  }
547 
548  if ( isset( $_COOKIE['comment_author_email_' . COOKIEHASH] ) ) {
559  $comment_author_email = apply_filters( 'pre_comment_author_email', $_COOKIE['comment_author_email_' . COOKIEHASH] );
560  $comment_author_email = wp_unslash($comment_author_email);
561  $comment_author_email = esc_attr($comment_author_email);
562  $_COOKIE['comment_author_email_'.COOKIEHASH] = $comment_author_email;
563  }
564 
565  if ( isset( $_COOKIE['comment_author_url_' . COOKIEHASH] ) ) {
576  $comment_author_url = apply_filters( 'pre_comment_author_url', $_COOKIE['comment_author_url_' . COOKIEHASH] );
577  $comment_author_url = wp_unslash($comment_author_url);
578  $_COOKIE['comment_author_url_'.COOKIEHASH] = $comment_author_url;
579  }
580 }
581 
592 function wp_allow_comment( $commentdata ) {
593  global $wpdb;
594 
595  // Simple duplicate check
596  // expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content)
597  $dupe = $wpdb->prepare(
598  "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = %s AND comment_approved != 'trash' AND ( comment_author = %s ",
599  wp_unslash( $commentdata['comment_post_ID'] ),
600  wp_unslash( $commentdata['comment_parent'] ),
601  wp_unslash( $commentdata['comment_author'] )
602  );
603  if ( $commentdata['comment_author_email'] ) {
604  $dupe .= $wpdb->prepare(
605  "OR comment_author_email = %s ",
606  wp_unslash( $commentdata['comment_author_email'] )
607  );
608  }
609  $dupe .= $wpdb->prepare(
610  ") AND comment_content = %s LIMIT 1",
611  wp_unslash( $commentdata['comment_content'] )
612  );
613 
614  $dupe_id = $wpdb->get_var( $dupe );
615 
626  $dupe_id = apply_filters( 'duplicate_comment_id', $dupe_id, $commentdata );
627 
628  if ( $dupe_id ) {
636  do_action( 'comment_duplicate_trigger', $commentdata );
637  if ( defined( 'DOING_AJAX' ) ) {
638  die( __('Duplicate comment detected; it looks as though you&#8217;ve already said that!') );
639  }
640  wp_die( __( 'Duplicate comment detected; it looks as though you&#8217;ve already said that!' ), 409 );
641  }
642 
654  do_action(
655  'check_comment_flood',
656  $commentdata['comment_author_IP'],
657  $commentdata['comment_author_email'],
658  $commentdata['comment_date_gmt']
659  );
660 
661  if ( ! empty( $commentdata['user_id'] ) ) {
662  $user = get_userdata( $commentdata['user_id'] );
663  $post_author = $wpdb->get_var( $wpdb->prepare(
664  "SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1",
665  $commentdata['comment_post_ID']
666  ) );
667  }
668 
669  if ( isset( $user ) && ( $commentdata['user_id'] == $post_author || $user->has_cap( 'moderate_comments' ) ) ) {
670  // The author and the admins get respect.
671  $approved = 1;
672  } else {
673  // Everyone else's comments will be checked.
674  if ( check_comment(
675  $commentdata['comment_author'],
676  $commentdata['comment_author_email'],
677  $commentdata['comment_author_url'],
678  $commentdata['comment_content'],
679  $commentdata['comment_author_IP'],
680  $commentdata['comment_agent'],
681  $commentdata['comment_type']
682  ) ) {
683  $approved = 1;
684  } else {
685  $approved = 0;
686  }
687 
688  if ( wp_blacklist_check(
689  $commentdata['comment_author'],
690  $commentdata['comment_author_email'],
691  $commentdata['comment_author_url'],
692  $commentdata['comment_content'],
693  $commentdata['comment_author_IP'],
694  $commentdata['comment_agent']
695  ) ) {
696  $approved = EMPTY_TRASH_DAYS ? 'trash' : 'spam';
697  }
698  }
699 
708  $approved = apply_filters( 'pre_comment_approved', $approved, $commentdata );
709  return $approved;
710 }
711 
726 function check_comment_flood_db( $ip, $email, $date ) {
727  global $wpdb;
728  // don't throttle admins or moderators
729  if ( current_user_can( 'manage_options' ) || current_user_can( 'moderate_comments' ) ) {
730  return;
731  }
732  $hour_ago = gmdate( 'Y-m-d H:i:s', time() - HOUR_IN_SECONDS );
733 
734  if ( is_user_logged_in() ) {
736  $check_column = '`user_id`';
737  } else {
738  $user = $ip;
739  $check_column = '`comment_author_IP`';
740  }
741 
742  $sql = $wpdb->prepare(
743  "SELECT `comment_date_gmt` FROM `$wpdb->comments` WHERE `comment_date_gmt` >= %s AND ( $check_column = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1",
744  $hour_ago,
745  $user,
746  $email
747  );
748  $lasttime = $wpdb->get_var( $sql );
749  if ( $lasttime ) {
750  $time_lastcomment = mysql2date('U', $lasttime, false);
751  $time_newcomment = mysql2date('U', $date, false);
761  $flood_die = apply_filters( 'comment_flood_filter', false, $time_lastcomment, $time_newcomment );
762  if ( $flood_die ) {
771  do_action( 'comment_flood_trigger', $time_lastcomment, $time_newcomment );
772 
773  if ( defined('DOING_AJAX') )
774  die( __('You are posting comments too quickly. Slow down.') );
775 
776  wp_die( __( 'You are posting comments too quickly. Slow down.' ), 429 );
777  }
778  }
779 }
780 
789 function separate_comments(&$comments) {
790  $comments_by_type = array('comment' => array(), 'trackback' => array(), 'pingback' => array(), 'pings' => array());
791  $count = count($comments);
792  for ( $i = 0; $i < $count; $i++ ) {
793  $type = $comments[$i]->comment_type;
794  if ( empty($type) )
795  $type = 'comment';
796  $comments_by_type[$type][] = &$comments[$i];
797  if ( 'trackback' == $type || 'pingback' == $type )
798  $comments_by_type['pings'][] = &$comments[$i];
799  }
800 
801  return $comments_by_type;
802 }
803 
818 function get_comment_pages_count( $comments = null, $per_page = null, $threaded = null ) {
819  global $wp_query;
820 
821  if ( null === $comments && null === $per_page && null === $threaded && !empty($wp_query->max_num_comment_pages) )
822  return $wp_query->max_num_comment_pages;
823 
824  if ( ( ! $comments || ! is_array( $comments ) ) && ! empty( $wp_query->comments ) )
825  $comments = $wp_query->comments;
826 
827  if ( empty($comments) )
828  return 0;
829 
830  if ( ! get_option( 'page_comments' ) ) {
831  return 1;
832  }
833 
834  if ( !isset($per_page) )
835  $per_page = (int) get_query_var('comments_per_page');
836  if ( 0 === $per_page )
837  $per_page = (int) get_option('comments_per_page');
838  if ( 0 === $per_page )
839  return 1;
840 
841  if ( !isset($threaded) )
842  $threaded = get_option('thread_comments');
843 
844  if ( $threaded ) {
845  $walker = new Walker_Comment;
846  $count = ceil( $walker->get_number_of_root_elements( $comments ) / $per_page );
847  } else {
848  $count = ceil( count( $comments ) / $per_page );
849  }
850 
851  return $count;
852 }
853 
874 function get_page_of_comment( $comment_ID, $args = array() ) {
875  global $wpdb;
876 
877  $page = null;
878 
879  if ( !$comment = get_comment( $comment_ID ) )
880  return;
881 
882  $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' );
883  $args = wp_parse_args( $args, $defaults );
884  $original_args = $args;
885 
886  // Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option.
887  if ( get_option( 'page_comments' ) ) {
888  if ( '' === $args['per_page'] ) {
889  $args['per_page'] = get_query_var( 'comments_per_page' );
890  }
891 
892  if ( '' === $args['per_page'] ) {
893  $args['per_page'] = get_option( 'comments_per_page' );
894  }
895  }
896 
897  if ( empty($args['per_page']) ) {
898  $args['per_page'] = 0;
899  $args['page'] = 0;
900  }
901 
902  if ( $args['per_page'] < 1 ) {
903  $page = 1;
904  }
905 
906  if ( null === $page ) {
907  if ( '' === $args['max_depth'] ) {
908  if ( get_option('thread_comments') )
909  $args['max_depth'] = get_option('thread_comments_depth');
910  else
911  $args['max_depth'] = -1;
912  }
913 
914  // Find this comment's top level parent if threading is enabled
915  if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent )
916  return get_page_of_comment( $comment->comment_parent, $args );
917 
918  $comment_args = array(
919  'type' => $args['type'],
920  'post_id' => $comment->comment_post_ID,
921  'fields' => 'ids',
922  'count' => true,
923  'status' => 'approve',
924  'parent' => 0,
925  'date_query' => array(
926  array(
927  'column' => "$wpdb->comments.comment_date_gmt",
928  'before' => $comment->comment_date_gmt,
929  )
930  ),
931  );
932 
933  $comment_query = new WP_Comment_Query();
934  $older_comment_count = $comment_query->query( $comment_args );
935 
936  // No older comments? Then it's page #1.
937  if ( 0 == $older_comment_count ) {
938  $page = 1;
939 
940  // Divide comments older than this one by comments per page to get this comment's page number
941  } else {
942  $page = ceil( ( $older_comment_count + 1 ) / $args['per_page'] );
943  }
944  }
945 
971  return apply_filters( 'get_page_of_comment', (int) $page, $args, $original_args );
972 }
973 
984  global $wpdb;
985 
986  $lengths = array(
987  'comment_author' => 245,
988  'comment_author_email' => 100,
989  'comment_author_url' => 200,
990  'comment_content' => 65525,
991  );
992 
993  if ( $wpdb->is_mysql ) {
994  foreach ( $lengths as $column => $length ) {
995  $col_length = $wpdb->get_col_length( $wpdb->comments, $column );
996  $max_length = 0;
997 
998  // No point if we can't get the DB column lengths
999  if ( is_wp_error( $col_length ) ) {
1000  break;
1001  }
1002 
1003  if ( ! is_array( $col_length ) && (int) $col_length > 0 ) {
1004  $max_length = (int) $col_length;
1005  } elseif ( is_array( $col_length ) && isset( $col_length['length'] ) && intval( $col_length['length'] ) > 0 ) {
1006  $max_length = (int) $col_length['length'];
1007 
1008  if ( ! empty( $col_length['type'] ) && 'byte' === $col_length['type'] ) {
1009  $max_length = $max_length - 10;
1010  }
1011  }
1012 
1013  if ( $max_length > 0 ) {
1014  $lengths[ $column ] = $max_length;
1015  }
1016  }
1017  }
1018 
1026  return apply_filters( 'wp_get_comment_fields_max_lengths', $lengths );
1027 }
1028 
1042 function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent) {
1055  do_action( 'wp_blacklist_check', $author, $email, $url, $comment, $user_ip, $user_agent );
1056 
1057  $mod_keys = trim( get_option('blacklist_keys') );
1058  if ( '' == $mod_keys )
1059  return false; // If moderation keys are empty
1060  $words = explode("\n", $mod_keys );
1061 
1062  foreach ( (array) $words as $word ) {
1063  $word = trim($word);
1064 
1065  // Skip empty lines
1066  if ( empty($word) ) { continue; }
1067 
1068  // Do some escaping magic so that '#' chars in the
1069  // spam words don't break things:
1070  $word = preg_quote($word, '#');
1071 
1072  $pattern = "#$word#i";
1073  if (
1074  preg_match($pattern, $author)
1075  || preg_match($pattern, $email)
1076  || preg_match($pattern, $url)
1077  || preg_match($pattern, $comment)
1078  || preg_match($pattern, $user_ip)
1079  || preg_match($pattern, $user_agent)
1080  )
1081  return true;
1082  }
1083  return false;
1084 }
1085 
1102 function wp_count_comments( $post_id = 0 ) {
1103  $post_id = (int) $post_id;
1104 
1113  $filtered = apply_filters( 'wp_count_comments', array(), $post_id );
1114  if ( ! empty( $filtered ) ) {
1115  return $filtered;
1116  }
1117 
1118  $count = wp_cache_get( "comments-{$post_id}", 'counts' );
1119  if ( false !== $count ) {
1120  return $count;
1121  }
1122 
1123  $stats = get_comment_count( $post_id );
1124  $stats['moderated'] = $stats['awaiting_moderation'];
1125  unset( $stats['awaiting_moderation'] );
1126 
1127  $stats_object = (object) $stats;
1128  wp_cache_set( "comments-{$post_id}", $stats_object, 'counts' );
1129 
1130  return $stats_object;
1131 }
1132 
1150 function wp_delete_comment($comment_id, $force_delete = false) {
1151  global $wpdb;
1152  if (!$comment = get_comment($comment_id))
1153  return false;
1154 
1155  if ( !$force_delete && EMPTY_TRASH_DAYS && !in_array( wp_get_comment_status( $comment ), array( 'trash', 'spam' ) ) )
1156  return wp_trash_comment($comment_id);
1157 
1165  do_action( 'delete_comment', $comment->comment_ID );
1166 
1167  // Move children up a level.
1168  $children = $wpdb->get_col( $wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = %d", $comment->comment_ID) );
1169  if ( !empty($children) ) {
1170  $wpdb->update($wpdb->comments, array('comment_parent' => $comment->comment_parent), array('comment_parent' => $comment->comment_ID));
1171  clean_comment_cache($children);
1172  }
1173 
1174  // Delete metadata
1175  $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment->comment_ID ) );
1176  foreach ( $meta_ids as $mid )
1177  delete_metadata_by_mid( 'comment', $mid );
1178 
1179  if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment->comment_ID ) ) )
1180  return false;
1181 
1189  do_action( 'deleted_comment', $comment->comment_ID );
1190 
1191  $post_id = $comment->comment_post_ID;
1192  if ( $post_id && $comment->comment_approved == 1 )
1194 
1195  clean_comment_cache( $comment->comment_ID );
1196 
1198  do_action( 'wp_set_comment_status', $comment->comment_ID, 'delete' );
1199 
1200  wp_transition_comment_status('delete', $comment->comment_approved, $comment);
1201  return true;
1202 }
1203 
1214 function wp_trash_comment($comment_id) {
1215  if ( !EMPTY_TRASH_DAYS )
1216  return wp_delete_comment($comment_id, true);
1217 
1218  if ( !$comment = get_comment($comment_id) )
1219  return false;
1220 
1228  do_action( 'trash_comment', $comment->comment_ID );
1229 
1230  if ( wp_set_comment_status( $comment, 'trash' ) ) {
1231  delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' );
1232  delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' );
1233  add_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', $comment->comment_approved );
1234  add_comment_meta( $comment->comment_ID, '_wp_trash_meta_time', time() );
1235 
1243  do_action( 'trashed_comment', $comment->comment_ID );
1244  return true;
1245  }
1246 
1247  return false;
1248 }
1249 
1258 function wp_untrash_comment($comment_id) {
1259  $comment = get_comment( $comment_id );
1260  if ( ! $comment ) {
1261  return false;
1262  }
1263 
1271  do_action( 'untrash_comment', $comment->comment_ID );
1272 
1273  $status = (string) get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true );
1274  if ( empty($status) )
1275  $status = '0';
1276 
1277  if ( wp_set_comment_status( $comment, $status ) ) {
1278  delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' );
1279  delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' );
1287  do_action( 'untrashed_comment', $comment->comment_ID );
1288  return true;
1289  }
1290 
1291  return false;
1292 }
1293 
1302 function wp_spam_comment( $comment_id ) {
1303  $comment = get_comment( $comment_id );
1304  if ( ! $comment ) {
1305  return false;
1306  }
1307 
1315  do_action( 'spam_comment', $comment->comment_ID );
1316 
1317  if ( wp_set_comment_status( $comment, 'spam' ) ) {
1318  delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' );
1319  delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' );
1320  add_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', $comment->comment_approved );
1321  add_comment_meta( $comment->comment_ID, '_wp_trash_meta_time', time() );
1329  do_action( 'spammed_comment', $comment->comment_ID );
1330  return true;
1331  }
1332 
1333  return false;
1334 }
1335 
1344 function wp_unspam_comment( $comment_id ) {
1345  $comment = get_comment( $comment_id );
1346  if ( ! $comment ) {
1347  return false;
1348  }
1349 
1357  do_action( 'unspam_comment', $comment->comment_ID );
1358 
1359  $status = (string) get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true );
1360  if ( empty($status) )
1361  $status = '0';
1362 
1363  if ( wp_set_comment_status( $comment, $status ) ) {
1364  delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' );
1365  delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' );
1373  do_action( 'unspammed_comment', $comment->comment_ID );
1374  return true;
1375  }
1376 
1377  return false;
1378 }
1379 
1388 function wp_get_comment_status($comment_id) {
1389  $comment = get_comment($comment_id);
1390  if ( !$comment )
1391  return false;
1392 
1393  $approved = $comment->comment_approved;
1394 
1395  if ( $approved == null )
1396  return false;
1397  elseif ( $approved == '1' )
1398  return 'approved';
1399  elseif ( $approved == '0' )
1400  return 'unapproved';
1401  elseif ( $approved == 'spam' )
1402  return 'spam';
1403  elseif ( $approved == 'trash' )
1404  return 'trash';
1405  else
1406  return false;
1407 }
1408 
1429 function wp_transition_comment_status($new_status, $old_status, $comment) {
1430  /*
1431  * Translate raw statuses to human readable formats for the hooks.
1432  * This is not a complete list of comment status, it's only the ones
1433  * that need to be renamed
1434  */
1435  $comment_statuses = array(
1436  0 => 'unapproved',
1437  'hold' => 'unapproved', // wp_set_comment_status() uses "hold"
1438  1 => 'approved',
1439  'approve' => 'approved', // wp_set_comment_status() uses "approve"
1440  );
1441  if ( isset($comment_statuses[$new_status]) ) $new_status = $comment_statuses[$new_status];
1442  if ( isset($comment_statuses[$old_status]) ) $old_status = $comment_statuses[$old_status];
1443 
1444  // Call the hooks
1445  if ( $new_status != $old_status ) {
1455  do_action( 'transition_comment_status', $new_status, $old_status, $comment );
1466  do_action( "comment_{$old_status}_to_{$new_status}", $comment );
1467  }
1482  do_action( "comment_{$new_status}_{$comment->comment_type}", $comment->comment_ID, $comment );
1483 }
1484 
1498  // Cookies should already be sanitized.
1499 
1500  $comment_author = '';
1501  if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) )
1502  $comment_author = $_COOKIE['comment_author_'.COOKIEHASH];
1503 
1504  $comment_author_email = '';
1505  if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) )
1506  $comment_author_email = $_COOKIE['comment_author_email_'.COOKIEHASH];
1507 
1508  $comment_author_url = '';
1509  if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) )
1510  $comment_author_url = $_COOKIE['comment_author_url_'.COOKIEHASH];
1511 
1525  return apply_filters( 'wp_get_current_commenter', compact('comment_author', 'comment_author_email', 'comment_author_url') );
1526 }
1527 
1563 function wp_insert_comment( $commentdata ) {
1564  global $wpdb;
1565  $data = wp_unslash( $commentdata );
1566 
1567  $comment_author = ! isset( $data['comment_author'] ) ? '' : $data['comment_author'];
1568  $comment_author_email = ! isset( $data['comment_author_email'] ) ? '' : $data['comment_author_email'];
1569  $comment_author_url = ! isset( $data['comment_author_url'] ) ? '' : $data['comment_author_url'];
1570  $comment_author_IP = ! isset( $data['comment_author_IP'] ) ? '' : $data['comment_author_IP'];
1571 
1572  $comment_date = ! isset( $data['comment_date'] ) ? current_time( 'mysql' ) : $data['comment_date'];
1573  $comment_date_gmt = ! isset( $data['comment_date_gmt'] ) ? get_gmt_from_date( $comment_date ) : $data['comment_date_gmt'];
1574 
1575  $comment_post_ID = ! isset( $data['comment_post_ID'] ) ? 0 : $data['comment_post_ID'];
1576  $comment_content = ! isset( $data['comment_content'] ) ? '' : $data['comment_content'];
1577  $comment_karma = ! isset( $data['comment_karma'] ) ? 0 : $data['comment_karma'];
1578  $comment_approved = ! isset( $data['comment_approved'] ) ? 1 : $data['comment_approved'];
1579  $comment_agent = ! isset( $data['comment_agent'] ) ? '' : $data['comment_agent'];
1580  $comment_type = ! isset( $data['comment_type'] ) ? '' : $data['comment_type'];
1581  $comment_parent = ! isset( $data['comment_parent'] ) ? 0 : $data['comment_parent'];
1582 
1583  $user_id = ! isset( $data['user_id'] ) ? 0 : $data['user_id'];
1584 
1585  $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' );
1586  if ( ! $wpdb->insert( $wpdb->comments, $compacted ) ) {
1587  return false;
1588  }
1589 
1590  $id = (int) $wpdb->insert_id;
1591 
1592  if ( $comment_approved == 1 ) {
1593  wp_update_comment_count( $comment_post_ID );
1594  }
1595  $comment = get_comment( $id );
1596 
1597  // If metadata is provided, store it.
1598  if ( isset( $commentdata['comment_meta'] ) && is_array( $commentdata['comment_meta'] ) ) {
1599  foreach ( $commentdata['comment_meta'] as $meta_key => $meta_value ) {
1600  add_comment_meta( $comment->comment_ID, $meta_key, $meta_value, true );
1601  }
1602  }
1603 
1612  do_action( 'wp_insert_comment', $id, $comment );
1613 
1614  wp_cache_set( 'last_changed', microtime(), 'comment' );
1615 
1616  return $id;
1617 }
1618 
1631 function wp_filter_comment($commentdata) {
1632  if ( isset( $commentdata['user_ID'] ) ) {
1643  $commentdata['user_id'] = apply_filters( 'pre_user_id', $commentdata['user_ID'] );
1644  } elseif ( isset( $commentdata['user_id'] ) ) {
1646  $commentdata['user_id'] = apply_filters( 'pre_user_id', $commentdata['user_id'] );
1647  }
1648 
1656  $commentdata['comment_agent'] = apply_filters( 'pre_comment_user_agent', ( isset( $commentdata['comment_agent'] ) ? $commentdata['comment_agent'] : '' ) );
1658  $commentdata['comment_author'] = apply_filters( 'pre_comment_author_name', $commentdata['comment_author'] );
1666  $commentdata['comment_content'] = apply_filters( 'pre_comment_content', $commentdata['comment_content'] );
1674  $commentdata['comment_author_IP'] = apply_filters( 'pre_comment_user_ip', $commentdata['comment_author_IP'] );
1676  $commentdata['comment_author_url'] = apply_filters( 'pre_comment_author_url', $commentdata['comment_author_url'] );
1678  $commentdata['comment_author_email'] = apply_filters( 'pre_comment_author_email', $commentdata['comment_author_email'] );
1679  $commentdata['filtered'] = true;
1680  return $commentdata;
1681 }
1682 
1693 function wp_throttle_comment_flood($block, $time_lastcomment, $time_newcomment) {
1694  if ( $block ) // a plugin has already blocked... we'll let that decision stand
1695  return $block;
1696  if ( ($time_newcomment - $time_lastcomment) < 15 )
1697  return true;
1698  return false;
1699 }
1700 
1740 function wp_new_comment( $commentdata ) {
1741  global $wpdb;
1742 
1743  if ( isset( $commentdata['user_ID'] ) ) {
1744  $commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID'];
1745  }
1746 
1747  $prefiltered_user_id = ( isset( $commentdata['user_id'] ) ) ? (int) $commentdata['user_id'] : 0;
1748 
1756  $commentdata = apply_filters( 'preprocess_comment', $commentdata );
1757 
1758  $commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
1759  if ( isset( $commentdata['user_ID'] ) && $prefiltered_user_id !== (int) $commentdata['user_ID'] ) {
1760  $commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID'];
1761  } elseif ( isset( $commentdata['user_id'] ) ) {
1762  $commentdata['user_id'] = (int) $commentdata['user_id'];
1763  }
1764 
1765  $commentdata['comment_parent'] = isset($commentdata['comment_parent']) ? absint($commentdata['comment_parent']) : 0;
1766  $parent_status = ( 0 < $commentdata['comment_parent'] ) ? wp_get_comment_status($commentdata['comment_parent']) : '';
1767  $commentdata['comment_parent'] = ( 'approved' == $parent_status || 'unapproved' == $parent_status ) ? $commentdata['comment_parent'] : 0;
1768 
1769  if ( ! isset( $commentdata['comment_author_IP'] ) ) {
1770  $commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR'];
1771  }
1772  $commentdata['comment_author_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', '', $commentdata['comment_author_IP'] );
1773 
1774  if ( ! isset( $commentdata['comment_agent'] ) ) {
1775  $commentdata['comment_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT']: '';
1776  }
1777  $commentdata['comment_agent'] = substr( $commentdata['comment_agent'], 0, 254 );
1778 
1779  if ( empty( $commentdata['comment_date'] ) ) {
1780  $commentdata['comment_date'] = current_time('mysql');
1781  }
1782 
1783  if ( empty( $commentdata['comment_date_gmt'] ) ) {
1784  $commentdata['comment_date_gmt'] = current_time( 'mysql', 1 );
1785  }
1786 
1787  $commentdata = wp_filter_comment($commentdata);
1788 
1789  $commentdata['comment_approved'] = wp_allow_comment($commentdata);
1790 
1791  $comment_ID = wp_insert_comment($commentdata);
1792  if ( ! $comment_ID ) {
1793  $fields = array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content' );
1794 
1795  foreach ( $fields as $field ) {
1796  if ( isset( $commentdata[ $field ] ) ) {
1797  $commentdata[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->comments, $field, $commentdata[ $field ] );
1798  }
1799  }
1800 
1801  $commentdata = wp_filter_comment( $commentdata );
1802 
1803  $commentdata['comment_approved'] = wp_allow_comment( $commentdata );
1804 
1805  $comment_ID = wp_insert_comment( $commentdata );
1806  if ( ! $comment_ID ) {
1807  return false;
1808  }
1809  }
1810 
1821  do_action( 'comment_post', $comment_ID, $commentdata['comment_approved'], $commentdata );
1822 
1823  return $comment_ID;
1824 }
1825 
1834 function wp_new_comment_notify_moderator( $comment_ID ) {
1835  $comment = get_comment( $comment_ID );
1836 
1837  // Only send notifications for pending comments.
1838  $maybe_notify = ( '0' == $comment->comment_approved );
1839 
1841  $maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_ID );
1842 
1843  if ( ! $maybe_notify ) {
1844  return false;
1845  }
1846 
1847  return wp_notify_moderator( $comment_ID );
1848 }
1849 
1861 function wp_new_comment_notify_postauthor( $comment_ID ) {
1862  $comment = get_comment( $comment_ID );
1863 
1864  $maybe_notify = get_option( 'comments_notify' );
1865 
1875  $maybe_notify = apply_filters( 'notify_post_author', $maybe_notify, $comment_ID );
1876 
1877  /*
1878  * wp_notify_postauthor() checks if notifying the author of their own comment.
1879  * By default, it won't, but filters can override this.
1880  */
1881  if ( ! $maybe_notify ) {
1882  return false;
1883  }
1884 
1885  // Only send notifications for approved comments.
1886  if ( ! isset( $comment->comment_approved ) || '1' != $comment->comment_approved ) {
1887  return false;
1888  }
1889 
1890  return wp_notify_postauthor( $comment_ID );
1891 }
1892 
1908 function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) {
1909  global $wpdb;
1910 
1911  switch ( $comment_status ) {
1912  case 'hold':
1913  case '0':
1914  $status = '0';
1915  break;
1916  case 'approve':
1917  case '1':
1918  $status = '1';
1919  add_action( 'wp_set_comment_status', 'wp_new_comment_notify_postauthor' );
1920  break;
1921  case 'spam':
1922  $status = 'spam';
1923  break;
1924  case 'trash':
1925  $status = 'trash';
1926  break;
1927  default:
1928  return false;
1929  }
1930 
1931  $comment_old = clone get_comment($comment_id);
1932 
1933  if ( !$wpdb->update( $wpdb->comments, array('comment_approved' => $status), array( 'comment_ID' => $comment_old->comment_ID ) ) ) {
1934  if ( $wp_error )
1935  return new WP_Error('db_update_error', __('Could not update comment status'), $wpdb->last_error);
1936  else
1937  return false;
1938  }
1939 
1940  clean_comment_cache( $comment_old->comment_ID );
1941 
1942  $comment = get_comment( $comment_old->comment_ID );
1943 
1954  do_action( 'wp_set_comment_status', $comment->comment_ID, $comment_status );
1955 
1956  wp_transition_comment_status($comment_status, $comment_old->comment_approved, $comment);
1957 
1958  wp_update_comment_count($comment->comment_post_ID);
1959 
1960  return true;
1961 }
1962 
1975 function wp_update_comment($commentarr) {
1976  global $wpdb;
1977 
1978  // First, get all of the original fields
1979  $comment = get_comment($commentarr['comment_ID'], ARRAY_A);
1980  if ( empty( $comment ) ) {
1981  return 0;
1982  }
1983 
1984  // Make sure that the comment post ID is valid (if specified).
1985  if ( ! empty( $commentarr['comment_post_ID'] ) && ! get_post( $commentarr['comment_post_ID'] ) ) {
1986  return 0;
1987  }
1988 
1989  // Escape data pulled from DB.
1991 
1992  $old_status = $comment['comment_approved'];
1993 
1994  // Merge old and new fields with new fields overwriting old ones.
1995  $commentarr = array_merge($comment, $commentarr);
1996 
1997  $commentarr = wp_filter_comment( $commentarr );
1998 
1999  // Now extract the merged array.
2000  $data = wp_unslash( $commentarr );
2001 
2009  $data['comment_content'] = apply_filters( 'comment_save_pre', $data['comment_content'] );
2010 
2011  $data['comment_date_gmt'] = get_gmt_from_date( $data['comment_date'] );
2012 
2013  if ( ! isset( $data['comment_approved'] ) ) {
2014  $data['comment_approved'] = 1;
2015  } elseif ( 'hold' == $data['comment_approved'] ) {
2016  $data['comment_approved'] = 0;
2017  } elseif ( 'approve' == $data['comment_approved'] ) {
2018  $data['comment_approved'] = 1;
2019  }
2020 
2021  $comment_ID = $data['comment_ID'];
2022  $comment_post_ID = $data['comment_post_ID'];
2023  $keys = array( 'comment_post_ID', 'comment_content', 'comment_author', 'comment_author_email', 'comment_approved', 'comment_karma', 'comment_author_url', 'comment_date', 'comment_date_gmt', 'comment_type', 'comment_parent', 'user_id', 'comment_agent', 'comment_author_IP' );
2024  $data = wp_array_slice_assoc( $data, $keys );
2025  $rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) );
2026 
2027  clean_comment_cache( $comment_ID );
2028  wp_update_comment_count( $comment_post_ID );
2038  do_action( 'edit_comment', $comment_ID );
2039  $comment = get_comment($comment_ID);
2040  wp_transition_comment_status($comment->comment_approved, $old_status, $comment);
2041  return $rval;
2042 }
2043 
2059  static $_defer = false;
2060 
2061  if ( is_bool($defer) ) {
2062  $_defer = $defer;
2063  // flush any deferred counts
2064  if ( !$defer )
2065  wp_update_comment_count( null, true );
2066  }
2067 
2068  return $_defer;
2069 }
2070 
2093 function wp_update_comment_count($post_id, $do_deferred=false) {
2094  static $_deferred = array();
2095 
2096  if ( empty( $post_id ) && ! $do_deferred ) {
2097  return false;
2098  }
2099 
2100  if ( $do_deferred ) {
2101  $_deferred = array_unique($_deferred);
2102  foreach ( $_deferred as $i => $_post_id ) {
2103  wp_update_comment_count_now($_post_id);
2104  unset( $_deferred[$i] );
2105  }
2106  }
2107 
2108  if ( wp_defer_comment_counting() ) {
2109  $_deferred[] = $post_id;
2110  return true;
2111  }
2112  elseif ( $post_id ) {
2114  }
2115 
2116 }
2117 
2129  global $wpdb;
2130  $post_id = (int) $post_id;
2131  if ( !$post_id )
2132  return false;
2133 
2134  wp_cache_delete( 'comments-0', 'counts' );
2135  wp_cache_delete( "comments-{$post_id}", 'counts' );
2136 
2137  if ( !$post = get_post($post_id) )
2138  return false;
2139 
2140  $old = (int) $post->comment_count;
2141 
2151  $new = apply_filters( 'pre_wp_update_comment_count_now', null, $old, $post_id );
2152 
2153  if ( is_null( $new ) ) {
2154  $new = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id ) );
2155  } else {
2156  $new = (int) $new;
2157  }
2158 
2159  $wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post_id) );
2160 
2162 
2172  do_action( 'wp_update_comment_count', $post_id, $new, $old );
2174  do_action( 'edit_post', $post_id, $post );
2175 
2176  return true;
2177 }
2178 
2179 //
2180 // Ping and trackback functions.
2181 //
2182 
2196 function discover_pingback_server_uri( $url, $deprecated = '' ) {
2197  if ( !empty( $deprecated ) )
2198  _deprecated_argument( __FUNCTION__, '2.7' );
2199 
2200  $pingback_str_dquote = 'rel="pingback"';
2201  $pingback_str_squote = 'rel=\'pingback\'';
2202 
2204  $parsed_url = parse_url($url);
2205 
2206  if ( ! isset( $parsed_url['host'] ) ) // Not a URL. This should never happen.
2207  return false;
2208 
2209  //Do not search for a pingback server on our own uploads
2210  $uploads_dir = wp_get_upload_dir();
2211  if ( 0 === strpos($url, $uploads_dir['baseurl']) )
2212  return false;
2213 
2214  $response = wp_safe_remote_head( $url, array( 'timeout' => 2, 'httpversion' => '1.0' ) );
2215 
2216  if ( is_wp_error( $response ) )
2217  return false;
2218 
2219  if ( wp_remote_retrieve_header( $response, 'x-pingback' ) )
2220  return wp_remote_retrieve_header( $response, 'x-pingback' );
2221 
2222  // Not an (x)html, sgml, or xml page, no use going further.
2223  if ( preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header( $response, 'content-type' )) )
2224  return false;
2225 
2226  // Now do a GET since we're going to look in the html headers (and we're sure it's not a binary file)
2227  $response = wp_safe_remote_get( $url, array( 'timeout' => 2, 'httpversion' => '1.0' ) );
2228 
2229  if ( is_wp_error( $response ) )
2230  return false;
2231 
2232  $contents = wp_remote_retrieve_body( $response );
2233 
2234  $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);
2235  $pingback_link_offset_squote = strpos($contents, $pingback_str_squote);
2236  if ( $pingback_link_offset_dquote || $pingback_link_offset_squote ) {
2237  $quote = ($pingback_link_offset_dquote) ? '"' : '\'';
2238  $pingback_link_offset = ($quote=='"') ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
2239  $pingback_href_pos = @strpos($contents, 'href=', $pingback_link_offset);
2240  $pingback_href_start = $pingback_href_pos+6;
2241  $pingback_href_end = @strpos($contents, $quote, $pingback_href_start);
2242  $pingback_server_url_len = $pingback_href_end - $pingback_href_start;
2243  $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len);
2244 
2245  // We may find rel="pingback" but an incomplete pingback URL
2246  if ( $pingback_server_url_len > 0 ) { // We got it!
2247  return $pingback_server_url;
2248  }
2249  }
2250 
2251  return false;
2252 }
2253 
2261 function do_all_pings() {
2262  global $wpdb;
2263 
2264  // Do pingbacks
2265  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")) {
2266  delete_metadata_by_mid( 'post', $ping->meta_id );
2267  pingback( $ping->post_content, $ping->ID );
2268  }
2269 
2270  // Do Enclosures
2271  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")) {
2272  delete_metadata_by_mid( 'post', $enclosure->meta_id );
2273  do_enclose( $enclosure->post_content, $enclosure->ID );
2274  }
2275 
2276  // Do Trackbacks
2277  $trackbacks = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE to_ping <> '' AND post_status = 'publish'");
2278  if ( is_array($trackbacks) )
2279  foreach ( $trackbacks as $trackback )
2280  do_trackbacks($trackback);
2281 
2282  //Do Update Services/Generic Pings
2283  generic_ping();
2284 }
2285 
2296  global $wpdb;
2297 
2298  $post = get_post( $post_id );
2299  $to_ping = get_to_ping($post_id);
2300  $pinged = get_pung($post_id);
2301  if ( empty($to_ping) ) {
2302  $wpdb->update($wpdb->posts, array('to_ping' => ''), array('ID' => $post_id) );
2303  return;
2304  }
2305 
2306  if ( empty($post->post_excerpt) ) {
2308  $excerpt = apply_filters( 'the_content', $post->post_content, $post->ID );
2309  } else {
2311  $excerpt = apply_filters( 'the_excerpt', $post->post_excerpt );
2312  }
2313 
2314  $excerpt = str_replace(']]>', ']]&gt;', $excerpt);
2315  $excerpt = wp_html_excerpt($excerpt, 252, '&#8230;');
2316 
2318  $post_title = apply_filters( 'the_title', $post->post_title, $post->ID );
2319  $post_title = strip_tags($post_title);
2320 
2321  if ( $to_ping ) {
2322  foreach ( (array) $to_ping as $tb_ping ) {
2323  $tb_ping = trim($tb_ping);
2324  if ( !in_array($tb_ping, $pinged) ) {
2325  trackback($tb_ping, $post_title, $excerpt, $post_id);
2326  $pinged[] = $tb_ping;
2327  } else {
2328  $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $tb_ping, $post_id) );
2329  }
2330  }
2331  }
2332 }
2333 
2342 function generic_ping( $post_id = 0 ) {
2343  $services = get_option('ping_sites');
2344 
2345  $services = explode("\n", $services);
2346  foreach ( (array) $services as $service ) {
2347  $service = trim($service);
2348  if ( '' != $service )
2349  weblog_ping($service);
2350  }
2351 
2352  return $post_id;
2353 }
2354 
2366  global $wp_version;
2367  include_once(ABSPATH . WPINC . '/class-IXR.php');
2368  include_once(ABSPATH . WPINC . '/class-wp-http-ixr-client.php');
2369 
2370  // original code by Mort (http://mort.mine.nu:8080)
2371  $post_links = array();
2372 
2373  $pung = get_pung($post_ID);
2374 
2375  // Step 1
2376  // Parsing the post, external links (if any) are stored in the $post_links array
2377  $post_links_temp = wp_extract_urls( $content );
2378 
2379  // Step 2.
2380  // Walking thru the links array
2381  // first we get rid of links pointing to sites, not to specific files
2382  // Example:
2383  // http://dummy-weblog.org
2384  // http://dummy-weblog.org/
2385  // http://dummy-weblog.org/post.php
2386  // We don't wanna ping first and second types, even if they have a valid <link/>
2387 
2388  foreach ( (array) $post_links_temp as $link_test ) :
2389  if ( !in_array($link_test, $pung) && (url_to_postid($link_test) != $post_ID) // If we haven't pung it already and it isn't a link to itself
2390  && !is_local_attachment($link_test) ) : // Also, let's never ping local attachments.
2391  if ( $test = @parse_url($link_test) ) {
2392  if ( isset($test['query']) )
2393  $post_links[] = $link_test;
2394  elseif ( isset( $test['path'] ) && ( $test['path'] != '/' ) && ( $test['path'] != '' ) )
2395  $post_links[] = $link_test;
2396  }
2397  endif;
2398  endforeach;
2399 
2400  $post_links = array_unique( $post_links );
2410  do_action_ref_array( 'pre_ping', array( &$post_links, &$pung, $post_ID ) );
2411 
2412  foreach ( (array) $post_links as $pagelinkedto ) {
2413  $pingback_server_url = discover_pingback_server_uri( $pagelinkedto );
2414 
2415  if ( $pingback_server_url ) {
2416  @ set_time_limit( 60 );
2417  // Now, the RPC call
2418  $pagelinkedfrom = get_permalink($post_ID);
2419 
2420  // using a timeout of 3 seconds should be enough to cover slow servers
2421  $client = new WP_HTTP_IXR_Client($pingback_server_url);
2422  $client->timeout = 3;
2435  $client->useragent = apply_filters( 'pingback_useragent', $client->useragent . ' -- WordPress/' . $wp_version, $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom );
2436  // when set to true, this outputs debug messages by itself
2437  $client->debug = false;
2438 
2439  if ( $client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || ( isset($client->error->code) && 48 == $client->error->code ) ) // Already registered
2440  add_ping( $post_ID, $pagelinkedto );
2441  }
2442  }
2443 }
2444 
2453 function privacy_ping_filter($sites) {
2454  if ( '0' != get_option('blog_public') )
2455  return $sites;
2456  else
2457  return '';
2458 }
2459 
2475 function trackback($trackback_url, $title, $excerpt, $ID) {
2476  global $wpdb;
2477 
2478  if ( empty($trackback_url) )
2479  return;
2480 
2481  $options = array();
2482  $options['timeout'] = 10;
2483  $options['body'] = array(
2484  'title' => $title,
2485  'url' => get_permalink($ID),
2486  'blog_name' => get_option('blogname'),
2487  'excerpt' => $excerpt
2488  );
2489 
2490  $response = wp_safe_remote_post( $trackback_url, $options );
2491 
2492  if ( is_wp_error( $response ) )
2493  return;
2494 
2495  $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', %s) WHERE ID = %d", $trackback_url, $ID) );
2496  return $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $trackback_url, $ID) );
2497 }
2498 
2509 function weblog_ping($server = '', $path = '') {
2510  global $wp_version;
2511  include_once(ABSPATH . WPINC . '/class-IXR.php');
2512  include_once(ABSPATH . WPINC . '/class-wp-http-ixr-client.php');
2513 
2514  // using a timeout of 3 seconds should be enough to cover slow servers
2515  $client = new WP_HTTP_IXR_Client($server, ((!strlen(trim($path)) || ('/' == $path)) ? false : $path));
2516  $client->timeout = 3;
2517  $client->useragent .= ' -- WordPress/'.$wp_version;
2518 
2519  // when set to true, this outputs debug messages by itself
2520  $client->debug = false;
2521  $home = trailingslashit( home_url() );
2522  if ( !$client->query('weblogUpdates.extendedPing', get_option('blogname'), $home, get_bloginfo('rss2_url') ) ) // then try a normal ping
2523  $client->query('weblogUpdates.ping', get_option('blogname'), $home);
2524 }
2525 
2535 function pingback_ping_source_uri( $source_uri ) {
2536  return (string) wp_http_validate_url( $source_uri );
2537 }
2538 
2551 function xmlrpc_pingback_error( $ixr_error ) {
2552  if ( $ixr_error->code === 48 )
2553  return $ixr_error;
2554  return new IXR_Error( 0, '' );
2555 }
2556 
2557 //
2558 // Cache
2559 //
2560 
2568 function clean_comment_cache($ids) {
2569  foreach ( (array) $ids as $id ) {
2570  wp_cache_delete( $id, 'comment' );
2571 
2579  do_action( 'clean_comment_cache', $id );
2580  }
2581 
2582  wp_cache_set( 'last_changed', microtime(), 'comment' );
2583 }
2584 
2598 function update_comment_cache( $comments, $update_meta_cache = true ) {
2599  foreach ( (array) $comments as $comment )
2600  wp_cache_add($comment->comment_ID, $comment, 'comment');
2601 
2602  if ( $update_meta_cache ) {
2603  // Avoid `wp_list_pluck()` in case `$comments` is passed by reference.
2604  $comment_ids = array();
2605  foreach ( $comments as $comment ) {
2606  $comment_ids[] = $comment->comment_ID;
2607  }
2608  update_meta_cache( 'comment', $comment_ids );
2609  }
2610 }
2611 
2624 function _prime_comment_caches( $comment_ids, $update_meta_cache = true ) {
2625  global $wpdb;
2626 
2627  $non_cached_ids = _get_non_cached_ids( $comment_ids, 'comment' );
2628  if ( !empty( $non_cached_ids ) ) {
2629  $fresh_comments = $wpdb->get_results( sprintf( "SELECT $wpdb->comments.* FROM $wpdb->comments WHERE comment_ID IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) );
2630 
2631  update_comment_cache( $fresh_comments, $update_meta_cache );
2632  }
2633 }
2634 
2635 //
2636 // Internal
2637 //
2638 
2649 function _close_comments_for_old_posts( $posts, $query ) {
2650  if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) )
2651  return $posts;
2652 
2660  $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
2661  if ( ! in_array( $posts[0]->post_type, $post_types ) )
2662  return $posts;
2663 
2664  $days_old = (int) get_option( 'close_comments_days_old' );
2665  if ( ! $days_old )
2666  return $posts;
2667 
2668  if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) {
2669  $posts[0]->comment_status = 'closed';
2670  $posts[0]->ping_status = 'closed';
2671  }
2672 
2673  return $posts;
2674 }
2675 
2687  if ( ! $open )
2688  return $open;
2689 
2690  if ( !get_option('close_comments_for_old_posts') )
2691  return $open;
2692 
2693  $days_old = (int) get_option('close_comments_days_old');
2694  if ( !$days_old )
2695  return $open;
2696 
2697  $post = get_post($post_id);
2698 
2700  $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
2701  if ( ! in_array( $post->post_type, $post_types ) )
2702  return $open;
2703 
2704  // Undated drafts should not show up as comments closed.
2705  if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) {
2706  return $open;
2707  }
2708 
2709  if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) )
2710  return false;
2711 
2712  return $open;
2713 }
2714 
2736 function wp_handle_comment_submission( $comment_data ) {
2737 
2738  $comment_post_ID = $comment_parent = 0;
2739  $comment_author = $comment_author_email = $comment_author_url = $comment_content = $_wp_unfiltered_html_comment = null;
2740 
2741  if ( isset( $comment_data['comment_post_ID'] ) ) {
2742  $comment_post_ID = (int) $comment_data['comment_post_ID'];
2743  }
2744  if ( isset( $comment_data['author'] ) && is_string( $comment_data['author'] ) ) {
2745  $comment_author = trim( strip_tags( $comment_data['author'] ) );
2746  }
2747  if ( isset( $comment_data['email'] ) && is_string( $comment_data['email'] ) ) {
2748  $comment_author_email = trim( $comment_data['email'] );
2749  }
2750  if ( isset( $comment_data['url'] ) && is_string( $comment_data['url'] ) ) {
2751  $comment_author_url = trim( $comment_data['url'] );
2752  }
2753  if ( isset( $comment_data['comment'] ) && is_string( $comment_data['comment'] ) ) {
2754  $comment_content = trim( $comment_data['comment'] );
2755  }
2756  if ( isset( $comment_data['comment_parent'] ) ) {
2757  $comment_parent = absint( $comment_data['comment_parent'] );
2758  }
2759  if ( isset( $comment_data['_wp_unfiltered_html_comment'] ) && is_string( $comment_data['_wp_unfiltered_html_comment'] ) ) {
2760  $_wp_unfiltered_html_comment = trim( $comment_data['_wp_unfiltered_html_comment'] );
2761  }
2762 
2763  $post = get_post( $comment_post_ID );
2764 
2765  if ( empty( $post->comment_status ) ) {
2766 
2774  do_action( 'comment_id_not_found', $comment_post_ID );
2775 
2776  return new WP_Error( 'comment_id_not_found' );
2777 
2778  }
2779 
2780  // get_post_status() will get the parent status for attachments.
2781  $status = get_post_status( $post );
2782 
2783  if ( ( 'private' == $status ) && ! current_user_can( 'read_post', $comment_post_ID ) ) {
2784  return new WP_Error( 'comment_id_not_found' );
2785  }
2786 
2787  $status_obj = get_post_status_object( $status );
2788 
2789  if ( ! comments_open( $comment_post_ID ) ) {
2790 
2798  do_action( 'comment_closed', $comment_post_ID );
2799 
2800  return new WP_Error( 'comment_closed', __( 'Sorry, comments are closed for this item.' ), 403 );
2801 
2802  } elseif ( 'trash' == $status ) {
2803 
2811  do_action( 'comment_on_trash', $comment_post_ID );
2812 
2813  return new WP_Error( 'comment_on_trash' );
2814 
2815  } elseif ( ! $status_obj->public && ! $status_obj->private ) {
2816 
2824  do_action( 'comment_on_draft', $comment_post_ID );
2825 
2826  return new WP_Error( 'comment_on_draft' );
2827 
2828  } elseif ( post_password_required( $comment_post_ID ) ) {
2829 
2837  do_action( 'comment_on_password_protected', $comment_post_ID );
2838 
2839  return new WP_Error( 'comment_on_password_protected' );
2840 
2841  } else {
2842 
2850  do_action( 'pre_comment_on_post', $comment_post_ID );
2851 
2852  }
2853 
2854  // If the user is logged in
2855  $user = wp_get_current_user();
2856  if ( $user->exists() ) {
2857  if ( empty( $user->display_name ) ) {
2858  $user->display_name=$user->user_login;
2859  }
2860  $comment_author = $user->display_name;
2861  $comment_author_email = $user->user_email;
2862  $comment_author_url = $user->user_url;
2863  $user_ID = $user->ID;
2864  if ( current_user_can( 'unfiltered_html' ) ) {
2865  if ( ! isset( $comment_data['_wp_unfiltered_html_comment'] )
2866  || ! wp_verify_nonce( $comment_data['_wp_unfiltered_html_comment'], 'unfiltered-html-comment_' . $comment_post_ID )
2867  ) {
2868  kses_remove_filters(); // start with a clean slate
2869  kses_init_filters(); // set up the filters
2870  }
2871  }
2872  } else {
2873  if ( get_option( 'comment_registration' ) ) {
2874  return new WP_Error( 'not_logged_in', __( 'Sorry, you must be logged in to post a comment.' ), 403 );
2875  }
2876  }
2877 
2878  $comment_type = '';
2879  $max_lengths = wp_get_comment_fields_max_lengths();
2880 
2881  if ( get_option( 'require_name_email' ) && ! $user->exists() ) {
2882  if ( 6 > strlen( $comment_author_email ) || '' == $comment_author ) {
2883  return new WP_Error( 'require_name_email', __( '<strong>ERROR</strong>: please fill the required fields (name, email).' ), 200 );
2884  } elseif ( ! is_email( $comment_author_email ) ) {
2885  return new WP_Error( 'require_valid_email', __( '<strong>ERROR</strong>: please enter a valid email address.' ), 200 );
2886  }
2887  }
2888 
2889  if ( isset( $comment_author ) && $max_lengths['comment_author'] < mb_strlen( $comment_author, '8bit' ) ) {
2890  return new WP_Error( 'comment_author_column_length', __( '<strong>ERROR</strong>: your name is too long.' ), 200 );
2891  }
2892 
2893  if ( isset( $comment_author_email ) && $max_lengths['comment_author_email'] < strlen( $comment_author_email ) ) {
2894  return new WP_Error( 'comment_author_email_column_length', __( '<strong>ERROR</strong>: your email address is too long.' ), 200 );
2895  }
2896 
2897  if ( isset( $comment_author_url ) && $max_lengths['comment_author_url'] < strlen( $comment_author_url ) ) {
2898  return new WP_Error( 'comment_author_url_column_length', __( '<strong>ERROR</strong>: your url is too long.' ), 200 );
2899  }
2900 
2901  if ( '' == $comment_content ) {
2902  return new WP_Error( 'require_valid_comment', __( '<strong>ERROR</strong>: please type a comment.' ), 200 );
2903  } elseif ( $max_lengths['comment_content'] < mb_strlen( $comment_content, '8bit' ) ) {
2904  return new WP_Error( 'comment_content_column_length', __( '<strong>ERROR</strong>: your comment is too long.' ), 200 );
2905  }
2906 
2907  $commentdata = compact(
2908  'comment_post_ID',
2909  'comment_author',
2910  'comment_author_email',
2911  'comment_author_url',
2912  'comment_content',
2913  'comment_type',
2914  'comment_parent',
2915  'user_ID'
2916  );
2917 
2918  $comment_id = wp_new_comment( wp_slash( $commentdata ) );
2919  if ( ! $comment_id ) {
2920  return new WP_Error( 'comment_save_error', __( '<strong>ERROR</strong>: The comment could not be saved. Please try again later.' ), 500 );
2921  }
2922 
2923  return get_comment( $comment_id );
2924 
2925 }
if(has_action( 'welcome_panel') &&current_user_can( 'edit_theme_options')) $option
Definition: index.php:101
wp_allow_comment( $commentdata)
Definition: comment.php:592
const ARRAY_N
Definition: wp-db.php:36
wp_safe_remote_head( $url, $args=array())
Definition: http.php:109
wp_spam_comment( $comment_id)
Definition: comment.php:1302
if( 'en' !==$locale) $title
Definition: about.php:23
is_email( $email, $deprecated=false)
get_lastcommentmodified($timezone='server')
Definition: comment.php:298
$GLOBALS['wp_press_this']
get_comment_pages_count( $comments=null, $per_page=null, $threaded=null)
Definition: comment.php:818
update_meta_cache($meta_type, $object_ids)
Definition: meta.php:788
$comment
wp_trash_comment($comment_id)
Definition: comment.php:1214
$user_id
Definition: user-edit.php:14
pingback_ping_source_uri( $source_uri)
Definition: comment.php:2535
$_COOKIE
Definition: xmlrpc.php:16
wp_get_current_commenter()
Definition: comment.php:1497
global $post_type
if(get_option('db_upgraded')) elseif(get_option( 'db_version') !=$wp_db_version &&empty( $_POST))
Definition: admin.php:45
$keys
Definition: wp-cron.php:61
wp_count_comments( $post_id=0)
Definition: comment.php:1102
wp_cache_delete( $key, $group='')
Definition: cache.php:81
get_approved_comments( $post_id, $args=array())
Definition: comment.php:139
wp_cache_set( $key, $data, $group='', $expire=0)
Definition: cache.php:196
if(isset( $_REQUEST['post_id'])) $id
wp_handle_comment_submission( $comment_data)
Definition: comment.php:2736
get_post_status( $ID='')
Definition: post.php:554
is_wp_error( $thing)
wp_new_comment_notify_moderator( $comment_ID)
Definition: comment.php:1834
do_enclose( $content, $post_ID)
Definition: functions.php:553
kses_remove_filters()
Definition: kses.php:1650
$post_id
wp_delete_comment($comment_id, $force_delete=false)
Definition: comment.php:1150
home_url()
Definition: noop.php:76
privacy_ping_filter($sites)
Definition: comment.php:2453
get_gmt_from_date( $string, $format='Y-m-d H:i:s')
const ABSPATH
endforeach
Definition: customize.php:165
wp_new_comment( $commentdata)
Definition: comment.php:1740
trackback($trackback_url, $title, $excerpt, $ID)
Definition: comment.php:2475
const OBJECT
Definition: wp-db.php:20
_close_comments_for_old_posts( $posts, $query)
Definition: comment.php:2649
sanitize_comment_cookies()
Definition: comment.php:530
add_action()
Definition: noop.php:41
wp_unspam_comment( $comment_id)
Definition: comment.php:1344
get_bloginfo()
Definition: noop.php:56
trailingslashit( $string)
COOKIE_DOMAIN
Definition: wp-login.php:404
apply_filters()
Definition: noop.php:26
url_to_postid( $url)
Definition: rewrite.php:462
_deprecated_argument( $function, $version, $message=null)
Definition: functions.php:3819
wp_safe_remote_post( $url, $args=array())
Definition: http.php:88
delete_comment_meta($comment_id, $meta_key, $meta_value='')
Definition: comment.php:430
check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type)
Definition: comment.php:39
do_action($tag, $arg='')
Definition: plugin.php:482
get_comment_statuses()
Definition: comment.php:232
get_option()
Definition: noop.php:31
$path
Definition: wp-load.php:56
get_to_ping( $post_id)
Definition: post.php:4127
post_type_supports( $post_type, $feature)
Definition: post.php:1635
get_query_var( $var, $default='')
Definition: query.php:26
get_comment_count( $post_id=0)
Definition: comment.php:338
_prime_comment_caches( $comment_ids, $update_meta_cache=true)
Definition: comment.php:2624
$out
wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent)
Definition: comment.php:1042
post_password_required( $post=null)
get_page_of_comment( $comment_ID, $args=array())
Definition: comment.php:874
const object
Definition: wp-db.php:21
wp_set_comment_status($comment_id, $comment_status, $wp_error=false)
Definition: comment.php:1908
const ARRAY_A
Definition: wp-db.php:31
discover_pingback_server_uri( $url, $deprecated='')
Definition: comment.php:2196
wp_insert_comment( $commentdata)
Definition: comment.php:1563
kses_init_filters()
Definition: kses.php:1622
separate_comments(&$comments)
Definition: comment.php:789
add_metadata($meta_type, $object_id, $meta_key, $meta_value, $unique=false)
Definition: meta.php:30
_close_comments_for_old_post( $open, $post_id)
Definition: comment.php:2686
add_ping( $post_id, $uri)
Definition: post.php:4035
current_user_can( $capability)
wp_filter_comment($commentdata)
Definition: comment.php:1631
wp_slash( $value)
if(defined( 'RELOCATE') &&RELOCATE) $secure
Definition: wp-login.php:402
wp_html_excerpt( $str, $count, $more=null)
wp_remote_retrieve_body( $response)
Definition: http.php:283
wp_get_comment_fields_max_lengths()
Definition: comment.php:983
get_post_status_object( $post_status)
Definition: post.php:752
get_metadata($meta_type, $object_id, $meta_key='', $single=false)
Definition: meta.php:461
static get_instance( $id)
check_comment_flood_db( $ip, $email, $date)
Definition: comment.php:726
current_time( $type, $gmt=0)
Definition: functions.php:61
wp_parse_args( $args, $defaults='')
Definition: functions.php:3300
get_default_comment_status( $post_type='post', $comment_type='comment')
Definition: comment.php:252
get_comment(&$comment=null, $output=OBJECT)
Definition: comment.php:170
$excerpt
const WPINC
clean_post_cache( $post)
Definition: post.php:5636
endif
Definition: about.php:192
wp_cache_add( $key, $data, $group='', $expire=0)
Definition: cache.php:27
_get_non_cached_ids( $object_ids, $cache_key)
Definition: functions.php:4903
if(! defined('WP_ADMIN'))
Definition: admin-ajax.php:17
global $post
wp_defer_comment_counting($defer=null)
Definition: comment.php:2058
delete_metadata_by_mid( $meta_type, $meta_id)
Definition: meta.php:701
wp_extract_urls( $content)
Definition: functions.php:516
update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_value='')
Definition: meta.php:143
wp_throttle_comment_flood($block, $time_lastcomment, $time_newcomment)
Definition: comment.php:1693
comments_open( $post_id=null)
clean_comment_cache($ids)
Definition: comment.php:2568
wp_metadata_lazyloader()
Definition: meta.php:861
xmlrpc_pingback_error( $ixr_error)
Definition: comment.php:2551
wp_get_comment_status($comment_id)
Definition: comment.php:1388
get_pung( $post_id)
Definition: post.php:4101
wp_untrash_comment($comment_id)
Definition: comment.php:1258
$ID
get_current_user_id()
Definition: user.php:423
absint( $maybeint)
Definition: functions.php:3613
wp_cache_get( $key, $group='', $force=false, &$found=null)
Definition: cache.php:120
generic_ping( $post_id=0)
Definition: comment.php:2342
is_local_attachment($url)
Definition: post.php:4767
wp_set_comment_cookies($comment, $user)
Definition: comment.php:504
wp_http_validate_url( $url)
Definition: http.php:508
wp_queue_comments_for_comment_meta_lazyload( $comments)
Definition: comment.php:478
get_comment_meta($comment_id, $key='', $single=false)
Definition: comment.php:446
if(! empty( $_GET['action']) &&in_array( $_GET['action'], $core_actions_get)) add_action( 'wp_ajax_' . $_GET['action'] str_replace('-', '_', $_GET[ 'action'])
Definition: admin-ajax.php:73
if(current_theme_supports( 'post-formats') &&post_type_supports( $post_type, 'post-formats')) add_meta_box( 'formatdiv' foreach(get_object_taxonomies( $post) as $tax_name) if( $thumbnail_support &&current_user_can( 'upload_files')) add_meta_box('postimagediv' if(post_type_supports($post_type, 'excerpt')) add_meta_box('postexcerpt' __( 'Excerpt')
get_comments( $args='')
Definition: comment.php:217
esc_attr()
Definition: noop.php:21
global $wp_version
wp_update_comment($commentarr)
Definition: comment.php:1975
do_all_pings()
Definition: comment.php:2261
do_trackbacks($post_id)
Definition: comment.php:2295
$content
Definition: feed-rss2.php:98
wp_array_slice_assoc( $array, $keys)
Definition: functions.php:3337
weblog_ping($server='', $path='')
Definition: comment.php:2509
get_post( $post=null, $output=OBJECT, $filter='raw')
Definition: post.php:430
mysql2date( $format, $date, $translate=true)
Definition: functions.php:26
if(current_theme_supports( 'post-formats') &&post_type_supports( $post_type, 'post-formats')) add_meta_box( 'formatdiv' _x('Format', 'post format')
wp_remote_retrieve_header( $response, $header)
Definition: http.php:231
add_comment_meta($comment_id, $meta_key, $meta_value, $unique=false)
Definition: comment.php:411
do_action_ref_array()
Definition: noop.php:51
$_SERVER['REQUEST_URI']
Definition: edit-tags.php:320
wp_new_comment_notify_postauthor( $comment_ID)
Definition: comment.php:1861
pingback($content, $post_ID)
Definition: comment.php:2365
update_comment_cache( $comments, $update_meta_cache=true)
Definition: comment.php:2598
wp_unslash( $value)
wp_safe_remote_get( $url, $args=array())
Definition: http.php:67
update_comment_meta($comment_id, $meta_key, $meta_value, $prev_value='')
Definition: comment.php:467
wp_update_comment_count_now($post_id)
Definition: comment.php:2128
if(current_theme_supports( 'post-formats') &&post_type_supports( $post_type, 'post-formats')) add_meta_box( 'formatdiv' null
global $wpdb
Definition: schema.php:18
wp_get_upload_dir()
Definition: functions.php:1817
wp_transition_comment_status($new_status, $old_status, $comment)
Definition: comment.php:1429
wp_die( $message='', $title='', $args=array())
Definition: functions.php:2539
delete_metadata($meta_type, $object_id, $meta_key, $meta_value='', $delete_all=false)
Definition: meta.php:307
wp_update_comment_count($post_id, $do_deferred=false)
Definition: comment.php:2093