admin管理员组

文章数量:1391943

After a third-party developer was used to reconnect our calendar with the Google Calendar API 3, we found that our .../wp_admin/error_log infinitely wrote:

[14-Apr-2015 11:46:59 America/New_York] PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/USERFOLDER/public_html/wp-content/themes/THEMENAME/functions.php on line 2410

We have disabled writing to the error log, as it literally repeats that error until the HDD fills. In the functions.php file, line 2410 referenced in the error above is blank; the code around it is as follows:

function THEMENAME_sort_terms_hierarchicaly($cats, Array &$into, $parentId = 0, $level = 0){

    foreach ($cats as $i => $cat) {

        if ($cat->parent == $parentId) {

            $into[$cat->term_id] = $cat;

            $into[$cat->term_id]->level = $level;

            unset($cats[$i]);

        }

    }
 ///THIS IS LINE 2410
    $level++;

    foreach ($into as $topCat) {

        $topCat->children = array();

        THEMENAME_sort_terms_hierarchicaly($cats, $topCat->children, $topCat->term_id, $level);

    }

    return $into;

}

Howdy_McGee points out below that in_array() is not within the code snippet, I am reviewing the 6 in_array(...) instances from the functions.php page but have not yet found the issue.

These first two are likely more precedent as they fall within the //Admin Section of the functions.php code.

// Adding is login page function

function is_login_page() {

    return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'));

}

Other in_array(..) from admin section:

// Remove unwanted items from admin menu

function THEMENAME_remove_admin_menu_items() {

    $remove_menu_items = array(__('Dashboard'),__('Posts'),__('Media'),__('Pages'),__('Comments'),__('Appearance'),__('Plugins'),__('Users'),__('Tools'),__('Settings'),);

    global $menu;

    end ($menu);

    while (prev($menu)){

        $item = explode(' ',$menu[key($menu)][0]);

        if(in_array($item[0] != NULL?$item[0]:"" , $remove_menu_items)){

        unset($menu[key($menu)]);}

    }

}

Is there something here that I have missed that would reference line 2410 and cause this error? Do I need to rewrite each of my...

in_array(x,$y) 

with... ?

is_array($y) && in_array(x,$y)

After a third-party developer was used to reconnect our calendar with the Google Calendar API 3, we found that our .../wp_admin/error_log infinitely wrote:

[14-Apr-2015 11:46:59 America/New_York] PHP Warning:  in_array() expects parameter 2 to be array, null given in /home/USERFOLDER/public_html/wp-content/themes/THEMENAME/functions.php on line 2410

We have disabled writing to the error log, as it literally repeats that error until the HDD fills. In the functions.php file, line 2410 referenced in the error above is blank; the code around it is as follows:

function THEMENAME_sort_terms_hierarchicaly($cats, Array &$into, $parentId = 0, $level = 0){

    foreach ($cats as $i => $cat) {

        if ($cat->parent == $parentId) {

            $into[$cat->term_id] = $cat;

            $into[$cat->term_id]->level = $level;

            unset($cats[$i]);

        }

    }
 ///THIS IS LINE 2410
    $level++;

    foreach ($into as $topCat) {

        $topCat->children = array();

        THEMENAME_sort_terms_hierarchicaly($cats, $topCat->children, $topCat->term_id, $level);

    }

    return $into;

}

Howdy_McGee points out below that in_array() is not within the code snippet, I am reviewing the 6 in_array(...) instances from the functions.php page but have not yet found the issue.

These first two are likely more precedent as they fall within the //Admin Section of the functions.php code.

// Adding is login page function

function is_login_page() {

    return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'));

}

Other in_array(..) from admin section:

// Remove unwanted items from admin menu

function THEMENAME_remove_admin_menu_items() {

    $remove_menu_items = array(__('Dashboard'),__('Posts'),__('Media'),__('Pages'),__('Comments'),__('Appearance'),__('Plugins'),__('Users'),__('Tools'),__('Settings'),);

    global $menu;

    end ($menu);

    while (prev($menu)){

        $item = explode(' ',$menu[key($menu)][0]);

        if(in_array($item[0] != NULL?$item[0]:"" , $remove_menu_items)){

        unset($menu[key($menu)]);}

    }

}

Is there something here that I have missed that would reference line 2410 and cause this error? Do I need to rewrite each of my...

in_array(x,$y) 

with... ?

is_array($y) && in_array(x,$y)
Share Improve this question edited Apr 15, 2015 at 15:54 beta208 asked Apr 15, 2015 at 13:26 beta208beta208 1911 silver badge13 bronze badges 4
  • There is not an in_array() in the code you posted. Search your file for in_array() calls and every instance add a conditional to verify what is given is ! empty() – Howdy_McGee Commented Apr 15, 2015 at 13:38
  • Thanks again for a good starting point, I have found two in_array()s within the Admin portion of our function.php's code. – beta208 Commented Apr 15, 2015 at 13:59
  • Just post line 2410 of your functions.php - neither of those snippets should be the cause of the problem, because in both cases argument 2 is always an array. – TheDeadMedic Commented Apr 16, 2015 at 8:40
  • Hi there, it's the blank line with the comment from the first snippet: } ///THIS IS LINE 2410 $level++; – beta208 Commented Apr 16, 2015 at 13:13
Add a comment  | 

1 Answer 1

Reset to default 0

In case you use a "child theme", i would search also in the parent themes function.php

@see https://codex.wordpress/Child_Themes

本文标签: wp adminWhat is wrong with functionsphp Fills error log with same error