viktor777 / wp-customizable-options
WordPress Customizer预览部分的实时编辑库。
dev-master
2016-07-08 07:45 UTC
Requires
- php: ^5.5 || ^7.0
This package is not auto-updated.
Last update: 2024-09-19 09:05:05 UTC
README
允许在前端WordPress Customizer预览部分编辑简单文本选项的库。
安装
Composer
$ composer require viktor777/wp-customizable-options
用法
初始化
register_customizable_options();
可编辑选项
the_customizable_text( $option, $default = false );
更改默认包装器
默认情况下,当管理员处于Customizer时,文本用'tag'包装在'span'标签中。您可以使用过滤器进行更改
add_filter( 'the_customizable_text_wrapper_tag', function () {
return 'div';
} );
更改默认过滤器
默认情况下,已实现'esc_html'函数来处理文本。您可以使用以下代码进行更改
/**
* Remove default filter
*/
remove_filter( 'the_customizable_text_value', '_the_customizable_text_value' );
/**
* Lets use e.g. 'esc_url' as filter
*/
add_filter( 'the_customizable_text_value', function () {
return is_bool( $value ) ? $value : esc_url( $value );
} );
演示
注意
- 如果您不使用代码在Customizer中添加设置,它将默认存储在名为'Customizable Options'的章节中
- Customizer中控制的标签默认由选项名称生成,例如'customizable_option' => 'Customizable Option'