我在 Wordpress 上有一个网站,我团队中的某个人更新了一些内容,现在该网站上有一个错误:
Warning: Illegal string offset 'output_key' in /.../wp-includes/nav-menu.php
我禁用了调试消息,现在该站点运行良好。我想这不是最好的解决方案。几个小时的谷歌搜索和在这里寻找东西让我意识到我必须告诉脚本这'output_key'是一个数组元素。
$defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item',
'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true );
$args = wp_parse_args( $args, $defaults );
$args['include'] = $items;
if ( ARRAY_A == $args['output']) {
$GLOBALS['_menu_item_sort_prop'] = $args['output_key'];
usort($items, '_sort_nav_menu_items');
$i = 1;
foreach( $items as $k => $item ) {
$items[$k]->$args['output_key'] = $i++; //here is the error
}
}
我试图询问$args它是否是第 1 行中的数组。
$defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item',
'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true );
$args = wp_parse_args( $args, $defaults );
$args['include'] = $items;
if ( ARRAY_A == $args['output'] && is_array($args) ) {
$GLOBALS['_menu_item_sort_prop'] = $args['output_key'];
usort($items, '_sort_nav_menu_items');
$i = 1;
foreach( $items as $k => $item ) {
$items[$k]->$args['output_key'] = $i++; //here is the error
}
}
但是第 6 行仍然在网站上显示错误。我不知道该怎么处理那条线。
