Skip to:
Content

bbPress.org

Changeset 5731


Ignore:
Timestamp:
05/12/2015 10:15:51 PM (9 years ago)
Author:
johnjamesjacoby
Message:

Forums: Normalize type-casting in some count functions. More to do here.

Props thebrandonallen, netweb. See #2801.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/forums/functions.php

    r5684 r5731  
    11931193        $children = bbp_forum_query_subforum_ids( $forum_id );
    11941194        if ( !empty( $children ) ) {
    1195             foreach ( (array) $children as $child ) {
     1195            foreach ( $children as $child ) {
    11961196                $children_last_topic = bbp_update_forum_last_topic_id( $child ); // Recursive
    11971197            }
     
    12631263        $children = bbp_forum_query_subforum_ids( $forum_id );
    12641264        if ( !empty( $children ) ) {
    1265             foreach ( (array) $children as $child ) {
     1265            foreach ( $children as $child ) {
    12661266                $children_last_reply = bbp_update_forum_last_reply_id( $child ); // Recursive
    12671267            }
     
    13291329        $children = bbp_forum_query_subforum_ids( $forum_id );
    13301330        if ( !empty( $children ) ) {
    1331             foreach ( (array) $children as $child ) {
     1331            foreach ( $children as $child ) {
    13321332                $children_last_active = bbp_update_forum_last_active_id( $child, $active_id );
    13331333            }
     
    13571357    // Update only if published
    13581358    if ( bbp_get_public_status_id() === get_post_status( $active_id ) ) {
    1359         update_post_meta( $forum_id, '_bbp_last_active_id', (int) $active_id );
    1360     }
    1361 
    1362     return (int) apply_filters( 'bbp_update_forum_last_active_id', (int) $active_id, $forum_id );
     1359        update_post_meta( $forum_id, '_bbp_last_active_id', $active_id );
     1360    }
     1361
     1362    return (int) apply_filters( 'bbp_update_forum_last_active_id', $active_id, $forum_id );
    13631363}
    13641364
     
    14101410    }
    14111411
    1412     update_post_meta( $forum_id, '_bbp_forum_subforum_count', (int) $subforums );
    1413 
    1414     return (int) apply_filters( 'bbp_update_forum_subforum_count', (int) $subforums, $forum_id );
     1412    $subforums = (int) $subforums;
     1413
     1414    update_post_meta( $forum_id, '_bbp_forum_subforum_count', $subforums );
     1415
     1416    return (int) apply_filters( 'bbp_update_forum_subforum_count', $subforums, $forum_id );
    14151417}
    14161418
     
    14411443    $children = bbp_forum_query_subforum_ids( $forum_id );
    14421444    if ( !empty( $children ) ) {
    1443         foreach ( (array) $children as $child ) {
     1445        foreach ( $children as $child ) {
    14441446            $children_topic_count += bbp_update_forum_topic_count( $child ); // Recursive
    14451447        }
     
    14501452
    14511453    // Calculate total topics in this forum
    1452     $total_topics = $topics + $children_topic_count;
     1454    $total_topics = (int) ( $topics + $children_topic_count );
    14531455
    14541456    // 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 );
    1457 
    1458     return (int) apply_filters( 'bbp_update_forum_topic_count', (int) $total_topics, $forum_id );
     1457    update_post_meta( $forum_id, '_bbp_topic_count',       $topics       );
     1458    update_post_meta( $forum_id, '_bbp_total_topic_count', $total_topics );
     1459
     1460    return (int) apply_filters( 'bbp_update_forum_topic_count', $total_topics, $forum_id );
    14591461}
    14601462
     
    15031505        }
    15041506
     1507        $topic_count = (int) $topic_count;
     1508
    15051509        // Update the count
    1506         update_post_meta( $forum_id, '_bbp_topic_count_hidden', (int) $topic_count );
    1507     }
    1508 
    1509     return (int) apply_filters( 'bbp_update_forum_topic_count_hidden', (int) $topic_count, $forum_id );
     1510        update_post_meta( $forum_id, '_bbp_topic_count_hidden', $topic_count );
     1511    }
     1512
     1513    return (int) apply_filters( 'bbp_update_forum_topic_count_hidden', $topic_count, $forum_id );
    15101514}
    15111515
     
    15461550
    15471551    // Don't count replies if the forum is a category
    1548     $topic_ids = bbp_forum_query_topic_ids( $forum_id );
    1549     if ( !empty( $topic_ids ) ) {
     1552    $reply_count = 0;
     1553    $topic_ids   = bbp_forum_query_topic_ids( $forum_id );
     1554    if ( ! empty( $topic_ids ) ) {
    15501555        $topic_ids   = implode( ',', wp_parse_id_list( $topic_ids ) );
    15511556        $reply_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent IN ( {$topic_ids} ) AND post_status = '%s' AND post_type = '%s';", bbp_get_public_status_id(), bbp_get_reply_post_type() ) );
    1552     } else {
    1553         $reply_count = 0;
    15541557    }
    15551558
    15561559    // Calculate total replies in this forum
    1557     $total_replies = (int) $reply_count + $children_reply_count;
     1560    $total_replies = (int) ( $reply_count + $children_reply_count );
    15581561
    15591562    // Update the count
    1560     update_post_meta( $forum_id, '_bbp_reply_count',       (int) $reply_count   );
    1561     update_post_meta( $forum_id, '_bbp_total_reply_count', (int) $total_replies );
    1562 
    1563     return (int) apply_filters( 'bbp_update_forum_reply_count', (int) $total_replies, $forum_id );
     1563    update_post_meta( $forum_id, '_bbp_reply_count',       $reply_count   );
     1564    update_post_meta( $forum_id, '_bbp_total_reply_count', $total_replies );
     1565
     1566    return (int) apply_filters( 'bbp_update_forum_reply_count', $total_replies, $forum_id );
    15641567}
    15651568
Note: See TracChangeset for help on using the changeset viewer.