/** * Copy files from one site to another * @since 0.2.0 * @param int $from_site_id duplicated site id * @param int $to_site_id new site id */ public static function copy_files($from_site_id, $to_site_id) { // Switch to Source site and get uploads info switch_to_blog($from_site_id); $wp_upload_info = wp_upload_dir(); $from_dir['path'] = str_replace(' ', "\\ ", trailingslashit($wp_upload_info['basedir'])); $from_site_id == MUCD_PRIMARY_SITE_ID ? $from_dir['exclude'] = MUCD_Option::get_primary_dir_exclude() : ($from_dir['exclude'] = array()); // Switch to Destination site and get uploads info switch_to_blog($to_site_id); $wp_upload_info = wp_upload_dir(); $to_dir = str_replace(' ', "\\ ", trailingslashit($wp_upload_info['basedir'])); restore_current_blog(); $dirs = array(); $dirs[] = array('from_dir_path' => $from_dir['path'], 'to_dir_path' => $to_dir, 'exclude_dirs' => $from_dir['exclude']); $dirs = apply_filters('mucd_copy_dirs', $dirs, $from_site_id, $to_site_id); foreach ($dirs as $dir) { if (isset($dir['to_dir_path']) && !MUCD_Files::init_dir($dir['to_dir_path'])) { MUCD_Files::mkdir_error($dir['to_dir_path']); } MUCD_Duplicate::write_log('Copy files from ' . $dir['from_dir_path'] . ' to ' . $dir['to_dir_path']); MUCD_Files::recurse_copy($dir['from_dir_path'], $dir['to_dir_path'], $dir['exclude_dirs']); } return true; }
/** * Initialize file before writing * @since 0.2.0 * @return boolean True on success, False on failure */ private function init_file() { if (MUCD_Files::init_dir($this->log_dir_path) !== false) { if (!($this->fp = @fopen($this->log_file_path, 'a'))) { return false; } chmod($this->log_file_path, 0777); return true; } return false; }