Title: Scandir errors: consistent errors when plugin uses scandir
Last modified: August 1, 2022

---

# Scandir errors: consistent errors when plugin uses scandir

 *  Resolved [sqzr1](https://wordpress.org/support/users/sqzr1/)
 * (@sqzr1)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/scandir-errors-consistent-errors-when-plugin-uses-scandir/)
 * Our debug log is showing alot of errors coming from wpdiscuz. They seem to all
   relate to when the plugin calls `scandir`.
 * Any ideas how to fix this?
 *     ```
       PHP message: Warning: scandir(vip://wp-content/uploads/wpdiscuz/themes/): failed to open dir: &quot;Automattic\VIP\Files\VIP_Filesystem_Stream_Wrapper::dir_opendir&quot; call failed in /var/www/wp-content/plugins/wpdiscuz/forms/wpdFormAttr/Form.php on line 1670 [] [
           wp-content/plugins/wpdiscuz/forms/wpdFormAttr/Form.php:1670 scandir(), 
           wp-content/plugins/wpdiscuz/utils/class.WpdiscuzHelper.php:349 wpdFormAttr\Form->getThemes(), 
           wp-content/plugins/wpdiscuz/class.WpdiscuzCore.php:1226 WpdiscuzHelper->enqueueWpDiscuzStyle(), 
           wp-includes/class-wp-hook.php:307 WpdiscuzCore->frontendFiles(), 
           wp-includes/class-wp-hook.php:331 WP_Hook->apply_filters(), 
           wp-includes/plugin.php:476 WP_Hook->do_action(), 
           wp-includes/script-loader.php:2156 do_action('wp_enqueue_scripts'), 
           wp-includes/class-wp-hook.php:307 wp_enqueue_scripts(), 
           wp-includes/class-wp-hook.php:331 WP_Hook->apply_filters(), 
           wp-includes/plugin.php:476 WP_Hook->do_action(), 
           wp-includes/general-template.php...
       ```
   
 * WordPress 6.0
    PHP 7.6 Plugin version 7.3.20
 * Another error where a for loop is called and an array that has been populated
   by scandir is passed into the for loop.
 *     ```
       PHP message: Warning: Invalid argument supplied for foreach() in /var/www/wp-content/plugins/wpdiscuz/forms/wpdFormAttr/Form.php on line 1673 [] [
           wp-content/plugins/wpdiscuz/utils/class.WpdiscuzHelper.php:349 wpdFormAttr\Form->getThemes(), 
           wp-content/plugins/wpdiscuz/class.WpdiscuzCore.php:1226 WpdiscuzHelper->enqueueWpDiscuzStyle(), 
           wp-includes/class-wp-hook.php:307 WpdiscuzCore->frontendFiles(), 
           wp-includes/class-wp-hook.php:331 WP_Hook->apply_filters(), 
           wp-includes/plugin.php:476 WP_Hook->do_action(), 
           wp-includes/script-loader.php:2156 do_action('wp_enqueue_scripts'), 
           wp-includes/class-wp-hook.php:307 wp_enqueue_scripts(), 
           wp-includes/class-wp-hook.php:331 WP_Hook->apply_filters(), 
           wp-includes/plugin.php:476 WP_Hook->do_action(), 
           wp-includes/general-template.php:3042 do_action('wp_head'), 
           wp-content/themes/foo/header.php:58 wp_head(), 
           wp-includes/template.php:770 require_once('wp-content/themes/foo/header.php'), 
           wp-includes/template.php:716 lo...
       ```
   
 * The relevant code is here:
 *     ```
       public function getThemes() {
           $themes = [];
           $path = str_replace("\\", "/", WPDISCUZ_DIR_PATH) . "/themes/";
           $scannedThemes = scandir($path);
           unset($scannedThemes[0]);
           unset($scannedThemes[1]);
           foreach ($scannedThemes as $k => $scannedTheme) {
               if (is_dir($path . $scannedTheme)) {
                   $theme = wp_get_theme($scannedTheme, $path);
                   if ($theme->exists()) {
                       $themes[$path . $scannedTheme] = [
                           "name" => $theme->get("Name"),
                           "desc" => $theme->get("Description"),
                           "url" => plugins_url(WPDISCUZ_DIR_NAME . "/themes/$scannedTheme"),
                       ];
                   }
               }
           }
           $uplDir = wp_upload_dir();
           $themesDir = str_replace("\\", "/", $uplDir["basedir"]) . wpdFormConst::THEMES_DIR;
           if (is_dir($themesDir)) {
               $scannedThemes = scandir($themesDir);
               unset($scannedThemes[0]);
               unset($scannedThemes[1]);
               /* ERROR OCCURS HERE */ foreach ($scannedThemes as $k => $scannedTheme) {  
                   if (is_dir($themesDir . $scannedTheme)) {
                       $theme = wp_get_theme($scannedTheme, $themesDir);
                       if ($theme->exists()) {
                           $themes[$themesDir . $scannedTheme] = [
                               "name" => $theme->get("Name"),
                               "desc" => $theme->get("Description"),
                               "url" => $uplDir["baseurl"] . wpdFormConst::THEMES_DIR . $scannedTheme,
                           ];
                       }
                   }
               }
           }
           return $themes;
       }
       ```
   
    -  This topic was modified 3 years, 10 months ago by [sqzr1](https://wordpress.org/support/users/sqzr1/).
    -  This topic was modified 3 years, 10 months ago by [sqzr1](https://wordpress.org/support/users/sqzr1/).
    -  This topic was modified 3 years, 10 months ago by [sqzr1](https://wordpress.org/support/users/sqzr1/).
      Reason: Not spam
    -  This topic was modified 3 years, 10 months ago by [sqzr1](https://wordpress.org/support/users/sqzr1/).

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Support [gVectors Support](https://wordpress.org/support/users/gvectorssupport/)
 * (@gvectorssupport)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/scandir-errors-consistent-errors-when-plugin-uses-scandir/#post-15876726)
 * We’ll check and get back to you ASAP.
 *  Thread Starter [sqzr1](https://wordpress.org/support/users/sqzr1/)
 * (@sqzr1)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/scandir-errors-consistent-errors-when-plugin-uses-scandir/#post-15879109)
 * Thanks, it looks like the issue is with WordPress VIP rather than with your plugin.
 * WordPress VIP has this weird ‘faux’ file setup on servers (some places the files
   don’t really exist!). This means certain file functions just fail. For eg, when
   your plugin uses scandir().
 * See here for more details on WP VIP file setup: [https://docs.wpvip.com/technical-references/vip-go-files-system/](https://docs.wpvip.com/technical-references/vip-go-files-system/)
 *  Thread Starter [sqzr1](https://wordpress.org/support/users/sqzr1/)
 * (@sqzr1)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/scandir-errors-consistent-errors-when-plugin-uses-scandir/#post-15883348)
 * [@gvectorssupport](https://wordpress.org/support/users/gvectorssupport/) Do you
   have any plans to update your plugin so it works with WordPress VIP’s file setup?
 * It would be great if you could as WordPress VIP is a very common webhosting business(
   I think they’re owned by Automattic).
    -  This reply was modified 3 years, 10 months ago by [sqzr1](https://wordpress.org/support/users/sqzr1/).
 *  Plugin Support [gVectors Support](https://wordpress.org/support/users/gvectorssupport/)
 * (@gvectorssupport)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/scandir-errors-consistent-errors-when-plugin-uses-scandir/#post-15883663)
 * Dear sqzr1,
 * The issue comes from the Automatic plugin and can’t be fixed by the wpDiscuz 
   side.
 * The same question is discussed here, but seems the solution isn’t provided. [https://github.com/Automattic/vip-go-mu-plugins/issues/1116](https://github.com/Automattic/vip-go-mu-plugins/issues/1116)
 * Anyway, you should contact the Automatic plugin support with this issue.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Scandir errors: consistent errors when plugin uses scandir’ is closed
to new replies.

 * ![](https://ps.w.org/wpdiscuz/assets/icon-256x256.png?rev=1076265)
 * [Comments - wpDiscuz](https://wordpress.org/plugins/wpdiscuz/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wpdiscuz/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wpdiscuz/)
 * [Active Topics](https://wordpress.org/support/plugin/wpdiscuz/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpdiscuz/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpdiscuz/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [gVectors Support](https://wordpress.org/support/users/gvectorssupport/)
 * Last activity: [3 years, 10 months ago](https://wordpress.org/support/topic/scandir-errors-consistent-errors-when-plugin-uses-scandir/#post-15883663)
 * Status: resolved