WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to implement caching using the filesystem so i need to check if i can write in a directory. I've read Otto's article, but i've failed to understand how should i implement a check where the user doesn't input any kind of password. So basically i need to use the direct method, what's the correct way to do it?

share|improve this question

This is what i ended up using

 * check if the path is writable. To make the check .
 * @param string $path
 * @return boolean
public static function is_writable( $path ) {
    global $wp_filesystem;
    include_once ABSPATH . 'wp-admin/includes/file.php';
    // If for some reason the include doesn't work as expected just return false.
    if( ! function_exists( 'WP_Filesystem' ) ) {
        return false;
    $writable = WP_Filesystem( false, $path );
    // We consider the directory as writable if it uses the direct transport,
    // otherwise credentials would be needed
    return $writable && $wp_filesystem->method === 'direct';
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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