PluginProbe
Media Cloud Sync / 1.3.10
Media Cloud Sync v1.3.10
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 1.3.10, at includes/main.php

221 lines 5.4 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 (!$this->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 * Check minimum PHP/WP requirements and queue an admin notice if missing.
55 *
56 * @return bool
57 * @since 1.3.10
58 */
59 private function is_environment_compatible(){
60 if (!version_compare(PHP_VERSION, '8.1', '>=')) {
61 add_action('admin_notices', [$this, 'php_version_check_fail']);
62 return false;
63 }
64 if (!version_compare(get_bloginfo('version'), '5.2', '>=')) {
65 add_action('admin_notices', [$this, 'wp_version_check_fail']);
66 return false;
67 }
68 return true;
69 }
70
71 /**
72 * Plugin admin notice for minimum PHP version.
73 *
74 * @return void
75 * @since 1.3.10
76 */
77 public function php_version_check_fail(){
78 /* translators: 1: Plugin name, 2: PHP version. */
79 $message = sprintf(esc_html__('%1$s requires PHP version %2$s+, plugin is currently not running.', 'media-cloud-sync'), WPMCS_PLUGIN_NAME, '8.1');
80 echo wp_kses_post(sprintf('<div class="error">%s</div>', wpautop($message)));
81 }
82
83 /**
84 * Plugin admin notice for minimum WordPress version.
85 *
86 * @return void
87 * @since 1.3.10
88 */
89 public function wp_version_check_fail(){
90 /* translators: 1: Plugin name, 2: WordPress version. */
91 $message = sprintf(esc_html__('%1$s requires WordPress version %2$s+. Because you are using an earlier version, the plugin is currently not running.', 'media-cloud-sync'), WPMCS_PLUGIN_NAME, '5.2');
92 echo wp_kses_post(sprintf('<div class="error">%s</div>', wpautop($message)));
93 }
94
95 /**
96 * Register autoloader.
97 *
98 * Elementor autoloader loads all the classes needed to run the plugin.
99 *
100 * @since 1.6.0
101 * @access private
102 */
103 private function register_autoloader(){
104 require_once WPMCS_INCLUDES_PATH.'autoloader.php';
105
106 Autoloader::run();
107 }
108
109
110 /**
111 * Instance.
112 *
113 * Ensures only one instance of the plugin class is loaded or can be loaded.
114 *
115 * @return Plugin An instance of the class.
116 * @since 1.0.0
117 * @access public
118 * @static
119 *
120 */
121 public static function instance(){
122 if (is_null(self::$instance)) {
123 self::$instance = new self();
124 }
125
126 return self::$instance;
127 }
128
129 /**
130 * Init.
131 *
132 * Initialize Plugin. Register support for all the
133 * supported post types and initialize components.
134 *
135 * @since 1.0.0
136 * @access public
137 */
138 public function init(){
139 $this->init_components();
140 $this->init_services();
141 }
142
143 /**
144 * Init components.
145 *
146 * @since 1.0.0
147 * @access private
148 */
149 private function init_components(){
150 /**
151 * All backend API has to initiallize outside is_admin(), as REST URL is not part of wp_admin
152 */
153 Front::instance();
154
155 if (is_admin()) {
156 Admin::instance();
157 Upgrade::instance();
158 }
159
160 Api::instance();
161 }
162
163 /**
164 * Init Services.
165 *
166 * @since 1.0.0
167 * @access private
168 */
169 public function init_services(){
170 Cdn::instance();
171 Cache::instance();
172 Compatibility::instance();
173
174 // Integrations
175 Integration::instance();
176 FilterContent::instance();
177
178 // Background Processing
179 BGRunner::instance();
180 Sync::instance();
181 }
182
183
184 /**
185 * @since 1.0.0
186 * @access public
187 */
188 public function on_rest_api_init(){
189 }
190
191 /**
192 * Clone.
193 *
194 * Disable class cloning and throw an error on object clone.
195 *
196 * The whole idea of the singleton design pattern is that there is a single
197 * object. Therefore, we don't want the object to be cloned.
198 *
199 * @access public
200 * @since 1.0.0
201 */
202 public function __clone(){
203 // Cloning instances of the class is forbidden.
204 _doing_it_wrong(__FUNCTION__, esc_html__('Something went wrong.', 'media-cloud-sync'), '1.0.0');
205 }
206
207 /**
208 * Wakeup.
209 *
210 * Disable unserializing of the class.
211 *
212 * @access public
213 * @since 1.0.0
214 */
215 public function __wakeup(){
216 // Unserializing instances of the class is forbidden.
217 _doing_it_wrong(__FUNCTION__, esc_html__('Something went wrong.', 'media-cloud-sync'), '1.0.0');
218 }
219 }
220
221 Main::instance();