|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Custom Typekit Fonts Update |
| 4 | + * |
| 5 | + * @package Custom Typekit Fonts |
| 6 | + * @author Brainstorm Force |
| 7 | + * @copyright Copyright (c) 2018, Astra |
| 8 | + * @link https://wpastra.com/ |
| 9 | + * @since Astra 1.0.0 |
| 10 | + */ |
| 11 | + |
| 12 | +if ( ! class_exists( 'Custom_Typekit_Fonts_Update' ) ) { |
| 13 | + |
| 14 | + /** |
| 15 | + * Custom_Typekit_Fonts_Update initial setup |
| 16 | + * |
| 17 | + * @since 1.0.0 |
| 18 | + */ |
| 19 | + class Custom_Typekit_Fonts_Update { |
| 20 | + |
| 21 | + |
| 22 | + /** |
| 23 | + * Class instance. |
| 24 | + * |
| 25 | + * @access private |
| 26 | + * @var $instance Class instance. |
| 27 | + */ |
| 28 | + private static $instance; |
| 29 | + |
| 30 | + /** |
| 31 | + * Initiator |
| 32 | + */ |
| 33 | + public static function get_instance() { |
| 34 | + if ( ! isset( self::$instance ) ) { |
| 35 | + self::$instance = new self(); |
| 36 | + } |
| 37 | + return self::$instance; |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Constructor |
| 42 | + */ |
| 43 | + public function __construct() { |
| 44 | + |
| 45 | + // Theme Updates. |
| 46 | + if ( is_admin() ) { |
| 47 | + add_action( 'admin_init', array( $this, 'init' ), 5 ); |
| 48 | + } else { |
| 49 | + add_action( 'init', array( $this, 'init' ), 5 ); |
| 50 | + } |
| 51 | + |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Return option name for storing the custom typekit version. |
| 56 | + * |
| 57 | + * @return String |
| 58 | + */ |
| 59 | + private function get_option_name() { |
| 60 | + return '_custom_typekit_fonts_version'; |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Implement theme update logic. |
| 65 | + * |
| 66 | + * @since 1.0.7 |
| 67 | + */ |
| 68 | + public function init() { |
| 69 | + do_action( 'custom_typekit_fonts_update_before' ); |
| 70 | + |
| 71 | + // Get auto saved version number. |
| 72 | + $saved_version = get_option( $this->get_option_name(), false ); |
| 73 | + |
| 74 | + // If equals then return. |
| 75 | + if ( version_compare( $saved_version, CUSTOM_TYPEKIT_FONTS_VER, '=' ) ) { |
| 76 | + return; |
| 77 | + } |
| 78 | + |
| 79 | + // Update to older version than 1.0.8 version. |
| 80 | + if ( version_compare( $saved_version, '1.0.8', '<' ) ) { |
| 81 | + $this->v_1_0_8(); |
| 82 | + } |
| 83 | + |
| 84 | + // Update auto saved version number. |
| 85 | + update_option( $this->get_option_name(), CUSTOM_TYPEKIT_FONTS_VER ); |
| 86 | + |
| 87 | + do_action( 'custom_typekit_fonts_update_after' ); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Force udpate typekit fonts. |
| 92 | + * |
| 93 | + * @return void |
| 94 | + */ |
| 95 | + private function v_1_0_8() { |
| 96 | + $typekit = new Custom_Typekit_Fonts(); |
| 97 | + $custom_typekit = get_option( 'custom-typekit-fonts' ); |
| 98 | + $option = array(); |
| 99 | + $option['custom-typekit-font-id'] = sanitize_text_field( $custom_typekit['custom-typekit-font-id'] ); |
| 100 | + $option['custom-typekit-font-details'] = $typekit->get_custom_typekit_details( $custom_typekit['custom-typekit-font-id'] ); |
| 101 | + |
| 102 | + update_option( 'custom-typekit-fonts', $option ); |
| 103 | + } |
| 104 | + |
| 105 | + } |
| 106 | + |
| 107 | +} |
| 108 | + |
| 109 | +/** |
| 110 | + * Kicking this off by calling 'get_instance()' method |
| 111 | + */ |
| 112 | +Custom_Typekit_Fonts_Update::get_instance(); |
0 commit comments