BBP_BuddyPress_Members

Member profile modifications.

Defined (1)

The class is defined in the following location(s).

/includes/extend/buddypress/members.php  
  1. class BBP_BuddyPress_Members { 
  2.  
  3. /** 
  4. * Main constructor for modifying bbPress profile links 
  5. * @since bbPress (r4395) 
  6. */ 
  7. public function __construct() { 
  8. $this->setup_actions(); 
  9. $this->setup_filters(); 
  10.  
  11. /** 
  12. * Setup the actions 
  13. * @since bbPress (r4395) 
  14. * @access private 
  15. * @uses add_filter() To add various filters 
  16. * @uses add_action() To add various actions 
  17. */ 
  18. private function setup_actions() { 
  19.  
  20. // Allow unsubscribe/unfavorite links to work 
  21. add_action( 'bp_template_redirect', array( $this, 'set_member_forum_query_vars' ) ); 
  22.  
  23. /** Favorites *********************************************************/ 
  24.  
  25. // Move handler to 'bp_actions' - BuddyPress bypasses template_loader 
  26. remove_action( 'template_redirect', 'bbp_favorites_handler', 1 ); 
  27. add_action( 'bp_actions', 'bbp_favorites_handler', 1 ); 
  28.  
  29. /** Subscriptions *****************************************************/ 
  30.  
  31. // Move handler to 'bp_actions' - BuddyPress bypasses template_loader 
  32. remove_action( 'template_redirect', 'bbp_subscriptions_handler', 1 ); 
  33. add_action( 'bp_actions', 'bbp_subscriptions_handler', 1 ); 
  34.  
  35. /** 
  36. * Setup the filters 
  37. * @since bbPress (r4395) 
  38. * @access private 
  39. * @uses add_filter() To add various filters 
  40. * @uses add_action() To add various actions 
  41. */ 
  42. private function setup_filters() { 
  43. add_filter( 'bbp_pre_get_user_profile_url', array( $this, 'user_profile_url' ) ); 
  44. add_filter( 'bbp_get_favorites_permalink', array( $this, 'get_favorites_permalink' ), 10, 2 ); 
  45. add_filter( 'bbp_get_subscriptions_permalink', array( $this, 'get_subscriptions_permalink' ), 10, 2 ); 
  46.  
  47. /** Filters ***************************************************************/ 
  48.  
  49. /** 
  50. * Override bbPress profile URL with BuddyPress profile URL 
  51. * @since bbPress (r3401) 
  52. * @param string $url 
  53. * @param int $user_id 
  54. * @param string $user_nicename 
  55. * @return string 
  56. */ 
  57. public function user_profile_url( $user_id ) { 
  58.  
  59. // Define local variable(s) 
  60. $profile_url = ''; 
  61. $component_slug = bbpress()->extend->buddypress->slug; 
  62.  
  63. // Special handling for forum component 
  64. if ( bp_is_current_component( $component_slug ) ) { 
  65.  
  66. // Empty action or 'topics' action 
  67. if ( !bp_current_action() || bp_is_current_action( bbp_get_topic_archive_slug() ) ) { 
  68. $profile_url = bp_core_get_user_domain( $user_id ) . $component_slug . '/' . bbp_get_topic_archive_slug(); 
  69.  
  70. // Empty action or 'topics' action 
  71. } elseif ( bp_is_current_action( bbp_get_reply_archive_slug() ) ) { 
  72. $profile_url = bp_core_get_user_domain( $user_id ) . $component_slug . '/' . bbp_get_reply_archive_slug(); 
  73.  
  74. // 'favorites' action 
  75. } elseif ( bbp_is_favorites_active() && bp_is_current_action( bbp_get_user_favorites_slug() ) ) { 
  76. $profile_url = $this->get_favorites_permalink( '', $user_id ); 
  77.  
  78. // 'subscriptions' action 
  79. } elseif ( bbp_is_subscriptions_active() && bp_is_current_action( bbp_get_user_subscriptions_slug() ) ) { 
  80. $profile_url = $this->get_subscriptions_permalink( '', $user_id ); 
  81.  
  82. // Not in users' forums area 
  83. } else { 
  84. $profile_url = bp_core_get_user_domain( $user_id ); 
  85.  
  86. return trailingslashit( $profile_url ); 
  87.  
  88. /** 
  89. * Override bbPress favorites URL with BuddyPress profile URL 
  90. * @since bbPress (r3721) 
  91. * @param string $url 
  92. * @param int $user_id 
  93. * @return string 
  94. */ 
  95. public function get_favorites_permalink( $url, $user_id ) { 
  96. $component_slug = bbpress()->extend->buddypress->slug; 
  97. $url = trailingslashit( bp_core_get_user_domain( $user_id ) . $component_slug . '/' . bbp_get_user_favorites_slug() ); 
  98. return $url; 
  99.  
  100. /** 
  101. * Override bbPress subscriptions URL with BuddyPress profile URL 
  102. * @since bbPress (r3721) 
  103. * @param string $url 
  104. * @param int $user_id 
  105. * @return string 
  106. */ 
  107. public function get_subscriptions_permalink( $url, $user_id ) { 
  108. $component_slug = bbpress()->extend->buddypress->slug; 
  109. $url = trailingslashit( bp_core_get_user_domain( $user_id ) . $component_slug . '/' . bbp_get_user_subscriptions_slug() ); 
  110. return $url; 
  111.  
  112. /** 
  113. * Set favorites and subscriptions query variables if viewing member profile 
  114. * pages. 
  115. * @since bbPress (r4615) 
  116. * @global WP_Query $wp_query 
  117. * @return If not viewing your own profile 
  118. */ 
  119. public function set_member_forum_query_vars() { 
  120.  
  121. // Special handling for forum component 
  122. if ( ! bp_is_my_profile() ) 
  123. return; 
  124.  
  125. global $wp_query; 
  126.  
  127. // 'favorites' action 
  128. if ( bbp_is_favorites_active() && bp_is_current_action( bbp_get_user_favorites_slug() ) ) { 
  129. $wp_query->bbp_is_single_user_favs = true; 
  130.  
  131. // 'subscriptions' action 
  132. } elseif ( bbp_is_subscriptions_active() && bp_is_current_action( bbp_get_user_subscriptions_slug() ) ) { 
  133. $wp_query->bbp_is_single_user_subs = true;