Skip to:
Content

BuddyPress.org

Ticket #7840: 7840.pushState.2.patch

File 7840.pushState.2.patch, 4.3 KB (added by imath, 3 years ago)
  • src/bp-core/classes/class-bp-component.php

    diff --git src/bp-core/classes/class-bp-component.php src/bp-core/classes/class-bp-component.php
    index e610cace6..52d8d0a01 100644
    class BP_Component { 
    476476         *
    477477         * @since 2.1.0
    478478         */
    479         public function setup_canonical_stack() {}
     479        public function setup_canonical_stack() {
     480                /**
     481                 * Fires at the end of the setup_canonical_stack method inside BP_Component.
     482                 *
     483                 * This is a dynamic hook that is based on the component string ID.
     484                 *
     485                 * @since 3.0.1
     486                 */
     487                do_action( 'bp_' . $this->id . '_setup_canonical_stack' );
     488        }
    480489
    481490        /**
    482491         * Set up component navigation.
  • src/bp-members/classes/class-bp-members-component.php

    diff --git src/bp-members/classes/class-bp-members-component.php src/bp-members/classes/class-bp-members-component.php
    index 01659b3a2..6db89412f 100644
    class BP_Members_Component extends BP_Component { 
    277277                                unset( $bp->canonical_stack['component'] );
    278278                        }
    279279                }
     280
     281                parent::setup_canonical_stack();
    280282        }
    281283
    282284        /**
  • 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..2fdf5057c 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 * Make sure no trailing slash is added to the User's private message action URLs.
     451 *
     452 * @since  3.0.1
     453 */
     454function bp_nouveau_messages_adjust_url() {
     455        $bp = buddypress();
     456
     457        if ( bp_is_user() && bp_is_current_component( 'messages' ) && ! isset($bp->canonical_stack['canonical_url'] ) && bp_current_action() ) {
     458                $bp->canonical_stack['canonical_url'] = join( '/', array_map( 'untrailingslashit', $bp->canonical_stack ) );
     459        }
     460}
  • 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..575747a59 100644
    class BP_Nouveau_Messages { 
    7171
    7272                // Messages
    7373                add_action( 'bp_messages_setup_nav', 'bp_nouveau_messages_adjust_nav' );
     74                add_action( 'bp_members_setup_canonical_stack', 'bp_nouveau_messages_adjust_url' );
    7475
    7576                // Remove deprecated scripts
    7677                remove_action( 'bp_enqueue_scripts', 'messages_add_autocomplete_js' );
  • 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() {