-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathload.php
More file actions
88 lines (81 loc) · 3.37 KB
/
load.php
File metadata and controls
88 lines (81 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* Plugin Name: Image Prioritizer
* Plugin URI: https://github.com/WordPress/performance/tree/trunk/plugins/image-prioritizer
* Description: Prioritizes the loading of images and videos based on how visible they are to actual visitors; adds <code>fetchpriority</code> and applies lazy-loading.
* Requires at least: 6.6
* Requires PHP: 7.2
* Requires Plugins: optimization-detective
* Version: 1.0.0-beta3
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* Text Domain: image-prioritizer
*
* @package image-prioritizer
*/
declare( strict_types = 1 );
// @codeCoverageIgnoreStart
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
// @codeCoverageIgnoreEnd
(
/**
* Register this copy of the plugin among other potential copies embedded in plugins or themes.
*
* @param string $global_var_name Global variable name for storing the plugin pending loading.
* @param string $version Version.
* @param Closure $load Callback that loads the plugin.
*/
static function ( string $global_var_name, string $version, Closure $load ): void {
if ( ! isset( $GLOBALS[ $global_var_name ] ) ) {
$bootstrap = static function () use ( $global_var_name ): void {
if (
isset( $GLOBALS[ $global_var_name ]['load'], $GLOBALS[ $global_var_name ]['version'] )
&&
$GLOBALS[ $global_var_name ]['load'] instanceof Closure
&&
is_string( $GLOBALS[ $global_var_name ]['version'] )
) {
call_user_func( $GLOBALS[ $global_var_name ]['load'], $GLOBALS[ $global_var_name ]['version'] );
unset( $GLOBALS[ $global_var_name ] );
}
};
/*
* Wait until after the plugins have loaded and the theme has loaded. The after_setup_theme action could be
* used since it is the first action that fires once the theme is loaded. However, plugins may embed this
* logic inside a module which initializes even later at the init action. The earliest action that this
* plugin has hooks for is the init action at the default priority of 10 (which includes the rest_api_init
* action), so this is why it gets initialized at priority 9.
*/
add_action( 'init', $bootstrap, 9 );
}
// Register this copy of the plugin.
if (
// Register this copy if none has been registered yet.
! isset( $GLOBALS[ $global_var_name ]['version'] )
||
// Or register this copy if the version greater than what is currently registered.
version_compare( $version, $GLOBALS[ $global_var_name ]['version'], '>' )
||
// Otherwise, register this copy if it is actually the one installed in the directory for plugins.
rtrim( WP_PLUGIN_DIR, '/' ) === dirname( __DIR__ )
) {
$GLOBALS[ $global_var_name ]['version'] = $version; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- It is prefixed.
$GLOBALS[ $global_var_name ]['load'] = $load; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- It is prefixed.
}
}
)(
'image_prioritizer_pending_plugin',
'1.0.0-beta3',
static function ( string $version ): void {
if ( defined( 'IMAGE_PRIORITIZER_VERSION' ) ) {
return;
}
define( 'IMAGE_PRIORITIZER_VERSION', $version );
require_once __DIR__ . '/helper.php';
require_once __DIR__ . '/hooks.php';
}
);