equal
deleted
inserted
replaced
24 public function __construct() { |
24 public function __construct() { |
25 $this->type = 'post-format'; |
25 $this->type = 'post-format'; |
26 } |
26 } |
27 |
27 |
28 /** |
28 /** |
29 * Searches the object type content for a given search request. |
29 * Searches the post formats for a given search request. |
30 * |
30 * |
31 * @since 5.6.0 |
31 * @since 5.6.0 |
32 * |
32 * |
33 * @param WP_REST_Request $request Full REST request. |
33 * @param WP_REST_Request $request Full REST request. |
34 * @return array Associative array containing an `WP_REST_Search_Handler::RESULT_IDS` containing |
34 * @return array { |
35 * an array of found IDs and `WP_REST_Search_Handler::RESULT_TOTAL` containing the |
35 * Associative array containing found IDs and total count for the matching search results. |
36 * total count for the matching search results. |
36 * |
|
37 * @type string[] $ids Array containing slugs for the matching post formats. |
|
38 * @type int $total Total count for the matching search results. |
|
39 * } |
37 */ |
40 */ |
38 public function search_items( WP_REST_Request $request ) { |
41 public function search_items( WP_REST_Request $request ) { |
39 $format_strings = get_post_format_strings(); |
42 $format_strings = get_post_format_strings(); |
40 $format_slugs = array_keys( $format_strings ); |
43 $format_slugs = array_keys( $format_strings ); |
41 |
44 |
44 if ( ! empty( $request['search'] ) ) { |
47 if ( ! empty( $request['search'] ) ) { |
45 $query_args['search'] = $request['search']; |
48 $query_args['search'] = $request['search']; |
46 } |
49 } |
47 |
50 |
48 /** |
51 /** |
49 * Filters the query arguments for a REST API search request. |
52 * Filters the query arguments for a REST API post format search request. |
50 * |
53 * |
51 * Enables adding extra arguments or setting defaults for a post format search request. |
54 * Enables adding extra arguments or setting defaults for a post format search request. |
52 * |
55 * |
53 * @since 5.6.0 |
56 * @since 5.6.0 |
54 * |
57 * |
82 self::RESULT_TOTAL => count( $found_ids ), |
85 self::RESULT_TOTAL => count( $found_ids ), |
83 ); |
86 ); |
84 } |
87 } |
85 |
88 |
86 /** |
89 /** |
87 * Prepares the search result for a given ID. |
90 * Prepares the search result for a given post format. |
88 * |
91 * |
89 * @since 5.6.0 |
92 * @since 5.6.0 |
90 * |
93 * |
91 * @param string $id Item ID, the post format slug. |
94 * @param string $id Item ID, the post format slug. |
92 * @param array $fields Fields to include for the item. |
95 * @param array $fields Fields to include for the item. |
93 * @return array Associative array containing all fields for the item. |
96 * @return array { |
|
97 * Associative array containing fields for the post format based on the `$fields` parameter. |
|
98 * |
|
99 * @type string $id Optional. Post format slug. |
|
100 * @type string $title Optional. Post format name. |
|
101 * @type string $url Optional. Post format permalink URL. |
|
102 * @type string $type Optional. String 'post-format'. |
|
103 *} |
94 */ |
104 */ |
95 public function prepare_item( $id, array $fields ) { |
105 public function prepare_item( $id, array $fields ) { |
96 $data = array(); |
106 $data = array(); |
97 |
107 |
98 if ( in_array( WP_REST_Search_Controller::PROP_ID, $fields, true ) ) { |
108 if ( in_array( WP_REST_Search_Controller::PROP_ID, $fields, true ) ) { |