Skip to:
Content
Pages
Categories
Search
Top
Bottom

Deliver Custom Message via BuddyPress to new users


  • ad4m_wordpress
    Participant

    @ad4m_wordpress

    I have it configured that when a new user registers they are redirected to their profile page.

    This is their first experience with the site, so I have automatically added myself as their friend.

    I’d also like each new user to have a custom message delivered to THEIR BUDDYPRESS messages area, NOT a custom email sent to the email address they registered with.

    Any ideas on how to accomplish this? or if there is a plugin that can handle it?

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

  • shanebp
    Moderator

    @shanebp

    Take a look at function messages_new_message in
    bp-messages/bp-messages-functions.php

    Example: Assuming your id is 1 and the new member’s id is 99

    messages_new_message( array('sender_id' => 1, 'subject' => 'Welcome', 'content' => 'This is the message content', 'recipients' => 99 ) ) )

    You can probably include it where ever you are making yourself their friend.


    Henry Wright
    Moderator

    @henrywright

    messages_new_message() is the function that’s used to send messages in BP core, so you could utilise that? You’ll want to hook your function to the bp_core_activated_user hook. For example:

    function send_message_to_new_member( $user_id, $key, $user ) {
        $args = array(
            'sender_id' => 1,
            'thread_id' => false,
            'recipients' => array( $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', 3 );

    Note: $result will be either the ID of the new message thread if the message was sent successfully, or it’ll be false on failure.


    Henry Wright
    Moderator

    @henrywright

    @shanebp you beat me to it 🙂

    @henrywright this could qualify as a neat little tip/custom function for the codex, if you care to? Although if being used this means messaging is active, is it not still prudent to run an active check bailing if not?


    Henry Wright
    Moderator

    @henrywright

    @hnla you’re right, it could be more robust. I’ve added a conditional check to test if the messages component is active.

    function send_message_to_new_member( $user_id, $key, $user ) {
    
        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', 3 );

    I think editing the codex is off-limits to the masses right now, although you may have access? See here.

    @@henrywright yes we essentially had to shut off access to the WP backend as the only effective way to cut off the bots as it was such an overwhelming and sustained onslaught, unlike anything I’ve seen before and I’ve experienced a few over the years. When access restored you should be able to post, hopefully whoever has had access previously i.e published pages was/is an author should find they continue to be able to edit/publish as they used to.


    ad4m_wordpress
    Participant

    @ad4m_wordpress

    @shanebp, @henrywright

    How could this be configured to alternatively pre-populate their wall with a message from me? Preferably one that includes a youtube.com embedded video?

    Again the goal is to give them a nice welcome message and short tour of the site and how they can use it.


    Henry Wright
    Moderator

    @henrywright

    Instead of using messages_new_message() to send a private message, you’d use bp_activity_post_update() to post an activity update. Note that the function accepts different arguments so you’ll need to amend those.

    See here for more info on the function.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Deliver Custom Message via BuddyPress to new users’ is closed to new replies.
Skip to toolbar