pressmodo / carbon-fields-custom-options-container
此包已被废弃,不再维护。没有建议的替代包。
这是一个经过修改的Carbon fields自定义选项容器,支持用于渲染页面的自定义文件。
0.1.0
2018-12-24 16:50 UTC
Requires
- php: >=5.3
- composer/installers: ^1.0
This package is auto-updated.
Last update: 2020-08-30 01:47:48 UTC
README
这个针对Carbon Fields的自定义容器提供了通过过滤器覆盖用于渲染选项面板的默认模板文件的能力。
要求
- Carbon fields
- Composer
安装
- 通过运行以下命令使用composer安装此包:
composer require pressmodo/carbon-fields-custom-options-container
- 创建一个选项面板,并将容器类型设置为
custom_options而不是theme_options。同时还需要设置一个页面文件。
Container::make( 'custom_options', 'Theme Options' )
->set_page_file( 'my-options' )
->add_fields(
array(
Field::make( 'text', 'crb_facebook_url' ),
Field::make( 'textarea', 'crb_footer_text' ),
)
);
用法
为了设置用于渲染选项页面的自定义文件,您需要使用过滤器:"cb_theme_options_{$page_file}_container_file",其中{$page_file}是上述提到的set_page_file方法设置的字符串(例如"cb_theme_options_my-options_container_file")。
通过过滤器,您需要返回用于渲染页面的自定义文件。您可以使用Carbon Field的现有文件作为起点。
add_filter( 'cb_theme_options_my-options_container_file', function () {
return 'path/to/custom-file.php';
});