Skip to:
Content

BuddyPress.org

Ticket #7840: 7840.pushState.patch

File 7840.pushState.patch, 3.2 KB (added by imath, 3 years ago)
  • src/bp-templates/bp-nouveau/includes/messages/functions.php

    diff --git src/bp-templates/bp-nouveau/includes/messages/functions.php src/bp-templates/bp-nouveau/includes/messages/functions.php
    index 191a85381..b0017a28c 100644
    function bp_nouveau_messages_localize_scripts( $params = array() ) { 
    114114                        'one'  => __( '(and 1 other)', 'buddypress' ),
    115115                        'more' => __( '(and %d others)', 'buddypress' ),
    116116                ),
     117                'rootUrl' => trailingslashit( str_replace( home_url(), '', bp_displayed_user_domain() ) . bp_get_messages_slug() ),
    117118        );
    118119
    119120        // Star private messages.
    function bp_nouveau_messages_adjust_nav() { 
    179180                if ( 'notices' === $secondary_nav_item->slug ) {
    180181                        bp_core_remove_subnav_item( bp_get_messages_slug(), $secondary_nav_item->slug, 'members' );
    181182                } else {
    182                         $params = array( 'link' => '#' . $secondary_nav_item->slug );
     183                        $params = array( 'link' => trailingslashit( $secondary_nav_item->link ) . $secondary_nav_item->slug );
    183184
    184185                        // Make sure Admins won't write a messages from the user's account.
    185186                        if ( 'compose' === $secondary_nav_item->slug ) {
    function bp_nouveau_messages_adjust_admin_nav( $admin_nav ) { 
    208209                        if ( 'notices' === $nav_id ) {
    209210                                $admin_nav[ $nav_iterator ]['href'] = esc_url( add_query_arg( array( 'page' => 'bp-notices' ), bp_get_admin_url( 'users.php' ) ) );
    210211                        } else {
    211                                 $admin_nav[ $nav_iterator ]['href'] = $user_messages_link . '#' . trim( $nav_id );
     212                                $admin_nav[ $nav_iterator ]['href'] = trailingslashit( $user_messages_link ) . trim( $nav_id );
    212213                        }
    213214                }
    214215        }
    function bp_nouveau_messages_notification_filters() { 
    444445                )
    445446        );
    446447}
     448
     449/**
     450 * Avoid canonical redirects for the User's private message screens
     451 *
     452 * @since  3.0.1
     453 *
     454 * @param  boolean $redirect True to redirect to canonical url. False otherwise.
     455 * @return boolean           True to redirect to canonical url. False otherwise.
     456 */
     457function bp_nouveau_messages_no_canonical_redirect( $redirect = true ) {
     458        if ( bp_is_user() && bp_is_current_component( 'messages' ) ) {
     459                $redirect = false;
     460        }
     461
     462        return $redirect;
     463}
  • src/bp-templates/bp-nouveau/includes/messages/loader.php

    diff --git src/bp-templates/bp-nouveau/includes/messages/loader.php src/bp-templates/bp-nouveau/includes/messages/loader.php
    index a041f2f6b..58697643a 100644
    class BP_Nouveau_Messages { 
    103103
    104104                // Messages
    105105                add_filter( 'bp_messages_admin_nav', 'bp_nouveau_messages_adjust_admin_nav', 10, 1 );
     106                add_filter( 'bp_do_redirect_canonical', 'bp_nouveau_messages_no_canonical_redirect', 10, 1 );
    106107        }
    107108}
    108109
  • src/bp-templates/bp-nouveau/js/buddypress-messages.js

    diff --git src/bp-templates/bp-nouveau/js/buddypress-messages.js src/bp-templates/bp-nouveau/js/buddypress-messages.js
    index 7c1ad32d4..2017e713b 100644
    window.bp = window.bp || {}; 
    3737
    3838                        this.setupNav();
    3939
    40                         Backbone.history.start();
     40                        Backbone.history.start( {
     41                                pushState: true,
     42                                root: BP_Nouveau.messages.rootUrl
     43                        } );
    4144                },
    4245
    4346                setupNav: function() {