Skip to content

Commit

Permalink
Improve preloading request code (#11007)
Browse files Browse the repository at this point in the history
This removes the conditional branching based on the existence of the `get_compact_response_links()` method on the `$server` object, as that method was introduced with WordPress 4.5, and Gutenberg requires WordPress 4.9.8 or later.

Also, it turns the indirect and slow call through `call_user_func()` into a direct method call.

Note: The call would actually be more correct as a static call (`$server::get_compact_response_links( $response)`), but this notation is PHP 5.3+ only.
  • Loading branch information
schlessera authored and danielbachhuber committed Oct 25, 2018
1 parent 4317761 commit 6c7ec27
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -863,11 +863,7 @@ function gutenberg_preload_api_request( $memo, $path ) {
if ( 200 === $response->status ) {
$server = rest_get_server();
$data = (array) $response->get_data();
if ( method_exists( $server, 'get_compact_response_links' ) ) {
$links = call_user_func( array( $server, 'get_compact_response_links' ), $response );
} else {
$links = call_user_func( array( $server, 'get_response_links' ), $response );
}
$links = $server->get_compact_response_links( $response );
if ( ! empty( $links ) ) {
$data['_links'] = $links;
}
Expand Down

0 comments on commit 6c7ec27

Please sign in to comment.