PluginProbe
Media Cloud Sync / trunk
Media Cloud Sync vtrunk
1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 All 34 releases
media-cloud-sync / includes / main.php

main.php in Media Cloud Sync trunk, at includes/main.php

180 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
40 // Register install / uninstall statically so activation does not instantiate
41 // Admin (and therefore does not attach any of its admin-side hooks).
42 register_activation_hook(WPMCS_FILE, [Admin::class, 'install']);
43 register_deactivation_hook(WPMCS_FILE, [Admin::class, 'deactivation']);
44
45 if (!Notices::instance()->is_environment_compatible()) {
46 return;
47 }
48
49 add_action('init', [$this, 'init'], 0);
50 add_action('rest_api_init', [$this, 'on_rest_api_init'], 9);
51 }
52
53
54 /**
55 * Register autoloader.
56 *
57 * Elementor autoloader loads all the classes needed to run the plugin.
58 *
59 * @since 1.6.0
60 * @access private
61 */
62 private function register_autoloader(){
63 require_once WPMCS_INCLUDES_PATH.'autoloader.php';
64
65 Autoloader::run();
66 }
67
68
69 /**
70 * Instance.
71 *
72 * Ensures only one instance of the plugin class is loaded or can be loaded.
73 *
74 * @return Plugin An instance of the class.
75 * @since 1.0.0
76 * @access public
77 * @static
78 *
79 */
80 public static function instance(){
81 if (is_null(self::$instance)) {
82 self::$instance = new self();
83 }
84
85 return self::$instance;
86 }
87
88 /**
89 * Init.
90 *
91 * Initialize Plugin. Register support for all the
92 * supported post types and initialize components.
93 *
94 * @since 1.0.0
95 * @access public
96 */
97 public function init(){
98 $this->init_components();
99 $this->init_services();
100 }
101
102 /**
103 * Init components.
104 *
105 * @since 1.0.0
106 * @access private
107 */
108 private function init_components(){
109 /**
110 * All backend API has to initiallize outside is_admin(), as REST URL is not part of wp_admin
111 */
112 Front::instance();
113
114 if (is_admin()) {
115 Admin::instance();
116 Upgrade::instance();
117 }
118
119 Api::instance();
120 }
121
122 /**
123 * Init Services.
124 *
125 * @since 1.0.0
126 * @access private
127 */
128 public function init_services(){
129 Cdn::instance();
130 Cache::instance();
131 Compatibility::instance();
132
133 // Integrations
134 Integration::instance();
135 FilterContent::instance();
136
137 // Background Processing
138 BGRunner::instance();
139 Sync::instance();
140 }
141
142
143 /**
144 * @since 1.0.0
145 * @access public
146 */
147 public function on_rest_api_init(){
148 }
149
150 /**
151 * Clone.
152 *
153 * Disable class cloning and throw an error on object clone.
154 *
155 * The whole idea of the singleton design pattern is that there is a single
156 * object. Therefore, we don't want the object to be cloned.
157 *
158 * @access public
159 * @since 1.0.0
160 */
161 public function __clone(){
162 // Cloning instances of the class is forbidden.
163 _doing_it_wrong(__FUNCTION__, esc_html__('Something went wrong.', 'media-cloud-sync'), '1.0.0');
164 }
165
166 /**
167 * Wakeup.
168 *
169 * Disable unserializing of the class.
170 *
171 * @access public
172 * @since 1.0.0
173 */
174 public function __wakeup(){
175 // Unserializing instances of the class is forbidden.
176 _doing_it_wrong(__FUNCTION__, esc_html__('Something went wrong.', 'media-cloud-sync'), '1.0.0');
177 }
178 }
179
180 Main::instance();