PHP 7.2 更新:header 中下拉菜单的警告声明
PHP 7.2 update : Warning Declaration of DropDown in the header
我刚刚将我的 1and1 帐户更新到 php 7.2。因为,我在我的 wordpress 网站的 header 上有这些警告:
Warning: Declaration of DropDown_Nav_Menu::start_lvl(&$output, $depth)
should be compatible with Walker_Nav_Menu::start_lvl(&$output, $depth
= 0, $args = Array) in /homepages/42/d459723492/htdocs/com/wp-content/themes/bluediamond-v1_02/include/plugin/dropdown-menus.php
on line 173
Warning: Declaration of DropDown_Nav_Menu::end_lvl(&$output, $depth)
should be compatible with Walker_Nav_Menu::end_lvl(&$output, $depth =
0, $args = Array) in
/homepages/42/d459723492/htdocs/com/wp-content/themes/bluediamond-v1_02/include/plugin/dropdown-menus.php
on line 173
Warning: Declaration of DropDown_Nav_Menu::start_el(&$output, $item,
$depth, $args) should be compatible with
Walker_Nav_Menu::start_el(&$output, $item, $depth = 0, $args = Array,
$id = 0) in
/homepages/42/d459723492/htdocs/com/wp-content/themes/bluediamond-v1_02/include/plugin/dropdown-menus.php
on line 173
Warning: Declaration of DropDown_Nav_Menu::end_el(&$output, $item,
$depth) should be compatible with Walker_Nav_Menu::end_el(&$output,
$item, $depth = 0, $args = Array) in
/homepages/42/d459723492/htdocs/com/wp-content/themes/bluediamond-v1_02/include/plugin/dropdown-menus.php
on line 173
函数如下:
function start_el( &$output, $item, $depth, $args ) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = 'menu-item-' . $item->ID;
$classes[] = 'menu-item-depth-' . $depth;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_unique( array_filter( $classes ) ), $item, $args ) );
$class_names = ' class="' . esc_attr( $class_names ) . '"';
// select current item
$selected = in_array( 'current-menu-item', $classes ) ? ' selected="selected"' : '';
$output .= $indent . '<option' . $class_names .' value="'. $item->url .'"'. $selected .'>';
// push sub-menu items in as we can't nest optgroups
$indent_string = str_repeat( apply_filters( 'dropdown_menus_indent_string', $args->indent_string, $item, $depth, $args ), ( $depth ) ? $depth : 0 );
$indent_string .= !empty( $indent_string ) ? apply_filters( 'dropdown_menus_indent_after', $args->indent_after, $item, $depth, $args ) : '';
$item_output = $args->before . $indent_string;
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_dropdown_start_el', $item_output, $item, $depth, $args );
}
/**
* @see Walker::end_el()
* @since 3.0.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param object $item Page data object. Not used.
* @param int $depth Depth of page. Not Used.
*/
function end_el( &$output, $item, $depth ) {
$output .= apply_filters( 'walker_nav_menu_dropdown_end_el', "</option>\n", $item, $depth);
}
}
我尝试解决问题但没有成功,你有什么想法吗?
子方法 class 中的方法应与父方法具有完全相同的结构,包括默认值。
您可以仔细检查 Walker_Nav_Menu 源代码在 WordPress 核心中的样子 - https://developer.wordpress.org/reference/classes/walker_nav_menu/。
对于您的情况,您必须更改两件事:
function start_el( &$output, $item, $depth, $args ) {
到
function start_el( &$output, $depth = 0, $args = array() ) {
以及其他应该替换的东西:
function end_el( &$output, $item, $depth ) {
到
function end_el( &$output, $depth = 0, $args = array() ) {
我刚刚将我的 1and1 帐户更新到 php 7.2。因为,我在我的 wordpress 网站的 header 上有这些警告:
Warning: Declaration of DropDown_Nav_Menu::start_lvl(&$output, $depth) should be compatible with Walker_Nav_Menu::start_lvl(&$output, $depth = 0, $args = Array) in /homepages/42/d459723492/htdocs/com/wp-content/themes/bluediamond-v1_02/include/plugin/dropdown-menus.php on line 173
Warning: Declaration of DropDown_Nav_Menu::end_lvl(&$output, $depth) should be compatible with Walker_Nav_Menu::end_lvl(&$output, $depth = 0, $args = Array) in /homepages/42/d459723492/htdocs/com/wp-content/themes/bluediamond-v1_02/include/plugin/dropdown-menus.php on line 173
Warning: Declaration of DropDown_Nav_Menu::start_el(&$output, $item, $depth, $args) should be compatible with Walker_Nav_Menu::start_el(&$output, $item, $depth = 0, $args = Array, $id = 0) in /homepages/42/d459723492/htdocs/com/wp-content/themes/bluediamond-v1_02/include/plugin/dropdown-menus.php on line 173
Warning: Declaration of DropDown_Nav_Menu::end_el(&$output, $item, $depth) should be compatible with Walker_Nav_Menu::end_el(&$output, $item, $depth = 0, $args = Array) in /homepages/42/d459723492/htdocs/com/wp-content/themes/bluediamond-v1_02/include/plugin/dropdown-menus.php on line 173
函数如下:
function start_el( &$output, $item, $depth, $args ) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = 'menu-item-' . $item->ID;
$classes[] = 'menu-item-depth-' . $depth;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_unique( array_filter( $classes ) ), $item, $args ) );
$class_names = ' class="' . esc_attr( $class_names ) . '"';
// select current item
$selected = in_array( 'current-menu-item', $classes ) ? ' selected="selected"' : '';
$output .= $indent . '<option' . $class_names .' value="'. $item->url .'"'. $selected .'>';
// push sub-menu items in as we can't nest optgroups
$indent_string = str_repeat( apply_filters( 'dropdown_menus_indent_string', $args->indent_string, $item, $depth, $args ), ( $depth ) ? $depth : 0 );
$indent_string .= !empty( $indent_string ) ? apply_filters( 'dropdown_menus_indent_after', $args->indent_after, $item, $depth, $args ) : '';
$item_output = $args->before . $indent_string;
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_dropdown_start_el', $item_output, $item, $depth, $args );
}
/**
* @see Walker::end_el()
* @since 3.0.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param object $item Page data object. Not used.
* @param int $depth Depth of page. Not Used.
*/
function end_el( &$output, $item, $depth ) {
$output .= apply_filters( 'walker_nav_menu_dropdown_end_el', "</option>\n", $item, $depth);
}
}
我尝试解决问题但没有成功,你有什么想法吗?
子方法 class 中的方法应与父方法具有完全相同的结构,包括默认值。
您可以仔细检查 Walker_Nav_Menu 源代码在 WordPress 核心中的样子 - https://developer.wordpress.org/reference/classes/walker_nav_menu/。
对于您的情况,您必须更改两件事:
function start_el( &$output, $item, $depth, $args ) {
到
function start_el( &$output, $depth = 0, $args = array() ) {
以及其他应该替换的东西:
function end_el( &$output, $item, $depth ) {
到
function end_el( &$output, $depth = 0, $args = array() ) {