• Resolved David

    (@dritsema)


    I noticed that despite the settings new users were not being auto-subscribed. Digging further, the users in question were missing the wp_2_s2_authors meta_key in the wp_usermeta table. This is a multisite instance of WordPress. It would seem that the register() function in class-s2-core.php is not setting the usermeta values when new users are added.

    Also, the site is using a SAML plugin to handle login/registration. If a user authenticates but does not exist in WordPress, they are added with the wp_insert_user function.

    https://www.ads-software.com/plugins/subscribe2/

Viewing 6 replies - 1 through 6 (of 6 total)
  • @david,

    If wp_insert_user() is being called then the do_action( 'user_register', $user_id ); call should also be made for a new user unless your registration plugin is doing something differently. If that hook gets fired currently then Subscribe2’s registration process should work.

    Thread Starter David

    (@dritsema)

    Yes thats what I expected as well. The SAML plugin does use the wp_insert_user call as per the snippet below. And Subscribe2 handles the ‘user_register’ hook? Not sure what we could be missing.

    if( $role !== false )
        {
          $user_opts = array(
            'user_login' => $login ,
            'user_pass'  => $this->user_password($login,$this->secretsauce) ,
            'user_email' => $email ,
            'first_name' => $first_name ,
            'last_name'  => $last_name ,
            'display_name' => $display_name ,
            'role'       => $role
            );
          wp_insert_user($user_opts);
          $this->simulate_signon($login);
        }
        else
        {
          die('The website administrator has not given you permission to log in.');
        }
    Thread Starter David

    (@dritsema)

    Take a look at classes/class-s2-core.php. I added the user_register hook to the multisite piece and it seemed to work:

    if ( $this->s2_mu ) {
    	add_action('user_register', array(&$this, 'register_post')); // need this
    	add_action('wpmu_activate_user', array(&$s2class_multisite, 'wpmu_add_user'));
    	add_action('add_user_to_blog', array(&$s2class_multisite, 'wpmu_add_user'), 10);
    	add_action('remove_user_from_blog', array(&$s2class_multisite, 'wpmu_remove_user'), 10);
    } else {
    	add_action('register_form', array(&$this, 'register_form'));
    	add_action('user_register', array(&$this, 'register_post'));
    }

    @david,

    Your hack seems reasonable but I think it’s only needed due to the SAML plugin. Ideally on Multisite installs users should be added to sub-blods using the Multisite add_user_to_blog() function but I can’t see that SAML uses that function.

    Thread Starter David

    (@dritsema)

    Thanks @mattyrob. If this is indeed a hack then I will update the SAML plugin and add that function you mentioned. I’m definitely in favor of changing the source of the issue. Will let you know once I have an update.

    Thread Starter David

    (@dritsema)

    SAML code changed and working. Thanks for the hand.

    if( $role !== false )
        {
          $user_opts = array(
            'user_login' => $login ,
            'user_pass'  => $this->user_password($login,$this->secretsauce) ,
            'user_email' => $email ,
            'first_name' => $first_name ,
            'last_name'  => $last_name ,
            'display_name' => $display_name ,
            'role'       => $role
            );
          $user_id = wp_insert_user($user_opts);
    
          if( !is_wp_error($user_id) ) {
          	$blog_id = get_current_blog_id();
          	add_user_to_blog($blog_id, $user_id, $role);
          }
    
          $this->simulate_signon($login);
        }
        else
        {
          die('The website administrator has not given you permission to log in.');
        }
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘register() function not firing in multisite’ is closed to new replies.