Ticket #3576: 3576.patch
File 3576.patch, 27.2 KB (added by , 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' ); 143 143 add_action( 'bbp_ready', 'bbp_setup_akismet', 2 ); // Spam prevention for topics and replies 144 144 145 145 // Setup BuddyPress using its own hook 146 add_action( 'bp_ include', 'bbp_setup_buddypress', 10); // Social network integration146 add_action( 'bp_loaded', 'bbp_setup_buddypress', 1 ); // Social network integration 147 147 148 148 // Try to load the bbpress-functions.php file from the active themes 149 149 add_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() { 39 39 bbpress()->extend->akismet = new BBP_Akismet(); 40 40 } 41 41 42 /** 43 * Loads the Forums BP Component. 44 * 45 * @since 2.6.10 46 */ 47 function 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 42 57 /** 43 58 * Requires and creates the BuddyPress extension, and adds component creation 44 59 * action to bp_init hook. @see bbp_setup_buddypress_component() 45 60 * 46 61 * @since 2.0.0 bbPress (r3395) 47 62 * 48 * @return If BuddyPress is not active63 * @return false If BuddyPress is not active 49 64 */ 50 65 function bbp_setup_buddypress() { 51 66 … … function bbp_setup_buddypress() { 68 83 return; 69 84 } 70 85 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 ); 76 87 } -
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 ); 20 20 add_action( 'load-settings_page_bbpress', 'bbp_maybe_create_group_forum_root' ); 21 21 add_action( 'bbp_delete_forum', 'bbp_maybe_delete_group_forum_root' ); 22 22 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 */ 35 function 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 */ 66 function 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 23 105 /** BuddyPress Helpers ********************************************************/ 24 106 25 107 /** -
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 { 33 33 * @since 2.1.0 bbPress (r3552) 34 34 */ 35 35 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 37 77 $this->setup_actions(); 38 78 $this->setup_filters(); 39 $this->maybe_unset_forum_menu();40 79 $this->fully_loaded(); 41 80 } 42 81 43 82 /** 44 * Setup the group forums class variables83 * Only set the group forum nav item if group does have a forum. 45 84 * 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. 47 89 */ 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; 53 93 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 } 58 99 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; 61 105 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 } 65 111 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 } 70 114 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(); 74 126 } 75 127 76 128 /** … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 232 284 $this->display_forums( 0 ); 233 285 } 234 286 235 /**236 * Maybe unset the group forum nav item if group does not have a forum237 *238 * @since 2.3.0 bbPress (r4552)239 *240 * @return If not viewing a single group241 */242 public function maybe_unset_forum_menu() {243 244 // Bail if not viewing a single group245 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 not253 $this->enable_nav_item = (bool) $checked;254 }255 256 287 /** 257 288 * Allow group members to have advanced privileges in group forum topics. 258 289 * … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 613 644 614 645 // Redirect after save when not in admin 615 646 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' ) ); 617 648 } 618 649 } 619 650 … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1269 1300 if ( bp_is_group() ) { 1270 1301 $topic = bbp_get_topic( $topic_id ); 1271 1302 $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; 1273 1311 } 1274 1312 1275 1313 return $redirect_url; … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1288 1326 $reply_position = bbp_get_reply_position( $reply_id, $topic_id ); 1289 1327 $reply_page = ceil( (int) $reply_position / (int) bbp_get_replies_per_page() ); 1290 1328 $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 ); 1296 1330 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 ); 1300 1334 } 1301 1335 1336 $redirect_url = bbp_get_group_url( groups_get_current_group(), $reply_url_args ) . $reply_hash; 1337 1302 1338 // Add topic view query arg back to end if it is set 1303 1339 if ( bbp_get_view_all() ) { 1304 1340 $redirect_url = bbp_add_view_all( $redirect_url ); … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1315 1351 */ 1316 1352 public function edit_redirect_to( $redirect_url = '' ) { 1317 1353 1318 // Get the current group, if there is one1319 $group = groups_get_current_group();1320 1321 1354 // If this is a group of any kind, empty out the redirect URL 1322 1355 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' ); 1324 1357 } 1325 1358 1326 1359 return $redirect_url; … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1444 1477 /** Permalink Mappers *****************************************************/ 1445 1478 1446 1479 /** 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. 1448 1481 * 1449 1482 * @since 2.2.0 bbPress (r4266) 1450 1483 * 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. 1453 1487 * @return string 1454 1488 */ 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() ) { 1456 1490 1457 1491 switch ( get_post_type( $post_id ) ) { 1458 1492 1459 1493 // Reply 1460 1494 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 } 1464 1502 break; 1465 1503 1466 1504 // Topic 1467 1505 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 ) ); 1471 1509 break; 1472 1510 1473 1511 // Forum 1474 1512 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(); 1477 1515 break; 1478 1516 1479 1517 // Unknown … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1492 1530 // @todo Multiple group forums/forum groups 1493 1531 $group_id = $group_ids[0]; 1494 1532 $group = groups_get_group( array( 'group_id' => $group_id ) ); 1533 array_unshift( $url_chunks, $this->slug ); 1495 1534 1496 1535 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' ); 1498 1537 } else { 1499 $group_permalink = trailingslashit( bp_get_group_permalink( $group ));1538 $group_permalink = bbp_get_group_url( $group, $url_chunks ); 1500 1539 } 1501 1540 1502 return trailingslashit( trailingslashit( $group_permalink . $this->slug ) . $url_end );1541 return $group_permalink; 1503 1542 } 1504 1543 1505 1544 /** … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1551 1590 * @return string 1552 1591 */ 1553 1592 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 ) ); 1555 1594 1556 if ( empty( $ new) ) {1595 if ( empty( $edit_url ) ) { 1557 1596 return $url; 1558 1597 } 1559 1598 1560 return trailingslashit( $new ) . bbpress()->edit_id . '/';1599 return $edit_url; 1561 1600 } 1562 1601 1563 1602 /** … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1612 1651 * @return array 1613 1652 */ 1614 1653 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(), '%#%' ) ); 1616 1655 1617 if ( empty( $ new) ) {1656 if ( empty( $pagination_base ) ) { 1618 1657 return $args; 1619 1658 } 1620 1659 1621 $args['base'] = trailingslashit( $new ) . bbp_get_paged_slug() . '/%#%/';1660 $args['base'] = $pagination_base; 1622 1661 1623 1662 return $args; 1624 1663 } … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1632 1671 * @return array 1633 1672 */ 1634 1673 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 ) ) { 1637 1677 return $args; 1638 1678 } 1639 1679 1640 $args['base'] = trailingslashit( $new ) . bbp_get_paged_slug() . '/%#%/';1680 $args['base'] = $pagination_base; 1641 1681 1642 1682 return $args; 1643 1683 } … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1680 1720 // Use the first group ID 1681 1721 $group_id = $group_ids[0]; 1682 1722 $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 ); 1685 1724 1686 1725 // Add topic slug to URL 1687 1726 if ( bbp_is_single_topic() ) { 1688 $redirect_to = trailingslashit( $redirect_to . $this->topic_slug . '/' .$slug );1727 array_push( $url_chunks, $this->topic_slug, $slug ); 1689 1728 } 1690 1729 1691 bp_core_redirect( $redirect_to);1730 bp_core_redirect( bbp_get_group_url( $group, $url_chunks ) ); 1692 1731 } 1693 1732 1694 1733 /** 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' ) ) : 30 30 * @subpackage BuddyPress 31 31 */ 32 32 class 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; 33 46 34 47 /** 35 48 * Start the forums component creation process … … class BBP_Forums_Component extends BP_Component { 42 55 esc_html__( 'Forums', 'bbpress' ), 43 56 bbpress()->includes_dir . 'extend/buddypress/' 44 57 ); 45 $this->includes(); 46 $this->setup_globals(); 47 $this->setup_actions(); 58 48 59 $this->fully_loaded(); 49 60 } 50 61 … … class BBP_Forums_Component extends BP_Component { 52 63 * Include BuddyPress classes and functions 53 64 */ 54 65 public function includes( $includes = array() ) { 66 $includes = array( 67 // Helper BuddyPress functions. 68 'functions.php', 55 69 56 // Helper BuddyPress functions 57 $includes[] = 'functions.php'; 58 59 // Members modifications 60 $includes[] = 'members.php'; 70 // Members modifications. 71 'members.php', 72 ); 61 73 62 74 // BuddyPress Notfications Extension functions 63 75 if ( bp_is_active( 'notifications' ) ) { … … class BBP_Forums_Component extends BP_Component { 74 86 $includes[] = 'groups.php'; 75 87 } 76 88 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 ); 90 90 } 91 91 92 92 /** … … class BBP_Forums_Component extends BP_Component { 170 170 } 171 171 172 172 /** 173 * Setup BuddyBar navigation173 * Register component navigation. 174 174 * 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. 176 183 */ 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() ) { 186 185 187 186 // Add 'Forums' to the main navigation 188 187 $main_nav = array( … … class BBP_Forums_Component extends BP_Component { 194 193 'item_css_id' => $this->id 195 194 ); 196 195 197 // Determine user to use198 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 link207 $forums_link = trailingslashit( $user_domain . $this->slug );208 209 196 // Topics started 210 197 $sub_nav[] = array( 211 198 'name' => esc_html__( 'Topics Started', 'bbpress' ), 212 199 'slug' => bbp_get_topic_archive_slug(), 213 'parent_url' => $forums_link,214 200 'parent_slug' => $this->slug, 215 201 'screen_function' => 'bbp_member_forums_screen_topics', 216 202 'position' => 20, … … class BBP_Forums_Component extends BP_Component { 221 207 $sub_nav[] = array( 222 208 'name' => esc_html__( 'Replies Created', 'bbpress' ), 223 209 'slug' => bbp_get_reply_archive_slug(), 224 'parent_url' => $forums_link,225 210 'parent_slug' => $this->slug, 226 211 'screen_function' => 'bbp_member_forums_screen_replies', 227 212 'position' => 40, … … class BBP_Forums_Component extends BP_Component { 233 218 $sub_nav[] = array( 234 219 'name' => esc_html__( 'Engagements', 'bbpress' ), 235 220 'slug' => bbp_get_user_engagements_slug(), 236 'parent_url' => $forums_link,237 221 'parent_slug' => $this->slug, 238 222 'screen_function' => 'bbp_member_forums_screen_engagements', 239 223 'position' => 60, … … class BBP_Forums_Component extends BP_Component { 246 230 $sub_nav[] = array( 247 231 'name' => esc_html__( 'Favorites', 'bbpress' ), 248 232 'slug' => bbp_get_user_favorites_slug(), 249 'parent_url' => $forums_link,250 233 'parent_slug' => $this->slug, 251 234 'screen_function' => 'bbp_member_forums_screen_favorites', 252 235 'position' => 80, … … class BBP_Forums_Component extends BP_Component { 255 238 } 256 239 257 240 // Subscribed topics (my profile only) 258 if ( b p_is_my_profile() && bbp_is_subscriptions_active() ) {241 if ( bbp_is_subscriptions_active() ) { 259 242 $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, 267 261 ); 268 262 } 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 } 269 303 270 304 parent::setup_nav( $main_nav, $sub_nav ); 271 305 } … … class BBP_Forums_Component extends BP_Component { 293 327 } else { 294 328 295 329 // 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() ) ); 305 338 } 306 339 307 340 // 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 { 225 225 return false; 226 226 } 227 227 228 // Setup profile URL229 $ url = array( bp_core_get_user_domain( $user_id ));228 // Init URL chunks. 229 $path_chunks = array(); 230 230 231 231 // Maybe push slug to end of URL array 232 232 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 ); 235 234 } 236 235 237 236 // Return 238 return implode( '', array_map( 'trailingslashit', $url ));237 return bbp_get_user_url( $user_id, $path_chunks ); 239 238 } 240 239 } 241 240 endif;