Ticket #6769: 6769.02.patch
File 6769.02.patch, 11.2 KB (added by , 8 years ago) |
---|
-
src/bp-core/bp-core-template.php
diff --git src/bp-core/bp-core-template.php src/bp-core/bp-core-template.php index abfb275..4dd2dd4 100644
function bp_is_user() { 2271 2271 } 2272 2272 2273 2273 /** 2274 * Is the current page a user custom front page? 2275 * 2276 * Will return true anytime there is a custom front page for the displayed user. 2277 * 2278 * @since 2.6.0 2279 * 2280 * @return bool True if the current page is a user custom front page. 2281 */ 2282 function bp_is_user_front() { 2283 return (bool) ( bp_is_user() && bp_is_current_component( 'front' ) ); 2284 } 2285 2286 /** 2274 2287 * Is the current page a user's activity stream page? 2275 2288 * 2276 2289 * Eg http://example.com/members/joe/activity/ (or any subpages thereof). -
src/bp-members/bp-members-functions.php
diff --git src/bp-members/bp-members-functions.php src/bp-members/bp-members-functions.php index 5f6fe13..1f5ffdb 100644
function bp_live_spammer_login_error() { 2480 2480 } 2481 2481 add_action( 'login_form_bp-spam', 'bp_live_spammer_login_error' ); 2482 2482 2483 /** 2484 * Get the displayed user Object 2485 * 2486 * @since 2.6.0 2487 * 2488 * @return object The displayed user object, null otherwise. 2489 */ 2490 function bp_get_displayed_user() { 2491 $bp = buddypress(); 2492 2493 $displayed_user = null; 2494 if ( ! empty( $bp->displayed_user->id ) ) { 2495 $displayed_user = $bp->displayed_user; 2496 } 2497 2498 /** 2499 * Filters the displayed_user object corresponding to the displayed member. 2500 * 2501 * @since 2.6.0 2502 * 2503 * @param object $displayed_user The displayed_user object. 2504 */ 2505 return apply_filters( 'bp_get_displayed_user', $displayed_user ); 2506 } 2507 2483 2508 /** Member Types *************************************************************/ 2484 2509 2485 2510 /** -
src/bp-members/bp-members-template.php
diff --git src/bp-members/bp-members-template.php src/bp-members/bp-members-template.php index f31a3d9..a843fc3 100644
function bp_get_loggedin_user_nav() { 1326 1326 } 1327 1327 1328 1328 /** 1329 * Output the contents of the current user's home page. 1330 * 1331 * @since 2.6.0 1332 */ 1333 function bp_displayed_user_front_template_part() { 1334 $located = bp_displayed_user_get_front_template(); 1335 1336 if ( false !== $located ) { 1337 $slug = str_replace( '.php', '', $located ); 1338 1339 /** 1340 * Let plugins adding an action to bp_get_template_part get it from here 1341 * 1342 * @param string $slug Template part slug requested. 1343 * @param string $name Template part name requested. 1344 */ 1345 do_action( 'get_template_part_' . $slug, $slug, false ); 1346 1347 load_template( $located, true ); 1348 } 1349 1350 return $located; 1351 } 1352 1353 /** 1354 * Locate a custom user front template if it exists. 1355 * 1356 * @since 2.6.0 1357 * 1358 * @param object|null $displayed_user Optional. Falls back to current user if not passed. 1359 * @return string|bool Path to front template on success; boolean false on failure. 1360 */ 1361 function bp_displayed_user_get_front_template( $displayed_user = null ) { 1362 if ( ! is_object( $displayed_user ) || empty( $displayed_user->id ) ) { 1363 $displayed_user = bp_get_displayed_user(); 1364 } 1365 1366 if ( ! isset( $displayed_user->id ) ) { 1367 return false; 1368 } 1369 1370 if ( isset( $displayed_user->front_template ) ) { 1371 return $displayed_user->front_template; 1372 } 1373 1374 // Init the hierarchy 1375 $template_names = array( 1376 'members/single/front-id-' . sanitize_file_name( $displayed_user->id ) . '.php', 1377 'members/single/front-nicename-' . sanitize_file_name( $displayed_user->userdata->user_nicename ) . '.php', 1378 ); 1379 1380 /** 1381 * Check for member types and add it to the hierarchy 1382 * 1383 * Make sure to register your member 1384 * type using the hook 'bp_register_member_types' 1385 */ 1386 if ( bp_get_member_types() ) { 1387 $displayed_user_member_type = bp_get_member_type( $displayed_user->id ); 1388 if ( ! $displayed_user_member_type ) { 1389 $displayed_user_member_type = 'none'; 1390 } 1391 1392 $template_names[] = 'members/single/front-member-type-' . sanitize_file_name( $displayed_user_member_type ) . '.php'; 1393 } 1394 1395 // Add The generic template to the end of the hierarchy 1396 $template_names[] = 'members/single/front.php'; 1397 1398 /** 1399 * Filters the hierarchy of user front templates corresponding to a specific user. 1400 * 1401 * @since 2.6.0 1402 * 1403 * @param array $template_names Array of template paths. 1404 */ 1405 return bp_locate_template( apply_filters( 'bp_displayed_user_get_front_template', $template_names ), false, true ); 1406 } 1407 1408 /** 1409 * Check if the displayed user has a custom front template. 1410 * 1411 * @since 2.6.0 1412 */ 1413 function bp_displayed_user_has_front_template() { 1414 $displayed_user = bp_get_displayed_user(); 1415 1416 return ! empty( $displayed_user->front_template ); 1417 } 1418 1419 /** 1329 1420 * Render the navigation markup for the displayed user. 1330 1421 * 1331 1422 * @since 1.1.0 -
src/bp-members/classes/class-bp-members-component.php
diff --git src/bp-members/classes/class-bp-members-component.php src/bp-members/classes/class-bp-members-component.php index edf49a4..73b45e0 100644
class BP_Members_Component extends BP_Component { 153 153 // Initialize the nav for the members component. 154 154 $this->nav = new BP_Core_Nav(); 155 155 156 // If A user is displayed, check if there is a front template 157 if ( bp_get_displayed_user() ) { 158 $bp->displayed_user->front_template = bp_displayed_user_get_front_template(); 159 } 160 156 161 /** Signup *********************************************************** 157 162 */ 158 163 … … class BP_Members_Component extends BP_Component { 178 183 179 184 /** Default Profile Component **************************************** 180 185 */ 181 182 if ( defined( 'BP_DEFAULT_COMPONENT' ) && BP_DEFAULT_COMPONENT ) { 186 if ( bp_displayed_user_has_front_template() ) { 187 $bp->default_component = 'front'; 188 } elseif ( defined( 'BP_DEFAULT_COMPONENT' ) && BP_DEFAULT_COMPONENT ) { 183 189 $bp->default_component = BP_DEFAULT_COMPONENT; 190 } elseif ( bp_is_active( 'activity' ) && isset( $bp->pages->activity ) ) { 191 $bp->default_component = bp_get_activity_slug(); 184 192 } else { 185 if ( bp_is_active( 'activity' ) && isset( $bp->pages->activity ) ) { 186 $bp->default_component = bp_get_activity_slug(); 187 } else { 188 $bp->default_component = ( 'xprofile' === $bp->profile->id ) ? 'profile' : $bp->profile->id; 189 } 193 $bp->default_component = ( 'xprofile' === $bp->profile->id ) ? 'profile' : $bp->profile->id; 190 194 } 191 195 192 196 /** Canonical Component Stack **************************************** … … class BP_Members_Component extends BP_Component { 242 246 */ 243 247 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 244 248 245 // Bail if XProfile component is active.246 if ( bp_is_active( 'xprofile') ) {249 // Don't set up navigation if there's no member. 250 if ( ! is_user_logged_in() && ! bp_is_user() ) { 247 251 return; 248 252 } 249 253 250 // Don't set up navigation if there's no member. 251 if ( ! is_user_logged_in() && ! bp_is_user() ) { 254 $is_xprofile_active = bp_is_active( 'xprofile' ); 255 256 // Bail if XProfile component is active and there's no custom front page for the user. 257 if ( ! bp_displayed_user_has_front_template() && $is_xprofile_active ) { 252 258 return; 253 259 } 254 260 … … class BP_Members_Component extends BP_Component { 261 267 return; 262 268 } 263 269 264 $slug = bp_get_profile_slug(); 265 $profile_link = trailingslashit( $user_domain . $slug ); 266 267 // Setup the main navigation. 268 $main_nav = array( 269 'name' => _x( 'Profile', 'Member profile main navigation', 'buddypress' ), 270 'slug' => $slug, 271 'position' => 20, 272 'screen_function' => 'bp_members_screen_display_profile', 273 'default_subnav_slug' => 'public', 274 'item_css_id' => buddypress()->profile->id 275 ); 270 // Set slug to profile in case the xProfile component is not active 271 $slug = bp_get_profile_slug(); 272 273 // Defaults to empty navs 274 $this->main_nav = array(); 275 $this->sub_nav = array(); 276 277 if ( ! $is_xprofile_active ) { 278 $this->main_nav = array( 279 'name' => _x( 'Profile', 'Member profile main navigation', 'buddypress' ), 280 'slug' => $slug, 281 'position' => 20, 282 'screen_function' => 'bp_members_screen_display_profile', 283 'default_subnav_slug' => 'public', 284 'item_css_id' => buddypress()->profile->id 285 ); 286 } 276 287 277 // Setup the subnav items for the member profile. 278 $sub_nav[] = array( 288 /** 289 * Setup the subnav items for the member profile. 290 * 291 * This is required in case there's a custom front or in case the xprofile component 292 * is not active. 293 */ 294 $this->sub_nav = array( 279 295 'name' => _x( 'View', 'Member profile view', 'buddypress' ), 280 296 'slug' => 'public', 281 'parent_url' => $profile_link,297 'parent_url' => trailingslashit( $user_domain . $slug ), 282 298 'parent_slug' => $slug, 283 299 'screen_function' => 'bp_members_screen_display_profile', 284 300 'position' => 10 285 301 ); 286 302 303 /** 304 * If there's a front template the members component nav 305 * will be there to display the user's front page. 306 */ 307 if ( bp_displayed_user_has_front_template() ) { 308 $main_nav = array( 309 'name' => _x( 'Home', 'Member Home page', 'buddypress' ), 310 'slug' => 'front', 311 'position' => 5, 312 'screen_function' => 'bp_members_screen_display_profile', 313 'default_subnav_slug' => 'public', 314 ); 315 316 // We need a dummy subnav for the front page to load. 317 $front_subnav = $this->sub_nav; 318 $front_subnav['parent_slug'] = 'front'; 319 320 // In case the subnav is displayed in the front template 321 $front_subnav['parent_url'] = trailingslashit( $user_domain . 'front' ); 322 323 // Set the subnav 324 $sub_nav[] = $front_subnav; 325 326 /** 327 * If the profile component is not active, we need to create a new 328 * nav to display the WordPress profile. 329 */ 330 if ( ! $is_xprofile_active ) { 331 add_action( 'bp_members_setup_nav', array( $this, 'setup_profile_nav' ) ); 332 } 333 334 /** 335 * If there's no front template and xProfile is not active, the members 336 * component nav will be there to display the WordPress profile 337 */ 338 } else { 339 $main_nav = $this->main_nav; 340 $sub_nav[] = $this->sub_nav; 341 } 342 343 287 344 parent::setup_nav( $main_nav, $sub_nav ); 288 345 } 289 346 290 347 /** 348 * Set up a profile nav in case the xProfile 349 * component is not active and a front template is 350 * used. 351 * 352 * @since 2.6.0 353 */ 354 public function setup_profile_nav() { 355 if ( empty( $this->main_nav ) || empty( $this->sub_nav ) ) { 356 return; 357 } 358 359 // Add the main nav 360 bp_core_new_nav_item( $this->main_nav, 'members' ); 361 362 // Add the sub nav item. 363 bp_core_new_subnav_item( $this->sub_nav, 'members' ); 364 } 365 366 /** 291 367 * Set up the title for pages and <title>. 292 368 * 293 369 * @since 1.5.0 -
src/bp-templates/bp-legacy/buddypress/members/single/home.php
diff --git src/bp-templates/bp-legacy/buddypress/members/single/home.php src/bp-templates/bp-legacy/buddypress/members/single/home.php index b7e5ee9..b28063e 100644
64 64 */ 65 65 do_action( 'bp_before_member_body' ); 66 66 67 if ( bp_is_user_activity() || !bp_current_component() ) : 67 if ( bp_is_user_front() ) : 68 bp_displayed_user_front_template_part(); 69 70 elseif ( bp_is_user_activity() ) : 68 71 bp_get_template_part( 'members/single/activity' ); 69 72 70 73 elseif ( bp_is_user_blogs() ) :