X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/0459461f9ea42e0b090759ff6fe5f48360bef750..4feeb71a9d812a9ae371c28a3d8b442a4394ded7:/wp-includes/class-wp-comment-query.php diff --git a/wp-includes/class-wp-comment-query.php b/wp-includes/class-wp-comment-query.php index 9f6aaa53..eae452f5 100644 --- a/wp-includes/class-wp-comment-query.php +++ b/wp-includes/class-wp-comment-query.php @@ -150,12 +150,14 @@ class WP_Comment_Query { * @since 4.4.0 `$parent__in` and `$parent__not_in` were added. * @since 4.4.0 Order by `comment__in` was added. `$update_comment_meta_cache`, `$no_found_rows`, * `$hierarchical`, and `$update_comment_post_cache` were added. + * @since 4.5.0 Introduced the `$author_url` argument. * @access public * * @param string|array $query { * Optional. Array or query string of comment query parameters. Default empty. * * @type string $author_email Comment author email address. Default empty. + * @type string $author_url Comment author URL. Default empty. * @type array $author__in Array of author IDs to include comments for. Default empty. * @type array $author__not_in Array of author IDs to exclude comments for. Default empty. * @type array $comment__in Array of comment IDs to include. Default empty. @@ -217,11 +219,12 @@ class WP_Comment_Query { * Default empty. * @type array $post__not_in Array of post IDs to exclude affiliated comments for. * Default empty. - * @type int $post_author Comment author ID to limit results by. Default empty. - * @type string $post_status Post status to retrieve affiliated comments for. - * Default empty. - * @type string $post_type Post type to retrieve affiliated comments for. + * @type int $post_author Post author ID to limit results by. Default empty. + * @type string|array $post_status Post status or array of post statuses to retrieve + * affiliated comments for. Pass 'any' to match any value. * Default empty. + * @type string $post_type Post type or array of post types to retrieve affiliated + * comments for. Pass 'any' to match any value. Default empty. * @type string $post_name Post name to retrieve affiliated comments for. * Default empty. * @type int $post_parent Post parent ID to retrieve affiliated comments for. @@ -256,6 +259,7 @@ class WP_Comment_Query { public function __construct( $query = '' ) { $this->query_var_defaults = array( 'author_email' => '', + 'author_url' => '', 'author__in' => '', 'author__not_in' => '', 'include_unapproved' => '', @@ -270,6 +274,8 @@ class WP_Comment_Query { 'orderby' => '', 'order' => 'DESC', 'parent' => '', + 'parent__in' => '', + 'parent__not_in' => '', 'post_author__in' => '', 'post_author__not_in' => '', 'post_ID' => '', @@ -681,6 +687,10 @@ class WP_Comment_Query { $this->sql_clauses['where']['author_email'] = $wpdb->prepare( 'comment_author_email = %s', $this->query_vars['author_email'] ); } + if ( '' !== $this->query_vars['author_url'] ) { + $this->sql_clauses['where']['author_url'] = $wpdb->prepare( 'comment_author_url = %s', $this->query_vars['author_url'] ); + } + if ( '' !== $this->query_vars['karma'] ) { $this->sql_clauses['where']['karma'] = $wpdb->prepare( 'comment_karma = %d', $this->query_vars['karma'] ); } @@ -738,7 +748,8 @@ class WP_Comment_Query { $this->sql_clauses['where']['user_id'] = $wpdb->prepare( 'user_id = %d', $this->query_vars['user_id'] ); } - if ( '' !== $this->query_vars['search'] ) { + // Falsy search strings are ignored. + if ( strlen( $this->query_vars['search'] ) ) { $search_sql = $this->get_search_sql( $this->query_vars['search'], array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' ) @@ -750,7 +761,7 @@ class WP_Comment_Query { // If any post-related query vars are passed, join the posts table. $join_posts_table = false; - $plucked = wp_array_slice_assoc( $this->query_vars, array( 'post_author', 'post_name', 'post_parent', 'post_status', 'post_type' ) ); + $plucked = wp_array_slice_assoc( $this->query_vars, array( 'post_author', 'post_name', 'post_parent' ) ); $post_fields = array_filter( $plucked ); if ( ! empty( $post_fields ) ) { @@ -762,6 +773,27 @@ class WP_Comment_Query { } } + // 'post_status' and 'post_type' are handled separately, due to the specialized behavior of 'any'. + foreach ( array( 'post_status', 'post_type' ) as $field_name ) { + $q_values = array(); + if ( ! empty( $this->query_vars[ $field_name ] ) ) { + $q_values = $this->query_vars[ $field_name ]; + if ( ! is_array( $q_values ) ) { + $q_values = explode( ',', $q_values ); + } + + // 'any' will cause the query var to be ignored. + if ( in_array( 'any', $q_values, true ) || empty( $q_values ) ) { + continue; + } + + $join_posts_table = true; + + $esses = array_fill( 0, count( $q_values ), '%s' ); + $this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ")", $q_values ); + } + } + // Comment author IDs for an IN clause. if ( ! empty( $this->query_vars['author__in'] ) ) { $this->sql_clauses['where']['author__in'] = 'user_id IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['author__in'] ) ) . ' )';