Ticket #3576: 3576.2.patch
File 3576.2.patch, 28.1 KB (added by , 13 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..7ca1c08e 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 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 37 68 $this->setup_actions(); 38 69 $this->setup_filters(); 39 $this->maybe_unset_forum_menu();40 70 $this->fully_loaded(); 41 71 } 42 72 43 73 /** 44 * Setup the group forums class variables74 * Only set the group forum nav item if group does have a forum. 45 75 * 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. 47 79 */ 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; 61 89 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 } 65 95 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 } 70 98 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(); 74 110 } 75 111 76 112 /** … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 232 268 $this->display_forums( 0 ); 233 269 } 234 270 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 271 /** 257 272 * Allow group members to have advanced privileges in group forum topics. 258 273 * … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 613 628 614 629 // Redirect after save when not in admin 615 630 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' ) ); 617 632 } 618 633 } 619 634 … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1269 1284 if ( bp_is_group() ) { 1270 1285 $topic = bbp_get_topic( $topic_id ); 1271 1286 $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; 1273 1295 } 1274 1296 1275 1297 return $redirect_url; … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1288 1310 $reply_position = bbp_get_reply_position( $reply_id, $topic_id ); 1289 1311 $reply_page = ceil( (int) $reply_position / (int) bbp_get_replies_per_page() ); 1290 1312 $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 ); 1296 1314 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 ); 1300 1318 } 1301 1319 1320 $redirect_url = bbp_get_group_url( groups_get_current_group(), $reply_url_args ) . $reply_hash; 1321 1302 1322 // Add topic view query arg back to end if it is set 1303 1323 if ( bbp_get_view_all() ) { 1304 1324 $redirect_url = bbp_add_view_all( $redirect_url ); … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1315 1335 */ 1316 1336 public function edit_redirect_to( $redirect_url = '' ) { 1317 1337 1318 // Get the current group, if there is one1319 $group = groups_get_current_group();1320 1321 1338 // If this is a group of any kind, empty out the redirect URL 1322 1339 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' ); 1324 1341 } 1325 1342 1326 1343 return $redirect_url; … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1444 1461 /** Permalink Mappers *****************************************************/ 1445 1462 1446 1463 /** 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. 1448 1465 * 1449 1466 * @since 2.2.0 bbPress (r4266) 1450 1467 * 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. 1453 1471 * @return string 1454 1472 */ 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() ) { 1456 1474 1457 1475 switch ( get_post_type( $post_id ) ) { 1458 1476 1459 1477 // Reply 1460 1478 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 1464 1483 break; 1465 1484 1466 1485 // Topic 1467 1486 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 ) ); 1471 1490 break; 1472 1491 1473 1492 // Forum 1474 1493 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(); 1477 1496 break; 1478 1497 1479 1498 // Unknown … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1481 1500 return $url; 1482 1501 } 1483 1502 1503 if ( $additional_chunks ) { 1504 $url_chunks = array_merge( $url_chunks, $additional_chunks ); 1505 } 1506 1484 1507 // Get group ID's for this forum 1485 1508 $group_ids = bbp_get_forum_group_ids( $forum_id ); 1486 1509 … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1492 1515 // @todo Multiple group forums/forum groups 1493 1516 $group_id = $group_ids[0]; 1494 1517 $group = groups_get_group( array( 'group_id' => $group_id ) ); 1518 array_unshift( $url_chunks, $this->slug ); 1495 1519 1496 1520 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' ); 1498 1522 } else { 1499 $group_permalink = trailingslashit( bp_get_group_permalink( $group ));1523 $group_permalink = bbp_get_group_url( $group, $url_chunks ); 1500 1524 } 1501 1525 1502 return trailingslashit( trailingslashit( $group_permalink . $this->slug ) . $url_end );1526 return $group_permalink; 1503 1527 } 1504 1528 1505 1529 /** … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1551 1575 * @return string 1552 1576 */ 1553 1577 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 ) ); 1555 1579 1556 if ( empty( $ new) ) {1580 if ( empty( $edit_url ) ) { 1557 1581 return $url; 1558 1582 } 1559 1583 1560 return trailingslashit( $new ) . bbpress()->edit_id . '/';1584 return $edit_url; 1561 1585 } 1562 1586 1563 1587 /** … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1612 1636 * @return array 1613 1637 */ 1614 1638 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(), '%#%' ) ); 1616 1640 1617 if ( empty( $ new) ) {1641 if ( empty( $pagination_base ) ) { 1618 1642 return $args; 1619 1643 } 1620 1644 1621 $args['base'] = trailingslashit( $new ) . bbp_get_paged_slug() . '/%#%/';1645 $args['base'] = $pagination_base; 1622 1646 1623 1647 return $args; 1624 1648 } … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1632 1656 * @return array 1633 1657 */ 1634 1658 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 ) ) { 1637 1662 return $args; 1638 1663 } 1639 1664 1640 $args['base'] = trailingslashit( $new ) . bbp_get_paged_slug() . '/%#%/';1665 $args['base'] = $pagination_base; 1641 1666 1642 1667 return $args; 1643 1668 } … … class BBP_Forums_Group_Extension extends BP_Group_Extension { 1680 1705 // Use the first group ID 1681 1706 $group_id = $group_ids[0]; 1682 1707 $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 ); 1685 1709 1686 1710 // Add topic slug to URL 1687 1711 if ( bbp_is_single_topic() ) { 1688 $redirect_to = trailingslashit( $redirect_to . $this->topic_slug . '/' .$slug );1712 array_push( $url_chunks, $this->topic_slug, $slug ); 1689 1713 } 1690 1714 1691 bp_core_redirect( $redirect_to);1715 bp_core_redirect( bbp_get_group_url( $group, $url_chunks ) ); 1692 1716 } 1693 1717 1694 1718 /** 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' ) ) : 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 { 135 135 // Setup the components 136 136 add_action( 'bp_init', array( $this, 'setup_components' ), 7 ); 137 137 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 138 142 parent::setup_actions(); 139 143 } 140 144 … … class BBP_Forums_Component extends BP_Component { 159 163 } 160 164 } 161 165 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 162 184 /** 163 185 * Allow the variables, actions, and filters to be modified by third party 164 186 * plugins and themes. … … class BBP_Forums_Component extends BP_Component { 170 192 } 171 193 172 194 /** 173 * Setup BuddyBar navigation195 * Register component navigation. 174 196 * 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. 176 205 */ 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() ) { 186 207 187 208 // Add 'Forums' to the main navigation 188 209 $main_nav = array( … … class BBP_Forums_Component extends BP_Component { 194 215 'item_css_id' => $this->id 195 216 ); 196 217 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 218 // Topics started 210 219 $sub_nav[] = array( 211 220 'name' => esc_html__( 'Topics Started', 'bbpress' ), 212 221 'slug' => bbp_get_topic_archive_slug(), 213 'parent_url' => $forums_link,214 222 'parent_slug' => $this->slug, 215 223 'screen_function' => 'bbp_member_forums_screen_topics', 216 224 'position' => 20, … … class BBP_Forums_Component extends BP_Component { 221 229 $sub_nav[] = array( 222 230 'name' => esc_html__( 'Replies Created', 'bbpress' ), 223 231 'slug' => bbp_get_reply_archive_slug(), 224 'parent_url' => $forums_link,225 232 'parent_slug' => $this->slug, 226 233 'screen_function' => 'bbp_member_forums_screen_replies', 227 234 'position' => 40, … … class BBP_Forums_Component extends BP_Component { 233 240 $sub_nav[] = array( 234 241 'name' => esc_html__( 'Engagements', 'bbpress' ), 235 242 'slug' => bbp_get_user_engagements_slug(), 236 'parent_url' => $forums_link,237 243 'parent_slug' => $this->slug, 238 244 'screen_function' => 'bbp_member_forums_screen_engagements', 239 245 'position' => 60, … … class BBP_Forums_Component extends BP_Component { 246 252 $sub_nav[] = array( 247 253 'name' => esc_html__( 'Favorites', 'bbpress' ), 248 254 'slug' => bbp_get_user_favorites_slug(), 249 'parent_url' => $forums_link,250 255 'parent_slug' => $this->slug, 251 256 'screen_function' => 'bbp_member_forums_screen_favorites', 252 257 'position' => 80, … … class BBP_Forums_Component extends BP_Component { 255 260 } 256 261 257 262 // Subscribed topics (my profile only) 258 if ( b p_is_my_profile() && bbp_is_subscriptions_active() ) {263 if ( bbp_is_subscriptions_active() ) { 259 264 $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', 267 273 ); 268 274 } 269 275 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 270 326 parent::setup_nav( $main_nav, $sub_nav ); 271 327 } 272 328 … … class BBP_Forums_Component extends BP_Component { 293 349 } else { 294 350 295 351 // 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() ) ); 305 360 } 306 361 307 362 // 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;