PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.5.0
Forumax – AI Powered Advanced Community Forum Plugin v2.5.0
2.5.0 2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 All 30 releases
bbp-core / lib / bbpress / includes / extend / buddypress / members.php

members.php in Forumax – AI Powered Advanced Community Forum Plugin 2.5.0, at lib/bbpress/includes/extend/buddypress/members.php

251 lines 6.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress BuddyPress Members Class
5 *
6 * @package bbPress
7 * @subpackage BuddyPress
8 */
9
10 // Exit if accessed directly
11 defined( 'ABSPATH' ) || exit;
12
13 if ( ! class_exists( 'BBP_Forums_Members' ) ) :
14 /**
15 * Member profile modifications
16 *
17 * @since 2.2.0 bbPress (r4395)
18 * @since 2.6.0 bbPress (r6320) Add engagements support
19 *
20 * @package bbPress
21 * @subpackage BuddyPress
22 */
23 class BBP_BuddyPress_Members {
24
25 /**
26 * Main constructor for modifying bbPress profile links
27 *
28 * @since 2.2.0 bbPress (r4395)
29 */
30 public function __construct() {
31 $this->setup_actions();
32 $this->setup_filters();
33 $this->fully_loaded();
34 }
35
36 /**
37 * Setup the actions
38 *
39 * @since 2.2.0 bbPress (r4395)
40 *
41 * @access private
42 */
43 private function setup_actions() {
44
45 // Allow unsubscribe/unfavorite links to work
46 add_action( 'bp_template_redirect', array( $this, 'set_member_forum_query_vars' ) );
47
48 /** Favorites *********************************************************/
49
50 // Move handler to 'bp_actions' - BuddyPress bypasses template_loader
51 remove_action( 'bbp_get_request', 'bbp_favorites_handler', 1 );
52 add_action( 'bp_actions', 'bbp_favorites_handler', 1 );
53
54 /** Subscriptions *****************************************************/
55
56 // Move handler to 'bp_actions' - BuddyPress bypasses template_loader
57 remove_action( 'bbp_get_request', 'bbp_subscriptions_handler', 1 );
58 add_action( 'bp_actions', 'bbp_subscriptions_handler', 1 );
59 }
60
61 /**
62 * Setup the filters
63 *
64 * @since 2.2.0 bbPress (r4395)
65 * @since 2.6.0 bbPress (r6320) Add engagements support
66 *
67 * @access private
68 */
69 private function setup_filters() {
70 add_filter( 'bbp_pre_get_user_profile_url', array( $this, 'get_user_profile_url' ) );
71 add_filter( 'bbp_pre_get_user_topics_created_url', array( $this, 'get_topics_created_url' ) );
72 add_filter( 'bbp_pre_get_user_replies_created_url', array( $this, 'get_replies_created_url' ) );
73 add_filter( 'bbp_pre_get_user_engagements_url', array( $this, 'get_engagements_permalink' ) );
74 add_filter( 'bbp_pre_get_favorites_permalink', array( $this, 'get_favorites_permalink' ) );
75 add_filter( 'bbp_pre_get_subscriptions_permalink', array( $this, 'get_subscriptions_permalink' ) );
76 }
77
78 /**
79 * Allow the variables, actions, and filters to be modified by third party
80 * plugins and themes.
81 *
82 * @since 2.6.0 bbPress (r6808)
83 */
84 private function fully_loaded() {
85 do_action_ref_array( 'bbp_buddypress_members_loaded', array( $this ) );
86 }
87
88 /** Filters ***************************************************************/
89
90 /**
91 * Override bbPress profile URL with BuddyPress profile URL
92 *
93 * @since 2.0.0 bbPress (r3401)
94 * @since 2.6.0 bbPress (r6320) Add engagements support
95 *
96 * @param int $user_id
97 * @return string
98 */
99 public function get_user_profile_url( $user_id = 0 ) {
100 return $this->get_profile_url( $user_id );
101 }
102
103 /**
104 * Override bbPress topics created URL with BuddyPress profile URL
105 *
106 * @since 2.6.0 bbPress (r3721)
107 * @since 2.6.0 bbPress (r6803) Use private method
108 *
109 * @param int $user_id
110 * @return string
111 */
112 public function get_topics_created_url( $user_id = 0 ) {
113 return $this->get_profile_url( $user_id, bbp_get_topic_archive_slug() );
114 }
115
116 /**
117 * Override bbPress replies created URL with BuddyPress profile URL
118 *
119 * @since 2.6.0 bbPress (r3721)
120 * @since 2.6.0 bbPress (r6803) Use private method
121 *
122 * @param int $user_id
123 * @return string
124 */
125 public function get_replies_created_url( $user_id = 0 ) {
126 return $this->get_profile_url( $user_id, bbp_get_reply_archive_slug() );
127 }
128
129 /**
130 * Override bbPress favorites URL with BuddyPress profile URL
131 *
132 * @since 2.1.0 bbPress (r3721)
133 * @since 2.6.0 bbPress (r6803) Use private method
134 *
135 * @param int $user_id
136 * @return string
137 */
138 public function get_favorites_permalink( $user_id = 0 ) {
139 return $this->get_profile_url( $user_id, bbp_get_user_favorites_slug() );
140 }
141
142 /**
143 * Override bbPress subscriptions URL with BuddyPress profile URL
144 *
145 * @since 2.1.0 bbPress (r3721)
146 * @since 2.6.0 bbPress (r6803) Use private method
147 *
148 * @param int $user_id
149 * @return string
150 */
151 public function get_subscriptions_permalink( $user_id = 0 ) {
152 return $this->get_profile_url( $user_id, bbp_get_user_subscriptions_slug() );
153 }
154
155 /**
156 * Override bbPress engagements URL with BuddyPress profile URL
157 *
158 * @since 2.6.0 bbPress (r6320)
159 *
160 * @param int $user_id
161 * @return string
162 */
163 public function get_engagements_permalink( $user_id = 0 ) {
164 return $this->get_profile_url( $user_id, bbp_get_user_engagements_slug() );
165 }
166
167 /**
168 * Set favorites and subscriptions query variables if viewing member profile
169 * pages.
170 *
171 * @since 2.3.0 bbPress (r4615)
172 * @since 2.6.0 bbPress (r6320) Support all profile sections
173 *
174 * @global WP_Query $wp_query
175 * @return If not viewing your own profile
176 */
177 public function set_member_forum_query_vars() {
178
179 // Special handling for forum component
180 if ( ! bp_is_my_profile() ) {
181 return;
182 }
183
184 // Get the main query object
185 $wp_query = bbp_get_wp_query();
186
187 // 'topics' action
188 if ( bp_is_current_action( bbp_get_topic_archive_slug() ) ) {
189 $wp_query->bbp_is_single_user_topics = true;
190
191 // 'replies' action
192 } elseif ( bp_is_current_action( bbp_get_reply_archive_slug() ) ) {
193 $wp_query->bbp_is_single_user_replies = true;
194
195 // 'favorites' action
196 } elseif ( bbp_is_favorites_active() && bp_is_current_action( bbp_get_user_favorites_slug() ) ) {
197 $wp_query->bbp_is_single_user_favs = true;
198
199 // 'subscriptions' action
200 } elseif ( bbp_is_subscriptions_active() && bp_is_current_action( bbp_get_user_subscriptions_slug() ) ) {
201 $wp_query->bbp_is_single_user_subs = true;
202
203 // 'engagements' action
204 } elseif ( bbp_is_engagements_active() && bp_is_current_action( bbp_get_user_engagements_slug() ) ) {
205 $wp_query->bbp_is_single_user_engagements = true;
206 }
207 }
208
209 /** Private Methods *******************************************************/
210
211 /**
212 * Private method used to concatenate user IDs and slugs into URLs
213 *
214 * @since 2.6.0 bbPress (r6803)
215 *
216 * @param int $user_id
217 * @param string $slug
218 *
219 * @return string
220 */
221 private function get_profile_url( $user_id = 0, $slug = '' ) {
222
223 // Do not filter if not on BuddyPress root blog
224 if ( empty( $user_id ) || ! bp_is_root_blog() ) {
225 return false;
226 }
227
228 // Default URL value
229 $url = array();
230
231 // BuddyPress < 12.0 (deprecated code is intentionally included)
232 if ( function_exists( 'bp_core_get_user_domain' ) ) {
233 $url = array( bp_core_get_user_domain( $user_id ) );
234
235 // BuddyPress > 12.0 (rewrite rules)
236 } elseif ( function_exists( 'bp_members_get_user_url' ) ) {
237 $url = array( bp_members_get_user_url( $user_id ) );
238 }
239
240 // Maybe push slug to end of URL array
241 if ( ! empty( $slug ) ) {
242 array_push( $url, bbpress()->extend->buddypress->slug );
243 array_push( $url, $slug );
244 }
245
246 // Return
247 return implode( '', array_map( 'trailingslashit', $url ) );
248 }
249 }
250 endif;
251