此插件目前处于测试阶段,随着它的成熟,可能会发生重大变化。 em> p>Issues and Support
问题和支持 h4>
Contribute to the project on GitHub.
在GitHub上为项目 进行贡献。 p>
Why a Framework for the Customizer?
为什么要使用定制程序框架? h4>
The recent WordPress Customizer API suffers from some of the same issues afflicting the old Settings API.
最近的WordPress Customizer API遇到了一些与旧的Settings API相同的问题。
The Settings API was overcomplicated, unintuitive, and confusing.
设置API过于复杂,不直观且令人困惑。
The result was a crop of theme option frameworks that have sprung up to make it easier for developers to create theme options.
结果是出现了一系列主题选项框架,以使开发人员更轻松地创建主题选项。
The Customizer API is a bit better, but it’s still more complicated than necessary, and registering Customizer settings is still a convoluted mess of settings functions, controls functions, and sanitization functions.
Customizer API稍好一些,但是它比必要的要复杂得多,并且注册Customizer设置仍然是设置函数,控件函数和清理函数的复杂杂乱。
Now, the ease of use which the theme option frameworks have provided for the Settings API is available for the Customizer, in the Customizer Framework plugin.
现在,Customizer可以在Customizer Framework插件中使用主题选项框架为Settings API提供的易用性。 p>
The Customizer Framework aims to be a lightweight wrapper around the convoluted Customizer API, which makes it fun to be a WordPress developer again.
Customizer Framework的目标是成为复杂的Customizer API的轻量级包装,这使得再次成为WordPress开发人员变得很有趣。
Developers can now focus their time on creating great themes that utilize the Customizer, not on writing 500 lines of code in order to create 10 Customizer settings.
现在,开发人员可以将时间集中在创建利用定制程序的出色主题上,而不是为了创建10个定制程序设置而编写500行代码。
Okay, so I might be exaggerating a bit.
好吧,所以我可能会有点夸张。
But not by much.
但不是很多。
Do you really want to spend your time registering a Customizer setting, then registering a control for that setting, and then writing a sanitization function for that setting?
您是否真的想花费时间注册一个Customizer设置,然后为该设置注册一个控件,然后为该设置编写一个清理功能?
And that’s only for one setting!
这仅适用于一种设置!
And then there’s the advanced controls, such as image or color, that require you to instantiate their own control class, requiring even more convoluted and unintuitive code.
然后是高级控件,例如图像或颜色,要求您实例化其自己的控件类,甚至需要更多复杂且不直观的代码。
And why should you even have to care about the differece between a setting and a control?
而且,为什么您甚至还要关心设置和控件之间的区别?
Don’t you have better things to spend your time on, like creating great WordPress themes?
您是否有更好的事情可以花时间,例如创建出色的WordPress主题?
I thought so.
我是这样想的。 p>
Usage
用法 h3>
Activate the plugin, or include
it in your theme.
激活插件,或在主题中包含 code>。 p>Before creating any settings, you need to create any new Customizer sections that you wish
在创建任何设置之前,您需要创建所需的任何新的定制程序部分
to use.
使用。
Any custom sections need to exist before you can add settings to them.
您必须先存在任何自定义部分,然后才能向其中添加设置。 p>
Finally, initialize a new CustomizerFramework
class, and add your settings:
最后,初始化一个新的 CustomizerFramework code>类,并添加您的设置: p>function mytheme_register_settings( $settings ) { function mytheme_register_settings($ settings){ $settings[] = array(
$ settings [] = array(
'id' => 'example_setting',
'id'=>'example_setting',
'label' => 'Example Setting Label',
'label'=>'示例设置标签',
'section' => 'example-section',
'section'=>'example-section',
'type' => 'text', // Optional, defaults to 'text'
'type'=>'text',//可选,默认为'text'
'default' => 'Example section default text', // Optional
'default'=>'示例节默认文本',//可选
);
);
}
}
add_filter( 'customizer_framework_settings', 'mytheme_register_settings' );
add_filter('customizer_framework_settings','mytheme_register_settings');
code> pre>
Setting Types
设置类型 h4>
Here are the currently available setting types:
以下是当前可用的设置类型: p>
checkbox
-
复选框 code> li>color
-
颜色 code> li>dropdown-pages
-
下拉页面 code> li>image
-
图片 code> li>radio
-
无线电 code> li>select
-
选择 code> li>text
-
文本 code> li>textarea
(requires WordPress 4.0)-
textarea code>(需要WordPress 4.0) li>
ul>
The radio
and select
types require an additional choices
parameter, containing an array of the valid choices:
radio code>和 select code>类型需要附加的 choices code>参数,其中包含有效选择的数组: p>'choices' => array( 'choices'=>数组( 'choice_1' => 'Choice 1',
'choice_1'=>'选择1',
'choice_2' => 'Choice 2',
'choice_2'=>'选择2',
'choice_3' => 'Choice 3',
'choice_3'=>'选择3',
),
),
'default' => 'choice_1',
'默认'=>'选择_1',
code> pre>
In addition, on WordPress 4.0, you can specify any additional HTML5 input types, such as url
or date
.
此外,在WordPress 4.0上,您可以指定任何其他HTML5输入类型,例如 url code>或 date code>。You can also include an atts
parameter, containing an array of additional input attributes which should be applied to the input:
您还可以包含一个 atts code>参数,其中包含应应用于输入的其他输入属性数组: p>'type' => 'url', 'type'=>'url','atts' => array(
'atts'=>数组(
'placeholder' => 'http://',
'占位符'=>'http://',
'class' => 'a-custom-css-class',
'class'=>'a-custom-css-class',
),
),
code> pre>
Sanitization
消毒 h4>
All settings are sanitized automatically, based on the setting type.
所有设置都会根据设置类型自动清除。
If you wish to specify your own sanitization function for a setting, add a sanitize_cb
parameter, containing the function name to be called, which should return the sanitized value.
如果要为设置指定自己的清理功能,请添加一个 sanitize_cb code>参数,其中包含要调用的函数名称,该参数应返回清理后的值。 p>'sanitize_cb' => 'my_custom_example_setting_sanitization_function', 'sanitize_cb'=>'my_custom_example_setting_sanitization_function',
code> pre>