Changeset 4395
- Timestamp:
- 11/11/2012 11:09:10 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bbpress.php
r4392 r4395 315 315 require( $this->includes_dir . 'users/options.php' ); 316 316 317 /** Extensions ********************************************************/318 319 require( $this->includes_dir . 'extend/akismet.php' );320 321 317 /** Hooks *************************************************************/ 322 318 319 require( $this->includes_dir . 'core/extend.php' ); 323 320 require( $this->includes_dir . 'core/actions.php' ); 324 321 require( $this->includes_dir . 'core/filters.php' ); -
trunk/includes/core/actions.php
r4394 r4395 294 294 295 295 add_action( 'bbp_activation', 'bbp_add_activation_redirect' ); 296 297 /**298 * Requires and creates the BuddyPress extension, and adds component creation299 * action to bp_init hook. @see bbp_setup_buddypress_component()300 *301 * @since bbPress (r3395)302 * @return If BuddyPress is not active303 */304 function bbp_setup_buddypress() {305 global $bp;306 307 // Bail if no BuddyPress308 if ( !empty( $bp->maintenance_mode ) || !defined( 'BP_VERSION' ) ) return;309 310 // Include the BuddyPress Component311 require( bbpress()->includes_dir . 'extend/buddypress/loader.php' );312 313 // Instantiate BuddyPress for bbPress314 bbpress()->extend->buddypress = new BBP_BuddyPress();315 316 // Add component setup to bp_init action317 add_action( 'bp_init', 'bbp_setup_buddypress_component' );318 } -
trunk/includes/extend/akismet.php
r4249 r4395 685 685 } 686 686 endif; 687 688 /**689 * Loads Akismet inside the bbPress global class690 *691 * @since bbPress (r3277)692 *693 * @return If bbPress is not active694 */695 function bbp_setup_akismet() {696 697 // Bail if no akismet698 if ( !defined( 'AKISMET_VERSION' ) ) return;699 700 // Bail if Akismet is turned off701 if ( !bbp_is_akismet_active() ) return;702 703 // Instantiate Akismet for bbPress704 bbpress()->extend->akismet = new BBP_Akismet();705 } -
trunk/includes/extend/buddypress/activity.php
r4394 r4395 130 130 private function setup_actions() { 131 131 132 /** Activity **********************************************************/ 133 134 // Bail if activity is not active 135 if ( bp_is_active( 'activity' ) ) { 136 137 // Register the activity stream actions 138 add_action( 'bp_register_activity_actions', array( $this, 'register_activity_actions' ) ); 139 140 // Hook into topic and reply creation 141 add_action( 'bbp_new_topic', array( $this, 'topic_create' ), 10, 4 ); 142 add_action( 'bbp_new_reply', array( $this, 'reply_create' ), 10, 5 ); 143 144 // Hook into topic and reply status changes 145 add_action( 'wp_insert_post', array( $this, 'topic_update' ), 10, 2 ); 146 add_action( 'wp_insert_post', array( $this, 'reply_update' ), 10, 2 ); 147 148 // Hook into topic and reply deletion 149 add_action( 'bbp_delete_topic', array( $this, 'topic_delete' ), 10, 1 ); 150 add_action( 'bbp_delete_reply', array( $this, 'reply_delete' ), 10, 1 ); 151 152 // Append forum filters in site wide activity streams 153 add_action( 'bp_activity_filter_options', array( $this, 'activity_filter_options' ), 10 ); 154 155 // Append forum filters in single member activity streams 156 add_action( 'bp_member_activity_filter_options', array( $this, 'activity_filter_options' ), 10 ); 157 158 // Append forum filters in single group activity streams 159 add_action( 'bp_group_activity_filter_options', array( $this, 'activity_filter_options' ), 10 ); 160 } 161 162 /** Favorites *********************************************************/ 163 164 // Move handler to 'bp_actions' - BuddyPress bypasses template_loader 165 remove_action( 'template_redirect', 'bbp_favorites_handler', 1 ); 166 add_action( 'bp_actions', 'bbp_favorites_handler', 1 ); 167 168 /** Subscriptions *****************************************************/ 169 170 // Move handler to 'bp_actions' - BuddyPress bypasses template_loader 171 remove_action( 'template_redirect', 'bbp_subscriptions_handler', 1 ); 172 add_action( 'bp_actions', 'bbp_subscriptions_handler', 1 ); 132 // Register the activity stream actions 133 add_action( 'bp_register_activity_actions', array( $this, 'register_activity_actions' ) ); 134 135 // Hook into topic and reply creation 136 add_action( 'bbp_new_topic', array( $this, 'topic_create' ), 10, 4 ); 137 add_action( 'bbp_new_reply', array( $this, 'reply_create' ), 10, 5 ); 138 139 // Hook into topic and reply status changes 140 add_action( 'wp_insert_post', array( $this, 'topic_update' ), 10, 2 ); 141 add_action( 'wp_insert_post', array( $this, 'reply_update' ), 10, 2 ); 142 143 // Hook into topic and reply deletion 144 add_action( 'bbp_delete_topic', array( $this, 'topic_delete' ), 10, 1 ); 145 add_action( 'bbp_delete_reply', array( $this, 'reply_delete' ), 10, 1 ); 146 147 // Append forum filters in site wide activity streams 148 add_action( 'bp_activity_filter_options', array( $this, 'activity_filter_options' ), 10 ); 149 150 // Append forum filters in single member activity streams 151 add_action( 'bp_member_activity_filter_options', array( $this, 'activity_filter_options' ), 10 ); 152 153 // Append forum filters in single group activity streams 154 add_action( 'bp_group_activity_filter_options', array( $this, 'activity_filter_options' ), 10 ); 173 155 } 174 156 … … 191 173 add_filter( 'bp_activity_get_permalink', array( $this, 'activity_get_permalink' ), 10, 2 ); 192 174 193 /** Profiles **********************************************************/194 195 // Override bbPress user profile URL with BuddyPress profile URL196 add_filter( 'bbp_pre_get_user_profile_url', array( $this, 'user_profile_url' ) );197 add_filter( 'bbp_get_favorites_permalink', array( $this, 'get_favorites_permalink' ), 10, 2 );198 add_filter( 'bbp_get_subscriptions_permalink', array( $this, 'get_subscriptions_permalink' ), 10, 2 );199 200 175 /** Mentions **********************************************************/ 201 176 202 // Only link mentions if activity component is active 203 if ( bp_is_active( 'activity' ) ) { 204 205 // Convert mentions into links on create 206 add_filter( 'bbp_new_topic_pre_content', 'bp_activity_at_name_filter' ); 207 add_filter( 'bbp_new_reply_pre_content', 'bp_activity_at_name_filter' ); 208 209 // Convert mentions into links on edit 210 add_filter( 'bbp_edit_topic_pre_content', 'bp_activity_at_name_filter' ); 211 add_filter( 'bbp_edit_reply_pre_content', 'bp_activity_at_name_filter' ); 212 } 177 // Convert mentions into links on create 178 add_filter( 'bbp_new_topic_pre_content', 'bp_activity_at_name_filter' ); 179 add_filter( 'bbp_new_reply_pre_content', 'bp_activity_at_name_filter' ); 180 181 // Convert mentions into links on edit 182 add_filter( 'bbp_edit_topic_pre_content', 'bp_activity_at_name_filter' ); 183 add_filter( 'bbp_edit_reply_pre_content', 'bp_activity_at_name_filter' ); 213 184 214 185 // Revert links into text on edit … … 430 401 431 402 <?php 432 }433 434 /**435 * Override bbPress profile URL with BuddyPress profile URL436 *437 * @since bbPress (r3401)438 * @param string $url439 * @param int $user_id440 * @param string $user_nicename441 * @return string442 */443 public function user_profile_url( $user_id ) {444 445 // Define local variable(s)446 $profile_url = '';447 448 // Special handling for forum component449 if ( bp_is_current_component( 'forums' ) ) {450 451 // Empty action or 'topics' action452 if ( !bp_current_action() || bp_is_current_action( 'topics' ) ) {453 $profile_url = bp_core_get_user_domain( $user_id ) . 'forums/topics';454 455 // Empty action or 'topics' action456 } elseif ( bp_is_current_action( 'replies' ) ) {457 $profile_url = bp_core_get_user_domain( $user_id ) . 'forums/replies';458 459 // 'favorites' action460 } elseif ( bbp_is_favorites_active() && bp_is_current_action( 'favorites' ) ) {461 $profile_url = $this->get_favorites_permalink( '', $user_id );462 463 // 'subscriptions' action464 } elseif ( bbp_is_subscriptions_active() && bp_is_current_action( 'subscriptions' ) ) {465 $profile_url = $this->get_subscriptions_permalink( '', $user_id );466 }467 468 // Not in users' forums area469 } else {470 $profile_url = bp_core_get_user_domain( $user_id );471 }472 473 return trailingslashit( $profile_url );474 }475 476 /**477 * Override bbPress favorites URL with BuddyPress profile URL478 *479 * @since bbPress (r3721)480 * @param string $url481 * @param int $user_id482 * @return string483 */484 public function get_favorites_permalink( $url, $user_id ) {485 $url = trailingslashit( bp_core_get_user_domain( $user_id ) . 'forums/favorites' );486 return $url;487 }488 489 /**490 * Override bbPress subscriptions URL with BuddyPress profile URL491 *492 * @since bbPress (r3721)493 * @param string $url494 * @param int $user_id495 * @return string496 */497 public function get_subscriptions_permalink( $url, $user_id ) {498 $url = trailingslashit( bp_core_get_user_domain( $user_id ) . 'forums/subscriptions' );499 return $url;500 403 } 501 404 -
trunk/includes/extend/buddypress/group.php
r4394 r4395 24 24 class BBP_Forums_Group_Extension extends BP_Group_Extension { 25 25 26 /** Methods ***************************************************************/ 27 26 28 /** 27 29 * Setup bbPress group extension variables … … 34 36 $this->name = __( 'Forum', 'bbpress' ); 35 37 $this->nav_item_name = __( 'Forum', 'bbpress' ); 36 $this->slug = 'forum s';38 $this->slug = 'forum'; 37 39 $this->topic_slug = 'topic'; 38 40 $this->reply_slug = 'reply'; … … 62 64 add_action( 'bp_actions', 'bbp_edit_reply_handler' ); 63 65 66 // Possibly redirect 67 add_action( 'template_redirect', array( $this, 'redirect_canonical' ) ); 68 64 69 // Tweak the redirect field 65 70 add_filter( 'bbp_new_topic_redirect_to', array( $this, 'new_topic_redirect_to' ), 10, 3 ); 66 71 add_filter( 'bbp_new_reply_redirect_to', array( $this, 'new_reply_redirect_to' ), 10, 3 ); 72 73 // Group forum pagination 74 add_filter( 'bbp_topic_pagination', array( $this, 'topic_pagination' ) ); 75 add_filter( 'bbp_replies_pagination', array( $this, 'replies_pagination' ) ); 76 77 // Map forum/topic/replys permalinks to their groups 78 add_filter( 'bbp_get_forum_permalink', array( $this, 'map_forum_permalink_to_group' ), 10, 2 ); 79 add_filter( 'bbp_get_topic_permalink', array( $this, 'map_topic_permalink_to_group' ), 10, 2 ); 80 add_filter( 'bbp_get_reply_permalink', array( $this, 'map_reply_permalink_to_group' ), 10, 2 ); 81 82 // Map reply edit links to their groups 83 add_filter( 'bbp_get_reply_edit_url', array( $this, 'map_reply_edit_url_to_group' ), 10, 2 ); 84 85 // Map assorted template function permalinks 86 add_filter( 'post_link', array( $this, 'post_link' ), 10, 2 ); 87 add_filter( 'page_link', array( $this, 'page_link' ), 10, 2 ); 88 add_filter( 'post_type_link', array( $this, 'post_type_link' ), 10, 2 ); 67 89 } 68 90 … … 695 717 <?php 696 718 } 719 720 /** Permalink Mappers *****************************************************/ 721 722 /** 723 * Maybe map a bbPress forum/topic/reply permalink to the corresponding group 724 * 725 * @param int $post_id 726 * @uses get_post() 727 * @uses bbp_is_reply() 728 * @uses bbp_get_reply_topic_id() 729 * @uses bbp_get_reply_forum_id() 730 * @uses bbp_is_topic() 731 * @uses bbp_get_topic_forum_id() 732 * @uses bbp_is_forum() 733 * @uses get_post_field() 734 * @uses bbp_get_forum_group_ids() 735 * @uses groups_get_group() 736 * @uses bp_get_group_admin_permalink() 737 * @uses bp_get_group_permalink() 738 * @return Bail early if not a group forum post 739 * @return string 740 */ 741 private function maybe_map_permalink_to_group( $post_id = 0, $url = false ) { 742 743 switch ( get_post_type( $post_id ) ) { 744 745 // Reply 746 case bbp_get_reply_post_type() : 747 $topic_id = bbp_get_reply_topic_id( $post_id ); 748 $forum_id = bbp_get_reply_forum_id( $post_id ); 749 $url_end = trailingslashit( $this->reply_slug ) . get_post_field( 'post_name', $post_id ); 750 break; 751 752 // Topic 753 case bbp_get_topic_post_type() : 754 $topic_id = $post_id; 755 $forum_id = bbp_get_topic_forum_id( $post_id ); 756 $url_end = trailingslashit( $this->topic_slug ) . get_post_field( 'post_name', $post_id ); 757 break; 758 759 // Forum 760 case bbp_get_forum_post_type() : 761 $forum_id = $post_id; 762 $url_end = ''; //get_post_field( 'post_name', $post_id ); 763 break; 764 765 // Unknown 766 default : 767 return $url; 768 break; 769 } 770 771 // Get group ID's for this forum 772 $group_ids = bbp_get_forum_group_ids( $forum_id ); 773 774 // Bail if the post isn't associated with a group 775 if ( empty( $group_ids ) ) 776 return $url; 777 778 // @todo Multiple group forums/forum groups 779 $group_id = $group_ids[0]; 780 $group = groups_get_group( array( 'group_id' => $group_id ) ); 781 782 if ( bp_is_group_admin_screen( $this->slug ) ) { 783 $group_permalink = trailingslashit( bp_get_group_admin_permalink( $group ) ); 784 } else { 785 $group_permalink = trailingslashit( bp_get_group_permalink( $group ) ); 786 } 787 788 return trailingslashit( trailingslashit( $group_permalink . $this->slug ) . $url_end ); 789 } 790 791 /** 792 * Map a forum permalink to its corresponding group 793 * 794 * @since bbPress (r3802) 795 * @param string $url 796 * @param int $forum_id 797 * @uses maybe_map_permalink_to_group() 798 * @return string 799 */ 800 public function map_forum_permalink_to_group( $url, $forum_id ) { 801 return $this->maybe_map_permalink_to_group( $forum_id, $url ); 802 } 803 804 /** 805 * Map a topic permalink to its group forum 806 * 807 * @since bbPress (r3802) 808 * @param string $url 809 * @param int $topic_id 810 * @uses maybe_map_permalink_to_group() 811 * @return string 812 */ 813 public function map_topic_permalink_to_group( $url, $topic_id ) { 814 return $this->maybe_map_permalink_to_group( $topic_id, $url ); 815 } 816 817 /** 818 * Map a reply permalink to its group forum 819 * 820 * @since bbPress (r3802) 821 * @param string $url 822 * @param int $reply_id 823 * @uses maybe_map_permalink_to_group() 824 * @return string 825 */ 826 public function map_reply_permalink_to_group( $url, $reply_id ) { 827 return $this->maybe_map_permalink_to_group( bbp_get_reply_topic_id( $reply_id ), $url ); 828 } 829 830 /** 831 * Map a reply edit link to its group forum 832 * 833 * @param string $url 834 * @param int $reply_id 835 * @uses maybe_map_permalink_to_group() 836 * @return string 837 */ 838 public function map_reply_edit_url_to_group( $url, $reply_id ) { 839 $new = $this->maybe_map_permalink_to_group( $reply_id ); 840 841 if ( empty( $new ) ) 842 return $url; 843 844 return trailingslashit( $new ) . bbpress()->edit_id . '/'; 845 } 846 847 /** 848 * Map a post link to its group forum 849 * 850 * @param string $url 851 * @param obj $post 852 * @param boolean $leavename 853 * @uses maybe_map_permalink_to_group() 854 * @return string 855 */ 856 public function post_link( $url, $post ) { 857 return $this->maybe_map_permalink_to_group( $post->ID, $url ); 858 } 859 860 /** 861 * Map a page link to its group forum 862 * 863 * @param string $url 864 * @param int $post_id 865 * @param $sample 866 * @uses maybe_map_permalink_to_group() 867 * @return string 868 */ 869 public function page_link( $url, $post_id ) { 870 return $this->maybe_map_permalink_to_group( $post_id, $url ); 871 } 872 873 /** 874 * Map a custom post type link to its group forum 875 * 876 * @param string $url 877 * @param obj $post 878 * @param $leavename 879 * @param $sample 880 * @uses maybe_map_permalink_to_group() 881 * @return string 882 */ 883 public function post_type_link( $url, $post ) { 884 return $this->maybe_map_permalink_to_group( $post->ID, $url ); 885 } 886 887 /** 888 * Fix pagination of topics on forum view 889 * 890 * @param array $args 891 * @global $wp_rewrite 892 * @uses bbp_get_forum_id() 893 * @uses maybe_map_permalink_to_group 894 * @return array 895 */ 896 public function topic_pagination( $args ) { 897 $new = $this->maybe_map_permalink_to_group( bbp_get_forum_id() ); 898 899 if ( empty( $new ) ) 900 return $args; 901 902 global $wp_rewrite; 903 904 $args['base'] = trailingslashit( $new ) . $wp_rewrite->pagination_base . '/%#%/'; 905 906 return $args; 907 } 908 909 /** 910 * Fix pagination of replies on topic view 911 * 912 * @param array $args 913 * @global $wp_rewrite 914 * @uses bbp_get_topic_id() 915 * @uses maybe_map_permalink_to_group 916 * @return array 917 */ 918 public function replies_pagination( $args ) { 919 $new = $this->maybe_map_permalink_to_group( bbp_get_topic_id() ); 920 if ( empty( $new ) ) 921 return $args; 922 923 global $wp_rewrite; 924 925 $args['base'] = trailingslashit( $new ) . $wp_rewrite->pagination_base . '/%#%/'; 926 927 return $args; 928 } 929 930 /** 931 * Ensure that forum content associated with a BuddyPress group can only be 932 * viewed via the group URL. 933 * 934 * @since bbPress (r3802) 935 */ 936 function redirect_canonical() { 937 938 // Viewing a single forum 939 if ( bbp_is_single_forum() ) { 940 $forum_id = get_the_ID(); 941 $group_ids = bbp_get_forum_group_ids( $forum_id ); 942 943 // Viewing a single topic 944 } elseif ( bbp_is_single_topic() ) { 945 $topic_id = get_the_ID(); 946 $slug = get_post_field( 'post_name', $topic_id ); 947 $forum_id = bbp_get_topic_forum_id( $topic_id ); 948 $group_ids = bbp_get_forum_group_ids( $forum_id ); 949 950 // Not a forum or topic 951 } else { 952 return; 953 } 954 955 // Bail if not a group forum 956 if ( empty( $group_ids ) ) 957 return; 958 959 // Use the first group ID 960 $group_id = $group_ids[0]; 961 $group = groups_get_group( array( 'group_id' => $group_id ) ); 962 $group_link = trailingslashit( bp_get_group_permalink( $group ) ); 963 $redirect_to = trailingslashit( $group_link . $this->slug ); 964 965 // Add topic slug to URL 966 if ( bbp_is_single_topic() ) { 967 $redirect_to = trailingslashit( $redirect_to . $this->topic_slug . '/' . $slug ); 968 } 969 970 bp_core_redirect( $redirect_to ); 971 } 697 972 } 698 973 endif; -
trunk/includes/extend/buddypress/loader.php
r4394 r4395 7 7 * @subpackage BuddyPress 8 8 * @todo maybe move to BuddyPress Forums once bbPress 1.1 can be removed 9 * @todo move this into the main component? 9 10 */ 10 11 … … 23 24 class BBP_BuddyPress { 24 25 25 /** Slugs *****************************************************************/26 27 /**28 * Forums slug29 *30 * @var string31 */32 private $forums_slug = '';33 34 /**35 * Topic slug36 *37 * @var string38 */39 private $topic_slug = '';40 41 /**42 * Reply slug43 *44 * @var string45 */46 private $reply_slug = '';47 48 26 /** Setup Methods *********************************************************/ 49 27 … … 55 33 public function __construct() { 56 34 $this->includes(); 57 $this->setup_components();58 $this->setup_globals();59 35 $this->setup_actions(); 60 36 $this->setup_filters(); … … 66 42 */ 67 43 public function includes() { 68 require( bbpress()->includes_dir . 'extend/buddypress/activity.php' ); // BuddyPress Activity Extension class 69 require( bbpress()->includes_dir . 'extend/buddypress/group.php' ); // BuddyPress Group Extension class 70 require( bbpress()->includes_dir . 'extend/buddypress/component.php' ); // BuddyPress Component Extension class 71 require( bbpress()->includes_dir . 'extend/buddypress/functions.php' ); // Helper BuddyPress functions 44 45 // BuddyPress Component Extension class 46 require( bbpress()->includes_dir . 'extend/buddypress/component.php' ); 47 48 // Helper BuddyPress functions 49 require( bbpress()->includes_dir . 'extend/buddypress/functions.php' ); 50 51 // BuddyPress Activity Extension class 52 if ( bp_is_active( 'activity' ) ) { 53 require( bbpress()->includes_dir . 'extend/buddypress/activity.php' ); 54 } 55 56 // BuddyPress Group Extension class 57 if ( bbp_is_group_forums_active() && bp_is_active( 'groups' ) ) { 58 require( bbpress()->includes_dir . 'extend/buddypress/group.php' ); 59 } 72 60 } 73 61 … … 76 64 */ 77 65 public function setup_components() { 78 bbpress()->extend->activity = new BBP_BuddyPress_Activity; 79 } 80 81 /** 82 * Extension variables 83 * 84 * @since bbPress (r3395) 85 * @access private 86 * @uses apply_filters() Calls various filters 87 */ 88 private function setup_globals() { 89 $this->forums_slug = 'forums'; 90 $this->topic_slug = 'topic'; 91 $this->reply_slug = 'reply'; 66 67 // Create the new BuddyPress Forums component 68 if ( ! bp_is_active( 'forums' ) || ! bp_forums_is_installed_correctly() ) { 69 buddypress()->forums = new BBP_Forums_Component(); 70 } 71 72 // Create new activity class 73 if ( bp_is_active( 'activity' ) ) { 74 bbpress()->extend->activity = new BBP_BuddyPress_Activity; 75 } 76 77 // Register the group extension only if groups are active 78 if ( bbp_is_group_forums_active() && bp_is_active( 'groups' ) ) { 79 bp_register_group_extension( 'BBP_Forums_Group_Extension' ); 80 } 92 81 } 93 82 … … 101 90 */ 102 91 private function setup_actions() { 103 add_action( 'template_redirect', array( $this, 'redirect_canonical' ) ); 92 93 // Setup the components 94 add_action( 'bp_init', array( $this, 'setup_components' ) ); 95 96 /** Favorites *********************************************************/ 97 98 // Move handler to 'bp_actions' - BuddyPress bypasses template_loader 99 remove_action( 'template_redirect', 'bbp_favorites_handler', 1 ); 100 add_action( 'bp_actions', 'bbp_favorites_handler', 1 ); 101 102 /** Subscriptions *****************************************************/ 103 104 // Move handler to 'bp_actions' - BuddyPress bypasses template_loader 105 remove_action( 'template_redirect', 'bbp_subscriptions_handler', 1 ); 106 add_action( 'bp_actions', 'bbp_subscriptions_handler', 1 ); 104 107 } 105 108 … … 114 117 private function setup_filters() { 115 118 116 // Map forum/topic/replys permalinks to their groups 117 add_filter( 'bbp_get_forum_permalink', array( $this, 'map_forum_permalink_to_group' ), 10, 2 ); 118 add_filter( 'bbp_get_topic_permalink', array( $this, 'map_topic_permalink_to_group' ), 10, 2 ); 119 add_filter( 'bbp_get_reply_permalink', array( $this, 'map_reply_permalink_to_group' ), 10, 2 ); 120 121 // Map reply edit links to their groups 122 add_filter( 'bbp_get_reply_edit_url', array( $this, 'map_reply_edit_url_to_group' ), 10, 2 ); 123 124 // Map assorted template function permalinks 125 add_filter( 'post_link', array( $this, 'post_link' ), 10, 2 ); 126 add_filter( 'page_link', array( $this, 'page_link' ), 10, 2 ); 127 add_filter( 'post_type_link', array( $this, 'post_type_link' ), 10, 2 ); 128 129 // Group forum pagination 130 add_filter( 'bbp_topic_pagination', array( $this, 'topic_pagination' ) ); 131 add_filter( 'bbp_replies_pagination', array( $this, 'replies_pagination' ) ); 119 // Override bbPress user profile URL with BuddyPress profile URL 120 add_filter( 'bbp_pre_get_user_profile_url', array( $this, 'user_profile_url' ) ); 121 add_filter( 'bbp_get_favorites_permalink', array( $this, 'get_favorites_permalink' ), 10, 2 ); 122 add_filter( 'bbp_get_subscriptions_permalink', array( $this, 'get_subscriptions_permalink' ), 10, 2 ); 132 123 } 133 124 … … 141 132 do_action_ref_array( 'bbp_buddypress_loaded', array( $this ) ); 142 133 } 143 144 /** Permalink Mappers *****************************************************/ 145 146 /** 147 * Maybe map a bbPress forum/topic/reply permalink to the corresponding group 148 * 149 * @param int $post_id 150 * @uses get_post() 151 * @uses bbp_is_reply() 152 * @uses bbp_get_reply_topic_id() 153 * @uses bbp_get_reply_forum_id() 154 * @uses bbp_is_topic() 155 * @uses bbp_get_topic_forum_id() 156 * @uses bbp_is_forum() 157 * @uses get_post_field() 158 * @uses bbp_get_forum_group_ids() 159 * @uses groups_get_group() 160 * @uses bp_get_group_admin_permalink() 161 * @uses bp_get_group_permalink() 162 * @return Bail early if not a group forum post 134 135 /** 136 * Override bbPress profile URL with BuddyPress profile URL 137 * 138 * @since bbPress (r3401) 139 * @param string $url 140 * @param int $user_id 141 * @param string $user_nicename 163 142 * @return string 164 143 */ 165 private function maybe_map_permalink_to_group( $post_id = 0, $url = false ) { 166 167 switch ( get_post_type( $post_id ) ) { 168 169 // Reply 170 case bbp_get_reply_post_type() : 171 $topic_id = bbp_get_reply_topic_id( $post_id ); 172 $forum_id = bbp_get_reply_forum_id( $post_id ); 173 $url_end = trailingslashit( $this->reply_slug ) . get_post_field( 'post_name', $post_id ); 174 break; 175 176 // Topic 177 case bbp_get_topic_post_type() : 178 $topic_id = $post_id; 179 $forum_id = bbp_get_topic_forum_id( $post_id ); 180 $url_end = trailingslashit( $this->topic_slug ) . get_post_field( 'post_name', $post_id ); 181 break; 182 183 // Forum 184 case bbp_get_forum_post_type() : 185 $forum_id = $post_id; 186 $url_end = get_post_field( 'post_name', $post_id ); 187 break; 188 189 // Unknown 190 default : 191 return $url; 192 break; 193 } 194 195 // Get group ID's for this forum 196 $group_ids = bbp_get_forum_group_ids( $forum_id ); 197 198 // Bail if the post isn't associated with a group 199 if ( empty( $group_ids ) ) 200 return $url; 201 202 // @todo Multiple group forums/forum groups 203 $group_id = $group_ids[0]; 204 $group = groups_get_group( array( 'group_id' => $group_id ) ); 205 206 if ( bp_is_group_admin_screen( $this->forums_slug ) ) { 207 $group_permalink = trailingslashit( bp_get_group_admin_permalink( $group ) ); 144 public function user_profile_url( $user_id ) { 145 146 // Define local variable(s) 147 $profile_url = ''; 148 149 // Special handling for forum component 150 if ( bp_is_current_component( 'forums' ) ) { 151 152 // Empty action or 'topics' action 153 if ( !bp_current_action() || bp_is_current_action( 'topics' ) ) { 154 $profile_url = bp_core_get_user_domain( $user_id ) . 'forums/topics'; 155 156 // Empty action or 'topics' action 157 } elseif ( bp_is_current_action( 'replies' ) ) { 158 $profile_url = bp_core_get_user_domain( $user_id ) . 'forums/replies'; 159 160 // 'favorites' action 161 } elseif ( bbp_is_favorites_active() && bp_is_current_action( 'favorites' ) ) { 162 $profile_url = $this->get_favorites_permalink( '', $user_id ); 163 164 // 'subscriptions' action 165 } elseif ( bbp_is_subscriptions_active() && bp_is_current_action( 'subscriptions' ) ) { 166 $profile_url = $this->get_subscriptions_permalink( '', $user_id ); 167 } 168 169 // Not in users' forums area 208 170 } else { 209 $ group_permalink = trailingslashit( bp_get_group_permalink( $group ));210 } 211 212 return trailingslashit( trailingslashit( $group_permalink . $this->forums_slug ) . $url_end);213 } 214 215 /** 216 * Map a forum permalink to its corresponding group217 * 218 * @since bbPress (r3 802)171 $profile_url = bp_core_get_user_domain( $user_id ); 172 } 173 174 return trailingslashit( $profile_url ); 175 } 176 177 /** 178 * Override bbPress favorites URL with BuddyPress profile URL 179 * 180 * @since bbPress (r3721) 219 181 * @param string $url 220 * @param int $forum_id 221 * @uses maybe_map_permalink_to_group() 182 * @param int $user_id 222 183 * @return string 223 184 */ 224 public function map_forum_permalink_to_group( $url, $forum_id ) { 225 return $this->maybe_map_permalink_to_group( $forum_id, $url ); 226 } 227 228 /** 229 * Map a topic permalink to its group forum 230 * 231 * @since bbPress (r3802) 185 public function get_favorites_permalink( $url, $user_id ) { 186 $url = trailingslashit( bp_core_get_user_domain( $user_id ) . 'forums/favorites' ); 187 return $url; 188 } 189 190 /** 191 * Override bbPress subscriptions URL with BuddyPress profile URL 192 * 193 * @since bbPress (r3721) 232 194 * @param string $url 233 * @param int $topic_id 234 * @uses maybe_map_permalink_to_group() 195 * @param int $user_id 235 196 * @return string 236 197 */ 237 public function map_topic_permalink_to_group( $url, $topic_id ) { 238 return $this->maybe_map_permalink_to_group( $topic_id, $url ); 239 } 240 241 /** 242 * Map a reply permalink to its group forum 243 * 244 * @since bbPress (r3802) 245 * @param string $url 246 * @param int $reply_id 247 * @uses maybe_map_permalink_to_group() 248 * @return string 249 */ 250 public function map_reply_permalink_to_group( $url, $reply_id ) { 251 return $this->maybe_map_permalink_to_group( bbp_get_reply_topic_id( $reply_id ), $url ); 252 } 253 254 /** 255 * Map a reply edit link to its group forum 256 * 257 * @param string $url 258 * @param int $reply_id 259 * @uses maybe_map_permalink_to_group() 260 * @return string 261 */ 262 public function map_reply_edit_url_to_group( $url, $reply_id ) { 263 $new = $this->maybe_map_permalink_to_group( $reply_id ); 264 265 if ( empty( $new ) ) 266 return $url; 267 268 return trailingslashit( $new ) . bbpress()->edit_id . '/'; 269 } 270 271 /** 272 * Map a post link to its group forum 273 * 274 * @param string $url 275 * @param obj $post 276 * @param boolean $leavename 277 * @uses maybe_map_permalink_to_group() 278 * @return string 279 */ 280 public function post_link( $url, $post ) { 281 return $this->maybe_map_permalink_to_group( $post->ID, $url ); 282 } 283 284 /** 285 * Map a page link to its group forum 286 * 287 * @param string $url 288 * @param int $post_id 289 * @param $sample 290 * @uses maybe_map_permalink_to_group() 291 * @return string 292 */ 293 public function page_link( $url, $post_id ) { 294 return $this->maybe_map_permalink_to_group( $post_id, $url ); 295 } 296 297 /** 298 * Map a custom post type link to its group forum 299 * 300 * @param string $url 301 * @param obj $post 302 * @param $leavename 303 * @param $sample 304 * @uses maybe_map_permalink_to_group() 305 * @return string 306 */ 307 public function post_type_link( $url, $post ) { 308 return $this->maybe_map_permalink_to_group( $post->ID, $url ); 309 } 310 311 /** 312 * Fix pagination of topics on forum view 313 * 314 * @param array $args 315 * @global $wp_rewrite 316 * @uses bbp_get_forum_id() 317 * @uses maybe_map_permalink_to_group 318 * @return array 319 */ 320 public function topic_pagination( $args ) { 321 $new = $this->maybe_map_permalink_to_group( bbp_get_forum_id() ); 322 323 if ( empty( $new ) ) 324 return $args; 325 326 global $wp_rewrite; 327 328 $args['base'] = trailingslashit( $new ) . $wp_rewrite->pagination_base . '/%#%/'; 329 330 return $args; 331 } 332 333 /** 334 * Fix pagination of replies on topic view 335 * 336 * @param array $args 337 * @global $wp_rewrite 338 * @uses bbp_get_topic_id() 339 * @uses maybe_map_permalink_to_group 340 * @return array 341 */ 342 public function replies_pagination( $args ) { 343 $new = $this->maybe_map_permalink_to_group( bbp_get_topic_id() ); 344 if ( empty( $new ) ) 345 return $args; 346 347 global $wp_rewrite; 348 349 $args['base'] = trailingslashit( $new ) . $wp_rewrite->pagination_base . '/%#%/'; 350 351 return $args; 352 } 353 354 /** 355 * Ensure that forum content associated with a BuddyPress group can only be 356 * viewed via the group URL. 357 * 358 * @since bbPress (r3802) 359 */ 360 function redirect_canonical() { 361 362 // Viewing a single forum 363 if ( bbp_is_single_forum() ) { 364 $forum_id = get_the_ID(); 365 $group_ids = bbp_get_forum_group_ids( $forum_id ); 366 367 // Viewing a single topic 368 } elseif ( bbp_is_single_topic() ) { 369 $topic_id = get_the_ID(); 370 $slug = get_post_field( 'post_name', $topic_id ); 371 $forum_id = bbp_get_topic_forum_id( $topic_id ); 372 $group_ids = bbp_get_forum_group_ids( $forum_id ); 373 374 // Not a forum or topic 375 } else { 376 return; 377 } 378 379 // Bail if not a group forum 380 if ( empty( $group_ids ) ) 381 return; 382 383 // Use the first group ID 384 $group_id = $group_ids[0]; 385 $group = groups_get_group( array( 'group_id' => $group_id ) ); 386 $group_link = trailingslashit( bp_get_group_permalink( $group ) ); 387 $redirect_to = trailingslashit( $group_link . $this->forums_slug ); 388 389 // Add topic slug to URL 390 if ( bbp_is_single_topic() ) { 391 $redirect_to = trailingslashit( $redirect_to . $this->topic_slug . '/' . $slug ); 392 } 393 394 bp_core_redirect( $redirect_to ); 198 public function get_subscriptions_permalink( $url, $user_id ) { 199 $url = trailingslashit( bp_core_get_user_domain( $user_id ) . 'forums/subscriptions' ); 200 return $url; 395 201 } 396 202 } 397 203 endif; 398 399 /**400 * Creates the Forums component in BuddyPress401 *402 * @since bbPress (r3653)403 *404 * @global type $bp405 * @return If bbPress is not active406 */407 function bbp_setup_buddypress_component() {408 global $bp;409 410 // Bail if no BuddyPress411 if ( !empty( $bp->maintenance_mode ) || !defined( 'BP_VERSION' ) ) return;412 413 // Bail if BuddyPress Forums are already active414 if ( bp_is_active( 'forums' ) && bp_forums_is_installed_correctly() ) return;415 416 // Create the new BuddyPress Forums component417 $bp->forums = new BBP_Forums_Component();418 419 // Register the group extension only if groups are active420 if ( bbp_is_group_forums_active() && bp_is_active( 'groups' ) ) {421 bp_register_group_extension( 'BBP_Forums_Group_Extension' );422 }423 }
Note: See TracChangeset
for help on using the changeset viewer.