Auto register new user on wordpress

Auto-registering new users on WordPress can be achieved through various plugins and custom code. Here are a few methods:

Method 1: Using a Plugin

  1. Install and activate the "Auto Register" plugin from the WordPress Plugin Directory.
  2. Go to Settings > Auto Register and configure the plugin to auto-register new users.
  3. Set the plugin to auto-register users based on specific criteria, such as email address or username.

Method 2: Using a Custom Plugin

  1. Create a new plugin file (e.g., auto-register.php) in the wp-content/plugins directory.
  2. Add the following code to the plugin file:
    
    <?php
    /*
    Plugin Name: Auto Register
    Description: Auto-register new users on WordPress
    */

function auto_register_new_user($user_id) { // Auto-register new user wp_insert_user(array( 'user_login' => 'newuser', 'user_email' => '[email protected]', 'user_pass' => 'password', 'role' => 'subscriber' // or any other role )); }

add_action('user_register', 'auto_register_new_user'); ?>

3. Activate the plugin and test it by creating a new user account.

**Method 3: Using a Custom Function**

1. Add the following code to your theme's `functions.php` file:
```php
<?php
function auto_register_new_user($user_id) {
    // Auto-register new user
    wp_insert_user(array(
        'user_login' => 'newuser',
        'user_email' => '[email protected]',
        'user_pass' => 'password',
        'role' => 'subscriber' // or any other role
    ));
}

add_action('user_register', 'auto_register_new_user');
?>
  1. Test the function by creating a new user account.

In all cases, the auto_register_new_user function is triggered when a new user registers on your WordPress site. The function uses the wp_insert_user function to create a new user account with the specified details.

Remember to customize the plugin or function code to fit your specific needs, such as changing the default user role or email address.