*/ private $active = array(); /** * Returns the singleton. * * @return Plugin */ public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); self::$instance->boot(); } return self::$instance; } /** * Activation: seed defaults once so the option autoloads from the first request. * * @return void */ public static function activate() { if ( false === get_option( CCTWEAKS_OPTION ) ) { add_option( CCTWEAKS_OPTION, Registry::defaults(), '', true ); } } /** * Boots the plugin. * * @return void */ private function boot() { $this->registry = new Registry(); $this->settings = new Settings( $this->registry ); // Only instantiate tweaks that are switched on: zero cost for everything else. foreach ( $this->registry->map() as $id => $def ) { if ( ! $this->settings->is_enabled( $id ) ) { continue; } $class = $def['class']; if ( class_exists( $class ) ) { $tweak = new $class( $id, $this->settings ); $tweak->boot(); $this->active[ $id ] = $tweak; } } if ( is_admin() ) { ( new Admin\Admin( $this->registry, $this->settings ) )->boot(); } } /** * Returns ids of active tweaks. * * @return string[] */ public function active_ids() { return array_keys( $this->active ); } }