itable( $file ); } return $this->fs->is_writable( $file ); } /** * Checks if a file is readable. * * @since 4.1.9 * * @param string $file Path to file. * @return bool Whether $file is readable. */ public function isReadable( $file ) { if ( ! $this->isWpfsValid() ) { return @is_readable( $file ); } return $this->fs->is_readable( $file ); } /** * Gets the file size (in bytes). * * @since 4.1.9 * * @param string $file Path to file. * @return int|bool Size of the file in bytes on success, false on failure. */ public function size( $file ) { if ( ! $this->isWpfsValid() ) { return @filesize( $file ); } return $this->fs->size( $file ); } /** * Checks if resource is a file. * * @since 4.1.9 * * @param string $file File path. * @return bool Whether $file is a file. */ public function isFile( $file ) { if ( ! $this->isWpfsValid() ) { return @is_file( $file ); } return $this->fs->is_file( $file ); } /** * Checks if resource is a directory. * * @since 4.1.9 * * @param string $path Directory path. * @return bool Whether $path is a directory. */ public function isDir( $path ) { if ( ! $this->isWpfsValid() ) { return @is_dir( $path ); } return $this->fs->is_dir( $path ); } /** * A simple check to ensure that the WP_Filesystem is valid. * * @since 4.1.9 * * @return bool True if valid, false if not. */ public function isWpfsValid() { if ( ! is_a( $this->fs, 'WP_Filesystem_Base' ) || ( // Errors is a WP_Error object. ! empty( $this->fs->errors ) && // We directly check if the errors array is empty for compatibility with WP < 5.1. ! empty( $this->fs->errors->errors ) ) ) { return false; } return true; } /** * In order to not have a conflict, we need to return a clone. * * @since 4.1.9 * * @return Filesystem The cloned Filesystem object. */ public function noConflict() { return clone $this; } }