Plugin Error - array_merge(): Argument #2 is not an array

Monday, July 7, 2014

I am building my first wordpress plugin and the error log is throwing up the following errors.



[06-Jul-2014 20:07:21 UTC] PHP Warning: array_merge(): Argument #2 is not an array in \wp-content\plugins\test-plugin\screen.php on line 49

[06-Jul-2014 20:07:21 UTC] PHP Warning: array_merge(): Argument #2 is not an array in \wp-content\plugins\test-plugin\screen.php on line 50

[06-Jul-2014 20:07:21 UTC] PHP Warning: end() expects parameter 1 to be array, null given in \wp-content\plugins\test-plugin\screen.php on line 323

[06-Jul-2014 20:07:21 UTC] PHP Warning: Invalid argument supplied for foreach() in \wp-content\plugins\test-plugin\screen.php on line 324


For the errors on line 49 & 50 the code is:



function register_settings() {
global $menu;
global $submenu;
$this->menus = array_merge(array(), $menu);
$this->submenus = array_merge(array(), $submenu);
$this->settings = get_option( $this->settings_name );
register_setting( 'admin-theme', $this->settings_name );
}


For the errors on lines 323 & 324 the code is:



function admin_menu() {
global $menu;
global $submenu;
// update menu
end( $menu );
foreach ($menu as $k=>&$v){
$id = explode(' <span', $v[0]);
$slug = 'menu_'.strtolower( str_replace( ' ','_',$id[0] ) );
$slug_hide = $slug.'_hide';
if($id[0] != NULL && $this->get_setting($slug) !== NULL){
$v[0] = $this->get_setting($slug). ( isset($id[1]) ? ' <span '.$id[1] : '' );
}
if( $this->get_setting($slug_hide) ){
unset($menu[$k]);
}
// update the submenu
if( isset($submenu[$v[2]]) ){
foreach ($submenu[$v[2]] as $key=>&$val){
$id = explode(' <span', $val[0]);
$slug_sub = $slug.'_'.strtolower( str_replace( ' ','_',$id[0] ) );
$slug_sub_hide = $slug_sub.'_hide';
if($id[0] != NULL && $this->get_setting($slug_sub) !== NULL){
$val[0] = $this->get_setting($slug_sub). ( isset($id[1]) ? ' <span '.$id[1] : '' );
}
if( $this->get_setting($slug_sub_hide) ){
unset( $submenu[$v[2]][$key] );
}
}
}
}
}


I can't seem to figure it out so if anyonecanhelp or point me in the right direction it would be greatly appreciated.







http://ift.tt/1odwfEV