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broken-link-checker / core / class-loader.php
broken-link-checker / core Last commit date
controllers 1 year ago external 1 year ago interfaces 3 years ago models 1 year ago traits 1 year ago utils 1 year ago views 3 years ago class-activation.php 3 years ago class-deactivation.php 3 years ago class-loader.php 1 year ago
class-loader.php
392 lines
1 <?php
2 /**
3 * Class to boot up plugin.
4 *
5 * @link https://wordpress.org/plugins/broken-link-checker/
6 * @since 2.0.0
7 *
8 * @author WPMUDEV (https://wpmudev.com)
9 * @package WPMUDEV_BLC\Core
10 *
11 * @copyright (c) 2022, Incsub (http://incsub.com)
12 */
13
14 namespace WPMUDEV_BLC\Core;
15
16 // If this file is called directly, abort.
17 defined( 'WPINC' ) || die;
18
19 use DirectoryIterator;
20 use mysql_xdevapi\Exception;
21 use WPMUDEV_BLC\Core\Utils\Abstracts\Base;
22 use function file_exists;
23 use function is_dir;
24 use function is_null;
25 use function str_replace;
26 use function strtolower;
27 use function trailingslashit;
28
29 /**
30 * Class WPMUDEV_BLC
31 *
32 * @package WPMUDEV_BLC\Core
33 */
34 final class Loader extends Base {
35
36 /**
37 * Scripts to be registered for frontend.
38 *
39 * @since 2.0.0
40 *
41 * @var array $scripts Front js scripts to be enqueued.
42 */
43 public static $scripts = array();
44
45 /**
46 * Scripts to be registered for backend.
47 *
48 * @since 2.0.0
49 *
50 * @var array $admin_scripts Admin js scripts to be enqueued.
51 */
52 public static $admin_scripts = array();
53
54 /**
55 * Styles to be registered for frontend.
56 *
57 * @since 2.0.0
58 *
59 * @var array $style Front end styles to be enqueued.
60 */
61 public static $styles = array();
62
63 /**
64 * Styles to be registered for backend.
65 *
66 * @since 2.0.0
67 *
68 * @var array $style Admin styles to be enqueued.
69 */
70 public static $admin_styles = array();
71 /**
72 * Settings helper class instance.
73 *
74 * @since 2.0.0
75 * @var object
76 */
77 public $settings;
78
79 /**
80 * Minimum supported php version.
81 *
82 * @since 2.0.0
83 * @var float
84 */
85 public $php_version = '7.2';
86
87 /**
88 * Minimum WordPress version.
89 *
90 * @since 2.0.0
91 * @var float
92 */
93 public $wp_version = '5.2';
94
95 /**
96 * Initialize functionality of the plugin.
97 *
98 * This is where we kick-start the plugin by defining
99 * everything required and register all hooks.
100 *
101 * @since 2.0.0
102 * @access protected
103 * @return void
104 */
105 protected function __construct() {
106 if ( ! $this->can_boot() ) {
107 return;
108 }
109
110 $this->init();
111 }
112
113 /**
114 * Main condition that checks if plugin parts should conitnue loading.
115 *
116 * @return bool
117 */
118 private function can_boot() {
119 /**
120 * Checks
121 * - PHP version
122 * - WP Version
123 * If not then return.
124 */
125 global $wp_version;
126
127 return (
128 version_compare( PHP_VERSION, $this->php_version, '>' ) &&
129 version_compare( $wp_version, $this->wp_version, '>' )
130 );
131 }
132
133 /**
134 * Register all the actions and filters.
135 *
136 * @since 2.0.0
137 * @access private
138 * @return void
139 */
140 private function init() {
141 // Initialize the core files and the app files.
142 // Core files are the base files that the app classes can rely on.
143 // Not all core files need to be initiated.
144
145 /**
146 * Static var to check if app is loaded.
147 */
148 static $loaded = false;
149
150 if ( $loaded ) {
151 return;
152 }
153
154 $loaded = true;
155
156 /**
157 * Start Hub Connector
158 */
159 $this->register_hub_connector();
160
161 /**
162 * Start app functions.
163 */
164 add_action( 'init', array( $this, 'init_app' ), 9 );
165
166 /*
167 * Setup plugin scripts
168 */
169 add_action( 'wp_enqueue_scripts', array( $this, 'handle_front_scripts' ) );
170 add_action( 'admin_enqueue_scripts', array( $this, 'handle_admin_scripts' ) );
171
172 /**
173 * Action hook to trigger after initializing all core actions.
174 *
175 * @since 2.0.0
176 */
177 do_action( 'wpmudev_blc_after_core_init' );
178 }
179
180 /**
181 * Load all App modules.
182 *
183 * @since 2.0.0
184 * @return void
185 */
186 public function init_app() {
187 // Load text domain.
188 load_plugin_textdomain(
189 'broken-link-checker',
190 false,
191 dirname( WPMUDEV_BLC_BASENAME ) . '/languages'
192 );
193
194 /*
195 * Load plugin components. (Admin pages, Shortcodes, Rest Endpoints etc).
196 * Structures that build the plugins features and ui.
197 */
198 $this->load_components(
199 apply_filters(
200 'wpmudev_blc_load_components',
201 array(
202 'Action_Links',
203 'Admin_Pages',
204 'Admin_Notices',
205 'Admin_Modals',
206 'Rest_Endpoints',
207 'Emails',
208 'Webhooks',
209 'Virtual_Posts',
210 'Scheduled_Events',
211 'Hub_Endpoints',
212 'Options',
213 'Submodules',
214 )
215 )
216 );
217 }
218
219 /**
220 * Register Hub connector submodule.
221 *
222 * @return void
223 */
224 public function register_hub_connector() {
225 if ( ! file_exists( WPMUDEV_BLC_DIR . 'core/external/hub-connector/connector.php' ) ) {
226 return;
227 }
228
229 require_once WPMUDEV_BLC_DIR . 'core/external/hub-connector/connector.php';
230
231 $options = array(
232 'screens' => array( 'toplevel_page_blc_dash' ),
233 'extra_args' => array(
234 'register' => array(
235 'connect_ref' => 'blc',
236 'utm_source' => 'blc',
237 'utm_medium' => 'plugin',
238 'utm_campaign' => 'blc_connector_main',
239 ),
240 ),
241 );
242
243 \WPMUDEV\Hub\Connector::get()->set_options( 'blc', $options );
244 }
245
246 /**
247 * Loads components.
248 *
249 * @since 2.0.0
250 *
251 * @param array $components An array of components (root folder names).
252 */
253 private function load_components( $components = array() ) {
254 if ( ! empty( $components ) ) {
255 array_map(
256 array( $this, 'load_component' ),
257 $components
258 );
259 }
260 }
261
262 /**
263 * Registers and enqueues plugin scripts and styles for backend
264 *
265 * @since 2.0.0
266 */
267 public function handle_admin_scripts() {
268 if ( ! empty( self::$admin_scripts ) ) {
269 $this->handle_scripts( self::$admin_scripts );
270 }
271
272 if ( ! empty( self::$admin_styles ) ) {
273 $this->handle_styles( self::$admin_styles );
274 }
275 }
276
277 /**
278 * Registers and enqueues plugin styles for frontend
279 *
280 * @since 2.0.0
281 *
282 * @param array $scripts An array with all scripts to be enqueued.
283 */
284 public function handle_scripts( $scripts = array() ) {
285 if ( ! empty( $scripts ) ) {
286 foreach ( $scripts as $handle => $script ) {
287 $src = $script['src'] ?? '';
288 $deps = $script['deps'] ?? array();
289 $ver = $script['ver'] ?? WPMUDEV_BLC_SCIPTS_VERSION;
290 $in_footer = $script['in_footer'] ?? false;
291 $has_translation = $script['translate'] ?? false;
292
293 wp_register_script( $handle, $src, $deps, $ver, $in_footer );
294
295 if ( isset( $script['localize'] ) ) {
296 foreach ( $script['localize'] as $object_name => $localize_array ) {
297 wp_localize_script( $handle, $object_name, $localize_array );
298 }
299 }
300
301 wp_enqueue_script( $handle );
302
303 if ( $has_translation ) {
304 wp_set_script_translations(
305 $handle,
306 'broken-link-checker',
307 plugin_dir_path( __FILE__ ) . 'languages'
308 );
309 }
310 }
311 }
312 }
313
314 /**
315 * Registers and enqueues plugin css files.
316 *
317 * @since 2.0.0
318 *
319 * @param array $styles An array with all styles to be enqueued.
320 */
321 public function handle_styles( $styles = array() ) {
322 if ( ! empty( $styles ) ) {
323 foreach ( $styles as $handle => $style ) {
324 $src = $style['src'] ?? '';
325 $deps = $style['deps'] ?? array();
326 $ver = $style['ver'] ?? WPMUDEV_BLC_SCIPTS_VERSION;
327 $media = $style['media'] ?? 'all';
328
329 wp_register_style( $handle, $src, $deps, $ver, $media );
330 wp_enqueue_style( $handle );
331 }
332 }
333 }
334
335 /**
336 * Registers and enqueues plugin scripts and styles for backend
337 *
338 * @since 2.0.0
339 */
340 public function handle_front_scripts() {
341 if ( ! empty( self::$scripts ) ) {
342 $this->handle_scripts( self::$scripts );
343 }
344
345 if ( ! empty( self::$styles ) ) {
346 $this->handle_styles( self::$styles );
347 }
348 }
349
350 /**
351 * Loads component's controller.
352 *
353 * @since 2.0.0
354 *
355 * @param string $component The component name which is the folder name that contains the component files (mvc etc).
356 * @param string $namespace_prefix The namespace where the component belongs to. Default is App which derives from the `plugin_path/app` main folder.
357 * @throws \Exception If class controller file not found.
358 */
359 private function load_component( $component = null, $namespace_prefix = 'App' ) {
360 if ( ! is_null( $component ) ) {
361 $component_path_part = str_replace( '_', '-', $component );
362 $component_path = trailingslashit( WPMUDEV_BLC_DIR ) . strtolower( trailingslashit( $namespace_prefix ) . trailingslashit( $component_path_part ) );
363
364 if ( is_dir( $component_path ) ) {
365 $component_dir = new DirectoryIterator( $component_path );
366
367 foreach ( $component_dir as $fileinfo ) {
368 if ( $fileinfo->isDir() && ! $fileinfo->isDot() ) {
369 $component_item_dir = $fileinfo->getFilename();
370 $component_item = str_replace( '-', '_', $component_item_dir );
371
372 if ( file_exists( trailingslashit( $component_path ) . trailingslashit( $component_item_dir ) . 'class-controller.php' ) ) {
373 $component_item = "WPMUDEV_BLC\\{$namespace_prefix}\\{$component}\\{$component_item}\\Controller";
374
375 try {
376 if ( method_exists( $component_item::instance(), 'init' ) ) {
377 $component_item::instance()->init();
378 } else {
379 throw new \Exception( 'Method init() is missing from class ' . get_class( $component_item::instance() ) );
380 }
381 } catch ( \Exception $e ) {
382 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
383 error_log( $e->getMessage() );
384 }
385 }
386 }
387 }
388 }
389 }
390 }
391 }
392