bbPress Messages – customizing and extending

Send automatic greeting and welcome messages to new users

In this quick tutorial we are going to talk about how to enable custom messages sent automatically to new user upon a successful registration on our WordPress blog or website.

Required plugins

For this process, you’re going to need:

  • bbPress, the parent plugin of bbPress Messages, for powering forums and communities
  • bbPress Messages: PRO ( v. 0.2.4 or greater), or lite ( v. 0.2.3 or greater ).

That’s all, and no, no BuddyPress is needed or involved.

Extending user registration system

We will be hooking into user_register, which provides us with a user ID for the currently registered user, which we will use to email the user a greeting and welcoming custom message of our own.

Make sure to provide a sender ID, and this is totally required, for the sake of simplicity I made it 1, which will be the first user on your blog and the admin. To find our your user ID, go to users, find your account, and click edit. Now in the address bar there will be something like ?user_id=ID_HERE . That’s the ID you should insert in the sender in follows-code.


Using BBP_messages_message::sender method

This method will allow us to insert the message. It takes 4 parameters, 3 required and one optional:

  • $user_id: (int) the recipient which we will direct the message to.
  • $message: (string) the custom message we are sending.
  • $sender: (int) the message sender user ID, which the user will be able to reply to (if possible) later upon login.
  • $notify(bool) choose whether to notify this user by email about this message or not. It defaults to true, but you can set it to false to not email.

The coding:

Add the following code, to your child theme’s functions file or with a custom plugin, and make sure to make necessary edits such as customizing the message and inserting the message sender ID.

add_action("user_register", function( $user_id ) { 
	if ( !class_exists('BBP_messages_message') ) return; // bbPress messages is not there

	$sender = 1; // admin. Please provide a valid user ID
	$message = sprintf(
		"Greetings, %s!\n\nThis is an automated message, sent to greet and thank you for signing up for a membership on our website.\n\nSee you online,\n%s — %s.",
		get_userdata( $user_id )->display_name,
		get_userdata( $sender )->display_name,
		get_bloginfo( "name" )
	); // message format

	return BBP_messages_message::sender( $user_id, $message, $sender );

That’s it. Hope this tutorial helps you greet and welcome your newly registered bbPress users, and point them to use the messaging functionality or provide instructions and so forth..

If you had any issues, please post in the plugin support forum provided provided by the author.

Digital Ocean

Cheap Cloud SSD Hosting

Get a VPS now starting at $5/m, fast and perfect for WordPress and PHP applications

Sign Up with $10 Credit