Skip to:
Content

BuddyPress.org

Changeset 13275


Ignore:
Timestamp:
04/29/2022 08:00:56 PM (3 years ago)
Author:
imath
Message:

BP Nouveau: support custom slugs in Messages UI

The Messages UI Backbone Router is no more using hardcoded slugs to define its routes. It's now possible to use customized slugs for the BP Messages component and still enjoy this UI.

Fixes #8691 (branch 10.0)

Location:
branches/10.0/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/10.0/src/bp-messages/classes/class-bp-messages-component.php

    r13196 r13275  
    269269        );
    270270
    271         // Show certain screens only if the current user is the displayed user.
    272         if ( bp_is_my_profile() ) {
    273 
    274             // Show "Compose" on the logged-in user's profile only.
    275             $sub_nav[] = array(
    276                 'name'            => __( 'Compose', 'buddypress' ),
    277                 'slug'            => 'compose',
    278                 'parent_url'      => $messages_link,
    279                 'parent_slug'     => $slug,
    280                 'screen_function' => 'messages_screen_compose',
    281                 'position'        => 30,
    282                 'user_has_access' => $access
    283             );
    284 
    285             /*
    286              * Show "Notices" on the logged-in user's profile only
    287              * and then only if the user can create notices.
    288              */
    289             if ( bp_current_user_can( 'bp_moderate' ) ) {
    290                 $sub_nav[] = array(
    291                     'name'            => __( 'Notices', 'buddypress' ),
    292                     'slug'            => 'notices',
    293                     'parent_url'      => $messages_link,
    294                     'parent_slug'     => $slug,
    295                     'screen_function' => 'messages_screen_notices',
    296                     'position'        => 90,
    297                     'user_has_access' => true
    298                 );
    299             }
    300         }
     271        // Show "Compose" on the logged-in user's profile only.
     272        $sub_nav[] = array(
     273            'name'            => __( 'Compose', 'buddypress' ),
     274            'slug'            => 'compose',
     275            'parent_url'      => $messages_link,
     276            'parent_slug'     => $slug,
     277            'screen_function' => 'messages_screen_compose',
     278            'position'        => 30,
     279            'user_has_access' => bp_is_my_profile(),
     280        );
     281
     282        // Show "Notices" to community admins only.
     283        $sub_nav[] = array(
     284            'name'            => __( 'Notices', 'buddypress' ),
     285            'slug'            => 'notices',
     286            'parent_url'      => $messages_link,
     287            'parent_slug'     => $slug,
     288            'screen_function' => 'messages_screen_notices',
     289            'position'        => 90,
     290            'user_has_access' => bp_current_user_can( 'bp_moderate' )
     291        );
    301292
    302293        parent::setup_nav( $main_nav, $sub_nav );
  • branches/10.0/src/bp-templates/bp-nouveau/includes/messages/functions.php

    r13036 r13275  
    44 *
    55 * @since 3.0.0
    6  * @version 10.0.0
     6 * @version 10.3.0
    77 */
    88
     
    9191    }
    9292
     93    $bp   = buddypress();
     94    $slug = bp_nouveau_get_component_slug( 'messages' );
     95
     96    // Use the primary nav to get potential custom slugs.
     97    $primary_nav = $bp->members->nav->get( $slug );
     98    if ( isset( $primary_nav->link ) && $primary_nav->link ) {
     99        $root_url = $primary_nav->link;
     100
     101        // Make sure to use the displayed user domain.
     102        if ( bp_loggedin_user_domain() ) {
     103            $root_url = str_replace( bp_loggedin_user_domain(), bp_displayed_user_domain(), $root_url );
     104        }
     105    } else {
     106        $root_url = trailingslashit( bp_displayed_user_domain() . $slug );
     107    }
     108
     109    // Build default routes list.
     110    $routes = array(
     111        'inbox'   => 'inbox',
     112        'sentbox' => 'sentbox',
     113        'compose' => 'compose',
     114    );
     115
     116    if ( bp_is_active( 'messages', 'star' ) ) {
     117        $routes['starred'] = 'starred';
     118    }
     119
     120    // Use the secondary nav to get potential custom slugs.
     121    $secondary_nav = $bp->members->nav->get_secondary( array( 'parent_slug' => $slug ), false );
     122
     123    // Resets the routes list using link slugs.
     124    if ( $secondary_nav ) {
     125        foreach ( $secondary_nav as $subnav_item ) {
     126            $routes[ $subnav_item->slug ] = trim( str_replace( $root_url, '', $subnav_item->link ), '/' );
     127
     128            if ( ! $routes[ $subnav_item->slug ] ) {
     129                $routes[ $subnav_item->slug ] = $subnav_item->slug;
     130            }
     131        }
     132    }
     133
    93134    $params['messages'] = array(
    94         'errors' => array(
     135        'errors'            => array(
    95136            'send_to'         => __( 'Please add at least one recipient.', 'buddypress' ),
    96137            'subject'         => __( 'Please add a subject to your message.', 'buddypress' ),
    97138            'message_content' => __( 'Please add some content to your message.', 'buddypress' ),
    98139        ),
    99         'nonces' => array(
     140        'nonces'            => array(
    100141            'send' => wp_create_nonce( 'messages_send_message' ),
    101142        ),
    102         'loading'       => __( 'Loading messages. Please wait.', 'buddypress' ),
    103         'doingAction'   => array(
     143        'loading'           => __( 'Loading messages. Please wait.', 'buddypress' ),
     144        'doingAction'       => array(
    104145            'read'   => __( 'Marking messages as read. Please wait.', 'buddypress' ),
    105146            'unread' => __( 'Marking messages as unread. Please wait.', 'buddypress' ),
     
    108149            'unstar' => __( 'Unstarring messages. Please wait.', 'buddypress' ),
    109150        ),
    110         'bulk_actions'  => bp_nouveau_messages_get_bulk_actions(),
    111         'howto'         => __( 'Click on the message title to preview it in the Active conversation box below.', 'buddypress' ),
    112         'howtoBulk'     => __( 'Use the select box to define your bulk action and click on the ✓ button to apply.', 'buddypress' ),
    113         'toOthers'      => array(
     151        'bulk_actions'      => bp_nouveau_messages_get_bulk_actions(),
     152        'howto'             => __( 'Click on the message title to preview it in the Active conversation box below.', 'buddypress' ),
     153        'howtoBulk'         => __( 'Use the select box to define your bulk action and click on the ✓ button to apply.', 'buddypress' ),
     154        'toOthers'          => array(
    114155            'one'  => __( '(and 1 other)', 'buddypress' ),
    115156
     
    117158            'more' => __( '(and %d others)', 'buddypress' ),
    118159        ),
    119         'rootUrl' => parse_url( trailingslashit( bp_displayed_user_domain() . bp_nouveau_get_component_slug( 'messages' ) ), PHP_URL_PATH ),
     160        'rootUrl'           => parse_url( $root_url, PHP_URL_PATH ),
     161        'supportedRoutes'   => $routes,
    120162    );
    121163
  • branches/10.0/src/bp-templates/bp-nouveau/js/buddypress-messages.js

    r13260 r13275  
    22/* jshint devel: true */
    33/* @since 3.0.0 */
    4 /* @version 10.2.0 */
     4/* @version 10.3.0 */
    55window.wp = window.wp || {};
    66window.bp = window.bp || {};
     
    3737            this.box      = 'inbox';
    3838
     39            // Set up supported routes.
     40            this.supportedRoutes = BP_Nouveau.messages.supportedRoutes;
     41
    3942            this.setupNav();
    4043
     
    5457            $( '#subnav a' ).on( 'click', function( event ) {
    5558                var view_id = $( event.target ).prop( 'id' ),
    56                     supportedView = [ 'inbox', 'starred', 'sentbox', 'compose' ];
     59                    supportedView = _.keys( self.supportedRoutes );
    5760
    5861                if ( -1 === _.indexOf( supportedView, view_id ) || 'unsupported' === self.box ) {
     
    7982
    8083                        // Navigate back to current box.
    81                         self.router.navigate( self.box + '/', { trigger: true } );
     84                        self.router.navigate( self.supportedRoutes[ self.box ] + '/', { trigger: true } );
    8285
    8386                    // Otherwise load it.
    8487                    } else {
    85                         self.router.navigate( 'compose/', { trigger: true } );
     88                        self.router.navigate( self.supportedRoutes.compose + '/', { trigger: true } );
    8689                    }
    8790
     
    9295                        self.clearViews();
    9396
    94                         self.router.navigate( view_id + '/', { trigger: true } );
     97                        self.router.navigate( self.supportedRoutes[ view_id ] + '/', { trigger: true } );
    9598                    }
    9699                }
     
    677680                bp.Nouveau.Messages.views.remove( { id: 'compose', view: form } );
    678681
    679                 bp.Nouveau.Messages.router.navigate( 'sentbox/', { trigger: true } );
     682                bp.Nouveau.Messages.router.navigate( bp.Nouveau.Messages.supportedRoutes.sentbox + '/', { trigger: true } );
    680683            } ).fail( function( response ) {
    681684                if ( response.feedback ) {
     
    14011404    bp.Nouveau.Messages.Router = Backbone.Router.extend( {
    14021405        routes: {
    1403             'compose/'    : 'composeMessage',
    14041406            'view/:id/'   : 'viewMessage',
    1405             'sentbox/'    : 'sentboxView',
    1406             'starred/'    : 'starredView',
    1407             'inbox/'      : 'inboxView',
    14081407            ''            : 'inboxView',
    14091408            '*unSupported': 'unSupported'
     1409        },
     1410
     1411        initialize: function() {
     1412            var self = this;
     1413
     1414            _.each( BP_Nouveau.messages.supportedRoutes, function( route, slug ) {
     1415                self.route( route + '/', slug + 'Route', function() {
     1416                    if ( 'compose' === slug ) {
     1417                        self.composeMessage();
     1418                    } else if ( 'sentbox' === slug ) {
     1419                        self.sentboxView();
     1420                    } else if ( 'starred' === slug ) {
     1421                        self.starredView();
     1422                    } else if ( 'inbox' === slug ) {
     1423                        self.inboxView();
     1424                    }
     1425                } );
     1426            } );
    14101427        },
    14111428
Note: See TracChangeset for help on using the changeset viewer.