i am just doing a routine, that will cleanup from a db site usermeta millions of records, due to a wrong code applied by a guy time ago.
i am doing a delete of all records, and reload news, so just this part we assume is +- the same
assuming we have it into a file, data line by line, we get data:
Code: Select all
// get the file data
$filename = 'E:/custom/Garmin_SUBSCRIPTION_codes_1.6.22.csv';
$fp = @fopen($filename, 'r');
if ($fp) {
$ary0 = explode(PHP_EOL, file_get_contents($filename));
}
But this is the first part that is the unique equal.
Now you have the array of data: we assume you'll have emails and usernames and password? Or just emails? and the rest created random?
Code: Select all
$username
(string) (Required) The user's username.
$password
(string) (Required) The user's password.
$email
(string) (Optional) The user's email.
Default value: ''
assume you have all params username, password and email you'll just create a foreach where
the code will do something like this:
Code: Select all
$ck_wpun_exists = username_exists($username);
$user_id = email_exists($user_email);
if ( ! $user_id && ! $ck_wpun_exists ) { // this user do not exists in WP
$role = 'subscriber';
$userdata = array(
'user_login' => $username,
'user_pass' => $user_password,
'user_email' => $user_email,
// 'user_registered' => date_i18n( 'Y-m-d H:i:s', $user_regdate ), // if you do not pass this param, the registration date will be the date of the script execution
'role' => $role
);
$user_id = wp_insert_user( $userdata );
if ( is_wp_error( $user_id ) ) {
echo 'user not added into Wp';
} else {
echo 'user ' .$user_id . ' added into Wp';
}
There are several more things to think to that i not precised here, but generally this will work fine in any scenario.
I know it is not the complete code you want, just a stupid example that assume you are a almost little skilled on programming php and wp, but it need to be created in case. If you want follow asking for steps, i will of course answer here!
p.s if data dump files is really big, containing millions of users, this routine may require to pass a specified number of users each time, insert one by one, and coded to run step by step without breaking due to max execution time.
Very easy concept, but as said, it require to be coded. The browser will run for hours doing tasks like these for millions of records.
Do not know if via cli would be faster. I assume will be exactly the same.
i am just doing a routine, that will cleanup from a db site usermeta millions of records, due to a wrong code applied by a guy time ago.
i am doing a delete of all records, and reload news, so just this part we assume is +- the same
assuming we have it into a file, data line by line, we get data:
[code] // get the file data
$filename = 'E:/custom/Garmin_SUBSCRIPTION_codes_1.6.22.csv';
$fp = @fopen($filename, 'r');
if ($fp) {
$ary0 = explode(PHP_EOL, file_get_contents($filename));
}[/code]
But this is the first part that is the unique equal.
Now you have the array of data: we assume you'll have emails and usernames and password? Or just emails? and the rest created random?
[code]$username
(string) (Required) The user's username.
$password
(string) (Required) The user's password.
$email
(string) (Optional) The user's email.
Default value: ''[/code]
assume you have all params username, password and email you'll just create a foreach where
the code will do something like this:
[code]$ck_wpun_exists = username_exists($username);
$user_id = email_exists($user_email);
if ( ! $user_id && ! $ck_wpun_exists ) { // this user do not exists in WP
$role = 'subscriber';
$userdata = array(
'user_login' => $username,
'user_pass' => $user_password,
'user_email' => $user_email,
// 'user_registered' => date_i18n( 'Y-m-d H:i:s', $user_regdate ), // if you do not pass this param, the registration date will be the date of the script execution
'role' => $role
);
$user_id = wp_insert_user( $userdata );
if ( is_wp_error( $user_id ) ) {
echo 'user not added into Wp';
} else {
echo 'user ' .$user_id . ' added into Wp';
}[/code]
There are several more things to think to that i not precised here, but generally this will work fine in any scenario.
I know it is not the complete code you want, just a stupid example that assume you are a almost little skilled on programming php and wp, but it need to be created in case. If you want follow asking for steps, i will of course answer here!
p.s if data dump files is really big, containing millions of users, this routine may require to pass a specified number of users each time, insert one by one, and coded to run step by step without breaking due to max execution time.
Very easy concept, but as said, it require to be coded. The browser will run for hours doing tasks like these for millions of records.
Do not know if via cli would be faster. I assume will be exactly the same.