php - Redux 框架 - 自定义字体过滤器
问题描述
我正在尝试将一组自定义字体传递给我认为是 Redux Framework 上的 custom_fonts 过滤器,到目前为止,此设置正在返回以下错误:
警告:在 .... 中为 foreach() 提供的参数无效
我的过滤器:
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 处理它,但不知道它为什么会中断。任何人都能够清除我可能遗漏的东西吗?
解决方案
这是因为您以错误的格式返回数组。
试试这个:
$array = array(
"custom_fonts"=> [
"foo" => "foo font",
"bar" => "bar font",
]
);
推荐阅读
- loops - HLA程序是死循环吗?
- c++ - cuda单独编译模式和cudart静态链接的链接错误
- c# - 在 .NET Core C# 中使用证书进行加密和解密
- django - 在 Django 中具有 CRUD 功能的用户特定配置文件页面
- linux - Linux:在 CentOS v7 上加载调试符号
- vue.js - Nuxt:以模态方式打开组件/页面,使用 dribble.com 等专用 url
- flutter - 如何在 Flutter Web 上进行语音识别
- typescript - 条件类型的可选参数
- gmail - 使用 Google 表格中的 GmailApp.sendEmail 时如何包含用户的 Gmail 签名
- php - 什么是裁剪小数 php 的最佳方法