Skip to:
Content

bbPress.org

Ticket #3576: 3576.2.patch

File 3576.2.patch, 28.1 KB (added by imath, 13 months ago)

Fixes broken pagination

  • src/includes/core/actions.php

    diff --git src/includes/core/actions.php src/includes/core/actions.php
    index 74adfe98..bb5b0ebe 100644
    add_action( 'bbp_footer', 'bbp_swap_no_js_body_class' ); 
    143143add_action( 'bbp_ready',  'bbp_setup_akismet',    2  ); // Spam prevention for topics and replies
    144144
    145145// Setup BuddyPress using its own hook
    146 add_action( 'bp_include', 'bbp_setup_buddypress', 10 ); // Social network integration
     146add_action( 'bp_loaded', 'bbp_setup_buddypress', 1 ); // Social network integration
    147147
    148148// Try to load the bbpress-functions.php file from the active themes
    149149add_action( 'bbp_after_setup_theme', 'bbp_load_theme_functions', 10 );
  • src/includes/core/extend.php

    diff --git src/includes/core/extend.php src/includes/core/extend.php
    index 7524cce5..ca03957e 100644
    function bbp_setup_akismet() { 
    3939        bbpress()->extend->akismet = new BBP_Akismet();
    4040}
    4141
     42/**
     43 * Loads the Forums BP Component.
     44 *
     45 * @since 2.6.10
     46 */
     47function bbp_setup_buddypress_component() {
     48        // Include the BuddyPress Component
     49        require_once bbpress()->includes_dir . 'extend/buddypress/loader.php';
     50
     51        buddypress()->forums = new BBP_Forums_Component();
     52
     53        // Instantiate BuddyPress for bbPress
     54        bbpress()->extend->buddypress = buddypress()->forums;
     55}
     56
    4257/**
    4358 * Requires and creates the BuddyPress extension, and adds component creation
    4459 * action to bp_init hook. @see bbp_setup_buddypress_component()
    4560 *
    4661 * @since 2.0.0 bbPress (r3395)
    4762 *
    48  * @return If BuddyPress is not active
     63 * @return false If BuddyPress is not active
    4964 */
    5065function bbp_setup_buddypress() {
    5166
    function bbp_setup_buddypress() { 
    6883                return;
    6984        }
    7085
    71         // Include the BuddyPress Component
    72         require_once bbpress()->includes_dir . 'extend/buddypress/loader.php';
    73 
    74         // Instantiate BuddyPress for bbPress
    75         bbpress()->extend->buddypress = new BBP_Forums_Component();
     86        add_action( 'bp_setup_components', 'bbp_setup_buddypress_component', 7 );
    7687}
  • src/includes/extend/buddypress/functions.php

    diff --git src/includes/extend/buddypress/functions.php src/includes/extend/buddypress/functions.php
    index b5bcc781..1b6710a5 100644
    add_filter( 'bbp_is_user_home', 'bbp_filter_is_user_home', 10, 1 ); 
    2020add_action( 'load-settings_page_bbpress', 'bbp_maybe_create_group_forum_root' );
    2121add_action( 'bbp_delete_forum',           'bbp_maybe_delete_group_forum_root' );
    2222
     23
     24/** BuddyPress Links **********************************************************/
     25
     26/**
     27 * Returns a BP member's URL according to their ID for BuddyPress >= 12.0 & < 12.0.
     28 *
     29 * @since 2.6.10
     30 *
     31 * @param integer $user_id     The user ID.
     32 * @param array   $path_chunks A list of URL chunks to add to the user's URL.
     33 * @return string              The BP member's URL.
     34 */
     35function bbp_get_user_url( $user_id = 0, $path_chunks = array() ) {
     36        $url = '';
     37        if ( function_exists( 'bp_core_get_query_parser' ) ) {
     38                $url = bp_members_get_user_url( $user_id, bp_members_get_path_chunks( $path_chunks ) );
     39        } else {
     40                $url = bp_core_get_user_domain( $user_id );
     41
     42                if ( $path_chunks ) {
     43                        $action_variables = end( $path_chunks );
     44                        if ( is_array( $action_variables ) ) {
     45                                array_pop( $path_chunks );
     46                                $path_chunks = array_merge( $path_chunks, $action_variables );
     47                        }
     48
     49                        $url .= trailingslashit( implode( '/', $path_chunks ) );
     50                }
     51        }
     52
     53        return $url;
     54}
     55
     56/**
     57 * Returns a BP group's URL according to their ID for BuddyPress >= 12.0 & < 12.0.
     58 *
     59 * @since 2.6.10
     60 *
     61 * @param BP_Groups_Group $group       The group object.
     62 * @param array           $path_chunks A list of URL chunks to add to the group's URL.
     63 * @param string          $context     Whether the URL should be generated for the `admin` context or not.
     64 * @return string                      The BP member's URL.
     65 */
     66function bbp_get_group_url( $group = null, $path_chunks = array(), $context = '' ) {
     67        $url = '';
     68
     69        // BuddyPress 12.0 & up.
     70        if ( function_exists( 'bp_core_get_query_parser' ) ) {
     71                if ( 'admin' === $context ) {
     72                        $url = bp_get_group_manage_url(
     73                                $group,
     74                                bp_groups_get_path_chunks( $path_chunks, 'manage' )
     75                        );
     76                } else {
     77                        $url = bp_get_group_url(
     78                                $group,
     79                                bp_groups_get_path_chunks( $path_chunks )
     80                        );
     81                }
     82
     83                // BuddyPress < 12.0.
     84        } else {
     85                if ( 'admin' === $context ) {
     86                        $url = trailingslashit( bp_get_group_admin_permalink( $group ) );
     87                } else {
     88                        $url = trailingslashit( bp_get_group_permalink( $group ) );
     89                }
     90
     91                if ( $path_chunks ) {
     92                        $action_variables = end( $path_chunks );
     93                        if ( is_array( $action_variables ) ) {
     94                                array_pop( $path_chunks );
     95                                $path_chunks = array_merge( $path_chunks, $action_variables );
     96                        }
     97
     98                        $url .= trailingslashit( implode( '/', $path_chunks ) );
     99                }
     100        }
     101
     102        return $url;
     103}
     104
    23105/** BuddyPress Helpers ********************************************************/
    24106
    25107/**
  • src/includes/extend/buddypress/groups.php

    diff --git src/includes/extend/buddypress/groups.php src/includes/extend/buddypress/groups.php
    index 147486de..7ca1c08e 100644
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    3333         * @since 2.1.0 bbPress (r3552)
    3434         */
    3535        public function __construct() {
    36                 $this->setup_variables();
     36                parent::init(
     37                        array(
     38                                'slug'              => 'forum',
     39                                'name'              => esc_html__( 'Forum', 'bbpress' ),
     40                                'nav_item_name'     => esc_html__( 'Forum', 'bbpress' ),
     41                                'visibility'        => 'public',
     42                                'nav_item_position' => 10,
     43                                'enable_nav_item'   => true,
     44                                'template_file'     => 'groups/single/plugins',
     45                                'display_hook'      => 'bp_template_content',
     46                                'screens'           => array(
     47                                        'create' => array(
     48                                                'position'             => 15,
     49                                                'enabled'              => true,
     50                                                'screen_callback'      => array( $this, 'create_screen' ),
     51                                                'screen_save_callback' => array( $this, 'create_screen_save' ),
     52                                        ),
     53                                        'edit'   => array(
     54                                                'enabled'              => true,
     55                                                'screen_callback'      => array( $this, 'edit_screen' ),
     56                                                'screen_save_callback' => array( $this, 'edit_screen_save' ),
     57                                        ),
     58                                ),
     59                                'show_tab_callback' => array( $this, 'show_tab' ),
     60                        )
     61                );
     62
     63                // Component slugs (hardcoded to match bbPress 1.x functionality)
     64                $this->slug       = 'forum';
     65                $this->topic_slug = 'topic';
     66                $this->reply_slug = 'reply';
     67
    3768                $this->setup_actions();
    3869                $this->setup_filters();
    39                 $this->maybe_unset_forum_menu();
    4070                $this->fully_loaded();
    4171        }
    4272
    4373        /**
    44          * Setup the group forums class variables
     74         * Only set the group forum nav item if group does have a forum.
    4575         *
    46          * @since 2.1.0 bbPress (r3552)
     76         * @since 2.6.10
     77         *
     78         * @return string 'anyone' or 'member' if group does have a forum. 'noone' otherwise.
    4779         */
    48         private function setup_variables() {
    49 
    50                 // Component Name
    51                 $this->name          = esc_html__( 'Forum', 'bbpress' );
    52                 $this->nav_item_name = esc_html__( 'Forum', 'bbpress' );
    53 
    54                 // Component slugs (hardcoded to match bbPress 1.x functionality)
    55                 $this->slug          = 'forum';
    56                 $this->topic_slug    = 'topic';
    57                 $this->reply_slug    = 'reply';
    58 
    59                 // Forum component is visible
    60                 $this->visibility = 'public';
     80        public function show_tab() {
     81                $visibility = 'noone';
     82
     83                $current_group = groups_get_current_group();
     84                if ( $current_group && groups_get_groupmeta( $current_group->id, 'forum_id' ) ) {
     85                        switch ( $current_group->status ) {
     86                                case 'public':
     87                                        $visibility = 'anyone';
     88                                        break;
    6189
    62                 // Set positions towards end
    63                 $this->create_step_position = 15;
    64                 $this->nav_item_position    = 10;
     90                                default:
     91                                        $visibility = 'member';
     92                                        break;
     93                        }
     94                }
    6595
    66                 // Allow create step and show in nav
    67                 $this->enable_create_step   = true;
    68                 $this->enable_nav_item      = true;
    69                 $this->enable_edit_item     = true;
     96                return $visibility;
     97        }
    7098
    71                 // Template file to load, and action to hook display on to
    72                 $this->template_file        = 'groups/single/plugins';
    73                 $this->display_hook         = 'bp_template_content';
     99        /**
     100         * Maybe unset the group forum nav item if group does not have a forum.
     101         *
     102         * @since 2.3.0 bbPress (r4552)
     103         * @deprecated 2.6.10
     104         *
     105         * @return boolean False if not viewing a single group.
     106         */
     107        public function maybe_unset_forum_menu() {
     108                _deprecated_function( __METHOD__, '2.6.10' );
     109                return ! $this->show_group_tab();
    74110        }
    75111
    76112        /**
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    232268                $this->display_forums( 0 );
    233269        }
    234270
    235         /**
    236          * Maybe unset the group forum nav item if group does not have a forum
    237          *
    238          * @since 2.3.0 bbPress (r4552)
    239          *
    240          * @return If not viewing a single group
    241          */
    242         public function maybe_unset_forum_menu() {
    243 
    244                 // Bail if not viewing a single group
    245                 if ( ! bp_is_group() ) {
    246                         return;
    247                 }
    248 
    249                 // Are forums enabled for this group?
    250                 $checked = bp_get_new_group_enable_forum() || groups_get_groupmeta( bp_get_new_group_id(), 'forum_id' );
    251 
    252                 // Tweak the nav item variable based on if group has forum or not
    253                 $this->enable_nav_item = (bool) $checked;
    254         }
    255 
    256271        /**
    257272         * Allow group members to have advanced privileges in group forum topics.
    258273         *
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    613628
    614629                // Redirect after save when not in admin
    615630                if ( ! is_admin() ) {
    616                         bp_core_redirect( trailingslashit( bp_get_group_permalink( buddypress()->groups->current_group ) . '/admin/' . $this->slug ) );
     631                        bp_core_redirect( bbp_get_group_url( groups_get_current_group(), array( $this->slug ), 'admin' ) );
    617632                }
    618633        }
    619634
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    12691284                if ( bp_is_group() ) {
    12701285                        $topic        = bbp_get_topic( $topic_id );
    12711286                        $topic_hash   = '#post-' . $topic_id;
    1272                         $redirect_url = trailingslashit( bp_get_group_permalink( groups_get_current_group() ) ) . trailingslashit( $this->slug ) . trailingslashit( $this->topic_slug ) . trailingslashit( $topic->post_name ) . $topic_hash;
     1287                        $redirect_url = trailingslashit(
     1288                                bbp_get_group_url(
     1289                                        groups_get_current_group(),
     1290                                        array( $this->slug, $this->topic_slug, $topic->post_name )
     1291                                )
     1292                        );
     1293
     1294                        $redirect_url .= $topic_hash;
    12731295                }
    12741296
    12751297                return $redirect_url;
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    12881310                        $reply_position = bbp_get_reply_position( $reply_id, $topic_id );
    12891311                        $reply_page     = ceil( (int) $reply_position / (int) bbp_get_replies_per_page() );
    12901312                        $reply_hash     = '#post-' . $reply_id;
    1291                         $topic_url      = trailingslashit( bp_get_group_permalink( groups_get_current_group() ) ) . trailingslashit( $this->slug ) . trailingslashit( $this->topic_slug ) . trailingslashit( $topic->post_name );
    1292 
    1293                         // Don't include pagination if on first page
    1294                         if ( 1 >= $reply_page ) {
    1295                                 $redirect_url = trailingslashit( $topic_url ) . $reply_hash;
     1313                        $reply_url_args = array( $this->slug, $this->topic_slug, $topic->post_name );
    12961314
    1297                         // Include pagination
    1298                         } else {
    1299                                 $redirect_url = trailingslashit( $topic_url ) . trailingslashit( bbp_get_paged_slug() ) . trailingslashit( $reply_page ) . $reply_hash;
     1315                        // Include pagination.
     1316                        if ( 1 < $reply_page ) {
     1317                                array_push( $reply_url_args, bbp_get_paged_slug(), $reply_page );
    13001318                        }
    13011319
     1320                        $redirect_url = bbp_get_group_url( groups_get_current_group(), $reply_url_args ) . $reply_hash;
     1321
    13021322                        // Add topic view query arg back to end if it is set
    13031323                        if ( bbp_get_view_all() ) {
    13041324                                $redirect_url = bbp_add_view_all( $redirect_url );
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    13151335         */
    13161336        public function edit_redirect_to( $redirect_url = '' ) {
    13171337
    1318                 // Get the current group, if there is one
    1319                 $group = groups_get_current_group();
    1320 
    13211338                // If this is a group of any kind, empty out the redirect URL
    13221339                if ( bp_is_group_admin_screen( $this->slug ) ) {
    1323                         $redirect_url = trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/' . $group->slug . '/admin/' . $this->slug );
     1340                        $redirect_url = bbp_get_group_url( groups_get_current_group(), array( $this->slug ), 'admin' );
    13241341                }
    13251342
    13261343                return $redirect_url;
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    14441461        /** Permalink Mappers *****************************************************/
    14451462
    14461463        /**
    1447          * Maybe map a bbPress forum/topic/reply permalink to the corresponding group
     1464         * Maybe map a bbPress forum/topic/reply permalink to the corresponding group.
    14481465         *
    14491466         * @since 2.2.0 bbPress (r4266)
    14501467         *
    1451          * @param int $post_id
    1452          * @return Bail early if not a group forum post
     1468         * @param int    $post_id          The object ID.
     1469         * @param string $url              The original URL.
     1470         * @param array  $additional_chunks URL chunk to add to original URL.
    14531471         * @return string
    14541472         */
    1455         private function maybe_map_permalink_to_group( $post_id = 0, $url = false ) {
     1473        private function maybe_map_permalink_to_group( $post_id = 0, $url = false, $additional_chunks = array() ) {
    14561474
    14571475                switch ( get_post_type( $post_id ) ) {
    14581476
    14591477                        // Reply
    14601478                        case bbp_get_reply_post_type() :
    1461                                 $topic_id = bbp_get_reply_topic_id( $post_id );
    1462                                 $forum_id = bbp_get_reply_forum_id( $post_id );
    1463                                 $url_end  = trailingslashit( $this->reply_slug ) . get_post_field( 'post_name', $post_id );
     1479                                $topic_id   = bbp_get_reply_topic_id( $post_id );
     1480                                $forum_id   = bbp_get_reply_forum_id( $post_id );
     1481                                $url_chunks = array( $this->reply_slug, get_post_field( 'post_name', $post_id ) );
     1482
    14641483                                break;
    14651484
    14661485                        // Topic
    14671486                        case bbp_get_topic_post_type() :
    1468                                 $topic_id = $post_id;
    1469                                 $forum_id = bbp_get_topic_forum_id( $post_id );
    1470                                 $url_end  = trailingslashit( $this->topic_slug ) . get_post_field( 'post_name', $post_id );
     1487                                $topic_id   = $post_id;
     1488                                $forum_id   = bbp_get_topic_forum_id( $post_id );
     1489                                $url_chunks = array( $this->topic_slug, get_post_field( 'post_name', $post_id ) );
    14711490                                break;
    14721491
    14731492                        // Forum
    14741493                        case bbp_get_forum_post_type() :
    1475                                 $forum_id = $post_id;
    1476                                 $url_end  = ''; //get_post_field( 'post_name', $post_id );
     1494                                $forum_id   = $post_id;
     1495                                $url_chunks = array();
    14771496                                break;
    14781497
    14791498                        // Unknown
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    14811500                                return $url;
    14821501                }
    14831502
     1503                if ( $additional_chunks ) {
     1504                        $url_chunks = array_merge( $url_chunks, $additional_chunks );
     1505                }
     1506
    14841507                // Get group ID's for this forum
    14851508                $group_ids = bbp_get_forum_group_ids( $forum_id );
    14861509
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    14921515                // @todo Multiple group forums/forum groups
    14931516                $group_id = $group_ids[0];
    14941517                $group    = groups_get_group( array( 'group_id' => $group_id ) );
     1518                array_unshift( $url_chunks, $this->slug );
    14951519
    14961520                if ( bp_is_group_admin_screen( $this->slug ) ) {
    1497                         $group_permalink = trailingslashit( bp_get_group_admin_permalink( $group ) );
     1521                        $group_permalink = bbp_get_group_url( $group, $url_chunks, 'admin' );
    14981522                } else {
    1499                         $group_permalink = trailingslashit( bp_get_group_permalink( $group ) );
     1523                        $group_permalink = bbp_get_group_url( $group, $url_chunks );
    15001524                }
    15011525
    1502                 return trailingslashit( trailingslashit( $group_permalink . $this->slug ) . $url_end );
     1526                return $group_permalink;
    15031527        }
    15041528
    15051529        /**
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    15511575         * @return string
    15521576         */
    15531577        public function map_reply_edit_url_to_group( $url, $reply_id ) {
    1554                 $new = $this->maybe_map_permalink_to_group( $reply_id );
     1578                $edit_url = $this->maybe_map_permalink_to_group( $reply_id, $url, array( bbpress()->edit_id ) );
    15551579
    1556                 if ( empty( $new ) ) {
     1580                if ( empty( $edit_url ) ) {
    15571581                        return $url;
    15581582                }
    15591583
    1560                 return trailingslashit( $new ) . bbpress()->edit_id  . '/';
     1584                return $edit_url;
    15611585        }
    15621586
    15631587        /**
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    16121636         * @return array
    16131637         */
    16141638        public function topic_pagination( $args ) {
    1615                 $new = $this->maybe_map_permalink_to_group( bbp_get_forum_id() );
     1639                $pagination_base = $this->maybe_map_permalink_to_group( bbp_get_forum_id(), '', array( bbp_get_paged_slug(), '%#%' ) );
    16161640
    1617                 if ( empty( $new ) ) {
     1641                if ( empty( $pagination_base ) ) {
    16181642                        return $args;
    16191643                }
    16201644
    1621                 $args['base'] = trailingslashit( $new ) . bbp_get_paged_slug() . '/%#%/';
     1645                $args['base'] = $pagination_base;
    16221646
    16231647                return $args;
    16241648        }
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    16321656         * @return array
    16331657         */
    16341658        public function replies_pagination( $args ) {
    1635                 $new = $this->maybe_map_permalink_to_group( bbp_get_topic_id() );
    1636                 if ( empty( $new ) ) {
     1659                $pagination_base = $this->maybe_map_permalink_to_group( bbp_get_topic_id(), '', array( bbp_get_paged_slug(), '%#%' ) );
     1660
     1661                if ( empty( $pagination_base ) ) {
    16371662                        return $args;
    16381663                }
    16391664
    1640                 $args['base'] = trailingslashit( $new ) . bbp_get_paged_slug() . '/%#%/';
     1665                $args['base'] = $pagination_base;
    16411666
    16421667                return $args;
    16431668        }
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    16801705                // Use the first group ID
    16811706                $group_id        = $group_ids[0];
    16821707                $group           = groups_get_group( array( 'group_id' => $group_id ) );
    1683                 $group_link  = trailingslashit( bp_get_group_permalink( $group ) );
    1684                 $redirect_to = trailingslashit( $group_link . $this->slug );
     1708                $url_chunks  = array( $this->slug );
    16851709
    16861710                // Add topic slug to URL
    16871711                if ( bbp_is_single_topic() ) {
    1688                         $redirect_to  = trailingslashit( $redirect_to . $this->topic_slug . '/' . $slug );
     1712                        array_push( $url_chunks, $this->topic_slug, $slug );
    16891713                }
    16901714
    1691                 bp_core_redirect( $redirect_to );
     1715                bp_core_redirect( bbp_get_group_url( $group, $url_chunks ) );
    16921716        }
    16931717
    16941718        /** Activity **************************************************************/
  • src/includes/extend/buddypress/loader.php

    diff --git src/includes/extend/buddypress/loader.php src/includes/extend/buddypress/loader.php
    index 1e0d59eb..cd1b9006 100644
    if ( ! class_exists( 'BBP_Forums_Component' ) ) : 
    3030 * @subpackage BuddyPress
    3131 */
    3232class BBP_Forums_Component extends BP_Component {
     33        /**
     34         * Member profile modifications.
     35         *
     36         * @var null|BBP_BuddyPress_Members
     37         */
     38        public $members = null;
     39
     40        /**
     41         * BuddyPress Activity extension.
     42         *
     43         * @var null|BBP_BuddyPress_Activity
     44         */
     45        public $activity = null;
    3346
    3447        /**
    3548         * Start the forums component creation process
    class BBP_Forums_Component extends BP_Component { 
    4255                        esc_html__( 'Forums', 'bbpress' ),
    4356                        bbpress()->includes_dir . 'extend/buddypress/'
    4457                );
    45                 $this->includes();
    46                 $this->setup_globals();
    47                 $this->setup_actions();
     58
    4859                $this->fully_loaded();
    4960        }
    5061
    class BBP_Forums_Component extends BP_Component { 
    5263         * Include BuddyPress classes and functions
    5364         */
    5465        public function includes( $includes = array() ) {
     66                $includes = array(
     67                        // Helper BuddyPress functions.
     68                        'functions.php',
    5569
    56                 // Helper BuddyPress functions
    57                 $includes[] = 'functions.php';
    58 
    59                 // Members modifications
    60                 $includes[] = 'members.php';
     70                        // Members modifications.
     71                        'members.php',
     72                );
    6173
    6274                // BuddyPress Notfications Extension functions
    6375                if ( bp_is_active( 'notifications' ) ) {
    class BBP_Forums_Component extends BP_Component { 
    7486                        $includes[] = 'groups.php';
    7587                }
    7688
    77                 // Require files if they exist
    78                 foreach ( $includes as $file ) {
    79                         if ( @is_file( $this->path . $file ) ) {
    80                                 require $this->path . $file;
    81                         }
    82                 }
    83 
    84                 /**
    85                  * Hook for plugins to include files, if necessary.
    86                  *
    87                  * @since 2.6.0 bbPress (r3552)
    88                  */
    89                 do_action( "bp_{$this->id}_includes" );
     89                parent::includes( $includes );
    9090        }
    9191
    9292        /**
    class BBP_Forums_Component extends BP_Component { 
    135135                // Setup the components
    136136                add_action( 'bp_init', array( $this, 'setup_components' ), 7 );
    137137
     138                // Adjust `WP_Query` paged var.
     139                add_action( 'bp_members_parse_query', array( $this, 'setup_pagination' ) );
     140                add_action( 'bp_groups_parse_query',  array( $this, 'setup_pagination' ) );
     141
    138142                parent::setup_actions();
    139143        }
    140144
    class BBP_Forums_Component extends BP_Component { 
    159163                }
    160164        }
    161165
     166        /**
     167         * Adjusts the `WP_Query` paged var.
     168         *
     169         * @since 2.6.10
     170         *
     171         * @param WP_Query $query The WP Query pasded by reference.
     172         */
     173        public function setup_pagination( &$query ) {
     174                if ( ( bp_is_user() && bp_is_current_component( 'forums' ) ) || ( bp_is_group() && bp_is_current_action( 'forum' ) ) ) {
     175                        $action_variables = (array) bp_action_variables();
     176                        $is_paged         = array_search( bbp_get_paged_slug(), $action_variables, true );
     177
     178                        if ( false !== $is_paged ) {
     179                                $query->set( 'paged', (int) bp_action_variable( $is_paged + 1 ) );
     180                        }
     181                }
     182        }
     183
    162184        /**
    163185         * Allow the variables, actions, and filters to be modified by third party
    164186         * plugins and themes.
    class BBP_Forums_Component extends BP_Component { 
    170192        }
    171193
    172194        /**
    173          * Setup BuddyBar navigation
     195         * Register component navigation.
    174196         *
    175          * @since 2.1.0 bbPress (r3552)
     197         * @since 2.6.10
     198         *
     199         * @see `BP_Component::register_nav()` for a description of arguments.
     200         *
     201         * @param array $main_nav Optional. See `BP_Component::register_nav()` for
     202         *                        description.
     203         * @param array $sub_nav  Optional. See `BP_Component::register_nav()` for
     204         *                        description.
    176205         */
    177         public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    178 
    179                 // Stop if there is no user displayed or logged in
    180                 if ( ! is_user_logged_in() && !bp_displayed_user_id() ) {
    181                         return;
    182                 }
    183 
    184                 // Define local variable(s)
    185                 $user_domain = '';
     206        public function register_nav( $main_nav = array(), $sub_nav = array() ) {
    186207
    187208                // Add 'Forums' to the main navigation
    188209                $main_nav = array(
    class BBP_Forums_Component extends BP_Component { 
    194215                        'item_css_id'         => $this->id
    195216                );
    196217
    197                 // Determine user to use
    198                 if ( bp_displayed_user_id() ) {
    199                         $user_domain = bp_displayed_user_domain();
    200                 } elseif ( bp_loggedin_user_domain() ) {
    201                         $user_domain = bp_loggedin_user_domain();
    202                 } else {
    203                         return;
    204                 }
    205 
    206                 // User link
    207                 $forums_link = trailingslashit( $user_domain . $this->slug );
    208 
    209218                // Topics started
    210219                $sub_nav[] = array(
    211220                        'name'            => esc_html__( 'Topics Started', 'bbpress' ),
    212221                        'slug'            => bbp_get_topic_archive_slug(),
    213                         'parent_url'      => $forums_link,
    214222                        'parent_slug'     => $this->slug,
    215223                        'screen_function' => 'bbp_member_forums_screen_topics',
    216224                        'position'        => 20,
    class BBP_Forums_Component extends BP_Component { 
    221229                $sub_nav[] = array(
    222230                        'name'            => esc_html__( 'Replies Created', 'bbpress' ),
    223231                        'slug'            => bbp_get_reply_archive_slug(),
    224                         'parent_url'      => $forums_link,
    225232                        'parent_slug'     => $this->slug,
    226233                        'screen_function' => 'bbp_member_forums_screen_replies',
    227234                        'position'        => 40,
    class BBP_Forums_Component extends BP_Component { 
    233240                        $sub_nav[] = array(
    234241                                'name'            => esc_html__( 'Engagements', 'bbpress' ),
    235242                                'slug'            => bbp_get_user_engagements_slug(),
    236                                 'parent_url'      => $forums_link,
    237243                                'parent_slug'     => $this->slug,
    238244                                'screen_function' => 'bbp_member_forums_screen_engagements',
    239245                                'position'        => 60,
    class BBP_Forums_Component extends BP_Component { 
    246252                        $sub_nav[] = array(
    247253                                'name'            => esc_html__( 'Favorites', 'bbpress' ),
    248254                                'slug'            => bbp_get_user_favorites_slug(),
    249                                 'parent_url'      => $forums_link,
    250255                                'parent_slug'     => $this->slug,
    251256                                'screen_function' => 'bbp_member_forums_screen_favorites',
    252257                                'position'        => 80,
    class BBP_Forums_Component extends BP_Component { 
    255260                }
    256261
    257262                // Subscribed topics (my profile only)
    258                 if ( bp_is_my_profile() && bbp_is_subscriptions_active() ) {
     263                if ( bbp_is_subscriptions_active() ) {
    259264                        $sub_nav[] = array(
    260                                 'name'            => esc_html__( 'Subscriptions', 'bbpress' ),
    261                                 'slug'            => bbp_get_user_subscriptions_slug(),
    262                                 'parent_url'      => $forums_link,
    263                                 'parent_slug'     => $this->slug,
    264                                 'screen_function' => 'bbp_member_forums_screen_subscriptions',
    265                                 'position'        => 100,
    266                                 'item_css_id'     => 'subscriptions'
     265                                'name'                     => esc_html__( 'Subscriptions', 'bbpress' ),
     266                                'slug'                     => bbp_get_user_subscriptions_slug(),
     267                                'parent_slug'              => $this->slug,
     268                                'screen_function'          => 'bbp_member_forums_screen_subscriptions',
     269                                'position'                 => 100,
     270                                'item_css_id'              => 'subscriptions',
     271                                'user_has_access'          => false,
     272                                'user_has_access_callback' => 'bp_is_my_profile',
    267273                        );
    268274                }
    269275
     276                if ( method_exists( get_parent_class( $this ), 'register_nav' ) ) {
     277                        parent::register_nav( $main_nav, $sub_nav );
     278
     279                } else {
     280                        return array(
     281                                'main_nav' => $main_nav,
     282                                'sub_nav'  => $sub_nav,
     283                        );
     284                }
     285        }
     286
     287        /**
     288         * Setup BuddyBar navigation
     289         *
     290         * @since 2.1.0 bbPress (r3552)
     291         */
     292        public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
     293                if ( ! method_exists( get_parent_class( $this ), 'register_nav' ) ) {
     294                        $nav = $this->register_nav();
     295
     296                        // Define local variable(s)
     297                        $user_id = 0;
     298
     299                        // Determine user to use
     300                        if ( bp_displayed_user_id() ) {
     301                                $user_id = bp_displayed_user_id();
     302                        } elseif ( bp_loggedin_user_id() ) {
     303                                $user_id = bp_loggedin_user_id();
     304                        } else {
     305                                return;
     306                        }
     307
     308                        // User link
     309                        $forums_link = bbp_get_user_url( $user_id, array( $this->slug ) );
     310
     311                        // The parent URL is only necessary when BP < 12.0
     312                        foreach ( $nav['sub_nav'] as $key_sub_nav => $data_sub_nav ) {
     313                                if ( isset( $data_sub_nav['user_has_access_callback'] ) ) {
     314                                        $data_sub_nav['user_has_access'] = call_user_func( $data_sub_nav['user_has_access_callback'] );
     315                                        unset( $data_sub_nav['user_has_access_callback'] );
     316                                }
     317
     318                                $data_sub_nav['parent_url']     = $forums_link;
     319                                $nav['sub_nav'][ $key_sub_nav ] = $data_sub_nav;
     320                        }
     321
     322                        $main_nav = $nav['main_nav'];
     323                        $sub_nav  = $nav['sub_nav'];
     324                }
     325
    270326                parent::setup_nav( $main_nav, $sub_nav );
    271327        }
    272328
    class BBP_Forums_Component extends BP_Component { 
    293349                        } else {
    294350
    295351                                // Setup the logged in user variables
    296                                 $user_domain = bp_loggedin_user_domain();
    297                                 $forums_link = trailingslashit( $user_domain . $this->slug );
    298 
    299                                 $my_account_link       = trailingslashit( $forums_link );
    300                                 $my_topics_link        = trailingslashit( $forums_link . bbp_get_topic_archive_slug() );
    301                                 $my_replies_link       = trailingslashit( $forums_link . bbp_get_reply_archive_slug() );
    302                                 $my_engagements_link   = trailingslashit( $forums_link . bbp_get_user_engagements_slug() );
    303                                 $my_favorites_link     = trailingslashit( $forums_link . bbp_get_user_favorites_slug() );
    304                                 $my_subscriptions_link = trailingslashit( $forums_link . bbp_get_user_subscriptions_slug() );
     352                                $user_id = bp_loggedin_user_id();
     353
     354                                $my_account_link       = bbp_get_user_url( $user_id, array( $this->slug ) );
     355                                $my_topics_link        = bbp_get_user_url( $user_id, array( $this->slug, bbp_get_topic_archive_slug() ) );
     356                                $my_replies_link       = bbp_get_user_url( $user_id, array( $this->slug, bbp_get_reply_archive_slug() ) );
     357                                $my_engagements_link   = bbp_get_user_url( $user_id, array( $this->slug, bbp_get_user_engagements_slug() ) );
     358                                $my_favorites_link     = bbp_get_user_url( $user_id, array( $this->slug, bbp_get_user_favorites_slug() ) );
     359                                $my_subscriptions_link = bbp_get_user_url( $user_id, array( $this->slug, bbp_get_user_subscriptions_slug() ) );
    305360                        }
    306361
    307362                        // Add the "My Account" sub menus
  • src/includes/extend/buddypress/members.php

    diff --git src/includes/extend/buddypress/members.php src/includes/extend/buddypress/members.php
    index ddeb5cdc..79926c6f 100644
    class BBP_BuddyPress_Members { 
    225225                        return false;
    226226                }
    227227
    228                 // Setup profile URL
    229                 $url = array( bp_core_get_user_domain( $user_id ) );
     228                // Init URL chunks.
     229                $path_chunks = array();
    230230
    231231                // Maybe push slug to end of URL array
    232232                if ( ! empty( $slug ) ) {
    233                         array_push( $url, bbpress()->extend->buddypress->slug );
    234                         array_push( $url, $slug );
     233                        $path_chunks = array( bbpress()->extend->buddypress->slug, $slug );
    235234                }
    236235
    237236                // Return
    238                 return implode( '', array_map( 'trailingslashit', $url ) );
     237                return bbp_get_user_url( $user_id, $path_chunks );
    239238        }
    240239}
    241240endif;