admin管理员组文章数量:1122846
I have been unable to resolve this problem even after reading many related posts. This problem begun after updating to PHP 8. It concerns a theme that I bought many years ago and that has been abandoned by his author. I'm planning to migrate to a new theme but this is going to take time and I need to temporarily reconnect the site.
This seems to be a classic disfunction around the parameters used in functions start_lvl
and start_el
when they are not compatible with Walker_Nav_Menu
parameters.
After reading many answers on the forum, in the theme's code, I replaced
function start_lvl( &$output, $depth )
by function start_lvl( &$output, $depth = 0, $args = array() )
and also function start_el( &$output, $item, $depth, $args )
by function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 )
but then I got a new fatal error pointing to the core
Fatal error: Uncaught ArgumentCountError: Too few arguments to function WP_Widget::__construct()
etc...
After reading on the forum about this new alert, I understood that I have to fix the problem on the theme, and must probably, on the parameters used to extend walker menu.
I will appreciate if someone there can help me to understand what is happening and how can I solve this situation. You can find here the original code used on the theme to extend Walker Menu :
<?php
class arctic_walker_menu extends Walker_Nav_Menu {
// add classes to ul sub-menus
function start_lvl( &$output, $depth ) {
// depth dependent classes
$indent = ( $depth > 0 ? str_repeat( "\t", $depth ) : '' ); // code indent
$display_depth = ( $depth + 1); // because it counts the first submenu as 0
$classes = array(
'sub-menu',
( $display_depth % 2 ? 'menu-odd' : 'menu-even' ),
( $display_depth >=2 ? 'sub-sub-menu' : '' ),
'menu-depth-' . $display_depth
);
$class_names = implode( ' ', $classes );
// build html
$output .= "\n" . $indent . '<ul class="' . $class_names . '">' . "\n";
}
function start_el( &$output, $item, $depth, $args ) {
global $wp_query;
$indent = ( $depth > 0 ? str_repeat( "\t", $depth ) : '' ); // code indent
// depth dependent classes
$depth_classes = array(
( $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ),
( $depth >=2 ? 'sub-sub-menu-item' : '' ),
( $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ),
'menu-item-depth-' . $depth
);
$depth_class_names = esc_attr( implode( ' ', $depth_classes ) );
// passed classes
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = esc_attr( implode( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ) );
// build html
$output .= $indent . '<li id="nav-menu-item-'. $item->ID . '" class="' . $depth_class_names . ' ' . $class_names . '">';
// link attributes
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$attributes .= ' class="menu-link ' . ( $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ) . '"';
$item_output = sprintf( '%1$s<a%2$s>%3$s%4$s%5$s</a>%6$s',
$args->before,
$attributes,
$args->link_before,
apply_filters( 'the_title', $item->title, $item->ID ),
$args->link_after,
$args->after
);
// build html
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
Regards, Guillermo
本文标签: customizationFatal error with startlvl and startel in an abandoned theme
版权声明:本文标题:customization - Fatal error with start_lvl and start_el in an abandoned theme 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736295352a1929552.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论