[buddypress-trac] [BuddyPress] #4328: Using a WP custom page template for a BP component's page

buddypress-trac at lists.automattic.com buddypress-trac at lists.automattic.com
Fri Jul 6 00:00:25 UTC 2012


#4328: Using a WP custom page template for a BP component's page
--------------------------------------------+------------------------------
 Reporter:  modemlooper                     |       Owner:
     Type:  enhancement                     |      Status:  new
 Priority:  normal                          |   Milestone:  Awaiting Review
Component:  Core                            |     Version:  1.5
 Severity:  major                           |  Resolution:
 Keywords:  reporter-feedback dev-feedback  |
--------------------------------------------+------------------------------
Changes (by r-a-y):

 * keywords:  reporter-feedback => reporter-feedback dev-feedback


Comment:

 I spent a little bit of time to implement this and it works!

 Here's the code snippet:

 {{{
 /**
  * On the WP page dashboard, if you set a custom page template for a BP
  * component page, let BP know of it and use it!
  */
 function ray_use_custom_page_template_for_bp_component_index( $template )
 {
         // see if a custom page template exists for the BP component page
         $custom_template = get_page_template_slug();

         // if no custom template, return the default one
         if ( empty( $custom_template ) )
                 return $template;

         // return our custom page template; we strip the extension because
 bp_core_load_template() requires it
         return ( str_replace( '.php', '', $custom_template ) );
 }
 add_filter( 'bp_activity_screen_index',
 'ray_use_custom_page_template_for_bp_component_index' );
 add_filter( 'bp_blogs_screen_index',
 'ray_use_custom_page_template_for_bp_component_index' );
 add_filter( 'bp_members_screen_index',
 'ray_use_custom_page_template_for_bp_component_index' );
 add_filter( 'bp_forums_template_directory_forums_setup',
 'ray_use_custom_page_template_for_bp_component_index' );
 add_filter( 'groups_template_directory_groups',
 'ray_use_custom_page_template_for_bp_component_index' );
 }}}

 '''Core devs:''' Not sure where to put this in core.  I was thinking of
 adding the function to `bp-core-functions.php`.  Then, adding the
 applicable filter to each component's `bp-COMPONENT-filters.php`.  Let me
 know what you think.

 `get_page_template_slug()` does use a few DB queries though -
 `get_post()`, `get_post_meta()` - just something to think about.

 The code snippet could be released as a tiny plugin as well.

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/4328#comment:5>
BuddyPress <http://buddypress.org/>
BuddyPress


More information about the buddypress-trac mailing list