Skip to:
Content

bbPress.org


Ignore:
Timestamp:
02/23/2017 11:24:29 PM (8 years ago)
Author:
johnjamesjacoby
Message:

Common: Introduce bbp_number_not_negative() and use it in the following ways:

  • Register the relevant meta-data keys for posts & users, so updated values can never be invalid
  • Filter return values for existing database values that might be invalid on existing installs
  • Use in place of intval() or (int) casts where negative values should not exist

This has the added benefit of introducing the bbp_register_meta hook, for future meta-data registrations (of which bbPress has much of.) We'll concentrate on counts for 2.6, and integrate IDs and timestamps in future releases.

See #3059.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/topics/template.php

    r6291 r6302  
    10701070 */
    10711071function bbp_get_topic_revision_count( $topic_id = 0, $integer = false ) {
    1072     $count  = (int) count( bbp_get_topic_revisions( $topic_id ) );
    1073     $filter = ( true === $integer ) ? 'bbp_get_topic_revision_count_int' : 'bbp_get_topic_revision_count';
     1072    $topic_id = bbp_get_topic_id( $topic_id );
     1073    $count    = bbp_number_not_negative( count( bbp_get_topic_revisions( $topic_id ) ) );
     1074    $filter   = ( true === $integer )
     1075        ? 'bbp_get_topic_revision_count_int'
     1076        : 'bbp_get_topic_revision_count';
    10741077
    10751078    return apply_filters( $filter, $count, $topic_id );
     
    22582261    function bbp_get_topic_reply_count( $topic_id = 0, $integer = false ) {
    22592262        $topic_id = bbp_get_topic_id( $topic_id );
    2260         $replies  = (int) get_post_meta( $topic_id, '_bbp_reply_count', true );
    2261         $filter   = ( true === $integer ) ? 'bbp_get_topic_reply_count_int' : 'bbp_get_topic_reply_count';
     2263        $replies  = bbp_number_not_negative( get_post_meta( $topic_id, '_bbp_reply_count', true ) );
     2264        $filter   = ( true === $integer )
     2265            ? 'bbp_get_topic_reply_count_int'
     2266            : 'bbp_get_topic_reply_count';
    22622267
    22632268        return apply_filters( $filter, $replies, $topic_id );
     
    22912296    function bbp_get_topic_post_count( $topic_id = 0, $integer = false ) {
    22922297        $topic_id = bbp_get_topic_id( $topic_id );
    2293         $replies  = (int) get_post_meta( $topic_id, '_bbp_reply_count', true ) + 1;
    2294         $filter   = ( true === $integer ) ? 'bbp_get_topic_post_count_int' : 'bbp_get_topic_post_count';
     2298        $replies  = bbp_number_not_negative( get_post_meta( $topic_id, '_bbp_reply_count', true ) + 1 );
     2299        $filter   = ( true === $integer )
     2300            ? 'bbp_get_topic_post_count_int'
     2301            : 'bbp_get_topic_post_count';
    22952302
    22962303        return apply_filters( $filter, $replies, $topic_id );
     
    23262333    function bbp_get_topic_reply_count_hidden( $topic_id = 0, $integer = false ) {
    23272334        $topic_id = bbp_get_topic_id( $topic_id );
    2328         $replies  = (int) get_post_meta( $topic_id, '_bbp_reply_count_hidden', true );
    2329         $filter   = ( true === $integer ) ? 'bbp_get_topic_reply_count_hidden_int' : 'bbp_get_topic_reply_count_hidden';
     2335        $replies  = bbp_number_not_negative( get_post_meta( $topic_id, '_bbp_reply_count_hidden', true ) );
     2336        $filter   = ( true === $integer )
     2337            ? 'bbp_get_topic_reply_count_hidden_int'
     2338            : 'bbp_get_topic_reply_count_hidden';
    23302339
    23312340        return apply_filters( $filter, $replies, $topic_id );
     
    23572366    function bbp_get_topic_voice_count( $topic_id = 0, $integer = false ) {
    23582367        $topic_id = bbp_get_topic_id( $topic_id );
    2359         $voices   = (int) get_post_meta( $topic_id, '_bbp_voice_count', true );
    2360         $filter   = ( true === $integer ) ? 'bbp_get_topic_voice_count_int' : 'bbp_get_topic_voice_count';
     2368        $voices   = bbp_number_not_negative( get_post_meta( $topic_id, '_bbp_voice_count', true ) );
     2369        $filter   = ( true === $integer )
     2370            ? 'bbp_get_topic_voice_count_int'
     2371            : 'bbp_get_topic_voice_count';
    23612372
    23622373        return apply_filters( $filter, $voices, $topic_id );
Note: See TracChangeset for help on using the changeset viewer.