前言
筛选启用 Bricks 编辑的文章类型列表。用于检查构建器是否应加载当前文章类型。
用法
将代码加入子主题的 functions.php:
add_filter( 'bricks/builder/supported_post_types', function( $supported_post_types, $current_post_type ) {
// Example: Always allow 'my_custom_post_type' to be edited with Bricks
if ( $current_post_type === 'my_custom_post_type' && ! in_array( 'my_custom_post_type', $supported_post_types ) ) {
$supported_post_types[] = 'my_custom_post_type';
}
return $supported_post_types;
}, 10, 2 );
参数
$supported_post_types(array):支持的文章类型 slug 数组(例如 [‘page’, ‘post’, ‘my_cpt’])。$current_post_type(string):正在被访问的文章的文章类型。
示例代码
筛选返回值
add_filter( 'bricks/builder/supported_post_types', function( $supported_post_types, $current_post_type ) {
// Example: Always allow 'my_custom_post_type' to be edited with Bricks
if ( $current_post_type === 'my_custom_post_type' && ! in_array( 'my_custom_post_type', $supported_post_types ) ) {
$supported_post_types[] = 'my_custom_post_type';
}
return $supported_post_types;
}, 10, 2 );
根据条件短路返回原值
根据条件跳过或修改返回值:
add_filter( 'bricks/builder/supported_post_types', function( $value, $supported_post_types ) {
if ( is_admin() ) { return $value; }
// TODO: custom logic here
return $value;
} );
补充说明
更多细节可参考 官方文档。