| @@ -33,16 +33,29 @@ | ||
| 33 | 33 | * @param mixed $default Optional. Default value to return if the option does not exist. |
| 34 | 34 | * @return mixed Value set for the option. |
| 35 | 35 | */ |
| 36 | 36 | public static function get_option( $option, $default = false ) { |
| 37 | + if ( is_multisite() && self::is_ao_active_for_network() ) { | |
| 38 | + static $configuration_per_site = null; | |
| 39 | + if ( null === $configuration_per_site || defined( 'TEST_MULTISITE_FORCE_AO_ON_NETWORK' ) ) { | |
| 40 | + $configuration_per_site = get_network_option( get_main_network_id(), 'autoptimize_enable_site_config', 'on' ); | |
| 41 | + if ( null === $configuration_per_site ) { | |
| 42 | + // Config per site is off, set as empty string to make sure the var it is not null any more so it can be cached. | |
| 43 | + $configuration_per_site = ''; | |
| 44 | + } | |
| 45 | + } | |
| 46 | + } else { | |
| 47 | + // Kind of dummy value as when not on multisite or if AO not network enabled, config is always on site-level. | |
| 48 | + $configuration_per_site = 'on'; | |
| 49 | + } | |
| 50 | + | |
| 37 | 51 | // This is always a network setting, it is on by default to ensure settings are available at site level unless explicitly turned off. |
| 38 | 52 | if ( 'autoptimize_enable_site_config' === $option ) { |
| 39 | - return get_network_option( get_main_network_id(), $option, 'on' ); | |
| 53 | + return $configuration_per_site; | |
| 40 | 54 | } |
| 41 | 55 | |
| 42 | 56 | // If the plugin is network activated and our per site setting is not on, use the network configuration. |
| 43 | - $configuration_per_site = get_network_option( get_main_network_id(), 'autoptimize_enable_site_config', 'on' ); | |
| 44 | - if ( self::is_ao_active_for_network() && ( 'on' !== $configuration_per_site || is_network_admin() ) ) { | |
| 57 | + if ( is_multisite() && self::is_ao_active_for_network() && ( 'on' !== $configuration_per_site || is_network_admin() ) ) { | |
| 45 | 58 | return get_network_option( get_main_network_id(), $option, $default ); |
| 46 | 59 | } |
| 47 | 60 | |
| 48 | 61 | return get_option( $option, $default ); |