Skip to content

Commit

Permalink
Page Attributes: Fix: Parent-Dropdown missing for custom post-type.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jorgefilipecosta committed Jul 23, 2018
1 parent 09db904 commit cc39590
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 || 'wp_block' === $post_type->name )
) {
// 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.
Expand All @@ -513,8 +514,10 @@ 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'] ) ||
'wp_block' === $prepared_args['post_type']
) {
// 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'] ) {
Expand Down

0 comments on commit cc39590

Please sign in to comment.