2

I just update to php 7.2 on my 1and1 account. Since, I have these warnings on the header of my wordpress website:

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

Here is the function :

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);
    }
}

I try to fix the problem but don´t achieve, do you have an idea ?

Dumi
  • 1,414
  • 4
  • 21
  • 41
Mazarine
  • 23
  • 1
  • 5

1 Answers1

2

Your methods in the child class should have the exact same structure as the parent ones, including the default values.

You can double check how the Walker_Nav_Menu source looks like in the WordPress core - https://developer.wordpress.org/reference/classes/walker_nav_menu/.

In your case, there are two things you have to change:

function start_el( &$output, $item, $depth, $args ) {

to

function start_el( &$output, $depth = 0, $args = array() ) {

and the other thing that should be replaced from:

function end_el( &$output, $item, $depth ) {

to

function end_el( &$output, $depth = 0, $args = array() ) {
mbelchev
  • 206
  • 1
  • 6
  • Thank you for your answer, but when I change the two things I have this fatal error : Fatal error: Cannot redeclare DropDown_Nav_Menu::start_lvl() in /homepages/42/d459723492/htdocs/com/wp-content/themes/bluediamond-v1_02/include/plugin/dropdown-menus.php on line 133 – Mazarine Mar 18 '19 at 10:44
  • @Mazarine Sorry for this, I've copied directly the function names from the documentation. Just updated my answer, the suffix should be "_el" not "_lvl". Give a try and let me know if it works or just share me the whole file. – mbelchev Mar 18 '19 at 12:52
  • In my case, with a different theme, Backstreet: ```Your PHP code changes were rolled back due to an error on line 141 of file wp-content/themes/Backstreet/panel/dropdown-menus.php. Please fix and try saving again. Object of class WP_Post could not be converted to string``` – CoderGuy123 May 01 '20 at 12:11