| 291 | |
| 292 | /** |
| 293 | * Increments the count of topics created by an user. |
| 294 | * |
| 295 | * @since bbPress (rXXXX) |
| 296 | * |
| 297 | * @param int $user_id |
| 298 | * @param int $by_how_many |
| 299 | * @uses bbp_get_user_topic_count() To get the users current topic count |
| 300 | * |
| 301 | * @ |
| 302 | */ |
| 303 | function bbp_increment_user_topic_count( $user_id, $by_how_many = 1 ) { |
| 304 | $count = intval( bbp_get_user_topic_count( $user_id ) ); |
| 305 | $count = $count + $by_how_many; |
| 306 | $count = apply_filters( 'bbp_increment_user_topic_count', $count, $user_id, $by_how_many ); |
| 307 | update_user_option( $user_id, '_bbp_topic_count', $count ); |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Increments the count of replies created by an user. |
| 312 | * |
| 313 | * @since bbPress (rXXXX) |
| 314 | * |
| 315 | * @param int $user_id |
| 316 | * @param int $by_how_many |
| 317 | * @uses bbp_get_user_reply_count() To get the users current reply count |
| 318 | */ |
| 319 | function bbp_increment_user_reply_count( $user_id, $by_how_many = 1 ) { |
| 320 | $count = intval( bbp_get_user_reply_count( $user_id ) ); |
| 321 | $count = $count + $by_how_many; |
| 322 | $count = apply_filters( 'bbp_increment_user_reply_count', $count, $user_id, $by_how_many ); |
| 323 | update_user_option( $user_id, '_bbp_reply_count', $count ); |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * Decrements the count of topics created by an user. |
| 328 | * |
| 329 | * @since bbPress (rXXXX) |
| 330 | * |
| 331 | * @param int $user_id |
| 332 | * @param int $by_how_many |
| 333 | * @uses bbp_get_user_topic_count() To get the users current topic count |
| 334 | */ |
| 335 | function bbp_decrement_user_topic_count( $user_id, $by_how_many = 1 ) { |
| 336 | |
| 337 | $count = intval( bbp_get_user_topic_count( $user_id ) ); |
| 338 | |
| 339 | $count = $count - $by_how_many; |
| 340 | $count = apply_filters( 'bbp_decrement_user_topic_count', $count, $user_id, $by_how_many ); |
| 341 | |
| 342 | // Topic count can't be less than zero. |
| 343 | if ( $count < 0 ) |
| 344 | $count = 0; |
| 345 | |
| 346 | update_user_option( $user_id, '_bbp_topic_count', $count ); |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * Decrements by one the count of replies created by an user. |
| 351 | * |
| 352 | * @since bbPress (rXXXX) |
| 353 | * |
| 354 | * @param int $user_id |
| 355 | * @param int $by_how_many |
| 356 | * @uses bbp_get_user_reply_count() To get the users current reply count |
| 357 | */ |
| 358 | function bbp_decrement_user_reply_count( $user_id, $by_how_many = 1 ) { |
| 359 | $count = intval( bbp_get_user_reply_count( $user_id ) ); |
| 360 | $count = $count - $by_how_many; |
| 361 | $count = apply_filters( 'bbp_decrement_user_reply_count', $count, $user_id, $by_how_many ); |
| 362 | |
| 363 | // Reply counts can't be less than zero. |
| 364 | if ( $count < 0 ) |
| 365 | $count = 0; |
| 366 | |
| 367 | update_user_option( $user_id, '_bbp_reply_count', $count ); |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * Increments by one the count of topics for an user when he creates a new topic. |
| 372 | * |
| 373 | * @since bbPress (rXXXX) |
| 374 | * |
| 375 | * @param $topic_id |
| 376 | * @param $forum_id |
| 377 | * @param $anonymous_data |
| 378 | * @param $topic_author |
| 379 | */ |
| 380 | function bbp_bump_user_topic_count_on_new_topic( $topic_id, $forum_id, $anonymous_data, $topic_author ) { |
| 381 | bbp_increment_user_topic_count( $topic_author ); |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * Increments by one the count of topics for an user when he creates a new topic. |
| 386 | * |
| 387 | * @since bbPress (rXXXX) |
| 388 | * |
| 389 | * @param $topic_id |
| 390 | * @param $forum_id |
| 391 | * @param $anonymous_data |
| 392 | * @param $topic_author |
| 393 | */ |
| 394 | function bbp_bump_user_reply_count_on_new_reply( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author ) { |
| 395 | bbp_increment_user_reply_count( $reply_author ); |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * Decrements by one the count of topics for an user when he creates a new topic. |
| 400 | * |
| 401 | * @since bbPress (rXXXX) |
| 402 | * |
| 403 | * @param $topic_id |
| 404 | */ |
| 405 | function bbp_dwindle_user_topic_count_on_deleted_topic( $topic_id ) { |
| 406 | $user = bbp_get_topic_author_id( $topic_id ); |
| 407 | bbp_decrement_user_topic_count( $user ); |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * Increments by one the count of replies for an user when he creates a new reply. |
| 412 | * |
| 413 | * @since bbPress (rXXXX) |
| 414 | * |
| 415 | * @param $reply_id |
| 416 | * |
| 417 | */ |
| 418 | function bbp_dwindle_user_reply_count_on_deleted_reply( $reply_id ) { |
| 419 | $user = bbp_get_reply_author_id( $reply_id ); |
| 420 | bbp_decrement_user_reply_count( $user ); |
| 421 | } |
| 422 | No newline at end of file |