'ids', 'number' => 0, // Skip sites the network admin has taken offline — activation // shouldn't resurrect prodigy_* tables/pages/options for them. 'archived' => 0, 'spam' => 0, 'deleted' => 0, ) ); foreach ( $site_ids as $site_id ) { switch_to_blog( $site_id ); try { activate_prodigy_for_current_site(); } finally { // Prodigy_Request_Maker is a process-lifetime singleton that bakes in // the current site's store key and cache prefix at construction time; // without resetting it here, every site after the first would activate // using the first site's identity. Prodigy_Request_Maker::$instance = null; restore_current_blog(); } } return; } activate_prodigy_for_current_site(); } /** * Runs the same per-site activation as register_activation_hook() for a site * created after this plugin was already network-activated. WordPress does not * refire the activation hook for sites created later, so without this, such a * site would only ever get its prodigy_* DB tables (via the init-time schema * self-heal in Prodigy_Db_Migrations::run()) and never its shop/cart/thank-you * pages, sidebars, or default options. * * @param WP_Site $new_site The newly created site. */ function activate_prodigy_for_new_site( WP_Site $new_site ): void { if ( ! function_exists( 'is_plugin_active_for_network' ) || ! is_plugin_active_for_network( plugin_basename( PRODIGY_PLUGIN_FILE ) ) ) { return; } require_once plugin_dir_path( __FILE__ ) . 'includes/class-prodigy-activator.php'; switch_to_blog( (int) $new_site->blog_id ); try { activate_prodigy_for_current_site(); } finally { Prodigy_Request_Maker::$instance = null; restore_current_blog(); } } /** * Runs the activation routine against whichever site is currently active * (the real site on single-site installs, or the switch_to_blog() target * during a network-wide activation loop). */ function activate_prodigy_for_current_site(): void { $order_model = new Prodigy_Order(); $request_maker = Prodigy_Request_Maker::get_instance(); $cart = new Prodigy_Cart( $request_maker, $order_model, new Cart_Error_Handler() ); $callback_api_listener = new Prodigy_Callback_Api_Listener( $order_model, $request_maker, $cart ); $prodigy_page = new Prodigy_Page( $order_model, $request_maker, $cart, $callback_api_listener ); new Prodigy_Activator( new Prodigy_Options(), $prodigy_page, new Prodigy_Product_Attributes() ); } /** * Get plugin directory name * * @return string */ function get_prodigy_plugin_directory_name(): string { return plugin_basename( __DIR__ ); } /** * The code that runs during plugin deactivation. * This action is documented in includes/class-prodigy-deactivator.php */ function deactivate_prodigy() { require_once plugin_dir_path( __FILE__ ) . 'includes/class-prodigy-deactivator.php'; Prodigy_Deactivator::deactivate(); } register_activation_hook( __FILE__, 'activate_prodigy' ); register_deactivation_hook( __FILE__, 'deactivate_prodigy' ); add_action( 'wp_initialize_site', 'activate_prodigy_for_new_site', 100 ); /** * Begins execution of the plugin. * * Since everything within the plugin is registered via hooks, * then kicking off the plugin from this point in the file does * not affect the page life cycle. * * @since 2.0.0 */ function run_prodigy() { $plugin = new Prodigy\Includes\Prodigy(); $plugin->run(); } run_prodigy();