array( get_current_user_id() ) ) ); } set_transient( Admin\Onboarding::REDIRECT, 1, MINUTE_IN_SECONDS ); Environment::remember_production_url_if_unset(); self::ensure_schedule(); // The first snapshot is the baseline: later snapshots are diffed against it. if ( ! Inventory::get_stored() ) { $baseline = Inventory::capture(); // WordPress marks the plugin active only after this hook runs. $self = plugin_basename( MAINTAINED_LOG_FILE ); if ( isset( $baseline['plugins'][ $self ] ) ) { $baseline['plugins'][ $self ]['active'] = true; } Inventory::store( $baseline ); Log::add( array( 'type' => Log::TYPE_SYSTEM, 'title' => __( 'Maintained.log activated: baseline inventory recorded', 'maintained-log' ), 'source' => Log::SOURCE_SYSTEM, ) ); } } /** * Deactivation hook. Data is kept; see uninstall.php. */ public static function deactivate() { wp_clear_scheduled_hook( Plugin::CRON_HOOK ); wp_clear_scheduled_hook( Plugin::POST_UPDATE_HOOK ); wp_clear_scheduled_hook( Performance::TICK_HOOK ); wp_clear_scheduled_hook( Vulnerabilities::TICK_HOOK ); } /** * Schedules the twice-daily job if it is missing: it is created on * activation, but files copied over FTP, migrations or cron cleanup * tools can leave the plugin active without it. */ public static function ensure_schedule() { if ( ! wp_next_scheduled( Plugin::CRON_HOOK ) ) { wp_schedule_event( time() + HOUR_IN_SECONDS, 'twicedaily', Plugin::CRON_HOOK ); } } /** * Upgrades the schema when the plugin is updated without reactivation. */ public static function maybe_upgrade() { if ( get_option( self::DB_VERSION_OPTION ) !== self::DB_VERSION ) { self::create_tables(); update_option( self::DB_VERSION_OPTION, self::DB_VERSION, false ); } } /** * Creates or updates the log table with dbDelta. */ private static function create_tables() { global $wpdb; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $table = Log::table(); $charset = $wpdb->get_charset_collate(); dbDelta( "CREATE TABLE {$table} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, created_at datetime NOT NULL, type varchar(20) NOT NULL, category varchar(40) NOT NULL DEFAULT '', status varchar(20) NOT NULL DEFAULT 'info', title text NOT NULL, details longtext NULL, user_id bigint(20) unsigned NOT NULL DEFAULT 0, source varchar(20) NOT NULL DEFAULT '', minutes int(10) unsigned NOT NULL DEFAULT 0, amends_id bigint(20) unsigned NOT NULL DEFAULT 0, hash char(64) NOT NULL DEFAULT '', PRIMARY KEY (id), KEY created_at (created_at), KEY type (type) ) {$charset};" ); } }