diff --git src/includes/common/functions.php src/includes/common/functions.php
index 9af29dc..77153d2 100644
|
|
function bbp_get_public_child_last_id( $parent_id = 0, $post_type = 'post' ) { |
1528 | 1528 | // Join post statuses together |
1529 | 1529 | $post_status = "'" . implode( "', '", $post_status ) . "'"; |
1530 | 1530 | |
1531 | | $child_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", $parent_id, $post_type ) ); |
| 1531 | $child_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", $parent_id, $post_type ) ); |
1532 | 1532 | wp_cache_set( $cache_id, $child_id, 'bbpress_posts' ); |
1533 | 1533 | } |
1534 | 1534 | |
1535 | 1535 | // Filter and return |
1536 | | return apply_filters( 'bbp_get_public_child_last_id', (int) $child_id, $parent_id, $post_type ); |
| 1536 | return (int) apply_filters( 'bbp_get_public_child_last_id', (int) $child_id, (int) $parent_id, $post_type ); |
1537 | 1537 | } |
1538 | 1538 | |
1539 | 1539 | /** |
… |
… |
function bbp_get_public_child_count( $parent_id = 0, $post_type = 'post' ) { |
1576 | 1576 | // Join post statuses together |
1577 | 1577 | $post_status = "'" . implode( "', '", $post_status ) . "'"; |
1578 | 1578 | |
1579 | | $child_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $parent_id, $post_type ) ); |
| 1579 | $child_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $parent_id, $post_type ) ); |
1580 | 1580 | wp_cache_set( $cache_id, $child_count, 'bbpress_posts' ); |
1581 | 1581 | } |
1582 | 1582 | |
1583 | 1583 | // Filter and return |
1584 | | return apply_filters( 'bbp_get_public_child_count', (int) $child_count, $parent_id, $post_type ); |
| 1584 | return (int) apply_filters( 'bbp_get_public_child_count', (int) $child_count, (int) $parent_id, $post_type ); |
1585 | 1585 | } |
1586 | 1586 | |
1587 | 1587 | /** |
… |
… |
function bbp_get_public_child_ids( $parent_id = 0, $post_type = 'post' ) { |
1629 | 1629 | } |
1630 | 1630 | |
1631 | 1631 | // Filter and return |
1632 | | return apply_filters( 'bbp_get_public_child_ids', $child_ids, $parent_id, $post_type ); |
| 1632 | return (array) apply_filters( 'bbp_get_public_child_ids', (array) $child_ids, (int) $parent_id, $post_type ); |
1633 | 1633 | } |
1634 | 1634 | |
1635 | 1635 | /** |
… |
… |
function bbp_get_all_child_ids( $parent_id = 0, $post_type = 'post' ) { |
1693 | 1693 | } |
1694 | 1694 | |
1695 | 1695 | // Filter and return |
1696 | | return apply_filters( 'bbp_get_all_child_ids', $child_ids, (int) $parent_id, $post_type ); |
| 1696 | return (array) apply_filters( 'bbp_get_all_child_ids', (array) $child_ids, (int) $parent_id, $post_type ); |
1697 | 1697 | } |
1698 | 1698 | |
1699 | 1699 | /** Globals *******************************************************************/ |
diff --git src/includes/forums/functions.php src/includes/forums/functions.php
index 917561c..1c78fc5 100644
|
|
function bbp_update_forum_topic_count( $forum_id = 0 ) { |
1452 | 1452 | $total_topics = $topics + $children_topic_count; |
1453 | 1453 | |
1454 | 1454 | // Update the count |
1455 | | update_post_meta( $forum_id, '_bbp_topic_count', (int) $topics ); |
1456 | | update_post_meta( $forum_id, '_bbp_total_topic_count', (int) $total_topics ); |
| 1455 | update_post_meta( $forum_id, '_bbp_topic_count', $topics ); |
| 1456 | update_post_meta( $forum_id, '_bbp_total_topic_count', $total_topics ); |
1457 | 1457 | |
1458 | | return (int) apply_filters( 'bbp_update_forum_topic_count', (int) $total_topics, $forum_id ); |
| 1458 | return (int) apply_filters( 'bbp_update_forum_topic_count', $total_topics, $forum_id ); |
1459 | 1459 | } |
1460 | 1460 | |
1461 | 1461 | /** |
… |
… |
function bbp_pre_get_posts_normalize_forum_visibility( $posts_query = null ) { |
1919 | 1919 | function bbp_forum_query_topic_ids( $forum_id ) { |
1920 | 1920 | $topic_ids = bbp_get_public_child_ids( $forum_id, bbp_get_topic_post_type() ); |
1921 | 1921 | |
1922 | | return apply_filters( 'bbp_forum_query_topic_ids', $topic_ids, $forum_id ); |
| 1922 | return (array) apply_filters( 'bbp_forum_query_topic_ids', $topic_ids, $forum_id ); |
1923 | 1923 | } |
1924 | 1924 | |
1925 | 1925 | /** |
… |
… |
function bbp_forum_query_subforum_ids( $forum_id ) { |
1939 | 1939 | $subforum_ids = bbp_get_all_child_ids( $forum_id, bbp_get_forum_post_type() ); |
1940 | 1940 | //usort( $subforum_ids, '_bbp_forum_query_usort_subforum_ids' ); |
1941 | 1941 | |
1942 | | return apply_filters( 'bbp_get_forum_subforum_ids', $subforum_ids, $forum_id ); |
| 1942 | return (array) apply_filters( 'bbp_get_forum_subforum_ids', $subforum_ids, $forum_id ); |
1943 | 1943 | } |
1944 | 1944 | |
1945 | 1945 | /** |
… |
… |
function bbp_forum_query_last_reply_id( $forum_id, $topic_ids = 0 ) { |
1989 | 1989 | $reply_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent IN ( {$topic_ids} ) AND post_status = '%s' AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", bbp_get_public_status_id(), bbp_get_reply_post_type() ) ); |
1990 | 1990 | wp_cache_set( $cache_id, $reply_id, 'bbpress_posts' ); // May be (int) 0 |
1991 | 1991 | } else { |
1992 | | wp_cache_set( $cache_id, '0', 'bbpress_posts' ); |
| 1992 | wp_cache_set( $cache_id, 0, 'bbpress_posts' ); |
1993 | 1993 | } |
1994 | 1994 | } |
1995 | 1995 | |
1996 | | return (int) apply_filters( 'bbp_get_forum_last_reply_id', (int) $reply_id, $forum_id ); |
| 1996 | return (int) apply_filters( 'bbp_get_forum_last_reply_id', $reply_id, $forum_id ); |
1997 | 1997 | } |
1998 | 1998 | |
1999 | 1999 | /** Listeners *****************************************************************/ |
diff --git src/includes/replies/functions.php src/includes/replies/functions.php
index 86b7011..5dbe5b9 100644
|
|
function bbp_update_reply_forum_id( $reply_id = 0, $forum_id = 0 ) { |
1059 | 1059 | // Update the forum ID |
1060 | 1060 | bbp_update_forum_id( $reply_id, $forum_id ); |
1061 | 1061 | |
1062 | | return apply_filters( 'bbp_update_reply_forum_id', (int) $forum_id, $reply_id ); |
| 1062 | return (int) apply_filters( 'bbp_update_reply_forum_id', (int) $forum_id, $reply_id ); |
1063 | 1063 | } |
1064 | 1064 | |
1065 | 1065 | /** |
… |
… |
function bbp_update_reply_topic_id( $reply_id = 0, $topic_id = 0 ) { |
1108 | 1108 | // Update the topic ID |
1109 | 1109 | bbp_update_topic_id( $reply_id, $topic_id ); |
1110 | 1110 | |
1111 | | return apply_filters( 'bbp_update_reply_topic_id', (int) $topic_id, $reply_id ); |
| 1111 | return (int) apply_filters( 'bbp_update_reply_topic_id', (int) $topic_id, $reply_id ); |
1112 | 1112 | } |
1113 | 1113 | |
1114 | 1114 | /* |
… |
… |
function bbp_get_reply_ancestors( $reply_id = 0 ) { |
1192 | 1192 | } |
1193 | 1193 | } |
1194 | 1194 | |
1195 | | return apply_filters( 'bbp_get_reply_ancestors', $ancestors, $reply_id ); |
| 1195 | return (array) apply_filters( 'bbp_get_reply_ancestors', $ancestors, $reply_id ); |
1196 | 1196 | } |
1197 | 1197 | |
1198 | 1198 | /** |
diff --git src/includes/topics/functions.php src/includes/topics/functions.php
index 66cdfc4..1183f53 100644
|
|
function bbp_bump_topic_reply_count( $topic_id = 0, $difference = 1 ) { |
2336 | 2336 | // Get counts |
2337 | 2337 | $topic_id = bbp_get_topic_id( $topic_id ); |
2338 | 2338 | $reply_count = bbp_get_topic_reply_count( $topic_id, true ); |
2339 | | $new_count = (int) $reply_count + (int) $difference; |
| 2339 | $difference = (int) $difference; |
| 2340 | $new_count = $reply_count + $difference; |
2340 | 2341 | |
2341 | 2342 | // Update this topic id's reply count |
2342 | | update_post_meta( $topic_id, '_bbp_reply_count', (int) $new_count ); |
| 2343 | update_post_meta( $topic_id, '_bbp_reply_count', $new_count ); |
2343 | 2344 | |
2344 | | return (int) apply_filters( 'bbp_bump_topic_reply_count', (int) $new_count, $topic_id, (int) $difference ); |
| 2345 | return (int) apply_filters( 'bbp_bump_topic_reply_count', $new_count, $topic_id, $difference ); |
2345 | 2346 | } |
2346 | 2347 | |
2347 | 2348 | /** |
… |
… |
function bbp_bump_topic_reply_count_hidden( $topic_id = 0, $difference = 1 ) { |
2363 | 2364 | // Get counts |
2364 | 2365 | $topic_id = bbp_get_topic_id( $topic_id ); |
2365 | 2366 | $reply_count = bbp_get_topic_reply_count_hidden( $topic_id, true ); |
2366 | | $new_count = (int) $reply_count + (int) $difference; |
| 2367 | $difference = (int) $difference; |
| 2368 | $new_count = $reply_count + $difference; |
2367 | 2369 | |
2368 | 2370 | // Update this topic id's hidder reply count |
2369 | | update_post_meta( $topic_id, '_bbp_reply_count_hidden', (int) $new_count ); |
| 2371 | update_post_meta( $topic_id, '_bbp_reply_count_hidden', $new_count ); |
2370 | 2372 | |
2371 | | return (int) apply_filters( 'bbp_bump_topic_reply_count_hidden', (int) $new_count, $topic_id, (int) $difference ); |
| 2373 | return (int) apply_filters( 'bbp_bump_topic_reply_count_hidden', $new_count, $topic_id, $difference ); |
2372 | 2374 | } |
2373 | 2375 | |
2374 | 2376 | /** Topic Updaters ************************************************************/ |
… |
… |
function bbp_update_topic_forum_id( $topic_id = 0, $forum_id = 0 ) { |
2403 | 2405 | $forum_id = get_post_field( 'post_parent', $topic_id ); |
2404 | 2406 | } |
2405 | 2407 | |
2406 | | update_post_meta( $topic_id, '_bbp_forum_id', (int) $forum_id ); |
| 2408 | $forum_id = (int) $forum_id; |
2407 | 2409 | |
2408 | | return apply_filters( 'bbp_update_topic_forum_id', (int) $forum_id, $topic_id ); |
| 2410 | update_post_meta( $topic_id, '_bbp_forum_id', $forum_id ); |
| 2411 | |
| 2412 | return (int) apply_filters( 'bbp_update_topic_forum_id', $forum_id, $topic_id ); |
2409 | 2413 | } |
2410 | 2414 | |
2411 | 2415 | /** |
… |
… |
function bbp_update_topic_forum_id( $topic_id = 0, $forum_id = 0 ) { |
2422 | 2426 | function bbp_update_topic_topic_id( $topic_id = 0 ) { |
2423 | 2427 | $topic_id = bbp_get_topic_id( $topic_id ); |
2424 | 2428 | |
2425 | | update_post_meta( $topic_id, '_bbp_topic_id', (int) $topic_id ); |
| 2429 | update_post_meta( $topic_id, '_bbp_topic_id', $topic_id ); |
2426 | 2430 | |
2427 | | return apply_filters( 'bbp_update_topic_topic_id', (int) $topic_id ); |
| 2431 | return (int) apply_filters( 'bbp_update_topic_topic_id', $topic_id ); |
2428 | 2432 | } |
2429 | 2433 | |
2430 | 2434 | /** |
… |
… |
function bbp_update_topic_reply_count( $topic_id = 0, $reply_count = 0 ) { |
2458 | 2462 | $reply_count = bbp_get_public_child_count( $topic_id, bbp_get_reply_post_type() ); |
2459 | 2463 | } |
2460 | 2464 | |
2461 | | update_post_meta( $topic_id, '_bbp_reply_count', (int) $reply_count ); |
| 2465 | $reply_count = (int) $reply_count; |
| 2466 | |
| 2467 | update_post_meta( $topic_id, '_bbp_reply_count', $reply_count ); |
2462 | 2468 | |
2463 | | return apply_filters( 'bbp_update_topic_reply_count', (int) $reply_count, $topic_id ); |
| 2469 | return (int) apply_filters( 'bbp_update_topic_reply_count', $reply_count, $topic_id ); |
2464 | 2470 | } |
2465 | 2471 | |
2466 | 2472 | /** |
… |
… |
function bbp_update_topic_reply_count_hidden( $topic_id = 0, $reply_count = 0 ) |
2501 | 2507 | $reply_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $topic_id, bbp_get_reply_post_type() ) ); |
2502 | 2508 | } |
2503 | 2509 | |
2504 | | update_post_meta( $topic_id, '_bbp_reply_count_hidden', (int) $reply_count ); |
| 2510 | $reply_count = (int) $reply_count; |
| 2511 | |
| 2512 | update_post_meta( $topic_id, '_bbp_reply_count_hidden', $reply_count ); |
2505 | 2513 | |
2506 | | return apply_filters( 'bbp_update_topic_reply_count_hidden', (int) $reply_count, $topic_id ); |
| 2514 | return (int) apply_filters( 'bbp_update_topic_reply_count_hidden', $reply_count, $topic_id ); |
2507 | 2515 | } |
2508 | 2516 | |
2509 | 2517 | /** |
… |
… |
function bbp_update_topic_last_active_id( $topic_id = 0, $active_id = 0 ) { |
2544 | 2552 | |
2545 | 2553 | // Update only if published |
2546 | 2554 | if ( bbp_get_public_status_id() === get_post_status( $active_id ) ) { |
2547 | | update_post_meta( $topic_id, '_bbp_last_active_id', (int) $active_id ); |
| 2555 | update_post_meta( $topic_id, '_bbp_last_active_id', $active_id ); |
2548 | 2556 | } |
2549 | 2557 | |
2550 | | return apply_filters( 'bbp_update_topic_last_active_id', (int) $active_id, $topic_id ); |
| 2558 | return (int) apply_filters( 'bbp_update_topic_last_active_id', $active_id, $topic_id ); |
2551 | 2559 | } |
2552 | 2560 | |
2553 | 2561 | /** |
… |
… |
function bbp_update_topic_last_reply_id( $topic_id = 0, $reply_id = 0 ) { |
2625 | 2633 | |
2626 | 2634 | // Update if reply is published |
2627 | 2635 | if ( bbp_is_reply_published( $reply_id ) ) { |
2628 | | update_post_meta( $topic_id, '_bbp_last_reply_id', (int) $reply_id ); |
| 2636 | update_post_meta( $topic_id, '_bbp_last_reply_id', $reply_id ); |
2629 | 2637 | } |
2630 | 2638 | |
2631 | | return apply_filters( 'bbp_update_topic_last_reply_id', (int) $reply_id, $topic_id ); |
| 2639 | return (int) apply_filters( 'bbp_update_topic_last_reply_id', $reply_id, $topic_id ); |
2632 | 2640 | } |
2633 | 2641 | |
2634 | 2642 | /** |
… |
… |
function bbp_update_topic_voice_count( $topic_id = 0 ) { |
2666 | 2674 | $voices = $wpdb->get_col( $wpdb->prepare( "SELECT COUNT( DISTINCT post_author ) FROM {$wpdb->posts} WHERE ( post_parent = %d AND post_status = '%s' AND post_type = '%s' ) OR ( ID = %d AND post_type = '%s' );", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ) ); |
2667 | 2675 | |
2668 | 2676 | // If there's an error, make sure we have at least have 1 voice |
2669 | | $voices = ( empty( $voices ) || is_wp_error( $voices ) ) ? 1 : $voices[0]; |
| 2677 | $voices = ( empty( $voices ) || is_wp_error( $voices ) ) ? 1 : (int) $voices[0]; |
2670 | 2678 | |
2671 | 2679 | // Update the voice count for this topic id |
2672 | | update_post_meta( $topic_id, '_bbp_voice_count', (int) $voices ); |
| 2680 | update_post_meta( $topic_id, '_bbp_voice_count', $voices ); |
2673 | 2681 | |
2674 | | return apply_filters( 'bbp_update_topic_voice_count', (int) $voices, $topic_id ); |
| 2682 | return (int) apply_filters( 'bbp_update_topic_voice_count', $voices, $topic_id ); |
2675 | 2683 | } |
2676 | 2684 | |
2677 | 2685 | /** |
… |
… |
function bbp_update_topic_anonymous_reply_count( $topic_id = 0 ) { |
2707 | 2715 | |
2708 | 2716 | $anonymous_replies = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( ID ) FROM {$wpdb->posts} WHERE ( post_parent = %d AND post_status = '%s' AND post_type = '%s' AND post_author = 0 ) OR ( ID = %d AND post_type = '%s' AND post_author = 0 );", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ) ); |
2709 | 2717 | |
2710 | | update_post_meta( $topic_id, '_bbp_anonymous_reply_count', (int) $anonymous_replies ); |
| 2718 | update_post_meta( $topic_id, '_bbp_anonymous_reply_count', $anonymous_replies ); |
2711 | 2719 | |
2712 | | return apply_filters( 'bbp_update_topic_anonymous_reply_count', (int) $anonymous_replies, $topic_id ); |
| 2720 | return (int) apply_filters( 'bbp_update_topic_anonymous_reply_count', $anonymous_replies, $topic_id ); |
2713 | 2721 | } |
2714 | 2722 | |
2715 | 2723 | /** |