前言
筛选 Bricks REST API 端点 /get-templates-data/ 所返回的数据。该端点用于检索模板、作者、合集、标签以及其他模板库资源。
用法
将代码加入子主题的 functions.php:
add_filter( 'bricks/api/get_templates_data', function( $templates_data ) {
// Example: Remove a specific template bundle by name
if ( ! empty( $templates_data['bundles'] ) ) {
foreach ( $templates_data['bundles'] as $key => $bundle ) {
if ( $bundle === 'Deprecated Bundle' ) {
unset( $templates_data['bundles'][ $key ] );
}
}
}
return $templates_data;
} );
参数
$templates_data(array):包含以下内容的数组:
示例代码
筛选返回值
add_filter( 'bricks/api/get_templates_data', function( $templates_data ) {
// Example: Remove a specific template bundle by name
if ( ! empty( $templates_data['bundles'] ) ) {
foreach ( $templates_data['bundles'] as $key => $bundle ) {
if ( $bundle === 'Deprecated Bundle' ) {
unset( $templates_data['bundles'][ $key ] );
}
}
}
return $templates_data;
} );
根据条件短路返回原值
根据条件跳过或修改返回值:
add_filter( 'bricks/api/get_templates_data', function( $value, $templates_data ) {
if ( is_admin() ) { return $value; }
// TODO: custom logic here
return $value;
} );
补充说明
更多细节可参考 官方文档。