Changeset 7316
- Timestamp:
- 06/27/2025 07:53:25 PM (6 months ago)
- File:
-
- 1 edited
-
trunk/src/includes/extend/buddypress/groups.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/extend/buddypress/groups.php
r7210 r7316 117 117 add_filter( 'bbp_topic_pagination', array( $this, 'topic_pagination' ) ); 118 118 add_filter( 'bbp_replies_pagination', array( $this, 'replies_pagination' ) ); 119 add_filter( 'bbp_get_global_object', array( $this, 'rewrite_pagination' ), 10, 2 ); 119 120 120 121 // Tweak the redirect field … … 614 615 // Redirect after save when not in admin 615 616 if ( ! is_admin() ) { 616 bp_core_redirect( trailingslashit( bp_get_group_permalink( buddypress()->groups->current_group ) . '/admin/' . $this->slug ) );617 bp_core_redirect( trailingslashit( $this->group_url( buddypress()->groups->current_group ) . '/admin/' . $this->slug ) ); 617 618 } 618 619 } … … 1270 1271 $topic = bbp_get_topic( $topic_id ); 1271 1272 $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;1273 $redirect_url = trailingslashit( $this->group_url( groups_get_current_group() ) ) . trailingslashit( $this->slug ) . trailingslashit( $this->topic_slug ) . trailingslashit( $topic->post_name ) . $topic_hash; 1273 1274 } 1274 1275 … … 1289 1290 $reply_page = ceil( (int) $reply_position / (int) bbp_get_replies_per_page() ); 1290 1291 $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 $topic_url = trailingslashit( $this->group_url( groups_get_current_group() ) ) . trailingslashit( $this->slug ) . trailingslashit( $this->topic_slug ) . trailingslashit( $topic->post_name ); 1292 1293 1293 1294 // Don't include pagination if on first page … … 1445 1446 1446 1447 /** 1448 * Get the URL for a group. 1449 * 1450 * @since 2.6.14 1451 * 1452 * @param int $group_id 1453 * @return string 1454 */ 1455 private function group_url( $group_id = 0 ) { 1456 1457 // Default return value 1458 $retval = ''; 1459 1460 // BuddyPress < 12.0 (deprecated code is intentionally included) 1461 if ( function_exists( 'bp_get_group_permalink' ) ) { 1462 $retval = bp_get_group_permalink( $group_id ); 1463 1464 // BuddyPress > 12.0 (rewrite rules) 1465 } elseif ( function_exists( 'bp_get_group_url' ) ) { 1466 $retval = bp_get_group_url( $group_id ); 1467 } 1468 1469 // Return 1470 return $retval; 1471 } 1472 1473 /** 1474 * Get the management URL for a group. 1475 * 1476 * @since 2.6.14 1477 * 1478 * @param int $group_id 1479 * @return string 1480 */ 1481 private function group_manage_url( $group_id = 0 ) { 1482 1483 // Default return value 1484 $retval = ''; 1485 1486 // BuddyPress < 12.0 (deprecated code is intentionally included) 1487 if ( function_exists( 'bp_get_group_admin_permalink' ) ) { 1488 $retval = bp_get_group_admin_permalink( $group_id ); 1489 1490 // BuddyPress > 12.0 (rewrite rules) 1491 } elseif ( function_exists( 'bp_get_group_manage_url' ) ) { 1492 $retval = bp_get_group_manage_url( $group_id ); 1493 } 1494 1495 // Return 1496 return $retval; 1497 } 1498 1499 /** 1447 1500 * Maybe map a bbPress forum/topic/reply permalink to the corresponding group 1448 1501 * … … 1494 1547 $group = groups_get_group( array( 'group_id' => $group_id ) ); 1495 1548 1496 if ( bp_is_group_admin_screen( $this->slug ) ) { 1497 $group_permalink = trailingslashit( bp_get_group_admin_permalink( $group ) ); 1498 } else { 1499 $group_permalink = trailingslashit( bp_get_group_permalink( $group ) ); 1500 } 1501 1502 return trailingslashit( trailingslashit( $group_permalink . $this->slug ) . $url_end ); 1549 // Admin 1550 $group_permalink = bp_is_group_admin_screen( $this->slug ) 1551 ? $this->group_manage_url( $group ) 1552 : $this->group_url( $group ); 1553 1554 return trailingslashit( trailingslashit( trailingslashit( $group_permalink ) . $this->slug ) . $url_end ); 1503 1555 } 1504 1556 … … 1642 1694 return $args; 1643 1695 } 1696 1697 /** 1698 * Fixes rewrite pagination in BuddyPress Group Forums & Topics. 1699 * 1700 * Required for compatibility with BuddyPress > 12.0, where the /groups/ 1701 * rewrite rule will be caught before bbPress's /page/ rule. 1702 * 1703 * @since 2.6.14 1704 * 1705 * @param object object Verified object 1706 * @param string $type Type of variable to check with `is_a()` 1707 * @return mixed $object Verified object if valid, Default or null if invalid 1708 */ 1709 public function rewrite_pagination( $object, $type = '' ) { 1710 1711 // Bail if wrong global 1712 if ( 'wp_query' !== $type ) { 1713 return $object; 1714 } 1715 1716 // Bail if not inside a BuddyPress Group 1717 if ( ! bp_is_group() ) { 1718 return $object; 1719 } 1720 1721 // Bail if not inside a BuddyPress Group Forum 1722 if ( ! bp_is_current_action( 'forum' ) ) { 1723 return $object; 1724 } 1725 1726 // Default "paged" value 1727 $page_number = null; 1728 1729 // Can't use bbp_is_single_topic() because it triggers a loop. 1730 $is_single_topic = bp_is_action_variable( 'topic', 0 ); 1731 1732 // Single Topic 1733 if ( true === $is_single_topic ) { 1734 1735 // Get the page number from 3rd position 1736 if ( bp_is_action_variable( 'page', 2 ) ) { 1737 $page_number = bp_action_variable( 3 ); 1738 } 1739 1740 // Single Forum 1741 } else { 1742 1743 // Get the page number from 1st position 1744 if ( bp_is_action_variable( 'page', 0 ) ) { 1745 $page_number = bp_action_variable( 1 ); 1746 } 1747 } 1748 1749 // Bail if no page number 1750 if ( empty( $page_number ) ) { 1751 return $object; 1752 } 1753 1754 // Set the 'paged' WP_Query var to the new action-based value 1755 $object->set( 'paged', $page_number ); 1756 1757 // Return the filtered/modified object 1758 return $object; 1759 } 1644 1760 1645 1761 /** … … 1681 1797 $group_id = $group_ids[0]; 1682 1798 $group = groups_get_group( array( 'group_id' => $group_id ) ); 1683 $group_link = trailingslashit( bp_get_group_permalink( $group ) );1799 $group_link = trailingslashit( $this->group_url( $group ) ); 1684 1800 $redirect_to = trailingslashit( $group_link . $this->slug ); 1685 1801
Note: See TracChangeset
for help on using the changeset viewer.