When implementing a custom component in BuddyPress, you will often have additions for the member theme. Member themes live in their own folder, /wp-content/bp-themes/.
To render a member theme template, your component will call dpa_load_template() which takes an argument of the name of the template to load. The path is hardcoded to the /wp-content/bp-themes/ folder.
The problem with this is that after installation of a custom component, the site administrator will need to move the relevant member theme files (bundled with your component) into /wp-content/bp-themes/. This is an annoyance to site administrator, and it may end up being a frequent support request (“why is X not working?”). This very first hurdle may even stop people trying out your component.
Something else I’ve seen is that when installing future updates, people may forget that they need to move the updated member theme files into place; this can cause incompatibility issues between versions of your software, something we’ve seen with recent versions of BuddyPress.
For my upcoming “Achievements” plugin (think a cross between forum points and Xbox Live), I decided all that I wanted the site administrator to do would be to download it from the Plugins admin panel – no moving files into the member theme.
So, I present to you my code: (06/01/10 – updated for BP 1.1.3+)
bp_core_load_template( 'yourcomponent_theme_filename' ); // loads /plugins/your_plugin/filename.php
function yourcomponent_screen_filter_template( $located_template, $template_name ) {
if ( !empty( $located_template ) )
return $located_template;
if ( $bp->current_component != $bp->your_component->slug )
return false;
if ( false !== strpos( $template_name[0], 'yourcomponent_theme_' ) ) {
$prefix = strlen( 'yourcomponent_theme_' );
$template_name = substr( $template_name[0], $prefix, strlen( $template_name[0] ) - $prefix );
$template_path = WP_PLUGIN_DIR . "/your_plugin/$template_name";
if ( file_exists( $template_path ) )
return $template_path;
}
return false;
}
add_filter( 'bp_located_template', 'yourcomponent_screen_filter_template', 10, 2 );
Sarah Gooding 11:15 pm on December 19, 2011 Permalink |
Hello Paul! Cool idea – I love it! Will the liking work for individual activity items or only blog posts? Is it backwards compatible or only working with the trunk? Thanks!
Paul Gibbs 11:37 pm on December 19, 2011 Permalink |
Right now, it’s proof-of-concept, so only blog posts. If I decide to put more time into this feature, the plan is to try to get it to work for any content on your website.
It should only be used with BP 1.6-trunk. This is because we’ve put in a lot of optimisations around memory use and caching in 1.6, and this takes advantage of that. Without those changes, this could slow down your server.
mrjarbenne 11:42 pm on December 19, 2011 Permalink |
This is an nice concept, and could potentially replace the functionality of the “favorite” button on the activity stream. Would it make sense to be able to view items that users have “liked” via their Profile?
Paul Gibbs 10:55 am on December 20, 2011 Permalink |
Yep, it would. It’s built with that in mind, though that isn’t done (yet — it’s surprisingly tricky).
donnacha WordSkill 12:18 am on December 20, 2011 Permalink |
Very handy, I like this.
The ability to Like individual comments and to display the number of Likes per comment would stimulate participation and reward good commenters.
Integration with Achievements would compound that effect.
The option to limit the ability to Like to logged in users or certain categories of user could be useful, although I think I would generally prefer to allow everyone to express their approval, whether logged in or not.
A matching Dislike option could lead to a lot of interesting uses, especially if Likes and Dislikes could be weighted differently.
If integrated with BuddyPress Moderation, a large number of dislikes and zero or very few Likes could trigger a flag.
Paul Gibbs 10:57 am on December 20, 2011 Permalink |
Great ideas. Thanks for sharing.
Ray 3:00 am on December 20, 2011 Permalink |
I might need this feature sooner than later, so I might spend some time helping to get this working with group forum posts… as soon as BP 1.6 drops that is!
Paul Gibbs 10:56 am on December 20, 2011 Permalink |
jackhowland 6:14 pm on January 8, 2012 Permalink |
Hi Paul,
I’m very interested in a Like/Add to Favorites feature and would love to be part of any testing. I’m creating a BP site for writers to share, edit, and react to one another’s work. Like a flickr or 500px.com but dedicated to more constructive, less fanny-patting (if you will) feedback. Anything I can do to help?
Thanks! Jack
Paul Gibbs 8:17 pm on February 10, 2012 Permalink |
During development of BuddyPress 1.7, I’ll be revisiting the Like in BP Labs.
Philipp 8:10 am on January 11, 2012 Permalink |
Amazing Paul! It just amazing!
Towfiq I. 8:12 am on February 4, 2012 Permalink |
Thanks for the plugin. Is it possible yo add the like button under each post? along with the avatars of the members who liked it?
Paul Gibbs 8:17 pm on February 10, 2012 Permalink |
Not right now. It was only a proof-of-concept. I’ll build on it in future.
towfiqi 8:19 pm on February 10, 2012 Permalink
Cool!! I found another plugin that you might want to look into:
http://wordpress.org/extend/plugins/gravatar-like/