wp/wp-includes/rest-api/search/class-wp-rest-post-search-handler.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
   130 		}
   130 		}
   131 
   131 
   132 		if ( in_array( WP_REST_Search_Controller::PROP_TITLE, $fields, true ) ) {
   132 		if ( in_array( WP_REST_Search_Controller::PROP_TITLE, $fields, true ) ) {
   133 			if ( post_type_supports( $post->post_type, 'title' ) ) {
   133 			if ( post_type_supports( $post->post_type, 'title' ) ) {
   134 				add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) );
   134 				add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) );
       
   135 				add_filter( 'private_title_format', array( $this, 'protected_title_format' ) );
   135 				$data[ WP_REST_Search_Controller::PROP_TITLE ] = get_the_title( $post->ID );
   136 				$data[ WP_REST_Search_Controller::PROP_TITLE ] = get_the_title( $post->ID );
   136 				remove_filter( 'protected_title_format', array( $this, 'protected_title_format' ) );
   137 				remove_filter( 'protected_title_format', array( $this, 'protected_title_format' ) );
       
   138 				remove_filter( 'private_title_format', array( $this, 'protected_title_format' ) );
   137 			} else {
   139 			} else {
   138 				$data[ WP_REST_Search_Controller::PROP_TITLE ] = '';
   140 				$data[ WP_REST_Search_Controller::PROP_TITLE ] = '';
   139 			}
   141 			}
   140 		}
   142 		}
   141 
   143 
   181 
   183 
   182 		return $links;
   184 		return $links;
   183 	}
   185 	}
   184 
   186 
   185 	/**
   187 	/**
   186 	 * Overwrites the default protected title format.
   188 	 * Overwrites the default protected and private title format.
   187 	 *
   189 	 *
   188 	 * By default, WordPress will show password protected posts with a title of
   190 	 * By default, WordPress will show password protected or private posts with a title of
   189 	 * "Protected: %s". As the REST API communicates the protected status of a post
   191 	 * "Protected: %s" or "Private: %s", as the REST API communicates the status of a post
   190 	 * in a machine readable format, we remove the "Protected: " prefix.
   192 	 * in a machine-readable format, we remove the prefix.
   191 	 *
   193 	 *
   192 	 * @since 5.0.0
   194 	 * @since 5.0.0
   193 	 *
   195 	 *
   194 	 * @return string Protected title format.
   196 	 * @return string Title format.
   195 	 */
   197 	 */
   196 	public function protected_title_format() {
   198 	public function protected_title_format() {
   197 		return '%s';
   199 		return '%s';
   198 	}
   200 	}
   199 
   201