Skip to:
Content

bbPress.org

Changeset 4258


Ignore:
Timestamp:
10/19/2012 07:42:49 AM (12 years ago)
Author:
johnjamesjacoby
Message:

Number Formatting:

  • Introduce $integer parameter to template-tags to switch filter for integer usage.
  • Use absint() where appropriate when getting counts.
  • Smarter int type casting.
  • Fixes bug where calculations were being done against formatted strings.
  • Fixes #1974.
Location:
trunk/bbp-includes
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/bbp-includes/core/widgets.php

    r4249 r4258  
    521521     *                                         time
    522522     * @uses bbp_get_topic_id() To get the topic id
    523      * @uses bbp_get_topic_reply_count() To get the topic reply count
    524523     */
    525524    public function widget( $args, $instance ) {
  • trunk/bbp-includes/forums/functions.php

    r4249 r4258  
    955955    // Get some counts
    956956    $forum_id          = bbp_get_forum_id( $forum_id );
    957     $topic_count       = bbp_get_forum_topic_count( $forum_id, false );
    958     $total_topic_count = bbp_get_forum_topic_count( $forum_id, true  );
     957    $topic_count       = bbp_get_forum_topic_count( $forum_id, false, false );
     958    $total_topic_count = bbp_get_forum_topic_count( $forum_id, true,  false );
    959959
    960960    // Update this forum id
     
    974974
    975975                // Get forum counts
    976                 $parent_topic_count       = bbp_get_forum_topic_count( $parent_forum_id, false );
    977                 $parent_total_topic_count = bbp_get_forum_topic_count( $parent_forum_id, true  );
     976                $parent_topic_count       = bbp_get_forum_topic_count( $parent_forum_id, false, false );
     977                $parent_total_topic_count = bbp_get_forum_topic_count( $parent_forum_id, true,  false );
    978978
    979979                // Update counts
  • trunk/bbp-includes/forums/template-tags.php

    r4249 r4258  
    694694
    695695    // Bail if there are no subforums
    696     if ( !bbp_get_forum_subforum_count( $forum_id ) )
     696    if ( !bbp_get_forum_subforum_count( $forum_id, false ) )
    697697        return;
    698698
     
    11171117     */
    11181118    function bbp_get_forum_topics_link( $forum_id = 0 ) {
    1119 
    11201119        $forum    = bbp_get_forum( $forum_id );
    11211120        $forum_id = $forum->ID;
    1122         $topics   = bbp_get_forum_topic_count( $forum_id );
    1123         $topics   = sprintf( _n( '%s topic', '%s topics', $topics, 'bbpress' ), $topics );
     1121        $topics   = sprintf( _n( '%s topic', '%s topics', bbp_get_forum_topic_count( $forum_id, true, false ), 'bbpress' ), bbp_get_forum_topic_count( $forum_id ) );
    11241122        $retval   = '';
    11251123
     
    11571155 * @since bbPress (r2464)
    11581156 *
     1157 * @param int $forum_id Optional. Forum id to check
     1158 * @param boolean $integer Optional. Whether or not to format the result
    11591159 * @uses bbp_get_forum_subforum_count() To get the forum's subforum count
    1160  * @param int $forum_id Optional. Forum id to check
    1161  */
    1162 function bbp_forum_subforum_count( $forum_id = 0 ) {
    1163     echo bbp_get_forum_subforum_count( $forum_id );
     1160 */
     1161function bbp_forum_subforum_count( $forum_id = 0, $integer = false ) {
     1162    echo bbp_get_forum_subforum_count( $forum_id, $integer );
    11641163}
    11651164    /**
     
    11691168     *
    11701169     * @param int $forum_id Optional. Forum id
     1170     * @param boolean $integer Optional. Whether or not to format the result
    11711171     * @uses bbp_get_forum_id() To get the forum id
    11721172     * @uses get_post_meta() To get the subforum count
     
    11751175     * @return int Forum's subforum count
    11761176     */
    1177     function bbp_get_forum_subforum_count( $forum_id = 0 ) {
     1177    function bbp_get_forum_subforum_count( $forum_id = 0, $integer = false ) {
    11781178        $forum_id    = bbp_get_forum_id( $forum_id );
    1179         $forum_count = get_post_meta( $forum_id, '_bbp_forum_subforum_count', true );
    1180 
    1181         return apply_filters( 'bbp_get_forum_subforum_count', (int) $forum_count, $forum_id );
     1179        $forum_count = absint( get_post_meta( $forum_id, '_bbp_forum_subforum_count', true ) );
     1180        $filter      = ( true === $integer ) ? 'bbp_get_forum_subforum_count_int' : 'bbp_get_forum_subforum_count';
     1181
     1182        return apply_filters( $filter, $forum_count, $forum_id );
    11821183    }
    11831184
     
    11891190 * @param int $forum_id Optional. Forum id
    11901191 * @param bool $total_count Optional. To get the total count or normal count?
     1192 * @param boolean $integer Optional. Whether or not to format the result
    11911193 * @uses bbp_get_forum_topic_count() To get the forum topic count
    11921194 */
    1193 function bbp_forum_topic_count( $forum_id = 0, $total_count = true ) {
    1194     echo bbp_get_forum_topic_count( $forum_id, $total_count );
     1195function bbp_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) {
     1196    echo bbp_get_forum_topic_count( $forum_id, $total_count, $integer );
    11951197}
    11961198    /**
     
    12021204     * @param bool $total_count Optional. To get the total count or normal
    12031205     *                           count? Defaults to total.
     1206     * @param boolean $integer Optional. Whether or not to format the result
    12041207     * @uses bbp_get_forum_id() To get the forum id
    12051208     * @uses get_post_meta() To get the forum topic count
     
    12081211     * @return int Forum topic count
    12091212     */
    1210     function bbp_get_forum_topic_count( $forum_id = 0, $total_count = true ) {
     1213    function bbp_get_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) {
    12111214        $forum_id = bbp_get_forum_id( $forum_id );
    1212         $topics   = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_topic_count' : '_bbp_total_topic_count', true );
    1213 
    1214         return apply_filters( 'bbp_get_forum_topic_count', (int) $topics, $forum_id );
     1215        $meta_key = empty( $total_count ) ? '_bbp_topic_count' : '_bbp_total_topic_count';
     1216        $topics   = absint( get_post_meta( $forum_id, $meta_key, true ) );
     1217        $filter   = ( true === $integer ) ? 'bbp_get_forum_topic_count_int' : 'bbp_get_forum_topic_count';
     1218
     1219        return apply_filters( $filter, $topics, $forum_id );
    12151220    }
    12161221
     
    12221227 * @param int $forum_id Optional. Forum id
    12231228 * @param bool $total_count Optional. To get the total count or normal count?
     1229 * @param boolean $integer Optional. Whether or not to format the result
    12241230 * @uses bbp_get_forum_reply_count() To get the forum reply count
    12251231 */
    1226 function bbp_forum_reply_count( $forum_id = 0, $total_count = true ) {
    1227     echo bbp_get_forum_reply_count( $forum_id, $total_count );
     1232function bbp_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) {
     1233    echo bbp_get_forum_reply_count( $forum_id, $total_count, $integer );
    12281234}
    12291235    /**
     
    12351241     * @param bool $total_count Optional. To get the total count or normal
    12361242     *                           count?
     1243     * @param boolean $integer Optional. Whether or not to format the result
    12371244     * @uses bbp_get_forum_id() To get the forum id
    12381245     * @uses get_post_meta() To get the forum reply count
     
    12411248     * @return int Forum reply count
    12421249     */
    1243     function bbp_get_forum_reply_count( $forum_id = 0, $total_count = true ) {
     1250    function bbp_get_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) {
    12441251        $forum_id = bbp_get_forum_id( $forum_id );
    1245         $replies  = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count', true );
    1246 
    1247         return apply_filters( 'bbp_get_forum_reply_count', (int) $replies, $forum_id );
     1252        $meta_key = empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count';
     1253        $replies  = absint( get_post_meta( $forum_id, $meta_key, true ) );
     1254        $filter   = ( true === $integer ) ? 'bbp_get_forum_reply_count_int' : 'bbp_get_forum_reply_count';
     1255
     1256        return apply_filters( $filter, $replies, $forum_id );
    12481257    }
    12491258
     
    12551264 * @param int $forum_id Optional. Forum id
    12561265 * @param bool $total_count Optional. To get the total count or normal count?
     1266 * @param boolean $integer Optional. Whether or not to format the result
    12571267 * @uses bbp_get_forum_post_count() To get the forum post count
    12581268 */
    1259 function bbp_forum_post_count( $forum_id = 0, $total_count = true ) {
    1260     echo bbp_get_forum_post_count( $forum_id, $total_count );
     1269function bbp_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) {
     1270    echo bbp_get_forum_post_count( $forum_id, $total_count, $integer );
    12611271}
    12621272    /**
     
    12681278     * @param bool $total_count Optional. To get the total count or normal
    12691279     *                           count?
     1280     * @param boolean $integer Optional. Whether or not to format the result
    12701281     * @uses bbp_get_forum_id() To get the forum id
    12711282     * @uses get_post_meta() To get the forum post count
     
    12741285     * @return int Forum post count
    12751286     */
    1276     function bbp_get_forum_post_count( $forum_id = 0, $total_count = true ) {
     1287    function bbp_get_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) {
    12771288        $forum_id = bbp_get_forum_id( $forum_id );
    1278         $topics   = bbp_get_forum_topic_count( $forum_id, $total_count );
    1279         $replies  = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count', true );
    1280 
    1281         return apply_filters( 'bbp_get_forum_post_count', (int) $replies + (int) $topics, $forum_id );
     1289        $topics   = bbp_get_forum_topic_count( $forum_id, $total_count, true );
     1290        $meta_key = empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count';
     1291        $replies  = absint( get_post_meta( $forum_id, $meta_key, true ) );
     1292        $retval   = $replies + $topics;
     1293        $filter   = ( true === $integer ) ? 'bbp_get_forum_post_count_int' : 'bbp_get_forum_post_count';
     1294
     1295        return apply_filters( $filter, $retval, $forum_id );
    12821296    }
    12831297
     
    12891303 *
    12901304 * @param int $forum_id Optional. Topic id
     1305 * @param boolean $integer Optional. Whether or not to format the result
    12911306 * @uses bbp_get_forum_topic_count_hidden() To get the forum hidden topic count
    12921307 */
    1293 function bbp_forum_topic_count_hidden( $forum_id = 0 ) {
    1294     echo bbp_get_forum_topic_count_hidden( $forum_id );
     1308function bbp_forum_topic_count_hidden( $forum_id = 0, $integer = false ) {
     1309    echo bbp_get_forum_topic_count_hidden( $forum_id, $integer );
    12951310}
    12961311    /**
     
    13011316     *
    13021317     * @param int $forum_id Optional. Topic id
     1318     * @param boolean $integer Optional. Whether or not to format the result
    13031319     * @uses bbp_get_forum_id() To get the forum id
    13041320     * @uses get_post_meta() To get the hidden topic count
     
    13071323     * @return int Topic hidden topic count
    13081324     */
    1309     function bbp_get_forum_topic_count_hidden( $forum_id = 0 ) {
     1325    function bbp_get_forum_topic_count_hidden( $forum_id = 0, $integer = false ) {
    13101326        $forum_id = bbp_get_forum_id( $forum_id );
    1311         $topics   = get_post_meta( $forum_id, '_bbp_topic_count_hidden', true );
    1312 
    1313         return (int) apply_filters( 'bbp_get_forum_topic_count_hidden', (int) $topics, $forum_id );
     1327        $topics   = absint( get_post_meta( $forum_id, '_bbp_topic_count_hidden', true ) );
     1328        $filter   = ( true === $integer ) ? 'bbp_get_forum_topic_count_hidden_int' : 'bbp_get_forum_topic_count_hidden';
     1329
     1330        return apply_filters( $filter, $topics, $forum_id );
    13141331    }
    13151332
     
    18221839
    18231840        // Get some forum data
     1841        $tc_int      = bbp_get_forum_topic_count( $forum_id, false );
     1842        $rc_int      = bbp_get_forum_reply_count( $forum_id, false );
    18241843        $topic_count = bbp_get_forum_topic_count( $forum_id );
    18251844        $reply_count = bbp_get_forum_reply_count( $forum_id );
     
    18281847        // Has replies
    18291848        if ( !empty( $reply_count ) ) {
    1830             $reply_text = sprintf( _n( '%s reply', '%s replies', $reply_count, 'bbpress' ), $reply_count );
     1849            $reply_text = sprintf( _n( '%s reply', '%s replies', $rc_int, 'bbpress' ), $reply_count );
    18311850        }
    18321851
     
    18391858        // Forum has no last active data
    18401859        } else {
    1841             $topic_text      = sprintf( _n( '%s topic', '%s topics', $topic_count, 'bbpress' ), $topic_count );
     1860            $topic_text      = sprintf( _n( '%s topic', '%s topics', $tc_int, 'bbpress' ), $topic_count );
    18421861        }
    18431862
  • trunk/bbp-includes/replies/functions.php

    r4255 r4258  
    262262        'post_type'      => bbp_get_reply_post_type(),
    263263        'comment_status' => 'closed',
    264         'menu_order'     => (int) ( bbp_get_topic_reply_count( $topic_id ) + 1 )
     264        'menu_order'     => bbp_get_topic_reply_count( $topic_id, false ) + 1
    265265    ) );
    266266
     
    13421342 * @since bbPress (r3540)
    13431343 *
     1344 * @param int $default Default replies per page (15)
    13441345 * @uses get_option() To get the setting
    13451346 * @uses apply_filters() To allow the return value to be manipulated
    13461347 * @return int
    13471348 */
    1348 function bbp_get_replies_per_page() {
    1349 
    1350     // The default per setting
    1351     $default = 15;
     1349function bbp_get_replies_per_page( $default = 15 ) {
    13521350
    13531351    // Get database option and cast as integer
    1354     $per = $retval = (int) get_option( '_bbp_replies_per_page', $default );
     1352    $retval = get_option( '_bbp_replies_per_page', $default );
    13551353
    13561354    // If return val is empty, set it to default
     
    13591357
    13601358    // Filter and return
    1361     return (int) apply_filters( 'bbp_get_replies_per_page', $retval, $per );
     1359    return absint( apply_filters( 'bbp_get_replies_per_page', $retval, $default ) );
    13621360}
    13631361
     
    13671365 * @since bbPress (r3540)
    13681366 *
     1367 * @param int $default Default replies per page (25)
    13691368 * @uses get_option() To get the setting
    13701369 * @uses apply_filters() To allow the return value to be manipulated
    13711370 * @return int
    13721371 */
    1373 function bbp_get_replies_per_rss_page() {
    1374 
    1375     // The default per setting
    1376     $default = 25;
     1372function bbp_get_replies_per_rss_page( $default = 25 ) {
    13771373
    13781374    // Get database option and cast as integer
    1379     $per = $retval = (int) get_option( '_bbp_replies_per_rss_page', $default );
     1375    $retval = get_option( '_bbp_replies_per_rss_page', $default );
    13801376
    13811377    // If return val is empty, set it to default
     
    13841380
    13851381    // Filter and return
    1386     return (int) apply_filters( 'bbp_get_replies_per_rss_page', $retval, $per );
     1382    return absint( apply_filters( 'bbp_get_replies_per_rss_page', $retval, $default ) );
    13871383}
    13881384
     
    16701666
    16711667        // Make sure the topic has replies before running another query
    1672         $reply_count = bbp_get_topic_reply_count( $topic_id );
     1668        $reply_count = bbp_get_topic_reply_count( $topic_id, false );
    16731669        if ( !empty( $reply_count ) ) {
    16741670
  • trunk/bbp-includes/replies/template-tags.php

    r4255 r4258  
    253253        }
    254254
    255         return (int) apply_filters( 'bbp_get_reply_id', (int) $bbp_reply_id, $reply_id );
     255        return (int) apply_filters( 'bbp_get_reply_id', $bbp_reply_id, $reply_id );
    256256    }
    257257
     
    691691 *
    692692 * @param int $reply_id Optional. Reply id
     693 * @param boolean $integer Optional. Whether or not to format the result
    693694 * @uses bbp_get_reply_revisions() To get the reply revisions
    694695 * @uses apply_filters() Calls 'bbp_get_reply_revision_count'
     
    696697 * @return string reply revision count
    697698 */
    698 function bbp_get_reply_revision_count( $reply_id = 0 ) {
    699     return apply_filters( 'bbp_get_reply_revisions', count( bbp_get_reply_revisions( $reply_id ) ), $reply_id );
     699function bbp_get_reply_revision_count( $reply_id = 0, $integer = false ) {
     700    $count = absint( count( bbp_get_reply_revisions( $reply_id ) ) );
     701    $filter = ( true === $integer ) ? 'bbp_get_reply_revision_count_int' : 'bbp_get_reply_revision_count';
     702
     703    return apply_filters( $filter, $count, $reply_id );
    700704}
    701705
     
    863867        $author_id = get_post_field( 'post_author', $reply_id );
    864868
    865         return (int) apply_filters( 'bbp_get_reply_author_id', (int) $author_id, $reply_id );
     869        return (int) apply_filters( 'bbp_get_reply_author_id', $author_id, $reply_id );
    866870    }
    867871
     
    12671271                $topic_id = bbp_get_topic_id( $topic_id );
    12681272
    1269         return apply_filters( 'bbp_get_reply_topic_id', (int) $topic_id, $reply_id );
     1273        return (int) apply_filters( 'bbp_get_reply_topic_id', $topic_id, $reply_id );
    12701274    }
    12711275
     
    13071311                $forum_id = bbp_get_forum_id( $forum_id );
    13081312
    1309         return apply_filters( 'bbp_get_reply_forum_id', (int) $forum_id, $reply_id );
     1313        return (int) apply_filters( 'bbp_get_reply_forum_id', $forum_id, $reply_id );
    13101314    }
    13111315
     
    13701374            $reply_position++;
    13711375
    1372         return (int) apply_filters( 'bbp_get_reply_position', (int) $reply_position, $reply_id, $topic_id );
     1376        return (int) apply_filters( 'bbp_get_reply_position', $reply_position, $reply_id, $topic_id );
    13731377    }
    13741378
  • trunk/bbp-includes/topics/functions.php

    r4255 r4258  
    30493049 * @since bbPress (r3540)
    30503050 *
     3051 * @param int $default Default replies per page (15)
    30513052 * @uses get_option() To get the setting
    30523053 * @uses apply_filters() To allow the return value to be manipulated
    30533054 * @return int
    30543055 */
    3055 function bbp_get_topics_per_page() {
    3056 
    3057     // The default per setting
    3058     $default = 15;
     3056function bbp_get_topics_per_page( $default = 15 ) {
    30593057
    30603058    // Get database option and cast as integer
    3061     $per = $retval = (int) get_option( '_bbp_topics_per_page', $default );
     3059    $retval = get_option( '_bbp_topics_per_page', $default );
    30623060
    30633061    // If return val is empty, set it to default
     
    30663064
    30673065    // Filter and return
    3068     return (int) apply_filters( 'bbp_get_topics_per_page', $retval, $per );
     3066    return absint( apply_filters( 'bbp_get_topics_per_page', $retval, $default ) );
    30693067}
    30703068
     
    30743072 * @since bbPress (r3540)
    30753073 *
     3074 * @param int $default Default replies per page (25)
    30763075 * @uses get_option() To get the setting
    30773076 * @uses apply_filters() To allow the return value to be manipulated
    30783077 * @return int
    30793078 */
    3080 function bbp_get_topics_per_rss_page() {
    3081 
    3082     // The default per setting
    3083     $default = 25;
     3079function bbp_get_topics_per_rss_page( $default = 25 ) {
    30843080
    30853081    // Get database option and cast as integer
    3086     $per = $retval = (int) get_option( '_bbp_topics_per_rss_page', $default );
     3082    $retval = get_option( '_bbp_topics_per_rss_page', $default );
    30873083
    30883084    // If return val is empty, set it to default
     
    30913087
    30923088    // Filter and return
    3093     return (int) apply_filters( 'bbp_get_topics_per_rss_page', $retval, $per );
     3089    return absint( apply_filters( 'bbp_get_topics_per_rss_page', $retval, $default ) );
    30943090}
    30953091
  • trunk/bbp-includes/topics/template-tags.php

    r4255 r4258  
    737737
    738738        // Get total and add 1 if topic is included in the reply loop
    739         $total = bbp_get_topic_reply_count( $topic_id );
     739        $total = bbp_get_topic_reply_count( $topic_id, true );
    740740
    741741        // Bump if topic is in loop
     
    918918 * @return string Topic revision count
    919919 */
    920 function bbp_get_topic_revision_count( $topic_id = 0 ) {
    921     return apply_filters( 'bbp_get_topic_revisions', count( bbp_get_topic_revisions( $topic_id ) ), $topic_id );
     920function bbp_get_topic_revision_count( $topic_id = 0, $integer = false ) {
     921    $count  = absint( count( bbp_get_topic_revisions( $topic_id ) ) );
     922    $filter = ( true === $integer ) ? 'bbp_get_topic_revision_count_int' : 'bbp_get_topic_revision_count';
     923
     924    return apply_filters( $filter, $count, $topic_id );
    922925}
    923926
     
    18551858        $topic    = bbp_get_topic( bbp_get_topic_id( (int) $topic_id ) );
    18561859        $topic_id = $topic->ID;
    1857         $replies  = bbp_get_topic_reply_count( $topic_id );
    1858         $replies  = sprintf( _n( '%s reply', '%s replies', $replies, 'bbpress' ), $replies );
     1860        $replies  = sprintf( _n( '%s reply', '%s replies', bbp_get_topic_reply_count( $topic_id, true ), 'bbpress' ), bbp_get_topic_reply_count( $topic_id ) );
    18591861        $retval   = '';
    18601862
     
    18931895 *
    18941896 * @param int $topic_id Optional. Topic id
     1897 * @param boolean $integer Optional. Whether or not to format the result
    18951898 * @uses bbp_get_topic_reply_count() To get the topic reply count
    18961899 */
    1897 function bbp_topic_reply_count( $topic_id = 0 ) {
    1898     echo bbp_get_topic_reply_count( $topic_id );
     1900function bbp_topic_reply_count( $topic_id = 0, $integer = false ) {
     1901    echo bbp_get_topic_reply_count( $topic_id, $integer );
    18991902}
    19001903    /**
     
    19041907     *
    19051908     * @param int $topic_id Optional. Topic id
     1909     * @param boolean $integer Optional. Whether or not to format the result
    19061910     * @uses bbp_get_topic_id() To get the topic id
    19071911     * @uses get_post_meta() To get the topic reply count meta
     
    19101914     * @return int Reply count
    19111915     */
    1912     function bbp_get_topic_reply_count( $topic_id = 0 ) {
     1916    function bbp_get_topic_reply_count( $topic_id = 0, $integer = false ) {
    19131917        $topic_id = bbp_get_topic_id( $topic_id );
    1914         $replies  = get_post_meta( $topic_id, '_bbp_reply_count', true );
    1915 
    1916         return apply_filters( 'bbp_get_topic_reply_count', (int) $replies, $topic_id );
     1918        $replies  = absint( get_post_meta( $topic_id, '_bbp_reply_count', true ) );
     1919        $filter   = ( true === $integer ) ? 'bbp_get_topic_reply_count_int' : 'bbp_get_topic_reply_count';
     1920
     1921        return apply_filters( $filter, $replies, $topic_id );
    19171922    }
    19181923
     
    19231928 *
    19241929 * @param int $topic_id Optional. Topic id
     1930 * @param boolean $integer Optional. Whether or not to format the result
    19251931 * @uses bbp_get_topic_post_count() To get the topic post count
    19261932 */
    1927 function bbp_topic_post_count( $topic_id = 0 ) {
    1928     echo bbp_get_topic_post_count( $topic_id );
     1933function bbp_topic_post_count( $topic_id = 0, $integer = false ) {
     1934    echo bbp_get_topic_post_count( $topic_id, $integer );
    19291935}
    19301936    /**
     
    19341940     *
    19351941     * @param int $topic_id Optional. Topic id
     1942     * @param boolean $integer Optional. Whether or not to format the result
    19361943     * @uses bbp_get_topic_id() To get the topic id
    19371944     * @uses get_post_meta() To get the topic post count meta
     
    19401947     * @return int Post count
    19411948     */
    1942     function bbp_get_topic_post_count( $topic_id = 0 ) {
     1949    function bbp_get_topic_post_count( $topic_id = 0, $integer = false ) {
    19431950        $topic_id = bbp_get_topic_id( $topic_id );
    1944         $replies  = get_post_meta( $topic_id, '_bbp_reply_count', true );
    1945 
    1946         return apply_filters( 'bbp_get_topic_post_count', (int) $replies + 1, $topic_id );
     1951        $replies  = absint( get_post_meta( $topic_id, '_bbp_reply_count', true ) ) + 1;
     1952        $filter   = ( true === $integer ) ? 'bbp_get_topic_post_count_int' : 'bbp_get_topic_post_count';
     1953
     1954        return apply_filters( $filter, $replies, $topic_id );
    19471955    }
    19481956
     
    19541962 *
    19551963 * @param int $topic_id Optional. Topic id
     1964 * @param boolean $integer Optional. Whether or not to format the result
    19561965 * @uses bbp_get_topic_reply_count_hidden() To get the topic hidden reply count
    19571966 */
    1958 function bbp_topic_reply_count_hidden( $topic_id = 0 ) {
    1959     echo bbp_get_topic_reply_count_hidden( $topic_id );
     1967function bbp_topic_reply_count_hidden( $topic_id = 0, $integer = false ) {
     1968    echo bbp_get_topic_reply_count_hidden( $topic_id, $integer );
    19601969}
    19611970    /**
     
    19661975     *
    19671976     * @param int $topic_id Optional. Topic id
     1977     * @param boolean $integer Optional. Whether or not to format the result
    19681978     * @uses bbp_get_topic_id() To get the topic id
    19691979     * @uses get_post_meta() To get the hidden reply count
     
    19721982     * @return int Topic hidden reply count
    19731983     */
    1974     function bbp_get_topic_reply_count_hidden( $topic_id = 0 ) {
     1984    function bbp_get_topic_reply_count_hidden( $topic_id = 0, $integer = false ) {
    19751985        $topic_id = bbp_get_topic_id( $topic_id );
    1976         $replies  = get_post_meta( $topic_id, '_bbp_reply_count_hidden', true );
    1977 
    1978         return (int) apply_filters( 'bbp_get_topic_reply_count_hidden', (int) $replies, $topic_id );
     1986        $replies  = absint( get_post_meta( $topic_id, '_bbp_reply_count_hidden', true ) );
     1987        $filter   = ( true === $integer ) ? 'bbp_get_topic_reply_count_hidden_int' : 'bbp_get_topic_reply_count_hidden';
     1988
     1989        return apply_filters( $filter, $replies, $topic_id );
    19791990    }
    19801991
     
    19871998 * @uses bbp_get_topic_voice_count() To get the topic voice count
    19881999 */
    1989 function bbp_topic_voice_count( $topic_id = 0 ) {
    1990     echo bbp_get_topic_voice_count( $topic_id );
     2000function bbp_topic_voice_count( $topic_id = 0, $integer = false ) {
     2001    echo bbp_get_topic_voice_count( $topic_id, $integer );
    19912002}
    19922003    /**
     
    20022013     * @return int Voice count of the topic
    20032014     */
    2004     function bbp_get_topic_voice_count( $topic_id = 0 ) {
     2015    function bbp_get_topic_voice_count( $topic_id = 0, $integer = false ) {
    20052016        $topic_id = bbp_get_topic_id( $topic_id );
    2006         $voices   = get_post_meta( $topic_id, '_bbp_voice_count', true );
    2007 
    2008         return apply_filters( 'bbp_get_topic_voice_count', (int) $voices, $topic_id );
     2017        $voices   = absint( get_post_meta( $topic_id, '_bbp_voice_count', true ) );
     2018        $filter   = ( true === $integer ) ? 'bbp_get_topic_voice_count_int' : 'bbp_get_topic_voice_count';
     2019
     2020        return apply_filters( $filter, $voices, $topic_id );
    20092021    }
    20102022
  • trunk/bbp-includes/users/options.php

    r4249 r4258  
    126126 *
    127127 * @param int $user_id
     128 * @param boolean $integer Optional. Whether or not to format the result
    128129 * @uses bbp_get_user_topic_count()
    129130 * @return string
    130131 */
    131 function bbp_user_topic_count( $user_id = 0 ) {
    132     echo bbp_get_user_topic_count( $user_id );
     132function bbp_user_topic_count( $user_id = 0, $integer = false ) {
     133    echo bbp_get_user_topic_count( $user_id, $integer );
    133134}
    134135    /**
     
    138139     *
    139140     * @param int $user_id
     141     * @param boolean $integer Optional. Whether or not to format the result
    140142     * @uses bbp_get_user_id()
    141143     * @uses get_user_option()
     
    143145     * @return string
    144146     */
    145     function bbp_get_user_topic_count( $user_id = 0 ) {
    146 
    147         // Validate user id
    148         $user_id = bbp_get_user_id( $user_id );
    149         if ( empty( $user_id ) )
    150             return false;
    151 
    152         $count = get_user_option( '_bbp_topic_count', $user_id );
    153 
    154         return apply_filters( 'bbp_get_user_topic_count', (int) $count, $user_id );
     147    function bbp_get_user_topic_count( $user_id = 0, $integer = false ) {
     148
     149        // Validate user id
     150        $user_id = bbp_get_user_id( $user_id );
     151        if ( empty( $user_id ) )
     152            return false;
     153
     154        $count  = absint( get_user_option( '_bbp_topic_count', $user_id ) );
     155        $filter = ( false == $integer ) ? 'bbp_get_user_topic_count_int' : 'bbp_get_user_topic_count';
     156
     157        return apply_filters( $filter, $count, $user_id );
    155158    }
    156159
     
    161164 *
    162165 * @param int $user_id
     166 * @param boolean $integer Optional. Whether or not to format the result
    163167 * @uses bbp_get_user_reply_count()
    164168 * @return string
    165169 */
    166 function bbp_user_reply_count( $user_id = 0 ) {
    167     echo bbp_get_user_reply_count( $user_id );
     170function bbp_user_reply_count( $user_id = 0, $integer = false ) {
     171    echo bbp_get_user_reply_count( $user_id, $integer );
    168172}
    169173    /**
     
    173177     *
    174178     * @param int $user_id
     179     * @param boolean $integer Optional. Whether or not to format the result
    175180     * @uses bbp_get_user_id()
    176181     * @uses get_user_option()
     
    178183     * @return string
    179184     */
    180     function bbp_get_user_reply_count( $user_id = 0 ) {
    181 
    182         // Validate user id
    183         $user_id = bbp_get_user_id( $user_id );
    184         if ( empty( $user_id ) )
    185             return false;
    186 
    187         $count = get_user_option( '_bbp_reply_count', $user_id );
    188 
    189         return apply_filters( 'bbp_get_user_reply_count', (int) $count, $user_id );
     185    function bbp_get_user_reply_count( $user_id = 0, $integer = false ) {
     186
     187        // Validate user id
     188        $user_id = bbp_get_user_id( $user_id );
     189        if ( empty( $user_id ) )
     190            return false;
     191
     192        $count  = absint( get_user_option( '_bbp_reply_count', $user_id ) );
     193        $filter = ( true == $integer ) ? 'bbp_get_user_topic_count_int' : 'bbp_get_user_topic_count';
     194
     195        return apply_filters( $filter, $count, $user_id );
    190196    }
    191197
     
    196202 *
    197203 * @param int $user_id
     204 * @param boolean $integer Optional. Whether or not to format the result
    198205 * @uses bbp_get_user_post_count()
    199206 * @return string
    200207 */
    201 function bbp_user_post_count( $user_id = 0 ) {
    202     echo bbp_get_user_post_count( $user_id );
     208function bbp_user_post_count( $user_id = 0, $integer = false ) {
     209    echo bbp_get_user_post_count( $user_id, $integer );
    203210}
    204211    /**
     
    208215     *
    209216     * @param int $user_id
     217     * @param boolean $integer Optional. Whether or not to format the result
    210218     * @uses bbp_get_user_id()
    211219     * @uses get_user_option()
     
    213221     * @return string
    214222     */
    215     function bbp_get_user_post_count( $user_id = 0 ) {
    216 
    217         // Validate user id
    218         $user_id = bbp_get_user_id( $user_id );
    219         if ( empty( $user_id ) )
    220             return false;
    221 
    222         $topics  = bbp_get_user_topic_count( $user_id );
    223         $replies = bbp_get_user_reply_count( $user_id );
    224         $count   = (int) $topics + (int) $replies;
    225 
    226         return apply_filters( 'bbp_get_user_post_count', (int) $count, $user_id );
     223    function bbp_get_user_post_count( $user_id = 0, $integer = false ) {
     224
     225        // Validate user id
     226        $user_id = bbp_get_user_id( $user_id );
     227        if ( empty( $user_id ) )
     228            return false;
     229
     230        $topics  = bbp_get_user_topic_count( $user_id, true );
     231        $replies = bbp_get_user_reply_count( $user_id, true );
     232        $count   = absint( $topics + $replies );
     233        $filter  = ( true == $integer ) ? 'bbp_get_user_post_count_int' : 'bbp_get_user_post_count';
     234
     235        return apply_filters( $filter, $count, $user_id );
    227236    }
    228237
Note: See TracChangeset for help on using the changeset viewer.