client = $client; $this->option_key = $this->client->getHookName( 'update_state' ); } public function all(): array { $value = get_option( $this->option_key, [] ); if ( ! is_array( $value ) ) { $value = []; } return wp_parse_args( $value, [ 'previous_version' => null, 'last_install_at' => null, 'last_install_status' => null, 'last_install_target' => null, 'last_install_is_rollback' => false, 'last_checked_at' => null, 'beta_enabled' => false, 'auto_update_window' => null, ] ); } public function get( string $key, $default = null ) { $all = $this->all(); // all() back-fills every known key via wp_parse_args, so a plain // array_key_exists() made the caller's $default unreachable for exactly // the keys it was written for. Treat "present but never set" (null) as // absent so the default applies. if ( ! array_key_exists( $key, $all ) || null === $all[ $key ] ) { return $default; } return $all[ $key ]; } public function set( array $changes ): void { $current = $this->all(); $next = array_merge( $current, $changes ); update_option( $this->option_key, $next, false ); } public function delete(): void { delete_option( $this->option_key ); } public function record_install( string $target_version, ?string $current_version, string $status, bool $is_rollback ): void { $changes = [ 'last_install_at' => time(), 'last_install_status' => $status, 'last_install_target' => $target_version, 'last_install_is_rollback' => $is_rollback, ]; // On a successful update or rollback, remember where we came from // so the UI can offer a one-click reverse without making the user // pick from the version-history table. if ( 'succeeded' === $status && $current_version && $current_version !== $target_version ) { $changes['previous_version'] = $current_version; } $this->set( $changes ); } public function record_check( int $time = null ): void { $this->set( [ 'last_checked_at' => $time ?: time() ] ); } } // End of file SE_License_SDK_Update_State.php.