• Resolved sqzr1

    (@sqzr1)


    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: "Automattic\VIP\Files\VIP_Filesystem_Stream_Wrapper::dir_opendir" 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.
    • This topic was modified 3 years, 10 months ago by sqzr1.
    • This topic was modified 3 years, 10 months ago by sqzr1. Reason: Not spam
    • This topic was modified 3 years, 10 months ago by sqzr1.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)

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