Skip to:
Content

bbPress.org

Ticket #2801: 2801.02.patch

File 2801.02.patch, 13.0 KB (added by thebrandonallen, 10 years ago)

Type casting improvements

  • src/includes/common/functions.php

    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' ) { 
    15281528                // Join post statuses together
    15291529                $post_status = "'" . implode( "', '", $post_status ) . "'";
    15301530
    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 ) );
    15321532                wp_cache_set( $cache_id, $child_id, 'bbpress_posts' );
    15331533        }
    15341534
    15351535        // 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 );
    15371537}
    15381538
    15391539/**
    function bbp_get_public_child_count( $parent_id = 0, $post_type = 'post' ) { 
    15761576                // Join post statuses together
    15771577                $post_status = "'" . implode( "', '", $post_status ) . "'";
    15781578
    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 ) );
    15801580                wp_cache_set( $cache_id, $child_count, 'bbpress_posts' );
    15811581        }
    15821582
    15831583        // 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 );
    15851585}
    15861586
    15871587/**
    function bbp_get_public_child_ids( $parent_id = 0, $post_type = 'post' ) { 
    16291629        }
    16301630
    16311631        // 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 );
    16331633}
    16341634
    16351635/**
    function bbp_get_all_child_ids( $parent_id = 0, $post_type = 'post' ) { 
    16931693        }
    16941694
    16951695        // 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 );
    16971697}
    16981698
    16991699/** Globals *******************************************************************/
  • src/includes/forums/functions.php

    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 ) { 
    14521452        $total_topics = $topics + $children_topic_count;
    14531453
    14541454        // 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 );
    14571457
    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 );
    14591459}
    14601460
    14611461/**
    function bbp_pre_get_posts_normalize_forum_visibility( $posts_query = null ) { 
    19191919function bbp_forum_query_topic_ids( $forum_id ) {
    19201920        $topic_ids = bbp_get_public_child_ids( $forum_id, bbp_get_topic_post_type() );
    19211921
    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 );
    19231923}
    19241924
    19251925/**
    function bbp_forum_query_subforum_ids( $forum_id ) { 
    19391939        $subforum_ids = bbp_get_all_child_ids( $forum_id, bbp_get_forum_post_type() );
    19401940        //usort( $subforum_ids, '_bbp_forum_query_usort_subforum_ids' );
    19411941
    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 );
    19431943}
    19441944
    19451945/**
    function bbp_forum_query_last_reply_id( $forum_id, $topic_ids = 0 ) { 
    19891989                        $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() ) );
    19901990                        wp_cache_set( $cache_id, $reply_id, 'bbpress_posts' ); // May be (int) 0
    19911991                } else {
    1992                         wp_cache_set( $cache_id, '0', 'bbpress_posts' );
     1992                        wp_cache_set( $cache_id, 0, 'bbpress_posts' );
    19931993                }
    19941994        }
    19951995
    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 );
    19971997}
    19981998
    19991999/** Listeners *****************************************************************/
  • src/includes/replies/functions.php

    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 ) { 
    10591059        // Update the forum ID
    10601060        bbp_update_forum_id( $reply_id, $forum_id );
    10611061
    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 );
    10631063}
    10641064
    10651065/**
    function bbp_update_reply_topic_id( $reply_id = 0, $topic_id = 0 ) { 
    11081108        // Update the topic ID
    11091109        bbp_update_topic_id( $reply_id, $topic_id );
    11101110
    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 );
    11121112}
    11131113
    11141114/*
    function bbp_get_reply_ancestors( $reply_id = 0 ) { 
    11921192                }
    11931193        }
    11941194
    1195         return apply_filters( 'bbp_get_reply_ancestors', $ancestors, $reply_id );
     1195        return (array) apply_filters( 'bbp_get_reply_ancestors', $ancestors, $reply_id );
    11961196}
    11971197
    11981198/**
  • src/includes/topics/functions.php

    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 ) { 
    23362336        // Get counts
    23372337        $topic_id    = bbp_get_topic_id( $topic_id );
    23382338        $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;
    23402341
    23412342        // 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 );
    23432344
    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 );
    23452346}
    23462347
    23472348/**
    function bbp_bump_topic_reply_count_hidden( $topic_id = 0, $difference = 1 ) { 
    23632364        // Get counts
    23642365        $topic_id    = bbp_get_topic_id( $topic_id );
    23652366        $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;
    23672369
    23682370        // 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 );
    23702372
    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 );
    23722374}
    23732375
    23742376/** Topic Updaters ************************************************************/
    function bbp_update_topic_forum_id( $topic_id = 0, $forum_id = 0 ) { 
    24032405                $forum_id = get_post_field( 'post_parent', $topic_id );
    24042406        }
    24052407
    2406         update_post_meta( $topic_id, '_bbp_forum_id', (int) $forum_id );
     2408        $forum_id = (int) $forum_id;
    24072409
    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 );
    24092413}
    24102414
    24112415/**
    function bbp_update_topic_forum_id( $topic_id = 0, $forum_id = 0 ) { 
    24222426function bbp_update_topic_topic_id( $topic_id = 0 ) {
    24232427        $topic_id = bbp_get_topic_id( $topic_id );
    24242428
    2425         update_post_meta( $topic_id, '_bbp_topic_id', (int) $topic_id );
     2429        update_post_meta( $topic_id, '_bbp_topic_id', $topic_id );
    24262430
    2427         return apply_filters( 'bbp_update_topic_topic_id', (int) $topic_id );
     2431        return (int) apply_filters( 'bbp_update_topic_topic_id', $topic_id );
    24282432}
    24292433
    24302434/**
    function bbp_update_topic_reply_count( $topic_id = 0, $reply_count = 0 ) { 
    24582462                $reply_count = bbp_get_public_child_count( $topic_id, bbp_get_reply_post_type() );
    24592463        }
    24602464
    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 );
    24622468
    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 );
    24642470}
    24652471
    24662472/**
    function bbp_update_topic_reply_count_hidden( $topic_id = 0, $reply_count = 0 ) 
    25012507                $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() ) );
    25022508        }
    25032509
    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 );
    25052513
    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 );
    25072515}
    25082516
    25092517/**
    function bbp_update_topic_last_active_id( $topic_id = 0, $active_id = 0 ) { 
    25442552
    25452553        // Update only if published
    25462554        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 );
    25482556        }
    25492557
    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 );
    25512559}
    25522560
    25532561/**
    function bbp_update_topic_last_reply_id( $topic_id = 0, $reply_id = 0 ) { 
    26252633
    26262634        // Update if reply is published
    26272635        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 );
    26292637        }
    26302638
    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 );
    26322640}
    26332641
    26342642/**
    function bbp_update_topic_voice_count( $topic_id = 0 ) { 
    26662674        $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() ) );
    26672675
    26682676        // 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];
    26702678
    26712679        // 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 );
    26732681
    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 );
    26752683}
    26762684
    26772685/**
    function bbp_update_topic_anonymous_reply_count( $topic_id = 0 ) { 
    27072715
    27082716        $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() ) );
    27092717
    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 );
    27112719
    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 );
    27132721}
    27142722
    27152723/**