callbacks as $priority => $callbacks ) { foreach ( $callbacks as $callback ) { $fn = $callback['function']; if ( is_array( $fn ) && is_object( $fn[0] ) && $fn[0] instanceof ActionScheduler_QueueRunner && 'maybe_dispatch_async_request' === $fn[1] ) { remove_action( 'shutdown', $fn, $priority ); } } } } add_action( 'shutdown', 'feednetic_guard_action_scheduler_shutdown', 9 ); /** * Runs migrations for a single site. Extracted so both the activation hook * and the wp_initialize_site hook can call the same logic. * * @return void */ function feednetic_run_migration(): void { ( new Feednetic\Database\Migrator() )->run(); } /* * Activation hook: runs on first activation (single-site) or network-activation. * * Callback arguments that come from WordPress are never type-declared: core * passes whatever it has (WP 6.6 passes null for $network_wide when WP-CLI * activates the plugin), so they are accepted raw and cast here. * * On plugin updates the activation hook does NOT fire; migrations are handled * instead by Plugin::boot() on every plugins_loaded request (version-gated, * so the check is cheap after the first run). */ register_activation_hook( __FILE__, static function ( $network_wide = false ): void { $network_wide = ! empty( $network_wide ); if ( $network_wide && is_multisite() ) { // Network activation: migrate every existing site now. $site_args = [ 'fields' => 'ids', 'number' => 0, ]; foreach ( get_sites( $site_args ) as $site_id ) { switch_to_blog( (int) $site_id ); feednetic_run_migration(); restore_current_blog(); } } else { feednetic_run_migration(); } } ); /* * New-site hook (multisite only): runs migrations when a new site joins the network * while the plugin is already network-activated. */ add_action( 'wp_initialize_site', static function ( $new_site ): void { if ( ! $new_site instanceof \WP_Site ) { return; } if ( ! function_exists( 'is_plugin_active_for_network' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } if ( is_plugin_active_for_network( plugin_basename( FEEDNETIC_FILE ) ) ) { switch_to_blog( (int) $new_site->blog_id ); feednetic_run_migration(); restore_current_blog(); } } ); /* * Main boot: runs on every request. Plugin::boot() calls Migrator::run() which * checks feednetic_db_version (a cached option) and is a no-op once up to date. * This handles plugin updates, which never trigger the activation hook. */ add_action( 'plugins_loaded', static function (): void { Feednetic\Plugin::getInstance()->boot(); } );