BuddyDev

Search

BuddyPress Activity as Wire Updated for BuddyPress 1.6 & BuddyPress 1.7

I have updated Activity as wire tutorial for BuddyPress 1.8, BuddyPress 1.9+. Please check the new tutorial here

Hi All,
It has been a long time since I updated the code for BuddyPress Activity as wire tutorial.

For those, who don’t know the purpose of it,  This code allows to use activity as wire using the @ mention.

This updated code handles a couple of issues that we had. The following issues are fixed:

  • Double Posting Bug: – The activity was being posted twice. The code in this post fixes that
  • Status updated issue: – The status of the user who posted the message was being updated. It is fixed

There are a couple more minor issues fixed and the code is tested with BuddyPress 1.6.4 and BuddyPress 1.7 Trunk. This will work with BuddyPress 1.5+ without any issue though.

So, let us get started.

Thoughts:-

Since we want to use activity as wire, we will use the @mention feature of BuddyPress to allow us do that. The @mention feature allows us to send public messages to other users and appear in the activity/mentions tab of the user whom we have mentioned. So, It makes perfect sense to use it as wire.

What we need to do:-

  1. Allow User to post when they are visiting other users(to give the feeling of wire)
  2. Use that post as the public message(using @mention feature)

Here is what is actually needed programatically:-

  1. We will need to bypass the BuddyPress default activity posting routine/function and write our own to accomplish the task
  2. we will need to tweak the activity screen(using members/single/acivity.php) to show the form
  3. We will need to tweak the activity posting form to ask the logged in user to post something to the other user when he is visiting the profile

Ok, so we need to write the code now.

Step1:- Making activity form visible on other user’s profile

For this, we will need to edit the members/single/activity.php and change the following line


if ( is_user_logged_in() && bp_is_my_profile() && ( !bp_current_action() || bp_is_current_action( 'just-me' ) ) )
 locate_template( array( 'activity/post-form.php'), true );

It is around line 63-64 to


if ( is_user_logged_in()&&( '' == bp_current_action() || 'just-me' == bp_current_action() ) )
locate_template( array( 'activity/post-form.php'), true ) ;

That will make the form visible on other user’s profile like this

Step2:- Customizing Activity Post Form

You can find it in bp-default(or your theme)/activity/post-form.php

Let us remove the group drop down. To do that, we will need to change this line in post-form.php

<?php if ( bp_is_active( 'groups' ) && !bp_is_my_profile() && !bp_is_group() ) : ?>

to this


<?php if (  function_exists('bp_has_groups') &&!bp_is_member() &&!bp_is_group() ) : ?>

So, the dropdown that shows where to post(group/my profile) gets removed.

Now, we need to change the title box for the post form.

The current title looks like this

We will need to modify the activity/post-form.php again.

Look for the code block which looks like this


<h5><?php if ( bp_is_group() )
 printf( __( "What's new in %s, %s?", 'buddypress' ), bp_get_group_name(), bp_get_user_firstname() );
 else
 printf( __( "What's new, %s?", 'buddypress' ), bp_get_user_firstname() );
 ?></h5>

and change that to this


<h5>
 <?php if ( bp_is_group() ) : ?>
 <?php printf( __( "What's new in %s, %s?", 'buddypress' ), bp_get_group_name(), bp_get_user_firstname() ); ?>
 <?php elseif(!bp_is_my_profile()&&bp_is_member()): ?>
 <?php printf( __( "Write something to %s?", 'buddypress' ), bp_get_displayed_user_fullname() ) ;?>
 <?php else : ?>
 <?php printf( __( "What's new %s?", 'buddypress' ), bp_get_user_firstname() ) ; ?>
 <?php endif; ?>

</h5>

and we are done.

So, the final thing that we need to do is bypass the BuddyPress activity posting routine and create our own routine.

It involves removing the BuddyPress function attached to wp_ajax_post_update and attaching our own.

Step3:- Rewriting the Activity posting routine

Here is the final code. You can put it in your theme’s functions.php or bp-custom.php


//remove the BuddyPress hook that saves the posts to activity stream
add_action('init', 'bpdev_aawire_fix_activity_posting_hooks');

