PluginProbe
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels / 2.3.8
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels v2.3.8
2.9.1 2.9.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 2.0.0 2.1.0 2.2.0 2.3.2 2.3.3 2.3.5 2.3.6 2.3.8 2.3.9 2.4.3 All 37 releases
← All changes | freemius/includes/class-fs-storage.php +107 -74 1.3.02.3.8 View file →
@@ -14,11 +14,13 @@
14 14 * Class FS_Storage
15 15 *
16 16 * A wrapper class for handling network level and single site level storage.
17 17 *
18 - * @property bool $is_network_activation
19 - * @property int $network_install_blog_id
20 - * @property object $sync_cron
18 + * @property bool $is_network_activation
19 + * @property int $network_install_blog_id
20 + * @property bool|null $is_extensions_tracking_allowed
21 + * @property bool|null $is_diagnostic_tracking_allowed
22 + * @property object $sync_cron
21 23 */
22 24 class FS_Storage {
23 25 /**
24 26 * @var FS_Storage[]
@@ -71,8 +73,18 @@
71 73 * }
72 74 */
73 75 private static $_NETWORK_OPTIONS_MAP;
74 76
77 + const OPTION_LEVEL_UNDEFINED = -1;
78 + // The option should be stored on the network level.
79 + const OPTION_LEVEL_NETWORK = 0;
80 + // The option should be stored on the network level when the plugin is network-activated.
81 + const OPTION_LEVEL_NETWORK_ACTIVATED = 1;
82 + // 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.
83 + const OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED = 2;
84 + // The option should be stored on the site level.
85 + const OPTION_LEVEL_SITE = 3;
86 +
75 87 /**
76 88 * @author Leo Fajardo (@leorw)
77 89 *
78 90 * @param string $module_type
@@ -141,12 +153,19 @@
141 153 *
142 154 * @param string $key
143 155 * @param mixed $value
144 156 * @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).
157 + * @param int $option_level Since 2.5.1
145 158 * @param bool $flush
146 159 */
147 - function store( $key, $value, $network_level_or_blog_id = null, $flush = true ) {
148 - if ( $this->should_use_network_storage( $key, $network_level_or_blog_id ) ) {
160 + function store(
161 + $key,
162 + $value,
163 + $network_level_or_blog_id = null,
164 + $option_level = self::OPTION_LEVEL_UNDEFINED,
165 + $flush = true
166 + ) {
167 + if ( $this->should_use_network_storage( $key, $network_level_or_blog_id, $option_level ) ) {
149 168 $this->_network_storage->store( $key, $value, $flush );
150 169 } else {
151 170 $storage = $this->get_site_storage( $network_level_or_blog_id );
152 171 $storage->store( $key, $value, $flush );
@@ -198,13 +217,19 @@
198 217 *
199 218 * @param string $key
200 219 * @param mixed $default
201 220 * @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).
221 + * @param int $option_level Since 2.5.1
202 222 *
203 223 * @return mixed
204 224 */
205 - function get( $key, $default = false, $network_level_or_blog_id = null ) {
206 - if ( $this->should_use_network_storage( $key, $network_level_or_blog_id ) ) {
225 + function get(
226 + $key,
227 + $default = false,
228 + $network_level_or_blog_id = null,
229 + $option_level = self::OPTION_LEVEL_UNDEFINED
230 + ) {
231 + if ( $this->should_use_network_storage( $key, $network_level_or_blog_id, $option_level ) ) {
207 232 return $this->_network_storage->get( $key, $default );
208 233 } else {
209 234 $storage = $this->get_site_storage( $network_level_or_blog_id );
210 235
@@ -288,21 +313,8 @@
288 313 if ( isset( $this->_storage->{$option} ) && ! isset( $this->_network_storage->{$option} ) ) {
289 314 // Migrate option to the network storage.
290 315 $this->_network_storage->store( $option, $this->_storage->{$option}, false );
291 316
292 - /**
293 - * Remove the option from site level storage.
294 - *
295 - * IMPORTANT:
296 - * The line below is intentionally commented since we want to preserve the option
297 - * on the site storage level for "downgrade compatibility". Basically, if the user
298 - * will downgrade to an older version of the plugin with the prev storage structure,
299 - * it will continue working.
300 - *
301 - * @todo After a few releases we can remove this.
302 - */
303 -// $this->_storage->remove($option, false);
304 -
305 317 $updated = true;
306 318 }
307 319 }
308 320
@@ -335,59 +347,64 @@
335 347 */
336 348 private static function load_network_options_map() {
337 349 self::$_NETWORK_OPTIONS_MAP = array(
338 350 // Network level options.
339 - 'affiliate_application_data' => 0,
340 - 'beta_data' => 0,
341 - 'connectivity_test' => 0,
342 - 'handle_gdpr_admin_notice' => 0,
343 - 'has_trial_plan' => 0,
344 - 'install_sync_timestamp' => 0,
345 - 'install_sync_cron' => 0,
346 - 'is_anonymous_ms' => 0,
347 - 'is_network_activated' => 0,
348 - 'is_on' => 0,
349 - 'is_plugin_new_install' => 0,
350 - 'network_install_blog_id' => 0,
351 - 'pending_sites_info' => 0,
352 - 'plugin_last_version' => 0,
353 - 'plugin_main_file' => 0,
354 - 'plugin_version' => 0,
355 - 'sdk_downgrade_mode' => 0,
356 - 'sdk_last_version' => 0,
357 - 'sdk_upgrade_mode' => 0,
358 - 'sdk_version' => 0,
359 - 'sticky_optin_added_ms' => 0,
360 - 'subscriptions' => 0,
361 - 'sync_timestamp' => 0,
362 - 'sync_cron' => 0,
363 - 'was_plugin_loaded' => 0,
364 - 'network_user_id' => 0,
365 - 'plugin_upgrade_mode' => 0,
366 - 'plugin_downgrade_mode' => 0,
367 - 'is_network_connected' => 0,
351 + 'affiliate_application_data' => self::OPTION_LEVEL_NETWORK,
352 + 'beta_data' => self::OPTION_LEVEL_NETWORK,
353 + 'connectivity_test' => self::OPTION_LEVEL_NETWORK,
354 + 'handle_gdpr_admin_notice' => self::OPTION_LEVEL_NETWORK,
355 + 'has_trial_plan' => self::OPTION_LEVEL_NETWORK,
356 + 'install_sync_timestamp' => self::OPTION_LEVEL_NETWORK,
357 + 'install_sync_cron' => self::OPTION_LEVEL_NETWORK,
358 + 'is_anonymous_ms' => self::OPTION_LEVEL_NETWORK,
359 + 'is_network_activated' => self::OPTION_LEVEL_NETWORK,
360 + 'is_on' => self::OPTION_LEVEL_NETWORK,
361 + 'is_plugin_new_install' => self::OPTION_LEVEL_NETWORK,
362 + 'last_load_timestamp' => self::OPTION_LEVEL_NETWORK,
363 + 'network_install_blog_id' => self::OPTION_LEVEL_NETWORK,
364 + 'pending_sites_info' => self::OPTION_LEVEL_NETWORK,
365 + 'plugin_last_version' => self::OPTION_LEVEL_NETWORK,
366 + 'plugin_main_file' => self::OPTION_LEVEL_NETWORK,
367 + 'plugin_version' => self::OPTION_LEVEL_NETWORK,
368 + 'sdk_downgrade_mode' => self::OPTION_LEVEL_NETWORK,
369 + 'sdk_last_version' => self::OPTION_LEVEL_NETWORK,
370 + 'sdk_upgrade_mode' => self::OPTION_LEVEL_NETWORK,
371 + 'sdk_version' => self::OPTION_LEVEL_NETWORK,
372 + 'sticky_optin_added_ms' => self::OPTION_LEVEL_NETWORK,
373 + 'subscriptions' => self::OPTION_LEVEL_NETWORK,
374 + 'sync_timestamp' => self::OPTION_LEVEL_NETWORK,
375 + 'sync_cron' => self::OPTION_LEVEL_NETWORK,
376 + 'was_plugin_loaded' => self::OPTION_LEVEL_NETWORK,
377 + 'network_user_id' => self::OPTION_LEVEL_NETWORK,
378 + 'plugin_upgrade_mode' => self::OPTION_LEVEL_NETWORK,
379 + 'plugin_downgrade_mode' => self::OPTION_LEVEL_NETWORK,
380 + 'is_network_connected' => self::OPTION_LEVEL_NETWORK,
368 381 /**
369 - * Special flag that is used when a super-admin upgrades to the new version of the SDK that
370 - * supports network level integration, when the connection decision wasn't made for all of the
371 - * sites in the network.
382 + * 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.
372 383 */
373 - 'is_network_activation' => 0,
384 + 'is_network_activation' => self::OPTION_LEVEL_NETWORK,
385 + 'license_migration' => self::OPTION_LEVEL_NETWORK,
374 386
375 387 // When network activated, then network level.
376 - 'install_timestamp' => 1,
377 - 'prev_is_premium' => 1,
378 - 'require_license_activation' => 1,
388 + 'install_timestamp' => self::OPTION_LEVEL_NETWORK_ACTIVATED,
389 + 'prev_is_premium' => self::OPTION_LEVEL_NETWORK_ACTIVATED,
390 + 'require_license_activation' => self::OPTION_LEVEL_NETWORK_ACTIVATED,
379 391
380 392 // If not network activated OR delegated, then site level.
381 - 'activation_timestamp' => 2,
382 - 'prev_user_id' => 2,
383 - 'sticky_optin_added' => 2,
384 - 'uninstall_reason' => 2,
385 - 'is_pending_activation' => 2,
386 - 'pending_license_key' => 2,
393 + 'activation_timestamp' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
394 + 'expired_license_notice_shown' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
395 + 'is_whitelabeled' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
396 + 'last_license_key' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
397 + 'last_license_user_id' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
398 + 'prev_user_id' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
399 + 'sticky_optin_added' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
400 + 'uninstall_reason' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
401 + 'is_pending_activation' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
402 + 'pending_license_key' => self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED,
387 403
388 404 // Site level options.
389 - 'is_anonymous' => 3,
405 + 'is_anonymous' => self::OPTION_LEVEL_SITE,
406 + 'clone_id' => self::OPTION_LEVEL_SITE,
390 407 );
391 408 }
392 409
393 410 /**
@@ -396,27 +413,35 @@
396 413 * @author Vova Feldman (@svovaf)
397 414 * @since 2.0.0
398 415 *
399 416 * @param string $key
417 + * @param int $option_level Since 2.5.1
400 418 *
401 - * @return bool|mixed
419 + * @return bool
402 420 */
403 - private function is_multisite_option( $key ) {
421 + private function is_multisite_option( $key, $option_level = self::OPTION_LEVEL_UNDEFINED ) {
404 422 if ( ! isset( self::$_NETWORK_OPTIONS_MAP ) ) {
405 423 self::load_network_options_map();
406 424 }
407 425
408 - if ( ! isset( self::$_NETWORK_OPTIONS_MAP[ $key ] ) ) {
426 + if (
427 + self::OPTION_LEVEL_UNDEFINED === $option_level &&
428 + isset( self::$_NETWORK_OPTIONS_MAP[ $key ] )
429 + ) {
430 + $option_level = self::$_NETWORK_OPTIONS_MAP[ $key ];
431 + }
432 +
433 + if ( self::OPTION_LEVEL_UNDEFINED === $option_level ) {
409 434 // Option not found -> use site level storage.
410 435 return false;
411 436 }
412 437
413 - if ( 0 === self::$_NETWORK_OPTIONS_MAP[ $key ] ) {
438 + if ( self::OPTION_LEVEL_NETWORK === $option_level ) {
414 439 // Option found and set to always use the network level storage on a multisite.
415 440 return true;
416 441 }
417 442
418 - if ( 3 === self::$_NETWORK_OPTIONS_MAP[ $key ] ) {
443 + if ( self::OPTION_LEVEL_SITE === $option_level ) {
419 444 // Option found and set to always use the site level storage on a multisite.
420 445 return false;
421 446 }
422 447
@@ -423,14 +448,17 @@
423 448 if ( ! $this->_is_network_active ) {
424 449 return false;
425 450 }
426 451
427 - if ( 1 === self::$_NETWORK_OPTIONS_MAP[ $key ] ) {
452 + if ( self::OPTION_LEVEL_NETWORK_ACTIVATED === $option_level ) {
428 453 // Network activated.
429 454 return true;
430 455 }
431 456
432 - if ( 2 === self::$_NETWORK_OPTIONS_MAP[ $key ] && ! $this->_is_delegated_connection ) {
457 + if (
458 + self::OPTION_LEVEL_NETWORK_ACTIVATED_NOT_DELEGATED === $option_level &&
459 + ! $this->_is_delegated_connection
460 + ) {
433 461 // Network activated and not delegated.
434 462 return true;
435 463 }
436 464
@@ -441,12 +469,17 @@
441 469 * @author Leo Fajardo
442 470 *
443 471 * @param string $key
444 472 * @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).
473 + * @param int $option_level Since 2.5.1
445 474 *
446 475 * @return bool
447 476 */
448 - private function should_use_network_storage( $key, $network_level_or_blog_id = null ) {
477 + private function should_use_network_storage(
478 + $key,
479 + $network_level_or_blog_id = null,
480 + $option_level = self::OPTION_LEVEL_UNDEFINED
481 + ) {
449 482 if ( ! $this->_is_multisite ) {
450 483 // Not a multisite environment.
451 484 return false;
452 485 }
@@ -456,14 +489,14 @@
456 489 return false;
457 490 }
458 491
459 492 if ( is_bool( $network_level_or_blog_id ) ) {
460 - // Explicitly specified whether should use the network or blog level storage.
493 + // Explicitly specified whether it should use the network or blog level storage.
461 494 return $network_level_or_blog_id;
462 495 }
463 496
464 497 // Determine which storage to use based on the option.
465 - return $this->is_multisite_option( $key );
498 + return $this->is_multisite_option( $key, $option_level );
466 499 }
467 500
468 501 /**
469 502 * @author Vova Feldman (@svovaf)
@@ -522,5 +555,5 @@
522 555 $this->_storage->{$k};
523 556 }
524 557
525 558 #endregion
526 - }
559 + }