Skip to:
Content

BuddyPress.org

Opened 16 years ago

Closed 16 years ago

#55 closed enhancement (fixed)

Unable to use many modules outside of BuddyPress theme

Reported by: sollaires's profile sollaires Owned by: apeatling's profile apeatling
Milestone: Priority: minor
Severity: Version:
Component: Keywords:
Cc:

Description

I'm seeing this right now for the friends module but it may be the case for other modules as well.

Many of the current template tags depend upon global variables that are only set by functions that rely on the slug existing in the URL. Currently, if you attempt to make your own template and start using the friend template tags on your own main/index pages, errors will crop up because this object is not defined.

It seems somewhat logical to allow developers to use these template tags outside the scope of the buddypress theme and without the restrictions based on the URL slugs. One solution I've implemented is to replace all occurances of

global $friends_template;

with

$friends_template = get_friends_template();

This function is simply defined as

function get_friends_template() {

static $friends_template = null;

if( null == $friends_template )
{

global $bp, $friends_template; template added to ensure compatibility

$friends_template = new BP_Friendship_Template( $bp[ 'current_userid' ] );

}

return $friends_template;

}

Additionally, the assignment of $friends_template in the friends_template() function is changed to:

$friends_template = get_friends_template();

This allows a developer to use the friends template tags anywhere they desire without needing to know how to create the friends template or worrying about loading it when they are not using the friends functionality (the static variable will never be loaded if it is never used).

Let me/us know if you have other plans on exposing this functionality to theme authors aside from a method like this.

Change History (3)

#1 @sollaires
16 years ago

Ack, remove the $friends_template global descoping in the get_friends_template() function. Those names will conflict since I'm using the same one as the static variable.

#2 @apeatling
16 years ago

  • Owner set to apeatling
  • Status changed from new to assigned

Great stuff. This is something that will be addressed shortly (see mailing list).

#3 @apeatling
16 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

This has been changed in rev 309.

Note: See TracTickets for help on using tickets.