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.
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.
@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?
@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.
@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.
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.