settings = $settings; } /** * Check if emergency bypass is requested in URL. * e.g., site.com/?awvb_safe_mode=1 */ public function check_emergency_bypass() { if ( isset( $_GET['awvb_safe_mode'] ) && '1' === sanitize_text_field( wp_unslash( $_GET['awvb_safe_mode'] ) ) ) { self::$emergency_bypass_active = true; } } /** * Is emergency safe mode active for current request? * * @return bool */ public static function is_emergency_active() { return self::$emergency_bypass_active; } /** * Create a new backup snapshot of current settings. * * @param string $label Optional note or label for the snapshot. * @return bool */ public function create_backup( $label = 'Manual Snapshot' ) { $current_settings = $this->settings->get_all(); $backups = get_option( 'awvb_settings_backups', array() ); if ( ! is_array( $backups ) ) { $backups = array(); } $backup_id = (string) time(); $backups[ $backup_id ] = array( 'id' => $backup_id, 'timestamp' => current_time( 'mysql' ), 'label' => sanitize_text_field( $label ), 'settings' => $current_settings, ); // Keep only the newest MAX_BACKUPS snapshots if ( count( $backups ) > self::MAX_BACKUPS ) { $backups = array_slice( $backups, -self::MAX_BACKUPS, self::MAX_BACKUPS, true ); } return update_option( 'awvb_settings_backups', $backups, false ); } /** * Restore settings from a specific backup ID. * * @param string $backup_id Timestamp backup ID. * @return bool|WP_Error */ public function restore_backup( $backup_id ) { $backups = get_option( 'awvb_settings_backups', array() ); if ( empty( $backups[ $backup_id ]['settings'] ) ) { return new WP_Error( 'not_found', esc_html__( 'Selected snapshot was not found.', 'ahtesham-web-vitals-booster' ) ); } $target_settings = $backups[ $backup_id ]['settings']; $success = $this->settings->update( $target_settings ); return $success; } /** * Get all saved backup snapshots. * * @return array */ public function get_backups() { $backups = get_option( 'awvb_settings_backups', array() ); if ( ! is_array( $backups ) ) { return array(); } // Return newest first return array_reverse( $backups, true ); } }