Docs: Improve inline comments per the documentation standards.
Includes minor code layout fixes for better readability. See #48303. Built from https://develop.svn.wordpress.org/trunk@47122 git-svn-id: http://core.svn.wordpress.org/trunk@46922 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -68,9 +68,12 @@ class WP_REST_Search_Controller extends WP_REST_Controller {
|
||||
|
||||
foreach ( $search_handlers as $search_handler ) {
|
||||
if ( ! $search_handler instanceof WP_REST_Search_Handler ) {
|
||||
|
||||
/* translators: %s: PHP class name. */
|
||||
_doing_it_wrong( __METHOD__, sprintf( __( 'REST search handlers must extend the %s class.' ), 'WP_REST_Search_Handler' ), '5.0.0' );
|
||||
_doing_it_wrong(
|
||||
__METHOD__,
|
||||
/* translators: %s: PHP class name. */
|
||||
sprintf( __( 'REST search handlers must extend the %s class.' ), 'WP_REST_Search_Handler' ),
|
||||
'5.0.0'
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -130,12 +133,17 @@ class WP_REST_Search_Controller extends WP_REST_Controller {
|
||||
$result = $handler->search_items( $request );
|
||||
|
||||
if ( ! isset( $result[ WP_REST_Search_Handler::RESULT_IDS ] ) || ! is_array( $result[ WP_REST_Search_Handler::RESULT_IDS ] ) || ! isset( $result[ WP_REST_Search_Handler::RESULT_TOTAL ] ) ) {
|
||||
return new WP_Error( 'rest_search_handler_error', __( 'Internal search handler error.' ), array( 'status' => 500 ) );
|
||||
return new WP_Error(
|
||||
'rest_search_handler_error',
|
||||
__( 'Internal search handler error.' ),
|
||||
array( 'status' => 500 )
|
||||
);
|
||||
}
|
||||
|
||||
$ids = array_map( 'absint', $result[ WP_REST_Search_Handler::RESULT_IDS ] );
|
||||
|
||||
$results = array();
|
||||
|
||||
foreach ( $ids as $id ) {
|
||||
$data = $this->prepare_item_for_response( $id, $request );
|
||||
$results[] = $this->prepare_response_for_collection( $data );
|
||||
@@ -147,7 +155,11 @@ class WP_REST_Search_Controller extends WP_REST_Controller {
|
||||
$max_pages = ceil( $total / $per_page );
|
||||
|
||||
if ( $page > $max_pages && $total > 0 ) {
|
||||
return new WP_Error( 'rest_search_invalid_page_number', __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) );
|
||||
return new WP_Error(
|
||||
'rest_search_invalid_page_number',
|
||||
__( 'The page number requested is larger than the number of pages available.' ),
|
||||
array( 'status' => 400 )
|
||||
);
|
||||
}
|
||||
|
||||
$response = rest_ensure_response( $results );
|
||||
@@ -217,6 +229,7 @@ class WP_REST_Search_Controller extends WP_REST_Controller {
|
||||
|
||||
$types = array();
|
||||
$subtypes = array();
|
||||
|
||||
foreach ( $this->search_handlers as $search_handler ) {
|
||||
$types[] = $search_handler->get_type();
|
||||
$subtypes = array_merge( $subtypes, $search_handler->get_subtypes() );
|
||||
@@ -267,6 +280,7 @@ class WP_REST_Search_Controller extends WP_REST_Controller {
|
||||
);
|
||||
|
||||
$this->schema = $schema;
|
||||
|
||||
return $this->add_additional_fields_schema( $this->schema );
|
||||
}
|
||||
|
||||
@@ -280,6 +294,7 @@ class WP_REST_Search_Controller extends WP_REST_Controller {
|
||||
public function get_collection_params() {
|
||||
$types = array();
|
||||
$subtypes = array();
|
||||
|
||||
foreach ( $this->search_handlers as $search_handler ) {
|
||||
$types[] = $search_handler->get_type();
|
||||
$subtypes = array_merge( $subtypes, $search_handler->get_subtypes() );
|
||||
@@ -356,7 +371,11 @@ class WP_REST_Search_Controller extends WP_REST_Controller {
|
||||
$type = $request->get_param( self::PROP_TYPE );
|
||||
|
||||
if ( ! $type || ! isset( $this->search_handlers[ $type ] ) ) {
|
||||
return new WP_Error( 'rest_search_invalid_type', __( 'Invalid type parameter.' ), array( 'status' => 400 ) );
|
||||
return new WP_Error(
|
||||
'rest_search_invalid_type',
|
||||
__( 'Invalid type parameter.' ),
|
||||
array( 'status' => 400 )
|
||||
);
|
||||
}
|
||||
|
||||
return $this->search_handlers[ $type ];
|
||||
|
||||
Reference in New Issue
Block a user