'CloneMute Staging Safety for WooCommerce', 'php' => '7.4', 'wp' => '7.0', 'woo_required' => false, ); } /** * Product descriptor for the library (built once). * * @return ProductDescriptor */ public static function descriptor(): ProductDescriptor { if ( null === self::$descriptor ) { $d = new ProductDescriptor( array( 'id' => 'clonemute', 'name' => 'CloneMute', 'prefix' => 'clonemute_', 'slug' => Pages::SETTINGS, 'textDomain' => 'clonemute', 'file' => self::$file, 'version' => self::VERSION, 'capability' => 'manage_options', 'modules' => array( 'settings', 'log', 'compat', 'lifecycle' ), 'uninstallDefault' => 'delete', 'uninstallKey' => 'uninstall_delete', 'uninstall' => array( 'cron' => array( 'clonemute_core_log_cleanup' ), ), 'logPolicy' => LogConfig::policy(), 'logPage' => false, 'menuItems' => Pages::menuItems(), 'healthTests' => SiteHealthTests::tests(), 'requirements' => self::requirements(), 'compat' => array( 'hpos' => true, 'blocks' => true, ), 'appSchema' => 1, 'migrations' => array( 1 => static function () { SettingsRepo::ensureExists(); }, ), ) ); $d->settings = SettingsPage::declaration( LogMaintenance::retentionImpact( $d ), LogMaintenance::capImpact( $d ), Caps::stateCapability() ); self::$descriptor = $d; } return self::$descriptor; } /** * Activation: tables, cron, defaults and the silent baseline. * * @param bool $network_wide Network activation. * @return void */ public static function activate( bool $network_wide ): void { Bootstrap::activate( self::descriptor(), $network_wide ); SettingsRepo::ensureExists(); } /** * Deactivation: the library clears its schedule (on every site for a network deactivation); no hook of this plugin is * loaded afterwards. * * @param bool $network_wide Network deactivation. * @return void */ public static function deactivate( bool $network_wide = false ): void { Bootstrap::deactivate( self::descriptor(), $network_wide ); } /** * Request-time decision (plugins_loaded, priority 10). * * Unarmed site: one autoloaded option read, one filter, return. Armed site: capture the snapshot (no query), compute * the effective state and register the guards only when it is active. * * @return void */ public static function boot(): void { try { $s = SettingsRepo::load(); add_filter( self::HOOK_ENV_STATE, array( self::class, 'envState' ) ); AdminBar::register(); SettingsRepo::register(); if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { self::registerAdmin(); } if ( 'armed' !== $s->state && ! Constants::armRequested() ) { return; } $snap = EnvCapture::capture( $s, false ); if ( Constants::armRequested() ) { $t = StateMachine::armFromConstant( $s, $snap, time() ); if ( $t->ok && $t->changes ) { $from = StateMachine::fromLabel( $s, $snap ); SettingsRepo::apply( $t->changes ); $s = SettingsRepo::load(); add_action( 'init', static function () use ( $from ) { LogWriter::event( 'state_change', 'state', $from . ' -> armed (CLONEMUTE_ENV)', array( 'to' => 'armed' ) ); }, 20 ); } } $eff = Guard::effective( $s, $snap ); if ( $eff->active ) { Guard::register( $s, $eff ); } } catch ( \Throwable $e ) { Runtime::noteError( 'boot', get_class( $e ) ); } } /** * Admin-only hooks. * * @return void */ private static function registerAdmin(): void { AdminActions::register(); Notices::register(); add_action( 'admin_init', array( SettingsRepo::class, 'ensureExists' ) ); } /** * Filter rotosix_env_state: {state, since}. "armed" only while the guards really are on. * * @param mixed $state Value so far (null when no provider). * @return mixed */ public static function envState( $state ) { unset( $state ); try { $s = SettingsRepo::load(); $snap = EnvCapture::capture( $s, false ); $eff = Guard::effective( $s, $snap ); return Effective::exposed( $s, $snap, $eff ); } catch ( \Throwable $e ) { return array( 'state' => 'unconfirmed', 'since' => 0, ); } } }