class-do-css.php
6 years ago
class-enqueue-css.php
6 years ago
class-plugin-update.php
6 years ago
class-settings.php
6 years ago
dashboard.php
6 years ago
defaults.php
6 years ago
functions.php
6 years ago
general.php
6 years ago
generate-css.php
6 years ago
class-plugin-update.php
80 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Handles option changes on plugin updates. |
| 4 | * |
| 5 | * @package GenerateBlocks |
| 6 | * @since 1.1 |
| 7 | */ |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; // Exit if accessed directly. |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * Process option updates if necessary. |
| 15 | */ |
| 16 | class GenerateBlocks_Plugin_Update { |
| 17 | /** |
| 18 | * Class instance. |
| 19 | * |
| 20 | * @access private |
| 21 | * @var $instance Class instance. |
| 22 | */ |
| 23 | private static $instance; |
| 24 | |
| 25 | /** |
| 26 | * Initiator |
| 27 | */ |
| 28 | public static function get_instance() { |
| 29 | if ( ! isset( self::$instance ) ) { |
| 30 | self::$instance = new self(); |
| 31 | } |
| 32 | return self::$instance; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Constructor |
| 37 | */ |
| 38 | public function __construct() { |
| 39 | if ( is_admin() ) { |
| 40 | add_action( 'admin_init', __CLASS__ . '::init', 5 ); |
| 41 | } else { |
| 42 | add_action( 'wp', __CLASS__ . '::init', 5 ); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Implement plugin update logic. |
| 48 | * |
| 49 | * @since 1.1.0 |
| 50 | */ |
| 51 | public static function init() { |
| 52 | if ( is_customize_preview() ) { |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | $saved_version = get_option( 'generateblocks_version', false ); |
| 57 | |
| 58 | if ( false === $saved_version ) { |
| 59 | if ( 'admin_init' === current_action() ) { |
| 60 | // If we're in the admin, add our version to the database. |
| 61 | update_option( 'generateblocks_version', sanitize_text_field( GENERATEBLOCKS_VERSION ) ); |
| 62 | } |
| 63 | |
| 64 | // Not an existing install, so no need to proceed further. |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | if ( version_compare( $saved_version, GENERATEBLOCKS_VERSION, '=' ) ) { |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | // Nothing to update yet. |
| 73 | |
| 74 | // Last thing to do is update our version. |
| 75 | update_option( 'generateblocks_version', sanitize_text_field( GENERATEBLOCKS_VERSION ) ); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | GenerateBlocks_Plugin_Update::get_instance(); |
| 80 |