Ticket #6065: 6065.03.patch
File 6065.03.patch, 5.0 KB (added by , 10 years ago) |
---|
-
src/bp-core/bp-core-filters.php
diff --git src/bp-core/bp-core-filters.php src/bp-core/bp-core-filters.php index fc8ea85..8ba40e1 100644
add_filter( 'bp_template_include', 'bp_template_include_theme_compat', 4, 2 65 65 // Filter BuddyPress template locations 66 66 add_filter( 'bp_get_template_stack', 'bp_add_template_stack_locations' ); 67 67 68 // Filter BuddyPress template hierarchy and look for page templates69 add_filter( 'bp_get_buddypress_template', 'bp_theme_compat_page_templates' );70 71 68 // Turn comments off for BuddyPress pages 72 69 add_filter( 'comments_open', 'bp_comments_open', 10, 2 ); 73 70 -
src/bp-core/bp-core-template-loader.php
diff --git src/bp-core/bp-core-template-loader.php src/bp-core/bp-core-template-loader.php index 229bf6e..1567965 100644
function bp_get_theme_compat_templates() { 462 462 'index.php' 463 463 ) ); 464 464 } 465 466 /**467 * Filter the default theme compatibility root template hierarchy, and prepend468 * a page template to the front if it's set.469 *470 * @see https://buddypress.trac.wordpress.org/ticket/6065471 *472 * @since BuddyPress (2.2.0)473 *474 * @param array $templates475 * @return array476 */477 function bp_theme_compat_page_templates( $templates = array() ) {478 479 // Bail if not looking at a directory480 if ( ! bp_is_directory() ) {481 return $templates;482 }483 484 // No page ID yet485 $page_id = 0;486 487 // Get the WordPress Page ID for the current view.488 foreach ( (array) buddypress()->pages as $component => $bp_page ) {489 490 // Handles the majority of components.491 if ( bp_is_current_component( $component ) ) {492 $page_id = (int) $bp_page->id;493 }494 495 // Stop if not on a user page.496 if ( ! bp_is_user() && ! empty( $page_id ) ) {497 break;498 }499 500 // The Members component requires an explicit check due to overlapping components.501 if ( bp_is_user() && ( 'members' === $component ) ) {502 $page_id = (int) $bp_page->id;503 break;504 }505 }506 507 // Bail if no directory page set508 if ( 0 === $page_id ) {509 return $templates;510 }511 512 // Check for page template513 $page_template = get_page_template_slug( $page_id );514 515 // Add it to the beginning of the templates array so it takes precedence516 // over the default hierarchy.517 if ( ! empty( $page_template ) ) {518 array_unshift( $templates, $page_template );519 }520 521 return $templates;522 } -
src/bp-templates/bp-legacy/buddypress-functions.php
diff --git src/bp-templates/bp-legacy/buddypress-functions.php src/bp-templates/bp-legacy/buddypress-functions.php index 431a56d..14b23c1 100644
class BP_Legacy extends BP_Theme_Compat { 80 80 // Template Output 81 81 add_filter( 'bp_get_activity_action_pre_meta', array( $this, 'secondary_avatars' ), 10, 2 ); 82 82 83 // Filter BuddyPress template hierarchy and look for page templates 84 add_filter( 'bp_get_buddypress_template', array( $this, 'theme_compat_page_templates' ), 10, 1 ); 85 83 86 /** Scripts ***********************************************************/ 84 87 85 88 add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); // Enqueue theme CSS … … class BP_Legacy extends BP_Theme_Compat { 440 443 441 444 return $action; 442 445 } 446 447 /** 448 * Filter the default theme compatibility root template hierarchy, and prepend 449 * a page template to the front if it's set. 450 * 451 * @see https://buddypress.trac.wordpress.org/ticket/6065 452 * 453 * @since BuddyPress (2.2.0) 454 * 455 * @param array $templates 456 * @uses apply_filters() call 'bp_legacy_theme_compat_page_templates_directory_only' and return false to it 457 * to use the defined page template for component's directory and its single items 458 * @return array 459 */ 460 public function theme_compat_page_templates( $templates = array() ) { 461 // Bail if not looking at a directory 462 if ( true === (bool) apply_filters( 'bp_legacy_theme_compat_page_templates_directory_only', ! bp_is_directory() ) ) { 463 return $templates; 464 } 465 466 // No page ID yet 467 $page_id = 0; 468 469 // Get the WordPress Page ID for the current view. 470 foreach ( (array) buddypress()->pages as $component => $bp_page ) { 471 472 // Handles the majority of components. 473 if ( bp_is_current_component( $component ) ) { 474 $page_id = (int) $bp_page->id; 475 } 476 477 // Stop if not on a user page. 478 if ( ! bp_is_user() && ! empty( $page_id ) ) { 479 break; 480 } 481 482 // The Members component requires an explicit check due to overlapping components. 483 if ( bp_is_user() && ( 'members' === $component ) ) { 484 $page_id = (int) $bp_page->id; 485 break; 486 } 487 } 488 489 // Bail if no directory page set 490 if ( 0 === $page_id ) { 491 return $templates; 492 } 493 494 // Check for page template 495 $page_template = get_page_template_slug( $page_id ); 496 497 // Add it to the beginning of the templates array so it takes precedence 498 // over the default hierarchy. 499 if ( ! empty( $page_template ) ) { 500 array_unshift( $templates, $page_template ); 501 } 502 503 return $templates; 504 } 443 505 } 444 506 new BP_Legacy(); 445 507 endif;