boot(); } return self::$instance; } /** * Activation: create the log table and seed the settings. * * @return void */ public static function activate() { Log::install(); if ( false === get_option( CCLG_OPTION ) ) { add_option( CCLG_OPTION, Settings::defaults(), '', true ); } if ( ! wp_next_scheduled( 'cclg_daily' ) ) { wp_schedule_event( time() + HOUR_IN_SECONDS, 'daily', 'cclg_daily' ); } } /** * Deactivation: stop the scheduled clean-up. Data stays until uninstall. * * @return void */ public static function deactivate() { wp_clear_scheduled_hook( 'cclg_daily' ); } /** * Boots the plugin. * * @return void */ private function boot() { if ( get_option( 'cclg_db_version' ) !== CCLG_DB_VERSION ) { Log::install(); } $this->settings = new Settings(); $ip = new Ip( $this->settings ); $this->limiter = new Limiter( $this->settings, $ip ); $this->limiter->boot(); if ( $this->settings->get( 'recovery_enabled' ) ) { ( new Recovery( $this->settings, $ip, $this->limiter ) )->boot(); } $turnstile = new Turnstile( $this->settings, $ip ); if ( $turnstile->is_configured() ) { $turnstile->boot(); } add_action( 'cclg_daily', array( $this, 'daily' ) ); if ( is_admin() ) { ( new Admin\Admin( $this->settings, $ip, $this->limiter ) )->boot(); } } /** * Daily housekeeping: drop log rows older than the retention period. * * @return void */ public function daily() { Log::prune( (int) $this->settings->get( 'log_days' ) ); } }