Changeset 43763 for branches/5.0/src/wp-includes/rest-api.php
- Timestamp:
- 10/19/2018 08:56:58 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0/src/wp-includes/rest-api.php
r43739 r43763 1312 1312 return $value; 1313 1313 } 1314 1315 /** 1316 * Append result of internal request to REST API for purpose of preloading data to be attached to a page. 1317 * Expected to be called in the context of `array_reduce`. 1318 * 1319 * @since 5.0.0 1320 * 1321 * @param array $memo Reduce accumulator. 1322 * @param string $path REST API path to preload. 1323 * @return array Modified reduce accumulator. 1324 */ 1325 function rest_preload_api_request( $memo, $path ) { 1326 // array_reduce() doesn't support passing an array in PHP 5.2, so we need to make sure we start with one. 1327 if ( ! is_array( $memo ) ) { 1328 $memo = array(); 1329 } 1330 1331 if ( empty( $path ) ) { 1332 return $memo; 1333 } 1334 1335 $path_parts = parse_url( $path ); 1336 if ( false === $path_parts ) { 1337 return $memo; 1338 } 1339 1340 $request = new WP_REST_Request( 'GET', $path_parts['path'] ); 1341 if ( ! empty( $path_parts['query'] ) ) { 1342 parse_str( $path_parts['query'], $query_params ); 1343 $request->set_query_params( $query_params ); 1344 } 1345 1346 $response = rest_do_request( $request ); 1347 if ( 200 === $response->status ) { 1348 $server = rest_get_server(); 1349 $data = (array) $response->get_data(); 1350 if ( method_exists( $server, 'get_compact_response_links' ) ) { 1351 $links = call_user_func( array( $server, 'get_compact_response_links' ), $response ); 1352 } else { 1353 $links = call_user_func( array( $server, 'get_response_links' ), $response ); 1354 } 1355 if ( ! empty( $links ) ) { 1356 $data['_links'] = $links; 1357 } 1358 1359 $memo[ $path ] = array( 1360 'body' => $data, 1361 'headers' => $response->headers, 1362 ); 1363 } 1364 1365 return $memo; 1366 }
Note: See TracChangeset
for help on using the changeset viewer.