function bpdev_aawire_fix_activity_posting_hooks() {
 remove_action('wp_ajax_post_update', 'bp_dtheme_post_update');
}

//add our own handler for activity posting

add_action('wp_ajax_post_update', 'bpdev_aawire_post_update');

/* AJAX update posting */

function bpdev_aawire_post_update() {
 global $bp;

/* Check the nonce */
 check_admin_referer('post_update', '_wpnonce_post_update');

if (!is_user_logged_in()) {
 echo '-1';
 exit(0);
 }

if (empty($_POST['content'])) {
 echo '-1<div id="message"><p>' . __('Please enter some content to post.', 'buddypress') . '</p></div>';
 exit(0);
 }

if (empty($_POST['object']) && function_exists('bp_activity_post_update')) {

//this is what I have changed

if (!bp_is_home() && bp_is_member())
 $content = "@" . bp_get_displayed_user_username() . " " . $_POST['content'];
 else
 $content = $_POST['content'];

//let us get the last activity id, we will use it to reset user's last activity
 $last_update = bp_get_user_meta(bp_loggedin_user_id(), 'bp_latest_update', true);
 $activity_id = bp_activity_post_update(array('content' => $content));

//reset the last update

bp_update_user_meta(bp_loggedin_user_id(), 'bp_latest_update', $last_update);

//end of my changes
 } elseif ($_POST['object'] == 'groups') {
 if (!empty($_POST['item_id']) && function_exists('groups_post_update'))
 $activity_id = groups_post_update(array('content' => $_POST['content'], 'group_id' => $_POST['item_id']));
 } else
 $activity_id = apply_filters('bp_activity_custom_update', $_POST['object'], $_POST['item_id'], $_POST['content']);

if (!$activity_id) {
 echo '-1<div id="message"><p>' . __('There was a problem posting your update, please try again.', 'buddypress') . '</p></div>';
 exit(0);
 }

if (bp_has_activities('include=' . $activity_id)) :
?>
 <?php while (bp_activities()) : bp_the_activity(); ?>
 <?php locate_template(array('activity/entry.php'), true) ?>
 <?php endwhile; ?>
 <?php

endif;
 exit(0);
}

That’s it.

hope it helps you to implement the wire feature on your BuddyPress 1.6/1.7 network.

Please do let me know your feedback/enhancement or anything I missed :)

PS: Will be releasing the BuddyBlog plugin tomorrow and there is a huge surprise coming this weekend :)

Get latest WordPress & BuddyPress tutorials, news and tricks in your inbox.

We send out a lovely email newsletter with the most popular stories. Be a part of it.

