HEX
Server: nginx
System: Linux pool195-106-36.bur.atomicsites.net 6.12.57+deb12-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.57-1~bpo12+1 (2025-11-17) x86_64
User: (0)
PHP: 8.3.32
Disabled: pcntl_fork
Upload Files
File: /wordpress/plugins/wp-cloud-client/1.1.6/src/Settings/NetworkSettingsRepository.php
<?php

declare(strict_types=1);

namespace VPlugins\WPCloudClient\Settings;

/**
 * Stores and retrieves network-wide settings from wp_sitemeta (site options).
 *
 * This is the multisite counterpart to SettingsRepository. Per-site credentials
 * (site_id, api_key) live in wp_options via SettingsRepository. Network-wide
 * policy defaults (environment) live here in wp_sitemeta.
 */
class NetworkSettingsRepository {

	/**
	 * The site option key used to store network settings.
	 */
	private const OPTION_KEY = 'wpcc_network_settings';

	/**
	 * Retrieve the default environment for new sub-sites.
	 *
	 * @return string Environment value ('PROD' or 'DEMO').
	 */
	public function getDefaultEnvironment(): string {
		return (string) ( $this->get( 'default_environment' ) ?? 'PROD' );
	}

	/**
	 * Update network settings by merging new values with existing ones.
	 *
	 * @param array<string, mixed> $values Key-value pairs to merge.
	 * @return bool True on success.
	 */
	public function update( array $values ): bool {
		$current = $this->all();
		$merged  = array_merge( $current, $values );

		return update_site_option( self::OPTION_KEY, $merged );
	}

	/**
	 * Retrieve all network settings as an array.
	 *
	 * @return array<string, mixed>
	 */
	public function all(): array {
		$value = get_site_option( self::OPTION_KEY, [] );

		return is_array( $value ) ? $value : [];
	}

	/**
	 * Delete the network settings option from wp_sitemeta.
	 *
	 * @return void
	 */
	public function delete(): void {
		delete_site_option( self::OPTION_KEY );
	}

	/**
	 * Retrieve a single network setting value by key.
	 *
	 * @param string $key Setting key.
	 * @return mixed|null
	 */
	private function get( string $key ): mixed {
		return $this->all()[ $key ] ?? null;
	}
}