/**
* Copies all attachment files of the site with given ID to the current site.
*
* @since 3.0.0
*
* @param int $source_site_id Source site ID.
*
* @return bool Whether or not any attachment files were copied.
*/
public function copy_attachments($source_site_id)
{
$destination_dir = $this->base_path_adapter->basedir();
switch_to_blog($source_site_id);
$source_dir = $this->base_path_adapter->basedir();
if (!(is_dir($source_dir) && is_readable($source_dir))) {
restore_current_blog();
return false;
}
$attachment_paths = $this->get_attachment_paths();
if (!$attachment_paths) {
restore_current_blog();
return false;
}
$this->found_files = false;
array_walk($attachment_paths, function (array $paths, $dir) use($source_dir, $destination_dir) {
$this->copy_dir($paths, "{$source_dir}/{$dir}", "{$destination_dir}/{$dir}");
});
if ($this->found_files) {
$source_url = $this->base_path_adapter->baseurl();
restore_current_blog();
$this->update_attachment_urls($source_url, $this->base_path_adapter->baseurl());
return true;
}
restore_current_blog();
return false;
}