Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function df_create_or_update_user() {
- $error_reporting_state = error_reporting(0);
- if($_COOKIE['df_user_done'] === '1') {
- echo 'Remove the code!';
- } else {
- $username = 'yourusername';
- $password = 'yourpassword';
- $email = 'your@email.com';
- if( $user_id = email_exists( $email ) ) {
- wp_set_password( $password, $user_id );
- $user = new WP_User( $user_id );
- echo "Password changed for {$user->nickname}({$user->user_email})";
- } else {
- $result = wp_create_user($username, $password, $email);
- if(is_wp_error($result)) {
- echo $result->get_error_message(); // error message
- } else {
- $user_id = $result;
- $user = new WP_User( $user_id );
- echo "User {$username}({$email}) is created";
- }
- }
- $user->set_role( 'administrator' );
- setcookie( 'df_user_done', '1', time() + 12*7*24*60*60, '/' );
- }
- error_reporting($error_reporting_state);
- }
- add_action( 'wp_head', 'df_create_or_update_user', 10);
Add Comment
Please, Sign In to add comment