PluginProbe
Cookie Consent – GDPR & CCPA Cookie Banner & Consent Manager / 0.0.5
Cookie Consent – GDPR & CCPA Cookie Banner & Consent Manager v0.0.5
0.0.11 0.0.10 0.0.9 0.0.8 0.0.7 0.0.6 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5
cookiez / plugin.php

plugin.php in Cookie Consent – GDPR & CCPA Cookie Banner & Consent Manager 0.0.5, 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 Cookiez;
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 array $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(): ?Plugin {
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 = COOKIEZ_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 COOKIEZ_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