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 / object-cache.copy.php

object-cache.copy.php in Performance Lab 3.6.1, at includes/server-timing/object-cache.copy.php

87 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Performance Lab Server Timing Object Cache Drop-In
4 * Plugin URI: https://github.com/WordPress/performance
5 * Description: Performance Lab drop-in to register Server-Timing metrics early. This is not a real object cache drop-in and will not override other actual object cache drop-ins.
6 * Version: 3
7 * Author: WordPress Performance Team
8 * Author URI: https://make.wordpress.org/performance/
9 * License: GPLv2 or later
10 * License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11 *
12 * Object cache drop-in from Performance Lab plugin.
13 *
14 * This drop-in is used, admittedly as a hack, to be able to measure server
15 * timings in WordPress as early as possible. Once a plugin is loaded, it is
16 * too late to capture several critical events.
17 *
18 * This file respects any real object cache implementation the site may already
19 * be using, and it is implemented in a way that there is no risk for breakage.
20 *
21 * If you do not want the Performance Lab plugin to place this file and thus be
22 * limited to server timings only from after plugins are loaded, you can remove
23 * this file and set the following constant (e.g. in wp-config.php):
24 *
25 * define( 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN', true );
26 *
27 * @package performance-lab
28 * @since 1.8.0
29 */
30
31 if ( ! defined( 'ABSPATH' ) ) {
32 exit; // Exit if accessed directly.
33 }
34
35 // Set constant to be able to later check for whether this file was loaded.
36 if ( ! defined( 'PERFLAB_OBJECT_CACHE_DROPIN_VERSION' ) ) {
37 define( 'PERFLAB_OBJECT_CACHE_DROPIN_VERSION', 3 );
38 }
39
40 if ( ! function_exists( 'perflab_load_server_timing_api_from_dropin' ) ) {
41 /**
42 * Loads the Performance Lab Server-Timing API if available.
43 *
44 * This function will short-circuit if at least one of the constants
45 * 'PERFLAB_DISABLE_SERVER_TIMING' or
46 * 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN' is set as true.
47 *
48 * @since 1.8.0
49 */
50 function perflab_load_server_timing_api_from_dropin(): void {
51 if ( defined( 'PERFLAB_DISABLE_SERVER_TIMING' ) && PERFLAB_DISABLE_SERVER_TIMING ) {
52 return;
53 }
54
55 if ( defined( 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN' ) && PERFLAB_DISABLE_OBJECT_CACHE_DROPIN ) {
56 return;
57 }
58
59 $plugins_dir = defined( 'WP_PLUGIN_DIR' ) ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins';
60 $plugin_dir = $plugins_dir . '/performance-lab/';
61 if ( ! file_exists( $plugin_dir . 'includes/server-timing/load.php' ) ) {
62 $plugin_dir = $plugins_dir . '/performance/';
63 if ( ! file_exists( $plugin_dir . 'includes/server-timing/load.php' ) ) {
64 return;
65 }
66 }
67
68 require_once $plugin_dir . 'includes/server-timing/class-perflab-server-timing-metric.php';
69 require_once $plugin_dir . 'includes/server-timing/class-perflab-server-timing.php';
70 require_once $plugin_dir . 'includes/server-timing/load.php';
71 require_once $plugin_dir . 'includes/server-timing/defaults.php';
72 }
73 }
74 perflab_load_server_timing_api_from_dropin();
75
76 /**
77 * Load the original object cache drop-in if present.
78 * This is only here for backward compatibility, as new Performance Lab
79 * versions no longer use the approach of backing up the original
80 * object-cache.php file and loading both.
81 * It is critical however to maintain this line here to not break existing
82 * sites where this approach has been working as expected.
83 */
84 if ( file_exists( WP_CONTENT_DIR . '/object-cache-plst-orig.php' ) ) {
85 require_once WP_CONTENT_DIR . '/object-cache-plst-orig.php';
86 }
87