Welcome to BuddyDress

Our themes show off your site’s content - and do it well. We look for inspiration all around us - introducing personality for a dramatic effect that will bring your content to life.

Founded on the idea that your site should be exceptional in style and quality, we draw on classic design techniques to present a beautiful and unique collection of themes at an excellent value.

remember me

Extending BuddyPress, for existing WordPress developers by Paul Gibbs

It’s over to Paul Gibbs for today’s 12 days of WordPress and BuddyPress.  Lets meet Paul first in his own words from his profile at BuddyPress.org:

” I’m a Core Developer on BuddyPress. I enjoy speaking at WordCamps, crafting code, and helping people.

I provide consultancy on projects and design custom plugins for your site;

contact me at paul@byotos.com, in #buddypress-dev on freenode, or on twitter as @pgibbs.”

A powerful tool in a WordPress developer’s arsenal is the ease and flexibility of creating a widget. Introduced in WordPress 2.8, the WP_Widget widget class abstracted most of the complexity involved in writing a widget, giving developers a framework to build on and prevent time being needlessly spent on, for example, building custom option panels. Widgets remain a great way for a PHP developer to become familiar with the WordPress platform and API features such as actions and filters.
BuddyPress’ Groups component has a similar extension architecture to widgets and we’re going to look at how existing WordPress developers, who haven’t written for BuddyPress before, can get started.

Introduction to BuddyPress components

BuddyPress is a single plugin, but internally it is subdivided into distinct parts, almost into separate plugins, which BuddyPress calls components. The core components are Activity Streams, Blog Tracking (for multisite), Forums, Friends, Groups, Private Messaging and eXtended Profile (xprofile). A plugin developer working on BuddyPress would either extend one of the core components or create a new component. An example of extending the Private Messaging component would be to add support for file attachments to messages, and a new component would be best for brand new functionality, such as a photo album.

At the moment, the Groups component has the best API for developers, so we’re going to be looking at John James Jacoby‘s BP Edit Group Slug plugin as an example. Download it and look at its source code whilst reading this article. The BP Edit Group Slug plugin allows you to change the group’s slug, which is part of the group’s permalink. You might want to use this if you decide to rename the group after creating it and want to update the permalink too.

Hooking into BuddyPress safely

Like with widgets, a group extension requires you to extends BuddyPress’ BP_Group_Extension class. To tell BuddyPress to load your group extension, use bp_register_group_extension(). However, be aware that John’s plugin is slightly out of date about how third-party plugins should hook into BuddyPress; the correct way is documented on the BuddyPress codex. We advise creating a loader.php file and putting in the following:

// Only load code that needs BuddyPress to run once BP is loaded and initialised.

{code type=PHP}
function my_plugin_init() {
require( dirname( __FILE__ ) . ‘/my-plugin.php’ );
add_action( ‘bp_include’, ‘my_plugin_init’ );{/code}

All of your code which is dependant on BuddyPress can then be put into the my-plugin.php file. This will make sure your plugin won’t break someone’s website if they were to deactivate BuddyPress before deactivating your plugin.

About BP_Group_Extension

In your class, there are six functions which you can choose to implement.

  • BP_Group_Extension::create_screen() — implement the HTML for the create screen, as seen when users create a new group.
  • BP_Group_Extension::create_screen_save() — handle saving of options from the create screen.
  • BP_Group_Extension::edit_screen() — implement the HTML for the edit screen, as seen when the group admin(s) edit their group.
  • BP_Group_Extension::edit_screen_save() — handle updating of options from the edit screen.
  • BP_Group_Extension::display() — implement the HTML to display output from your group extension in the group.
  • BP_Group_Extension::widget_display() — invoked when the user is on the front page of a group (by default, the activity stream page).

You are not required to implement all of these functions in your class. For example, as John’s plugin is only used for the group admin(s) to change the permalink, there is no need to display anything to regular visitors. In addition to these methods, there are a few helpful class properties:

  • $enable_create_step, $enable_nav_item, $enable_edit_item — booleans. Set these if you want to display your extension on the create/edit screens, or add a nav item. Optional (all default to true).
  • $create_step_position, $nav_item_position — integers. Use to change the order of where your extension displays on the create scree and the navigation bar. Optional (defaults to 81).
  • $name, $slug — strings. The title of your grope extension, and the slug for its permalink. Both required.
  • $nav_item_name — string. Set to use this instead of $name in the navigation bar. Optional.
  • $visibility — string. Controls whether this extension will be visible to non-members of a group? Options: “public” or “private” (defaults to “public”).
  • $display_hook — string. ADVANCED. Defaults to ‘groups_custom_group_boxes’.
  • $template_file — string. ADVANCED. Defaults to ‘groups/single/plugins’.

$display_hook and $template_file are two advanced options which will give you more control over which template is used when you display() your group. You don’t need to worry about these as the defaults will be appropriate most of the time.

Where to get help

Using John’s plugin as an example, I suggest that you spend an afternoon over this Christmas period learning to implement your own group extension and seeing what you can come up with. If you need any help, please leave a message on the BuddyPress Community site where I’ll be happy to help you learn how to develop with BuddyPress. Merry Christmas!

9 Responses to “Extending BuddyPress, for existing WordPress developers by Paul Gibbs”

  1. I have been utilizing your Code plugin efficiently since January, and want to congratulate you on your excellent work.

  2. In WordPress we can pick ideal wordpress design and can customize it according to our need.

  3. Julian, unfortunately, currently, the plugin develops the service
    for languages that are diverse internally within the signal.

  4. So you can employ Zen-Cart creator from major Webdevelopment
    Firm, nevertheless, you are strange with PHP.

  5. I’m not sure where you are getting your info, but good topic.

    I needs to spend some time learning more or understanding
    more. Thanks for wonderful info I was looking for this info for
    my mission.

    my site … No Good Deed: A Story of Medicine, Murder Accusations, and the Debate over How We Die pdf

  6. Vortex or Globe is very suitable for the library or study.
    A popular bedroom theme for little boys probably is the space
    theme. Ivory, jade and stained glass were common materials for accessories,
    which were usually tall and thin and graceful, with gentle

  7. Calvin says:

    When some one searches for his necessary thing, therefore
    he/she wants to be available that in detail, thus that thing
    is maintained over here.

    Here is my homepage – Calvin

  8. [...] Extending BuddyPress, for existing WordPress developers by Paul Gibbs [...]

  9. [...] 12 days of WordPress and BuddyPress post is brought to us by Paul Gibbs. “Extending BuddyPress for existing WordPress developers” keeps the ball going with this [...]

Leave a Reply