PluginProbe
Content Egg – Affiliate Product Importer & Price Comparison / 11.2.0
Content Egg – Affiliate Product Importer & Price Comparison v11.2.0
11.8.1 11.8.0 11.7.0 11.6.0 11.5.0 11.4.0 11.3.0 11.2.0 11.1.0 trunk 1.6.0 1.6.1 1.7.1 1.8.0 1.9.0 10.0.0 10.1.0 11.0.0 2.0.1 2.1.0 2.2.0 2.3.0 2.4.0 2.4.2 2.5.1 All 65 releases
content-egg / loader.php

loader.php in Content Egg – Affiliate Product Importer & Price Comparison 11.2.0, at loader.php

107 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ContentEgg;
4
5 use ContentEgg\application\vendor\CVarDumper;
6
7 defined('\ABSPATH') || exit;
8
9 /**
10 * AutoLoader class file
11 *
12 * @author keywordrush.com <support@keywordrush.com>
13 * @link https://www.keywordrush.com
14 * @copyright Copyright &copy; 2026 keywordrush.com
15 */
16 class AutoLoader
17 {
18 const NS_CUSTOM_MODULES = 'ContentEggCustomModule';
19
20 private static $base_dir;
21 private static $classMap = array();
22
23 public function __construct()
24 {
25
26 self::$base_dir = PLUGIN_PATH;
27 $this->register_auto_loader();
28 }
29
30 public function register_auto_loader()
31 {
32 spl_autoload_register(array($this, 'autoload'));
33 if (defined('\CONTENT_EGG_CUSTOM_MODULES') && \CONTENT_EGG_CUSTOM_MODULES)
34 spl_autoload_register(array($this, 'autoloadCustomModule'));
35 }
36
37 /**
38 * Implementations of PSR-4
39 * @link: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md
40 */
41 public static function autoload($className)
42 {
43 $prefix = __NAMESPACE__ . '\\';
44 // does the class use the namespace prefix?
45 $len = strlen($prefix);
46
47 if (strncmp($prefix, $className, $len) !== 0)
48 {
49 // no, move to the next registered autoloader
50 return;
51 }
52
53 // trying map autoloader first
54 if (isset(self::$classMap[$className]))
55 {
56 include(self::$base_dir . self::$classMap[$className]);
57 }
58
59 // get the relative class name
60 $relative_class = substr($className, $len);
61
62 // replace the namespace prefix with the base directory, replace namespace
63 // separators with directory separators in the relative class name, append
64 // with .php
65 $file = self::$base_dir . str_replace('\\', '/', $relative_class) . '.php';
66
67 // if the file exists, require it
68 if (file_exists($file))
69 {
70 require $file;
71 }
72 }
73
74 public static function autoloadCustomModule($className)
75 {
76 $prefix = self::NS_CUSTOM_MODULES . '\\';
77 $len = strlen($prefix);
78
79 if (strncmp($prefix, $className, $len) !== 0)
80 {
81 return;
82 }
83
84 $relative_class = substr($className, $len);
85 $path = \WP_CONTENT_DIR . DIRECTORY_SEPARATOR . CUSTOM_MODULES_DIR . DIRECTORY_SEPARATOR;
86 $file = $path . str_replace('\\', '/', $relative_class) . '.php';
87 if (file_exists($file))
88 {
89 require $file;
90 }
91 }
92 }
93
94 new AutoLoader();
95
96 function prn($var, $depth = 10, $highlight = true)
97 {
98 echo CVarDumper::dumpAsString($var, $depth, $highlight); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
99 echo '<br />';
100 }
101
102 function prnx($var, $depth = 10, $highlight = true)
103 {
104 echo CVarDumper::dumpAsString($var, $depth, $highlight); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
105 die('Exit');
106 }
107