PluginProbe
Image Optimization – Compress Images and Convert to WebP or AVIF / 1.7.6
Image Optimization – Compress Images and Convert to WebP or AVIF v1.7.6
1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 All 32 releases
image-optimization / plugin.php

plugin.php in Image Optimization – Compress Images and Convert to WebP or AVIF 1.7.6, at plugin.php

110 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ImageOptimization;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 /**
9 * Class Plugin
10 * Main Plugin class
11 */
12 class Plugin {
13 /**
14 * Instance
15 *
16 * @access public
17 * @static
18 *
19 * @var Plugin The single instance of the class.
20 */
21 public static $instance = null;
22
23 /**
24 * Modules Manager
25 * @var null|Manager
26 */
27 public $modules_manager = null;
28
29 /**
30 * class aliases
31 * @access private
32 * @var array
33 */
34 private $classes_aliases = [];
35
36 /**
37 * Instance
38 *
39 * Ensures only one instance of the class is loaded or can be loaded.
40 *
41 * @access public
42 *
43 * @return Plugin An instance of the class.
44 */
45 public static function instance() {
46 if ( is_null( self::$instance ) ) {
47 self::$instance = new self();
48 }
49
50 return self::$instance;
51 }
52
53 public function autoload( $class ) {
54 if ( 0 !== strpos( $class, __NAMESPACE__ ) ) {
55 return;
56 }
57
58 $has_class_alias = isset( $this->classes_aliases[ $class ] );
59
60 // Backward Compatibility: Save old class name for set an alias after the new class is loaded
61 if ( $has_class_alias ) {
62 $class_alias_name = $this->classes_aliases[ $class ];
63 $class_to_load = $class_alias_name;
64 } else {
65 $class_to_load = $class;
66 }
67
68 if ( ! class_exists( $class_to_load ) ) {
69 $filename = strtolower(
70 preg_replace(
71 [ '/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ],
72 [ '', '$1-$2', '-', DIRECTORY_SEPARATOR ],
73 $class_to_load
74 )
75 );
76 $filename = IMAGE_OPTIMIZATION_PATH . $filename . '.php';
77
78 if ( is_readable( $filename ) ) {
79 include $filename;
80 }
81 }
82
83 if ( $has_class_alias ) {
84 class_alias( $class_alias_name, $class );
85 }
86 }
87
88 private function includes() {
89 require_once IMAGE_OPTIMIZATION_PATH . 'includes/modules-manager.php';
90 $this->modules_manager = new Manager();
91 }
92
93 /**
94 * Plugin class constructor
95 *
96 * Register plugin action hooks and filters
97 *
98 * @access public
99 */
100 public function __construct() {
101 static $autoloader_registered = false;
102 if ( ! $autoloader_registered ) {
103 $autoloader_registered = spl_autoload_register( [ $this, 'autoload' ] );
104 }
105 $this->includes();
106 }
107 }
108 // Instantiate Plugin Class
109 Plugin::instance();
110