PHP Error in Wordpress Theme

admin2025-06-02  2

So I'm having some issues with an AWS multisite hosting of wordpress. Every couple of weeks my entire instance of websites goes down. The first time it happened I was getting 500 errors so I just restarted the instance & everything was fine. But the second time there were no 500 errors, and while restarting worked, I'd ideally like to solve the issue entirely so I dug a bit deeper & looked at my php error logs & found this:

"PHP WARNING: Declaration of my_menu_walker::start_el(&$output, $item, $depth, $args) should be compatible with Walker_Nav_Menu::start_el(&$output, $item, $depth = 0, $args = Array, $id = 0) in {filepath} on line 61"

Essentially there is some kind of issue with a line of code in the theme on one of my hosted sites, but as it's not a theme I created or anything like that I have no idea how to fix it. Here's the full class that's having issues. Line 61 is the last line of this class before the closing }'s.

class my_menu_walker extends Walker_Nav_Menu {

    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;
        $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
        $class_names = ' class="'. esc_attr( $class_names ) . '"';

          $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';

          $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        ) .'"' : '';
          $description  = ! empty( $item->description ) ? '<span>'.esc_attr( $item->description ).'</span>' : '';

           if($depth != 0) 
                  $description = $append = $prepend = "";

            $item_output = $args->before;
            $item_output .= '<a'. $attributes .'>';
            $item_output .= $description.$args->link_after;
            $item_output .= $args->link_before.apply_filters( 'the_title', $item->title, $item->ID );
            $item_output .= '</a>';
            $item_output .= $args->after;
            $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
    }
}

Normally I would just send issues like this to the theme maker's support, but this theme is so old that I no longer have access to support from the theme maker without paying a large sum so if I can resolve it without doing that, that would be ideal.

So I'm having some issues with an AWS multisite hosting of wordpress. Every couple of weeks my entire instance of websites goes down. The first time it happened I was getting 500 errors so I just restarted the instance & everything was fine. But the second time there were no 500 errors, and while restarting worked, I'd ideally like to solve the issue entirely so I dug a bit deeper & looked at my php error logs & found this:

"PHP WARNING: Declaration of my_menu_walker::start_el(&$output, $item, $depth, $args) should be compatible with Walker_Nav_Menu::start_el(&$output, $item, $depth = 0, $args = Array, $id = 0) in {filepath} on line 61"

Essentially there is some kind of issue with a line of code in the theme on one of my hosted sites, but as it's not a theme I created or anything like that I have no idea how to fix it. Here's the full class that's having issues. Line 61 is the last line of this class before the closing }'s.

class my_menu_walker extends Walker_Nav_Menu {

    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;
        $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
        $class_names = ' class="'. esc_attr( $class_names ) . '"';

          $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';

          $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        ) .'"' : '';
          $description  = ! empty( $item->description ) ? '<span>'.esc_attr( $item->description ).'</span>' : '';

           if($depth != 0) 
                  $description = $append = $prepend = "";

            $item_output = $args->before;
            $item_output .= '<a'. $attributes .'>';
            $item_output .= $description.$args->link_after;
            $item_output .= $args->link_before.apply_filters( 'the_title', $item->title, $item->ID );
            $item_output .= '</a>';
            $item_output .= $args->after;
            $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
    }
}

Normally I would just send issues like this to the theme maker's support, but this theme is so old that I no longer have access to support from the theme maker without paying a large sum so if I can resolve it without doing that, that would be ideal.

Share Improve this question asked Feb 22, 2019 at 15:57 Trenton MooreTrenton Moore 739 bronze badges 2
  • The warning you mentioned is not a cause of the failure of your instance. This is just a PHP warning that doesn't affect website loading or even performance. You need to look for Fatal errors in your logs. If you can't find any, try with Apache error logs you may find something there. – Nour Edin Al-Habal Commented Feb 22, 2019 at 16:20
  • Follow the steps in this answer to resolve your issue: wordpress.stackexchange/a/325869/97257 – Nour Edin Al-Habal Commented Feb 22, 2019 at 16:23
Add a comment  | 

1 Answer 1

Reset to default 0

Replcace this

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

with this

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

I hope this will work.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748876317a314454.html

最新回复(0)