compatibility
1 month ago
controls
2 months ago
fields
2 months ago
modules
2 months ago
utils
3 weeks ago
autoload.php
5 months ago
index.php
5 months ago
autoload.php
74 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Lightweight PSR-4 autoloader for Kirki packages. |
| 4 | * |
| 5 | * This replaces the per-package Composer vendor folders so we only keep |
| 6 | * one shared autoloader and source files to reduce build size. |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | // Prevent registering multiple times. |
| 12 | if ( defined( 'KIRKI_AUTOLOAD_REGISTERED' ) ) { |
| 13 | return; |
| 14 | } |
| 15 | |
| 16 | define( 'KIRKI_AUTOLOAD_REGISTERED', true ); |
| 17 | |
| 18 | $packages = array( |
| 19 | 'headline-divider' => 'HeadlineDivider', |
| 20 | 'input-slider' => 'InputSlider', |
| 21 | 'margin-padding' => 'MarginPadding', |
| 22 | 'responsive' => 'Responsive', |
| 23 | 'tabs' => 'Tabs', |
| 24 | ); |
| 25 | |
| 26 | $base_dir = __DIR__ . '/controls/'; |
| 27 | |
| 28 | $psr4_map = array( |
| 29 | 'Kirki\\Control\\' => array(), |
| 30 | 'Kirki\\Field\\' => array(), |
| 31 | ); |
| 32 | |
| 33 | foreach ( $packages as $slug => $namespace ) { |
| 34 | $package_base = $base_dir . $slug; |
| 35 | |
| 36 | $control_dir = $package_base . '/src/Control'; |
| 37 | if ( is_dir( $control_dir ) ) { |
| 38 | $psr4_map['Kirki\\Control\\'][] = $control_dir; |
| 39 | } |
| 40 | |
| 41 | $field_dir = $package_base . '/src/Field'; |
| 42 | if ( is_dir( $field_dir ) ) { |
| 43 | $psr4_map['Kirki\\Field\\'][] = $field_dir; |
| 44 | } |
| 45 | |
| 46 | $root_dir = $package_base . '/src'; |
| 47 | if ( is_dir( $root_dir ) ) { |
| 48 | $psr4_map[ 'Kirki\\' . $namespace . '\\' ][] = $root_dir; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | spl_autoload_register( |
| 53 | function ( $class ) use ( $psr4_map ) { |
| 54 | foreach ( $psr4_map as $prefix => $directories ) { |
| 55 | if ( 0 !== strpos( $class, $prefix ) ) { |
| 56 | continue; |
| 57 | } |
| 58 | |
| 59 | $relative_class = substr( $class, strlen( $prefix ) ); |
| 60 | $relative_path = str_replace( '\\', '/', $relative_class ) . '.php'; |
| 61 | |
| 62 | foreach ( $directories as $directory ) { |
| 63 | $file = $directory . '/' . $relative_path; |
| 64 | |
| 65 | if ( file_exists( $file ) ) { |
| 66 | require_once $file; |
| 67 | return; |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | ); |
| 73 | |
| 74 |