Skip to:
Content

bbPress.org

Ticket #3576: 3576.patch

File 3576.patch, 27.2 KB (added by imath, 20 months ago)
  • 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..c5f6f5c4 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                $args = array(
     37                        'slug'              => 'forum',
     38                        'name'              => esc_html__( 'Forum', 'bbpress' ),
     39                        'nav_item_name'     => esc_html__( 'Forum', 'bbpress' ),
     40                        'visibility'        => 'public',
     41                        'nav_item_position' => 10,
     42                        'enable_nav_item'   => true,
     43                        'template_file'     => 'groups/single/plugins',
     44                        'display_hook'      => 'bp_template_content',
     45                        'screens'           => array(
     46                                'create' => array(
     47                                        'position'             => 15,
     48                                        'enabled'              => true,
     49                                        'screen_callback'      => array( $this, 'create_screen' ),
     50                                        'screen_save_callback' => array( $this, 'create_screen_save' ),
     51                                ),
     52                                'edit'   => array(
     53                                        'enabled'              => true,
     54                                        'screen_callback'      => array( $this, 'edit_screen' ),
     55                                        'screen_save_callback' => array( $this, 'edit_screen_save' ),
     56                                ),
     57                        ),
     58                );
     59
     60                // BuddyPress 12.0 & up.
     61                if ( function_exists( 'bp_core_get_query_parser' ) && 'rewrites' === bp_core_get_query_parser() ) {
     62                        $args['show_tab']          = 'noone';
     63                        $args['show_tab_callback'] = array( $this, 'show_tab' );
     64
     65                        // BuddyPress < 12.0 or BuddyPress 12.0 with the BP Classic plugin active.
     66                } else {
     67                        $args['show_tab'] = $this->show_tab();
     68                }
     69
     70                parent::init( $args );
     71
     72                // Component slugs (hardcoded to match bbPress 1.x functionality)
     73                $this->slug       = 'forum';
     74                $this->topic_slug = 'topic';
     75                $this->reply_slug = 'reply';
     76
    3777                $this->setup_actions();
    3878                $this->setup_filters();
    39                 $this->maybe_unset_forum_menu();
    4079                $this->fully_loaded();
    4180        }
    4281
    4382        /**
    44          * Setup the group forums class variables
     83         * Only set the group forum nav item if group does have a forum.
    4584         *
    46          * @since 2.1.0 bbPress (r3552)
     85         * @since 2.6.10
     86         *
     87         * @param  int    $group_id The current Group ID.
     88         * @return string           'anyone' or 'member' if group does have a forum. 'noone' otherwise.
    4789         */
    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' );
     90        public function show_tab( $group_id = '' ) {
     91                $visibility = 'noone';
     92                $group      = null;
    5393
    54                 // Component slugs (hardcoded to match bbPress 1.x functionality)
    55                 $this->slug          = 'forum';
    56                 $this->topic_slug    = 'topic';
    57                 $this->reply_slug    = 'reply';
     94                if ( ! $group_id ) {
     95                        $group = groups_get_current_group();
     96                } else {
     97                        $group = bp_get_group( $group_id );
     98                }
    5899
    59                 // Forum component is visible
    60                 $this->visibility = 'public';
     100                if ( $group && groups_get_groupmeta( $group->id, 'forum_id' ) ) {
     101                        switch ( $group->status ) {
     102                                case 'public':
     103                                        $visibility = 'anyone';
     104                                        break;
    61105
    62                 // Set positions towards end
    63                 $this->create_step_position = 15;
    64                 $this->nav_item_position    = 10;
     106                                default:
     107                                        $visibility = 'member';
     108                                        break;
     109                        }
     110                }
    65111
    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;
     112                return $visibility;
     113        }
    70114
    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';
     115        /**
     116         * Maybe unset the group forum nav item if group does not have a forum.
     117         *
     118         * @since 2.3.0 bbPress (r4552)
     119         * @deprecated 2.6.10
     120         *
     121         * @return boolean False if not viewing a single group.
     122         */
     123        public function maybe_unset_forum_menu() {
     124                _deprecated_function( __METHOD__, '2.6.10' );
     125                return ! $this->show_group_tab();
    74126        }
    75127
    76128        /**
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    232284                $this->display_forums( 0 );
    233285        }
    234286
    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 
    256287        /**
    257288         * Allow group members to have advanced privileges in group forum topics.
    258289         *
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    613644
    614645                // Redirect after save when not in admin
    615646                if ( ! is_admin() ) {
    616                         bp_core_redirect( trailingslashit( bp_get_group_permalink( buddypress()->groups->current_group ) . '/admin/' . $this->slug ) );
     647                        bp_core_redirect( bbp_get_group_url( groups_get_current_group(), array( $this->slug ), 'admin' ) );
    617648                }
    618649        }
    619650
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    12691300                if ( bp_is_group() ) {
    12701301                        $topic        = bbp_get_topic( $topic_id );
    12711302                        $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;
     1303                        $redirect_url = trailingslashit(
     1304                                bbp_get_group_url(
     1305                                        groups_get_current_group(),
     1306                                        array( $this->slug, $this->topic_slug, $topic->post_name )
     1307                                )
     1308                        );
     1309
     1310                        $redirect_url .= $topic_hash;
    12731311                }
    12741312
    12751313                return $redirect_url;
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    12881326                        $reply_position = bbp_get_reply_position( $reply_id, $topic_id );
    12891327                        $reply_page     = ceil( (int) $reply_position / (int) bbp_get_replies_per_page() );
    12901328                        $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;
     1329                        $reply_url_args = array( $this->slug, $this->topic_slug, $topic->post_name );
    12961330
    1297                         // Include pagination
    1298                         } else {
    1299                                 $redirect_url = trailingslashit( $topic_url ) . trailingslashit( bbp_get_paged_slug() ) . trailingslashit( $reply_page ) . $reply_hash;
     1331                        // Include pagination.
     1332                        if ( 1 < $reply_page ) {
     1333                                array_push( $reply_url_args, bbp_get_paged_slug(), $reply_page );
    13001334                        }
    13011335
     1336                        $redirect_url = bbp_get_group_url( groups_get_current_group(), $reply_url_args ) . $reply_hash;
     1337
    13021338                        // Add topic view query arg back to end if it is set
    13031339                        if ( bbp_get_view_all() ) {
    13041340                                $redirect_url = bbp_add_view_all( $redirect_url );
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    13151351         */
    13161352        public function edit_redirect_to( $redirect_url = '' ) {
    13171353
    1318                 // Get the current group, if there is one
    1319                 $group = groups_get_current_group();
    1320 
    13211354                // If this is a group of any kind, empty out the redirect URL
    13221355                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 );
     1356                        $redirect_url = bbp_get_group_url( groups_get_current_group(), array( $this->slug ), 'admin' );
    13241357                }
    13251358
    13261359                return $redirect_url;
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    14441477        /** Permalink Mappers *****************************************************/
    14451478
    14461479        /**
    1447          * Maybe map a bbPress forum/topic/reply permalink to the corresponding group
     1480         * Maybe map a bbPress forum/topic/reply permalink to the corresponding group.
    14481481         *
    14491482         * @since 2.2.0 bbPress (r4266)
    14501483         *
    1451          * @param int $post_id
    1452          * @return Bail early if not a group forum post
     1484         * @param int    $post_id          The object ID.
     1485         * @param string $url              The original URL.
     1486         * @param array  $additional_chunks URL chunk to add to original URL.
    14531487         * @return string
    14541488         */
    1455         private function maybe_map_permalink_to_group( $post_id = 0, $url = false ) {
     1489        private function maybe_map_permalink_to_group( $post_id = 0, $url = false, $additional_chunks = array() ) {
    14561490
    14571491                switch ( get_post_type( $post_id ) ) {
    14581492
    14591493                        // Reply
    14601494                        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 );
     1495                                $topic_id   = bbp_get_reply_topic_id( $post_id );
     1496                                $forum_id   = bbp_get_reply_forum_id( $post_id );
     1497                                $url_chunks = array( $this->reply_slug, get_post_field( 'post_name', $post_id ) );
     1498
     1499                                if ( $additional_chunks ) {
     1500                                        $url_chunks = array_merge( $url_chunks, $additional_chunks );
     1501                                }
    14641502                                break;
    14651503
    14661504                        // Topic
    14671505                        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 );
     1506                                $topic_id   = $post_id;
     1507                                $forum_id   = bbp_get_topic_forum_id( $post_id );
     1508                                $url_chunks = array( $this->topic_slug, get_post_field( 'post_name', $post_id ) );
    14711509                                break;
    14721510
    14731511                        // Forum
    14741512                        case bbp_get_forum_post_type() :
    1475                                 $forum_id = $post_id;
    1476                                 $url_end  = ''; //get_post_field( 'post_name', $post_id );
     1513                                $forum_id   = $post_id;
     1514                                $url_chunks = array();
    14771515                                break;
    14781516
    14791517                        // Unknown
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    14921530                // @todo Multiple group forums/forum groups
    14931531                $group_id = $group_ids[0];
    14941532                $group    = groups_get_group( array( 'group_id' => $group_id ) );
     1533                array_unshift( $url_chunks, $this->slug );
    14951534
    14961535                if ( bp_is_group_admin_screen( $this->slug ) ) {
    1497                         $group_permalink = trailingslashit( bp_get_group_admin_permalink( $group ) );
     1536                        $group_permalink = bbp_get_group_url( $group, $url_chunks, 'admin' );
    14981537                } else {
    1499                         $group_permalink = trailingslashit( bp_get_group_permalink( $group ) );
     1538                        $group_permalink = bbp_get_group_url( $group, $url_chunks );
    15001539                }
    15011540
    1502                 return trailingslashit( trailingslashit( $group_permalink . $this->slug ) . $url_end );
     1541                return $group_permalink;
    15031542        }
    15041543
    15051544        /**
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    15511590         * @return string
    15521591         */
    15531592        public function map_reply_edit_url_to_group( $url, $reply_id ) {
    1554                 $new = $this->maybe_map_permalink_to_group( $reply_id );
     1593                $edit_url = $this->maybe_map_permalink_to_group( $reply_id, $url, array( bbpress()->edit_id ) );
    15551594
    1556                 if ( empty( $new ) ) {
     1595                if ( empty( $edit_url ) ) {
    15571596                        return $url;
    15581597                }
    15591598
    1560                 return trailingslashit( $new ) . bbpress()->edit_id  . '/';
     1599                return $edit_url;
    15611600        }
    15621601
    15631602        /**
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    16121651         * @return array
    16131652         */
    16141653        public function topic_pagination( $args ) {
    1615                 $new = $this->maybe_map_permalink_to_group( bbp_get_forum_id() );
     1654                $pagination_base = $this->maybe_map_permalink_to_group( bbp_get_forum_id(), '', array( bbp_get_paged_slug(), '%#%' ) );
    16161655
    1617                 if ( empty( $new ) ) {
     1656                if ( empty( $pagination_base ) ) {
    16181657                        return $args;
    16191658                }
    16201659
    1621                 $args['base'] = trailingslashit( $new ) . bbp_get_paged_slug() . '/%#%/';
     1660                $args['base'] = $pagination_base;
    16221661
    16231662                return $args;
    16241663        }
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    16321671         * @return array
    16331672         */
    16341673        public function replies_pagination( $args ) {
    1635                 $new = $this->maybe_map_permalink_to_group( bbp_get_topic_id() );
    1636                 if ( empty( $new ) ) {
     1674                $pagination_base = $this->maybe_map_permalink_to_group( bbp_get_topic_id(), '', array( bbp_get_paged_slug(), '%#%' ) );
     1675
     1676                if ( empty( $pagination_base ) ) {
    16371677                        return $args;
    16381678                }
    16391679
    1640                 $args['base'] = trailingslashit( $new ) . bbp_get_paged_slug() . '/%#%/';
     1680                $args['base'] = $pagination_base;
    16411681
    16421682                return $args;
    16431683        }
    class BBP_Forums_Group_Extension extends BP_Group_Extension { 
    16801720                // Use the first group ID
    16811721                $group_id        = $group_ids[0];
    16821722                $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 );
     1723                $url_chunks  = array( $this->slug );
    16851724
    16861725                // Add topic slug to URL
    16871726                if ( bbp_is_single_topic() ) {
    1688                         $redirect_to  = trailingslashit( $redirect_to . $this->topic_slug . '/' . $slug );
     1727                        array_push( $url_chunks, $this->topic_slug, $slug );
    16891728                }
    16901729
    1691                 bp_core_redirect( $redirect_to );
     1730                bp_core_redirect( bbp_get_group_url( $group, $url_chunks ) );
    16921731        }
    16931732
    16941733        /** Activity **************************************************************/
  • src/includes/extend/buddypress/loader.php

    diff --git src/includes/extend/buddypress/loader.php src/includes/extend/buddypress/loader.php
    index 1e0d59eb..102fe3aa 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 { 
    170170        }
    171171
    172172        /**
    173          * Setup BuddyBar navigation
     173         * Register component navigation.
    174174         *
    175          * @since 2.1.0 bbPress (r3552)
     175         * @since 2.6.10
     176         *
     177         * @see `BP_Component::register_nav()` for a description of arguments.
     178         *
     179         * @param array $main_nav Optional. See `BP_Component::register_nav()` for
     180         *                        description.
     181         * @param array $sub_nav  Optional. See `BP_Component::register_nav()` for
     182         *                        description.
    176183         */
    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 = '';
     184        public function register_nav( $main_nav = array(), $sub_nav = array() ) {
    186185
    187186                // Add 'Forums' to the main navigation
    188187                $main_nav = array(
    class BBP_Forums_Component extends BP_Component { 
    194193                        'item_css_id'         => $this->id
    195194                );
    196195
    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 
    209196                // Topics started
    210197                $sub_nav[] = array(
    211198                        'name'            => esc_html__( 'Topics Started', 'bbpress' ),
    212199                        'slug'            => bbp_get_topic_archive_slug(),
    213                         'parent_url'      => $forums_link,
    214200                        'parent_slug'     => $this->slug,
    215201                        'screen_function' => 'bbp_member_forums_screen_topics',
    216202                        'position'        => 20,
    class BBP_Forums_Component extends BP_Component { 
    221207                $sub_nav[] = array(
    222208                        'name'            => esc_html__( 'Replies Created', 'bbpress' ),
    223209                        'slug'            => bbp_get_reply_archive_slug(),
    224                         'parent_url'      => $forums_link,
    225210                        'parent_slug'     => $this->slug,
    226211                        'screen_function' => 'bbp_member_forums_screen_replies',
    227212                        'position'        => 40,
    class BBP_Forums_Component extends BP_Component { 
    233218                        $sub_nav[] = array(
    234219                                'name'            => esc_html__( 'Engagements', 'bbpress' ),
    235220                                'slug'            => bbp_get_user_engagements_slug(),
    236                                 'parent_url'      => $forums_link,
    237221                                'parent_slug'     => $this->slug,
    238222                                'screen_function' => 'bbp_member_forums_screen_engagements',
    239223                                'position'        => 60,
    class BBP_Forums_Component extends BP_Component { 
    246230                        $sub_nav[] = array(
    247231                                'name'            => esc_html__( 'Favorites', 'bbpress' ),
    248232                                'slug'            => bbp_get_user_favorites_slug(),
    249                                 'parent_url'      => $forums_link,
    250233                                'parent_slug'     => $this->slug,
    251234                                'screen_function' => 'bbp_member_forums_screen_favorites',
    252235                                'position'        => 80,
    class BBP_Forums_Component extends BP_Component { 
    255238                }
    256239
    257240                // Subscribed topics (my profile only)
    258                 if ( bp_is_my_profile() && bbp_is_subscriptions_active() ) {
     241                if ( bbp_is_subscriptions_active() ) {
    259242                        $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'
     243                                'name'                     => esc_html__( 'Subscriptions', 'bbpress' ),
     244                                'slug'                     => bbp_get_user_subscriptions_slug(),
     245                                'parent_slug'              => $this->slug,
     246                                'screen_function'          => 'bbp_member_forums_screen_subscriptions',
     247                                'position'                 => 100,
     248                                'item_css_id'              => 'subscriptions',
     249                                'user_has_access'          => false,
     250                                'user_has_access_callback' => 'bp_is_my_profile',
     251                        );
     252                }
     253
     254                if ( method_exists( get_parent_class( $this ), 'register_nav' ) ) {
     255                        parent::register_nav( $main_nav, $sub_nav );
     256
     257                } else {
     258                        return array(
     259                                'main_nav' => $main_nav,
     260                                'sub_nav'  => $sub_nav,
    267261                        );
    268262                }
     263        }
     264
     265        /**
     266         * Setup BuddyBar navigation
     267         *
     268         * @since 2.1.0 bbPress (r3552)
     269         */
     270        public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
     271                if ( ! method_exists( get_parent_class( $this ), 'register_nav' ) ) {
     272                        $nav = $this->register_nav();
     273
     274                        // Define local variable(s)
     275                        $user_id = 0;
     276
     277                        // Determine user to use
     278                        if ( bp_displayed_user_id() ) {
     279                                $user_id = bp_displayed_user_id();
     280                        } elseif ( bp_loggedin_user_id() ) {
     281                                $user_id = bp_loggedin_user_id();
     282                        } else {
     283                                return;
     284                        }
     285
     286                        // User link
     287                        $forums_link = bbp_get_user_url( $user_id, array( $this->slug ) );
     288
     289                        // The parent URL is only necessary when BP < 12.0
     290                        foreach ( $nav['sub_nav'] as $key_sub_nav => $data_sub_nav ) {
     291                                if ( isset( $data_sub_nav['user_has_access_callback'] ) ) {
     292                                        $data_sub_nav['user_has_access'] = call_user_func( $data_sub_nav['user_has_access_callback'] );
     293                                        unset( $data_sub_nav['user_has_access_callback'] );
     294                                }
     295
     296                                $data_sub_nav['parent_url']     = $forums_link;
     297                                $nav['sub_nav'][ $key_sub_nav ] = $data_sub_nav;
     298                        }
     299
     300                        $main_nav = $nav['main_nav'];
     301                        $sub_nav  = $nav['sub_nav'];
     302                }
    269303
    270304                parent::setup_nav( $main_nav, $sub_nav );
    271305        }
    class BBP_Forums_Component extends BP_Component { 
    293327                        } else {
    294328
    295329                                // 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() );
     330                                $user_id = bp_loggedin_user_id();
     331
     332                                $my_account_link       = bbp_get_user_url( $user_id, array( $this->slug ) );
     333                                $my_topics_link        = bbp_get_user_url( $user_id, array( $this->slug, bbp_get_topic_archive_slug() ) );
     334                                $my_replies_link       = bbp_get_user_url( $user_id, array( $this->slug, bbp_get_reply_archive_slug() ) );
     335                                $my_engagements_link   = bbp_get_user_url( $user_id, array( $this->slug, bbp_get_user_engagements_slug() ) );
     336                                $my_favorites_link     = bbp_get_user_url( $user_id, array( $this->slug, bbp_get_user_favorites_slug() ) );
     337                                $my_subscriptions_link = bbp_get_user_url( $user_id, array( $this->slug, bbp_get_user_subscriptions_slug() ) );
    305338                        }
    306339
    307340                        // 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;