Site icon WebDevStudios

What’s New in BuddyPress 2.5

BuddyPress 2.5 adds a few new tools and as always some under the hood improvements that you should get jazzed about! Here are some of the updates we can come to expect from this next BuddyPress update:

BP Email

Contributor Paul Gibbs has added a UI method for creating custom emails. This is a really neat feature. BuddyPress sends emails when users perform specific actions on the site. The emails are a way to keep users engaged with the site and to follow conversations. There is a  new API to send messages.

In the admin, you add a new email message very much like adding a page or post. You can include tokens in the content to be replaced at send time. The token variables are for dynamically replaced text. If you are a plugin developer or want to add custom emails, it’s pretty easy. Everything is post, taxonomy and terms. The post is the message with the post type being bp-email.  The taxonomy is bp-email-type. The terms are what you will use to pass to bp_send_email() during some action hook.

Custom Emails

BuddyPress only includes emails for BuddyPress core functionality. Blog posting is not part of BuddyPress, but it could be an integral part of your community. Let’s look at an example to send an email to a blog post author when a user comments on their post:

Since the emails are post types and taxonomy terms. We will need to insert a post for the post type and then assign it a custom taxonomy term. There is no special BuddyPress code here; it’s straight up WordPress wp_insert_post()wp_set_post_terms() and wp_update_term(). Note: You must hook this to the action bp_core_install_emails. This hook ensures your emails can be flushed out if they need a reset.

function bp_custom_email_message() {

    // Create post object
    $my_post = array(
      'post_title'    => __( '[{{{site.name}}}] New post comment.', 'buddypress' ),
      'post_content'  => __( '{{commenter.name}} commented on your blog post.', 'buddypress' ),
      'post_status'   => 'publish',
      'post_type' => bp_get_email_post_type() // this is the post type for emails
    );

    // Insert the email post into the database
    $post = wp_insert_post( $my_post );

    if ( $post_id ) {
        // add our email to the taxonomy term 'post_recieved_comment'
        $term_id = wp_set_post_terms( $post, 'post_recieved_comment', bp_get_email_tax_type() );
        // update the term's description
        wp_update_term( $term_id[0], bp_get_email_tax_type(), array( 'description' => 'A member comments on a posts' ) );
    }

}
add_action( 'bp_core_install_emails', 'bp_custom_email_message' );

With that function, you should see the new email post in the admin with the correct term “situation” selected. Note: All situations are listed so only select the one that will work with your tokens. This is something that will need to be dealt with in a future version of BuddyPress.

For the next step, hook an action to wp_insert_comment to get the comment data and then send the post author an email. In this function, you create the tokens to parse out in the email before sending.

function bp_comment_inserted( $comment_id, $comment_object ) {

    if ( $comment_object ) {
        // get the post data
        $post = get_post( $comment_object->comment_post_ID );
        // add tokens to parse in email
        $args = array(
            'tokens' => array(
                'site.name' => get_bloginfo( 'name' ),
                'commenter.name' => $comment_object->comment_author,
            ),
        );
        // send args and user idto recieve email
        bp_send_email( 'post_recieved_comment', (int) $post->post_author, $args );
    }
}
add_action( 'wp_insert_comment','bp_comment_inserted', 99, 2 );

Email Design

In the BP Email admin menu there is a link to customizer, here you’ll have the ability to customize the style of the HTML emails from the customizer. In admin, under “Appearance,” there will be an “Emails” menu item. Click this and it will take you to the customizer where you can edit colors and fonts. This is a nice touch for branding your site emails.

 

Comment Tracking

BuddyPress has always had comment tracking for Posts but not Custom Post Types. The feature keeps the comments on posts and comments on the posts activity item in sync. You can add support when you register a post type or after. The code below shows how to add support. You can customize the text of the activity action when a comment is added.

$labels = array(
    'name'                              => 'foos',
    'singular_name'                     => 'foo',
    'bp_activity_comments_admin_filter' => __( 'Comments about foos', 'custom-textdomain' ), // label for the Admin dropdown filter
    'bp_activity_comments_front_filter' => __( 'Foo Comments', 'custom-textdomain' ),        // label for the Front dropdown filter
    'bp_activity_new_comment'           => __( '%1$s commented on the <a href="%2$s">foo</a>', 'custom-textdomain' ),
    'bp_activity_new_comment_ms'        => __( '%1$s commented on the <a href="%2$s">foo</a>, on the site %3$s', 'custom-textdomain' )
);
 
register_post_type( 'foo', array(
    'labels'   => $labels,
    'public'   => true,
    'supports' => array( 'buddypress-activity', 'comments' ), // Adding the comments support
    'bp_activity' => array(
        'action_id'         => 'new_foo',                     // The activity type for posts
        'comment_action_id' => 'new_foo_comment',             // The activity type for comments
    ),
) );

Emojis

WordPress recently added some new emoji enhancements and  BuddyPress 2.5 is taking advantage. Emojis will now show up in activity updates, private messages, and group descriptions. ?????

 

Auto Linking Fields

Auto linked profile fields have typically a very polarizing feature–people either love it or hate it. The feature takes common profile field words and creates a link that, when clicked, sends you to the members directory and filters the list with any other members with the same word in their profile. There is a filter to disable it all together, but not per specific field. Not anymore! @Boone has added a options UI to the profile fields admin creation screen so you can turn this off or on per field. Visit the admin and edit a profile fields you should see the meta box below the visibility options.

 

Activity Stream

2.5 receives some under the hood enhancements for activity.

Twenty Twelve Style Sheet

BuddyPress has companion stylesheets for WordPress yearly themes. These stylesheets have a bit more styles to make BP Legacy templates fit better. BuddyPress 2.5 includes a style sheet for Twenty Twelve.

Inline Docs and A11y

New A11y support for BuddyPress administration screens and ongoing enhancements of inline code documentation.


That about wraps it up. I’m excited for BP Email feature; how about you? It’s the first unique feature BuddyPress has added in awhile that really enhances BuddyPress over all as great solution to creating community sites.

BuddyPress 2.5 RC1 download it from here.

Exit mobile version