前言
此筛选器允许你注册可在 Bricks 内使用的自定义字体图标集。
用法
将代码加入子主题的 functions.php:
add_filter( 'bricks/filter_element/controls', function( $controls, $element ) {
// Add a custom control to all filter elements
$controls['my_custom_setting'] = [
'tab' => 'content',
'group' => 'filter',
'label' => esc_html__( 'My Custom Setting', 'my-plugin' ),
'type' => 'checkbox',
];
return $controls;
}, 10, 2 );
参数
$controls(array):元素控件数组。$element(object):筛选元素实例。
示例代码
筛选返回值
add_filter( 'bricks/filter_element/controls', function( $controls, $element ) {
// Add a custom control to all filter elements
$controls['my_custom_setting'] = [
'tab' => 'content',
'group' => 'filter',
'label' => esc_html__( 'My Custom Setting', 'my-plugin' ),
'type' => 'checkbox',
];
return $controls;
}, 10, 2 );
根据条件短路返回原值
根据条件跳过或修改返回值:
add_filter( 'bricks/filter_element/controls', function( $value, $controls ) {
if ( is_admin() ) { return $value; }
// TODO: custom logic here
return $value;
} );
补充说明
更多细节可参考 官方文档。