/**
	 * Recursively remove the supplied directory.
	 *
	 * @since 1.15.0
	 *
	 * @return bool|WP_Error Boolean true on success or a WP_Error object if an error occurs.
	 */
	public static function remove( $dir ) {
		if ( ! ITSEC_Lib_File::exists( $dir ) ) {
			return true;
		}
		
		
		if ( ! ITSEC_Lib_Utility::is_callable_function( 'rmdir' ) ) {
			return new WP_Error( 'itsec-lib-directory-remove-rmdir-is-disabled', sprintf( __( 'The directory %s could not be removed as the rmdir() function is disabled. This is a system configuration issue.', 'it-l10n-ithemes-security-pro' ), $dir ) );
		}
		
		
		$files = self::read( $dir );
		
		if ( is_wp_error( $files ) ) {
			return new WP_Error( 'itsec-lib-directory-remove-read-error', sprintf( __( 'Unable to remove %1$s due to the following error: %2$s', 'it-l10n-ithemes-security-pro' ), $dir, $files->get_error_message() ) );
		}
		
		foreach ( $files as $file ) {
			if ( ITSEC_Lib_File::is_file( $file ) ) {
				ITSEC_Lib_File::remove( $file );
			} else if ( self::is_dir( $file ) ) {
				self::remove( $file );
			}
		}
		
		$result = rmdir( $dir );
		@clearstatcache( true, $dir );
		
		if ( $result ) {
			return true;
		}
		
		return new WP_Error( 'itsec-lib-directory-remove-unknown-error', sprintf( __( 'Unable to remove %s due to an unknown error.', 'it-l10n-ithemes-security-pro' ), $dir ) );
	}
 /**
  * Test to see if the requested directory is writable.
  *
  * @since 2.3.0
  *
  * @param string $dir Full path to the directory to test.
  * @return bool True if the directory is writable, false otherwise.
  */
 public static function is_writable($dir)
 {
     $dir = rtrim($dir, '/');
     if (!self::is_dir($dir)) {
         return false;
     }
     $test_count = 0;
     do {
         $test_file = 'itsec-test-file-' . wp_generate_password(10, false) . '.txt';
     } while ($test_count++ < 10 && ITSEC_Lib_File::exists("{$dir}/{$test_file}"));
     if (ITSEC_Lib_File::exists("{$dir}/{$test_file}")) {
         return false;
     }
     $result = ITSEC_Lib_File::write("{$dir}/{$test_file}", __('This is a test file generated by iThemes Security. It can be removed.', 'better-wp-security'));
     ITSEC_Lib_File::remove("{$dir}/{$test_file}");
     if (true === $result) {
         return $result;
     }
     return false;
 }