Aller au contenu
FR

Adding a User via Functions.php

Adding a User via Functions.php
Version audio de cet article

With this tutorial, we will show you how to add a WordPress user via the functions.php file. This how-to is pretty useful in case you can’t access your admin section of WordPress for whatever reason may be.

While you can always do a password reset, you can easily add a simply line of code within your functions.php file via an FTP software:

Adding a WordPress user via functions.php

function nomdevotrefuonction(){
  /// Ici mettez votre nom utilisateur sans majuscules
  $user = 'Username';
  /// Ici mettez votre mot de passe
  $pass = 'Password';
  /// Ici mettez votre courriel
  $email = 'email@domain.com';
 
  /// Condition que utilisateur existe pas on le créé
  if ( !username_exists( $user )  && !email_exists( $email ) ) {
  $user_id = wp_create_user( $user, $pass, $email );
  $user = new WP_User( $user_id );
  $user->set_role( 'administrator' );
  } 
}
 
add_action('init','nomdevotrefuonction');

Once you’ll save the changes in the functions.php file, the new user will be created thus allowing you to log back in.