Bricks 中文文档:bricks/filter-element/datepicker_options

📎 原始资料  |  下载原始 JSON 文件 (bricks-filter-element-datepicker_options.json) 前言 Bricks 1.4 引入了 bricks/indexer/row 钩子,允许你修改索引器生成的单个索引行。 用法 将代码加入子主题的 functions.php: add_filter( ‘bricks/filter-element/datepicker_options’, function( $datepicker_options, $element ) { // Example: Change the date form…

前言

Bricks 1.4 引入了 bricks/indexer/row 钩子,允许你修改索引器生成的单个索引行。

用法

将代码加入子主题的 functions.php

add_filter( 'bricks/filter-element/datepicker_options', function( $datepicker_options, $element ) {
    // Example: Change the date format
    $datepicker_options['dateFormat'] = 'Y-m-d';


    // Example: Disable specific dates
    $datepicker_options['disable'] = [ '2023-12-25', '2024-01-01' ];


    return $datepicker_options;
}, 10, 2 );

参数

  • $datepicker_options (array):Flatpickr 选项数组。
  • $element (object):Filter: Datepicker 元素实例。

示例代码

筛选返回值

add_filter( 'bricks/filter-element/datepicker_options', function( $datepicker_options, $element ) {
    // Example: Change the date format
    $datepicker_options['dateFormat'] = 'Y-m-d';


    // Example: Disable specific dates
    $datepicker_options['disable'] = [ '2023-12-25', '2024-01-01' ];


    return $datepicker_options;
}, 10, 2 );

根据条件短路返回原值

根据条件跳过或修改返回值:

add_filter( 'bricks/filter-element/datepicker_options', function( $value, $datepicker_options ) {
    if ( is_admin() ) { return $value; }
    // TODO: custom logic here
    return $value;
} );

补充说明

更多细节可参考 官方文档