Pages

Saturday, December 29, 2012

Add Media Links in Activity Stream

Buddypress Media is a great plugin authored by rtCamp. They enable site users to upload media in albums. Media includes music, videos and photos.

However, the plugin lacks one important part - Adding media from the front end. Much like how another plugin Activity Plus does. Activity Plus lacks what BP Media provides - and that is - organizing into albums and having them stored for future use right on the members pages.

I thought of marrying both. i.e bringing BP media on the front-page where Activity Updates are posted.

//add media links

function add_media_links(){

    global $bp, $current_user;;

if (is_user_logged_in()) {

echo '<div style="float:right; font-weight:bold;">';

echo '<a href="'.$bp->root_domain . '/members/' . $current_user->user_login  .'/media/" style="color:black; padding-right:10px">Upload</a>';

echo '<a href="'.$bp->root_domain . '/members/' . $current_user->user_login  .'/albums/" style="color:black; padding-right:10px">My Albums</a>';

echo '<a href="'.$bp->root_domain . '/members/' . $current_user->user_login  .'/photos/" style="color:black; padding-right:10px">My Photos</a>';

echo '<a href="'.$bp->root_domain . '/members/' . $current_user->user_login  .'/videos/" style="color:black; padding-right:10px">My Videos</a>';

echo '<a href="'.$bp->root_domain . '/members/' . $current_user->user_login  .'/music/" style="color:black; padding-right:10px">My Music</a>';

echo '</div>';

}

else {

echo '<div style="float:right; font-weight:bold;">';

echo '<a href="'.$bp->root_domain . '/login/" style="color:black; padding-right:10px">Upload</a>';

echo '<a href="'.$bp->root_domain . '/login/" style="color:black; padding-right:10px">My Albums</a>';

echo '<a href="'.$bp->root_domain . '/login/" style="color:black; padding-right:10px">My Photos</a>';

echo '<a href="'.$bp->root_domain . '/login/" style="color:black; padding-right:10px">My Videos</a>';

echo '<a href="'.$bp->root_domain . '/login/" style="color:black; padding-right:10px">My Music</a>';

echo '</div>';}

return;

}

add_filter('bp_before_directory_activity_content',add_media_links');

?>
You may want to add this to your functions.php file.

This code, specially the last line of the code adds a filter such that whenever bp_before_directory_activity_content function is triggered, my own custom function add_media_links will trigger automatically where in, if the user is logged in, it provides direct links to the media upload as it takes $current_user->username to take them to their own page for media uploads. And if its just a visitor, these links will redirect to the login page.



You can see this in my site which is live in action at: DublinWala.Com

4 comments:

  1. Hi Daya,

    I'm from the team that develops BuddyPress Media. We've recently started recoding BuddyPress Media to rtMedia for WordPress, BuddyPress and bbPress. You might be interested in the fresh path rtMedia is taking and the flexibility it'll offer for you to tweak it further.

    See: http://rtcamp.com/news/getting-ready-for-rtmedia/

    This tutorial will not work with the updated plugin, so you will need to update this too.

    ReplyDelete
  2. Thanks Saurabh for stopping by and leaving a comment. Will closely follow the release of rtMedia plugin.

    ReplyDelete
  3. Hi Daya,

    Thanks for the tutorial, but which functions.php are you editing? the theme's?

    ReplyDelete
  4. Hi Akira,

    Yes. You can add the above code to your theme's functions.php file. However, please note that its a good practice to have a child theme of your theme and then create a new functions.php file and add the above code to that file. You can learn about child themes at WordPress.Org.

    If you want to go ahead without creating child themes, the above tutorial still holds good.

    Cheers.

    ReplyDelete