Skip to:
Content

BuddyPress.org

Changeset 10538


Ignore:
Timestamp:
02/06/2016 06:07:22 PM (10 years ago)
Author:
djpaul
Message:

Emails: add email menus to network admin for network-activated configs.

This provides consistency with the rest of BuddyPress; namely, that when network activated, you manage all BuddyPress content from the network admin.
With post types and taxonomies, we have to do a little extra work to add links to the root site on the network-admin, because of API limitations in WordPress.

See #6592

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/classes/class-bp-admin.php

    r10537 r10538  
    146146
    147147                // Add menu item to settings menu.
     148                add_action( 'admin_menu',               array( $this, 'site_admin_menus' ), 5 );
    148149                add_action( bp_core_admin_hook(),       array( $this, 'admin_menus' ), 5 );
    149150
     
    186187
    187188        /**
    188          * Add the navigational menu elements.
     189         * Register site- or network-admin nav menu elements.
     190         *
     191         * Contextually hooked to site or network-admin depending on current configuration.
    189192         *
    190193         * @since 1.6.0
     
    304307                );
    305308
    306                 $hooks[] = add_theme_page(
    307                         _x( 'Emails', 'screen heading', 'buddypress' ),
    308                         _x( 'Emails', 'screen heading', 'buddypress' ),
    309                         $this->capability,
    310                         'bp-emails-customizer-redirect',
    311                         'bp_email_redirect_to_customizer'
    312                 );
     309                // For network-wide configs, add a link to (the root site's) Emails screen.
     310                if ( is_network_admin() && bp_is_network_activated() ) {
     311                        $email_labels = bp_get_email_post_type_labels();
     312                        $email_url    = get_admin_url( bp_get_root_blog_id(), 'edit.php?post_type=' . bp_get_email_post_type() );
     313
     314                        $hooks[] = add_menu_page(
     315                                $email_labels['name'],
     316                                $email_labels['name'],
     317                                $this->capability,
     318                                '',
     319                                '',
     320                                'dashicons-email',
     321                                26
     322                        );
     323
     324                        // Hack: change the link to point to the root site's admin, not the network admin.
     325                        $GLOBALS['menu'][26][2] = esc_url_raw( $email_url );
     326                }
     327
     328                foreach( $hooks as $hook ) {
     329                        add_action( "admin_head-$hook", 'bp_core_modify_admin_menu_highlight' );
     330                }
     331        }
     332
     333        /**
     334         * Register site-admin nav menu elements.
     335         *
     336         * @since 2.5.0
     337         */
     338        public function site_admin_menus() {
     339                if ( ! bp_current_user_can( 'manage_options' ) ) {
     340                        return;
     341                }
     342
     343                $hooks = array();
     344
     345                if ( bp_is_root_blog() ) {
     346                        // Appearance > Emails.
     347                        $hooks[] = add_theme_page(
     348                                _x( 'Emails', 'screen heading', 'buddypress' ),
     349                                _x( 'Emails', 'screen heading', 'buddypress' ),
     350                                $this->capability,
     351                                'bp-emails-customizer-redirect',
     352                                'bp_email_redirect_to_customizer'
     353                        );
     354                }
    313355
    314356                foreach( $hooks as $hook ) {
     
    906948        public function emails_admin_menu_order( $custom_menus = array() ) {
    907949                array_push( $custom_menus, 'edit.php?post_type=' . bp_get_email_post_type() );
     950
     951                if ( is_network_admin() && bp_is_network_activated() ) {
     952                        array_push(
     953                                $custom_menus,
     954                                get_admin_url( bp_get_root_blog_id(), 'edit.php?post_type=' . bp_get_email_post_type() )
     955                        );
     956                }
     957
    908958                return $custom_menus;
    909959        }
Note: See TracChangeset for help on using the changeset viewer.