Skip to:
Content

bbPress.org

Changeset 5732


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

Bumps: Normalize type-casting in bump functions.

Props thebrandonallen, netweb. See #2801.

Location:
trunk/src/includes
Files:
3 edited

Legend:

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

    r5731 r5732  
    10511051function bbp_bump_forum_topic_count( $forum_id = 0, $difference = 1, $update_ancestors = true ) {
    10521052
     1053    // Bail if no bump
     1054    if ( empty( $difference ) ) {
     1055        return false;
     1056    }
     1057
    10531058    // Get some counts
    10541059    $forum_id          = bbp_get_forum_id( $forum_id );
    10551060    $topic_count       = bbp_get_forum_topic_count( $forum_id, false, true );
    10561061    $total_topic_count = bbp_get_forum_topic_count( $forum_id, true,  true );
     1062    $difference        = (int) $difference;
    10571063
    10581064    // Update this forum id
    1059     update_post_meta( $forum_id, '_bbp_topic_count',       (int) $topic_count       + (int) $difference );
    1060     update_post_meta( $forum_id, '_bbp_total_topic_count', (int) $total_topic_count + (int) $difference );
     1065    update_post_meta( $forum_id, '_bbp_topic_count',       (int) ( $topic_count       + $difference ) );
     1066    update_post_meta( $forum_id, '_bbp_total_topic_count', (int) ( $total_topic_count + $difference ) );
    10611067
    10621068    // Check for ancestors
     
    10761082
    10771083                // Update counts
    1078                 update_post_meta( $parent_forum_id, '_bbp_topic_count',       (int) $parent_topic_count       + (int) $difference );
    1079                 update_post_meta( $parent_forum_id, '_bbp_total_topic_count', (int) $parent_total_topic_count + (int) $difference );
     1084                update_post_meta( $parent_forum_id, '_bbp_topic_count',       (int) ( $parent_topic_count       + $difference ) );
     1085                update_post_meta( $parent_forum_id, '_bbp_total_topic_count', (int) ( $parent_total_topic_count + $difference ) );
    10801086            }
    10811087        }
    10821088    }
    10831089
    1084     return (int) apply_filters( 'bbp_bump_forum_topic_count', (int) $total_topic_count + (int) $difference, $forum_id, (int) $difference, (bool) $update_ancestors );
     1090    $forum_topic_count = (int) ( $total_topic_count + $difference );
     1091
     1092    return (int) apply_filters( 'bbp_bump_forum_topic_count', $forum_topic_count, $forum_id, $difference, $update_ancestors );
    10851093}
    10861094
     
    11011109function bbp_bump_forum_topic_count_hidden( $forum_id = 0, $difference = 1 ) {
    11021110
     1111    // Bail if no bump
     1112    if ( empty( $difference ) ) {
     1113        return false;
     1114    }
     1115
    11031116    // Get some counts
    11041117    $forum_id    = bbp_get_forum_id( $forum_id );
    11051118    $topic_count = bbp_get_forum_topic_count_hidden( $forum_id, true );
    1106     $new_count   = (int) $topic_count + (int) $difference;
     1119    $difference  = (int) $difference;
     1120    $new_count   = (int) ( $topic_count + $difference );
    11071121
    11081122    // Update this forum id
    1109     update_post_meta( $forum_id, '_bbp_topic_count_hidden', (int) $new_count );
    1110 
    1111     return (int) apply_filters( 'bbp_bump_forum_topic_count_hidden', (int) $new_count, $forum_id, (int) $difference );
     1123    update_post_meta( $forum_id, '_bbp_topic_count_hidden', $new_count );
     1124
     1125    return (int) apply_filters( 'bbp_bump_forum_topic_count_hidden', $new_count, $forum_id, $difference );
    11121126}
    11131127
     
    11281142function bbp_bump_forum_reply_count( $forum_id = 0, $difference = 1, $update_ancestors = true ) {
    11291143
     1144    // Bail if no bump
     1145    if ( empty( $difference ) ) {
     1146        return false;
     1147    }
     1148
    11301149    // Get some counts
    11311150    $forum_id          = bbp_get_forum_id( $forum_id );
    11321151    $topic_count       = bbp_get_forum_reply_count( $forum_id, false, true );
    11331152    $total_reply_count = bbp_get_forum_reply_count( $forum_id, true,  true );
     1153    $difference        = (int) $difference;
    11341154
    11351155    // Update this forum id
    1136     update_post_meta( $forum_id, '_bbp_reply_count',       (int) $topic_count       + (int) $difference );
    1137     update_post_meta( $forum_id, '_bbp_total_reply_count', (int) $total_reply_count + (int) $difference );
     1156    update_post_meta( $forum_id, '_bbp_reply_count',       (int) ( $topic_count       + $difference ) );
     1157    update_post_meta( $forum_id, '_bbp_total_reply_count', (int) ( $total_reply_count + $difference ) );
    11381158
    11391159    // Check for ancestors
     
    11531173
    11541174                // Update counts
    1155                 update_post_meta( $parent_forum_id, '_bbp_reply_count',       (int) $parent_topic_count       + (int) $difference );
    1156                 update_post_meta( $parent_forum_id, '_bbp_total_reply_count', (int) $parent_total_reply_count + (int) $difference );
     1175                update_post_meta( $parent_forum_id, '_bbp_reply_count',       (int) ( $parent_topic_count       + $difference ) );
     1176                update_post_meta( $parent_forum_id, '_bbp_total_reply_count', (int) ( $parent_total_reply_count + $difference ) );
    11571177            }
    11581178        }
    11591179    }
    11601180
    1161     return (int) apply_filters( 'bbp_bump_forum_reply_count', (int) $total_reply_count + (int) $difference, $forum_id, (int) $difference, (bool) $update_ancestors );
     1181    $forum_reply_count = (int) ( $total_reply_count + $difference );
     1182
     1183    return (int) apply_filters( 'bbp_bump_forum_reply_count', $forum_reply_count, $forum_id, $difference, $update_ancestors );
    11621184}
    11631185
  • trunk/src/includes/topics/functions.php

    r5729 r5732  
    23362336function bbp_bump_topic_reply_count( $topic_id = 0, $difference = 1 ) {
    23372337
     2338    // Bail if no bump
     2339    if ( empty( $difference ) ) {
     2340        return false;
     2341    }
     2342
    23382343    // Get counts
    23392344    $topic_id    = bbp_get_topic_id( $topic_id );
    23402345    $reply_count = bbp_get_topic_reply_count( $topic_id, true );
    2341     $new_count   = (int) $reply_count + (int) $difference;
     2346    $difference  = (int) $difference;
     2347    $new_count   = (int) ( $reply_count + $difference );
    23422348
    23432349    // Update this topic id's reply count
    2344     update_post_meta( $topic_id, '_bbp_reply_count', (int) $new_count );
    2345 
    2346     return (int) apply_filters( 'bbp_bump_topic_reply_count', (int) $new_count, $topic_id, (int) $difference );
     2350    update_post_meta( $topic_id, '_bbp_reply_count', $new_count );
     2351
     2352    return (int) apply_filters( 'bbp_bump_topic_reply_count', $new_count, $topic_id, $difference );
    23472353}
    23482354
     
    23632369function bbp_bump_topic_reply_count_hidden( $topic_id = 0, $difference = 1 ) {
    23642370
     2371    // Bail if no bump
     2372    if ( empty( $difference ) ) {
     2373        return false;
     2374    }
     2375
    23652376    // Get counts
    23662377    $topic_id    = bbp_get_topic_id( $topic_id );
    23672378    $reply_count = bbp_get_topic_reply_count_hidden( $topic_id, true );
    2368     $new_count   = (int) $reply_count + (int) $difference;
     2379    $difference  = (int) $difference;
     2380    $new_count   = (int) ( $reply_count + $difference );
    23692381
    23702382    // Update this topic id's hidder reply count
    2371     update_post_meta( $topic_id, '_bbp_reply_count_hidden', (int) $new_count );
    2372 
    2373     return (int) apply_filters( 'bbp_bump_topic_reply_count_hidden', (int) $new_count, $topic_id, (int) $difference );
     2383    update_post_meta( $topic_id, '_bbp_reply_count_hidden', $new_count );
     2384
     2385    return (int) apply_filters( 'bbp_bump_topic_reply_count_hidden', $new_count, $topic_id, $difference );
    23742386}
    23752387
  • trunk/src/includes/users/functions.php

    r5666 r5732  
    17871787function bbp_bump_user_topic_count( $user_id = 0, $difference = 1 ) {
    17881788
     1789    // Bail if no bump
     1790    if ( empty( $difference ) ) {
     1791        return false;
     1792    }
     1793
    17891794    // Validate user ID
    17901795    $user_id = bbp_get_user_id( $user_id );
     
    17991804    }
    18001805
     1806    $difference       = (int) $difference;
     1807    $user_topic_count = (int) ( $count + $difference );
     1808
    18011809    // Add them up and filter them
    1802     $new_count = apply_filters( 'bbp_bump_user_topic_count', ( (int) $count + (int) $difference ), $user_id, $difference, $count );
     1810    $new_count = (int) apply_filters( 'bbp_bump_user_topic_count', $user_topic_count, $user_id, $difference, $count );
    18031811
    18041812    return bbp_update_user_topic_count( $user_id, $new_count );
     
    18171825function bbp_bump_user_reply_count( $user_id = 0, $difference = 1 ) {
    18181826
     1827    // Bail if no bump
     1828    if ( empty( $difference ) ) {
     1829        return false;
     1830    }
     1831
    18191832    // Validate user ID
    18201833    $user_id = bbp_get_user_id( $user_id );
     
    18281841        $count = bbp_get_user_reply_count_raw( $user_id );
    18291842    }
     1843
     1844    $difference       = (int) $difference;
     1845    $user_reply_count = (int) ( $count + $difference );
    18301846
    18311847    // Add them up and filter them
Note: See TracChangeset for help on using the changeset viewer.