Support » Fixing WordPress » in_array() expects parameter 2 to be array, null given

  • Resolved johannaellamay

    (@johannaellamay)


    Hi! My site suddenly broke down. It was okay for one second, I didn’t edit any codes. And when I refreshed, this error occurred:

    ( ! ) warning: in_array() expects parameter 2 to be array, null given in c:\wamp\www\cameraandcheese\wp-content\themes\_strap-master\_strap-master\inc\functions-strap.php on line 18

    I started with a starter theme I found called _strap-master which is based on _s and bootstrap. Below is the code. Can anyone please verify where the error is? Line 18 is if( !in_array(‘dropdown’, $sorted_menu_items[$parent_index]->classes) ) {

    function bootstrap_menu_objects($sorted_menu_items, $args)
    {
        if($args->theme_location == 'primary')
        {//
            $current = array('current-menu-ancestor', 'current-menu-item');
            $registry = array();
            foreach($sorted_menu_items as $i => $item) {
                $is_current = array_intersect( (array) $item->classes, $current );
                if ( !empty($is_current) ) $item->classes[] = 'active';
                $registry[$item->ID] = $i;
                if($item->menu_item_parent) {
                    $parent_index = $registry[$item->menu_item_parent];
                    if( !in_array('dropdown', $sorted_menu_items[$parent_index]->classes) ) {
                        $sorted_menu_items[$parent_index]->classes[] = 'dropdown';
                    }
                }
            }
            //print_r($sorted_menu_items);print_r($args);exit;
        }
        return $sorted_menu_items;
    }
    add_filter( 'wp_nav_menu_objects', 'bootstrap_menu_objects', 10, 2 );
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘in_array() expects parameter 2 to be array, null given’ is closed to new replies.