Skip to:
Content

BuddyPress.org


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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.