Last active
November 23, 2021 16:08
-
-
Save abaicus/a0930d6b0e1c9fac68efb675eef9a901 to your computer and use it in GitHub Desktop.
Inserts 13000 lot of users into the db
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
const TEST_USERS_OPT = 'test-users-generated'; | |
$generated = get_option( TEST_USERS_OPT ); | |
if( $generated === 'yes' ) { | |
return; | |
} | |
function do_insert( $place_holders, $values ) { | |
global $wpdb; | |
update_option( TEST_USERS_OPT, 'yes' ); | |
$query = "INSERT INTO wp_users (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_registered`, `display_name`) VALUES "; | |
$query .= implode( ', ', $place_holders ); | |
$sql = $wpdb->prepare( "$query ", $values ); | |
$wpdb->query( $sql ); | |
} | |
$data_to_be_inserted = array(); | |
for( $i = 0; $i <= 13000; $i ++ ) { | |
$data_to_be_inserted[] = [ | |
'user_login' => 'name-' . $i, | |
'user_pass' => 'test-1'. $i, | |
'user_nicename' => 'test' . $i, | |
'user_email' => $i . '[email protected]', | |
'user_registered' => current_time( 'mysql' ), | |
'display_name' => 'user-' . $i | |
]; | |
} | |
$values = $place_holders = []; | |
foreach ( $data_to_be_inserted as $data ) { | |
array_push( $values, | |
$data['user_login'], | |
$data['user_pass'], | |
$data['user_nicename'], | |
$data['user_email'], | |
$data['user_registered'], | |
$data['display_name'] ); | |
$place_holders[] = "( %s, %s, %s, %s, %s, %s)"; | |
} | |
do_insert( $place_holders, $values ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment