[wordpress插件] Customizer Framework定制框架

wordpress 插件 文章 2020-04-10 21:11 0 240 全屏看文
评分
0
描述

A lightweight and easy-to-use framework for the WordPress Customizer.

一个轻巧易用的WordPress Customizer框架。

Provides a simple and intuitive API for registering Customizer settings, including advanced control types.

提供简单直观的API,用于注册Customizer设置,包括高级控件类型。

Automatically sanitizes settings based on the control type.

根据控件类型自动清除设置。

Eliminates the tedious task of registering a setting, control, and sanitization function for each individual Customizer setting.

消除了为每个Customizer设置注册设置,控制和清理功能的繁琐任务。

The framework may be used by both plugins and themes, although since at this time the settings are saved as theme mods, any plugin settings will be specific to the active theme.

插件和主题都可以使用该框架,尽管由于此时将设置保存为主题模块,所以任何插件设置都将特定于活动主题。

Support for option type settings is planned.

计划支持选项类型设置。

This plugin is currently in beta, and may be subject to major changes as it matures.

此插件目前处于测试阶段,随着它的成熟,可能会发生重大变化。

Issues and Support

问题和支持

Contribute to the project on GitHub.

在GitHub上为项目 进行贡献。

Why a Framework for the Customizer?

为什么要使用定制程序框架?

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提供的易用性。

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.

我是这样想的。

Usage

用法

Activate the plugin, or include it in your theme.

激活插件,或在主题中包含

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.

您必须先存在任何自定义部分,然后才能向其中添加设置。

Finally, initialize a new CustomizerFramework class, and add your settings:

最后,初始化一个新的 CustomizerFramework 类,并添加您的设置:

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');

Setting Types

设置类型

Here are the currently available setting types:

以下是当前可用的设置类型:

    • checkbox
    • 复选框

    • color
    • 颜色

    • dropdown-pages
    • 下拉页面

    • image
    • 图片

    • radio
    • 无线电

    • select
    • 选择

    • text
    • 文本

    • textarea (requires WordPress 4.0)
    • textarea (需要WordPress 4.0)

    The radio and select types require an additional choices parameter, containing an array of the valid choices:

    radio select 类型需要附加的 choices 参数,其中包含有效选择的数组:

    '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',

    In addition, on WordPress 4.0, you can specify any additional HTML5 input types, such as url or date.

    此外,在WordPress 4.0上,您可以指定任何其他HTML5输入类型,例如 url date

    You can also include an atts parameter, containing an array of additional input attributes which should be applied to the input:

    您还可以包含一个 atts 参数,其中包含应应用于输入的其他输入属性数组:

    'type' => 'url',

     'type'=>'url',

    'atts' => array(    

    'atts'=>数组(    

    'placeholder' => 'http://',    

    '占位符'=>'http://',    

    'class' => 'a-custom-css-class',

    'class'=>'a-custom-css-class',

    ),

    ),

    Sanitization

    消毒

    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 参数,其中包含要调用的函数名称,该参数应返回清理后的值。

    'sanitize_cb' => 'my_custom_example_setting_sanitization_function',

     'sanitize_cb'=>'my_custom_example_setting_sanitization_function',

安装步骤

Install like any other plugin.

像其他任何插件一样安装。

If you’re a theme developer, then you already know how to install a plugin, and I won’t bore you with the details.

如果您是主题开发人员,那么您已经知道如何安装插件,并且我不会为您带来任何细节。

See Other Notes for usage instuctions.

有关使用说明,请参见其他说明

If you're creating a theme for public release, I recommend that you consider using the TGM Plugin Activation library to

如果您要创建要公开发布的主题,建议您考虑使用 TGM插件激活

make it easy for your users to install the Customizer Framework after activating your theme.

使您的用户在激活主题后轻松安装Customizer Framework。

You could also include the plugin it in your theme, but remember to check for the existince of the plugin version first to avoid conflicts.

您也可以将插件包括到主题中,但是请记住首先检查插件版本是否存在,以免发生冲突。

下载地址
https://downloads.wordpress.org/plugin/customizer-framework.0.1.zip
-EOF-