Do you miss the wire of buddypress 1.x era. Yes, you can use the activity as wire. You might have seen it on buddypress.org profile.

Here is a screenshot from my dev btw

activity-as-wire-300x182

Thanks to Andrew for asking this question and here is the way to use activity as wire.

How to do it:

You will need to edit at 3 places.

  • We will edit members/single/activity.php
  • activity/post-form.php and
  • functions.php

Step 1: Showing the form on other user’s profile

Let us start with members/single/activity.php

Since we want the post forum to appear on all the users profile, we will change a line in the members/single/activity.php

on line 39-41 in bp-default theme(or find the relevant line in your theme)’s activity file you will see something like this

1
2
3
<?php if ( is_user_logged_in() &&bp_is_my_profile()&&( '' == bp_current_action() || 'just-me' == bp_current_action() ) ) : ?>
<?php locate_template( array( 'activity/post-form.php'), true ) ?>
<?php endif; ?>

Now we need the form on other users profile, so change it to

1
2
3
<?php if ( is_user_logged_in()&&( '' == bp_current_action() || 'just-me' == bp_current_action() ) ) : ?>
<?php locate_template( array( 'activity/post-form.php'), true ) ?>
<?php endif; ?>

So, we have taken out the condition bp_is_myprofile() and now the form will be displayed on other users profile too.

drop-down-on-othersprofile-300x150

But wait, did you notice that silly drop down below the form which will appear on other users profile as shown above.

No problem, let us tweak the form slightly.

Step2: Customizing the activity post form

Open bp-default(or your theme)/activity/post-form.php

on line no. 36 of the file(or please check the condition in your theme) you will see something like this

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

Let us change it to

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

We have simply changed the conditional from bp_is_myprofile() to bp_is_member(), so the dropdown will not show on any user’s page. It should look as shown below.

no-dd-on-otheruserprofile-300x152

If you have completed the above steps, you should pat on your back, ohh yes, you are 30% done :D

ok, ok, let us give the final touch.

Step 3: Handling the posting of message

What we need more is we need to handle the special case of using activity form to post on other users profile.

That’s easy. We will remove the ajax action which comes by default in bp-default theme and add our own to handle the update.

Add the following lines to your functions.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/** all the credit to @apeatling, the code below is a modified version of apeatling's code for function bp_dtheme_post_update in bp-default/_inc/ajax.php */
//let us remove the default handler for activity posting
remove_action( 'wp_ajax_post_update', 'bp_dtheme_post_update' );
//add our own handler for activity posting
add_action(  'wp_ajax_post_update', 'bp_mytheme_post_update' );
/* AJAX update posting */
function bp_mytheme_post_update() {
global $bp;
/* Check the nonce */
check_admin_referer( 'post_update', '_wpnonce_post_update' );
if ( !is_user_logged_in() ) {
echo '-1';
return false;
}
if ( empty( $_POST['content'] ) ) {
echo '-1<div id="message"><p>' . __( 'Please enter some content to post.', 'buddypress' ) . '</p></div>';
return false;
}
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'];
$activity_id = bp_activity_post_update( array( 'content' => $content ) );
//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>';
return false;
}
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;
}

Now go, check others profile and write some message, check their @mention tab and feel good about the wire.

If you take a look closely, there is a catch still there, when you are on other users profile it still asks you what’s new mr. awesome ?, well awesome should be your first name, we need to change it to displayed user’s name, should not we.

incorrect-text-on-form-page-300x150

So, we need to modify the activity/post-form.php again.

This time, we will modify the following lines(for bp-default, it starts on line no. 17)

1
2
3
4
5
6
7
<h5>
<?php if ( bp_is_group() ) : ?>
<?php printf( __( "What's new in %s, %s?", 'buddypress' ), bp_get_group_name(), bp_get_user_firstname() ) ?>
<?php else : ?>
<?php printf( __( "What's new %s?", 'buddypress' ), bp_get_user_firstname() ) ?>
<?php endif; ?>
</h5>

Change it to

1
2
3
4
5
6
7
8
9
10
<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_home()&&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 here is the screen shot again

correct-text-on-ac-form-300x154

Now your freaking awesome activity as wire setup is ready. Enjoy and feel free to leave your comments/suggestions for further improvement of this already awesome technique :D

For those of you, who want my modified codes/pages of default theme, I have bundled them as a child theme of bp-default here. You may want to use this wired Child Theme or just move individual files to their respective folders in bp-default(or the child theme for better future updates). Try The wired Child and experiment for more :)

Download Link:-http://buddydev.com/http//buddydev.com/public-download/wired-child.zip