/** * Tests getting cononical [absolute] path of file * * Tests wp_realpath() */ public function test_wp_realpath() { /** * Test using URI */ $this->assertEquals($this->path, wp_realpath($this->uri)); $this->assertFalse(wp_realpath('test://somedir/../' . $this->filename)); /** * Test using path */ $this->assertEquals($this->path, wp_realpath($this->path)); $this->assertEquals($this->path, wp_realpath($this->test_dir . '/../stream_tests/' . $this->filename)); /** * Test a false return */ $this->assertFalse(wp_realpath('')); }
/** * Removes directory recursively * * IMPORTANT: This function is experimental and has not been tested. * * Attempts to remove the given directory recursively. Unlike PHP's rmdir() * which only removes the directory if it's empty, wp_rmdir_recursive() will * try to recursively delete all files and directories. Essentially this is * equivalent to a "rm -rf" command, or a forced rmdir() if you will. * * @param string $uri * the URI or path to file. * * @return bool * true on success or false on failure. * * @link http://us2.php.net/manual/en/function.rmdir.php * @see rmdir() * @since 1.0.0 */ function wp_rmdir_recursive($uri) { $path = wp_realpath($uri); $path = rtrim($path, "/"); $objects = glob($path . '/*', GLOB_MARK); foreach ($objects as $object) { if (is_dir($object)) { wp_rmdir_recursive($object); } else { unlink($object); } } if (is_dir($path)) { return rmdir($path); } return true; }