WP_REST_Comments_Controller::get_collection_params() WordPress Method

The WP_REST_Comments_Controller::get_collection_params() method is used to get the collection parameters for comments. This includes the default parameters for ordering and for the comments controller.

WP_REST_Comments_Controller::get_collection_params() #

Retrieves the query params for collections.


Return

(array) Comments collection parameters.


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
public function get_collection_params() {
    $query_params = parent::get_collection_params();
 
    $query_params['context']['default'] = 'view';
 
    $query_params['after'] = array(
        'description' => __( 'Limit response to comments published after a given ISO8601 compliant date.' ),
        'type'        => 'string',
        'format'      => 'date-time',
    );
 
    $query_params['author'] = array(
        'description' => __( 'Limit result set to comments assigned to specific user IDs. Requires authorization.' ),
        'type'        => 'array',
        'items'       => array(
            'type' => 'integer',
        ),
    );
 
    $query_params['author_exclude'] = array(
        'description' => __( 'Ensure result set excludes comments assigned to specific user IDs. Requires authorization.' ),
        'type'        => 'array',
        'items'       => array(
            'type' => 'integer',
        ),
    );
 
    $query_params['author_email'] = array(
        'default'     => null,
        'description' => __( 'Limit result set to that from a specific author email. Requires authorization.' ),
        'format'      => 'email',
        'type'        => 'string',
    );
 
    $query_params['before'] = array(
        'description' => __( 'Limit response to comments published before a given ISO8601 compliant date.' ),
        'type'        => 'string',
        'format'      => 'date-time',
    );
 
    $query_params['exclude'] = array(
        'description' => __( 'Ensure result set excludes specific IDs.' ),
        'type'        => 'array',
        'items'       => array(
            'type' => 'integer',
        ),
        'default'     => array(),
    );
 
    $query_params['include'] = array(
        'description' => __( 'Limit result set to specific IDs.' ),
        'type'        => 'array',
        'items'       => array(
            'type' => 'integer',
        ),
        'default'     => array(),
    );
 
    $query_params['offset'] = array(
        'description' => __( 'Offset the result set by a specific number of items.' ),
        'type'        => 'integer',
    );
 
    $query_params['order'] = array(
        'description' => __( 'Order sort attribute ascending or descending.' ),
        'type'        => 'string',
        'default'     => 'desc',
        'enum'        => array(
            'asc',
            'desc',
        ),
    );
 
    $query_params['orderby'] = array(
        'description' => __( 'Sort collection by comment attribute.' ),
        'type'        => 'string',
        'default'     => 'date_gmt',
        'enum'        => array(
            'date',
            'date_gmt',
            'id',
            'include',
            'post',
            'parent',
            'type',
        ),
    );
 
    $query_params['parent'] = array(
        'default'     => array(),
        'description' => __( 'Limit result set to comments of specific parent IDs.' ),
        'type'        => 'array',
        'items'       => array(
            'type' => 'integer',
        ),
    );
 
    $query_params['parent_exclude'] = array(
        'default'     => array(),
        'description' => __( 'Ensure result set excludes specific parent IDs.' ),
        'type'        => 'array',
        'items'       => array(
            'type' => 'integer',
        ),
    );
 
    $query_params['post'] = array(
        'default'     => array(),
        'description' => __( 'Limit result set to comments assigned to specific post IDs.' ),
        'type'        => 'array',
        'items'       => array(
            'type' => 'integer',
        ),
    );
 
    $query_params['status'] = array(
        'default'           => 'approve',
        'description'       => __( 'Limit result set to comments assigned a specific status. Requires authorization.' ),
        'sanitize_callback' => 'sanitize_key',
        'type'              => 'string',
        'validate_callback' => 'rest_validate_request_arg',
    );
 
    $query_params['type'] = array(
        'default'           => 'comment',
        'description'       => __( 'Limit result set to comments assigned a specific type. Requires authorization.' ),
        'sanitize_callback' => 'sanitize_key',
        'type'              => 'string',
        'validate_callback' => 'rest_validate_request_arg',
    );
 
    $query_params['password'] = array(
        'description' => __( 'The password for the post if it is password protected.' ),
        'type'        => 'string',
    );
 
    /**
     * Filters REST API collection parameters for the comments controller.
     *
     * This filter registers the collection parameter, but does not map the
     * collection parameter to an internal WP_Comment_Query parameter. Use the
     * `rest_comment_query` filter to set WP_Comment_Query parameters.
     *
     * @since 4.7.0
     *
     * @param array $query_params JSON Schema-formatted collection parameters.
     */
    return apply_filters( 'rest_comment_collection_params', $query_params );
}


Top ↑

Changelog

Changelog
VersionDescription
4.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.