Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/29/2020 04:09:19 PM (7 years ago)
Author:
imath
Message:

Move Avatars & Cover from xProfile to Members component : step 6

Move the Avatars & Cover navigation and the Avatars REST Controllers from the xProfile Component to the Members one.

See #8156

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/classes/class-bp-members-component.php

    r12488 r12559  
    107107                if ( bp_is_user() ) {
    108108                        require $this->path . 'bp-members/screens/profile.php';
     109
     110                        // Action - Delete avatar.
     111                        if ( is_user_logged_in()&& bp_is_user_change_avatar() && bp_is_action_variable( 'delete-avatar', 0 ) ) {
     112                                require $this->path . 'bp-members/actions/delete-avatar.php';
     113                        }
     114
     115                        // Sub-nav items.
     116                        if ( is_user_logged_in() &&
     117                                in_array( bp_current_action(), array( 'change-avatar', 'change-cover-image' ), true )
     118                        ) {
     119                                require $this->path . 'bp-members/screens/' . bp_current_action() . '.php';
     120                        }
    109121                }
    110122
    … …  
    290302
    291303        /**
     304         * Get the Avatar and Cover image subnavs.
     305         *
     306         * @since 6.0.0
     307         *
     308         * @return array The Avatar and Cover image subnavs.
     309         */
     310        public function get_avatar_cover_image_subnavs() {
     311                $subnavs = array();
     312
     313                $access       = bp_core_can_edit_settings();
     314                $slug         = bp_get_profile_slug();
     315                $profile_link = bp_get_members_component_link( $slug );
     316
     317                // Change Avatar.
     318                if ( buddypress()->avatar->show_avatars ) {
     319                        $subnavs[] = array(
     320                                'name'            => _x( 'Change Profile Photo', 'Profile header sub menu', 'buddypress' ),
     321                                'slug'            => 'change-avatar',
     322                                'parent_url'      => $profile_link,
     323                                'parent_slug'     => $slug,
     324                                'screen_function' => 'bp_members_screen_change_avatar',
     325                                'position'        => 30,
     326                                'user_has_access' => $access
     327                        );
     328                }
     329
     330                // Change Cover image.
     331                if ( bp_displayed_user_use_cover_image_header() ) {
     332                        $subnavs[] = array(
     333                                'name'            => _x( 'Change Cover Image', 'Profile header sub menu', 'buddypress' ),
     334                                'slug'            => 'change-cover-image',
     335                                'parent_url'      => $profile_link,
     336                                'parent_slug'     => $slug,
     337                                'screen_function' => 'bp_members_screen_change_cover_image',
     338                                'position'        => 40,
     339                                'user_has_access' => $access
     340                        );
     341                }
     342
     343                return $subnavs;
     344        }
     345
     346        /**
    292347         * Set up fall-back component navigation if XProfile is inactive.
    293348         *
    … …  
    312367                // Bail if XProfile component is active and there's no custom front page for the user.
    313368                if ( ! bp_displayed_user_has_front_template() && $is_xprofile_active ) {
     369                        add_action( 'bp_xprofile_setup_nav', array( $this, 'setup_xprofile_nav' ) );
    314370                        return;
    315371                }
    … …  
    340396                                'item_css_id'         => buddypress()->profile->id
    341397                        );
     398
     399                /**
     400                 * The xProfile component is active.
     401                 *
     402                 * We need to make sure the Change Avatar and Change Cover Image subnavs are
     403                 * added just like it was the case before.
     404                 */
     405                } else {
     406                        add_action( 'bp_xprofile_setup_nav', array( $this, 'setup_xprofile_nav' ) );
    342407                }
    343408
    … …  
    394459                } else {
    395460                        $main_nav  = $this->main_nav;
    396                         $sub_nav[] = $this->sub_nav;
     461                        $sub_nav   = array( $this->sub_nav );
     462
     463                        if ( ! $is_xprofile_active ) {
     464                                $sub_nav = array_merge( $sub_nav, $this->get_avatar_cover_image_subnavs() );
     465                        }
    397466                }
    398467
    … …  
    418487                // Add the sub nav item.
    419488                bp_core_new_subnav_item( $this->sub_nav, 'members' );
     489
     490                // Get the Avatar and cover image subnavs.
     491                $this->setup_xprofile_nav();
     492        }
     493
     494        /**
     495         * Set up the xProfile nav.
     496         *
     497         * @since 6.0.0
     498         */
     499        public function setup_xprofile_nav() {
     500                // Get the Avatar and cover image subnavs.
     501                $items = $this->get_avatar_cover_image_subnavs();
     502
     503                foreach ( $items as $item ) {
     504                        bp_core_new_subnav_item( $item, 'members' );
     505                }
     506        }
     507
     508        /**
     509         * Get the Avatar and Cover image admin navs.
     510         *
     511         * @since 6.0.0
     512         *
     513         * @param  string $admin_bar_menu_id The Admin bar menu ID to attach sub items to.
     514         * @return array                     The Avatar and Cover image admin navs.
     515         */
     516        public function get_avatar_cover_image_admin_navs( $admin_bar_menu_id = '' ) {
     517                $wp_admin_nav = array();
     518                $profile_link = trailingslashit( bp_loggedin_user_domain() . bp_get_profile_slug() );
     519
     520                if ( ! $admin_bar_menu_id ) {
     521                        $admin_bar_menu_id = $this->id;
     522                }
     523
     524                // Edit Avatar.
     525                if ( buddypress()->avatar->show_avatars ) {
     526                        $wp_admin_nav[] = array(
     527                                'parent'   => 'my-account-' . $admin_bar_menu_id,
     528                                'id'       => 'my-account-' . $admin_bar_menu_id . '-change-avatar',
     529                                'title'    => _x( 'Change Profile Photo', 'My Account Profile sub nav', 'buddypress' ),
     530                                'href'     => trailingslashit( $profile_link . 'change-avatar' ),
     531                                'position' => 30
     532                        );
     533                }
     534
     535                // Edit Cover Image
     536                if ( bp_displayed_user_use_cover_image_header() ) {
     537                        $wp_admin_nav[] = array(
     538                                'parent'   => 'my-account-' . $admin_bar_menu_id,
     539                                'id'       => 'my-account-' . $admin_bar_menu_id . '-change-cover-image',
     540                                'title'    => _x( 'Change Cover Image', 'My Account Profile sub nav', 'buddypress' ),
     541                                'href'     => trailingslashit( $profile_link . 'change-cover-image' ),
     542                                'position' => 40
     543                        );
     544                }
     545
     546                return $wp_admin_nav;
     547        }
     548
     549        /**
     550         * Set up the Admin Bar.
     551         *
     552         * @since 6.0.0
     553         *
     554         * @param array $wp_admin_nav Admin Bar items.
     555         */
     556        public function setup_admin_bar( $wp_admin_nav = array() ) {
     557                // Menus for logged in user.
     558                if ( is_user_logged_in() ) {
     559                        $profile_link = trailingslashit( bp_loggedin_user_domain() . bp_get_profile_slug() );
     560
     561                        if ( ! bp_is_active( 'xprofile' ) ) {
     562                                // Add the "Profile" sub menu.
     563                                $wp_admin_nav[] = array(
     564                                        'parent' => buddypress()->my_account_menu_id,
     565                                        'id'     => 'my-account-' . $this->id,
     566                                        'title'  => _x( 'Profile', 'My Account Profile', 'buddypress' ),
     567                                        'href'   => $profile_link
     568                                );
     569
     570                                // View Profile.
     571                                $wp_admin_nav[] = array(
     572                                        'parent'   => 'my-account-' . $this->id,
     573                                        'id'       => 'my-account-' . $this->id . '-public',
     574                                        'title'    => _x( 'View', 'My Account Profile sub nav', 'buddypress' ),
     575                                        'href'     => $profile_link,
     576                                        'position' => 10
     577                                );
     578
     579                                $wp_admin_nav = array_merge( $wp_admin_nav, $this->get_avatar_cover_image_admin_navs() );
     580
     581                        /**
     582                         * The xProfile is active.
     583                         *
     584                         * Add the Change Avatar and Change Cover Image Admin Bar items
     585                         * to the xProfile Admin Bar Menu.
     586                         */
     587                        } else {
     588                                add_filter( 'bp_xprofile_admin_nav', array( $this, 'setup_xprofile_admin_nav' ), 2 );
     589                        }
     590                }
     591
     592                parent::setup_admin_bar( $wp_admin_nav );
     593        }
     594
     595        /**
     596         * Adds "Profile > Change Avatar" & "Profile > Change Cover Image" subnav item
     597         * under the "Profile" adminbar menu.
     598         *
     599         * @since 6.0.0
     600         *
     601         * @param array $wp_admin_nav The Profile adminbar nav array.
     602         * @return array
     603         */
     604        public function setup_xprofile_admin_nav( $wp_admin_nav ) {
     605                $items = $this->get_avatar_cover_image_admin_navs( buddypress()->profile->id );
     606
     607                if ( $items ) {
     608                        $wp_admin_nav = array_merge( $wp_admin_nav, $items );
     609                }
     610
     611                return $wp_admin_nav;
    420612        }
    421613
    … …  
    474666                        'BP_REST_Components_Endpoint',
    475667                        'BP_REST_Members_Endpoint',
     668                        'BP_REST_Attachments_Member_Avatar_Endpoint',
    476669                ) );
    477670        }
Note: See TracChangeset for help on using the changeset viewer.