PluginProbe
Speculative Loading / trunk
Speculative Loading vtrunk
1.7.0 1.1.0 1.2.0 1.2.1 1.2.2 1.3.0 1.3.1 1.4.0 1.5.0 1.6.0 trunk 1.0.0 1.0.1
speculation-rules / load.php

load.php in Speculative Loading trunk, at load.php

86 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Speculative Loading
4 * Plugin URI: https://github.com/WordPress/performance/tree/trunk/plugins/speculation-rules
5 * Description: Enables browsers to speculatively prerender or prefetch pages to achieve near-instant loads based on user interaction.
6 * Requires at least: 6.9
7 * Requires PHP: 7.4
8 * Version: 1.7.0
9 * Author: WordPress Performance Team
10 * Author URI: https://make.wordpress.org/performance/
11 * License: GPLv2 or later
12 * License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
13 * Text Domain: speculation-rules
14 *
15 * @package speculation-rules
16 */
17
18 declare( strict_types = 1 );
19
20 // @codeCoverageIgnoreStart
21 if ( ! defined( 'ABSPATH' ) ) {
22 exit; // Exit if accessed directly.
23 }
24
25 (
26 /**
27 * Register this copy of the plugin among other potential copies embedded in plugins or themes.
28 *
29 * @param string $global_var_name Global variable name for storing the plugin pending loading.
30 * @param string $version Version.
31 * @param Closure $load Callback that loads the plugin.
32 */
33 static function ( string $global_var_name, string $version, Closure $load ): void {
34 if ( ! isset( $GLOBALS[ $global_var_name ] ) ) {
35 $bootstrap = static function () use ( $global_var_name ): void {
36 if (
37 isset( $GLOBALS[ $global_var_name ]['load'], $GLOBALS[ $global_var_name ]['version'] )
38 &&
39 $GLOBALS[ $global_var_name ]['load'] instanceof Closure
40 &&
41 is_string( $GLOBALS[ $global_var_name ]['version'] )
42 ) {
43 call_user_func( $GLOBALS[ $global_var_name ]['load'], $GLOBALS[ $global_var_name ]['version'] );
44 unset( $GLOBALS[ $global_var_name ] );
45 }
46 };
47
48 // Wait until after the plugins have loaded and the theme has loaded. The after_setup_theme action is used
49 // because it is the first action that fires once the theme is loaded.
50 add_action( 'after_setup_theme', $bootstrap, PHP_INT_MIN );
51 }
52
53 // Register this copy of the plugin.
54 if (
55 // Register this copy if none has been registered yet.
56 ! isset( $GLOBALS[ $global_var_name ]['version'] )
57 ||
58 // Or register this copy if the version greater than what is currently registered.
59 version_compare( $version, $GLOBALS[ $global_var_name ]['version'], '>' )
60 ||
61 // Otherwise, register this copy if it is actually the one installed in the directory for plugins.
62 rtrim( WP_PLUGIN_DIR, '/' ) === dirname( __DIR__ )
63 ) {
64 $GLOBALS[ $global_var_name ]['version'] = $version; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- It is prefixed.
65 $GLOBALS[ $global_var_name ]['load'] = $load; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- It is prefixed.
66 }
67 }
68 )(
69 'plsr_pending_plugin_info',
70 '1.7.0',
71 static function ( string $version ): void {
72
73 // Define the constant.
74 if ( defined( 'SPECULATION_RULES_VERSION' ) ) {
75 return;
76 }
77
78 define( 'SPECULATION_RULES_VERSION', $version );
79 define( 'SPECULATION_RULES_MAIN_FILE', plugin_basename( __FILE__ ) );
80
81 require_once __DIR__ . '/hooks.php';
82 require_once __DIR__ . '/settings.php';
83 }
84 );
85 // @codeCoverageIgnoreEnd
86