WP_Filesystem_Direct::move()publicWP 2.5.0

Moves a file or directory.

After moving files or directories, OPcache will need to be invalidated.

If moving a directory fails, copy_dir() be used for a recursive copy.

Use move_dir() moving directories with OPcache invalidation and a fallback to copy_dir().

Метод класса: WP_Filesystem_Direct{}

Хуков нет.

Возвращает

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

Использование

$WP_Filesystem_Direct = new WP_Filesystem_Direct();
$WP_Filesystem_Direct->move( $source, $destination, $overwrite );
$source(строка) (обязательный)
Path to the source file.
$destination(строка) (обязательный)
Path to the destination file.
$overwrite(true|false)
Whether to overwrite the destination file if it exists.
По умолчанию: false

Список изменений

С версии 2.5.0 Введена.

Код WP_Filesystem_Direct::move() WP 6.5.2

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

	if ( $overwrite && $this->exists( $destination ) && ! $this->delete( $destination, true ) ) {
		// Can't overwrite if the destination couldn't be deleted.
		return false;
	}

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

	// Backward compatibility: Only fall back to `::copy()` for single files.
	if ( $this->is_file( $source ) && $this->copy( $source, $destination, $overwrite ) && $this->exists( $destination ) ) {
		$this->delete( $source );

		return true;
	} else {
		return false;
	}
}