Skip to:
Content
Pages
Categories
Search
Top
Bottom

Welcome private message for new buddypress users registering (like Welcome Pack)


  • Kir 2012
    Participant

    @kir-2012

    – I’m using Buddypress Version 2.3.2.1 and WordPress 4.2 and

    Hi, I’ve managed to find a few messages about this with various, similar solutions, but I can’t seem to get it working –

    I want to do something like the Welcome Pack plugin used to do, and send a message to every new user so it is in the inbox of the new user when they log in waiting to welcome them.

    Here’s the code I’ve got which I’ve tried in both functions and bp custom with no success:

    //send msg to new user
    function send_msg_to_new_member( $user_id, $key, $user ) {
        $args = array(
            'sender_id' => 1,
            'thread_id' => false,
            'recipients' => array( $user_id ),
            'subject' => 'Welcome to the site',
            'content' => 'Content of msg goes here',
            'date_sent' => bp_core_current_time()
        );
        $result = messages_new_message( $args );
    }
    add_action( 'bp_core_activated_user', 'send_msg_to_new_member', 3 );
    ?>
    

    Has anyone done this themselves, or got any suggestions as to what I’m doing wrong?
    Many thanks

Viewing 6 replies - 1 through 6 (of 6 total)

  • danbp
    Participant

    @danbp

    You’re declaring 3 arguments, but only one is given if you are testing this localy.
    Possible local scenarion you used:
    – you create a new user
    – you login as admin and activate the pending user. You get 3 warnings. Logout.
    – login as new user.
    – you see the message

    Remove $key & $user and redo the same and all went fine.
    Use function send_msg_to_new_member( $user_id ) and change 3 to 1.
    Add also a conditional check to test if the messages component is active. (see link blow).

    Not tested yet on live site.

    This was originally published by @henrywright here:
    https://buddypress.org/support/topic/deliver-custom-message-via-buddypress-to-new-users/#post-229688


    danbp
    Participant

    @danbp

    Just want to confirm that your snippet is (only)working on live site. For local usage, you’ve already the solution. 😉


    Kir 2012
    Participant

    @kir-2012

    Hi thanks for your reply

    So I replaced the code with this:

    //auto send msg
    
    function send_message_to_new_member( $user_id) {
    
        if ( ! bp_is_active( 'messages' ) )
            return;
    
        $args = array(
            'sender_id' => 1,
            'thread_id' => false,
            'recipients' => $user_id,
            'subject' => 'Hello new user',
            'content' => 'Welcome to the site',
            'date_sent' => bp_core_current_time()
        );
    
        $result = messages_new_message( $args );
    }
    add_action( 'bp_core_activated_user', 'send_message_to_new_member', 1 );
    

    I tried this in functions and bp custom and I can’t get it working – am I doing it correctly or did I get it wrong again?

    Thanks for your help


    Kir 2012
    Participant

    @kir-2012

    Additional: I am working on a live site


    danbp
    Participant

    @danbp

    As I said previously, you can use your first function in bp-custom if you’re only on a live site. For me, it is working correctly. Perhaps, try by activating debug mode in wp-config, so if an error is somewhere, you’ll get a warning message.
    Can’t tell you more, sorry.


    shanebp
    Moderator

    @shanebp

    also, the 1 in this:
    add_action( 'bp_core_activated_user', 'send_message_to_new_member', 1 );

    Is the priority, not the number of args.

    https://codex.wordpress.org/Function_Reference/add_action

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Welcome private message for new buddypress users registering (like Welcome Pack)’ is closed to new replies.
Skip to toolbar