equal
deleted
inserted
replaced
85 * |
85 * |
86 * @param WP_REST_Request $request Full details about the request. |
86 * @param WP_REST_Request $request Full details about the request. |
87 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
87 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
88 */ |
88 */ |
89 public function get_items( $request ) { |
89 public function get_items( $request ) { |
90 /* |
|
91 * Include an unmodified `$wp_version`, so the API can craft a response that's tailored to |
|
92 * it. Some plugins modify the version in a misguided attempt to improve security by |
|
93 * obscuring the version, which can cause invalid requests. |
|
94 */ |
|
95 require ABSPATH . WPINC . '/version.php'; |
|
96 |
|
97 $valid_query_args = array( |
90 $valid_query_args = array( |
98 'offset' => true, |
91 'offset' => true, |
99 'order' => true, |
92 'order' => true, |
100 'orderby' => true, |
93 'orderby' => true, |
101 'page' => true, |
94 'page' => true, |
104 'slug' => true, |
97 'slug' => true, |
105 ); |
98 ); |
106 $query_args = array_intersect_key( $request->get_params(), $valid_query_args ); |
99 $query_args = array_intersect_key( $request->get_params(), $valid_query_args ); |
107 |
100 |
108 $query_args['locale'] = get_user_locale(); |
101 $query_args['locale'] = get_user_locale(); |
109 $query_args['wp-version'] = $wp_version; |
102 $query_args['wp-version'] = wp_get_wp_version(); |
110 $query_args['pattern-categories'] = isset( $request['category'] ) ? $request['category'] : false; |
103 $query_args['pattern-categories'] = isset( $request['category'] ) ? $request['category'] : false; |
111 $query_args['pattern-keywords'] = isset( $request['keyword'] ) ? $request['keyword'] : false; |
104 $query_args['pattern-keywords'] = isset( $request['keyword'] ) ? $request['keyword'] : false; |
112 |
105 |
113 $query_args = array_filter( $query_args ); |
106 $query_args = array_filter( $query_args ); |
114 |
107 |
164 |
157 |
165 if ( is_wp_error( $raw_patterns ) ) { |
158 if ( is_wp_error( $raw_patterns ) ) { |
166 $raw_patterns->add_data( array( 'status' => 500 ) ); |
159 $raw_patterns->add_data( array( 'status' => 500 ) ); |
167 |
160 |
168 return $raw_patterns; |
161 return $raw_patterns; |
|
162 } |
|
163 |
|
164 if ( $request->is_method( 'HEAD' ) ) { |
|
165 // Return early as this handler doesn't add any response headers. |
|
166 return new WP_REST_Response( array() ); |
169 } |
167 } |
170 |
168 |
171 $response = array(); |
169 $response = array(); |
172 |
170 |
173 if ( $raw_patterns ) { |
171 if ( $raw_patterns ) { |
374 * @param array $query_params JSON Schema-formatted collection parameters. |
372 * @param array $query_params JSON Schema-formatted collection parameters. |
375 */ |
373 */ |
376 return apply_filters( 'rest_pattern_directory_collection_params', $query_params ); |
374 return apply_filters( 'rest_pattern_directory_collection_params', $query_params ); |
377 } |
375 } |
378 |
376 |
379 /* |
377 /** |
380 * Include a hash of the query args, so that different requests are stored in |
378 * Include a hash of the query args, so that different requests are stored in |
381 * separate caches. |
379 * separate caches. |
382 * |
380 * |
383 * MD5 is chosen for its speed, low-collision rate, universal availability, and to stay |
381 * MD5 is chosen for its speed, low-collision rate, universal availability, and to stay |
384 * under the character limit for `_site_transient_timeout_{...}` keys. |
382 * under the character limit for `_site_transient_timeout_{...}` keys. |