- Timestamp:
- 04/12/2023 10:12:37 PM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-members/classes/class-bp-members-component.php
r13443 r13450 423 423 * 424 424 * @since 6.0.0 425 * @deprecated 12.0.0 425 426 * 426 427 * @return array The Avatar and Cover image subnavs. 427 428 */ 428 429 public function get_avatar_cover_image_subnavs() { 429 $subnavs = array(); 430 431 $access = bp_core_can_edit_settings(); 432 $slug = bp_get_profile_slug(); 433 434 // Change Avatar. 435 if ( buddypress()->avatar->show_avatars ) { 436 $subnavs[] = array( 437 'name' => _x( 'Change Profile Photo', 'Profile header sub menu', 'buddypress' ), 438 'slug' => 'change-avatar', 439 'parent_slug' => $slug, 440 'screen_function' => 'bp_members_screen_change_avatar', 441 'position' => 30, 442 'user_has_access' => $access 443 ); 444 } 445 446 // Change Cover image. 447 if ( bp_displayed_user_use_cover_image_header() ) { 448 $subnavs[] = array( 449 'name' => _x( 'Change Cover Image', 'Profile header sub menu', 'buddypress' ), 450 'slug' => 'change-cover-image', 451 'parent_slug' => $slug, 452 'screen_function' => 'bp_members_screen_change_cover_image', 453 'position' => 40, 454 'user_has_access' => $access 455 ); 456 } 457 458 return $subnavs; 459 } 460 461 /** 462 * Set up fall-back component navigation if XProfile is inactive. 463 * 464 * @since 1.5.0 465 * 466 * @see BP_Component::setup_nav() for a description of arguments. 467 * 468 * @param array $main_nav Optional. See BP_Component::setup_nav() for 430 _deprecated_function( __METHOD__, '12.0.0' ); 431 } 432 433 /** 434 * Register component navigation. 435 * 436 * @since 12.0.0 437 * 438 * @see `BP_Component::register_nav()` for a description of arguments. 439 * 440 * @param array $main_nav Optional. See `BP_Component::register_nav()` for 469 441 * description. 470 * @param array $sub_nav Optional. See BP_Component::setup_nav()for442 * @param array $sub_nav Optional. See `BP_Component::register_nav()` for 471 443 * description. 472 444 */ 473 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 474 475 // Don't set up navigation if there's no member. 476 if ( ! is_user_logged_in() && ! bp_is_user() ) { 477 return; 478 } 479 480 $is_xprofile_active = bp_is_active( 'xprofile' ); 481 482 // Bail if XProfile component is active and there's no custom front page for the user. 483 if ( ! bp_displayed_user_has_front_template() && $is_xprofile_active ) { 484 add_action( 'bp_xprofile_setup_nav', array( $this, 'setup_xprofile_nav' ) ); 485 return; 486 } 487 445 public function register_nav( $main_nav = array(), $sub_nav = array() ) { 488 446 // Set slug to profile in case the xProfile component is not active 489 447 $slug = bp_get_profile_slug(); 490 448 491 // Defaults to empty navs 492 $this->main_nav = array(); 493 $this->sub_nav = array(); 494 495 if ( ! $is_xprofile_active ) { 496 $this->main_nav = array( 497 'name' => _x( 'Profile', 'Member profile main navigation', 'buddypress' ), 498 'slug' => $slug, 499 'position' => 20, 500 'screen_function' => 'bp_members_screen_display_profile', 501 'default_subnav_slug' => 'public', 502 'item_css_id' => buddypress()->profile->id 503 ); 504 505 /** 506 * The xProfile component is active. 507 * 508 * We need to make sure the Change Avatar and Change Cover Image subnavs are 509 * added just like it was the case before. 510 */ 511 } else { 512 add_action( 'bp_xprofile_setup_nav', array( $this, 'setup_xprofile_nav' ) ); 513 } 514 515 /** 516 * Setup the subnav items for the member profile. 517 * 518 * This is required in case there's a custom front or in case the xprofile component 519 * is not active. 520 */ 521 $this->sub_nav = array( 449 $main_nav = array( 450 'name' => _x( 'Profile', 'Member profile main navigation', 'buddypress' ), 451 'slug' => $slug, 452 'position' => 20, 453 'screen_function' => 'bp_members_screen_display_profile', 454 'default_subnav_slug' => 'public', 455 'item_css_id' => buddypress()->profile->id, 456 'generate' => ! bp_is_active( 'xprofile' ), 457 ); 458 459 $sub_nav[] = array( 522 460 'name' => _x( 'View', 'Member profile view', 'buddypress' ), 523 461 'slug' => 'public', 524 462 'parent_slug' => $slug, 525 463 'screen_function' => 'bp_members_screen_display_profile', 526 'position' => 10 527 ); 528 529 /** 530 * If there's a front template the members component nav 531 * will be there to display the user's front page. 532 */ 533 if ( bp_displayed_user_has_front_template() ) { 534 $main_nav = array( 535 'name' => _x( 'Home', 'Member Home page', 'buddypress' ), 536 'slug' => 'front', 537 'position' => 5, 538 'screen_function' => 'bp_members_screen_display_profile', 539 'default_subnav_slug' => 'public', 540 ); 541 542 // We need a dummy subnav for the front page to load. 543 $front_subnav = $this->sub_nav; 544 $front_subnav['parent_slug'] = 'front'; 545 546 // Set the subnav 547 $sub_nav[] = $front_subnav; 548 549 /** 550 * If the profile component is not active, we need to create a new 551 * nav to display the WordPress profile. 552 */ 553 if ( ! $is_xprofile_active ) { 554 add_action( 'bp_members_setup_nav', array( $this, 'setup_profile_nav' ) ); 555 } 556 557 /** 558 * If there's no front template and xProfile is not active, the members 559 * component nav will be there to display the WordPress profile 560 */ 561 } else { 562 $main_nav = $this->main_nav; 563 $sub_nav = array( $this->sub_nav ); 564 565 if ( ! $is_xprofile_active ) { 566 $sub_nav = array_merge( $sub_nav, $this->get_avatar_cover_image_subnavs() ); 567 } 568 } 569 570 parent::setup_nav( $main_nav, $sub_nav ); 464 'position' => 10, 465 'generate' => ! bp_is_active( 'xprofile' ), 466 ); 467 468 $sub_nav[] = array( 469 'name' => _x( 'Change Profile Photo', 'Profile header sub menu', 'buddypress' ), 470 'slug' => 'change-avatar', 471 'parent_slug' => $slug, 472 'screen_function' => 'bp_members_screen_change_avatar', 473 'position' => 30, 474 'user_has_access' => false, 475 'user_has_access_callback' => 'bp_core_can_edit_settings', 476 'generate' => buddypress()->avatar->show_avatars, 477 ); 478 479 $sub_nav[] = array( 480 'name' => _x( 'Change Cover Image', 'Profile header sub menu', 'buddypress' ), 481 'slug' => 'change-cover-image', 482 'parent_slug' => $slug, 483 'screen_function' => 'bp_members_screen_change_cover_image', 484 'position' => 40, 485 'user_has_access' => false, 486 'user_has_access_callback' => 'bp_core_can_edit_settings', 487 'generate' => bp_displayed_user_use_cover_image_header(), 488 ); 489 490 parent::register_nav( $main_nav, $sub_nav ); 571 491 } 572 492 … … 577 497 * 578 498 * @since 2.6.0 499 * @deprecated 12.0.0 579 500 */ 580 501 public function setup_profile_nav() { 581 if ( empty( $this->main_nav ) || empty( $this->sub_nav ) ) { 582 return; 583 } 584 585 // Add the main nav 586 bp_core_new_nav_item( $this->main_nav, 'members' ); 587 588 // Add the sub nav item. 589 bp_core_new_subnav_item( $this->sub_nav, 'members' ); 590 591 // Get the Avatar and cover image subnavs. 592 $this->setup_xprofile_nav(); 502 _deprecated_function( __METHOD__, '12.0.0' ); 593 503 } 594 504 … … 597 507 * 598 508 * @since 6.0.0 509 * @deprecated 12.0.0 599 510 */ 600 511 public function setup_xprofile_nav() { 601 // Get the Avatar and cover image subnavs. 602 $items = $this->get_avatar_cover_image_subnavs(); 603 604 foreach ( $items as $item ) { 605 bp_core_new_subnav_item( $item, 'members' ); 606 } 512 _deprecated_function( __METHOD__, '12.0.0' ); 607 513 } 608 514
Note: See TracChangeset
for help on using the changeset viewer.