| 43 | |
| 44 | // Filter out hidden reply references from public views |
| 45 | add_filter( 'bbp_get_topic_last_reply_id', array( $this, 'get_last_public_reply_id' ), 10, 2 ); |
| 46 | add_filter( 'bbp_get_topic_last_active', array( $this, 'get_last_public_post_time' ), 10, 2 ); |
| 47 | add_filter( 'bbp_get_topic_last_active_id', array( $this, 'get_last_public_post_id' ), 10, 2 ); |
| 48 | add_filter( 'bbp_get_topic_reply_count_int', array( $this, 'get_public_reply_count' ), 10, 2 ); |
| 337 | |
| 338 | /** |
| 339 | * Return the ID of the last public reply in a topic. |
| 340 | * |
| 341 | * @param int $reply_id Reply ID. |
| 342 | * @param int $topic_id Topic ID. |
| 343 | * @return int Last public reply ID. |
| 344 | */ |
| 345 | function get_last_public_reply_id( $reply_id, $topic_id ) { |
| 346 | if ( 'publish' !== get_post_status( $reply_id ) ) { |
| 347 | $reply_id = bbp_get_public_child_last_id( $topic_id, bbp_get_reply_post_type() ); |
| 348 | } |
| 349 | |
| 350 | return $reply_id; |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * Return last public activity time for a topic. |
| 355 | * |
| 356 | * @param string $last_active Last activity time. |
| 357 | * @param int $topic_id Topic ID. |
| 358 | * @return string Last public activity time. |
| 359 | */ |
| 360 | function get_last_public_post_time( $last_active, $topic_id ) { |
| 361 | if ( bbp_get_topic_reply_count_hidden( $topic_id ) ) { |
| 362 | $reply_id = bbp_get_topic_last_reply_id( $topic_id ); |
| 363 | |
| 364 | $last_active = get_post_field( 'post_date', $reply_id ); |
| 365 | $last_active = ! empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : ''; |
| 366 | } |
| 367 | |
| 368 | return $last_active; |
| 369 | } |
| 370 | |
| 371 | /** |
| 372 | * Return the ID of the last public post in a topic. |
| 373 | * |
| 374 | * @param int $active_id Last post ID. |
| 375 | * @param int $topic_id Topic ID. |
| 376 | * @return int Last public post ID. |
| 377 | */ |
| 378 | function get_last_public_post_id( $active_id, $topic_id ) { |
| 379 | if ( bbp_get_topic_reply_count_hidden( $topic_id ) ) { |
| 380 | $active_id = bbp_get_topic_last_reply_id( $topic_id ); |
| 381 | } |
| 382 | |
| 383 | return $active_id; |
| 384 | } |
| 385 | |
| 386 | /** |
| 387 | * Return public reply count for a topic. |
| 388 | * |
| 389 | * @param int $replies Reply count. |
| 390 | * @param int $topic_id Topic ID. |
| 391 | * @return int Public reply count. |
| 392 | */ |
| 393 | function get_public_reply_count( $replies, $topic_id ) { |
| 394 | if ( bbp_get_topic_reply_count_hidden( $topic_id ) ) { |
| 395 | $replies = bbp_get_public_child_count( $topic_id, bbp_get_reply_post_type() ); |
| 396 | } |
| 397 | |
| 398 | return $replies; |
| 399 | } |
| 400 | |