PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 3.1.8
Kirki – Freeform Page Builder, Website Builder & Customizer v3.1.8
6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / class-kirki-autoload.php
kirki Last commit date
assets 4 years ago controls 4 years ago core 4 years ago deprecated 4 years ago field 4 years ago lib 4 years ago modules 4 years ago CHANGELOG.md 4 years ago LICENSE 4 years ago class-kirki-autoload.php 4 years ago kirki.php 4 years ago readme.txt 4 years ago upgrade-notifications.php 4 years ago
class-kirki-autoload.php
124 lines
1 <?php
2 /**
3 * The Kirki autoloader.
4 * Handles locating and loading other class-files.
5 *
6 * @package Kirki
7 * @category Core
8 * @author Ari Stathopoulos (@aristath)
9 * @copyright Copyright (c) 2020, David Vongries
10 * @license https://opensource.org/licenses/MIT
11 * @since 1.0
12 */
13
14 /**
15 * Autoloader class.
16 *
17 * @since 3.0.10
18 */
19 class Kirki_Autoload {
20
21 /**
22 * Cached paths.
23 *
24 * @access private
25 * @since 3.0.10
26 * @var array
27 */
28 private $cached_paths = array();
29
30 /**
31 * Class constructor.
32 *
33 * @access public
34 * @since 3.0.10
35 */
36 public function __construct() {
37
38 spl_autoload_register( array( $this, 'autoload' ) );
39 }
40
41 /**
42 * The Kirki class autoloader.
43 * Finds the path to a class that we're requiring and includes the file.
44 *
45 * @access protected
46 * @since 3.0.10
47 * @param string $class_name The name of the class we're trying to load.
48 */
49 protected function autoload( $class_name ) {
50
51 // Not a Kirki file, early exit.
52 if ( 0 !== stripos( $class_name, 'Kirki' ) ) {
53 return;
54 }
55
56 // Check if we've got it cached and ready.
57 if ( isset( $this->cached_paths[ $class_name ] ) && file_exists( $this->cached_paths[ $class_name ] ) ) {
58 include_once $this->cached_paths[ $class_name ]; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude
59 return;
60 }
61
62 $paths = $this->get_paths( $class_name );
63
64 foreach ( $paths as $path ) {
65 $path = wp_normalize_path( $path );
66 if ( file_exists( $path ) ) {
67 $this->cached_paths[ $class_name ] = $path;
68 include_once $path; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude
69 return;
70 }
71 }
72 }
73
74 /**
75 * Get an array of possible paths for the file.
76 *
77 * @access protected
78 * @since 3.0.10
79 * @param string $class_name The name of the class we're trying to load.
80 * @return array
81 */
82 protected function get_paths( $class_name ) {
83
84 $paths = array();
85 // Build the filename.
86 $filename = 'class-' . strtolower( str_replace( '_', '-', $class_name ) ) . '.php';
87
88 // Break class-name is parts.
89 $name_parts = explode( '_', str_replace( 'Kirki_', '', $class_name ) );
90
91 // Handle modules loading.
92 if ( isset( $name_parts[0] ) && 'Modules' === $name_parts[0] ) {
93 $path = dirname( __FILE__ ) . '/modules/';
94 $path .= strtolower( str_replace( '_', '-', str_replace( 'Kirki_Modules_', '', $class_name ) ) ) . '/';
95 $paths[] = $path . $filename;
96 } elseif ( 'Kirki_Fonts' === $class_name ) {
97 $paths[] = dirname( __FILE__ ) . '/modules/webfonts/class-kirki-fonts.php';
98 }
99
100 if ( isset( $name_parts[0] ) ) {
101
102 // Handle controls loading.
103 if ( 'Control' === $name_parts[0] || 'Settings' === $name_parts[0] ) {
104 $path = dirname( __FILE__ ) . '/controls/php/';
105 $paths[] = $path . $filename;
106 }
107 }
108
109 $paths[] = dirname( __FILE__ ) . '/core/' . $filename;
110 $paths[] = dirname( __FILE__ ) . '/lib/' . $filename;
111
112 $substr = str_replace( 'Kirki_', '', $class_name );
113 $exploded = explode( '_', $substr );
114 $levels = count( $exploded );
115
116 $previous_path = '';
117 for ( $i = 0; $i < $levels; $i++ ) {
118 $paths[] = dirname( __FILE__ ) . '/' . $previous_path . strtolower( $exploded[ $i ] ) . '/' . $filename;
119 $previous_path .= strtolower( $exploded[ $i ] ) . '/';
120 }
121 return $paths;
122 }
123 }
124