| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS; |
| 4 |
|
| 5 |
|
| 6 |
defined('ABSPATH') || exit; |
| 7 |
|
| 8 |
/** |
| 9 |
* Media Cloud Sync Plugin by Dudlewebs |
| 10 |
* |
| 11 |
* The main plugin handler class is responsible for initializing Plugin. |
| 12 |
* |
| 13 |
* @since 1.0.0 |
| 14 |
*/ |
| 15 |
class Main { |
| 16 |
/** |
| 17 |
* Instance. |
| 18 |
* |
| 19 |
* Holds the plugin instance. |
| 20 |
* |
| 21 |
* @since 1.0.0 |
| 22 |
* @access public |
| 23 |
* @static |
| 24 |
* |
| 25 |
* @var Plugin |
| 26 |
*/ |
| 27 |
public static $instance = null; |
| 28 |
|
| 29 |
/** |
| 30 |
* Plugin constructor.+ |
| 31 |
* |
| 32 |
* Initializing plugin. |
| 33 |
* |
| 34 |
* @since 1.0.0 |
| 35 |
* @access private |
| 36 |
*/ |
| 37 |
private function __construct(){ |
| 38 |
$this->register_autoloader(); |
| 39 |
add_action('init', [$this, 'init'], 0); |
| 40 |
add_action('rest_api_init', [$this, 'on_rest_api_init'], 9); |
| 41 |
|
| 42 |
$adminInstance = Admin::instance(); |
| 43 |
// reg activation hook. |
| 44 |
register_activation_hook(WPMCS_FILE, [$adminInstance, 'install']); |
| 45 |
// reg deactivation hook. |
| 46 |
register_deactivation_hook(WPMCS_FILE, [$adminInstance, 'deactivation']); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Register autoloader. |
| 51 |
* |
| 52 |
* Elementor autoloader loads all the classes needed to run the plugin. |
| 53 |
* |
| 54 |
* @since 1.6.0 |
| 55 |
* @access private |
| 56 |
*/ |
| 57 |
private function register_autoloader(){ |
| 58 |
require_once WPMCS_INCLUDES_PATH.'autoloader.php'; |
| 59 |
|
| 60 |
Autoloader::run(); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
/** |
| 65 |
* Instance. |
| 66 |
* |
| 67 |
* Ensures only one instance of the plugin class is loaded or can be loaded. |
| 68 |
* |
| 69 |
* @return Plugin An instance of the class. |
| 70 |
* @since 1.0.0 |
| 71 |
* @access public |
| 72 |
* @static |
| 73 |
* |
| 74 |
*/ |
| 75 |
public static function instance(){ |
| 76 |
if (is_null(self::$instance)) { |
| 77 |
self::$instance = new self(); |
| 78 |
} |
| 79 |
|
| 80 |
return self::$instance; |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Init. |
| 85 |
* |
| 86 |
* Initialize Plugin. Register support for all the |
| 87 |
* supported post types and initialize components. |
| 88 |
* |
| 89 |
* @since 1.0.0 |
| 90 |
* @access public |
| 91 |
*/ |
| 92 |
public function init(){ |
| 93 |
$this->init_components(); |
| 94 |
$this->init_services(); |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Init components. |
| 99 |
* |
| 100 |
* @since 1.0.0 |
| 101 |
* @access private |
| 102 |
*/ |
| 103 |
private function init_components(){ |
| 104 |
/** |
| 105 |
* All backend API has to initiallize outside is_admin(), as REST URL is not part of wp_admin |
| 106 |
*/ |
| 107 |
Schema::init(); |
| 108 |
Api::instance(); |
| 109 |
|
| 110 |
Front::instance(); |
| 111 |
|
| 112 |
if (is_admin()) { |
| 113 |
Admin::instance(); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* Init Services. |
| 119 |
* |
| 120 |
* @since 1.0.0 |
| 121 |
* @access private |
| 122 |
*/ |
| 123 |
public function init_services(){ |
| 124 |
/** |
| 125 |
* Create global variable for accessing service |
| 126 |
*/ |
| 127 |
global $wpmcsItem; |
| 128 |
global $wpmcsService; |
| 129 |
$wpmcsItem = Item::instance(); |
| 130 |
$wpmcsService = Service::instance(); |
| 131 |
|
| 132 |
Media::instance(); |
| 133 |
Cdn::instance(); |
| 134 |
Cache::instance(); |
| 135 |
MediaLibrary::instance(); |
| 136 |
FilterContent::instance(); |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
/** |
| 141 |
* @since 1.0.0 |
| 142 |
* @access public |
| 143 |
*/ |
| 144 |
public function on_rest_api_init(){ |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Clone. |
| 149 |
* |
| 150 |
* Disable class cloning and throw an error on object clone. |
| 151 |
* |
| 152 |
* The whole idea of the singleton design pattern is that there is a single |
| 153 |
* object. Therefore, we don't want the object to be cloned. |
| 154 |
* |
| 155 |
* @access public |
| 156 |
* @since 1.0.0 |
| 157 |
*/ |
| 158 |
public function __clone(){ |
| 159 |
// Cloning instances of the class is forbidden. |
| 160 |
_doing_it_wrong(__FUNCTION__, esc_html__('Something went wrong.', 'media-cloud-sync'), '1.0.0'); |
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* Wakeup. |
| 165 |
* |
| 166 |
* Disable unserializing of the class. |
| 167 |
* |
| 168 |
* @access public |
| 169 |
* @since 1.0.0 |
| 170 |
*/ |
| 171 |
public function __wakeup(){ |
| 172 |
// Unserializing instances of the class is forbidden. |
| 173 |
_doing_it_wrong(__FUNCTION__, esc_html__('Something went wrong.', 'media-cloud-sync'), '1.0.0'); |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
Main::instance(); |