0
votes

I have been using this function to automatically require PHP files in a directory.

function req_php_files($filepath) {

  $Directory = new RecursiveDirectoryIterator($filepath);
  $Iterator = new RecursiveIteratorIterator($Directory);
  $Regex = new RegexIterator($Iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);

  $php_files = array();
  foreach ($Regex as $file) {

      array_push($php_files, $file[0]);
  }

  foreach ($php_files as $req_file) { 

    require_once $req_file; 

  }
}

This worked well up until recently for some reason now I'm getting an error when loading wp-admin

PHP Warning: array_keys() expects parameter 1 to be array, null given in /Applications/MAMP/htdocs/vac3/wp-admin/includes/plugin.php on line 1718

PHP Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/vac3/wp-admin/includes/plugin.php on line 1718

Here is how I call the function

$theme_path = 'wp-content/themes/' . get_template() . '/acf';
$theme_path_admin = '../wp-content/themes/' . get_template() . '/acf/';

if (!is_admin()) {

  $filepath= new SplFileInfo($theme_path);

} else {

  //filepath from admin

  $filepath= new SplFileInfo($theme_path_admin);


}

req_php_files($filepath->getRealPath()); ?>

this is line 1718 in the /wp-admin/includes/plugin.php

foreach (array_keys( $_wp_submenu_nopriv ) as $key ) {

My question is What part of my function is passing a non-array value to $_wp_submenu_nopriv?

2

2 Answers

0
votes

The error is saying that the variable $_wp_submenu_nopriv is not an array. You need to find the origin of this variable and find out what type is being passed in.

0
votes

These errors are seemingly misleading. Errors where caused by requiring files manually from a file that was already required by the function

the function was requiring a config.php which loaded the below

<?php require_once 'admin.php'; ?>
<?php require_once 'notification.php'; ?>

deleting the config.php file cleared the errors.