Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/content-.../inc/freemius/includes
File: class-fs-storage.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* @package Freemius
[2] Fix | Delete
* @copyright Copyright (c) 2015, Freemius, Inc.
[3] Fix | Delete
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
[4] Fix | Delete
* @since 1.2.3
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[8] Fix | Delete
exit;
[9] Fix | Delete
}
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Class FS_Storage
[13] Fix | Delete
*
[14] Fix | Delete
* A wrapper class for handling network level and single site level storage.
[15] Fix | Delete
*
[16] Fix | Delete
* @property bool $is_network_activation
[17] Fix | Delete
* @property int $network_install_blog_id
[18] Fix | Delete
* @property bool|null $is_extensions_tracking_allowed
[19] Fix | Delete
* @property bool|null $is_diagnostic_tracking_allowed
[20] Fix | Delete
* @property object $sync_cron
[21] Fix | Delete
*/
[22] Fix | Delete
class FS_Storage {
[23] Fix | Delete
/**
[24] Fix | Delete
* @var FS_Storage[]
[25] Fix | Delete
*/
[26] Fix | Delete
private static $_instances = array();
[27] Fix | Delete
/**
[28] Fix | Delete
* @var FS_Key_Value_Storage Site level storage.
[29] Fix | Delete
*/
[30] Fix | Delete
private $_storage;
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* @var FS_Key_Value_Storage Network level storage.
[34] Fix | Delete
*/
[35] Fix | Delete
private $_network_storage;
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* @var string
[39] Fix | Delete
*/
[40] Fix | Delete
private $_module_type;
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* @var string
[44] Fix | Delete
*/
[45] Fix | Delete
private $_module_slug;
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* @var int The ID of the blog that is associated with the current site level options.
[49] Fix | Delete
*/
[50] Fix | Delete
private $_blog_id = 0;
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* @var bool
[54] Fix | Delete
*/
[55] Fix | Delete
private $_is_multisite;
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* @var bool
[59] Fix | Delete
*/
[60] Fix | Delete
private $_is_network_active = false;
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* @var bool
[64] Fix | Delete
*/
[65] Fix | Delete
private $_is_delegated_connection = false;
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* @var array {
[69] Fix | Delete
* @key string Option name.
[70] Fix | Delete
* @value int If 0 store on the network level. If 1, store on the network level only if module was network level activated. If 2, store on the network level only if network activated and NOT delegated the connection.
[71] Fix | Delete
* }
[72] Fix | Delete
*/
[73] Fix | Delete
private static $_NETWORK_OPTIONS_MAP;
[74] Fix | Delete
[75] Fix | Delete
const OPTION_LEVEL_UNDEFINED = -1;
[76] Fix | Delete
// The option should be stored on the network level.
[77] Fix | Delete
const OPTION_LEVEL_NETWORK = 0;
[78] Fix | Delete
// The option should be stored on the network level when the plugin is network-activated.
[79] Fix | Delete
const OPTION_LEVEL_NETWORK_ACTIVATED = 1;
[80] Fix | Delete
// The option should be stored on the network level when the plugin is network-activated and the opt-in connection was NOT delegated to the sub-site admin.
[81] Fix | Delete
const OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED = 2;
[82] Fix | Delete
// The option should be stored on the site level.
[83] Fix | Delete
const OPTION_LEVEL_SITE = 3;
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* @author Leo Fajardo (@leorw)
[87] Fix | Delete
*
[88] Fix | Delete
* @param string $module_type
[89] Fix | Delete
* @param string $slug
[90] Fix | Delete
*
[91] Fix | Delete
* @return FS_Storage
[92] Fix | Delete
*/
[93] Fix | Delete
static function instance( $module_type, $slug ) {
[94] Fix | Delete
$key = $module_type . ':' . $slug;
[95] Fix | Delete
[96] Fix | Delete
if ( ! isset( self::$_instances[ $key ] ) ) {
[97] Fix | Delete
self::$_instances[ $key ] = new FS_Storage( $module_type, $slug );
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
return self::$_instances[ $key ];
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
/**
[104] Fix | Delete
* @author Leo Fajardo (@leorw)
[105] Fix | Delete
*
[106] Fix | Delete
* @param string $module_type
[107] Fix | Delete
* @param string $slug
[108] Fix | Delete
*/
[109] Fix | Delete
private function __construct( $module_type, $slug ) {
[110] Fix | Delete
$this->_module_type = $module_type;
[111] Fix | Delete
$this->_module_slug = $slug;
[112] Fix | Delete
$this->_is_multisite = is_multisite();
[113] Fix | Delete
[114] Fix | Delete
if ( $this->_is_multisite ) {
[115] Fix | Delete
$this->_blog_id = get_current_blog_id();
[116] Fix | Delete
$this->_network_storage = FS_Key_Value_Storage::instance( $module_type . '_data', $slug, true );
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
$this->_storage = FS_Key_Value_Storage::instance( $module_type . '_data', $slug, $this->_blog_id );
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* Tells this storage wrapper class that the context plugin is network active. This flag will affect how values
[124] Fix | Delete
* are retrieved/stored from/into the storage.
[125] Fix | Delete
*
[126] Fix | Delete
* @author Leo Fajardo (@leorw)
[127] Fix | Delete
*
[128] Fix | Delete
* @param bool $is_network_active
[129] Fix | Delete
* @param bool $is_delegated_connection
[130] Fix | Delete
*/
[131] Fix | Delete
function set_network_active( $is_network_active = true, $is_delegated_connection = false ) {
[132] Fix | Delete
$this->_is_network_active = $is_network_active;
[133] Fix | Delete
$this->_is_delegated_connection = $is_delegated_connection;
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
/**
[137] Fix | Delete
* Switch the context of the site level storage manager.
[138] Fix | Delete
*
[139] Fix | Delete
* @author Vova Feldman (@svovaf)
[140] Fix | Delete
* @since 2.0.0
[141] Fix | Delete
*
[142] Fix | Delete
* @param int $blog_id
[143] Fix | Delete
*/
[144] Fix | Delete
function set_site_blog_context( $blog_id ) {
[145] Fix | Delete
$this->_storage = $this->get_site_storage( $blog_id );
[146] Fix | Delete
$this->_blog_id = $blog_id;
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* @author Leo Fajardo (@leorw)
[151] Fix | Delete
*
[152] Fix | Delete
* @param string $key
[153] Fix | Delete
* @param mixed $value
[154] Fix | Delete
* @param null|bool|int $network_level_or_blog_id When an integer, use the given blog storage. When `true` use the multisite storage (if there's a network). When `false`, use the current context blog storage. When `null`, the decision which storage to use (MS vs. Current S) will be handled internally and determined based on the $option (based on self::$_BINARY_MAP).
[155] Fix | Delete
* @param int $option_level Since 2.5.1
[156] Fix | Delete
* @param bool $flush
[157] Fix | Delete
*/
[158] Fix | Delete
function store(
[159] Fix | Delete
$key,
[160] Fix | Delete
$value,
[161] Fix | Delete
$network_level_or_blog_id = null,
[162] Fix | Delete
$option_level = self::OPTION_LEVEL_UNDEFINED,
[163] Fix | Delete
$flush = true
[164] Fix | Delete
) {
[165] Fix | Delete
if ( $this->should_use_network_storage( $key, $network_level_or_blog_id, $option_level ) ) {
[166] Fix | Delete
$this->_network_storage->store( $key, $value, $flush );
[167] Fix | Delete
} else {
[168] Fix | Delete
$storage = $this->get_site_storage( $network_level_or_blog_id );
[169] Fix | Delete
$storage->store( $key, $value, $flush );
[170] Fix | Delete
}
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
/**
[174] Fix | Delete
* @author Leo Fajardo (@leorw)
[175] Fix | Delete
*
[176] Fix | Delete
* @param bool $store
[177] Fix | Delete
* @param string[] $exceptions Set of keys to keep and not clear.
[178] Fix | Delete
* @param int|null|bool $network_level_or_blog_id
[179] Fix | Delete
*/
[180] Fix | Delete
function clear_all( $store = true, $exceptions = array(), $network_level_or_blog_id = null ) {
[181] Fix | Delete
if ( ! $this->_is_multisite ||
[182] Fix | Delete
false === $network_level_or_blog_id ||
[183] Fix | Delete
is_null( $network_level_or_blog_id ) ||
[184] Fix | Delete
is_numeric( $network_level_or_blog_id )
[185] Fix | Delete
) {
[186] Fix | Delete
$storage = $this->get_site_storage( $network_level_or_blog_id );
[187] Fix | Delete
$storage->clear_all( $store, $exceptions );
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
if ( $this->_is_multisite &&
[191] Fix | Delete
( true === $network_level_or_blog_id || is_null( $network_level_or_blog_id ) )
[192] Fix | Delete
) {
[193] Fix | Delete
$this->_network_storage->clear_all( $store, $exceptions );
[194] Fix | Delete
}
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
/**
[198] Fix | Delete
* @author Leo Fajardo (@leorw)
[199] Fix | Delete
*
[200] Fix | Delete
* @param string $key
[201] Fix | Delete
* @param bool $store
[202] Fix | Delete
* @param null|bool|int $network_level_or_blog_id When an integer, use the given blog storage. When `true` use the multisite storage (if there's a network). When `false`, use the current context blog storage. When `null`, the decision which storage to use (MS vs. Current S) will be handled internally and determined based on the $option (based on self::$_BINARY_MAP).
[203] Fix | Delete
*/
[204] Fix | Delete
function remove( $key, $store = true, $network_level_or_blog_id = null ) {
[205] Fix | Delete
if ( $this->should_use_network_storage( $key, $network_level_or_blog_id ) ) {
[206] Fix | Delete
$this->_network_storage->remove( $key, $store );
[207] Fix | Delete
} else {
[208] Fix | Delete
$storage = $this->get_site_storage( $network_level_or_blog_id );
[209] Fix | Delete
$storage->remove( $key, $store );
[210] Fix | Delete
}
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
/**
[214] Fix | Delete
* @author Leo Fajardo (@leorw)
[215] Fix | Delete
*
[216] Fix | Delete
* @param string $key
[217] Fix | Delete
* @param mixed $default
[218] Fix | Delete
* @param null|bool|int $network_level_or_blog_id When an integer, use the given blog storage. When `true` use the multisite storage (if there's a network). When `false`, use the current context blog storage. When `null`, the decision which storage to use (MS vs. Current S) will be handled internally and determined based on the $option (based on self::$_BINARY_MAP).
[219] Fix | Delete
* @param int $option_level Since 2.5.1
[220] Fix | Delete
*
[221] Fix | Delete
* @return mixed
[222] Fix | Delete
*/
[223] Fix | Delete
function get(
[224] Fix | Delete
$key,
[225] Fix | Delete
$default = false,
[226] Fix | Delete
$network_level_or_blog_id = null,
[227] Fix | Delete
$option_level = self::OPTION_LEVEL_UNDEFINED
[228] Fix | Delete
) {
[229] Fix | Delete
if ( $this->should_use_network_storage( $key, $network_level_or_blog_id, $option_level ) ) {
[230] Fix | Delete
return $this->_network_storage->get( $key, $default );
[231] Fix | Delete
} else {
[232] Fix | Delete
$storage = $this->get_site_storage( $network_level_or_blog_id );
[233] Fix | Delete
[234] Fix | Delete
return $storage->get( $key, $default );
[235] Fix | Delete
}
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
/**
[239] Fix | Delete
* Multisite activated:
[240] Fix | Delete
* true: Save network storage.
[241] Fix | Delete
* int: Save site specific storage.
[242] Fix | Delete
* false|0: Save current site storage.
[243] Fix | Delete
* null: Save network and current site storage.
[244] Fix | Delete
* Site level activated:
[245] Fix | Delete
* Save site storage.
[246] Fix | Delete
*
[247] Fix | Delete
* @author Vova Feldman (@svovaf)
[248] Fix | Delete
* @since 2.0.0
[249] Fix | Delete
*
[250] Fix | Delete
* @param bool|int|null $network_level_or_blog_id
[251] Fix | Delete
*/
[252] Fix | Delete
function save( $network_level_or_blog_id = null ) {
[253] Fix | Delete
if ( $this->_is_network_active &&
[254] Fix | Delete
( true === $network_level_or_blog_id || is_null( $network_level_or_blog_id ) )
[255] Fix | Delete
) {
[256] Fix | Delete
$this->_network_storage->save();
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
if ( ! $this->_is_network_active || true !== $network_level_or_blog_id ) {
[260] Fix | Delete
$storage = $this->get_site_storage( $network_level_or_blog_id );
[261] Fix | Delete
$storage->save();
[262] Fix | Delete
}
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
/**
[266] Fix | Delete
* @author Vova Feldman (@svovaf)
[267] Fix | Delete
* @since 2.0.0
[268] Fix | Delete
*
[269] Fix | Delete
* @return string
[270] Fix | Delete
*/
[271] Fix | Delete
function get_module_slug() {
[272] Fix | Delete
return $this->_module_slug;
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
/**
[276] Fix | Delete
* @author Vova Feldman (@svovaf)
[277] Fix | Delete
* @since 2.0.0
[278] Fix | Delete
*
[279] Fix | Delete
* @return string
[280] Fix | Delete
*/
[281] Fix | Delete
function get_module_type() {
[282] Fix | Delete
return $this->_module_type;
[283] Fix | Delete
}
[284] Fix | Delete
[285] Fix | Delete
/**
[286] Fix | Delete
* Migration script to the new storage data structure that is network compatible.
[287] Fix | Delete
*
[288] Fix | Delete
* IMPORTANT:
[289] Fix | Delete
* This method should be executed only after it is determined if this is a network
[290] Fix | Delete
* level compatible product activation.
[291] Fix | Delete
*
[292] Fix | Delete
* @author Vova Feldman (@svovaf)
[293] Fix | Delete
* @since 2.0.0
[294] Fix | Delete
*/
[295] Fix | Delete
function migrate_to_network() {
[296] Fix | Delete
if ( ! $this->_is_multisite ) {
[297] Fix | Delete
return;
[298] Fix | Delete
}
[299] Fix | Delete
[300] Fix | Delete
$updated = false;
[301] Fix | Delete
[302] Fix | Delete
if ( ! isset( self::$_NETWORK_OPTIONS_MAP ) ) {
[303] Fix | Delete
self::load_network_options_map();
[304] Fix | Delete
}
[305] Fix | Delete
[306] Fix | Delete
foreach ( self::$_NETWORK_OPTIONS_MAP as $option => $storage_level ) {
[307] Fix | Delete
if ( ! $this->is_multisite_option( $option ) ) {
[308] Fix | Delete
continue;
[309] Fix | Delete
}
[310] Fix | Delete
[311] Fix | Delete
if ( isset( $this->_storage->{$option} ) && ! isset( $this->_network_storage->{$option} ) ) {
[312] Fix | Delete
// Migrate option to the network storage.
[313] Fix | Delete
$this->_network_storage->store( $option, $this->_storage->{$option}, false );
[314] Fix | Delete
[315] Fix | Delete
$updated = true;
[316] Fix | Delete
}
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
if ( ! $updated ) {
[320] Fix | Delete
return;
[321] Fix | Delete
}
[322] Fix | Delete
[323] Fix | Delete
// Update network level storage.
[324] Fix | Delete
$this->_network_storage->save();
[325] Fix | Delete
// $this->_storage->save();
[326] Fix | Delete
}
[327] Fix | Delete
[328] Fix | Delete
#--------------------------------------------------------------------------------
[329] Fix | Delete
#region Helper Methods
[330] Fix | Delete
#--------------------------------------------------------------------------------
[331] Fix | Delete
[332] Fix | Delete
/**
[333] Fix | Delete
* We don't want to load the map right away since it's not even needed in a non-MS environment.
[334] Fix | Delete
*
[335] Fix | Delete
* Example:
[336] Fix | Delete
* array(
[337] Fix | Delete
* 'option1' => 0, // Means that the option should always be stored on the network level.
[338] Fix | Delete
* 'option2' => 1, // Means that the option should be stored on the network level only when the module was network level activated.
[339] Fix | Delete
* 'option2' => 2, // Means that the option should be stored on the network level only when the module was network level activated AND the connection was NOT delegated.
[340] Fix | Delete
* 'option3' => 3, // Means that the option should always be stored on the site level.
[341] Fix | Delete
* )
[342] Fix | Delete
*
[343] Fix | Delete
* @author Vova Feldman (@svovaf)
[344] Fix | Delete
* @since 2.0.0
[345] Fix | Delete
*/
[346] Fix | Delete
private static function load_network_options_map() {
[347] Fix | Delete
self::$_NETWORK_OPTIONS_MAP = array(
[348] Fix | Delete
// Network level options.
[349] Fix | Delete
'affiliate_application_data' => self::OPTION_LEVEL_NETWORK,
[350] Fix | Delete
'beta_data' => self::OPTION_LEVEL_NETWORK,
[351] Fix | Delete
'connectivity_test' => self::OPTION_LEVEL_NETWORK,
[352] Fix | Delete
'handle_gdpr_admin_notice' => self::OPTION_LEVEL_NETWORK,
[353] Fix | Delete
'has_trial_plan' => self::OPTION_LEVEL_NETWORK,
[354] Fix | Delete
'install_sync_timestamp' => self::OPTION_LEVEL_NETWORK,
[355] Fix | Delete
'install_sync_cron' => self::OPTION_LEVEL_NETWORK,
[356] Fix | Delete
'is_anonymous_ms' => self::OPTION_LEVEL_NETWORK,
[357] Fix | Delete
'is_network_activated' => self::OPTION_LEVEL_NETWORK,
[358] Fix | Delete
'is_on' => self::OPTION_LEVEL_NETWORK,
[359] Fix | Delete
'is_plugin_new_install' => self::OPTION_LEVEL_NETWORK,
[360] Fix | Delete
'last_load_timestamp' => self::OPTION_LEVEL_NETWORK,
[361] Fix | Delete
'network_install_blog_id' => self::OPTION_LEVEL_NETWORK,
[362] Fix | Delete
'pending_sites_info' => self::OPTION_LEVEL_NETWORK,
[363] Fix | Delete
'plugin_last_version' => self::OPTION_LEVEL_NETWORK,
[364] Fix | Delete
'plugin_main_file' => self::OPTION_LEVEL_NETWORK,
[365] Fix | Delete
'plugin_version' => self::OPTION_LEVEL_NETWORK,
[366] Fix | Delete
'sdk_downgrade_mode' => self::OPTION_LEVEL_NETWORK,
[367] Fix | Delete
'sdk_last_version' => self::OPTION_LEVEL_NETWORK,
[368] Fix | Delete
'sdk_upgrade_mode' => self::OPTION_LEVEL_NETWORK,
[369] Fix | Delete
'sdk_version' => self::OPTION_LEVEL_NETWORK,
[370] Fix | Delete
'sticky_optin_added_ms' => self::OPTION_LEVEL_NETWORK,
[371] Fix | Delete
'subscriptions' => self::OPTION_LEVEL_NETWORK,
[372] Fix | Delete
'sync_timestamp' => self::OPTION_LEVEL_NETWORK,
[373] Fix | Delete
'sync_cron' => self::OPTION_LEVEL_NETWORK,
[374] Fix | Delete
'was_plugin_loaded' => self::OPTION_LEVEL_NETWORK,
[375] Fix | Delete
'network_user_id' => self::OPTION_LEVEL_NETWORK,
[376] Fix | Delete
'plugin_upgrade_mode' => self::OPTION_LEVEL_NETWORK,
[377] Fix | Delete
'plugin_downgrade_mode' => self::OPTION_LEVEL_NETWORK,
[378] Fix | Delete
'is_network_connected' => self::OPTION_LEVEL_NETWORK,
[379] Fix | Delete
/**
[380] Fix | Delete
* Special flag that is used when a super-admin upgrades to the new version of the SDK that supports network level integration, when the connection decision wasn't made for all the sites in the network.
[381] Fix | Delete
*/
[382] Fix | Delete
'is_network_activation' => self::OPTION_LEVEL_NETWORK,
[383] Fix | Delete
'license_migration' => self::OPTION_LEVEL_NETWORK,
[384] Fix | Delete
[385] Fix | Delete
// When network activated, then network level.
[386] Fix | Delete
'install_timestamp' => self::OPTION_LEVEL_NETWORK_ACTIVATED,
[387] Fix | Delete
'prev_is_premium' => self::OPTION_LEVEL_NETWORK_ACTIVATED,
[388] Fix | Delete
'require_license_activation' => self::OPTION_LEVEL_NETWORK_ACTIVATED,
[389] Fix | Delete
[390] Fix | Delete
// If not network activated OR delegated, then site level.
[391] Fix | Delete
'activation_timestamp' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
[392] Fix | Delete
'expired_license_notice_shown' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
[393] Fix | Delete
'is_whitelabeled' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
[394] Fix | Delete
'last_license_key' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
[395] Fix | Delete
'last_license_user_id' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
[396] Fix | Delete
'prev_user_id' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
[397] Fix | Delete
'sticky_optin_added' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
[398] Fix | Delete
'uninstall_reason' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
[399] Fix | Delete
'is_pending_activation' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
[400] Fix | Delete
'pending_license_key' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
[401] Fix | Delete
[402] Fix | Delete
// Site level options.
[403] Fix | Delete
'is_anonymous' => self::OPTION_LEVEL_SITE,
[404] Fix | Delete
'clone_id' => self::OPTION_LEVEL_SITE,
[405] Fix | Delete
);
[406] Fix | Delete
}
[407] Fix | Delete
[408] Fix | Delete
/**
[409] Fix | Delete
* This method will and should only be executed when is_multisite() is true.
[410] Fix | Delete
*
[411] Fix | Delete
* @author Vova Feldman (@svovaf)
[412] Fix | Delete
* @since 2.0.0
[413] Fix | Delete
*
[414] Fix | Delete
* @param string $key
[415] Fix | Delete
* @param int $option_level Since 2.5.1
[416] Fix | Delete
*
[417] Fix | Delete
* @return bool
[418] Fix | Delete
*/
[419] Fix | Delete
private function is_multisite_option( $key, $option_level = self::OPTION_LEVEL_UNDEFINED ) {
[420] Fix | Delete
if ( ! isset( self::$_NETWORK_OPTIONS_MAP ) ) {
[421] Fix | Delete
self::load_network_options_map();
[422] Fix | Delete
}
[423] Fix | Delete
[424] Fix | Delete
if (
[425] Fix | Delete
self::OPTION_LEVEL_UNDEFINED === $option_level &&
[426] Fix | Delete
isset( self::$_NETWORK_OPTIONS_MAP[ $key ] )
[427] Fix | Delete
) {
[428] Fix | Delete
$option_level = self::$_NETWORK_OPTIONS_MAP[ $key ];
[429] Fix | Delete
}
[430] Fix | Delete
[431] Fix | Delete
if ( self::OPTION_LEVEL_UNDEFINED === $option_level ) {
[432] Fix | Delete
// Option not found -> use site level storage.
[433] Fix | Delete
return false;
[434] Fix | Delete
}
[435] Fix | Delete
[436] Fix | Delete
if ( self::OPTION_LEVEL_NETWORK === $option_level ) {
[437] Fix | Delete
// Option found and set to always use the network level storage on a multisite.
[438] Fix | Delete
return true;
[439] Fix | Delete
}
[440] Fix | Delete
[441] Fix | Delete
if ( self::OPTION_LEVEL_SITE === $option_level ) {
[442] Fix | Delete
// Option found and set to always use the site level storage on a multisite.
[443] Fix | Delete
return false;
[444] Fix | Delete
}
[445] Fix | Delete
[446] Fix | Delete
if ( ! $this->_is_network_active ) {
[447] Fix | Delete
return false;
[448] Fix | Delete
}
[449] Fix | Delete
[450] Fix | Delete
if ( self::OPTION_LEVEL_NETWORK_ACTIVATED === $option_level ) {
[451] Fix | Delete
// Network activated.
[452] Fix | Delete
return true;
[453] Fix | Delete
}
[454] Fix | Delete
[455] Fix | Delete
if (
[456] Fix | Delete
self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED === $option_level &&
[457] Fix | Delete
! $this->_is_delegated_connection
[458] Fix | Delete
) {
[459] Fix | Delete
// Network activated and not delegated.
[460] Fix | Delete
return true;
[461] Fix | Delete
}
[462] Fix | Delete
[463] Fix | Delete
return false;
[464] Fix | Delete
}
[465] Fix | Delete
[466] Fix | Delete
/**
[467] Fix | Delete
* @author Leo Fajardo
[468] Fix | Delete
*
[469] Fix | Delete
* @param string $key
[470] Fix | Delete
* @param null|bool|int $network_level_or_blog_id When an integer, use the given blog storage. When `true` use the multisite storage (if there's a network). When `false`, use the current context blog storage. When `null`, the decision which storage to use (MS vs. Current S) will be handled internally and determined based on the $option (based on self::$_BINARY_MAP).
[471] Fix | Delete
* @param int $option_level Since 2.5.1
[472] Fix | Delete
*
[473] Fix | Delete
* @return bool
[474] Fix | Delete
*/
[475] Fix | Delete
private function should_use_network_storage(
[476] Fix | Delete
$key,
[477] Fix | Delete
$network_level_or_blog_id = null,
[478] Fix | Delete
$option_level = self::OPTION_LEVEL_UNDEFINED
[479] Fix | Delete
) {
[480] Fix | Delete
if ( ! $this->_is_multisite ) {
[481] Fix | Delete
// Not a multisite environment.
[482] Fix | Delete
return false;
[483] Fix | Delete
}
[484] Fix | Delete
[485] Fix | Delete
if ( is_numeric( $network_level_or_blog_id ) ) {
[486] Fix | Delete
// Explicitly asked to use a specified blog storage.
[487] Fix | Delete
return false;
[488] Fix | Delete
}
[489] Fix | Delete
[490] Fix | Delete
if ( is_bool( $network_level_or_blog_id ) ) {
[491] Fix | Delete
// Explicitly specified whether it should use the network or blog level storage.
[492] Fix | Delete
return $network_level_or_blog_id;
[493] Fix | Delete
}
[494] Fix | Delete
[495] Fix | Delete
// Determine which storage to use based on the option.
[496] Fix | Delete
return $this->is_multisite_option( $key, $option_level );
[497] Fix | Delete
}
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function