[buddypress-trac] [BuddyPress] #3741: BuddyPress should have theme compatibility

buddypress-trac at lists.automattic.com buddypress-trac at lists.automattic.com
Wed Aug 29 15:39:02 UTC 2012


#3741: BuddyPress should have theme compatibility
-----------------------------+------------------------------
 Reporter:  johnjamesjacoby  |       Owner:  johnjamesjacoby
     Type:  enhancement      |      Status:  new
 Priority:  highest          |   Milestone:  1.7
Component:  Theme            |     Version:
 Severity:  critical         |  Resolution:
 Keywords:                   |
-----------------------------+------------------------------
Changes (by imath):

 * keywords:  2nd-opinion needs-testing =>
 * type:  task => enhancement


Comment:

 Hello,

 First : very interesting new way to manage theme compatibility : great
 work!

 I've played a bit with it and the twentyeleven theme. I've noticed that
 the activity entry when calling the permalink was leading to
 'members/username/home' BuddyPress template part instead of
 'members/username/activity/p/acitivity_id' one. So i've edited the file
 /buddypress/bp-activity/bp-activity-screens.php by adding after line 346
 to handle this case. It seems to work, but is surely improvable :

 {{{
         public function is_activity() {

                 //starting after line 346
                 if( bp_is_single_activity() ) {
                         add_action(
 'bp_template_include_reset_dummy_post_data', array( $this,
 'single_activity_dummy_post' ) );
                         add_filter( 'bp_replace_the_content',
 array( $this, 'single_activity_content'    ) );
                 }
         }
         // then i've added this 2 functions in the class :
         public function single_activity_dummy_post() {
                 bp_theme_compat_reset_post( array(
                         'ID'             => 0,
                         'post_title'     => __( '', 'buddypress' ),
                         'post_author'    => 0,
                         'post_date'      => 0,
                         'post_content'   => '',
                         'post_type'      => 'bp_activity',
                         'post_status'    => 'publish',
                         'is_single'     => true,
                         'comment_status' => 'closed'
                 ) );
         }
         public function single_activity_content() {
                 bp_buffer_template_part(
 'members/single/activity/permalink' );
         }
 }}}

 Then i kept on playing with it and in the wp editor i've changed the
 template file from default template to sidebar template in the Page
 Attributes box and it didn't changed the template. It was still page.php
 that was loaded. So i've edited some files to make it work and it
 worked... But i then try with a template that uses several
 get_template_part function like the showcase.php and i guess, i had a bad
 idea as the different content are all filled with BuddyPress content.

 Just in case this is what i've done :

 {{{
 //in bp-core/bp-template-loader.php
 // edited function bp_get_theme_compat_templates after line 302
         $wp_editor_template = bp_get_page_template();

         if( !empty( $wp_editor_template ) )
                 $templates = array_merge( array( $wp_editor_template ),
 $templates );

         return bp_get_query_template( 'buddypress', $templates );

 //in bp-core/bp-core-template.php added 2 functions to watch for a
 wp_editor template
 /**
 * do this BuddyPress page has a custom template ?
 */
 function bp_is_page_template( $template = '' ) {
         if ( bp_is_blog_page() )
                 return false;

         /* not sure of this one...*/
         $page_id = get_queried_object_id();

         /* just in case */
         if( empty( $page_id ) ){
                 $component_page_ids = bp_core_get_directory_page_ids();
                 $current_component = bp_current_component();
                 $page_id = $component_page_ids[ $current_component ];
         }

         $page_template = get_page_template_slug( $page_id );

         if ( empty( $template ) )
                 return (bool) $page_template;

         if ( $template == $page_template )
                 return true;

         if ( 'default' == $template && ! $page_template )
                 return true;

         return false;
 }

 /**
 * returns the template chosen from the wp editor
 */
 function bp_get_page_template( $current_component = '' ) {
         $component_page_ids = bp_core_get_directory_page_ids();

         if( empty( $current_component ) )
                 $current_component = bp_current_component();

         $page_id = $component_page_ids[ $current_component ];

         if( !empty( $page_id) )
                 return apply_filters( 'bp_get_page_template',
 get_page_template_slug( $page_id ) );

         else
                 return false;
 }

 //and added a specific condition to add body class in
 bp_get_the_body_class function
                         if( bp_is_page_template() ) {
                                 $bp_classes[] = 'page-template';
                                 $bp_classes[] = 'page-template-' .
 sanitize_html_class( str_replace( '.', '-', bp_get_page_template() ) );
                         }

 // and finally edited the bp-core/bp-core-theme-compatability.php file
 //after line 368
 $defaults['is_singular'] = bp_is_page_template() ? false : is_singular();

 // then after $wp_query->is_single  = $dummy['is_single'];
         $wp_query->is_singular  = $dummy['is_singular'];

 }}}

 Tanks again for the great work.

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


More information about the buddypress-trac mailing list