[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> class-wp-comment-query.php (source)

   1  <?php
   2  /**
   3   * Comment API: WP_Comment_Query class
   4   *
   5   * @package WordPress
   6   * @subpackage Comments
   7   * @since 4.4.0
   8   */
   9  
  10  /**
  11   * Core class used for querying comments.
  12   *
  13   * @since 3.1.0
  14   *
  15   * @see WP_Comment_Query::__construct() for accepted arguments.
  16   */
  17  class WP_Comment_Query {
  18  
  19      /**
  20       * SQL for database query.
  21       *
  22       * @since 4.0.1
  23       * @var string
  24       */
  25      public $request;
  26  
  27      /**
  28       * Metadata query container
  29       *
  30       * @since 3.5.0
  31       * @var object WP_Meta_Query
  32       */
  33      public $meta_query = false;
  34  
  35      /**
  36       * Metadata query clauses.
  37       *
  38       * @since 4.4.0
  39       * @var array
  40       */
  41      protected $meta_query_clauses;
  42  
  43      /**
  44       * SQL query clauses.
  45       *
  46       * @since 4.4.0
  47       * @var array
  48       */
  49      protected $sql_clauses = array(
  50          'select'  => '',
  51          'from'    => '',
  52          'where'   => array(),
  53          'groupby' => '',
  54          'orderby' => '',
  55          'limits'  => '',
  56      );
  57  
  58      /**
  59       * SQL WHERE clause.
  60       *
  61       * Stored after the {@see 'comments_clauses'} filter is run on the compiled WHERE sub-clauses.
  62       *
  63       * @since 4.4.2
  64       * @var string
  65       */
  66      protected $filtered_where_clause;
  67  
  68      /**
  69       * Date query container
  70       *
  71       * @since 3.7.0
  72       * @var object WP_Date_Query
  73       */
  74      public $date_query = false;
  75  
  76      /**
  77       * Query vars set by the user.
  78       *
  79       * @since 3.1.0
  80       * @var array
  81       */
  82      public $query_vars;
  83  
  84      /**
  85       * Default values for query vars.
  86       *
  87       * @since 4.2.0
  88       * @var array
  89       */
  90      public $query_var_defaults;
  91  
  92      /**
  93       * List of comments located by the query.
  94       *
  95       * @since 4.0.0
  96       * @var array
  97       */
  98      public $comments;
  99  
 100      /**
 101       * The amount of found comments for the current query.
 102       *
 103       * @since 4.4.0
 104       * @var int
 105       */
 106      public $found_comments = 0;
 107  
 108      /**
 109       * The number of pages.
 110       *
 111       * @since 4.4.0
 112       * @var int
 113       */
 114      public $max_num_pages = 0;
 115  
 116      /**
 117       * Make private/protected methods readable for backward compatibility.
 118       *
 119       * @since 4.0.0
 120       *
 121       * @param string   $name      Method to call.
 122       * @param array    $arguments Arguments to pass when calling.
 123       * @return mixed|false Return value of the callback, false otherwise.
 124       */
 125  	public function __call( $name, $arguments ) {
 126          if ( 'get_search_sql' === $name ) {
 127              return $this->get_search_sql( ...$arguments );
 128          }
 129          return false;
 130      }
 131  
 132      /**
 133       * Constructor.
 134       *
 135       * Sets up the comment query, based on the query vars passed.
 136       *
 137       * @since 4.2.0
 138       * @since 4.4.0 `$parent__in` and `$parent__not_in` were added.
 139       * @since 4.4.0 Order by `comment__in` was added. `$update_comment_meta_cache`, `$no_found_rows`,
 140       *              `$hierarchical`, and `$update_comment_post_cache` were added.
 141       * @since 4.5.0 Introduced the `$author_url` argument.
 142       * @since 4.6.0 Introduced the `$cache_domain` argument.
 143       * @since 4.9.0 Introduced the `$paged` argument.
 144       *
 145       * @param string|array $query {
 146       *     Optional. Array or query string of comment query parameters. Default empty.
 147       *
 148       *     @type string       $author_email              Comment author email address. Default empty.
 149       *     @type string       $author_url                Comment author URL. Default empty.
 150       *     @type array        $author__in                Array of author IDs to include comments for. Default empty.
 151       *     @type array        $author__not_in            Array of author IDs to exclude comments for. Default empty.
 152       *     @type array        $comment__in               Array of comment IDs to include. Default empty.
 153       *     @type array        $comment__not_in           Array of comment IDs to exclude. Default empty.
 154       *     @type bool         $count                     Whether to return a comment count (true) or array of
 155       *                                                   comment objects (false). Default false.
 156       *     @type array        $date_query                Date query clauses to limit comments by. See WP_Date_Query.
 157       *                                                   Default null.
 158       *     @type string       $fields                    Comment fields to return. Accepts 'ids' for comment IDs
 159       *                                                   only or empty for all fields. Default empty.
 160       *     @type int          $ID                        Currently unused.
 161       *     @type array        $include_unapproved        Array of IDs or email addresses of users whose unapproved
 162       *                                                   comments will be returned by the query regardless of
 163       *                                                   `$status`. Default empty.
 164       *     @type int          $karma                     Karma score to retrieve matching comments for.
 165       *                                                   Default empty.
 166       *     @type string       $meta_key                  Include comments with a matching comment meta key.
 167       *                                                   Default empty.
 168       *     @type string       $meta_value                Include comments with a matching comment meta value.
 169       *                                                   Requires `$meta_key` to be set. Default empty.
 170       *     @type array        $meta_query                Meta query clauses to limit retrieved comments by.
 171       *                                                   See WP_Meta_Query. Default empty.
 172       *     @type int          $number                    Maximum number of comments to retrieve.
 173       *                                                   Default empty (no limit).
 174       *     @type int          $paged                     When used with $number, defines the page of results to return.
 175       *                                                   When used with $offset, $offset takes precedence. Default 1.
 176       *     @type int          $offset                    Number of comments to offset the query. Used to build
 177       *                                                   LIMIT clause. Default 0.
 178       *     @type bool         $no_found_rows             Whether to disable the `SQL_CALC_FOUND_ROWS` query.
 179       *                                                   Default: true.
 180       *     @type string|array $orderby                   Comment status or array of statuses. To use 'meta_value'
 181       *                                                   or 'meta_value_num', `$meta_key` must also be defined.
 182       *                                                   To sort by a specific `$meta_query` clause, use that
 183       *                                                   clause's array key. Accepts 'comment_agent',
 184       *                                                   'comment_approved', 'comment_author',
 185       *                                                   'comment_author_email', 'comment_author_IP',
 186       *                                                   'comment_author_url', 'comment_content', 'comment_date',
 187       *                                                   'comment_date_gmt', 'comment_ID', 'comment_karma',
 188       *                                                   'comment_parent', 'comment_post_ID', 'comment_type',
 189       *                                                   'user_id', 'comment__in', 'meta_value', 'meta_value_num',
 190       *                                                   the value of $meta_key, and the array keys of
 191       *                                                   `$meta_query`. Also accepts false, an empty array, or
 192       *                                                   'none' to disable `ORDER BY` clause.
 193       *                                                   Default: 'comment_date_gmt'.
 194       *     @type string       $order                     How to order retrieved comments. Accepts 'ASC', 'DESC'.
 195       *                                                   Default: 'DESC'.
 196       *     @type int          $parent                    Parent ID of comment to retrieve children of.
 197       *                                                   Default empty.
 198       *     @type array        $parent__in                Array of parent IDs of comments to retrieve children for.
 199       *                                                   Default empty.
 200       *     @type array        $parent__not_in            Array of parent IDs of comments *not* to retrieve
 201       *                                                   children for. Default empty.
 202       *     @type array        $post_author__in           Array of author IDs to retrieve comments for.
 203       *                                                   Default empty.
 204       *     @type array        $post_author__not_in       Array of author IDs *not* to retrieve comments for.
 205       *                                                   Default empty.
 206       *     @type int          $post_ID                   Currently unused.
 207       *     @type int          $post_id                   Limit results to those affiliated with a given post ID.
 208       *                                                   Default 0.
 209       *     @type array        $post__in                  Array of post IDs to include affiliated comments for.
 210       *                                                   Default empty.
 211       *     @type array        $post__not_in              Array of post IDs to exclude affiliated comments for.
 212       *                                                   Default empty.
 213       *     @type int          $post_author               Post author ID to limit results by. Default empty.
 214       *     @type string|array $post_status               Post status or array of post statuses to retrieve
 215       *                                                   affiliated comments for. Pass 'any' to match any value.
 216       *                                                   Default empty.
 217       *     @type string       $post_type                 Post type or array of post types to retrieve affiliated
 218       *                                                   comments for. Pass 'any' to match any value. Default empty.
 219       *     @type string       $post_name                 Post name to retrieve affiliated comments for.
 220       *                                                   Default empty.
 221       *     @type int          $post_parent               Post parent ID to retrieve affiliated comments for.
 222       *                                                   Default empty.
 223       *     @type string       $search                    Search term(s) to retrieve matching comments for.
 224       *                                                   Default empty.
 225       *     @type string|array $status                    Comment stati to limit results by. Accepts an array
 226       *                                                   or space/comma-separated list of 'hold' (`comment_status=0`),
 227       *                                                   'approve' (`comment_status=1`), 'all', or a custom
 228       *                                                   comment status. Default 'all'.
 229       *     @type string|array $type                      Include comments of a given type, or array of types.
 230       *                                                   Accepts 'comment', 'pings' (includes 'pingback' and
 231       *                                                   'trackback'), or anycustom type string. Default empty.
 232       *     @type array        $type__in                  Include comments from a given array of comment types.
 233       *                                                   Default empty.
 234       *     @type array        $type__not_in              Exclude comments from a given array of comment types.
 235       *                                                   Default empty.
 236       *     @type int          $user_id                   Include comments for a specific user ID. Default empty.
 237       *     @type bool|string  $hierarchical              Whether to include comment descendants in the results.
 238       *                                                   'threaded' returns a tree, with each comment's children
 239       *                                                   stored in a `children` property on the `WP_Comment`
 240       *                                                   object. 'flat' returns a flat array of found comments plus
 241       *                                                   their children. Pass `false` to leave out descendants.
 242       *                                                   The parameter is ignored (forced to `false`) when
 243       *                                                   `$fields` is 'ids' or 'counts'. Accepts 'threaded',
 244       *                                                   'flat', or false. Default: false.
 245       *     @type string       $cache_domain              Unique cache key to be produced when this query is stored in
 246       *                                                   an object cache. Default is 'core'.
 247       *     @type bool         $update_comment_meta_cache Whether to prime the metadata cache for found comments.
 248       *                                                   Default true.
 249       *     @type bool         $update_comment_post_cache Whether to prime the cache for comment posts.
 250       *                                                   Default false.
 251       * }
 252       */
 253  	public function __construct( $query = '' ) {
 254          $this->query_var_defaults = array(
 255              'author_email'              => '',
 256              'author_url'                => '',
 257              'author__in'                => '',
 258              'author__not_in'            => '',
 259              'include_unapproved'        => '',
 260              'fields'                    => '',
 261              'ID'                        => '',
 262              'comment__in'               => '',
 263              'comment__not_in'           => '',
 264              'karma'                     => '',
 265              'number'                    => '',
 266              'offset'                    => '',
 267              'no_found_rows'             => true,
 268              'orderby'                   => '',
 269              'order'                     => 'DESC',
 270              'paged'                     => 1,
 271              'parent'                    => '',
 272              'parent__in'                => '',
 273              'parent__not_in'            => '',
 274              'post_author__in'           => '',
 275              'post_author__not_in'       => '',
 276              'post_ID'                   => '',
 277              'post_id'                   => 0,
 278              'post__in'                  => '',
 279              'post__not_in'              => '',
 280              'post_author'               => '',
 281              'post_name'                 => '',
 282              'post_parent'               => '',
 283              'post_status'               => '',
 284              'post_type'                 => '',
 285              'status'                    => 'all',
 286              'type'                      => '',
 287              'type__in'                  => '',
 288              'type__not_in'              => '',
 289              'user_id'                   => '',
 290              'search'                    => '',
 291              'count'                     => false,
 292              'meta_key'                  => '',
 293              'meta_value'                => '',
 294              'meta_query'                => '',
 295              'date_query'                => null, // See WP_Date_Query.
 296              'hierarchical'              => false,
 297              'cache_domain'              => 'core',
 298              'update_comment_meta_cache' => true,
 299              'update_comment_post_cache' => false,
 300          );
 301  
 302          if ( ! empty( $query ) ) {
 303              $this->query( $query );
 304          }
 305      }
 306  
 307      /**
 308       * Parse arguments passed to the comment query with default query parameters.
 309       *
 310       * @since 4.2.0 Extracted from WP_Comment_Query::query().
 311       *
 312       * @param string|array $query WP_Comment_Query arguments. See WP_Comment_Query::__construct()
 313       */
 314  	public function parse_query( $query = '' ) {
 315          if ( empty( $query ) ) {
 316              $query = $this->query_vars;
 317          }
 318  
 319          $this->query_vars = wp_parse_args( $query, $this->query_var_defaults );
 320  
 321          /**
 322           * Fires after the comment query vars have been parsed.
 323           *
 324           * @since 4.2.0
 325           *
 326           * @param WP_Comment_Query $this The WP_Comment_Query instance (passed by reference).
 327           */
 328          do_action_ref_array( 'parse_comment_query', array( &$this ) );
 329      }
 330  
 331      /**
 332       * Sets up the WordPress query for retrieving comments.
 333       *
 334       * @since 3.1.0
 335       * @since 4.1.0 Introduced 'comment__in', 'comment__not_in', 'post_author__in',
 336       *              'post_author__not_in', 'author__in', 'author__not_in', 'post__in',
 337       *              'post__not_in', 'include_unapproved', 'type__in', and 'type__not_in'
 338       *              arguments to $query_vars.
 339       * @since 4.2.0 Moved parsing to WP_Comment_Query::parse_query().
 340       *
 341       * @param string|array $query Array or URL query string of parameters.
 342       * @return array|int List of comments, or number of comments when 'count' is passed as a query var.
 343       */
 344  	public function query( $query ) {
 345          $this->query_vars = wp_parse_args( $query );
 346          return $this->get_comments();
 347      }
 348  
 349      /**
 350       * Get a list of comments matching the query vars.
 351       *
 352       * @since 4.2.0
 353       *
 354       * @global wpdb $wpdb WordPress database abstraction object.
 355       *
 356       * @return int|array List of comments or number of found comments if `$count` argument is true.
 357       */
 358  	public function get_comments() {
 359          global $wpdb;
 360  
 361          $this->parse_query();
 362  
 363          // Parse meta query.
 364          $this->meta_query = new WP_Meta_Query();
 365          $this->meta_query->parse_query_vars( $this->query_vars );
 366  
 367          /**
 368           * Fires before comments are retrieved.
 369           *
 370           * @since 3.1.0
 371           *
 372           * @param WP_Comment_Query $this Current instance of WP_Comment_Query (passed by reference).
 373           */
 374          do_action_ref_array( 'pre_get_comments', array( &$this ) );
 375  
 376          // Reparse query vars, in case they were modified in a 'pre_get_comments' callback.
 377          $this->meta_query->parse_query_vars( $this->query_vars );
 378          if ( ! empty( $this->meta_query->queries ) ) {
 379              $this->meta_query_clauses = $this->meta_query->get_sql( 'comment', $wpdb->comments, 'comment_ID', $this );
 380          }
 381  
 382          $comment_data = null;
 383  
 384          /**
 385           * Filter the comments data before the query takes place.
 386           *
 387           * Return a non-null value to bypass WordPress's default comment queries.
 388           *
 389           * The expected return type from this filter depends on the value passed in the request query_vars.
 390           * When `$this->query_vars['count']` is set, the filter should return the comment count as an int.
 391           * When `'ids' === $this->query_vars['fields']`, the filter should return an array of comment IDs.
 392           * Otherwise the filter should return an array of WP_Comment objects.
 393           *
 394           * @since 5.3.0
 395           *
 396           * @param array|int|null   $comment_data Return an array of comment data to short-circuit WP's comment query,
 397           *                                       the comment count as an integer if `$this->query_vars['count']` is set,
 398           *                                       or null to allow WP to run its normal queries.
 399           * @param WP_Comment_Query $this         The WP_Comment_Query instance, passed by reference.
 400           */
 401          $comment_data = apply_filters_ref_array( 'comments_pre_query', array( $comment_data, &$this ) );
 402  
 403          if ( null !== $comment_data ) {
 404              return $comment_data;
 405          }
 406  
 407          /*
 408           * Only use the args defined in the query_var_defaults to compute the key,
 409           * but ignore 'fields', which does not affect query results.
 410           */
 411          $_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) );
 412          unset( $_args['fields'] );
 413  
 414          $key          = md5( serialize( $_args ) );
 415          $last_changed = wp_cache_get_last_changed( 'comment' );
 416  
 417          $cache_key   = "get_comments:$key:$last_changed";
 418          $cache_value = wp_cache_get( $cache_key, 'comment' );
 419          if ( false === $cache_value ) {
 420              $comment_ids = $this->get_comment_ids();
 421              if ( $comment_ids ) {
 422                  $this->set_found_comments();
 423              }
 424  
 425              $cache_value = array(
 426                  'comment_ids'    => $comment_ids,
 427                  'found_comments' => $this->found_comments,
 428              );
 429              wp_cache_add( $cache_key, $cache_value, 'comment' );
 430          } else {
 431              $comment_ids          = $cache_value['comment_ids'];
 432              $this->found_comments = $cache_value['found_comments'];
 433          }
 434  
 435          if ( $this->found_comments && $this->query_vars['number'] ) {
 436              $this->max_num_pages = ceil( $this->found_comments / $this->query_vars['number'] );
 437          }
 438  
 439          // If querying for a count only, there's nothing more to do.
 440          if ( $this->query_vars['count'] ) {
 441              // $comment_ids is actually a count in this case.
 442              return intval( $comment_ids );
 443          }
 444  
 445          $comment_ids = array_map( 'intval', $comment_ids );
 446  
 447          if ( 'ids' === $this->query_vars['fields'] ) {
 448              $this->comments = $comment_ids;
 449              return $this->comments;
 450          }
 451  
 452          _prime_comment_caches( $comment_ids, $this->query_vars['update_comment_meta_cache'] );
 453  
 454          // Fetch full comment objects from the primed cache.
 455          $_comments = array();
 456          foreach ( $comment_ids as $comment_id ) {
 457              $_comment = get_comment( $comment_id );
 458              if ( $_comment ) {
 459                  $_comments[] = $_comment;
 460              }
 461          }
 462  
 463          // Prime comment post caches.
 464          if ( $this->query_vars['update_comment_post_cache'] ) {
 465              $comment_post_ids = array();
 466              foreach ( $_comments as $_comment ) {
 467                  $comment_post_ids[] = $_comment->comment_post_ID;
 468              }
 469  
 470              _prime_post_caches( $comment_post_ids, false, false );
 471          }
 472  
 473          /**
 474           * Filters the comment query results.
 475           *
 476           * @since 3.1.0
 477           *
 478           * @param WP_Comment[]     $_comments An array of comments.
 479           * @param WP_Comment_Query $this      Current instance of WP_Comment_Query (passed by reference).
 480           */
 481          $_comments = apply_filters_ref_array( 'the_comments', array( $_comments, &$this ) );
 482  
 483          // Convert to WP_Comment instances.
 484          $comments = array_map( 'get_comment', $_comments );
 485  
 486          if ( $this->query_vars['hierarchical'] ) {
 487              $comments = $this->fill_descendants( $comments );
 488          }
 489  
 490          $this->comments = $comments;
 491          return $this->comments;
 492      }
 493  
 494      /**
 495       * Used internally to get a list of comment IDs matching the query vars.
 496       *
 497       * @since 4.4.0
 498       *
 499       * @global wpdb $wpdb WordPress database abstraction object.
 500       *
 501       * @return int|array A single count of comment IDs if a count query. An array of comment IDs if a full query.
 502       */
 503  	protected function get_comment_ids() {
 504          global $wpdb;
 505  
 506          // Assemble clauses related to 'comment_approved'.
 507          $approved_clauses = array();
 508  
 509          // 'status' accepts an array or a comma-separated string.
 510          $status_clauses = array();
 511          $statuses       = wp_parse_list( $this->query_vars['status'] );
 512  
 513          // Empty 'status' should be interpreted as 'all'.
 514          if ( empty( $statuses ) ) {
 515              $statuses = array( 'all' );
 516          }
 517  
 518          // 'any' overrides other statuses.
 519          if ( ! in_array( 'any', $statuses, true ) ) {
 520              foreach ( $statuses as $status ) {
 521                  switch ( $status ) {
 522                      case 'hold':
 523                          $status_clauses[] = "comment_approved = '0'";
 524                          break;
 525  
 526                      case 'approve':
 527                          $status_clauses[] = "comment_approved = '1'";
 528                          break;
 529  
 530                      case 'all':
 531                      case '':
 532                          $status_clauses[] = "( comment_approved = '0' OR comment_approved = '1' )";
 533                          break;
 534  
 535                      default:
 536                          $status_clauses[] = $wpdb->prepare( 'comment_approved = %s', $status );
 537                          break;
 538                  }
 539              }
 540  
 541              if ( ! empty( $status_clauses ) ) {
 542                  $approved_clauses[] = '( ' . implode( ' OR ', $status_clauses ) . ' )';
 543              }
 544          }
 545  
 546          // User IDs or emails whose unapproved comments are included, regardless of $status.
 547          if ( ! empty( $this->query_vars['include_unapproved'] ) ) {
 548              $include_unapproved = wp_parse_list( $this->query_vars['include_unapproved'] );
 549  
 550              $unapproved_ids    = array();
 551              $unapproved_emails = array();
 552              foreach ( $include_unapproved as $unapproved_identifier ) {
 553                  // Numeric values are assumed to be user IDs.
 554                  if ( is_numeric( $unapproved_identifier ) ) {
 555                      $approved_clauses[] = $wpdb->prepare( "( user_id = %d AND comment_approved = '0' )", $unapproved_identifier );
 556                  } else {
 557                      // Otherwise we match against email addresses.
 558                      if ( ! empty( $_GET['unapproved'] ) && ! empty( $_GET['moderation-hash'] ) ) {
 559                          // Only include requested comment.
 560                          $approved_clauses[] = $wpdb->prepare( "( comment_author_email = %s AND comment_approved = '0' AND comment_ID = %d )", $unapproved_identifier, (int) $_GET['unapproved'] );
 561                      } else {
 562                          // Include all of the author's unapproved comments.
 563                          $approved_clauses[] = $wpdb->prepare( "( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier );
 564                      }
 565                  }
 566              }
 567          }
 568  
 569          // Collapse comment_approved clauses into a single OR-separated clause.
 570          if ( ! empty( $approved_clauses ) ) {
 571              if ( 1 === count( $approved_clauses ) ) {
 572                  $this->sql_clauses['where']['approved'] = $approved_clauses[0];
 573              } else {
 574                  $this->sql_clauses['where']['approved'] = '( ' . implode( ' OR ', $approved_clauses ) . ' )';
 575              }
 576          }
 577  
 578          $order = ( 'ASC' === strtoupper( $this->query_vars['order'] ) ) ? 'ASC' : 'DESC';
 579  
 580          // Disable ORDER BY with 'none', an empty array, or boolean false.
 581          if ( in_array( $this->query_vars['orderby'], array( 'none', array(), false ), true ) ) {
 582              $orderby = '';
 583          } elseif ( ! empty( $this->query_vars['orderby'] ) ) {
 584              $ordersby = is_array( $this->query_vars['orderby'] ) ?
 585                  $this->query_vars['orderby'] :
 586                  preg_split( '/[,\s]/', $this->query_vars['orderby'] );
 587  
 588              $orderby_array            = array();
 589              $found_orderby_comment_id = false;
 590              foreach ( $ordersby as $_key => $_value ) {
 591                  if ( ! $_value ) {
 592                      continue;
 593                  }
 594  
 595                  if ( is_int( $_key ) ) {
 596                      $_orderby = $_value;
 597                      $_order   = $order;
 598                  } else {
 599                      $_orderby = $_key;
 600                      $_order   = $_value;
 601                  }
 602  
 603                  if ( ! $found_orderby_comment_id && in_array( $_orderby, array( 'comment_ID', 'comment__in' ), true ) ) {
 604                      $found_orderby_comment_id = true;
 605                  }
 606  
 607                  $parsed = $this->parse_orderby( $_orderby );
 608  
 609                  if ( ! $parsed ) {
 610                      continue;
 611                  }
 612  
 613                  if ( 'comment__in' === $_orderby ) {
 614                      $orderby_array[] = $parsed;
 615                      continue;
 616                  }
 617  
 618                  $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order );
 619              }
 620  
 621              // If no valid clauses were found, order by comment_date_gmt.
 622              if ( empty( $orderby_array ) ) {
 623                  $orderby_array[] = "$wpdb->comments.comment_date_gmt $order";
 624              }
 625  
 626              // To ensure determinate sorting, always include a comment_ID clause.
 627              if ( ! $found_orderby_comment_id ) {
 628                  $comment_id_order = '';
 629  
 630                  // Inherit order from comment_date or comment_date_gmt, if available.
 631                  foreach ( $orderby_array as $orderby_clause ) {
 632                      if ( preg_match( '/comment_date(?:_gmt)*\ (ASC|DESC)/', $orderby_clause, $match ) ) {
 633                          $comment_id_order = $match[1];
 634                          break;
 635                      }
 636                  }
 637  
 638                  // If no date-related order is available, use the date from the first available clause.
 639                  if ( ! $comment_id_order ) {
 640                      foreach ( $orderby_array as $orderby_clause ) {
 641                          if ( false !== strpos( 'ASC', $orderby_clause ) ) {
 642                              $comment_id_order = 'ASC';
 643                          } else {
 644                              $comment_id_order = 'DESC';
 645                          }
 646  
 647                          break;
 648                      }
 649                  }
 650  
 651                  // Default to DESC.
 652                  if ( ! $comment_id_order ) {
 653                      $comment_id_order = 'DESC';
 654                  }
 655  
 656                  $orderby_array[] = "$wpdb->comments.comment_ID $comment_id_order";
 657              }
 658  
 659              $orderby = implode( ', ', $orderby_array );
 660          } else {
 661              $orderby = "$wpdb->comments.comment_date_gmt $order";
 662          }
 663  
 664          $number = absint( $this->query_vars['number'] );
 665          $offset = absint( $this->query_vars['offset'] );
 666          $paged  = absint( $this->query_vars['paged'] );
 667          $limits = '';
 668  
 669          if ( ! empty( $number ) ) {
 670              if ( $offset ) {
 671                  $limits = 'LIMIT ' . $offset . ',' . $number;
 672              } else {
 673                  $limits = 'LIMIT ' . ( $number * ( $paged - 1 ) ) . ',' . $number;
 674              }
 675          }
 676  
 677          if ( $this->query_vars['count'] ) {
 678              $fields = 'COUNT(*)';
 679          } else {
 680              $fields = "$wpdb->comments.comment_ID";
 681          }
 682  
 683          $post_id = absint( $this->query_vars['post_id'] );
 684          if ( ! empty( $post_id ) ) {
 685              $this->sql_clauses['where']['post_id'] = $wpdb->prepare( 'comment_post_ID = %d', $post_id );
 686          }
 687  
 688          // Parse comment IDs for an IN clause.
 689          if ( ! empty( $this->query_vars['comment__in'] ) ) {
 690              $this->sql_clauses['where']['comment__in'] = "$wpdb->comments.comment_ID IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__in'] ) ) . ' )';
 691          }
 692  
 693          // Parse comment IDs for a NOT IN clause.
 694          if ( ! empty( $this->query_vars['comment__not_in'] ) ) {
 695              $this->sql_clauses['where']['comment__not_in'] = "$wpdb->comments.comment_ID NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__not_in'] ) ) . ' )';
 696          }
 697  
 698          // Parse comment parent IDs for an IN clause.
 699          if ( ! empty( $this->query_vars['parent__in'] ) ) {
 700              $this->sql_clauses['where']['parent__in'] = 'comment_parent IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['parent__in'] ) ) . ' )';
 701          }
 702  
 703          // Parse comment parent IDs for a NOT IN clause.
 704          if ( ! empty( $this->query_vars['parent__not_in'] ) ) {
 705              $this->sql_clauses['where']['parent__not_in'] = 'comment_parent NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['parent__not_in'] ) ) . ' )';
 706          }
 707  
 708          // Parse comment post IDs for an IN clause.
 709          if ( ! empty( $this->query_vars['post__in'] ) ) {
 710              $this->sql_clauses['where']['post__in'] = 'comment_post_ID IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post__in'] ) ) . ' )';
 711          }
 712  
 713          // Parse comment post IDs for a NOT IN clause.
 714          if ( ! empty( $this->query_vars['post__not_in'] ) ) {
 715              $this->sql_clauses['where']['post__not_in'] = 'comment_post_ID NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post__not_in'] ) ) . ' )';
 716          }
 717  
 718          if ( '' !== $this->query_vars['author_email'] ) {
 719              $this->sql_clauses['where']['author_email'] = $wpdb->prepare( 'comment_author_email = %s', $this->query_vars['author_email'] );
 720          }
 721  
 722          if ( '' !== $this->query_vars['author_url'] ) {
 723              $this->sql_clauses['where']['author_url'] = $wpdb->prepare( 'comment_author_url = %s', $this->query_vars['author_url'] );
 724          }
 725  
 726          if ( '' !== $this->query_vars['karma'] ) {
 727              $this->sql_clauses['where']['karma'] = $wpdb->prepare( 'comment_karma = %d', $this->query_vars['karma'] );
 728          }
 729  
 730          // Filtering by comment_type: 'type', 'type__in', 'type__not_in'.
 731          $raw_types = array(
 732              'IN'     => array_merge( (array) $this->query_vars['type'], (array) $this->query_vars['type__in'] ),
 733              'NOT IN' => (array) $this->query_vars['type__not_in'],
 734          );
 735  
 736          $comment_types = array();
 737          foreach ( $raw_types as $operator => $_raw_types ) {
 738              $_raw_types = array_unique( $_raw_types );
 739  
 740              foreach ( $_raw_types as $type ) {
 741                  switch ( $type ) {
 742                      // An empty translates to 'all', for backward compatibility.
 743                      case '':
 744                      case 'all':
 745                          break;
 746  
 747                      case 'comment':
 748                      case 'comments':
 749                          $comment_types[ $operator ][] = "''";
 750                          $comment_types[ $operator ][] = "'comment'";
 751                          break;
 752  
 753                      case 'pings':
 754                          $comment_types[ $operator ][] = "'pingback'";
 755                          $comment_types[ $operator ][] = "'trackback'";
 756                          break;
 757  
 758                      default:
 759                          $comment_types[ $operator ][] = $wpdb->prepare( '%s', $type );
 760                          break;
 761                  }
 762              }
 763  
 764              if ( ! empty( $comment_types[ $operator ] ) ) {
 765                  $types_sql = implode( ', ', $comment_types[ $operator ] );
 766                  $this->sql_clauses['where'][ 'comment_type__' . strtolower( str_replace( ' ', '_', $operator ) ) ] = "comment_type $operator ($types_sql)";
 767              }
 768          }
 769  
 770          $parent = $this->query_vars['parent'];
 771          if ( $this->query_vars['hierarchical'] && ! $parent ) {
 772              $parent = 0;
 773          }
 774  
 775          if ( '' !== $parent ) {
 776              $this->sql_clauses['where']['parent'] = $wpdb->prepare( 'comment_parent = %d', $parent );
 777          }
 778  
 779          if ( is_array( $this->query_vars['user_id'] ) ) {
 780              $this->sql_clauses['where']['user_id'] = 'user_id IN (' . implode( ',', array_map( 'absint', $this->query_vars['user_id'] ) ) . ')';
 781          } elseif ( '' !== $this->query_vars['user_id'] ) {
 782              $this->sql_clauses['where']['user_id'] = $wpdb->prepare( 'user_id = %d', $this->query_vars['user_id'] );
 783          }
 784  
 785          // Falsey search strings are ignored.
 786          if ( strlen( $this->query_vars['search'] ) ) {
 787              $search_sql = $this->get_search_sql(
 788                  $this->query_vars['search'],
 789                  array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' )
 790              );
 791  
 792              // Strip leading 'AND'.
 793              $this->sql_clauses['where']['search'] = preg_replace( '/^\s*AND\s*/', '', $search_sql );
 794          }
 795  
 796          // If any post-related query vars are passed, join the posts table.
 797          $join_posts_table = false;
 798          $plucked          = wp_array_slice_assoc( $this->query_vars, array( 'post_author', 'post_name', 'post_parent' ) );
 799          $post_fields      = array_filter( $plucked );
 800  
 801          if ( ! empty( $post_fields ) ) {
 802              $join_posts_table = true;
 803              foreach ( $post_fields as $field_name => $field_value ) {
 804                  // $field_value may be an array.
 805                  $esses = array_fill( 0, count( (array) $field_value ), '%s' );
 806  
 807                  // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
 808                  $this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $field_value );
 809              }
 810          }
 811  
 812          // 'post_status' and 'post_type' are handled separately, due to the specialized behavior of 'any'.
 813          foreach ( array( 'post_status', 'post_type' ) as $field_name ) {
 814              $q_values = array();
 815              if ( ! empty( $this->query_vars[ $field_name ] ) ) {
 816                  $q_values = $this->query_vars[ $field_name ];
 817                  if ( ! is_array( $q_values ) ) {
 818                      $q_values = explode( ',', $q_values );
 819                  }
 820  
 821                  // 'any' will cause the query var to be ignored.
 822                  if ( in_array( 'any', $q_values, true ) || empty( $q_values ) ) {
 823                      continue;
 824                  }
 825  
 826                  $join_posts_table = true;
 827  
 828                  $esses = array_fill( 0, count( $q_values ), '%s' );
 829  
 830                  // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
 831                  $this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $q_values );
 832              }
 833          }
 834  
 835          // Comment author IDs for an IN clause.
 836          if ( ! empty( $this->query_vars['author__in'] ) ) {
 837              $this->sql_clauses['where']['author__in'] = 'user_id IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['author__in'] ) ) . ' )';
 838          }
 839  
 840          // Comment author IDs for a NOT IN clause.
 841          if ( ! empty( $this->query_vars['author__not_in'] ) ) {
 842              $this->sql_clauses['where']['author__not_in'] = 'user_id NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['author__not_in'] ) ) . ' )';
 843          }
 844  
 845          // Post author IDs for an IN clause.
 846          if ( ! empty( $this->query_vars['post_author__in'] ) ) {
 847              $join_posts_table                              = true;
 848              $this->sql_clauses['where']['post_author__in'] = 'post_author IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post_author__in'] ) ) . ' )';
 849          }
 850  
 851          // Post author IDs for a NOT IN clause.
 852          if ( ! empty( $this->query_vars['post_author__not_in'] ) ) {
 853              $join_posts_table                                  = true;
 854              $this->sql_clauses['where']['post_author__not_in'] = 'post_author NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post_author__not_in'] ) ) . ' )';
 855          }
 856  
 857          $join    = '';
 858          $groupby = '';
 859  
 860          if ( $join_posts_table ) {
 861              $join .= "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID";
 862          }
 863  
 864          if ( ! empty( $this->meta_query_clauses ) ) {
 865              $join .= $this->meta_query_clauses['join'];
 866  
 867              // Strip leading 'AND'.
 868              $this->sql_clauses['where']['meta_query'] = preg_replace( '/^\s*AND\s*/', '', $this->meta_query_clauses['where'] );
 869  
 870              if ( ! $this->query_vars['count'] ) {
 871                  $groupby = "{$wpdb->comments}.comment_ID";
 872              }
 873          }
 874  
 875          if ( ! empty( $this->query_vars['date_query'] ) && is_array( $this->query_vars['date_query'] ) ) {
 876              $this->date_query                         = new WP_Date_Query( $this->query_vars['date_query'], 'comment_date' );
 877              $this->sql_clauses['where']['date_query'] = preg_replace( '/^\s*AND\s*/', '', $this->date_query->get_sql() );
 878          }
 879  
 880          $where = implode( ' AND ', $this->sql_clauses['where'] );
 881  
 882          $pieces = array( 'fields', 'join', 'where', 'orderby', 'limits', 'groupby' );
 883          /**
 884           * Filters the comment query clauses.
 885           *
 886           * @since 3.1.0
 887           *
 888           * @param string[]         $pieces An associative array of comment query clauses.
 889           * @param WP_Comment_Query $this   Current instance of WP_Comment_Query (passed by reference).
 890           */
 891          $clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) );
 892  
 893          $fields  = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
 894          $join    = isset( $clauses['join'] ) ? $clauses['join'] : '';
 895          $where   = isset( $clauses['where'] ) ? $clauses['where'] : '';
 896          $orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
 897          $limits  = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
 898          $groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
 899  
 900          $this->filtered_where_clause = $where;
 901  
 902          if ( $where ) {
 903              $where = 'WHERE ' . $where;
 904          }
 905  
 906          if ( $groupby ) {
 907              $groupby = 'GROUP BY ' . $groupby;
 908          }
 909  
 910          if ( $orderby ) {
 911              $orderby = "ORDER BY $orderby";
 912          }
 913  
 914          $found_rows = '';
 915          if ( ! $this->query_vars['no_found_rows'] ) {
 916              $found_rows = 'SQL_CALC_FOUND_ROWS';
 917          }
 918  
 919          $this->sql_clauses['select']  = "SELECT $found_rows $fields";
 920          $this->sql_clauses['from']    = "FROM $wpdb->comments $join";
 921          $this->sql_clauses['groupby'] = $groupby;
 922          $this->sql_clauses['orderby'] = $orderby;
 923          $this->sql_clauses['limits']  = $limits;
 924  
 925          $this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}";
 926  
 927          if ( $this->query_vars['count'] ) {
 928              return intval( $wpdb->get_var( $this->request ) );
 929          } else {
 930              $comment_ids = $wpdb->get_col( $this->request );
 931              return array_map( 'intval', $comment_ids );
 932          }
 933      }
 934  
 935      /**
 936       * Populates found_comments and max_num_pages properties for the current
 937       * query if the limit clause was used.
 938       *
 939       * @since 4.6.0
 940       *
 941       * @global wpdb $wpdb WordPress database abstraction object.
 942       */
 943  	private function set_found_comments() {
 944          global $wpdb;
 945  
 946          if ( $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) {
 947              /**
 948               * Filters the query used to retrieve found comment count.
 949               *
 950               * @since 4.4.0
 951               *
 952               * @param string           $found_comments_query SQL query. Default 'SELECT FOUND_ROWS()'.
 953               * @param WP_Comment_Query $comment_query        The `WP_Comment_Query` instance.
 954               */
 955              $found_comments_query = apply_filters( 'found_comments_query', 'SELECT FOUND_ROWS()', $this );
 956  
 957              $this->found_comments = (int) $wpdb->get_var( $found_comments_query );
 958          }
 959      }
 960  
 961      /**
 962       * Fetch descendants for located comments.
 963       *
 964       * Instead of calling `get_children()` separately on each child comment, we do a single set of queries to fetch
 965       * the descendant trees for all matched top-level comments.
 966       *
 967       * @since 4.4.0
 968       *
 969       * @global wpdb $wpdb WordPress database abstraction object.
 970       *
 971       * @param WP_Comment[] $comments Array of top-level comments whose descendants should be filled in.
 972       * @return array
 973       */
 974  	protected function fill_descendants( $comments ) {
 975          global $wpdb;
 976  
 977          $levels = array(
 978              0 => wp_list_pluck( $comments, 'comment_ID' ),
 979          );
 980  
 981          $key          = md5( serialize( wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ) ) );
 982          $last_changed = wp_cache_get_last_changed( 'comment' );
 983  
 984          // Fetch an entire level of the descendant tree at a time.
 985          $level        = 0;
 986          $exclude_keys = array( 'parent', 'parent__in', 'parent__not_in' );
 987          do {
 988              // Parent-child relationships may be cached. Only query for those that are not.
 989              $child_ids           = array();
 990              $uncached_parent_ids = array();
 991              $_parent_ids         = $levels[ $level ];
 992              foreach ( $_parent_ids as $parent_id ) {
 993                  $cache_key        = "get_comment_child_ids:$parent_id:$key:$last_changed";
 994                  $parent_child_ids = wp_cache_get( $cache_key, 'comment' );
 995                  if ( false !== $parent_child_ids ) {
 996                      $child_ids = array_merge( $child_ids, $parent_child_ids );
 997                  } else {
 998                      $uncached_parent_ids[] = $parent_id;
 999                  }
1000              }
1001  
1002              if ( $uncached_parent_ids ) {
1003                  // Fetch this level of comments.
1004                  $parent_query_args = $this->query_vars;
1005                  foreach ( $exclude_keys as $exclude_key ) {
1006                      $parent_query_args[ $exclude_key ] = '';
1007                  }
1008                  $parent_query_args['parent__in']    = $uncached_parent_ids;
1009                  $parent_query_args['no_found_rows'] = true;
1010                  $parent_query_args['hierarchical']  = false;
1011                  $parent_query_args['offset']        = 0;
1012                  $parent_query_args['number']        = 0;
1013  
1014                  $level_comments = get_comments( $parent_query_args );
1015  
1016                  // Cache parent-child relationships.
1017                  $parent_map = array_fill_keys( $uncached_parent_ids, array() );
1018                  foreach ( $level_comments as $level_comment ) {
1019                      $parent_map[ $level_comment->comment_parent ][] = $level_comment->comment_ID;
1020                      $child_ids[]                                    = $level_comment->comment_ID;
1021                  }
1022  
1023                  foreach ( $parent_map as $parent_id => $children ) {
1024                      $cache_key = "get_comment_child_ids:$parent_id:$key:$last_changed";
1025                      wp_cache_set( $cache_key, $children, 'comment' );
1026                  }
1027              }
1028  
1029              $level++;
1030              $levels[ $level ] = $child_ids;
1031          } while ( $child_ids );
1032  
1033          // Prime comment caches for non-top-level comments.
1034          $descendant_ids = array();
1035          for ( $i = 1, $c = count( $levels ); $i < $c; $i++ ) {
1036              $descendant_ids = array_merge( $descendant_ids, $levels[ $i ] );
1037          }
1038  
1039          _prime_comment_caches( $descendant_ids, $this->query_vars['update_comment_meta_cache'] );
1040  
1041          // Assemble a flat array of all comments + descendants.
1042          $all_comments = $comments;
1043          foreach ( $descendant_ids as $descendant_id ) {
1044              $all_comments[] = get_comment( $descendant_id );
1045          }
1046  
1047          // If a threaded representation was requested, build the tree.
1048          if ( 'threaded' === $this->query_vars['hierarchical'] ) {
1049              $threaded_comments = array();
1050              $ref               = array();
1051              foreach ( $all_comments as $k => $c ) {
1052                  $_c = get_comment( $c->comment_ID );
1053  
1054                  // If the comment isn't in the reference array, it goes in the top level of the thread.
1055                  if ( ! isset( $ref[ $c->comment_parent ] ) ) {
1056                      $threaded_comments[ $_c->comment_ID ] = $_c;
1057                      $ref[ $_c->comment_ID ]               = $threaded_comments[ $_c->comment_ID ];
1058  
1059                      // Otherwise, set it as a child of its parent.
1060                  } else {
1061  
1062                      $ref[ $_c->comment_parent ]->add_child( $_c );
1063                      $ref[ $_c->comment_ID ] = $ref[ $_c->comment_parent ]->get_child( $_c->comment_ID );
1064                  }
1065              }
1066  
1067              // Set the 'populated_children' flag, to ensure additional database queries aren't run.
1068              foreach ( $ref as $_ref ) {
1069                  $_ref->populated_children( true );
1070              }
1071  
1072              $comments = $threaded_comments;
1073          } else {
1074              $comments = $all_comments;
1075          }
1076  
1077          return $comments;
1078      }
1079  
1080      /**
1081       * Used internally to generate an SQL string for searching across multiple columns
1082       *
1083       * @since 3.1.0
1084       *
1085       * @global wpdb $wpdb WordPress database abstraction object.
1086       *
1087       * @param string $string
1088       * @param array $cols
1089       * @return string
1090       */
1091  	protected function get_search_sql( $string, $cols ) {
1092          global $wpdb;
1093  
1094          $like = '%' . $wpdb->esc_like( $string ) . '%';
1095  
1096          $searches = array();
1097          foreach ( $cols as $col ) {
1098              $searches[] = $wpdb->prepare( "$col LIKE %s", $like );
1099          }
1100  
1101          return ' AND (' . implode( ' OR ', $searches ) . ')';
1102      }
1103  
1104      /**
1105       * Parse and sanitize 'orderby' keys passed to the comment query.
1106       *
1107       * @since 4.2.0
1108       *
1109       * @global wpdb $wpdb WordPress database abstraction object.
1110       *
1111       * @param string $orderby Alias for the field to order by.
1112       * @return string|false Value to used in the ORDER clause. False otherwise.
1113       */
1114  	protected function parse_orderby( $orderby ) {
1115          global $wpdb;
1116  
1117          $allowed_keys = array(
1118              'comment_agent',
1119              'comment_approved',
1120              'comment_author',
1121              'comment_author_email',
1122              'comment_author_IP',
1123              'comment_author_url',
1124              'comment_content',
1125              'comment_date',
1126              'comment_date_gmt',
1127              'comment_ID',
1128              'comment_karma',
1129              'comment_parent',
1130              'comment_post_ID',
1131              'comment_type',
1132              'user_id',
1133          );
1134  
1135          if ( ! empty( $this->query_vars['meta_key'] ) ) {
1136              $allowed_keys[] = $this->query_vars['meta_key'];
1137              $allowed_keys[] = 'meta_value';
1138              $allowed_keys[] = 'meta_value_num';
1139          }
1140  
1141          $meta_query_clauses = $this->meta_query->get_clauses();
1142          if ( $meta_query_clauses ) {
1143              $allowed_keys = array_merge( $allowed_keys, array_keys( $meta_query_clauses ) );
1144          }
1145  
1146          $parsed = false;
1147          if ( $this->query_vars['meta_key'] === $orderby || 'meta_value' === $orderby ) {
1148              $parsed = "$wpdb->commentmeta.meta_value";
1149          } elseif ( 'meta_value_num' === $orderby ) {
1150              $parsed = "$wpdb->commentmeta.meta_value+0";
1151          } elseif ( 'comment__in' === $orderby ) {
1152              $comment__in = implode( ',', array_map( 'absint', $this->query_vars['comment__in'] ) );
1153              $parsed      = "FIELD( {$wpdb->comments}.comment_ID, $comment__in )";
1154          } elseif ( in_array( $orderby, $allowed_keys, true ) ) {
1155  
1156              if ( isset( $meta_query_clauses[ $orderby ] ) ) {
1157                  $meta_clause = $meta_query_clauses[ $orderby ];
1158                  $parsed      = sprintf( 'CAST(%s.meta_value AS %s)', esc_sql( $meta_clause['alias'] ), esc_sql( $meta_clause['cast'] ) );
1159              } else {
1160                  $parsed = "$wpdb->comments.$orderby";
1161              }
1162          }
1163  
1164          return $parsed;
1165      }
1166  
1167      /**
1168       * Parse an 'order' query variable and cast it to ASC or DESC as necessary.
1169       *
1170       * @since 4.2.0
1171       *
1172       * @param string $order The 'order' query variable.
1173       * @return string The sanitized 'order' query variable.
1174       */
1175  	protected function parse_order( $order ) {
1176          if ( ! is_string( $order ) || empty( $order ) ) {
1177              return 'DESC';
1178          }
1179  
1180          if ( 'ASC' === strtoupper( $order ) ) {
1181              return 'ASC';
1182          } else {
1183              return 'DESC';
1184          }
1185      }
1186  }


Generated: Fri Jul 10 01:00:03 2020 Cross-referenced by PHPXref 0.7.1