Skip to content

Commit

Permalink
Merge pull request #74 from pierre-dargham/develop
Browse files Browse the repository at this point in the history
Version 1.5.0
  • Loading branch information
davddo authored May 15, 2018
2 parents e51c218 + 21d7069 commit ba5bc86
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
29 changes: 20 additions & 9 deletions lib/duplicate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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) );
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions multisite-clone-duplicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit ba5bc86

Please sign in to comment.