I am trying to copy directory using WP_Filesystem API with the method copy_dir() on plugin activation, but it is give me the following error message:

Plugin could not be activated because it triggered a fatal error.

Fatal error: Call to undefined method WP_Filesystem_Direct::copy_dir()
in D:\xampp\htdocs\wordpress\wp-content\plugins\xxxxxxxx\xxxxxx.php on line 98

Here is my codes:

function sstssfb_activation_hook_vcheck() {

    /* INITIALIZE WPFilesytem */
    $access_type = get_filesystem_method();
    if($access_type === 'direct') {
        $url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
        $creds = request_filesystem_credentials($url, '', false, false, array());
            // initialize the API
            if ( ! WP_Filesystem($creds) ) {
                // any problems and we exit
            global $wp_filesystem;

    /* MOVE ADDITIONAL assets TO THAT (sstssfb_assets) DIRECTORY */
        // addons
        $wp_filesystem->copy_dir(SSTSSFBDIR_ADDONS_ORI, SSTSSFB_ASSET_DIR, true);
        // themes
        $wp_filesystem->copy_dir(SSTSSFB_THEMEDIR_ORI, SSTSSFB_ASSET_DIR, true);

    register_activation_hook(__FILE__, "sstssfb_activation_hook_vcheck");

What would be the problem here?

  • The problem here, honestly and respectfully, is that having a plugin copy files around the filesystem is almost always the wrong way to solve a problem and will always be subject to server permissions beyond your control and so may not work whatever your do. If you could explain the problem you are trying to solve rather than the broken method you are using to try to solve that problem perhaps someone will have a solution.
    – s_ha_dum
    Commented Nov 18, 2015 at 15:11

1 Answer 1


That was my fault!

The problem is copy_dir isn't a WP_Filesystem method, so it cannot be called as an instance of WP_Filesystem like this: $wp_filesystem->copy_dir(), but independently like this: copy_dir("source", "destination") after the WP_Filesystem() has already been called and setup.

Reference copy_dir

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.