41 Responses to BuddyPress Activity as Wire Updated for BuddyPress 1.6 & BuddyPress 1.7

  • Im still getting double posts using trunk 1.7

  • My bad. Ajax issue on my part

  • >> Will be releasing the BuddyBlog plugin tomorrow and there is a huge surprise coming this weekend

    I like surprises and will be waiting for BuddyBlog :-)

    • Hi Mercime,
      Thank you for the comment :)

      I am almost done writing the post for BuddyBlog, will be releasing it any time today :) and yes, some surprise is coming soon after that :)

  • Great tutorial! Just some comments that caused me some trouble:

    * bp_get_template_part() is used in latest 1.7 trunk so use that instead of replacing with locate_template()
    * bp_is_user() should nowadays be used instead of bp_is_member()

  • I want to thank you so much for making this possible. Though I would love to ask a favor of you if it is possible to have a drop down to choose to post as anonymous whether as a post or a comment anywhere on the site?

  • Howdy! This is exactly what I’m trying to do. I have renamed “Group” to “Team” for my application, and can’t get this working.

    The item writes to the database no problem, but doesn’t show up when I hit refresh!

    • I am by the way, on BuddyPress 1.6.5

      • NEVERMIND – You have to click “Mentions” rather than be on “Personal”…. THANKS this is a great start.

  • Hi.

    I have followed your steps and successfully implemented it.

    Is there a way to change the format of the date on comments? I currently have them showing as “admin posted an update 8 hours, 16 minutes ago”. I am wanting to change it so i display as a date and time.

    Any help would be great as this is for a uni project.

    Thanks

  • hello brajesh
    i also want to do same but am sorry where to do..in buddypress theme or plugin where to make changes

  • Hi,

    I have made the changes required and after the user posts the wall will not be automatically updated, this due I don’t know why, when I remove your code the updating without refresh works, but when I put your code back it will not work, my current BPress version is 1.7.2 could this be an issue? Please give me some advice on how can I get this to work or localize the error, thanks :)

  • I am so close. I have made the changes according to your tutorial. I can post on a user’s wall, it shows up in the public activity BUT it doesnt show on the user’s wall (it does show up on mine) and if I use the most updated tutorial it only shows as, “User posted a new activity” without showing what I posted. I appreciate your time.

  • Same here! The post won’t appear on the users wall!

    Nice work though! Thx for that! :)

    Solution appreciated..

  • Sorry, my fault! For some reason the code for the functions.php disappeared!
    Everything works fine now!

    Thank you very much for this, Brajesh!
    :)

    • Hi Ronson,
      Thank you. I was wondering because I could not reproduce the problem.
      Appreciate you taking time to reply :)

  • Hi Brajesh!
    One more question.. :)

    Everything still works, even after merging mentions with the userstream.

    Issue: When using the Activity-plus-plugin, the media won’t go to the userstream,
    only to the main-activity-stream, as a simple update, without mentioning the user.

    Is that something that could be solved with this hack? Or must this be done within the plugin-files?

    Thx a lot for your support!

  • Hi I’ve made the changes as per your instructions but the post box does not show on other users wall. I am right in thinking the file is located in:

    buddypress> bp-templates> bp-legacy> buddypress> members> single> activity.php

    wordpress 3.5.1 with Buddypress 1.7.2

    Any advice would be great.

    • HI Neil,
      Sorry for the delayed reply.

      The file should be in your current active theme/members/single/activity.php. Is that file present in your theme?

  • actually, it is in bp-themes > bp-default!

  • Is there a way to do this without using the @mention ?

  • Brajesh,

    This is awesome stuff, thank you.

    Do you know if your code is compatible with BP Media?

    It has not been working for me. Thought I did make a couple of slight modifications.

    1) I created child files.
    2) On post-form.php I did the following instead:

    // if (  function_exists(‘bp_has_groups’) &&!bp_is_member() &&!bp_is_group() ) :
    if ( bp_is_active( ‘groups’ ) &&!bp_is_member() &&!bp_is_group() ) :?>

    -Tom

  • hello SBrajesh i was a premium member here in buddydev and i am highly impressed of what you have done in buddydev, i just needed you to develop a Wall plugin that is similar to meg@info’s buddypress Facebook ‘Wall’ except for the ‘Like’ feature. Plugin includes notify you
    A: when someone post on your wall
    B:you can’t post on some ones wall(stream) if not friend
    I believe it’s a great ‘IDEA’ if you could use meg@info’ plugin as a head start (reducing time developing) so please develop one much appreciated.

    • Hi David,
      Thank you for being a valuable member here. I highly appreciate your support. Please allow me to look into the plugin tomorrow and will get back to you with details.

      Thank you for sharing the Idea :)

  • Hi Brajesh,

    How would i get this to work with an activity loop filter (seen here http://codex.buddypress.org/developer/loops-reference/the-activity-stream-loop/)

    What i want is for the activity stream to display updates made by the user (eg the “What’s new Brasjesh” update box) or by people visiting their profile and leaving an update using your wire box (eg the ‘Write something to Brajesh’ post box)

    Basically i don’t want photos, group or any other updates appearing in users stream.

  • Also when a user posts an update onto someones wall using the ‘write something to’ option the post only appears in the own users stream back on their profile page – nowhere on the stream they actually just posted on.

    Brajesh i want to make every users stream basically a comment and reply only wall. No activities about photos uploaded, group activities, friendships etc. My site is a dating site – it needs to be less about the social and sharing side of things or more about the direct contacting other members approach.

    People shouldn’t see in another users streams what comment they’ve made on another users photos or profile… that’s not the privacy a dating site needs. I understand there is a plugin that can restrict the privacy level of every activity a member makes but on a dating site members shouldn’t have to manually privatize their activity each time.

    I’m just about ready to disable the whole user activity stream except that it renders your ‘poke’ plugin useless causing an error in line 20 and that plguin is an important one for my site.

    If there is a way to just turn the stream into a comment wall then please help, happy to arrange a custom project for you to work on my site on a per hour or quoted basis. Thanks

  • Hi Brajesh,

    I use this plugin for groups in a different way. Is this plugin supported for BP 1.9.1.

    • Hi Gwu,
      As far as I have tested It works for BuddyPress 1.9. I am not sure how you use it for group? Can you check and let me know. If you find any issue, please do let me know. I will do my best to resolve quickly :)

  • Hi Brajesh,
    thank you for your awesome instruction , my setup is WP 3.8 + BP 1.91.
    i’m using your tutorial to implant wall-system in my web site ,but there is a problem that if i use your code my updates on both my profile(status) and other people’s profile(post) doesn’t show instantly like default BP (ajax-problem it think), i need to refresh the page to see my typed post .
    i edit some of your code and i ended up with twice posting and then i get really confused !.
    maybe there is incompatibility with BP 1.9.1 !?

    is there anyway that you could help me with that ?!
    thank you very much

  • Hello,

    I have a question, I had the form on the page, it did work really well, but I have edited a code to de bp-custom.php that says that my mentions page is the starting page for all members to begin with. That code is also working great. But together they do not work.

    My other code is:


    function bp_change_activity_subnav_default() {

    if ( bp_is_user_activity() ) {

    $args = array(
    ‘parent_slug’ => ‘activity’,
    ‘subnav_slug’ => ‘mentions’
    );

    bp_core_new_nav_default($args);

    }

    }
    add_action(‘bp_setup_nav’, ‘bp_change_activity_subnav_default’, 5);


    Can somebody help me get the two codes working together?

    Thank you.

  • hi brajesh, i have been using a few of your free plugins and thing they are amazing! now david assang makes a very valid point brajesh, why dont you take a look at meg@infos buddypress wall plugin and make a better one? although this is infact a good plugin it has alot of flaws, when posting on users wall it the post dissapears from wall after a refresh, there is no notifications either , it has facebook style commenting which is flawless, but overall this plugin needs to be upgraded to do what it is lacking, meg@info doesnt respond in his support!, we all know you are capable of making a plugin to act like a real wall and it would ake sense for you to perfect the things that are broken in buddypress wall with a version of your own, i cannot understand why you havent allready taken this idea onboard and devoloped a plugin like this, it would be so damn good if it worked right :)

  • I have left a couple of messages and I haven’t had a reply, I have installed this plugin and am using Buddypress 1.9.2 and it doesn’t seem to work.

    Can you let me know if this plugin is compatible with this version of Buddypress and if not, is there plans to make it compatible. If it is compatible then I will know that there is a problem with my installation.

    Thanks,

    Allan

    • Hi Allan
      My apologies. For past few months, I was not able to focus on Blog and could not reply to many comment.s My apologies for that.
      This code is not tested at the moment and I do have plans to update it by weekend for BuddyPress 1.9.2 and test for BuddyPress 2.0.

      In future, I will be supporting all our plugins again. Sorry for the inconvenience.

  • Thanks Brajesh,

    I really appreciate your quick response and all your hard work!
    I am just about to launch my site and I know that this feature would be invaluable, I have also installed global unified search, will that also be updated?

    Thanks once again.

    Allan

    • HI Allan,
      Thank you.
      I have just posted the new update to activity as wire. I am updating all other codes. It may take me a week or two but everything is being updated here. Global Unified Search is my next target( hoping to put an update by Tuesday).

      • Hi Brajesh,

        Thank you so much and being true to your word and having the update ready for the weekend.

        I installed it as a plug in and it works perfectly. I really appreciate this.

        Allan

  • Pingback: BuddyPress Activity As wire updated for BuddyPress 1.8, BuddyPress 1.9+ | Buddy Dev

  • Hi All,
    here is an update for BuddyPress 1.8+( I have tested with BuddyPress 1.9.2)
    http://buddydev.com/buddypress/buddypress-activity-wire-updated-buddypress-1-8-buddypress-1-9/
    Please do let me know your thoughts and suggestion there.

    Thank you
    Brajesh