Skip to content

Commit

Permalink
Move activation logic to separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
b1ink0 committed Dec 24, 2024
1 parent e7c1001 commit 7e4e057
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
20 changes: 6 additions & 14 deletions plugins/optimization-detective/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ static function ( string $global_var_name, string $version, Closure $load ): voi
* action), so this is why it gets initialized at priority 9.
*/
add_action( 'init', $bootstrap, 9 );

register_activation_hook(
__FILE__,
static function () use ( $bootstrap ): void {
/*
* The activation hook is called before the init action, so the plugin is not loaded yet. This
* means that the plugin must be bootstrapped here to run the activation logic.
*/
$bootstrap();
od_plugin_activation();
}
Expand Down Expand Up @@ -146,18 +151,5 @@ class_alias( OD_URL_Metric_Group_Collection::class, 'OD_URL_Metrics_Group_Collec
* @since n.e.x.t
*/
function od_plugin_activation(): void {
// Add the option if it doesn't exist.
if ( ! (bool) get_option( 'od_rest_api_info' ) ) {
add_option( 'od_rest_api_info', array() );
}
od_schedule_rest_api_health_check();
// Run the check immediately after Optimization Detective is activated.
add_action(
'activated_plugin',
static function ( string $plugin ): void {
if ( 'optimization-detective/load.php' === $plugin ) {
od_optimization_detective_rest_api_test();
}
}
);
od_rest_api_health_check_plugin_activation();
}
22 changes: 22 additions & 0 deletions plugins/optimization-detective/site-health/rest-api/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,25 @@ function od_rest_api_health_check_admin_notice( string $plugin_file ): void {
);
}
}

/**
* Plugin activation hook for the REST API health check.
*
* @since n.e.x.t
*/
function od_rest_api_health_check_plugin_activation(): void {
// Add the option if it doesn't exist.
if ( ! (bool) get_option( 'od_rest_api_info' ) ) {
add_option( 'od_rest_api_info', array() );
}
od_schedule_rest_api_health_check();
// Run the check immediately after Optimization Detective is activated.
add_action(
'activated_plugin',
static function ( string $plugin ): void {
if ( 'optimization-detective/load.php' === $plugin ) {
od_optimization_detective_rest_api_test();
}
}
);
}

0 comments on commit 7e4e057

Please sign in to comment.