inc2734 / wp-customizer-framework
A library for WordPress Customizer.
Package info
github.com/inc2734/wp-customizer-framework
pkg:composer/inc2734/wp-customizer-framework
Requires
- php: >=7.4
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^1.0
- phpcompatibility/phpcompatibility-wp: ^2.1.8
- phpunit/phpunit: ^9.6
- squizlabs/php_codesniffer: ^3.13.6
- wp-coding-standards/wpcs: ^3.4.1
- yoast/phpunit-polyfills: ^2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master
- 11.1.0
- 11.0.5
- 11.0.4
- 11.0.3
- 11.0.2
- 11.0.1
- 11.0.0
- 10.1.1
- 10.1.0
- 10.0.1
- 10.0.0
- 9.0.0
- 8.0.0
- 7.1.4
- 7.1.3
- 7.1.2
- 7.1.1
- 7.1.0
- 7.0.2
- 7.0.1
- 7.0.0
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.1.0
- 4.0.0
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.5
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.8
- 3.0.7
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 2.3.0
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.1.0
- 1.0.2
- 1.0.1
- 1.0.0
- dev-develop
This package is auto-updated.
Last update: 2026-11-13 05:42:21 UTC
README
A Framework of WordPress Customizer API.
Install
In your theme directory.
$ composer require inc2734/wp-customizer-framework
How to use
Initialize
require_once( get_theme_file_path( '/vendor/autoload.php' ) );
new \Inc2734\WP_Customizer_Framework\Bootstrap(
'handle' => 'main style sheet handle',
);
Customizer
use Inc2734\WP_Customizer_Framework\Framework;
Framework::panel( 'panel-id', [
'title' => 'panel-name',
] );
Framework::section( 'section-id', [
'title' => 'section-name',
] );
Framework::control( 'type', 'control-id', [
'label' => 'Header Color',
'default' => '#f00',
] );
$panel = Framework::get_panel( 'panel-id' );
$section = Framework::get_section( 'section-id' );
$control = Framework::get_control( 'control-id' );
$control->join( $section )->join( $panel );
$control->partial( [
'selector' => '.blogname',
] );
Lazy control UI arguments
Use the optional ui_args_callback to build labels, descriptions, choices, and other UI arguments only when they are needed:
Framework::control( 'select', 'layout', [ 'default' => 'wide', 'ui_args_callback' => function () { return [ 'label' => __( 'Layout', 'my-theme' ), 'choices' => [ 'wide' => __( 'Wide', 'my-theme' ), 'narrow' => __( 'Narrow', 'my-theme' ), ], ]; }, ] );
The callback takes no arguments and returns an array. It runs once, when UI arguments are first read or the control is registered. Sanitizers that need choices also resolve it. get_control() still returns the original concrete control object; reading settings and defaults does not invoke the callback.
Supply all setting arguments, including default, type, capability, and sanitization callbacks, outside ui_args_callback. Setting arguments returned by the callback are ignored. Explicit UI arguments and values assigned with set_arg() or set_extend_arg() take precedence over deferred values, including assignments made before the callback runs. Existing controls without the callback retain their behavior.
Set styles
use Inc2734\WP_Customizer_Framework\Style;
add_action(
'inc2734_wp_customizer_framework_load_styles',
function() {
$accent_color = get_theme_mod( 'accent-color' );
Style::attach(
'The handle of enqueued style',
[
[
'selectors' => [
'.page-title',
'.strong',
],
'properties' => [
"color: {$accent_color}",
"border-bottom-color: {$accent_color}",
],
'media_query' => '@media (min-width: 768px)', // Optional
],
]
);
}
);
Using placeholder
use Inc2734\WP_Customizer_Framework\Style;
add_action(
'inc2734_wp_customizer_framework_load_styles',
function() {
/**
* Extend "btn-base" placeholder
*
* Style::extend( 'btn-base', [ '.btn-a' ] );
*/
include_once( get_theme_file_path( '/css/btn-a.php' ) );
/**
* Extend "btn-base" placeholder
*
* Style::extend( 'btn-base', [ '.btn-b' ] );
*/
include_once( get_theme_file_path( '/css/btn-b.php' ) );
/**
* Extend "btn-base" placeholder
*
* Style::extend( 'btn-base', [ '.btn-c' ] );
*/
include_once( get_theme_file_path( '/css/btn-c.php' ) );
}
);
add_action(
'inc2734_wp_customizer_framework_after_load_styles',
function() {
Style::placeholder(
'btn-base',
function( $selectors ) {
$accent_color = get_theme_mod( 'accent-color' );
Style::attach(
'The handle of enqueued style',
[
[
'selectors' => $selectors,
'properties' => [ "border-color: {$accent_color}" ],
],
]
);
}
);
}
);