我正在进行灵活字段字段类型的一些自定义。我想要做的是完全删除format_value过滤器,并在load_value之后运行我自己的过滤器
我已尝试使用以下代码删除我确信可以使用的过滤器。可惜。我做错了什么?
remove_filter( 'acf/format_value/type=flexible_content', array('acf_field_flexible_content', 'format_value'), 10 );
参考:
以下是有关过滤器的信息: https://www.advancedcustomfields.com/resources/acf-format_value/
在$ wp_filter global中这里是引用:
[acf/format_value/type=flexible_content] => WP_Hook Object
(
[callbacks] => Array
(
[10] => Array
(
[000000004e0e085b00000000706fba6bformat_value] => Array
(
[function] => Array
(
[0] => acf_field_flexible_content Object
(
[name] => flexible_content
[label] => Flexible Content
[category] => layout
[defaults] => Array
(
[layouts] => Array
(
)
[min] =>
[max] =>
[button_label] => Add Row
)
[l10n] => Array
(
[layout] => layout
[layouts] => layouts
[remove] => remove {layout}?
[min] => This field requires at least {min} {identifier}
[max] => This field has a limit of {max} {identifier}
[min_layout] => This field requires at least {min} {label} {identifier}
[max_layout] => Maximum {label} limit reached ({max} {identifier})
[available] => {available} {label} {identifier} available (max {max})
[required] => {required} {label} {identifier} required (min {min})
[layout_warning] => Flexible Content requires at least 1 layout
)
[public] => 1
)
[1] => format_value
)
[accepted_args] => 3
)
)
[4000] => Array
(
[my_acf_format_valuexxxx] => Array
(
[function] => my_acf_format_valuexxxx
[accepted_args] => 3
)
)
)
[iterations:WP_Hook:private] => Array
(
)
[current_priority:WP_Hook:private] => Array
(
)
[nesting_level:WP_Hook:private] => 0
[doing_action:WP_Hook:private] =>
)
答案 0 :(得分:1)
所以我最终向ACF提出了一张关于此的支持票,得到了很好的回应和解决方案FYI:
remove_filter函数需要一个objct作为>的第一个参数。数组目标,而不是字符串。您可以获得灵活的内容字段 像这样的对象:
acf_get_field_type( $field_type )
使用此功能,您的代码应如下所示:
remove_filter('acf/format_value/type=flexible_content',array(acf_get_field_type('flexible_content'), 'format_value'), 10 );
经过测试和工作: - )
答案 1 :(得分:1)
我将添加,您必须在acf/init
挂钩中使用它。否则它将无法正常工作,或者如果您使用init
钩子,则将致命,因为未定义acf_get_field_type
。
(我对图库字段使用了相同的方法)
add_action('acf/init', function () {
remove_filter('acf/format_value/type=gallery', array(acf_get_field_type('gallery'), 'format_value'), 10);
});