PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 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 All 36 releases
media-cloud-sync / includes / main.php

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

181 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 StreamWrapper::instance();
133
134 // Integrations
135 Integration::instance();
136 FilterContent::instance();
137
138 // Background Processing
139 BGRunner::instance();
140 Sync::instance();
141 }
142
143
144 /**
145 * @since 1.0.0
146 * @access public
147 */
148 public function on_rest_api_init(){
149 }
150
151 /**
152 * Clone.
153 *
154 * Disable class cloning and throw an error on object clone.
155 *
156 * The whole idea of the singleton design pattern is that there is a single
157 * object. Therefore, we don't want the object to be cloned.
158 *
159 * @access public
160 * @since 1.0.0
161 */
162 public function __clone(){
163 // Cloning instances of the class is forbidden.
164 _doing_it_wrong(__FUNCTION__, esc_html__('Something went wrong.', 'media-cloud-sync'), '1.0.0');
165 }
166
167 /**
168 * Wakeup.
169 *
170 * Disable unserializing of the class.
171 *
172 * @access public
173 * @since 1.0.0
174 */
175 public function __wakeup(){
176 // Unserializing instances of the class is forbidden.
177 _doing_it_wrong(__FUNCTION__, esc_html__('Something went wrong.', 'media-cloud-sync'), '1.0.0');
178 }
179 }
180
181 Main::instance();