PluginProbe
bbPress / 2.6.6
bbPress v2.6.6
2.6.17 trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 All 72 releases
← All changes | includes/users/options.php +133 -68 2.2.12.6.6 View file →
@@ -7,25 +7,24 @@
7 7 * @subpackage UserOptions
8 8 */
9 9
10 10 // Exit if accessed directly
11 -if ( !defined( 'ABSPATH' ) ) exit;
11 +defined( 'ABSPATH' ) || exit;
12 12
13 13 /**
14 14 * Get the default user options and their values
15 15 *
16 - * @since bbPress (r3910)
16 + * @since 2.1.0 bbPress (r3910)
17 + *
17 18 * @return array Filtered user option names and values
18 19 */
19 20 function bbp_get_default_user_options() {
20 21
21 - // Default options
22 - return apply_filters( 'bbp_get_default_user_options', array(
23 - '_bbp_last_posted' => '0', // For checking flooding
24 - '_bbp_topic_count' => '0', // Total topics per site
25 - '_bbp_reply_count' => '0', // Total replies per site
26 - '_bbp_favorites' => '', // Favorite topics per site
27 - '_bbp_subscriptions' => '' // Subscribed topics per site
22 + // Filter & return
23 + return (array) apply_filters( 'bbp_get_default_user_options', array(
24 + '_bbp_last_posted' => '0', // For checking flooding
25 + '_bbp_topic_count' => '0', // Total topics per site
26 + '_bbp_reply_count' => '0' // Total replies per site
28 27 ) );
29 28 }
30 29
31 30 /**
@@ -32,23 +31,22 @@
32 31 * Add default user options
33 32 *
34 33 * This is destructive, so existing bbPress user options will be overridden.
35 34 *
36 - * @since bbPress (r3910)
37 - * @uses bbp_get_default_user_options() To get default options
38 - * @uses update_user_option() Adds default options
39 - * @uses do_action() Calls 'bbp_add_user_options'
35 + * @since 2.1.0 bbPress (r3910)
40 36 */
41 37 function bbp_add_user_options( $user_id = 0 ) {
42 38
43 39 // Validate user id
44 40 $user_id = bbp_get_user_id( $user_id );
45 - if ( empty( $user_id ) )
41 + if ( empty( $user_id ) ) {
46 42 return;
43 + }
47 44
48 45 // Add default options
49 - foreach ( bbp_get_default_user_options() as $key => $value )
46 + foreach ( bbp_get_default_user_options() as $key => $value ) {
50 47 update_user_option( $user_id, $key, $value );
48 + }
51 49
52 50 // Allow previously activated plugins to append their own user options.
53 51 do_action( 'bbp_add_user_options', $user_id );
54 52 }
@@ -58,23 +56,22 @@
58 56 *
59 57 * Hooked to bbp_uninstall, it is only called once when bbPress is uninstalled.
60 58 * This is destructive, so existing bbPress user options will be destroyed.
61 59 *
62 - * @since bbPress (r3910)
63 - * @uses bbp_get_default_user_options() To get default options
64 - * @uses delete_user_option() Removes default options
65 - * @uses do_action() Calls 'bbp_delete_options'
60 + * @since 2.1.0 bbPress (r3910)
66 61 */
67 62 function bbp_delete_user_options( $user_id = 0 ) {
68 63
69 64 // Validate user id
70 65 $user_id = bbp_get_user_id( $user_id );
71 - if ( empty( $user_id ) )
66 + if ( empty( $user_id ) ) {
72 67 return;
68 + }
73 69
74 70 // Add default options
75 - foreach ( bbp_get_default_user_options() as $key => $value )
71 + foreach ( array_keys( bbp_get_default_user_options() ) as $key ) {
76 72 delete_user_option( $user_id, $key );
73 + }
77 74
78 75 // Allow previously activated plugins to append their own options.
79 76 do_action( 'bbp_delete_user_options', $user_id );
80 77 }
@@ -82,18 +79,16 @@
82 79 /**
83 80 * Add filters to each bbPress option and allow them to be overloaded from
84 81 * inside the $bbp->options array.
85 82 *
86 - * @since bbPress (r3910)
87 - * @uses bbp_get_default_user_options() To get default options
88 - * @uses add_filter() To add filters to 'pre_option_{$key}'
89 - * @uses do_action() Calls 'bbp_add_option_filters'
83 + * @since 2.1.0 bbPress (r3910)
90 84 */
91 85 function bbp_setup_user_option_filters() {
92 86
93 87 // Add filters to each bbPress option
94 - foreach ( bbp_get_default_user_options() as $key => $value )
88 + foreach ( array_keys( bbp_get_default_user_options() ) as $key ) {
95 89 add_filter( 'get_user_option_' . $key, 'bbp_filter_get_user_option', 10, 3 );
90 + }
96 91
97 92 // Allow previously activated plugins to append their own options.
98 93 do_action( 'bbp_setup_user_option_filters' );
99 94 }
@@ -101,9 +96,10 @@
101 96 /**
102 97 * Filter default options and allow them to be overloaded from inside the
103 98 * $bbp->user_options array.
104 99 *
105 - * @since bbPress (r3910)
100 + * @since 2.1.0 bbPress (r3910)
101 + *
106 102 * @param bool $value Optional. Default value false
107 103 * @return mixed false if not overloaded, mixed if set
108 104 */
109 105 function bbp_filter_get_user_option( $value = false, $option = '', $user = 0 ) {
@@ -109,10 +105,11 @@
109 105 function bbp_filter_get_user_option( $value = false, $option = '', $user = 0 ) {
110 106 $bbp = bbpress();
111 107
112 108 // Check the options global for preset value
113 - if ( isset( $user->ID ) && isset( $bbp->user_options[$user->ID] ) && !empty( $bbp->user_options[$user->ID][$option] ) )
114 - $value = $bbp->user_options[$user->ID][$option];
109 + if ( isset( $user->ID ) && isset( $bbp->user_options[ $user->ID ] ) && ! empty( $bbp->user_options[ $user->ID ][ $option ] ) ) {
110 + $value = $bbp->user_options[ $user->ID ][ $option ];
111 + }
115 112
116 113 // Always return a value, even if false
117 114 return $value;
118 115 }
@@ -119,30 +116,86 @@
119 116
120 117 /** Post Counts ***************************************************************/
121 118
122 119 /**
120 + * Update the topic count for a user
121 + *
122 + * @since 2.6.0 bbPress (r5309)
123 + *
124 + * @param int $user_id
125 + * @param mixed $count
126 + * @return boolean
127 + */
128 +function bbp_update_user_topic_count( $user_id = 0, $count = false ) {
129 +
130 + // Validate user id
131 + $user_id = bbp_get_user_id( $user_id );
132 + if ( empty( $user_id ) ) {
133 + return false;
134 + }
135 +
136 + // Just in time filtering of the user's topic count
137 + $count = apply_filters( 'bbp_update_user_topic_count', $count, $user_id );
138 +
139 + // Bail if no count was passed
140 + if ( false === $count ) {
141 + return false;
142 + }
143 +
144 + // Return the updated user option
145 + return update_user_option( $user_id, '_bbp_topic_count', $count );
146 +}
147 +
148 +/**
149 + * Update the reply count for a user
150 + *
151 + * @since 2.6.0 bbPress (r5309)
152 + *
153 + * @param int $user_id
154 + * @param mixed $count
155 + * @return boolean
156 + */
157 +function bbp_update_user_reply_count( $user_id = 0, $count = false ) {
158 +
159 + // Validate user id
160 + $user_id = bbp_get_user_id( $user_id );
161 + if ( empty( $user_id ) ) {
162 + return false;
163 + }
164 +
165 + // Just in time filtering of the user's reply count
166 + $count = apply_filters( 'bbp_update_user_reply_count', $count, $user_id );
167 +
168 + // Bail if no count was passed
169 + if ( false === $count ) {
170 + return false;
171 + }
172 +
173 + // Return the updated user option
174 + return update_user_option( $user_id, '_bbp_reply_count', $count );
175 +}
176 +
177 +/**
123 178 * Output a users topic count
124 179 *
125 - * @since bbPress (r3632)
180 + * @since 2.1.0 bbPress (r3632)
126 181 *
127 182 * @param int $user_id
128 183 * @param boolean $integer Optional. Whether or not to format the result
129 - * @uses bbp_get_user_topic_count()
184 + *
130 185 * @return string
131 186 */
132 187 function bbp_user_topic_count( $user_id = 0, $integer = false ) {
133 - echo bbp_get_user_topic_count( $user_id, $integer );
188 + echo esc_html( bbp_get_user_topic_count( $user_id, $integer ) );
134 189 }
135 190 /**
136 191 * Return a users reply count
137 192 *
138 - * @since bbPress (r3632)
193 + * @since 2.1.0 bbPress (r3632)
139 194 *
140 195 * @param int $user_id
141 196 * @param boolean $integer Optional. Whether or not to format the result
142 - * @uses bbp_get_user_id()
143 - * @uses get_user_option()
144 - * @uses apply_filters()
197 + *
145 198 * @return string
146 199 */
147 200 function bbp_get_user_topic_count( $user_id = 0, $integer = false ) {
148 201
@@ -147,14 +200,18 @@
147 200 function bbp_get_user_topic_count( $user_id = 0, $integer = false ) {
148 201
149 202 // Validate user id
150 203 $user_id = bbp_get_user_id( $user_id );
151 - if ( empty( $user_id ) )
204 + if ( empty( $user_id ) ) {
152 205 return false;
206 + }
153 207
154 - $count = (int) get_user_option( '_bbp_topic_count', $user_id );
155 - $filter = ( false == $integer ) ? 'bbp_get_user_topic_count_int' : 'bbp_get_user_topic_count';
208 + $count = get_user_option( '_bbp_topic_count', $user_id );
209 + $filter = ( true === $integer )
210 + ? 'bbp_get_user_topic_count_int'
211 + : 'bbp_get_user_topic_count';
156 212
213 + // Filter & return
157 214 return apply_filters( $filter, $count, $user_id );
158 215 }
159 216
160 217 /**
@@ -159,28 +216,26 @@
159 216
160 217 /**
161 218 * Output a users reply count
162 219 *
163 - * @since bbPress (r3632)
220 + * @since 2.1.0 bbPress (r3632)
164 221 *
165 222 * @param int $user_id
166 223 * @param boolean $integer Optional. Whether or not to format the result
167 - * @uses bbp_get_user_reply_count()
224 + *
168 225 * @return string
169 226 */
170 227 function bbp_user_reply_count( $user_id = 0, $integer = false ) {
171 - echo bbp_get_user_reply_count( $user_id, $integer );
228 + echo esc_html( bbp_get_user_reply_count( $user_id, $integer ) );
172 229 }
173 230 /**
174 231 * Return a users reply count
175 232 *
176 - * @since bbPress (r3632)
233 + * @since 2.1.0 bbPress (r3632)
177 234 *
178 235 * @param int $user_id
179 236 * @param boolean $integer Optional. Whether or not to format the result
180 - * @uses bbp_get_user_id()
181 - * @uses get_user_option()
182 - * @uses apply_filters()
237 + *
183 238 * @return string
184 239 */
185 240 function bbp_get_user_reply_count( $user_id = 0, $integer = false ) {
186 241
@@ -185,13 +240,16 @@
185 240 function bbp_get_user_reply_count( $user_id = 0, $integer = false ) {
186 241
187 242 // Validate user id
188 243 $user_id = bbp_get_user_id( $user_id );
189 - if ( empty( $user_id ) )
244 + if ( empty( $user_id ) ) {
190 245 return false;
246 + }
191 247
192 - $count = (int) get_user_option( '_bbp_reply_count', $user_id );
193 - $filter = ( true == $integer ) ? 'bbp_get_user_topic_count_int' : 'bbp_get_user_topic_count';
248 + $count = get_user_option( '_bbp_reply_count', $user_id );
249 + $filter = ( true === $integer )
250 + ? 'bbp_get_user_reply_count_int'
251 + : 'bbp_get_user_reply_count';
194 252
195 253 return apply_filters( $filter, $count, $user_id );
196 254 }
197 255
@@ -197,28 +255,26 @@
197 255
198 256 /**
199 257 * Output a users total post count
200 258 *
201 - * @since bbPress (r3632)
259 + * @since 2.1.0 bbPress (r3632)
202 260 *
203 261 * @param int $user_id
204 262 * @param boolean $integer Optional. Whether or not to format the result
205 - * @uses bbp_get_user_post_count()
263 + *
206 264 * @return string
207 265 */
208 266 function bbp_user_post_count( $user_id = 0, $integer = false ) {
209 - echo bbp_get_user_post_count( $user_id, $integer );
267 + echo esc_html( bbp_get_user_post_count( $user_id, $integer ) );
210 268 }
211 269 /**
212 270 * Return a users total post count
213 271 *
214 - * @since bbPress (r3632)
272 + * @since 2.1.0 bbPress (r3632)
215 273 *
216 274 * @param int $user_id
217 275 * @param boolean $integer Optional. Whether or not to format the result
218 - * @uses bbp_get_user_id()
219 - * @uses get_user_option()
220 - * @uses apply_filters()
276 + *
221 277 * @return string
222 278 */
223 279 function bbp_get_user_post_count( $user_id = 0, $integer = false ) {
224 280
@@ -223,15 +279,18 @@
223 279 function bbp_get_user_post_count( $user_id = 0, $integer = false ) {
224 280
225 281 // Validate user id
226 282 $user_id = bbp_get_user_id( $user_id );
227 - if ( empty( $user_id ) )
283 + if ( empty( $user_id ) ) {
228 284 return false;
285 + }
229 286
230 287 $topics = bbp_get_user_topic_count( $user_id, true );
231 288 $replies = bbp_get_user_reply_count( $user_id, true );
232 - $count = (int) $topics + $replies;
233 - $filter = ( true == $integer ) ? 'bbp_get_user_post_count_int' : 'bbp_get_user_post_count';
289 + $count = $topics + $replies;
290 + $filter = ( true === $integer )
291 + ? 'bbp_get_user_post_count_int'
292 + : 'bbp_get_user_post_count';
234 293
235 294 return apply_filters( $filter, $count, $user_id );
236 295 }
237 296
@@ -239,9 +298,10 @@
239 298
240 299 /**
241 300 * Update a users last posted time, for use with post throttling
242 301 *
243 - * @since bbPress (r3910)
302 + * @since 2.1.0 bbPress (r3910)
303 + *
244 304 * @param int $user_id User ID to update
245 305 * @param int $time Time in time() format
246 306 * @return bool False if no user or failure, true if successful
247 307 */
@@ -248,14 +308,16 @@
248 308 function bbp_update_user_last_posted( $user_id = 0, $time = 0 ) {
249 309
250 310 // Validate user id
251 311 $user_id = bbp_get_user_id( $user_id );
252 - if ( empty( $user_id ) )
312 + if ( empty( $user_id ) ) {
253 313 return false;
314 + }
254 315
255 316 // Set time to now if nothing is passed
256 - if ( empty( $time ) )
317 + if ( empty( $time ) ) {
257 318 $time = time();
319 + }
258 320
259 321 return update_user_option( $user_id, '_bbp_last_posted', $time );
260 322 }
261 323
@@ -261,20 +323,21 @@
261 323
262 324 /**
263 325 * Output the raw value of the last posted time.
264 326 *
265 - * @since bbPress (r3910)
327 + * @since 2.1.0 bbPress (r3910)
328 + *
266 329 * @param int $user_id User ID to retrieve value for
267 - * @uses bbp_get_user_last_posted() To output the last posted time
268 330 */
269 331 function bbp_user_last_posted( $user_id = 0 ) {
270 - echo bbp_get_user_last_posted( $user_id );
332 + echo esc_html( bbp_get_user_last_posted( $user_id ) );
271 333 }
272 334
273 335 /**
274 - * Return the raw value of teh last posted time.
336 + * Return the raw value of the last posted time.
275 337 *
276 - * @since bbPress (r3910)
338 + * @since 2.1.0 bbPress (r3910)
339 + *
277 340 * @param int $user_id User ID to retrieve value for
278 341 * @return mixed False if no user, time() format if exists
279 342 */
280 343 function bbp_get_user_last_posted( $user_id = 0 ) {
@@ -280,11 +343,13 @@
280 343 function bbp_get_user_last_posted( $user_id = 0 ) {
281 344
282 345 // Validate user id
283 346 $user_id = bbp_get_user_id( $user_id );
284 - if ( empty( $user_id ) )
347 + if ( empty( $user_id ) ) {
285 348 return false;
349 + }
286 350
287 351 $time = get_user_option( '_bbp_last_posted', $user_id );
288 352
353 + // Filter & return
289 354 return apply_filters( 'bbp_get_user_last_posted', $time, $user_id );
290 355 }