PHP - Custom Registration Form is not running working as expected

I am trying to automatically create a new site/blog when a user registers. I am using using a hook function as shown below. It works fine when using default forms, but not when I use my custom user registration form. The form adds the new users however a new site is not created for the user.

<?php
add_action( 'user_register', 'user_registration_create_site', 10, 1 );

function user_registration_create_site( $user_id ) {

$user_info = get_userdata( $user_id );
if ( isset( $user_info->user_login ) ) {
$main_site = 'weareyou.online'; // Add your main domain here
wpmu_create_blog( $main_site, '/'.$user_info->user_login.'/', $user_info->user_login, $user_id , array( 'public' => 1 ) );
}
}
  • Nicklas
    • Flash Drive

    Now I use this function:
    add_action('cred_save_data', 'my_save_data_action',10,2);
    function my_save_data_action($post_id, $form_data)
    {
    // if a specific form
    if ($form_data['id']==425)
    {
    $user_info = get_userdata( $post_id );
    if ( isset( $user_info->user_login ) ) {
    $main_site = 'weareyou.online'; // Add your main domain here
    $new_blog = wpmu_create_blog( $main_site, '/'.$user_info->user_login.'/', $user_info->user_login, $user_id , array( 'public' => 1 ) );
    add_user_to_blog( $new_blog, $post_id, $user_info->roles );
    wp_delete_user( $post_id);
    }
    }
    }

    I new site is created and the new user is assigned to the new site thats is created with the form. But when I try to login on the new site I get "the page redirects incorrectly" error.

  • Patrick Freitas
    • Staff

    Hi Nicklas

    Hope you are doing well,

    As we spoke in the chat section, the problem is that the URL is being created using the e-mail, so it contains an extra.com that might be causing the issue.

    However, extending the code after the chat, I did research, this function would help you for the first name and surname situation.

    <?php domain_exists($domain, $path, $site_id); ?>

    References on https://codex.wordpress.org/WPMU_Functions/domain_exists

    After creating your function, if possible, update the thread, and it can help other members with the same doubt :slight_smile:

    Best Regards,
    Patrick Freitas

  • Ari
    • Recruit

    Hey Nicklas

    Hope you are fine today!

    In your above reply: https://premium.wpmudev.org/forums/topic/php-custom-registration-form-is-not-running-working-as-expected#post-1351609

    The code you are trying which is not working, can be for many reasons. And we can achieve this functionality in many ways.

    I see you sent the FTP access, can you also give me the page link and screenshot of that form! so I can check how we should proceed to this functionality?

    Regards,
    Ari

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.