Skip to:
Content

BuddyPress.org

Ticket #4639: 4639-ray.02.patch​

File 4639-ray.02.patch​, 1.6 KB (added by DJPaul, 8 years ago)
Line 
1Index: bp-members/bp-members-screens.php
2===================================================================
3--- bp-members/bp-members-screens.php   (revision 6480)
4+++ bp-members/bp-members-screens.php   (working copy)
5@@ -279,6 +279,7 @@
6         */
7        public function __construct() {
8                add_action( 'bp_setup_theme_compat', array( $this, 'is_members' ) );
9+               add_filter( 'bp_get_root_template',  array( $this, 'template_hierarchy' ), 10, 2 );
10        }
11 
12        /**
13@@ -314,6 +315,35 @@
14                }
15        }
16 
17+       /**
18+        * Add custom template hierarchy for member pages.
19+        *
20+        * This is to mirror how WordPress has {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
21+        *
22+        * @since BuddyPress (1.7)
23+        *
24+        * @param string $template The template theme compat should look for before falling back to the default.
25+        * @param string $page_template The page template used to inject BP content into.
26+        * @return array|bool $templates Array of custom templates to look for. Boolean false if not a member page.
27+        * @uses bp_get_query_template() Retrieve paths to a template.
28+        */
29+       function template_hierarchy( $template, $page_template ) {
30+               // If we're not viewing a user, bail out
31+               if ( ! bp_is_user() )
32+                       return $template;
33+
34+               $user_id    = bp_displayed_user_id();
35+               $user_login = sanitize_file_name( buddypress()->displayed_user->userdata->user_login );
36+
37+               // User login trumps the user ID
38+               $templates = array(
39+                       'members/single/home-' . $user_login . '.php',
40+                       'members/single/home-' . $user_id    . '.php',
41+               );
42+
43+               return bp_get_query_template( 'members', $templates );
44+       }
45+
46        /** Directory *************************************************************/
47 
48        /**