$version, 'bundle' => $bundle, 'snapshot_at' => time(), ) ); $history = array_slice( $history, 0, self::MAX_ENTRIES ); update_option( 'aeo_connect_history', $history, false ); } /** * Return the snapshot history (newest first). * * @return array[] */ public static function get_history() { $history = get_option( 'aeo_connect_history', array() ); return is_array( $history ) ? array_values( $history ) : array(); } /** * Restore a history entry: set it back as the current bundle/version. * * Note: the next sync may re-apply the latest version published on * everlange.com (the SaaS stays the source of truth). * * @param int $index Zero-based history index (0 = most recent snapshot). * @return true|WP_Error */ public static function restore( $index ) { $index = (int) $index; $history = self::get_history(); if ( ! isset( $history[ $index ] ) || ! is_array( $history[ $index ] ) ) { return new WP_Error( 'aeo_connect_no_snapshot', __( 'The requested snapshot no longer exists.', 'aeo-tool-connect' ) ); } $entry = $history[ $index ]; if ( empty( $entry['bundle'] ) || ! is_array( $entry['bundle'] ) || empty( $entry['version'] ) ) { return new WP_Error( 'aeo_connect_bad_snapshot', __( 'The requested snapshot is corrupted.', 'aeo-tool-connect' ) ); } update_option( 'aeo_connect_bundle', $entry['bundle'], false ); update_option( 'aeo_connect_version', (int) $entry['version'], false ); return true; } }