-
Notifications
You must be signed in to change notification settings - Fork 138
Added server timing to REST API response #1206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
westonruter
merged 13 commits into
WordPress:trunk
from
ashwinparthasarathi:update/add-server-timing-in-rest-api
May 14, 2024
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d8584b0
Added server timing to REST API response
ashwinparthasarathi 94f3c79
Updated code to include a hooks.php file
ashwinparthasarathi d806f93
Update includes/server-timing/hooks.php
ashwinparthasarathi 288cc08
Update includes/server-timing/hooks.php
ashwinparthasarathi f695170
Updated code as per review comments
ashwinparthasarathi d45bd02
Merge branch 'update/add-server-timing-in-rest-api' of github.com:ash…
ashwinparthasarathi 6e3a3a7
Update includes/server-timing/hooks.php
ashwinparthasarathi c370810
Update includes/server-timing/hooks.php
ashwinparthasarathi fe88513
Update includes/server-timing/hooks.php
ashwinparthasarathi 26c7077
Merge branch 'WordPress:trunk' into update/add-server-timing-in-rest-api
ashwinparthasarathi e665159
Changed code based on review comments.
ashwinparthasarathi c69b1cd
Merge branch 'trunk' into update/add-server-timing-in-rest-api
westonruter 82ffc1a
Update includes/server-timing/hooks.php
ashwinparthasarathi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Updated code to include a hooks.php file
- Loading branch information
commit 94f3c79be5522cdf8dca2abee38c10dde71e65d1
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php | ||
| /** | ||
| * Hook callbacks used for Server Timing. | ||
| * | ||
| * @package dominant-color-images | ||
| * | ||
| * @since 1.0.0 | ||
ashwinparthasarathi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
|
|
||
| if ( ! defined( 'ABSPATH' ) ) { | ||
| exit; // Exit if accessed directly. | ||
| } | ||
|
|
||
|
|
||
ashwinparthasarathi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /** | ||
| * Adds server timing to REST API response. | ||
| * | ||
ashwinparthasarathi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * @param WP_REST_Response|WP_Error $response Result to send to the client. Usually a `WP_REST_Response`. | ||
| * @return WP_REST_Response|WP_Error Filtered response. | ||
| */ | ||
| function rest_post_dispatch_add_server_timing( $response ) { | ||
ashwinparthasarathi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) { | ||
| return $response; | ||
| } | ||
|
|
||
| if ( ! function_exists( 'perflab_server_timing' ) || ! $response instanceof WP_REST_Response ) { | ||
| return $response; | ||
| } | ||
ashwinparthasarathi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| $server_timing = perflab_server_timing(); | ||
|
|
||
| do_action( 'perflab_server_timing_send_header' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound | ||
ashwinparthasarathi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ashwinparthasarathi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| $response->header( 'Server-Timing', $server_timing->get_header() ); | ||
ashwinparthasarathi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return $response; | ||
| } | ||
| add_filter( 'rest_post_dispatch', 'rest_post_dispatch_add_server_timing' ); | ||
ashwinparthasarathi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.