Redux 框架 - 自定义字体过滤器
Redux Framework - Custom Fonts Filter
我正在尝试将一组自定义字体传递给我认为是 Redux 框架上的 custom_fonts 过滤器,到目前为止,此设置返回错误:
Warning: Invalid argument supplied for foreach() in ....
我的过滤器:
add_filter('redux/theming/field/typography/custom_fonts', function ( $array ) {
$array = array(
"foo" => "foo font",
"bar" => "bar font",
);
return $array;
});
Redux 核心似乎在通过时处理 custom_fonts:
if ( $this->field['custom_fonts'] !== false ) {
$this->field['custom_fonts'] = apply_filters( "redux/{$this->parent->args['opt_name']}/field/typography/custom_fonts", array() );
if ( ! empty( $this->field['custom_fonts'] ) ) {
foreach ( $this->field['custom_fonts'] as $group => $fonts ) {
$this->parent->font_groups['customfonts'] = array(
'text' => $group,
'children' => array(),
);
foreach ( $fonts as $family => $v ) {
$this->parent->font_groups['customfonts']['children'][] = array(
'id' => $family,
'text' => $family,
'data-google' => 'false',
);
}
}
}
}
我的数据正在传递到过滤器,因为它试图通过 foreach 处理它,但不明白为什么它可能会中断。谁能弄清楚我可能遗漏了什么?
这是因为您return数组的格式有误。
试一试:
$array = array(
"custom_fonts"=> [
"foo" => "foo font",
"bar" => "bar font",
]
);
我正在尝试将一组自定义字体传递给我认为是 Redux 框架上的 custom_fonts 过滤器,到目前为止,此设置返回错误:
Warning: Invalid argument supplied for foreach() in ....
我的过滤器:
add_filter('redux/theming/field/typography/custom_fonts', function ( $array ) {
$array = array(
"foo" => "foo font",
"bar" => "bar font",
);
return $array;
});
Redux 核心似乎在通过时处理 custom_fonts:
if ( $this->field['custom_fonts'] !== false ) {
$this->field['custom_fonts'] = apply_filters( "redux/{$this->parent->args['opt_name']}/field/typography/custom_fonts", array() );
if ( ! empty( $this->field['custom_fonts'] ) ) {
foreach ( $this->field['custom_fonts'] as $group => $fonts ) {
$this->parent->font_groups['customfonts'] = array(
'text' => $group,
'children' => array(),
);
foreach ( $fonts as $family => $v ) {
$this->parent->font_groups['customfonts']['children'][] = array(
'id' => $family,
'text' => $family,
'data-google' => 'false',
);
}
}
}
}
我的数据正在传递到过滤器,因为它试图通过 foreach 处理它,但不明白为什么它可能会中断。谁能弄清楚我可能遗漏了什么?
这是因为您return数组的格式有误。
试一试:
$array = array(
"custom_fonts"=> [
"foo" => "foo font",
"bar" => "bar font",
]
);