WP_Filesystem_Direct::move()publicWP 2.5.0

Moves a file.

Method of the class: WP_Filesystem_Direct{}

No Hooks.

Return

true|false. True on success, false on failure.

Usage

$WP_Filesystem_Direct = new WP_Filesystem_Direct();
$WP_Filesystem_Direct->move( $source, $destination, $overwrite );
$source(string) (required)
Path to the source file.
$destination(string) (required)
Path to the destination file.
$overwrite(true|false)
Whether to overwrite the destination file if it exists.
Default: false

Changelog

Since 2.5.0 Introduced.

WP_Filesystem_Direct::move() code WP 6.1.1

public function move( $source, $destination, $overwrite = false ) {
	if ( ! $overwrite && $this->exists( $destination ) ) {
		return false;
	}

	// Try using rename first. if that fails (for example, source is read only) try copy.
	if ( @rename( $source, $destination ) ) {
		return true;
	}

	if ( $this->copy( $source, $destination, $overwrite ) && $this->exists( $destination ) ) {
		$this->delete( $source );

		return true;
	} else {
		return false;
	}
}