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