PluginProbe
Performance Lab / 3.6.1
Performance Lab v3.6.1
trunk 1.0.0 1.0.0-beta.1 1.0.0-beta.2 1.0.0-beta.3 1.0.0-rc.1 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0 2.6.1 2.7.0 2.8.0 All 44 releases
performance-lab / includes / server-timing / hooks.php

hooks.php in Performance Lab 3.6.1, at includes/server-timing/hooks.php

42 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Hook callbacks used for Server Timing.
4 *
5 * @package performance-lab
6 *
7 * @since 3.1.0
8 */
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit; // Exit if accessed directly.
12 }
13
14 /**
15 * Adds server timing to REST API response.
16 *
17 * @since 3.1.0
18 *
19 * @param WP_REST_Response|WP_Error $response Result to send to the client. Usually a `WP_REST_Response`.
20 * @return WP_REST_Response|WP_Error Filtered response.
21 */
22 function perflab_rest_post_dispatch_add_server_timing( $response ) {
23 // TODO: Change condition to use wp_is_rest_endpoint() once minimum-supported version is WordPress 6.5.
24 if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST || ! $response instanceof WP_REST_Response ) {
25 return $response;
26 }
27
28 $server_timing = perflab_server_timing();
29
30 /** This filter is documented in includes/server-timing/class-perflab-server-timing.php */
31 do_action( 'perflab_server_timing_send_header' );
32
33 $header_value = $server_timing->get_header();
34
35 if ( '' !== $header_value ) {
36 $response->header( 'Server-Timing', $header_value, false );
37 }
38
39 return $response;
40 }
41 add_filter( 'rest_post_dispatch', 'perflab_rest_post_dispatch_add_server_timing', PHP_INT_MAX );
42