[ 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 ) ) {
 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  
 557                      // Otherwise we match against email addresses.
 558                  } else {
 559                      $approved_clauses[] = $wpdb->prepare( "( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier );
 560                  }
 561              }
 562          }
 563  
 564          // Collapse comment_approved clauses into a single OR-separated clause.
 565          if ( ! empty( $approved_clauses ) ) {
 566              if ( 1 === count( $approved_clauses ) ) {
 567                  $this->sql_clauses['where']['approved'] = $approved_clauses[0];
 568              } else {
 569                  $this->sql_clauses['where']['approved'] = '( ' . implode( ' OR ', $approved_clauses ) . ' )';
 570              }
 571          }
 572  
 573          $order = ( 'ASC' == strtoupper( $this->query_vars['order'] ) ) ? 'ASC' : 'DESC';
 574  
 575          // Disable ORDER BY with 'none', an empty array, or boolean false.
 576          if ( in_array( $this->query_vars['orderby'], array( 'none', array(), false ), true ) ) {
 577              $orderby = '';
 578          } elseif ( ! empty( $this->query_vars['orderby'] ) ) {
 579              $ordersby = is_array( $this->query_vars['orderby'] ) ?
 580                  $this->query_vars['orderby'] :
 581                  preg_split( '/[,\s]/', $this->query_vars['orderby'] );
 582  
 583              $orderby_array            = array();
 584              $found_orderby_comment_id = false;
 585              foreach ( $ordersby as $_key => $_value ) {
 586                  if ( ! $_value ) {
 587                      continue;
 588                  }
 589  
 590                  if ( is_int( $_key ) ) {
 591                      $_orderby = $_value;
 592                      $_order   = $order;
 593                  } else {
 594                      $_orderby = $_key;
 595                      $_order   = $_value;
 596                  }
 597  
 598                  if ( ! $found_orderby_comment_id && in_array( $_orderby, array( 'comment_ID', 'comment__in' ) ) ) {
 599                      $found_orderby_comment_id = true;
 600                  }
 601  
 602                  $parsed = $this->parse_orderby( $_orderby );
 603  
 604                  if ( ! $parsed ) {
 605                      continue;
 606                  }
 607  
 608                  if ( 'comment__in' === $_orderby ) {
 609                      $orderby_array[] = $parsed;
 610                      continue;
 611                  }
 612  
 613                  $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order );
 614              }
 615  
 616              // If no valid clauses were found, order by comment_date_gmt.
 617              if ( empty( $orderby_array ) ) {
 618                  $orderby_array[] = "$wpdb->comments.comment_date_gmt $order";
 619              }
 620  
 621              // To ensure determinate sorting, always include a comment_ID clause.
 622              if ( ! $found_orderby_comment_id ) {
 623                  $comment_id_order = '';
 624  
 625                  // Inherit order from comment_date or comment_date_gmt, if available.
 626                  foreach ( $orderby_array as $orderby_clause ) {
 627                      if ( preg_match( '/comment_date(?:_gmt)*\ (ASC|DESC)/', $orderby_clause, $match ) ) {
 628                          $comment_id_order = $match[1];
 629                          break;
 630                      }
 631                  }
 632  
 633                  // If no date-related order is available, use the date from the first available clause.
 634                  if ( ! $comment_id_order ) {
 635                      foreach ( $orderby_array as $orderby_clause ) {
 636                          if ( false !== strpos( 'ASC', $orderby_clause ) ) {
 637                              $comment_id_order = 'ASC';
 638                          } else {
 639                              $comment_id_order = 'DESC';
 640                          }
 641  
 642                          break;
 643                      }
 644                  }
 645  
 646                  // Default to DESC.
 647                  if ( ! $comment_id_order ) {
 648                      $comment_id_order = 'DESC';
 649                  }
 650  
 651                  $orderby_array[] = "$wpdb->comments.comment_ID $comment_id_order";
 652              }
 653  
 654              $orderby = implode( ', ', $orderby_array );
 655          } else {
 656              $orderby = "$wpdb->comments.comment_date_gmt $order";
 657          }
 658  
 659          $number = absint( $this->query_vars['number'] );
 660          $offset = absint( $this->query_vars['offset'] );
 661          $paged  = absint( $this->query_vars['paged'] );
 662          $limits = '';
 663  
 664          if ( ! empty( $number ) ) {
 665              if ( $offset ) {
 666                  $limits = 'LIMIT ' . $offset . ',' . $number;
 667              } else {
 668                  $limits = 'LIMIT ' . ( $number * ( $paged - 1 ) ) . ',' . $number;
 669              }
 670          }
 671  
 672          if ( $this->query_vars['count'] ) {
 673              $fields = 'COUNT(*)';
 674          } else {
 675              $fields = "$wpdb->comments.comment_ID";
 676          }
 677  
 678          $post_id = absint( $this->query_vars['post_id'] );
 679          if ( ! empty( $post_id ) ) {
 680              $this->sql_clauses['where']['post_id'] = $wpdb->prepare( 'comment_post_ID = %d', $post_id );
 681          }
 682  
 683          // Parse comment IDs for an IN clause.
 684          if ( ! empty( $this->query_vars['comment__in'] ) ) {
 685              $this->sql_clauses['where']['comment__in'] = "$wpdb->comments.comment_ID IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__in'] ) ) . ' )';
 686          }
 687  
 688          // Parse comment IDs for a NOT IN clause.
 689          if ( ! empty( $this->query_vars['comment__not_in'] ) ) {
 690              $this->sql_clauses['where']['comment__not_in'] = "$wpdb->comments.comment_ID NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__not_in'] ) ) . ' )';
 691          }
 692  
 693          // Parse comment parent IDs for an IN clause.
 694          if ( ! empty( $this->query_vars['parent__in'] ) ) {
 695              $this->sql_clauses['where']['parent__in'] = 'comment_parent IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['parent__in'] ) ) . ' )';
 696          }
 697  
 698          // Parse comment parent IDs for a NOT IN clause.
 699          if ( ! empty( $this->query_vars['parent__not_in'] ) ) {
 700              $this->sql_clauses['where']['parent__not_in'] = 'comment_parent NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['parent__not_in'] ) ) . ' )';
 701          }
 702  
 703          // Parse comment post IDs for an IN clause.
 704          if ( ! empty( $this->query_vars['post__in'] ) ) {
 705              $this->sql_clauses['where']['post__in'] = 'comment_post_ID IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post__in'] ) ) . ' )';
 706          }
 707  
 708          // Parse comment post IDs for a NOT IN clause.
 709          if ( ! empty( $this->query_vars['post__not_in'] ) ) {
 710              $this->sql_clauses['where']['post__not_in'] = 'comment_post_ID NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post__not_in'] ) ) . ' )';
 711          }
 712  
 713          if ( '' !== $this->query_vars['author_email'] ) {
 714              $this->sql_clauses['where']['author_email'] = $wpdb->prepare( 'comment_author_email = %s', $this->query_vars['author_email'] );
 715          }
 716  
 717          if ( '' !== $this->query_vars['author_url'] ) {
 718              $this->sql_clauses['where']['author_url'] = $wpdb->prepare( 'comment_author_url = %s', $this->query_vars['author_url'] );
 719          }
 720  
 721          if ( '' !== $this->query_vars['karma'] ) {
 722              $this->sql_clauses['where']['karma'] = $wpdb->prepare( 'comment_karma = %d', $this->query_vars['karma'] );
 723          }
 724  
 725          // Filtering by comment_type: 'type', 'type__in', 'type__not_in'.
 726          $raw_types = array(
 727              'IN'     => array_merge( (array) $this->query_vars['type'], (array) $this->query_vars['type__in'] ),
 728              'NOT IN' => (array) $this->query_vars['type__not_in'],
 729          );
 730  
 731          $comment_types = array();
 732          foreach ( $raw_types as $operator => $_raw_types ) {
 733              $_raw_types = array_unique( $_raw_types );
 734  
 735              foreach ( $_raw_types as $type ) {
 736                  switch ( $type ) {
 737                      // An empty translates to 'all', for backward compatibility
 738                      case '':
 739                      case 'all':
 740                          break;
 741  
 742                      case 'comment':
 743                      case 'comments':
 744                          $comment_types[ $operator ][] = "''";
 745                          break;
 746  
 747                      case 'pings':
 748                          $comment_types[ $operator ][] = "'pingback'";
 749                          $comment_types[ $operator ][] = "'trackback'";
 750                          break;
 751  
 752                      default:
 753                          $comment_types[ $operator ][] = $wpdb->prepare( '%s', $type );
 754                          break;
 755                  }
 756              }
 757  
 758              if ( ! empty( $comment_types[ $operator ] ) ) {
 759                  $types_sql = implode( ', ', $comment_types[ $operator ] );
 760                  $this->sql_clauses['where'][ 'comment_type__' . strtolower( str_replace( ' ', '_', $operator ) ) ] = "comment_type $operator ($types_sql)";
 761              }
 762          }
 763  
 764          $parent = $this->query_vars['parent'];
 765          if ( $this->query_vars['hierarchical'] && ! $parent ) {
 766              $parent = 0;
 767          }
 768  
 769          if ( '' !== $parent ) {
 770              $this->sql_clauses['where']['parent'] = $wpdb->prepare( 'comment_parent = %d', $parent );
 771          }
 772  
 773          if ( is_array( $this->query_vars['user_id'] ) ) {
 774              $this->sql_clauses['where']['user_id'] = 'user_id IN (' . implode( ',', array_map( 'absint', $this->query_vars['user_id'] ) ) . ')';
 775          } elseif ( '' !== $this->query_vars['user_id'] ) {
 776              $this->sql_clauses['where']['user_id'] = $wpdb->prepare( 'user_id = %d', $this->query_vars['user_id'] );
 777          }
 778  
 779          // Falsy search strings are ignored.
 780          if ( strlen( $this->query_vars['search'] ) ) {
 781              $search_sql = $this->get_search_sql(
 782                  $this->query_vars['search'],
 783                  array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' )
 784              );
 785  
 786              // Strip leading 'AND'.
 787              $this->sql_clauses['where']['search'] = preg_replace( '/^\s*AND\s*/', '', $search_sql );
 788          }
 789  
 790          // If any post-related query vars are passed, join the posts table.
 791          $join_posts_table = false;
 792          $plucked          = wp_array_slice_assoc( $this->query_vars, array( 'post_author', 'post_name', 'post_parent' ) );
 793          $post_fields      = array_filter( $plucked );
 794  
 795          if ( ! empty( $post_fields ) ) {
 796              $join_posts_table = true;
 797              foreach ( $post_fields as $field_name => $field_value ) {
 798                  // $field_value may be an array.
 799                  $esses = array_fill( 0, count( (array) $field_value ), '%s' );
 800  
 801                  // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
 802                  $this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $field_value );
 803              }
 804          }
 805  
 806          // 'post_status' and 'post_type' are handled separately, due to the specialized behavior of 'any'.
 807          foreach ( array( 'post_status', 'post_type' ) as $field_name ) {
 808              $q_values = array();
 809              if ( ! empty( $this->query_vars[ $field_name ] ) ) {
 810                  $q_values = $this->query_vars[ $field_name ];
 811                  if ( ! is_array( $q_values ) ) {
 812                      $q_values = explode( ',', $q_values );
 813                  }
 814  
 815                  // 'any' will cause the query var to be ignored.
 816                  if ( in_array( 'any', $q_values, true ) || empty( $q_values ) ) {
 817                      continue;
 818                  }
 819  
 820                  $join_posts_table = true;
 821  
 822                  $esses = array_fill( 0, count( $q_values ), '%s' );
 823  
 824                  // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
 825                  $this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $q_values );
 826              }
 827          }
 828  
 829          // Comment author IDs for an IN clause.
 830          if ( ! empty( $this->query_vars['author__in'] ) ) {
 831              $this->sql_clauses['where']['author__in'] = 'user_id IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['author__in'] ) ) . ' )';
 832          }
 833  
 834          // Comment author IDs for a NOT IN clause.
 835          if ( ! empty( $this->query_vars['author__not_in'] ) ) {
 836              $this->sql_clauses['where']['author__not_in'] = 'user_id NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['author__not_in'] ) ) . ' )';
 837          }
 838  
 839          // Post author IDs for an IN clause.
 840          if ( ! empty( $this->query_vars['post_author__in'] ) ) {
 841              $join_posts_table                              = true;
 842              $this->sql_clauses['where']['post_author__in'] = 'post_author IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post_author__in'] ) ) . ' )';
 843          }
 844  
 845          // Post author IDs for a NOT IN clause.
 846          if ( ! empty( $this->query_vars['post_author__not_in'] ) ) {
 847              $join_posts_table                                  = true;
 848              $this->sql_clauses['where']['post_author__not_in'] = 'post_author NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post_author__not_in'] ) ) . ' )';
 849          }
 850  
 851          $join    = '';
 852          $groupby = '';
 853  
 854          if ( $join_posts_table ) {
 855              $join .= "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID";
 856          }
 857  
 858          if ( ! empty( $this->meta_query_clauses ) ) {
 859              $join .= $this->meta_query_clauses['join'];
 860  
 861              // Strip leading 'AND'.
 862              $this->sql_clauses['where']['meta_query'] = preg_replace( '/^\s*AND\s*/', '', $this->meta_query_clauses['where'] );
 863  
 864              if ( ! $this->query_vars['count'] ) {
 865                  $groupby = "{$wpdb->comments}.comment_ID";
 866              }
 867          }
 868  
 869          if ( ! empty( $this->query_vars['date_query'] ) && is_array( $this->query_vars['date_query'] ) ) {
 870              $this->date_query                         = new WP_Date_Query( $this->query_vars['date_query'], 'comment_date' );
 871              $this->sql_clauses['where']['date_query'] = preg_replace( '/^\s*AND\s*/', '', $this->date_query->get_sql() );
 872          }
 873  
 874          $where = implode( ' AND ', $this->sql_clauses['where'] );
 875  
 876          $pieces = array( 'fields', 'join', 'where', 'orderby', 'limits', 'groupby' );
 877          /**
 878           * Filters the comment query clauses.
 879           *
 880           * @since 3.1.0
 881           *
 882           * @param string[]         $pieces An associative array of comment query clauses.
 883           * @param WP_Comment_Query $this   Current instance of WP_Comment_Query (passed by reference).
 884           */
 885          $clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) );
 886  
 887          $fields  = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
 888          $join    = isset( $clauses['join'] ) ? $clauses['join'] : '';
 889          $where   = isset( $clauses['where'] ) ? $clauses['where'] : '';
 890          $orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
 891          $limits  = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
 892          $groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
 893  
 894          $this->filtered_where_clause = $where;
 895  
 896          if ( $where ) {
 897              $where = 'WHERE ' . $where;
 898          }
 899  
 900          if ( $groupby ) {
 901              $groupby = 'GROUP BY ' . $groupby;
 902          }
 903  
 904          if ( $orderby ) {
 905              $orderby = "ORDER BY $orderby";
 906          }
 907  
 908          $found_rows = '';
 909          if ( ! $this->query_vars['no_found_rows'] ) {
 910              $found_rows = 'SQL_CALC_FOUND_ROWS';
 911          }
 912  
 913          $this->sql_clauses['select']  = "SELECT $found_rows $fields";
 914          $this->sql_clauses['from']    = "FROM $wpdb->comments $join";
 915          $this->sql_clauses['groupby'] = $groupby;
 916          $this->sql_clauses['orderby'] = $orderby;
 917          $this->sql_clauses['limits']  = $limits;
 918  
 919          $this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}";
 920  
 921          if ( $this->query_vars['count'] ) {
 922              return intval( $wpdb->get_var( $this->request ) );
 923          } else {
 924              $comment_ids = $wpdb->get_col( $this->request );
 925              return array_map( 'intval', $comment_ids );
 926          }
 927      }
 928  
 929      /**
 930       * Populates found_comments and max_num_pages properties for the current
 931       * query if the limit clause was used.
 932       *
 933       * @since 4.6.0
 934       *
 935       * @global wpdb $wpdb WordPress database abstraction object.
 936       */
 937  	private function set_found_comments() {
 938          global $wpdb;
 939  
 940          if ( $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) {
 941              /**
 942               * Filters the query used to retrieve found comment count.
 943               *
 944               * @since 4.4.0
 945               *
 946               * @param string           $found_comments_query SQL query. Default 'SELECT FOUND_ROWS()'.
 947               * @param WP_Comment_Query $comment_query        The `WP_Comment_Query` instance.
 948               */
 949              $found_comments_query = apply_filters( 'found_comments_query', 'SELECT FOUND_ROWS()', $this );
 950  
 951              $this->found_comments = (int) $wpdb->get_var( $found_comments_query );
 952          }
 953      }
 954  
 955      /**
 956       * Fetch descendants for located comments.
 957       *
 958       * Instead of calling `get_children()` separately on each child comment, we do a single set of queries to fetch
 959       * the descendant trees for all matched top-level comments.
 960       *
 961       * @since 4.4.0
 962       *
 963       * @global wpdb $wpdb WordPress database abstraction object.
 964       *
 965       * @param WP_Comment[] $comments Array of top-level comments whose descendants should be filled in.
 966       * @return array
 967       */
 968  	protected function fill_descendants( $comments ) {
 969          global $wpdb;
 970  
 971          $levels = array(
 972              0 => wp_list_pluck( $comments, 'comment_ID' ),
 973          );
 974  
 975          $key          = md5( serialize( wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ) ) );
 976          $last_changed = wp_cache_get_last_changed( 'comment' );
 977  
 978          // Fetch an entire level of the descendant tree at a time.
 979          $level        = 0;
 980          $exclude_keys = array( 'parent', 'parent__in', 'parent__not_in' );
 981          do {
 982              // Parent-child relationships may be cached. Only query for those that are not.
 983              $child_ids           = array();
 984              $uncached_parent_ids = array();
 985              $_parent_ids         = $levels[ $level ];
 986              foreach ( $_parent_ids as $parent_id ) {
 987                  $cache_key        = "get_comment_child_ids:$parent_id:$key:$last_changed";
 988                  $parent_child_ids = wp_cache_get( $cache_key, 'comment' );
 989                  if ( false !== $parent_child_ids ) {
 990                      $child_ids = array_merge( $child_ids, $parent_child_ids );
 991                  } else {
 992                      $uncached_parent_ids[] = $parent_id;
 993                  }
 994              }
 995  
 996              if ( $uncached_parent_ids ) {
 997                  // Fetch this level of comments.
 998                  $parent_query_args = $this->query_vars;
 999                  foreach ( $exclude_keys as $exclude_key ) {
1000                      $parent_query_args[ $exclude_key ] = '';
1001                  }
1002                  $parent_query_args['parent__in']    = $uncached_parent_ids;
1003                  $parent_query_args['no_found_rows'] = true;
1004                  $parent_query_args['hierarchical']  = false;
1005                  $parent_query_args['offset']        = 0;
1006                  $parent_query_args['number']        = 0;
1007  
1008                  $level_comments = get_comments( $parent_query_args );
1009  
1010                  // Cache parent-child relationships.
1011                  $parent_map = array_fill_keys( $uncached_parent_ids, array() );
1012                  foreach ( $level_comments as $level_comment ) {
1013                      $parent_map[ $level_comment->comment_parent ][] = $level_comment->comment_ID;
1014                      $child_ids[]                                    = $level_comment->comment_ID;
1015                  }
1016  
1017                  foreach ( $parent_map as $parent_id => $children ) {
1018                      $cache_key = "get_comment_child_ids:$parent_id:$key:$last_changed";
1019                      wp_cache_set( $cache_key, $children, 'comment' );
1020                  }
1021              }
1022  
1023              $level++;
1024              $levels[ $level ] = $child_ids;
1025          } while ( $child_ids );
1026  
1027          // Prime comment caches for non-top-level comments.
1028          $descendant_ids = array();
1029          for ( $i = 1, $c = count( $levels ); $i < $c; $i++ ) {
1030              $descendant_ids = array_merge( $descendant_ids, $levels[ $i ] );
1031          }
1032  
1033          _prime_comment_caches( $descendant_ids, $this->query_vars['update_comment_meta_cache'] );
1034  
1035          // Assemble a flat array of all comments + descendants.
1036          $all_comments = $comments;
1037          foreach ( $descendant_ids as $descendant_id ) {
1038              $all_comments[] = get_comment( $descendant_id );
1039          }
1040  
1041          // If a threaded representation was requested, build the tree.
1042          if ( 'threaded' === $this->query_vars['hierarchical'] ) {
1043              $threaded_comments = array();
1044              $ref               = array();
1045              foreach ( $all_comments as $k => $c ) {
1046                  $_c = get_comment( $c->comment_ID );
1047  
1048                  // If the comment isn't in the reference array, it goes in the top level of the thread.
1049                  if ( ! isset( $ref[ $c->comment_parent ] ) ) {
1050                      $threaded_comments[ $_c->comment_ID ] = $_c;
1051                      $ref[ $_c->comment_ID ]               = $threaded_comments[ $_c->comment_ID ];
1052  
1053                      // Otherwise, set it as a child of its parent.
1054                  } else {
1055  
1056                      $ref[ $_c->comment_parent ]->add_child( $_c );
1057                      $ref[ $_c->comment_ID ] = $ref[ $_c->comment_parent ]->get_child( $_c->comment_ID );
1058                  }
1059              }
1060  
1061              // Set the 'populated_children' flag, to ensure additional database queries aren't run.
1062              foreach ( $ref as $_ref ) {
1063                  $_ref->populated_children( true );
1064              }
1065  
1066              $comments = $threaded_comments;
1067          } else {
1068              $comments = $all_comments;
1069          }
1070  
1071          return $comments;
1072      }
1073  
1074      /**
1075       * Used internally to generate an SQL string for searching across multiple columns
1076       *
1077       * @since 3.1.0
1078       *
1079       * @global wpdb $wpdb WordPress database abstraction object.
1080       *
1081       * @param string $string
1082       * @param array $cols
1083       * @return string
1084       */
1085  	protected function get_search_sql( $string, $cols ) {
1086          global $wpdb;
1087  
1088          $like = '%' . $wpdb->esc_like( $string ) . '%';
1089  
1090          $searches = array();
1091          foreach ( $cols as $col ) {
1092              $searches[] = $wpdb->prepare( "$col LIKE %s", $like );
1093          }
1094  
1095          return ' AND (' . implode( ' OR ', $searches ) . ')';
1096      }
1097  
1098      /**
1099       * Parse and sanitize 'orderby' keys passed to the comment query.
1100       *
1101       * @since 4.2.0
1102       *
1103       * @global wpdb $wpdb WordPress database abstraction object.
1104       *
1105       * @param string $orderby Alias for the field to order by.
1106       * @return string|false Value to used in the ORDER clause. False otherwise.
1107       */
1108  	protected function parse_orderby( $orderby ) {
1109          global $wpdb;
1110  
1111          $allowed_keys = array(
1112              'comment_agent',
1113              'comment_approved',
1114              'comment_author',
1115              'comment_author_email',
1116              'comment_author_IP',
1117              'comment_author_url',
1118              'comment_content',
1119              'comment_date',
1120              'comment_date_gmt',
1121              'comment_ID',
1122              'comment_karma',
1123              'comment_parent',
1124              'comment_post_ID',
1125              'comment_type',
1126              'user_id',
1127          );
1128  
1129          if ( ! empty( $this->query_vars['meta_key'] ) ) {
1130              $allowed_keys[] = $this->query_vars['meta_key'];
1131              $allowed_keys[] = 'meta_value';
1132              $allowed_keys[] = 'meta_value_num';
1133          }
1134  
1135          $meta_query_clauses = $this->meta_query->get_clauses();
1136          if ( $meta_query_clauses ) {
1137              $allowed_keys = array_merge( $allowed_keys, array_keys( $meta_query_clauses ) );
1138          }
1139  
1140          $parsed = false;
1141          if ( $orderby == $this->query_vars['meta_key'] || $orderby == 'meta_value' ) {
1142              $parsed = "$wpdb->commentmeta.meta_value";
1143          } elseif ( $orderby == 'meta_value_num' ) {
1144              $parsed = "$wpdb->commentmeta.meta_value+0";
1145          } elseif ( $orderby == 'comment__in' ) {
1146              $comment__in = implode( ',', array_map( 'absint', $this->query_vars['comment__in'] ) );
1147              $parsed      = "FIELD( {$wpdb->comments}.comment_ID, $comment__in )";
1148          } elseif ( in_array( $orderby, $allowed_keys ) ) {
1149  
1150              if ( isset( $meta_query_clauses[ $orderby ] ) ) {
1151                  $meta_clause = $meta_query_clauses[ $orderby ];
1152                  $parsed      = sprintf( 'CAST(%s.meta_value AS %s)', esc_sql( $meta_clause['alias'] ), esc_sql( $meta_clause['cast'] ) );
1153              } else {
1154                  $parsed = "$wpdb->comments.$orderby";
1155              }
1156          }
1157  
1158          return $parsed;
1159      }
1160  
1161      /**
1162       * Parse an 'order' query variable and cast it to ASC or DESC as necessary.
1163       *
1164       * @since 4.2.0
1165       *
1166       * @param string $order The 'order' query variable.
1167       * @return string The sanitized 'order' query variable.
1168       */
1169  	protected function parse_order( $order ) {
1170          if ( ! is_string( $order ) || empty( $order ) ) {
1171              return 'DESC';
1172          }
1173  
1174          if ( 'ASC' === strtoupper( $order ) ) {
1175              return 'ASC';
1176          } else {
1177              return 'DESC';
1178          }
1179      }
1180  }


Generated: Tue Sep 17 01:00:03 2019 Cross-referenced by PHPXref 0.7.1