default_config = $default_config; $this->config_file = $config_file; } /** * Fetches config items from multiple sources, merging them based on precedence. * * @return array */ public function load(): array { $merge_items = []; // This file is the only source available when advanced-cache.php is loaded. if ( file_exists( $this->config_file->get() ) ) { $merge_items[] = require $this->config_file->get(); } // Fetch the network configuration. Note: we currently have no true MS support/settings page etc...this is just for the future. if ( function_exists( 'get_network_option' ) && is_multisite() ) { $merge_items[] = (array) get_network_option( get_main_network_id(), self::OPTION_KEY, [] ); } // Allow local sites to override the network configuration. if ( function_exists( 'get_option' ) ) { $merge_items[] = (array) get_option( self::OPTION_KEY, [] ); } return $this->merge_configs( ...$merge_items ); } /** * Merge configuration items, starting with the default configuration. * * @param array ...$configs The different config sources. * * @return array */ private function merge_configs( array ...$configs ): array { $merged = $this->default_config->get(); foreach ( $configs as $config ) { $merged = Arr::merge_recursive( $merged, $config ); } return $merged; } }