diff --git a/README.md b/README.md index 91734a5..d3222d5 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ * Contributors: pdargham, julienog, daviddaug, globalis * Tags: duplicate, clone, copy, duplication, duplicator, factory, multisite, site, blog, network, wpmu, new blog * Requires at least: 4.0.0 -* Tested up to: 4.7.1 -* Stable tag: 1.4.1 +* Tested up to: 4.9.5 +* Stable tag: 1.5.0 * License: GPLv2 or later * License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -95,6 +95,11 @@ Screenshots on ## Changelog +### 1.5.0 +* Fix duplicating exponentially usermeta +* Fix unix WP path validation and allow points +* Remove cache flushing on error + ### 1.4.1 * Fix wp_cli activation diff --git a/lib/duplicate.php b/lib/duplicate.php index 9a0970c..7b2f2cd 100644 --- a/lib/duplicate.php +++ b/lib/duplicate.php @@ -52,7 +52,6 @@ public static function duplicate_site($data) { $user_id = MUCD_Duplicate::create_admin($email, $domain); if ( is_wp_error( $user_id ) ) { - wp_cache_flush(); $form_message['error'] = $user_id->get_error_message(); return $form_message; } @@ -63,7 +62,6 @@ public static function duplicate_site($data) { $wpdb->show_errors(); if ( is_wp_error( $to_site_id ) ) { - wp_cache_flush(); $form_message['error'] = $to_site_id->get_error_message(); return $form_message; } @@ -140,6 +138,20 @@ public static function copy_users($from_site_id, $to_site_id) { global $wpdb; + // Bugfix Pierre Dargham : relocating this declaration outside of the loop + // PHP < 5.3 + function user_array_map( $a ){ return $a[0]; } + + if (is_main_site($from_site_id)) { + $is_from_main_site = true; + $all_sites_ids = MUCD_Functions::get_sites(['fields' => 'ids']); + if(!empty($all_sites_ids)) { + $all_sites_ids = array_map( 'user_array_map', $all_sites_ids ); + } + } else { + $is_from_main_site = false; + } + // Source Site information $from_site_prefix = $wpdb->get_blog_prefix( $from_site_id ); // prefix $from_site_prefix_length = strlen($from_site_prefix); // prefix length @@ -154,24 +166,23 @@ public static function copy_users($from_site_id, $to_site_id) { switch_to_blog($to_site_id); - // Bugfix Pierre Dargham : relocating this declaration outside of the loop - // PHP < 5.3 - function user_array_map( $a ){ return $a[0]; } - foreach ($users as $user) { if($user->user_email != $admin_email) { add_user_to_blog( $to_site_id, $user->ID, 'subscriber'); - // PHP >= 5.3 - //$all_meta = array_map( function( $a ){ return $a[0]; }, get_user_meta( $user->ID ) ); - // PHP < 5.3 $all_meta = array_map( 'user_array_map', get_user_meta( $user->ID ) ); foreach ($all_meta as $metakey => $metavalue) { $prefix = substr($metakey, 0, $from_site_prefix_length); if($prefix==$from_site_prefix) { $raw_meta_name = substr($metakey,$from_site_prefix_length); + if($is_from_main_site) { + $parts = explode('_', $raw_meta_name, 2); + if (count($parts) > 1 && in_array($parts[0], $all_sites_ids)) { + continue; + } + } update_user_meta( $user->ID, $to_site_prefix . $raw_meta_name, maybe_unserialize($metavalue) ); } } diff --git a/lib/functions.php b/lib/functions.php index 05f5baf..90426b3 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -27,7 +27,7 @@ public static function valid_windows_dir_path($path) { * @return boolean true | false */ public static function valid_unix_dir_path($path) { - $reg = "/^(\/([a-z0-9+\$_-])+)*\/?$/"; + $reg = "/^(\/([a-z0-9+\$_.-])+)*\/?$/"; $bool = preg_match($reg,$path); return ($bool == 1); } diff --git a/multisite-clone-duplicator.php b/multisite-clone-duplicator.php index 52ec6af..e94402b 100644 --- a/multisite-clone-duplicator.php +++ b/multisite-clone-duplicator.php @@ -4,11 +4,11 @@ * Plugin URI: http://wordpress.org/plugins/multisite-clone-duplicator/ * Description: Clones an existing site into a new one in a multisite installation : copies all the posts, settings and files * Author: Julien OGER, Pierre DARGHAM, David DAUGREILH, GLOBALIS media systems - * Author URI: https://github.com/pierre-dargham/multisite-clone-duplicator + * Author URI: https://github.com/globalis-ms/multisite-clone-duplicator * - * Version: 1.4.1 + * Version: 1.5.0 * Requires at least: 4.0.0 - * Tested up to: 4.7.1 + * Tested up to: 4.9.5 * * Network: true */ @@ -53,7 +53,7 @@ class MUCD { /** * Plugin's version number */ - const VERSION = '1.4.1'; + const VERSION = '1.5.0'; /** * Register hooks used by the plugin diff --git a/readme.txt b/readme.txt index e4d4fc2..193b53a 100644 --- a/readme.txt +++ b/readme.txt @@ -2,8 +2,8 @@ Contributors: pdargham, julienog, daviddaug, globalis Tags: duplicate, clone, copy, duplication, duplicator, factory, multisite, site, blog, network, wpmu, new blog Requires at least: 4.0.0 -Tested up to: 4.7.1 -Stable tag: 1.4.1 +Tested up to: 4.9.5 +Stable tag: 1.5.0 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -93,6 +93,11 @@ As of now, following languages are supported : English (en_US), French (fr_FR), == Changelog == += 1.5.0 = +* Fix duplicating exponentially usermeta +* Fix unix WP path validation and allow points +* Remove cache flushing on error + = 1.4.1 = * Fix wp_cli activation