deprecated
1 month ago
Aliases.php
2 months ago
Config.php
5 months ago
Control.php
5 months ago
Deprecated.php
5 months ago
Field.php
2 months ago
Framework.php
5 months ago
Init.php
2 months ago
Kirki.php
2 months ago
Modules.php
2 months ago
Pro_Namespace_Compatibility.php
5 months ago
Sanitize_Values.php
5 months ago
Scripts.php
2 months ago
Settings.php
5 months ago
Values.php
5 months ago
Pro_Namespace_Compatibility.php
93 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Backward compatibility for old Kirki Pro namespace. |
| 4 | * |
| 5 | * This file provides class aliases for the old \Kirki\Pro\* namespace |
| 6 | * to maintain backward compatibility after removing the Pro namespace. |
| 7 | * |
| 8 | * @package Kirki |
| 9 | * @since 5.1.1 |
| 10 | */ |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | // Prevent registering multiple times. |
| 15 | if ( defined( 'KIRKI_PRO_NAMESPACE_COMPATIBILITY_LOADED' ) ) { |
| 16 | return; |
| 17 | } |
| 18 | |
| 19 | define( 'KIRKI_PRO_NAMESPACE_COMPATIBILITY_LOADED', true ); |
| 20 | |
| 21 | /** |
| 22 | * Autoloader for old Pro namespace classes. |
| 23 | * |
| 24 | * This autoloader intercepts attempts to load old Pro namespace classes |
| 25 | * and loads the corresponding new namespace class instead. |
| 26 | * It uses lazy loading to avoid loading classes before WordPress Customizer is available. |
| 27 | */ |
| 28 | spl_autoload_register( |
| 29 | function ( $class ) { |
| 30 | // Only handle \Kirki\Pro\* classes. |
| 31 | if ( 0 !== strpos( $class, 'Kirki\\Pro\\' ) ) { |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | $new_class = str_replace( 'Kirki\\Pro\\', 'Kirki\\', $class ); |
| 36 | |
| 37 | if ( class_exists( $new_class, false ) ) { |
| 38 | class_alias( $new_class, $class ); |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | // Control classes extend WP_Customize_Control, so WordPress Customizer must be loaded first. |
| 43 | $is_control_class = ( 0 === strpos( $new_class, 'Kirki\\Control\\' ) ); |
| 44 | |
| 45 | // For Control classes, WP_Customize_Control must be available. |
| 46 | if ( $is_control_class && ! class_exists( 'WP_Customize_Control', false ) ) { |
| 47 | // Defer loading until WordPress Customizer is ready. |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | // Try to trigger the main autoloader first. |
| 52 | if ( class_exists( $new_class ) ) { |
| 53 | class_alias( $new_class, $class ); |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | // Try to load the new class file manually if autoloader didn't find it. |
| 58 | $relative_class = str_replace( 'Kirki\\', '', $new_class ); |
| 59 | $relative_path = str_replace( '\\', '/', $relative_class ) . '.php'; |
| 60 | |
| 61 | // Check in Field and Control directories. |
| 62 | $base_dir = dirname( dirname( __DIR__ ) ) . '/'; |
| 63 | $packages = array( 'controls/margin-padding', 'controls/headline-divider', 'controls/input-slider', 'controls/responsive', 'controls/tabs' ); |
| 64 | |
| 65 | foreach ( $packages as $package ) { |
| 66 | $file_name = basename( $relative_path ); |
| 67 | |
| 68 | $field_file = $base_dir . $package . '/src/Field/' . $file_name; |
| 69 | if ( file_exists( $field_file ) ) { |
| 70 | require_once $field_file; |
| 71 | if ( class_exists( $new_class, false ) ) { |
| 72 | class_alias( $new_class, $class ); |
| 73 | } |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | // Check Control directory (requires WP_Customize_Control). |
| 78 | $control_file = $base_dir . $package . '/src/Control/' . $file_name; |
| 79 | if ( file_exists( $control_file ) && class_exists( 'WP_Customize_Control', false ) ) { |
| 80 | require_once $control_file; |
| 81 | if ( class_exists( $new_class, false ) ) { |
| 82 | class_alias( $new_class, $class ); |
| 83 | } |
| 84 | return; |
| 85 | } |
| 86 | } |
| 87 | }, |
| 88 | true, // Throw exception if class not found. |
| 89 | true // Prepend to autoload stack (high priority). |
| 90 | ); |
| 91 | |
| 92 | |
| 93 |