Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion inc/customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// 载入Kirki
if ( ! class_exists( 'Kirki' ) ) {
require_once __DIR__ . '/kirki/kirki.php';
new \Kirki\Pro\Init();

define( 'KIRKI_NO_OUTPUT', true );
define( 'KIRKI_NO_GUTENBERG_OUTPUT', true );
Expand Down
1 change: 1 addition & 0 deletions inc/kirki/assets/customizer/controls.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions inc/kirki/assets/customizer/controls.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions inc/kirki/assets/customizer/preview.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@
*/

new \Kirki\Compatibility\Aliases();
new \Kirki\Compatibility\Scripts();
new \Kirki\Compatibility\Deprecated();
new \Kirki\Data\Option();
112 changes: 112 additions & 0 deletions inc/kirki/customizer/class-customizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php
/**
* The Kirki Customizer class.
*
* @package kirki
* @since 5.0.0
*/

namespace Kirki;

use Kirki\L10n;
use Kirki\Compatibility\Modules;
use Kirki\Compatibility\Framework;
use Kirki\Compatibility\Kirki;

/**
* The Customizer class.
*/
class Customizer
{

/**
* Init the customizer.
*
* @return void
*/
public static function init()
{

if (!defined('KIRKI_PLUGIN_FILE')) {
define('KIRKI_PLUGIN_FILE', dirname(__DIR__) . '/kirki.php');
}

require_once __DIR__ . '/lib/class-aricolor.php';
require_once __DIR__ . '/lib/class-kirki-color.php';
require_once dirname(__DIR__) . '/vendor/autoload.php';
require_once __DIR__ . '/bootstrap.php';

if (!defined('KIRKI_VERSION')) {
define('KIRKI_VERSION', '5.2.3');
}

if (!defined('KIRKI_PLUGIN_DIR')) {
define('KIRKI_PLUGIN_DIR', dirname(__DIR__));
}

if (!defined('KIRKI_PLUGIN_URL')) {
define('KIRKI_PLUGIN_URL', URL::get_from_path(dirname(__DIR__)));
}

// Start Kirki.
global $kirki;
$kirki = Framework::get_instance();

// Instantiate the modules.
$kirki->modules = new Modules();

// Instantiate classes.
new Kirki();
new L10n('kirki', dirname(__DIR__) . '/languages');

// Add an empty config for global fields.
Kirki::add_config('');

// Load custom config if exists.
$custom_config_path = dirname(__DIR__) . '/custom-config.php';
if (file_exists($custom_config_path)) {
require_once $custom_config_path;
}

// Add upgrade notifications.
require_once __DIR__ . '/lib/upgrade-notifications.php';

// Load packages.
require_once __DIR__ . '/packages/index.php';

// Handle tests.
if (defined('KIRKI_TEST') && true === constant('KIRKI_TEST') && file_exists(__DIR__ . '/example.php')) {
include_once __DIR__ . '/example.php';
}

// Enqueue common assets.
add_action('customize_controls_enqueue_scripts', [__CLASS__, 'enqueue_assets'], 5);
add_action('customize_preview_init', [__CLASS__, 'enqueue_assets'], 5);
}

/**
* Enqueue common assets.
*
* @param array $deps The script dependencies.
* @return void
*/
public static function enqueue_assets($deps = [])
{
// Preview frame is NOT admin, Pane frame IS admin.
$is_preview_frame = is_customize_preview() && !is_admin();

if (empty($deps)) {
$deps = ['jquery', 'wp-element'];
if ($is_preview_frame) {
$deps[] = 'customize-preview';
} else {
$deps[] = 'customize-controls';
}
}

$file = $is_preview_frame ? 'preview' : 'controls';

wp_enqueue_style('kirki-customizer', URL::get_from_path(dirname(__DIR__) . "/assets/customizer/{$file}.min.css"), [], KIRKI_VERSION);
wp_enqueue_script('kirki-customizer', URL::get_from_path(dirname(__DIR__) . "/assets/customizer/{$file}.min.js"), $deps, KIRKI_VERSION, true);
}
}
35 changes: 35 additions & 0 deletions inc/kirki/customizer/controls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Controls and Modules for the Customizer Pane
import './packages/controls/base/src/control.js';
import './packages/controls/checkbox/src/control.js';
import './packages/controls/color-palette/src/control.js';
import './packages/controls/dashicons/src/control.js';
import './packages/controls/date/src/control.js';
import './packages/controls/dimension/src/control.js';
import './packages/controls/editor/src/control.js';
import './packages/controls/generic/src/control.js';
import './packages/controls/image/src/control.js';
import './packages/controls/input-slider/src/control.js';
import './packages/controls/margin-padding/src/control.js';
import './packages/controls/multicheck/src/control.js';
import './packages/controls/palette/src/control.js';
import './packages/controls/radio/src/control.js';
import './packages/controls/react-colorful/src/control.js';
import './packages/controls/react-select/src/control.js';
import './packages/controls/repeater/src/control.js';
import './packages/controls/responsive/src/control.js';
import './packages/controls/slider/src/control.js';
import './packages/controls/sortable/src/control.js';
import './packages/controls/tabs/src/control.js';

// Fields
import './packages/fields/dimensions/src/control.scss';
import './packages/fields/typography/src/control.js';
import './packages/fields/background/src/script.js';

// Modules
import './packages/modules/field-dependencies/src/control.js';
import './packages/modules/tooltips/src/control.js';
import './packages/modules/panels/src/script.js';
import './packages/modules/sections/src/script.js';
import './packages/modules/preset/src/script.js';
import './packages/modules/section-icons/src/icons.js';
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @since 2.3.8
* @param array $plugin_data An array of plugin metadata.
* @param array $response An array of metadata about the available plugin update.
* @param object $response An object of metadata about the available plugin update.
*/
function kirki_show_upgrade_notification( $plugin_data, $response ) {

Expand All @@ -35,4 +35,6 @@ function kirki_show_upgrade_notification( $plugin_data, $response ) {
endif;
}
endif;
add_action( 'in_plugin_update_message-' . plugin_basename( __FILE__ ), 'kirki_show_upgrade_notification', 10, 2 );

$plugin_file = defined( 'KIRKI_PLUGIN_FILE' ) ? KIRKI_PLUGIN_FILE : __FILE__;
add_action( 'in_plugin_update_message-' . plugin_basename( $plugin_file ), 'kirki_show_upgrade_notification', 10, 2 );
73 changes: 73 additions & 0 deletions inc/kirki/customizer/packages/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* Lightweight PSR-4 autoloader for Kirki packages.
*
* This replaces the per-package Composer vendor folders so we only keep
* one shared autoloader and source files to reduce build size.
*/

defined( 'ABSPATH' ) || exit;

// Prevent registering multiple times.
if ( defined( 'KIRKI_AUTOLOAD_REGISTERED' ) ) {
return;
}

define( 'KIRKI_AUTOLOAD_REGISTERED', true );

$packages = array(
'headline-divider' => 'HeadlineDivider',
'input-slider' => 'InputSlider',
'margin-padding' => 'MarginPadding',
'responsive' => 'Responsive',
'tabs' => 'Tabs',
);

$base_dir = __DIR__ . '/controls/';

$psr4_map = array(
'Kirki\\Control\\' => array(),
'Kirki\\Field\\' => array(),
);

foreach ( $packages as $slug => $namespace ) {
$package_base = $base_dir . $slug;

$control_dir = $package_base . '/src/Control';
if ( is_dir( $control_dir ) ) {
$psr4_map['Kirki\\Control\\'][] = $control_dir;
}

$field_dir = $package_base . '/src/Field';
if ( is_dir( $field_dir ) ) {
$psr4_map['Kirki\\Field\\'][] = $field_dir;
}

$root_dir = $package_base . '/src';
if ( is_dir( $root_dir ) ) {
$psr4_map[ 'Kirki\\' . $namespace . '\\' ][] = $root_dir;
}
}

spl_autoload_register(
function ( $class ) use ( $psr4_map ) {
foreach ( $psr4_map as $prefix => $directories ) {
if ( 0 !== strpos( $class, $prefix ) ) {
continue;
}

$relative_class = substr( $class, strlen( $prefix ) );
$relative_path = str_replace( '\\', '/', $relative_class ) . '.php';

foreach ( $directories as $directory ) {
$file = $directory . '/' . $relative_path;

if ( file_exists( $file ) ) {
require_once $file;
return;
}
}
}
}
);

Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* Backward compatibility for old Kirki Pro namespace.
*
* This file provides class aliases for the old \Kirki\Pro\* namespace
* to maintain backward compatibility after removing the Pro namespace.
*
* @package Kirki
* @since 5.1.1
*/

defined( 'ABSPATH' ) || exit;

// Prevent registering multiple times.
if ( defined( 'KIRKI_PRO_NAMESPACE_COMPATIBILITY_LOADED' ) ) {
return;
}

define( 'KIRKI_PRO_NAMESPACE_COMPATIBILITY_LOADED', true );

/**
* Autoloader for old Pro namespace classes.
*
* This autoloader intercepts attempts to load old Pro namespace classes
* and loads the corresponding new namespace class instead.
* It uses lazy loading to avoid loading classes before WordPress Customizer is available.
*/
spl_autoload_register(
function ( $class ) {
// Only handle \Kirki\Pro\* classes.
if ( 0 !== strpos( $class, 'Kirki\\Pro\\' ) ) {
return;
}

$new_class = str_replace( 'Kirki\\Pro\\', 'Kirki\\', $class );

if ( class_exists( $new_class, false ) ) {
class_alias( $new_class, $class );
return;
}

// Control classes extend WP_Customize_Control, so WordPress Customizer must be loaded first.
$is_control_class = ( 0 === strpos( $new_class, 'Kirki\\Control\\' ) );

// For Control classes, WP_Customize_Control must be available.
if ( $is_control_class && ! class_exists( 'WP_Customize_Control', false ) ) {
// Defer loading until WordPress Customizer is ready.
return;
}

// Try to trigger the main autoloader first.
if ( class_exists( $new_class ) ) {
class_alias( $new_class, $class );
return;
}

// Try to load the new class file manually if autoloader didn't find it.
$relative_class = str_replace( 'Kirki\\', '', $new_class );
$relative_path = str_replace( '\\', '/', $relative_class ) . '.php';

// Check in Field and Control directories.
$base_dir = dirname( dirname( __DIR__ ) ) . '/';
$packages = array( 'controls/margin-padding', 'controls/headline-divider', 'controls/input-slider', 'controls/responsive', 'controls/tabs' );

foreach ( $packages as $package ) {
$file_name = basename( $relative_path );

$field_file = $base_dir . $package . '/src/Field/' . $file_name;
if ( file_exists( $field_file ) ) {
require_once $field_file;
if ( class_exists( $new_class, false ) ) {
class_alias( $new_class, $class );
}
return;
}

// Check Control directory (requires WP_Customize_Control).
$control_file = $base_dir . $package . '/src/Control/' . $file_name;
if ( file_exists( $control_file ) && class_exists( 'WP_Customize_Control', false ) ) {
require_once $control_file;
if ( class_exists( $new_class, false ) ) {
class_alias( $new_class, $class );
}
return;
}
}
},
true, // Throw exception if class not found.
true // Prepend to autoload stack (high priority).
);


Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function __construct() {
* If lower then we need to enqueue the backported scripts.
*/
if ( version_compare( $GLOBALS['wp_version'], '5.0', '<' ) ) {
add_action( 'wp_enqueue_scripts', [ $this, 'register_scripts' ] );
add_action( 'admin_register_scripts', [ $this, 'register_scripts' ] );
add_action( 'customize_controls_enqueue_scripts', [ $this, 'register_scripts' ] );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,8 @@ public function kirki_script_dependencies() {
public function enqueue() {

// Enqueue the styles.
wp_enqueue_style( 'kirki-control-base', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver );

// Enqueue the scripts.
wp_enqueue_script( 'kirki-control-base', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'customize-controls' ], self::$control_ver, false );

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,7 @@ class Checkbox extends Base {
* @since 1.0
* @return void
*/
public function enqueue() {
parent::enqueue();

// Enqueue the script.
wp_enqueue_script( 'kirki-control-checkbox', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base' ], self::$control_ver, false );

// Enqueue the style.
wp_enqueue_style( 'kirki-control-checkbox-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver );
}


/**
* An Underscore (JS) template for this control's content (but not its container).
Expand Down
Loading