| 1 |
<?php |
| 2 |
/** |
| 3 |
* Templately plugin. |
| 4 |
* |
| 5 |
* The main plugin handler class is responsible for initializing Templately. The |
| 6 |
* class registers and all the components required to run the plugin. |
| 7 |
* |
| 8 |
* @package Templately |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace Templately; |
| 12 |
|
| 13 |
defined('ABSPATH') or exit; |
| 14 |
|
| 15 |
use Templately\Admin\Admin; |
| 16 |
|
| 17 |
final class Plugin { |
| 18 |
/** |
| 19 |
* Plugin Version |
| 20 |
* @var string |
| 21 |
*/ |
| 22 |
protected static $version; |
| 23 |
/** |
| 24 |
* Plugin Name |
| 25 |
* @var string |
| 26 |
*/ |
| 27 |
protected static $plugin_name; |
| 28 |
/** |
| 29 |
* Plugin Instance |
| 30 |
* @var \Templately\Plugin |
| 31 |
*/ |
| 32 |
private static $_instance = null; |
| 33 |
/** |
| 34 |
* Elementor Instance |
| 35 |
* |
| 36 |
* @var \Templately\Elementor |
| 37 |
*/ |
| 38 |
public $elementor = null; |
| 39 |
/** |
| 40 |
* Admin Instance |
| 41 |
* |
| 42 |
* @var \Templately\Admin\Admin |
| 43 |
*/ |
| 44 |
public $admin = null; |
| 45 |
|
| 46 |
/** |
| 47 |
* Get a single instance of Plugin |
| 48 |
* @return Plugin |
| 49 |
*/ |
| 50 |
public static function get_instance() { |
| 51 |
if (is_null(self::$_instance)) { |
| 52 |
self::$_instance = new self(); |
| 53 |
} |
| 54 |
return self::$_instance; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Plugin constructor. |
| 59 |
* Initializing Templately plugin. |
| 60 |
* |
| 61 |
* @access private |
| 62 |
*/ |
| 63 |
private function __construct() { |
| 64 |
if (defined('TEMPLATELY_VERSION')) { |
| 65 |
self::$version = TEMPLATELY_VERSION; |
| 66 |
} else { |
| 67 |
self::$version = '0.0.1'; |
| 68 |
} |
| 69 |
Installer::init(); |
| 70 |
Loader::add_action('admin_init', $this, 'migrate'); |
| 71 |
self::$plugin_name = 'templately'; |
| 72 |
$this->admin = Admin::get_instance(); |
| 73 |
REST::get_instance(); |
| 74 |
$this->elementor = Elementor::get_instance(); |
| 75 |
self::run(); |
| 76 |
do_action('templately_init'); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Run all actions and hooks |
| 81 |
* |
| 82 |
* @return void |
| 83 |
*/ |
| 84 |
public static function run() { |
| 85 |
/** |
| 86 |
* Loader will run actions and filters function for the plugin. |
| 87 |
*/ |
| 88 |
Loader::run(); |
| 89 |
} |
| 90 |
/** |
| 91 |
* Migrate Users to Global Signed In if they are already logged in. |
| 92 |
* @since 1.1.5 |
| 93 |
* @return void |
| 94 |
*/ |
| 95 |
public static function migrate(){ |
| 96 |
$templately_old_version = \get_option('_templately_migrate' ); |
| 97 |
if( \version_compare(TEMPLATELY_VERSION, $templately_old_version, '>') && \version_compare($templately_old_version, '1.1.4', '=') ) { |
| 98 |
if( \get_option( '_templately_connected', false ) ) { |
| 99 |
if( \current_user_can('manage_options') ) { |
| 100 |
\update_option( '_templately_user_login_choice', ['choice' => true, 'id' => \get_current_user_id() ] ); |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
if( \version_compare(TEMPLATELY_VERSION, '1.2.0', '=') && ! \get_option('_templately_verification_migrate', false ) ) { |
| 105 |
if( DB::get_user_specific_login_meta( '_templately_connected', false ) ) { |
| 106 |
\update_option( '_templately_verification_migrate', true ); |
| 107 |
$user_data = DB::get_user_specific_login_meta('_templately_connect_data'); |
| 108 |
$user_data['is_verified'] = true; |
| 109 |
DB::update_user_specific_login_meta( '_templately_connect_data', $user_data ); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
if( \version_compare(TEMPLATELY_VERSION, '1.2.2', '=') && \version_compare($templately_old_version, '1.2.2', '<') ) { |
| 114 |
DB::delete_option('_templately_dependencies'); |
| 115 |
DB::delete_option('_templately_tags'); |
| 116 |
DB::delete_option('_templately_categories'); |
| 117 |
} |
| 118 |
|
| 119 |
if( \version_compare(TEMPLATELY_VERSION, '1.3.0', '=') && \version_compare($templately_old_version, '1.2.3', '=') ) { |
| 120 |
DB::delete_transient( 'templately_item_counts' ); |
| 121 |
} |
| 122 |
|
| 123 |
if( \version_compare(TEMPLATELY_VERSION, '1.3.5', '=') && \version_compare($templately_old_version, '1.3.5', '<') ) { |
| 124 |
DB::delete_transient( 'templately_dependencies' ); |
| 125 |
} |
| 126 |
|
| 127 |
// SET VERSION |
| 128 |
\update_option( '_templately_migrate', TEMPLATELY_VERSION ); |
| 129 |
} |
| 130 |
/** |
| 131 |
* Get Plugin Name or You can say Text Domain |
| 132 |
* @return string |
| 133 |
*/ |
| 134 |
public static function get_name() { |
| 135 |
return self::$plugin_name; |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* Get Plugin Version |
| 140 |
* @return String |
| 141 |
*/ |
| 142 |
public static function get_version() { |
| 143 |
return self::$version; |
| 144 |
} |
| 145 |
} |
| 146 |
|