diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php index 0cb54c91ed3de..e3057e75d86b8 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php @@ -327,10 +327,12 @@ public function prepare_item_for_response( $post, $request ) { } if ( rest_is_field_included( 'title.rendered', $fields ) ) { add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); + add_filter( 'private_title_format', array( $this, 'protected_title_format' ) ); $data['title']['rendered'] = get_the_title( $post->ID ); remove_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); + remove_filter( 'private_title_format', array( $this, 'protected_title_format' ) ); } if ( rest_is_field_included( 'settings', $fields ) ) { diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php index 4119b6530e91e..9fbaa95371b54 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php @@ -510,6 +510,7 @@ public function prepare_item_for_response( $item, $request ) { if ( rest_is_field_included( 'title.rendered', $fields ) ) { add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); + add_filter( 'private_title_format', array( $this, 'protected_title_format' ) ); /** This filter is documented in wp-includes/post-template.php */ $title = apply_filters( 'the_title', $menu_item->title, $menu_item->ID ); @@ -517,6 +518,7 @@ public function prepare_item_for_response( $item, $request ) { $data['title']['rendered'] = $title; remove_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); + remove_filter( 'private_title_format', array( $this, 'protected_title_format' ) ); } if ( rest_is_field_included( 'status', $fields ) ) { diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index e5420c74fb3ea..d6afdef470af2 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -1844,10 +1844,12 @@ public function prepare_item_for_response( $item, $request ) { } if ( rest_is_field_included( 'title.rendered', $fields ) ) { add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); + add_filter( 'private_title_format', array( $this, 'protected_title_format' ) ); $data['title']['rendered'] = get_the_title( $post->ID ); remove_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); + remove_filter( 'private_title_format', array( $this, 'protected_title_format' ) ); } $has_password_filter = false; @@ -2047,15 +2049,15 @@ public function prepare_item_for_response( $item, $request ) { } /** - * Overwrites the default protected title format. + * Overwrites the default protected and private title format. * - * By default, WordPress will show password protected posts with a title of - * "Protected: %s", as the REST API communicates the protected status of a post - * in a machine-readable format, we remove the "Protected: " prefix. + * By default, WordPress will show password protected or private posts with a title of + * "Protected: %s" or "Private: %s", as the REST API communicates the status of a post + * in a machine-readable format, we remove the prefix. * * @since 4.7.0 * - * @return string Protected title format. + * @return string Title format. */ public function protected_title_format() { return '%s'; diff --git a/src/wp-includes/rest-api/search/class-wp-rest-post-search-handler.php b/src/wp-includes/rest-api/search/class-wp-rest-post-search-handler.php index 58b36506e7d9f..fff921f749e07 100644 --- a/src/wp-includes/rest-api/search/class-wp-rest-post-search-handler.php +++ b/src/wp-includes/rest-api/search/class-wp-rest-post-search-handler.php @@ -132,8 +132,10 @@ public function prepare_item( $id, array $fields ) { if ( in_array( WP_REST_Search_Controller::PROP_TITLE, $fields, true ) ) { if ( post_type_supports( $post->post_type, 'title' ) ) { add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); + add_filter( 'private_title_format', array( $this, 'protected_title_format' ) ); $data[ WP_REST_Search_Controller::PROP_TITLE ] = get_the_title( $post->ID ); remove_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); + remove_filter( 'private_title_format', array( $this, 'protected_title_format' ) ); } else { $data[ WP_REST_Search_Controller::PROP_TITLE ] = ''; } @@ -183,15 +185,15 @@ public function prepare_item_links( $id ) { } /** - * Overwrites the default protected title format. + * Overwrites the default protected and private title format. * - * By default, WordPress will show password protected posts with a title of - * "Protected: %s". As the REST API communicates the protected status of a post - * in a machine-readable format, we remove the "Protected: " prefix. + * By default, WordPress will show password protected or private posts with a title of + * "Protected: %s" or "Private: %s", as the REST API communicates the status of a post + * in a machine-readable format, we remove the prefix. * * @since 5.0.0 * - * @return string Protected title format. + * @return string Title format. */ public function protected_title_format() { return '%s'; diff --git a/tests/phpunit/includes/testcase-rest-post-type-controller.php b/tests/phpunit/includes/testcase-rest-post-type-controller.php index 9b1d366315bc4..75326284e6e5d 100644 --- a/tests/phpunit/includes/testcase-rest-post-type-controller.php +++ b/tests/phpunit/includes/testcase-rest-post-type-controller.php @@ -107,8 +107,10 @@ protected function check_post_data( $post, $data, $context, $links ) { // Check filtered values. if ( post_type_supports( $post->post_type, 'title' ) ) { add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); + add_filter( 'private_title_format', array( $this, 'protected_title_format' ) ); $this->assertSame( get_the_title( $post->ID ), $data['title']['rendered'] ); remove_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); + remove_filter( 'private_title_format', array( $this, 'protected_title_format' ) ); if ( 'edit' === $context ) { $this->assertSame( $post->post_title, $data['title']['raw'] ); } else { diff --git a/tests/phpunit/tests/rest-api/wpRestMenuItemsController.php b/tests/phpunit/tests/rest-api/wpRestMenuItemsController.php index 53d52350b6b1c..5508123deac19 100644 --- a/tests/phpunit/tests/rest-api/wpRestMenuItemsController.php +++ b/tests/phpunit/tests/rest-api/wpRestMenuItemsController.php @@ -862,8 +862,10 @@ protected function check_menu_item_data( $post, $data, $context, $links ) { // Check filtered values. if ( post_type_supports( self::POST_TYPE, 'title' ) ) { add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); + add_filter( 'private_title_format', array( $this, 'protected_title_format' ) ); $this->assertSame( $post->title, $data['title']['rendered'] ); remove_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); + remove_filter( 'private_title_format', array( $this, 'protected_title_format' ) ); if ( 'edit' === $context ) { $this->assertSame( $post->title, $data['title']['raw'] ); } else {