164
* @global wpdb $wpdb WordPress database abstraction object.
164
* @global wpdb $wpdb WordPress database abstraction object.
165
* @global object $comment
166
167
* @param object|string|int $comment Comment to retrieve.
167
168
* @param string $output Optional. OBJECT or ARRAY_A or ARRAY_N constants.
298
299
* @param callable $name Method to call.
299
300
* @param array $arguments Arguments to pass when calling.
300
* @return mixed|bool Return value of the callback, false otherwise.
301
* @return mixed|false Return value of the callback, false otherwise.
302
303
public function __call( $name, $arguments ) {
303
304
if ( 'get_search_sql' === $name ) {
377
378
* @type array $type__not_in Exclude comments from a given array of comment types. Default empty.
378
379
* @type int $user_id Include comments for a specific user ID. Default empty.
380
* @return WP_Comment_Query WP_Comment_Query instance.
382
382
public function __construct( $query = '' ) {
383
383
$this->query_var_defaults = array(
456
456
* @param string|array $query Array or URL query string of parameters.
457
* @return array List of comments.
457
* @return array|int List of comments, or number of comments when 'count' is passed as a query var.
459
459
public function query( $query ) {
460
460
$this->query_vars = wp_parse_args( $query );
482
482
$this->meta_query = new WP_Meta_Query();
483
483
$this->meta_query->parse_query_vars( $this->query_vars );
485
if ( ! empty( $this->meta_query->queries ) ) {
486
$meta_query_clauses = $this->meta_query->get_sql( 'comment', $wpdb->comments, 'comment_ID', $this );
490
486
* Fires before comments are retrieved.
496
492
do_action_ref_array( 'pre_get_comments', array( &$this ) );
494
// Reparse query vars, in case they were modified in a 'pre_get_comments' callback.
495
$this->meta_query->parse_query_vars( $this->query_vars );
496
if ( ! empty( $this->meta_query->queries ) ) {
497
$meta_query_clauses = $this->meta_query->get_sql( 'comment', $wpdb->comments, 'comment_ID', $this );
498
500
// $args can include anything. Only use the args defined in the query_var_defaults to compute the key.
499
501
$key = md5( serialize( wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ) ) );
500
502
$last_changed = wp_cache_get( 'last_changed', 'comment' );
697
699
// Parse comment IDs for an IN clause.
698
700
if ( ! empty( $this->query_vars['comment__in'] ) ) {
699
$where[] = 'comment_ID IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['comment__in'] ) ) . ' )';
701
$where[] = "$wpdb->comments.comment_ID IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__in'] ) ) . ' )';
702
704
// Parse comment IDs for a NOT IN clause.
703
705
if ( ! empty( $this->query_vars['comment__not_in'] ) ) {
704
$where[] = 'comment_ID NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['comment__not_in'] ) ) . ' )';
706
$where[] = "$wpdb->comments.comment_ID NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__not_in'] ) ) . ' )';
707
709
// Parse comment post IDs for an IN clause.
893
895
$comments = apply_filters_ref_array( 'the_comments', array( $results, &$this ) );
895
897
wp_cache_add( $cache_key, $comments, 'comment' );
898
if ( '*' === $fields ) {
899
update_comment_cache( $comments );
897
902
$this->comments = $comments;
898
903
return $this->comments;
930
937
* @global wpdb $wpdb WordPress database abstraction object.
932
939
* @param string $orderby Alias for the field to order by.
933
* @return string|bool Value to used in the ORDER clause. False otherwise.
940
* @return string|false Value to used in the ORDER clause. False otherwise.
935
942
protected function parse_orderby( $orderby ) {
968
975
if ( $orderby == $this->query_vars['meta_key'] || $orderby == 'meta_value' ) {
969
976
$parsed = "$wpdb->commentmeta.meta_value";
970
} else if ( $orderby == 'meta_value_num' ) {
977
} elseif ( $orderby == 'meta_value_num' ) {
971
978
$parsed = "$wpdb->commentmeta.meta_value+0";
972
} else if ( in_array( $orderby, $allowed_keys ) ) {
979
} elseif ( in_array( $orderby, $allowed_keys ) ) {
974
981
if ( isset( $meta_query_clauses[ $orderby ] ) ) {
975
982
$meta_clause = $meta_query_clauses[ $orderby ];
1037
* Gets the default comment status for a post type.
1041
* @param string $post_type Optional. Post type. Default 'post'.
1042
* @param string $comment_type Optional. Comment type. Default 'comment'.
1043
* @return string Expected return value is 'open' or 'closed'.
1045
function get_default_comment_status( $post_type = 'post', $comment_type = 'comment' ) {
1046
switch ( $comment_type ) {
1049
$supports = 'trackbacks';
1053
$supports = 'comments';
1054
$option = 'comment';
1058
if ( 'page' === $post_type ) {
1060
} elseif ( post_type_supports( $post_type, $supports ) ) {
1061
$status = get_option( "default_{$option}_status" );
1067
* Filter the default comment status for the given post type.
1071
* @param string $status Default status for the given post type,
1072
* either 'open' or 'closed'.
1073
* @param string $post_type Post type. Default is `post`.
1074
* @param string $comment_type Type of comment. Default is `comment`.
1076
return apply_filters( 'get_default_comment_status' , $status, $post_type, $comment_type );
1030
1080
* The date the last comment was modified.
1034
1084
* @global wpdb $wpdb WordPress database abstraction object.
1085
* @staticvar array $cache_lastcommentmodified
1036
1087
* @param string $timezone Which timezone to use in reference to 'gmt', 'blog',
1037
1088
* or 'server' locations.
1294
1345
* @global wpdb $wpdb WordPress database abstraction object.
1296
1347
* @param array $commentdata Contains information on the comment
1297
* @return mixed Signifies the approval status (0|1|'spam')
1348
* @return int|string Signifies the approval status (0|1|'spam')
1299
1350
function wp_allow_comment( $commentdata ) {
1483
1534
* @uses Walker_Comment
1536
* @global WP_Query $wp_query
1485
1538
* @param array $comments Optional array of comment objects. Defaults to $wp_query->comments
1486
* @param int $per_page Optional comments per page.
1487
* @param boolean $threaded Optional control over flat or threaded comments.
1539
* @param int $per_page Optional comments per page.
1540
* @param bool $threaded Optional control over flat or threaded comments.
1488
1541
* @return int Number of comment pages.
1490
1543
function get_comment_pages_count( $comments = null, $per_page = null, $threaded = null ) {
2085
* Inserts a comment to the database.
2087
* The available comment data key names are 'comment_author_IP', 'comment_date',
2088
* 'comment_date_gmt', 'comment_parent', 'comment_approved', and 'user_id'.
2142
* Inserts a comment into the database.
2092
2146
* @global wpdb $wpdb WordPress database abstraction object.
2094
* @param array $commentdata Contains information on the comment.
2095
* @return int|bool The new comment's ID on success, false on failure.
2148
* @param array $commentdata {
2149
* Array of arguments for inserting a new comment.
2151
* @type string $comment_agent The HTTP user agent of the `$comment_author` when
2152
* the comment was submitted. Default empty.
2153
* @type int|string $comment_approved Whether the comment has been approved. Default 1.
2154
* @type string $comment_author The name of the author of the comment. Default empty.
2155
* @type string $comment_author_email The email address of the `$comment_author`. Default empty.
2156
* @type string $comment_author_IP The IP address of the `$comment_author`. Default empty.
2157
* @type string $comment_author_url The URL address of the `$comment_author`. Default empty.
2158
* @type string $comment_content The content of the comment. Default empty.
2159
* @type string $comment_date The date the comment was submitted. To set the date
2160
* manually, `$comment_date_gmt` must also be specified.
2161
* Default is the current time.
2162
* @type string $comment_date_gmt The date the comment was submitted in the GMT timezone.
2163
* Default is `$comment_date` in the site's GMT timezone.
2164
* @type int $comment_karma The karma of the comment. Default 0.
2165
* @type int $comment_parent ID of this comment's parent, if any. Default 0.
2166
* @type int $comment_post_ID ID of the post that relates to the comment, if any.
2168
* @type string $comment_type Comment type. Default empty.
2169
* @type int $user_id ID of the user who submitted the comment. Default 0.
2171
* @return int|false The new comment's ID on success, false on failure.
2097
2173
function wp_insert_comment( $commentdata ) {
2238
2314
* See {@link https://core.trac.wordpress.org/ticket/9235}
2241
* @param array $commentdata Contains information on the comment.
2242
* @return int|bool The ID of the comment on success, false on failure.
2317
* @since 4.3.0 'comment_agent' and 'comment_author_IP' can be set via `$commentdata`.
2319
* @see wp_insert_comment()
2321
* @global wpdb $wpdb
2323
* @param array $commentdata Contains information on the comment. See wp_insert_comment()
2324
* for information on accepted arguments.
2325
* @return int|false The ID of the comment on success, false on failure.
2244
2327
function wp_new_comment( $commentdata ) {
2270
2353
$parent_status = ( 0 < $commentdata['comment_parent'] ) ? wp_get_comment_status($commentdata['comment_parent']) : '';
2271
2354
$commentdata['comment_parent'] = ( 'approved' == $parent_status || 'unapproved' == $parent_status ) ? $commentdata['comment_parent'] : 0;
2273
$commentdata['comment_author_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', '',$_SERVER['REMOTE_ADDR'] );
2274
$commentdata['comment_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? substr( $_SERVER['HTTP_USER_AGENT'], 0, 254 ) : '';
2356
if ( ! isset( $commentdata['comment_author_IP'] ) ) {
2357
$commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR'];
2359
$commentdata['comment_author_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', '', $commentdata['comment_author_IP'] );
2361
if ( ! isset( $commentdata['comment_agent'] ) ) {
2362
$commentdata['comment_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT']: '';
2364
$commentdata['comment_agent'] = substr( $commentdata['comment_agent'], 0, 254 );
2276
2366
if ( empty( $commentdata['comment_date'] ) ) {
2277
2367
$commentdata['comment_date'] = current_time('mysql');
2341
2433
* @param int $comment_id Comment ID.
2342
2434
* @param string $comment_status New comment status, either 'hold', 'approve', 'spam', or 'trash'.
2343
2435
* @param bool $wp_error Whether to return a WP_Error object if there is a failure. Default is false.
2523
2615
* @see wp_update_comment_count_now() For what could cause a false return value
2617
* @staticvar array $_deferred
2525
2619
* @param int $post_id Post ID
2526
2620
* @param bool $do_deferred Whether to process previously deferred post comment counts
2527
* @return bool|null True on success, false on failure
2621
* @return bool|void True on success, false on failure
2529
2623
function wp_update_comment_count($post_id, $do_deferred=false) {
2530
2624
static $_deferred = array();
2880
2975
* @param string $title Title of post.
2881
2976
* @param string $excerpt Excerpt of post.
2882
2977
* @param int $ID Post ID.
2883
* @return mixed Database query from update.
2978
* @return int|false|void Database query from update.
2885
2980
function trackback($trackback_url, $title, $excerpt, $ID) {
3007
3103
* @access private
3010
* @param object $posts Post data object.
3011
* @param object $query Query object.
3106
* @param WP_Post $posts Post data object.
3107
* @param WP_Query $query Query object.
3014
3110
function _close_comments_for_old_posts( $posts, $query ) {
3015
3111
if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) )