| 1 |
<?php |
| 2 |
/** |
| 3 |
* Update |
| 4 |
* |
| 5 |
* @package Copy the Code |
| 6 |
* @since 2.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! class_exists( 'Copy_The_Code_Update' ) ) : |
| 10 |
|
| 11 |
/** |
| 12 |
* Copy The Code Update |
| 13 |
* |
| 14 |
* @since 2.0.0 |
| 15 |
*/ |
| 16 |
class Copy_The_Code_Update { |
| 17 |
|
| 18 |
/** |
| 19 |
* Instance |
| 20 |
* |
| 21 |
* @var object Class object. |
| 22 |
* @access private |
| 23 |
* @since 2.0.0 |
| 24 |
*/ |
| 25 |
private static $instance; |
| 26 |
|
| 27 |
/** |
| 28 |
* Initiator |
| 29 |
* |
| 30 |
* @since 2.0.0 |
| 31 |
* @return object initialized object of class. |
| 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 |
* @since 2.0.0 |
| 44 |
*/ |
| 45 |
public function __construct() { |
| 46 |
add_action( 'admin_init', __CLASS__ . '::init' ); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Init |
| 51 |
* |
| 52 |
* @since 2.0.0 |
| 53 |
* @return void |
| 54 |
*/ |
| 55 |
public static function init() { |
| 56 |
|
| 57 |
do_action( 'copy_the_code_update_before' ); |
| 58 |
|
| 59 |
// Get auto saved version number. |
| 60 |
$saved_version = get_option( 'copy-the-code-auto-version', false ); |
| 61 |
|
| 62 |
// Update auto saved version number. |
| 63 |
if ( ! $saved_version ) { |
| 64 |
update_option( 'copy-the-code-auto-version', COPY_THE_CODE_VER ); |
| 65 |
} |
| 66 |
|
| 67 |
// If equals then return. |
| 68 |
if ( version_compare( $saved_version, COPY_THE_CODE_VER, '=' ) ) { |
| 69 |
return; |
| 70 |
} |
| 71 |
|
| 72 |
// Update to older version than 1.0.1 version. |
| 73 |
if ( version_compare( $saved_version, '2.0.0', '<' ) ) { |
| 74 |
self::v_2_0_0(); |
| 75 |
} |
| 76 |
|
| 77 |
// Update auto saved version number. |
| 78 |
update_option( 'copy-the-code-auto-version', COPY_THE_CODE_VER ); |
| 79 |
|
| 80 |
do_action( 'copy_the_code_update_after' ); |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Create a default |
| 85 |
* |
| 86 |
* @since 2.0.0 |
| 87 |
* @return void |
| 88 |
*/ |
| 89 |
public static function v_2_0_0() { |
| 90 |
|
| 91 |
$defaults = array( |
| 92 |
'selector' => 'pre', |
| 93 |
'style' => 'button', |
| 94 |
'button-text' => 'Copy', |
| 95 |
'button-title' => 'Copy', |
| 96 |
'button-copy-text' => 'Copied!', |
| 97 |
'button-position' => 'inside', |
| 98 |
); |
| 99 |
|
| 100 |
$stored_data = Copy_The_Code_Page::get_instance()->get_page_settings(); |
| 101 |
$data = wp_parse_args( $stored_data, $defaults ); |
| 102 |
|
| 103 |
$args = array( |
| 104 |
'post_type' => 'copy-to-clipboard', |
| 105 |
'post_status' => 'publish', |
| 106 |
'post_title' => $data['selector'], |
| 107 |
'meta_input' => $data, |
| 108 |
); |
| 109 |
|
| 110 |
wp_insert_post( $args ); |
| 111 |
} |
| 112 |
|
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Kicking this off by calling 'get_instance()' method |
| 117 |
*/ |
| 118 |
Copy_The_Code_Update::get_instance(); |
| 119 |
|
| 120 |
endif; |
| 121 |
|