Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 91 additions & 41 deletions plugins/optimization-detective/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,102 @@
exit;
}

// Define the constant.
if ( defined( 'OPTIMIZATION_DETECTIVE_VERSION' ) ) {
return;
}
(
/**
* 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 ) {
if ( ! isset( $GLOBALS[ $global_var_name ] ) ) {
$bootstrap = static function () use ( $global_var_name ) {
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 ] );
}
};

if (
( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) &&
! file_exists( __DIR__ . '/build/web-vitals.asset.php' )
) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
trigger_error(
esc_html(
sprintf(
/* translators: 1: File path. 2: CLI command. */
'[Optimization Detective] ' . __( 'Unable to load %1$s. Please make sure you have run %2$s.', 'optimization-detective' ),
'build/web-vitals.asset.php',
'`npm install && npm run build:optimization-detective`'
)
),
E_USER_ERROR
);
}
// 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;
}
}
)(
'optimization_detective_pending_plugin',
'0.1.1',
static function ( string $version ) {

// Define the constant.
if ( defined( 'OPTIMIZATION_DETECTIVE_VERSION' ) ) {
return;
}

if (
( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) &&
! file_exists( __DIR__ . '/build/web-vitals.asset.php' )
) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
trigger_error(
esc_html(
sprintf(
/* translators: 1: File path. 2: CLI command. */
'[Optimization Detective] ' . __( 'Unable to load %1$s. Please make sure you have run %2$s.', 'optimization-detective' ),
'build/web-vitals.asset.php',
'`npm install && npm run build:optimization-detective`'
)
),
E_USER_ERROR
);
}

define( 'OPTIMIZATION_DETECTIVE_VERSION', '0.1.1' );
define( 'OPTIMIZATION_DETECTIVE_VERSION', $version );

require_once __DIR__ . '/helper.php';
require_once __DIR__ . '/helper.php';

// Core infrastructure classes.
require_once __DIR__ . '/class-od-data-validation-exception.php';
require_once __DIR__ . '/class-od-html-tag-processor.php';
require_once __DIR__ . '/class-od-url-metric.php';
require_once __DIR__ . '/class-od-url-metrics-group.php';
require_once __DIR__ . '/class-od-url-metrics-group-collection.php';
// Core infrastructure classes.
require_once __DIR__ . '/class-od-data-validation-exception.php';
require_once __DIR__ . '/class-od-html-tag-processor.php';
require_once __DIR__ . '/class-od-url-metric.php';
require_once __DIR__ . '/class-od-url-metrics-group.php';
require_once __DIR__ . '/class-od-url-metrics-group-collection.php';

// Storage logic.
require_once __DIR__ . '/storage/class-od-url-metrics-post-type.php';
require_once __DIR__ . '/storage/class-od-storage-lock.php';
require_once __DIR__ . '/storage/data.php';
require_once __DIR__ . '/storage/rest-api.php';
// Storage logic.
require_once __DIR__ . '/storage/class-od-url-metrics-post-type.php';
require_once __DIR__ . '/storage/class-od-storage-lock.php';
require_once __DIR__ . '/storage/data.php';
require_once __DIR__ . '/storage/rest-api.php';

// Detection logic.
require_once __DIR__ . '/detection.php';
// Detection logic.
require_once __DIR__ . '/detection.php';

// Optimization logic.
require_once __DIR__ . '/class-od-html-tag-walker.php';
require_once __DIR__ . '/optimization.php';
// Optimization logic.
require_once __DIR__ . '/class-od-html-tag-walker.php';
require_once __DIR__ . '/optimization.php';

// Add hooks for the above requires.
require_once __DIR__ . '/hooks.php';
// Add hooks for the above requires.
require_once __DIR__ . '/hooks.php';
}
);