forked from AH72KING/Joomla-To-Wordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.php
93 lines (82 loc) · 3.59 KB
/
user.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
set_time_limit( 1800 );
require_once 'config.php';
$wpdb = new wpdb( WPDP_USER, WPDP_PASS, WPDP_DB, WPDP_HOST );
$joomdb = new wpdb( JOOM_USER, JOOM_PASS, JOOM_DB, JOOM_HOST );
$users = $joomdb->get_results( 'select * from ' . JOOM_PREFIX . 'users' );
if ( $users ) {
foreach ($users as $user) {
$user_data = array(
'ID' => $user->id,
'user_pass' => $user->password,
'user_login' => $user->username,
'user_email' => $user->email,
'display_name' => $user->username, // change to $user->name if you want the user's real name in this field instead of username
'user_registered' => $user->registerDate,
);
$user_metadata_capabilities = array(
'user_id' => $user->id,
'meta_key' => 'wp_capabilities',
'meta_value' => 'a:2:{s:10:"subscriber";b:1;s:15:"bbp_participant";b:1;}' // default user wordpress role is subscriber and bbpress is participant
// 'meta_value' => 'a:1:{s:10:"subscriber";b:1;}' // use this if not using bbpress
);
$user_metadata_joomlapass = array(
'user_id' => $user->id,
'meta_key' => 'joomlapass',
'meta_value' => $user->password
);
// import real name into first_name and last_name usermeta fields
$names = explode(" ", $user->name);
$first = $names[0];
$last = "";
if (count($names) > 1) {
$i=0;
foreach ($names as $key => $value) {
if ($i > 0) {
$last .= " $value";
}
$i++;
}
}
$last = trim($last);
$user_metadata_firstname = array(
'user_id' => $user->id,
'meta_key' => 'first_name',
'meta_value' => $first
);
$user_metadata_lastname = array(
'user_id' => $user->id,
'meta_key' => 'last_name',
'meta_value' => $last
);
$user_metadata_nickname = array(
'user_id' => $user->id,
'meta_key' => 'nickname',
'meta_value' => $user->username
);
$user_metadata_user_level = array(
'user_id' => $user->id,
'meta_key' => 'wp_user_level',
'meta_value' => '0' // change wp_user_level if you want to
);
$wpdb->insert(''. WPDP_PREFIX . 'users', $user_data);
$wpdb->insert(''. WPDP_PREFIX . 'usermeta', $user_metadata_joomlapass);
$wpdb->insert(''. WPDP_PREFIX . 'usermeta', $user_metadata_firstname);
$wpdb->insert(''. WPDP_PREFIX . 'usermeta', $user_metadata_lastname);
$wpdb->insert(''. WPDP_PREFIX . 'usermeta', $user_metadata_nickname);
$wpdb->insert(''. WPDP_PREFIX . 'usermeta', $user_metadata_capabilities);
// $wpdb->insert(''. WPDP_PREFIX . 'usermeta', $user_metadata_user_level);
//In Simple SQL
/*
INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`)
VALUES ('newadmin', MD5('pass123'), 'firstname lastname', '[email protected]', '0');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, (Select max(id) FROM wp_users), 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, (Select max(id) FROM wp_users), 'wp_user_level', '10');
*/
}
echo 'Users are Transferred';
} else {
echo "No Users Found<br>";
}