| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * bbPress User Options. | |
| 4 | + * bbPress User Options | |
| 5 | 5 | * |
| 6 | 6 | * @package bbPress |
| 7 | 7 | * @subpackage UserOptions |
| 8 | 8 | */ |
| @@ -10,13 +10,13 @@ | ||
| 10 | 10 | // Exit if accessed directly |
| 11 | 11 | defined( 'ABSPATH' ) || exit; |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | - * Get the default user options and their values. | |
| 14 | + * Get the default user options and their values | |
| 15 | 15 | * |
| 16 | 16 | * @since 2.1.0 bbPress (r3910) |
| 17 | 17 | * |
| 18 | - * @return array Filtered user option names and values. | |
| 18 | + * @return array Filtered user option names and values | |
| 19 | 19 | */ |
| 20 | 20 | function bbp_get_default_user_options() { |
| 21 | 21 | |
| 22 | 22 | // Filter & return |
| @@ -30,9 +30,9 @@ | ||
| 30 | 30 | ); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | - * Add default user options. | |
| 34 | + * Add default user options | |
| 35 | 35 | * |
| 36 | 36 | * This is destructive, so existing bbPress user options will be overridden. |
| 37 | 37 | * |
| 38 | 38 | * @since 2.1.0 bbPress (r3910) |
| @@ -54,9 +54,9 @@ | ||
| 54 | 54 | do_action( 'bbp_add_user_options', $user_id ); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * Delete default user options. | |
| 58 | + * Delete default user options | |
| 59 | 59 | * |
| 60 | 60 | * Hooked to bbp_uninstall, it is only called once when bbPress is uninstalled. |
| 61 | 61 | * This is destructive, so existing bbPress user options will be destroyed. |
| 62 | 62 | * |
| @@ -101,10 +101,10 @@ | ||
| 101 | 101 | * $bbp->user_options array. |
| 102 | 102 | * |
| 103 | 103 | * @since 2.1.0 bbPress (r3910) |
| 104 | 104 | * |
| 105 | - * @param bool $value Optional. Default value false. | |
| 106 | - * @return mixed false if not overloaded, mixed if set. | |
| 105 | + * @param bool $value Optional. Default value false | |
| 106 | + * @return mixed false if not overloaded, mixed if set | |
| 107 | 107 | */ |
| 108 | 108 | function bbp_filter_get_user_option( $value = false, $option = '', $user = 0 ) { |
| 109 | 109 | $bbp = bbpress(); |
| 110 | 110 | |
| @@ -119,9 +119,9 @@ | ||
| 119 | 119 | |
| 120 | 120 | /** Post Counts ***************************************************************/ |
| 121 | 121 | |
| 122 | 122 | /** |
| 123 | - * Update the topic count for a user. | |
| 123 | + * Update the topic count for a user | |
| 124 | 124 | * |
| 125 | 125 | * @since 2.6.0 bbPress (r5309) |
| 126 | 126 | * @since 2.6.17 Support atomic count differences. |
| 127 | 127 | * |
| @@ -201,14 +201,14 @@ | ||
| 201 | 201 | return update_user_option( $user_id, '_bbp_reply_count', $count ); |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
| 205 | - * Output a users topic count. | |
| 205 | + * Output a users topic count | |
| 206 | 206 | * |
| 207 | 207 | * @since 2.1.0 bbPress (r3632) |
| 208 | 208 | * |
| 209 | - * @param int $user_id User id. | |
| 210 | - * @param boolean $integer Optional. Whether or not to format the result. | |
| 209 | + * @param int $user_id | |
| 210 | + * @param boolean $integer Optional. Whether or not to format the result | |
| 211 | 211 | * |
| 212 | 212 | * @return string |
| 213 | 213 | */ |
| 214 | 214 | function bbp_user_topic_count( $user_id = 0, $integer = false ) { |
| @@ -213,43 +213,42 @@ | ||
| 213 | 213 | */ |
| 214 | 214 | function bbp_user_topic_count( $user_id = 0, $integer = false ) { |
| 215 | 215 | echo esc_html( bbp_get_user_topic_count( $user_id, $integer ) ); |
| 216 | 216 | } |
| 217 | + /** | |
| 218 | + * Return a users reply count | |
| 219 | + * | |
| 220 | + * @since 2.1.0 bbPress (r3632) | |
| 221 | + * | |
| 222 | + * @param int $user_id | |
| 223 | + * @param boolean $integer Optional. Whether or not to format the result | |
| 224 | + * | |
| 225 | + * @return string | |
| 226 | + */ | |
| 227 | + function bbp_get_user_topic_count( $user_id = 0, $integer = false ) { | |
| 217 | 228 | |
| 218 | -/** | |
| 219 | - * Return a users reply count. | |
| 220 | - * | |
| 221 | - * @since 2.1.0 bbPress (r3632) | |
| 222 | - * | |
| 223 | - * @param int $user_id User id. | |
| 224 | - * @param boolean $integer Optional. Whether or not to format the result. | |
| 225 | - * | |
| 226 | - * @return string | |
| 227 | - */ | |
| 228 | -function bbp_get_user_topic_count( $user_id = 0, $integer = false ) { | |
| 229 | + // Validate user id | |
| 230 | + $user_id = bbp_get_user_id( $user_id ); | |
| 231 | + if ( empty( $user_id ) ) { | |
| 232 | + return false; | |
| 233 | + } | |
| 229 | 234 | |
| 230 | - // Validate user id | |
| 231 | - $user_id = bbp_get_user_id( $user_id ); | |
| 232 | - if ( empty( $user_id ) ) { | |
| 233 | - return false; | |
| 235 | + $count = get_user_option( '_bbp_topic_count', $user_id ); | |
| 236 | + $filter = ( true === $integer ) | |
| 237 | + ? 'bbp_get_user_topic_count_int' | |
| 238 | + : 'bbp_get_user_topic_count'; | |
| 239 | + | |
| 240 | + // Filter & return | |
| 241 | + return apply_filters( $filter, $count, $user_id ); | |
| 234 | 242 | } |
| 235 | 243 | |
| 236 | - $count = get_user_option( '_bbp_topic_count', $user_id ); | |
| 237 | - $filter = ( true === $integer ) | |
| 238 | - ? 'bbp_get_user_topic_count_int' | |
| 239 | - : 'bbp_get_user_topic_count'; | |
| 240 | - | |
| 241 | - // Filter & return | |
| 242 | - return apply_filters( $filter, $count, $user_id ); | |
| 243 | -} | |
| 244 | - | |
| 245 | 244 | /** |
| 246 | - * Output a users reply count. | |
| 245 | + * Output a users reply count | |
| 247 | 246 | * |
| 248 | 247 | * @since 2.1.0 bbPress (r3632) |
| 249 | 248 | * |
| 250 | - * @param int $user_id User id. | |
| 251 | - * @param boolean $integer Optional. Whether or not to format the result. | |
| 249 | + * @param int $user_id | |
| 250 | + * @param boolean $integer Optional. Whether or not to format the result | |
| 252 | 251 | * |
| 253 | 252 | * @return string |
| 254 | 253 | */ |
| 255 | 254 | function bbp_user_reply_count( $user_id = 0, $integer = false ) { |
| @@ -254,41 +253,40 @@ | ||
| 254 | 253 | */ |
| 255 | 254 | function bbp_user_reply_count( $user_id = 0, $integer = false ) { |
| 256 | 255 | echo esc_html( bbp_get_user_reply_count( $user_id, $integer ) ); |
| 257 | 256 | } |
| 257 | + /** | |
| 258 | + * Return a users reply count | |
| 259 | + * | |
| 260 | + * @since 2.1.0 bbPress (r3632) | |
| 261 | + * | |
| 262 | + * @param int $user_id | |
| 263 | + * @param boolean $integer Optional. Whether or not to format the result | |
| 264 | + * | |
| 265 | + * @return string | |
| 266 | + */ | |
| 267 | + function bbp_get_user_reply_count( $user_id = 0, $integer = false ) { | |
| 258 | 268 | |
| 259 | -/** | |
| 260 | - * Return a users reply count. | |
| 261 | - * | |
| 262 | - * @since 2.1.0 bbPress (r3632) | |
| 263 | - * | |
| 264 | - * @param int $user_id User id. | |
| 265 | - * @param boolean $integer Optional. Whether or not to format the result. | |
| 266 | - * | |
| 267 | - * @return string | |
| 268 | - */ | |
| 269 | -function bbp_get_user_reply_count( $user_id = 0, $integer = false ) { | |
| 269 | + // Validate user id | |
| 270 | + $user_id = bbp_get_user_id( $user_id ); | |
| 271 | + if ( empty( $user_id ) ) { | |
| 272 | + return false; | |
| 273 | + } | |
| 270 | 274 | |
| 271 | - // Validate user id | |
| 272 | - $user_id = bbp_get_user_id( $user_id ); | |
| 273 | - if ( empty( $user_id ) ) { | |
| 274 | - return false; | |
| 275 | + $count = get_user_option( '_bbp_reply_count', $user_id ); | |
| 276 | + $filter = ( true === $integer ) | |
| 277 | + ? 'bbp_get_user_reply_count_int' | |
| 278 | + : 'bbp_get_user_reply_count'; | |
| 279 | + | |
| 280 | + return apply_filters( $filter, $count, $user_id ); | |
| 275 | 281 | } |
| 276 | 282 | |
| 277 | - $count = get_user_option( '_bbp_reply_count', $user_id ); | |
| 278 | - $filter = ( true === $integer ) | |
| 279 | - ? 'bbp_get_user_reply_count_int' | |
| 280 | - : 'bbp_get_user_reply_count'; | |
| 281 | - | |
| 282 | - return apply_filters( $filter, $count, $user_id ); | |
| 283 | -} | |
| 284 | - | |
| 285 | 283 | /** |
| 286 | - * Output a users total post count. | |
| 284 | + * Output a users total post count | |
| 287 | 285 | * |
| 288 | 286 | * @since 2.1.0 bbPress (r3632) |
| 289 | 287 | * |
| 290 | - * @param int $user_id User id. | |
| 288 | + * @param int $user_id | |
| 291 | 289 | * @param boolean $integer Optional. Whether or not to format the result |
| 292 | 290 | * |
| 293 | 291 | * @return string |
| 294 | 292 | */ |
| @@ -294,47 +292,46 @@ | ||
| 294 | 292 | */ |
| 295 | 293 | function bbp_user_post_count( $user_id = 0, $integer = false ) { |
| 296 | 294 | echo esc_html( bbp_get_user_post_count( $user_id, $integer ) ); |
| 297 | 295 | } |
| 296 | + /** | |
| 297 | + * Return a users total post count | |
| 298 | + * | |
| 299 | + * @since 2.1.0 bbPress (r3632) | |
| 300 | + * | |
| 301 | + * @param int $user_id | |
| 302 | + * @param boolean $integer Optional. Whether or not to format the result | |
| 303 | + * | |
| 304 | + * @return string | |
| 305 | + */ | |
| 306 | + function bbp_get_user_post_count( $user_id = 0, $integer = false ) { | |
| 298 | 307 | |
| 299 | -/** | |
| 300 | - * Return a users total post count. | |
| 301 | - * | |
| 302 | - * @since 2.1.0 bbPress (r3632) | |
| 303 | - * | |
| 304 | - * @param int $user_id User id. | |
| 305 | - * @param boolean $integer Optional. Whether or not to format the result. | |
| 306 | - * | |
| 307 | - * @return string | |
| 308 | - */ | |
| 309 | -function bbp_get_user_post_count( $user_id = 0, $integer = false ) { | |
| 308 | + // Validate user id | |
| 309 | + $user_id = bbp_get_user_id( $user_id ); | |
| 310 | + if ( empty( $user_id ) ) { | |
| 311 | + return false; | |
| 312 | + } | |
| 310 | 313 | |
| 311 | - // Validate user id | |
| 312 | - $user_id = bbp_get_user_id( $user_id ); | |
| 313 | - if ( empty( $user_id ) ) { | |
| 314 | - return false; | |
| 314 | + $topics = bbp_get_user_topic_count( $user_id, true ); | |
| 315 | + $replies = bbp_get_user_reply_count( $user_id, true ); | |
| 316 | + $count = $topics + $replies; | |
| 317 | + $filter = ( true === $integer ) | |
| 318 | + ? 'bbp_get_user_post_count_int' | |
| 319 | + : 'bbp_get_user_post_count'; | |
| 320 | + | |
| 321 | + return apply_filters( $filter, $count, $user_id ); | |
| 315 | 322 | } |
| 316 | 323 | |
| 317 | - $topics = bbp_get_user_topic_count( $user_id, true ); | |
| 318 | - $replies = bbp_get_user_reply_count( $user_id, true ); | |
| 319 | - $count = $topics + $replies; | |
| 320 | - $filter = ( true === $integer ) | |
| 321 | - ? 'bbp_get_user_post_count_int' | |
| 322 | - : 'bbp_get_user_post_count'; | |
| 323 | - | |
| 324 | - return apply_filters( $filter, $count, $user_id ); | |
| 325 | -} | |
| 326 | - | |
| 327 | 324 | /** Last Posted ***************************************************************/ |
| 328 | 325 | |
| 329 | 326 | /** |
| 330 | - * Update a users last posted time, for use with post throttling. | |
| 327 | + * Update a users last posted time, for use with post throttling | |
| 331 | 328 | * |
| 332 | 329 | * @since 2.1.0 bbPress (r3910) |
| 333 | 330 | * |
| 334 | - * @param int $user_id User ID to update. | |
| 335 | - * @param int $time Time in time() format. | |
| 336 | - * @return bool False if no user or failure, true if successful. | |
| 331 | + * @param int $user_id User ID to update | |
| 332 | + * @param int $time Time in time() format | |
| 333 | + * @return bool False if no user or failure, true if successful | |
| 337 | 334 | */ |
| 338 | 335 | function bbp_update_user_last_posted( $user_id = 0, $time = 0 ) { |
| 339 | 336 | |
| 340 | 337 | // Validate user id |
| @@ -355,31 +352,31 @@ | ||
| 355 | 352 | * Output the raw value of the last posted time. |
| 356 | 353 | * |
| 357 | 354 | * @since 2.1.0 bbPress (r3910) |
| 358 | 355 | * |
| 359 | - * @param int $user_id User ID to retrieve value for. | |
| 356 | + * @param int $user_id User ID to retrieve value for | |
| 360 | 357 | */ |
| 361 | 358 | function bbp_user_last_posted( $user_id = 0 ) { |
| 362 | 359 | echo esc_html( bbp_get_user_last_posted( $user_id ) ); |
| 363 | 360 | } |
| 364 | 361 | |
| 365 | -/** | |
| 366 | - * Return the raw value of the last posted time. | |
| 367 | - * | |
| 368 | - * @since 2.1.0 bbPress (r3910) | |
| 369 | - * | |
| 370 | - * @param int $user_id User ID to retrieve value for. | |
| 371 | - * @return mixed False if no user, time() format if exists. | |
| 372 | - */ | |
| 373 | -function bbp_get_user_last_posted( $user_id = 0 ) { | |
| 362 | + /** | |
| 363 | + * Return the raw value of the last posted time. | |
| 364 | + * | |
| 365 | + * @since 2.1.0 bbPress (r3910) | |
| 366 | + * | |
| 367 | + * @param int $user_id User ID to retrieve value for | |
| 368 | + * @return mixed False if no user, time() format if exists | |
| 369 | + */ | |
| 370 | + function bbp_get_user_last_posted( $user_id = 0 ) { | |
| 374 | 371 | |
| 375 | - // Validate user id | |
| 376 | - $user_id = bbp_get_user_id( $user_id ); | |
| 377 | - if ( empty( $user_id ) ) { | |
| 378 | - return false; | |
| 379 | - } | |
| 372 | + // Validate user id | |
| 373 | + $user_id = bbp_get_user_id( $user_id ); | |
| 374 | + if ( empty( $user_id ) ) { | |
| 375 | + return false; | |
| 376 | + } | |
| 380 | 377 | |
| 381 | - $time = get_user_option( '_bbp_last_posted', $user_id ); | |
| 378 | + $time = get_user_option( '_bbp_last_posted', $user_id ); | |
| 382 | 379 | |
| 383 | - // Filter & return | |
| 384 | - return apply_filters( 'bbp_get_user_last_posted', $time, $user_id ); | |
| 385 | -} | |
| 380 | + // Filter & return | |
| 381 | + return apply_filters( 'bbp_get_user_last_posted', $time, $user_id ); | |
| 382 | + } | |