wpseek.com
A WordPress-centric search engine for devs and theme authors



move_dir › WordPress Function

Since5.9.0
Deprecatedn/a
move_dir ( $from, $to )
Parameters: (2)
  • (string) $from Source directory.
    Required: Yes
  • (string) $to Destination directory.
    Required: Yes
Returns:
  • (true|WP_Error) True on success, WP_Error on failure.
Defined at:
Codex:

Moves a directory from one location to another via the rename() PHP function.

If the renaming failed, falls back to copy_dir(). Assumes that WP_Filesystem() has already been called and setup.


Source

function move_dir( $from, $to ) {
	global $wp_filesystem;

	$wp_filesystem->rmdir( $to );
	if ( @rename( $from, $to ) ) {
		return true;
	}

	$wp_filesystem->mkdir( $to );
	$result = copy_dir( $from, $to );

	return $result;
}