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-options.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_Options
[13] Fix | Delete
*
[14] Fix | Delete
* A wrapper class for handling network level and single site level options.
[15] Fix | Delete
*/
[16] Fix | Delete
class FS_Options {
[17] Fix | Delete
/**
[18] Fix | Delete
* @var string
[19] Fix | Delete
*/
[20] Fix | Delete
private $_id;
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* @var array[string]FS_Options {
[24] Fix | Delete
* @key string
[25] Fix | Delete
* @value FS_Options
[26] Fix | Delete
* }
[27] Fix | Delete
*/
[28] Fix | Delete
private static $_instances;
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* @var FS_Option_Manager Site level options.
[32] Fix | Delete
*/
[33] Fix | Delete
private $_options;
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* @var FS_Option_Manager Network level options.
[37] Fix | Delete
*/
[38] Fix | Delete
private $_network_options;
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* @var int The ID of the blog that is associated with the current site level options.
[42] Fix | Delete
*/
[43] Fix | Delete
private $_blog_id = 0;
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* @var bool
[47] Fix | Delete
*/
[48] Fix | Delete
private $_is_multisite;
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* @var string[] Lazy collection of params on the site level.
[52] Fix | Delete
*/
[53] Fix | Delete
private static $_SITE_OPTIONS_MAP;
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* @author Leo Fajardo (@leorw)
[57] Fix | Delete
* @since 2.0.0
[58] Fix | Delete
*
[59] Fix | Delete
* @param string $id
[60] Fix | Delete
* @param bool $load
[61] Fix | Delete
*
[62] Fix | Delete
* @return FS_Options
[63] Fix | Delete
*/
[64] Fix | Delete
static function instance( $id, $load = false ) {
[65] Fix | Delete
if ( ! isset( self::$_instances[ $id ] ) ) {
[66] Fix | Delete
self::$_instances[ $id ] = new FS_Options( $id, $load );
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
return self::$_instances[ $id ];
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
/**
[73] Fix | Delete
* @author Leo Fajardo (@leorw)
[74] Fix | Delete
* @since 2.0.0
[75] Fix | Delete
*
[76] Fix | Delete
* @param string $id
[77] Fix | Delete
* @param bool $load
[78] Fix | Delete
*/
[79] Fix | Delete
private function __construct( $id, $load = false ) {
[80] Fix | Delete
$this->_id = $id;
[81] Fix | Delete
$this->_is_multisite = is_multisite();
[82] Fix | Delete
[83] Fix | Delete
if ( $this->_is_multisite ) {
[84] Fix | Delete
$this->_blog_id = get_current_blog_id();
[85] Fix | Delete
$this->_network_options = FS_Option_Manager::get_manager( $id, $load, true );
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
$this->_options = FS_Option_Manager::get_manager( $id, $load, $this->_blog_id );
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Switch the context of the site level options manager.
[93] Fix | Delete
*
[94] Fix | Delete
* @author Vova Feldman (@svovaf)
[95] Fix | Delete
* @since 2.0.0
[96] Fix | Delete
*
[97] Fix | Delete
* @param $blog_id
[98] Fix | Delete
*/
[99] Fix | Delete
function set_site_blog_context( $blog_id ) {
[100] Fix | Delete
$this->_blog_id = $blog_id;
[101] Fix | Delete
[102] Fix | Delete
$this->_options = FS_Option_Manager::get_manager( $this->_id, false, $this->_blog_id );
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
/**
[106] Fix | Delete
* @author Leo Fajardo (@leorw)
[107] Fix | Delete
*
[108] Fix | Delete
* @param string $option
[109] Fix | Delete
* @param mixed $default
[110] 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::$_SITE_LEVEL_PARAMS).
[111] Fix | Delete
*
[112] Fix | Delete
* @return mixed
[113] Fix | Delete
*/
[114] Fix | Delete
function get_option( $option, $default = null, $network_level_or_blog_id = null ) {
[115] Fix | Delete
if ( $this->should_use_network_storage( $option, $network_level_or_blog_id ) ) {
[116] Fix | Delete
return $this->_network_options->get_option( $option, $default );
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
$site_options = $this->get_site_options( $network_level_or_blog_id );
[120] Fix | Delete
[121] Fix | Delete
return $site_options->get_option( $option, $default );
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
/**
[125] Fix | Delete
* @author Leo Fajardo (@leorw)
[126] Fix | Delete
* @since 2.0.0
[127] Fix | Delete
*
[128] Fix | Delete
* @param string $option
[129] Fix | Delete
* @param mixed $value
[130] Fix | Delete
* @param bool $flush
[131] 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::$_SITE_LEVEL_PARAMS).
[132] Fix | Delete
*/
[133] Fix | Delete
function set_option( $option, $value, $flush = false, $network_level_or_blog_id = null ) {
[134] Fix | Delete
if ( $this->should_use_network_storage( $option, $network_level_or_blog_id ) ) {
[135] Fix | Delete
$this->_network_options->set_option( $option, $value, $flush );
[136] Fix | Delete
} else {
[137] Fix | Delete
$site_options = $this->get_site_options( $network_level_or_blog_id );
[138] Fix | Delete
$site_options->set_option( $option, $value, $flush );
[139] Fix | Delete
}
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
/**
[143] Fix | Delete
* @author Vova Feldman (@svovaf)
[144] Fix | Delete
* @since 2.0.0
[145] Fix | Delete
*
[146] Fix | Delete
* @param string $option
[147] Fix | Delete
* @param bool $flush
[148] 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::$_SITE_LEVEL_PARAMS).
[149] Fix | Delete
*/
[150] Fix | Delete
function unset_option( $option, $flush = false, $network_level_or_blog_id = null ) {
[151] Fix | Delete
if ( $this->should_use_network_storage( $option, $network_level_or_blog_id ) ) {
[152] Fix | Delete
$this->_network_options->unset_option( $option, $flush );
[153] Fix | Delete
} else {
[154] Fix | Delete
$site_options = $this->get_site_options( $network_level_or_blog_id );
[155] Fix | Delete
$site_options->unset_option( $option, $flush );
[156] Fix | Delete
}
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
/**
[160] Fix | Delete
* @author Leo Fajardo (@leorw)
[161] Fix | Delete
* @since 2.0.0
[162] Fix | Delete
*
[163] Fix | Delete
* @param bool $flush
[164] Fix | Delete
* @param bool $network_level
[165] Fix | Delete
*/
[166] Fix | Delete
function load( $flush = false, $network_level = true ) {
[167] Fix | Delete
if ( $this->_is_multisite && $network_level ) {
[168] Fix | Delete
$this->_network_options->load( $flush );
[169] Fix | Delete
} else {
[170] Fix | Delete
$this->_options->load( $flush );
[171] Fix | Delete
}
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
/**
[175] Fix | Delete
* @author Leo Fajardo (@leorw)
[176] Fix | Delete
* @since 2.0.0
[177] Fix | Delete
*
[178] 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`, store both network storage and the current context blog storage.
[179] Fix | Delete
*/
[180] Fix | Delete
function store( $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
0 == $network_level_or_blog_id ||
[184] Fix | Delete
is_null( $network_level_or_blog_id )
[185] Fix | Delete
) {
[186] Fix | Delete
$site_options = $this->get_site_options( $network_level_or_blog_id );
[187] Fix | Delete
$site_options->store();
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
if ( $this->_is_multisite &&
[191] Fix | Delete
( is_null( $network_level_or_blog_id ) || true === $network_level_or_blog_id )
[192] Fix | Delete
) {
[193] Fix | Delete
$this->_network_options->store();
[194] Fix | Delete
}
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
/**
[198] Fix | Delete
* @author Vova Feldman (@svovaf)
[199] Fix | Delete
* @since 2.0.0
[200] Fix | Delete
*
[201] Fix | Delete
* @param int|null|bool $network_level_or_blog_id
[202] Fix | Delete
* @param bool $flush
[203] Fix | Delete
*/
[204] Fix | Delete
function clear( $network_level_or_blog_id = null, $flush = false ) {
[205] Fix | Delete
if ( ! $this->_is_multisite ||
[206] Fix | Delete
false === $network_level_or_blog_id ||
[207] Fix | Delete
is_null( $network_level_or_blog_id ) ||
[208] Fix | Delete
is_numeric( $network_level_or_blog_id )
[209] Fix | Delete
) {
[210] Fix | Delete
$site_options = $this->get_site_options( $network_level_or_blog_id );
[211] Fix | Delete
$site_options->clear( $flush );
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
if ( $this->_is_multisite &&
[215] Fix | Delete
( true === $network_level_or_blog_id || is_null( $network_level_or_blog_id ) )
[216] Fix | Delete
) {
[217] Fix | Delete
$this->_network_options->clear( $flush );
[218] Fix | Delete
}
[219] Fix | Delete
}
[220] Fix | Delete
[221] Fix | Delete
/**
[222] Fix | Delete
* Migration script to the new storage data structure that is network compatible.
[223] Fix | Delete
*
[224] Fix | Delete
* IMPORTANT:
[225] Fix | Delete
* This method should be executed only after it is determined if this is a network
[226] Fix | Delete
* level compatible product activation.
[227] Fix | Delete
*
[228] Fix | Delete
* @author Vova Feldman (@svovaf)
[229] Fix | Delete
* @since 2.0.0
[230] Fix | Delete
*
[231] Fix | Delete
* @param int $blog_id
[232] Fix | Delete
*/
[233] Fix | Delete
function migrate_to_network( $blog_id = 0 ) {
[234] Fix | Delete
if ( ! $this->_is_multisite ) {
[235] Fix | Delete
return;
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
$updated = false;
[239] Fix | Delete
[240] Fix | Delete
$site_options = $this->get_site_options( $blog_id );
[241] Fix | Delete
[242] Fix | Delete
$keys = $site_options->get_options_keys();
[243] Fix | Delete
[244] Fix | Delete
foreach ( $keys as $option ) {
[245] Fix | Delete
if ( $this->is_site_option( $option ) ||
[246] Fix | Delete
// Don't move admin notices to the network storage.
[247] Fix | Delete
in_array($option, array(
[248] Fix | Delete
// Don't move admin notices to the network storage.
[249] Fix | Delete
'admin_notices',
[250] Fix | Delete
// Don't migrate the module specific data, it will be migrated by the FS_Storage.
[251] Fix | Delete
'plugin_data',
[252] Fix | Delete
'theme_data',
[253] Fix | Delete
))
[254] Fix | Delete
) {
[255] Fix | Delete
continue;
[256] Fix | Delete
}
[257] Fix | Delete
[258] Fix | Delete
$option_updated = false;
[259] Fix | Delete
[260] Fix | Delete
// Migrate option to the network storage.
[261] Fix | Delete
$site_option = $site_options->get_option( $option );
[262] Fix | Delete
[263] Fix | Delete
if ( ! $this->_network_options->has_option( $option ) ) {
[264] Fix | Delete
// Option not set on the network level, so just set it.
[265] Fix | Delete
$this->_network_options->set_option( $option, $site_option, false );
[266] Fix | Delete
[267] Fix | Delete
$option_updated = true;
[268] Fix | Delete
} else {
[269] Fix | Delete
// Option already set on the network level, so we need to merge it inelegantly.
[270] Fix | Delete
$network_option = $this->_network_options->get_option( $option );
[271] Fix | Delete
[272] Fix | Delete
if ( is_array( $network_option ) && is_array( $site_option ) ) {
[273] Fix | Delete
// Option is an array.
[274] Fix | Delete
foreach ( $site_option as $key => $value ) {
[275] Fix | Delete
if ( ! isset( $network_option[ $key ] ) ) {
[276] Fix | Delete
$network_option[ $key ] = $value;
[277] Fix | Delete
[278] Fix | Delete
$option_updated = true;
[279] Fix | Delete
} else if ( is_array( $network_option[ $key ] ) && is_array( $value ) ) {
[280] Fix | Delete
if ( empty( $network_option[ $key ] ) ) {
[281] Fix | Delete
$network_option[ $key ] = $value;
[282] Fix | Delete
[283] Fix | Delete
$option_updated = true;
[284] Fix | Delete
} else if ( empty( $value ) ) {
[285] Fix | Delete
// Do nothing.
[286] Fix | Delete
} else {
[287] Fix | Delete
reset($value);
[288] Fix | Delete
$first_key = key($value);
[289] Fix | Delete
if ( $value[$first_key] instanceof FS_Entity ) {
[290] Fix | Delete
// Merge entities by IDs.
[291] Fix | Delete
$network_entities_ids = array();
[292] Fix | Delete
foreach ( $network_option[ $key ] as $entity ) {
[293] Fix | Delete
$network_entities_ids[ $entity->id ] = true;
[294] Fix | Delete
}
[295] Fix | Delete
[296] Fix | Delete
foreach ( $value as $entity ) {
[297] Fix | Delete
if ( ! isset( $network_entities_ids[ $entity->id ] ) ) {
[298] Fix | Delete
$network_option[ $key ][] = $entity;
[299] Fix | Delete
[300] Fix | Delete
$option_updated = true;
[301] Fix | Delete
}
[302] Fix | Delete
}
[303] Fix | Delete
}
[304] Fix | Delete
}
[305] Fix | Delete
}
[306] Fix | Delete
}
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
if ( $option_updated ) {
[310] Fix | Delete
$this->_network_options->set_option( $option, $network_option, false );
[311] Fix | Delete
}
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
/**
[315] Fix | Delete
* Remove the option from site level storage.
[316] Fix | Delete
*
[317] Fix | Delete
* IMPORTANT:
[318] Fix | Delete
* The line below is intentionally commented since we want to preserve the option
[319] Fix | Delete
* on the site storage level for "downgrade compatibility". Basically, if the user
[320] Fix | Delete
* will downgrade to an older version of the plugin with the prev storage structure,
[321] Fix | Delete
* it will continue working.
[322] Fix | Delete
*
[323] Fix | Delete
* @todo After a few releases we can remove this.
[324] Fix | Delete
*/
[325] Fix | Delete
// $site_options->unset_option($option, false);
[326] Fix | Delete
[327] Fix | Delete
if ( $option_updated ) {
[328] Fix | Delete
$updated = true;
[329] Fix | Delete
}
[330] Fix | Delete
}
[331] Fix | Delete
[332] Fix | Delete
if ( ! $updated ) {
[333] Fix | Delete
return;
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
// Update network level storage.
[337] Fix | Delete
$this->_network_options->store();
[338] Fix | Delete
// $site_options->store();
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
[342] Fix | Delete
#--------------------------------------------------------------------------------
[343] Fix | Delete
#region Helper Methods
[344] Fix | Delete
#--------------------------------------------------------------------------------
[345] Fix | Delete
[346] Fix | Delete
/**
[347] Fix | Delete
* We don't want to load the map right away since it's not even needed in a non-MS environment.
[348] Fix | Delete
*
[349] Fix | Delete
* @author Vova Feldman (@svovaf)
[350] Fix | Delete
* @since 2.0.0
[351] Fix | Delete
*/
[352] Fix | Delete
private static function load_site_options_map() {
[353] Fix | Delete
self::$_SITE_OPTIONS_MAP = array(
[354] Fix | Delete
'sites' => true,
[355] Fix | Delete
'theme_sites' => true,
[356] Fix | Delete
'unique_id' => true,
[357] Fix | Delete
'active_plugins' => true,
[358] Fix | Delete
);
[359] Fix | Delete
}
[360] Fix | Delete
[361] Fix | Delete
/**
[362] Fix | Delete
* @author Vova Feldman (@svovaf)
[363] Fix | Delete
* @since 2.0.0
[364] Fix | Delete
*
[365] Fix | Delete
* @param string $option
[366] Fix | Delete
*
[367] Fix | Delete
* @return bool
[368] Fix | Delete
*/
[369] Fix | Delete
private function is_site_option( $option ) {
[370] Fix | Delete
if ( WP_FS__ACCOUNTS_OPTION_NAME != $this->_id ) {
[371] Fix | Delete
return false;
[372] Fix | Delete
}
[373] Fix | Delete
[374] Fix | Delete
if ( ! isset( self::$_SITE_OPTIONS_MAP ) ) {
[375] Fix | Delete
self::load_site_options_map();
[376] Fix | Delete
}
[377] Fix | Delete
[378] Fix | Delete
return isset( self::$_SITE_OPTIONS_MAP[ $option ] );
[379] Fix | Delete
}
[380] Fix | Delete
[381] Fix | Delete
/**
[382] Fix | Delete
* @author Vova Feldman (@svovaf)
[383] Fix | Delete
* @since 2.0.0
[384] Fix | Delete
*
[385] Fix | Delete
* @param int $blog_id
[386] Fix | Delete
*
[387] Fix | Delete
* @return FS_Option_Manager
[388] Fix | Delete
*/
[389] Fix | Delete
private function get_site_options( $blog_id = 0 ) {
[390] Fix | Delete
if ( 0 == $blog_id || $blog_id == $this->_blog_id ) {
[391] Fix | Delete
return $this->_options;
[392] Fix | Delete
}
[393] Fix | Delete
[394] Fix | Delete
return FS_Option_Manager::get_manager( $this->_id, true, $blog_id );
[395] Fix | Delete
}
[396] Fix | Delete
[397] Fix | Delete
/**
[398] Fix | Delete
* Check if an option should be stored on the MS network storage.
[399] Fix | Delete
*
[400] Fix | Delete
* @author Vova Feldman (@svovaf)
[401] Fix | Delete
* @since 2.0.0
[402] Fix | Delete
*
[403] Fix | Delete
* @param string $option
[404] 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::$_SITE_LEVEL_PARAMS).
[405] Fix | Delete
*
[406] Fix | Delete
* @return bool
[407] Fix | Delete
*/
[408] Fix | Delete
private function should_use_network_storage( $option, $network_level_or_blog_id = null ) {
[409] Fix | Delete
if ( ! $this->_is_multisite ) {
[410] Fix | Delete
// Not a multisite environment.
[411] Fix | Delete
return false;
[412] Fix | Delete
}
[413] Fix | Delete
[414] Fix | Delete
if ( is_numeric( $network_level_or_blog_id ) ) {
[415] Fix | Delete
// Explicitly asked to use a specified blog storage.
[416] Fix | Delete
return false;
[417] Fix | Delete
}
[418] Fix | Delete
[419] Fix | Delete
if ( is_bool( $network_level_or_blog_id ) ) {
[420] Fix | Delete
// Explicitly specified whether should use the network or blog level storage.
[421] Fix | Delete
return $network_level_or_blog_id;
[422] Fix | Delete
}
[423] Fix | Delete
[424] Fix | Delete
// Determine which storage to use based on the option.
[425] Fix | Delete
return ! $this->is_site_option( $option );
[426] Fix | Delete
}
[427] Fix | Delete
[428] Fix | Delete
#endregion
[429] Fix | Delete
}
[430] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function