HP Notice: PHP warning: Invalid argument provided for foreach() in plugin.php
P粉561749334
P粉561749334 2023-12-13 11:14:24
0
2
568

I'm getting tons of errors in my error log. Does anyone know how to solve this problem?

They are all the same:

[Mon Jun 27 12:39:xx.518352 2022] [proxy_fcgi:error] [pid 4663:tid 139793920644864] [client 84.80.28.xx:52348] AH01071: Error occurred "PHP message: PHP warning: Invalid " is the parameter provided for foreach() in /home/685947.example.com/public_html/wp-admin/includes/plugin.php on line 1779, reference address: https://example.com/mijn-account/

This is the code (default WordPress file):

function remove_menu_page( $menu_slug ) {
    global $menu;

    foreach ( $menu as $i => $item ) {
        if ( $menu_slug === $item[2] ) {
            unset( $menu[ $i ] );
            return $item;
        }
    }

    return false;
}

P粉561749334
P粉561749334

reply all(2)
P粉553428780

The value received by the variable ($menu) may not be an array.

It would be fun to add validation, for example:

function remove_menu_page( $menu_slug ) {
    global $menu;
    
    if (!is_array($menu)) return false;

    foreach ( $menu as $i => $item ) {
        if ( $menu_slug === $item[2] ) {
            unset( $menu[ $i ] );
            return $item;
        }
    }

    return false;
}
Jenson.Wang

Variable ($menu) may be an empty array

function remove_menu_page( $menu_slug ) {    
    global $menu;    
    if(!empty($menu)){ 
        foreach ( $menu as $i => $item ) {        
            if ( $menu_slug === $item[2] ) {            
                unset( $menu[ $i ] );            
                return $item;        
            }   
        }  
    }  
  return false;
}

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template