From ce95e57fb0188b7cb8e78c22c4358d7ba3e42e2f Mon Sep 17 00:00:00 2001 From: Jorge Date: Fri, 20 Jul 2018 15:45:51 +0100 Subject: [PATCH] Page Attributes: Fix: Parent-Dropdown missing for custom post-type. We here allowing unbound requests for pages because pages have a parent picker UI than needed unbound requests. Pages were not the only CPT's that allow choosing a parent post. This commits makes sure we allow unbound requests for all hierarchical post types. --- lib/rest-api.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/rest-api.php b/lib/rest-api.php index d2d08cbd824d7e..16aff116ab2449 100644 --- a/lib/rest-api.php +++ b/lib/rest-api.php @@ -487,14 +487,15 @@ function gutenberg_handle_early_callback_checks( $response, $handler, $request ) * * @see https://core.trac.wordpress.org/ticket/43998 * - * @param array $query_params JSON Schema-formatted collection parameters. - * @param string $post_type Post type being accessed. + * @param array $query_params JSON Schema-formatted collection parameters. + * @param WP_Post_Type Post type object being accessed. * @return array */ function gutenberg_filter_post_collection_parameters( $query_params, $post_type ) { - $post_types = array( 'page', 'wp_block' ); - if ( in_array( $post_type->name, $post_types, true ) - && isset( $query_params['per_page'] ) ) { + if ( + isset( $query_params['per_page'] ) && + ( $post_type->hierarchical || $post_type->name === 'wp_block' ) + ) { // Change from '1' to '-1', which means unlimited. $query_params['per_page']['minimum'] = -1; // Default sanitize callback is 'absint', which won't work in our case. @@ -513,8 +514,7 @@ function gutenberg_filter_post_collection_parameters( $query_params, $post_type * @return array */ function gutenberg_filter_post_query_arguments( $prepared_args, $request ) { - $post_types = array( 'page', 'wp_block' ); - if ( in_array( $prepared_args['post_type'], $post_types, true ) ) { + if ( is_post_type_hierarchical( $prepared_args['post_type'] ) || $prepared_args['post_type'] === 'wp_block' ) { // Avoid triggering 'rest_post_invalid_page_number' error // which will need to be addressed in https://core.trac.wordpress.org/ticket/43998. if ( -1 === $prepared_args['posts_per_page'] ) {