WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/10/2019 06:41:03 PM (18 months ago)
Author:
adamsilverstein
Message:

Comments: add a new comments_pre_query filter to short circuit WP_Comment_Query 'get_comments' queries.

Return a non-null value to bypass WordPress's default comment queries.

Props felipeelia, spacedmonkey.
Fixes #45800.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-comment-query.php

    r45603 r46086  
    380380        }
    381381
     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         *                                       or null to allow WP to run its normal queries.
     398         * @param WP_Comment_Query $this         The WP_Comment_Query instance, passed by reference.
     399         */
     400        $comment_data = apply_filters_ref_array( 'comments_pre_query', array( $comment_data, &$this ) );
     401
     402        if ( null !== $comment_data ) {
     403            return $comment_data;
     404        }
     405
    382406        /*
    383407         * Only use the args defined in the query_var_defaults to compute the key,
Note: See TracChangeset for help on using the changeset viewer.