Ticket #6769: 6769.patch
File 6769.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 1f2c5e9..98d223c 100644
function bp_is_user() { 2256 2256 } 2257 2257 2258 2258 /** 2259 * Is the current page a user custom front page? 2260 * 2261 * Will return true anytime there is a custom front page for the displayed user. 2262 * 2263 * @since 2.6.0 2264 * 2265 * @return bool True if the current page is a user custom front page. 2266 */ 2267 function bp_is_user_front() { 2268 return (bool) ( bp_is_user() && bp_is_current_component( 'front' ) ); 2269 } 2270 2271 /** 2259 2272 * Is the current page a user's activity stream page? 2260 2273 * 2261 2274 * 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 bffd155..591d0e4 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 92a2c85..37261da 100644
class BP_Members_Component extends BP_Component { 150 150 // The domain for the user currently being displayed. 151 151 $bp->displayed_user->domain = bp_core_get_user_domain( bp_displayed_user_id() ); 152 152 153 // If A user is displayed, check if there is a front template 154 if ( bp_get_displayed_user() ) { 155 $bp->displayed_user->front_template = bp_displayed_user_get_front_template(); 156 } 157 153 158 /** Signup *********************************************************** 154 159 */ 155 160 … … class BP_Members_Component extends BP_Component { 175 180 176 181 /** Default Profile Component **************************************** 177 182 */ 178 179 if ( defined( 'BP_DEFAULT_COMPONENT' ) && BP_DEFAULT_COMPONENT ) { 183 if ( bp_displayed_user_has_front_template() ) { 184 $bp->default_component = 'front'; 185 } elseif ( defined( 'BP_DEFAULT_COMPONENT' ) && BP_DEFAULT_COMPONENT ) { 180 186 $bp->default_component = BP_DEFAULT_COMPONENT; 187 } elseif ( bp_is_active( 'activity' ) && isset( $bp->pages->activity ) ) { 188 $bp->default_component = bp_get_activity_slug(); 181 189 } else { 182 if ( bp_is_active( 'activity' ) && isset( $bp->pages->activity ) ) { 183 $bp->default_component = bp_get_activity_slug(); 184 } else { 185 $bp->default_component = ( 'xprofile' === $bp->profile->id ) ? 'profile' : $bp->profile->id; 186 } 190 $bp->default_component = ( 'xprofile' === $bp->profile->id ) ? 'profile' : $bp->profile->id; 187 191 } 188 192 189 193 /** Canonical Component Stack **************************************** … … class BP_Members_Component extends BP_Component { 239 243 */ 240 244 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 241 245 242 // Bail if XProfile component is active.243 if ( bp_is_active( 'xprofile') ) {246 // Don't set up navigation if there's no member. 247 if ( ! is_user_logged_in() && ! bp_is_user() ) { 244 248 return; 245 249 } 246 250 247 // Don't set up navigation if there's no member. 248 if ( ! is_user_logged_in() && ! bp_is_user() ) { 251 $is_xprofile_active = bp_is_active( 'xprofile' ); 252 253 // Bail if XProfile component is active and there's no custom front page for the user. 254 if ( ! bp_displayed_user_has_front_template() && $is_xprofile_active ) { 249 255 return; 250 256 } 251 257 … … class BP_Members_Component extends BP_Component { 258 264 return; 259 265 } 260 266 261 $slug = bp_get_profile_slug(); 262 $profile_link = trailingslashit( $user_domain . $slug ); 263 264 // Setup the main navigation. 265 $main_nav = array( 266 'name' => _x( 'Profile', 'Member profile main navigation', 'buddypress' ), 267 'slug' => $slug, 268 'position' => 20, 269 'screen_function' => 'bp_members_screen_display_profile', 270 'default_subnav_slug' => 'public', 271 'item_css_id' => buddypress()->profile->id 272 ); 267 // Set slug to profile in case the xProfile component is not active 268 $slug = bp_get_profile_slug(); 269 270 // Defaults to empty navs 271 $this->main_nav = array(); 272 $this->sub_nav = array(); 273 274 if ( ! $is_xprofile_active ) { 275 $this->main_nav = array( 276 'name' => _x( 'Profile', 'Member profile main navigation', 'buddypress' ), 277 'slug' => $slug, 278 'position' => 20, 279 'screen_function' => 'bp_members_screen_display_profile', 280 'default_subnav_slug' => 'public', 281 'item_css_id' => buddypress()->profile->id 282 ); 283 } 273 284 274 // Setup the subnav items for the member profile. 275 $sub_nav[] = array( 285 /** 286 * Setup the subnav items for the member profile. 287 * 288 * This is required in case there's a custom front or in case the xprofile component 289 * is not active. 290 */ 291 $this->sub_nav = array( 276 292 'name' => _x( 'View', 'Member profile view', 'buddypress' ), 277 293 'slug' => 'public', 278 'parent_url' => $profile_link,294 'parent_url' => trailingslashit( $user_domain . $slug ), 279 295 'parent_slug' => $slug, 280 296 'screen_function' => 'bp_members_screen_display_profile', 281 297 'position' => 10 282 298 ); 283 299 300 /** 301 * If there's a front template the members component nav 302 * will be there to display the user's front page. 303 */ 304 if ( bp_displayed_user_has_front_template() ) { 305 $main_nav = array( 306 'name' => _x( 'Home', 'Member Home page', 'buddypress' ), 307 'slug' => 'front', 308 'position' => 5, 309 'screen_function' => 'bp_members_screen_display_profile', 310 'default_subnav_slug' => 'public', 311 ); 312 313 // We need a dummy subnav for the front page to load. 314 $front_subnav = $this->sub_nav; 315 $front_subnav['parent_slug'] = 'front'; 316 317 // In case the subnav is displayed in the front template 318 $front_subnav['parent_url'] = trailingslashit( $user_domain . 'front' ); 319 320 // Set the subnav 321 $sub_nav[] = $front_subnav; 322 323 /** 324 * If the profile component is not active, we need to create a new 325 * nav to display the WordPress profile. 326 */ 327 if ( ! $is_xprofile_active ) { 328 add_action( 'bp_members_setup_nav', array( $this, 'setup_profile_nav' ) ); 329 } 330 331 /** 332 * If there's no front template and xProfile is not active, the members 333 * component nav will be there to display the WordPress profile 334 */ 335 } else { 336 $main_nav = $this->main_nav; 337 $sub_nav[] = $this->sub_nav; 338 } 339 340 284 341 parent::setup_nav( $main_nav, $sub_nav ); 285 342 } 286 343 287 344 /** 345 * Set up a profile nav in case the xProfile 346 * component is not active and a front template is 347 * used. 348 * 349 * @since 2.6.0 350 */ 351 public function setup_profile_nav() { 352 if ( empty( $this->main_nav ) || empty( $this->sub_nav ) ) { 353 return; 354 } 355 356 // Add the main nav 357 bp_core_new_nav_item( $this->main_nav ); 358 359 // Add the sub nav item. 360 bp_core_new_subnav_item( $this->sub_nav ); 361 } 362 363 /** 288 364 * Set up the title for pages and <title>. 289 365 * 290 366 * @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() ) :