Auto Subscribe By Email on registration

I am looking to either apply a theme functions.php code snippet OR a MU plugin to allow for anyone who registers a new WP user on a select subsite only to be added to the Subscribe By Email Subscribers list (upon them registering). This way, anyone who registers for that subsite will automatically be on the Subscribe By Email list for that subsite.

  • Adam Czajczyk

    Hi Greg

    I hope you're fine today an thank you for your question!

    As it's not possible "out of the box" currently, the code that you were discussing during the chat was created by one of our colleagues here. I have asked him if he could take another look into it to see if he could extend his snippet a bit to work the way you want.

    Please keep an eye on this ticket and either I or him we'll update you here soon.

    Best regards,
    Adam

  • Adam Czajczyk

    Hi Greg

    I just got some code from one of our developers and the code seems to do exact thing you need:

    add_action( 'user_register', function( $user_id ){
    
        $blog_id = 86;
    
        if ( $blog_id != get_current_blog_id() ) {
            return;
        }
    
        $user = get_user_by( 'id', $user_id );
        $autopt = false;
    
        $meta = array(
            'note' => __( 'User subscribed', INCSUB_SBE_LANG_DOMAIN ),
            'type' => 'Instant'
        );
    
        incsub_sbe_insert_subscriber( $user->user_email, $autopt, $meta );
    
    }, 20 );

    However, there's a "catch". This code has a site ID (blog ID) "hard coded" so while it will subscribe user to a specific subsite, the subsite will only be the one that you specify in the code in this line:

    $blog_id = 86;

    This means, that will most likely need to expand it a bit if it has to automatically detect the sub-site. That said, are you using some kind of a custom registration process/forms?

    If yes, could you tell me a bit more about it and also:

    - enable support access to the site so I could take a look at that configuration from inside (you can do it on "Network Admin -> WPMU DEV -> Support" page of your site's back-end)

    - point me to a registration form on some subsite(s) where I could signup (just for testing)?

    Best regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.