-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Facilitate embedding of Embed Optimizer #1337
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
( | ||
/** | ||
* 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 ] ); | ||
} | ||
}; | ||
|
||
// Load in the Embed Optimizer plugin hooks. | ||
require_once __DIR__ . '/hooks.php'; | ||
// Wait until after the plugins have loaded and the theme has loaded. The after_setup_theme action is used | ||
// because it is the first action that fires once the theme is loaded. | ||
add_action( 'after_setup_theme', $bootstrap, PHP_INT_MIN ); | ||
} | ||
|
||
// 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; | ||
$GLOBALS[ $global_var_name ]['load'] = $load; | ||
} | ||
} | ||
)( | ||
'embed_optimizer_pending_plugin', | ||
'0.1.2', | ||
static function ( string $version ): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block of code is a direct copy of what is in Optimization Detective's load.php
.
962a43b
to
6911c56
Compare
6911c56
to
36604fe
Compare
In line with Optimization Detective and Image Prioritizer, this updates the bootstrap logic for Embed Optimizer so that it can be embedded in a theme or plugin.