| 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: 2 |
| 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 |
// Set constant to be able to later check for whether this file was loaded. |
| 32 |
if ( ! defined( 'PERFLAB_OBJECT_CACHE_DROPIN_VERSION' ) ) { |
| 33 |
define( 'PERFLAB_OBJECT_CACHE_DROPIN_VERSION', 2 ); |
| 34 |
} |
| 35 |
|
| 36 |
if ( ! function_exists( 'perflab_load_server_timing_api_from_dropin' ) ) { |
| 37 |
/** |
| 38 |
* Loads the Performance Lab Server-Timing API if available. |
| 39 |
* |
| 40 |
* This function will short-circuit if the constant |
| 41 |
* 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN' is set as true. |
| 42 |
* |
| 43 |
* @since 1.8.0 |
| 44 |
*/ |
| 45 |
function perflab_load_server_timing_api_from_dropin() { |
| 46 |
if ( defined( 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN' ) && PERFLAB_DISABLE_OBJECT_CACHE_DROPIN ) { |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
$plugins_dir = defined( 'WP_PLUGIN_DIR' ) ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins'; |
| 51 |
$plugin_dir = $plugins_dir . '/performance-lab/'; |
| 52 |
if ( ! file_exists( $plugin_dir . 'server-timing/load.php' ) ) { |
| 53 |
$plugin_dir = $plugins_dir . '/performance/'; |
| 54 |
if ( ! file_exists( $plugin_dir . 'server-timing/load.php' ) ) { |
| 55 |
return; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
require_once $plugin_dir . 'server-timing/class-perflab-server-timing-metric.php'; |
| 60 |
require_once $plugin_dir . 'server-timing/class-perflab-server-timing.php'; |
| 61 |
require_once $plugin_dir . 'server-timing/load.php'; |
| 62 |
require_once $plugin_dir . 'server-timing/defaults.php'; |
| 63 |
} |
| 64 |
} |
| 65 |
perflab_load_server_timing_api_from_dropin(); |
| 66 |
|
| 67 |
/** |
| 68 |
* Load the original object cache drop-in if present. |
| 69 |
* This is only here for backward compatibility, as new Performance Lab |
| 70 |
* versions no longer use the approach of backing up the original |
| 71 |
* object-cache.php file and loading both. |
| 72 |
* It is critical however to maintain this line here to not break existing |
| 73 |
* sites where this approach has been working as expected. |
| 74 |
*/ |
| 75 |
if ( file_exists( WP_CONTENT_DIR . '/object-cache-plst-orig.php' ) ) { |
| 76 |
require_once WP_CONTENT_DIR . '/object-cache-plst-orig.php'; |
| 77 |
} |
| 78 |
|