Skip to content

Instantly share code, notes, and snippets.

@abaicus
Last active November 23, 2021 16:08
Show Gist options
  • Save abaicus/a0930d6b0e1c9fac68efb675eef9a901 to your computer and use it in GitHub Desktop.
Save abaicus/a0930d6b0e1c9fac68efb675eef9a901 to your computer and use it in GitHub Desktop.
Inserts 13000 lot of users into the db
<?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