Support » Plugins and Hacks » Hacks » How to initialize WP_Filesystem object?

  • Resolved fhsm


    I’m trying to use the the wordpress file system abstraction class in a plugin. I can’t figure out what I’m supposed to pass in to WP_Filesystem to correctly initialize it.

    WordPress(Apache) has write privilege for my uploads dir so it should be able to use direct file system access; however, I’ve found that in my plugin the wp_filesystem is trying to use the FTP ‘driver’. If I add define('FS_METHOD', 'direct'); before calling WP_Filesystem(); and force the direct fs access driver I’m able to use WP_Filesystem as expected.

    I’ve tried WP_Filesystem(array(), 'path/to/my/uploads/dir'); which doesn’t work even though I can write to that path from php in my plugin. Clearly I’m not understanding how get_filesystem_method works when called by WP_Filesystem.

    I don’t want to use FS_METHOD define to force wp_filesystem to the correct driver (for my particular server) as a long term solution. (TL;DR)So what should I be passing for $args and $context to WP_Filesystem to allow the auto detection by get_filesystem_method to work?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How to initialize WP_Filesystem object?’ is closed to new replies.