Skip to:
Content
Pages
Categories
Search
Top
Bottom

Using activity as wire in Buddypress, following up


  • nawakiri
    Participant

    @nawakiri

    I have been trying to find out ways to implement a Facebook-like “write on wall” or “post to profile” functionality, and it seems that I am not alone. After some research, I was lead to this very helpful article written by Brajesh Singh in 2010:

    Using activity as wire in Buddypress 1.2 themes

    This is a brief report how I adapted the mod to WordPress 3.4.2 + Buddypress 1.6.1 + Buddpress Template Pack 1.2.1. So far everything seems to work. In case of any confusion, this mod does not exactly implement Facebook write-to-wall. The trick here is to enable the status update form on profiles and, when it is used in the profile of user X, append a short piece of text @mentioning user X. The status will thus show up later in X’s “Mention” tab. It will look more like write-to-wall if I manage to combine the “Personal” and “Mention” streams into one, another mod many people seem to want to have.

    I am using not the bp-default theme but Twenty-Eleven + Buddpress Template Pack 1.2.1. All the mods suggested by Brajesh Singh basically still work, modulo different locations and some code updates. Please refer to Brajesh’s original article. The following describes the difference.

    For Step 1, find lines 65-66 in members/single/activity.php

    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 );

    Change line 65 to

    if ( is_user_logged_in() && ( !bp_current_action() || bp_is_current_action( 'just-me' ) ) )

    For Step 2, find line 38 of activity/post-form.php

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

    Change to

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

    For Step 3, in functions.php of your theme (create this file if it does not exist)

    <?php

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

    add_action("init","bpdev_remove_post_update");

    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' . __( 'Please enter some content to post.', 'buddypress' ) . '';
    return false;
    }

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

    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 ) );

    } 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' . __( 'There was a problem posting your update, please try again.', 'buddypress' ) . '';
    return false;
    }

    if ( bp_has_activities ( 'include=' . $activity_id ) ) {
    while ( bp_activities() ) {
    bp_the_activity();
    locate_template( array( 'activity/entry.php' ), true );
    }
    }
    }

    ?>

    The code above is mostly the same as that of Brajesh Singh, apart from the beginning. Brajesh’s code starts with:

    remove_action( 'wp_ajax_post_update', 'bp_dtheme_post_update' );
    add_action( 'wp_ajax_post_update', 'bp_mytheme_post_update' );

    It didn’t work for me — my status updates got duplicated. I then found somewhere else that it didn’t work for themes other than bp-default. If you use bp-default, you might need Brajesh’s version.

    Hope the above helps.

Viewing 5 replies - 1 through 5 (of 5 total)

  • Roger Coathup
    Participant

    @rogercoathup

    ‘send public message’ built in to 1.6+ provides this functionality — posting to another user’s wall


    nawakiri
    Participant

    @nawakiri

    Oops… now I feel stupid. How come I didn’t notice that? 🙂


    Roger Coathup
    Participant

    @rogercoathup

    It’s really badly named — very confusing.  You’re not the first person to not know that ‘send public message’ means post update on user wall.

    On the bright side, by adapting Brajesh’s plugin for 1.6, you’ll have learnt a lot more about coding for BuddyPress

     

     


    Jigesh
    Participant

    @jigesh

    yes this is surely works, thank you for your valuable update , but i guess this can be improved by linking all activity filter in one , something like facebook ,

    Great!


    NSxguy24
    Participant

    @nsxguy24

    Where do i find this? i’ve been looking!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Using activity as wire in Buddypress, following up’ is closed to new replies.
Skip to toolbar