abilities
1 week ago
admin
1 week ago
compatibility
1 week ago
extensions
1 week ago
foopluginbase
1 week ago
public
1 week ago
thumbs
1 week ago
asset-manifest.php
1 week ago
class-attachment-filters.php
1 week ago
class-command-palette.php
1 week ago
class-foogallery-animated-gif-support.php
1 week ago
class-foogallery-attachment-custom-class.php
1 week ago
class-foogallery-attachment-filename.php
1 week ago
class-foogallery-attachment-type.php
1 week ago
class-foogallery-attachment.php
1 week ago
class-foogallery-cache.php
1 week ago
class-foogallery-common-fields.php
1 week ago
class-foogallery-crop-position.php
1 week ago
class-foogallery-datasource-media_library.php
1 week ago
class-foogallery-debug.php
1 week ago
class-foogallery-delayed-runtime-loader.php
1 week ago
class-foogallery-extensions-compatibility.php
1 week ago
class-foogallery-force-https.php
1 week ago
class-foogallery-lazyload.php
1 week ago
class-foogallery-license-constant-handler.php
1 week ago
class-foogallery-lightbox.php
1 week ago
class-foogallery-no-javascript-fallback.php
1 week ago
class-foogallery-paging.php
1 week ago
class-foogallery-password-protect.php
1 week ago
class-foogallery-sitemaps.php
1 week ago
class-foogallery-widget.php
1 week ago
class-foogallery.php
1 week ago
class-gallery-advanced-settings.php
1 week ago
class-il8n.php
1 week ago
class-override-thumbnail.php
1 week ago
class-posttypes.php
1 week ago
class-previews.php
1 week ago
class-retina.php
1 week ago
class-thumbnail-dimensions.php
1 week ago
class-thumbnails.php
1 week ago
class-version-check.php
1 week ago
constants.php
1 week ago
functions.php
1 week ago
gallery-management-functions.php
1 week ago
includes.php
1 week ago
index.php
1 week ago
render-functions.php
1 week ago
class-version-check.php
136 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Created by brad. |
| 9 | * Date: 15/11/2015 |
| 10 | */ |
| 11 | if ( ! class_exists( 'FooGallery_Version_Check' ) ) { |
| 12 | |
| 13 | class FooGallery_Version_Check { |
| 14 | |
| 15 | /** |
| 16 | * Wire up the check so it is done in the admin after admin includes are loaded. |
| 17 | */ |
| 18 | public function wire_up_checker() { |
| 19 | if ( is_admin() ) { |
| 20 | // When in admin, check if a new version is running. |
| 21 | add_action( 'admin_init', array( $this, 'perform_check' ) ); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Perform a check to see if the plugin has been updated |
| 27 | */ |
| 28 | public function perform_check() { |
| 29 | $stored_version = self::get_stored_version(); |
| 30 | |
| 31 | if ( $stored_version != FOOGALLERY_VERSION ) { |
| 32 | //This code will run every time the plugin is updated |
| 33 | |
| 34 | //perform all our housekeeping |
| 35 | $this->perform_housekeeping( $stored_version ); |
| 36 | |
| 37 | //set the current version, so that this does not run again until the next update! |
| 38 | update_site_option( FOOGALLERY_OPTION_VERSION, array( |
| 39 | 'version' => FOOGALLERY_VERSION, |
| 40 | 'updated_at' => time(), |
| 41 | ) ); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Get the stored FooGallery version. |
| 47 | * |
| 48 | * @return string |
| 49 | */ |
| 50 | public static function get_stored_version() { |
| 51 | $version_data = get_site_option( FOOGALLERY_OPTION_VERSION ); |
| 52 | |
| 53 | if ( is_array( $version_data ) && isset( $version_data['version'] ) ) { |
| 54 | return $version_data['version']; |
| 55 | } |
| 56 | |
| 57 | return $version_data; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Get the last FooGallery update timestamp. |
| 62 | * |
| 63 | * @return int |
| 64 | */ |
| 65 | public static function get_last_update_time() { |
| 66 | $version_data = get_site_option( FOOGALLERY_OPTION_VERSION ); |
| 67 | |
| 68 | if ( is_array( $version_data ) && isset( $version_data['updated_at'] ) ) { |
| 69 | return absint( $version_data['updated_at'] ); |
| 70 | } |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Runs after FooGallery has been updated via the backend |
| 77 | * |
| 78 | * @param string|false $previous_version The previously stored FooGallery version. |
| 79 | */ |
| 80 | function perform_housekeeping( $previous_version = false ) { |
| 81 | //allow extensions or other plugins to do stuff when foogallery is updated |
| 82 | // this will catch both manual and auto updates! |
| 83 | do_action( 'foogallery_admin_new_version_detected' ); |
| 84 | |
| 85 | $this->maybe_force_legacy_runtime_scripts_for_existing_install( $previous_version ); |
| 86 | |
| 87 | //we need to clear the foogallery css load optimizations when we update the plugin, to ensure the latest CSS files are loaded |
| 88 | foogallery_clear_all_css_load_optimizations(); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Existing installs should keep the legacy runtime enqueue behavior unless explicitly opted in. |
| 93 | * |
| 94 | * @param string|false $previous_version The previously stored FooGallery version. |
| 95 | * |
| 96 | * @return void |
| 97 | */ |
| 98 | private function maybe_force_legacy_runtime_scripts_for_existing_install( $previous_version ) { |
| 99 | if ( ! is_string( $previous_version ) || '' === $previous_version || ! version_compare( $previous_version, '3.1.36', '<' ) ) { |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | if ( $this->setting_has_explicit_value( 'force_legacy_runtime_scripts' ) ) { |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | foogallery_set_setting( 'force_legacy_runtime_scripts', 'on' ); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Check if a setting is explicitly saved and not only supplied by defaults. |
| 112 | * |
| 113 | * @param string $key The setting key. |
| 114 | * |
| 115 | * @return bool |
| 116 | */ |
| 117 | private function setting_has_explicit_value( $key ) { |
| 118 | $options = get_option( FOOGALLERY_SLUG ); |
| 119 | |
| 120 | if ( is_array( $options ) && array_key_exists( $key, $options ) ) { |
| 121 | return true; |
| 122 | } |
| 123 | |
| 124 | if ( function_exists( 'is_multisite' ) && is_multisite() ) { |
| 125 | $site_options = get_site_option( FOOGALLERY_SLUG ); |
| 126 | |
| 127 | if ( is_array( $site_options ) && array_key_exists( $key, $site_options ) ) { |
| 128 | return true; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | return false; |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 |