Skip to:
Content

bbPress.org

Ticket #2519: 2519.7.patch

File 2519.7.patch, 7.2 KB (added by johnjamesjacoby, 10 years ago)

Better, but still not convinced. Try to better guess $user_id and have default unknown text if no count is retrieved for some reason

  • includes/forums/capabilities.php

     
    214214/**
    215215 * Maps forum moderator capabilities
    216216 *
    217  * @since bbPress (rXXXX)
     217 * @since bbPress (r5834)
    218218 *
    219219 * @param array  $caps Capabilities for meta capability.
    220220 * @param string $cap Capability name.
  • includes/users/template.php

     
    603603                // Parse arguments against default values
    604604                $r = bbp_parse_args( $args, array(
    605605                        'post_id' => $post_id,
    606                         'before'  => '<span class="bbp-author-ip">(',
    607                         'after'   => ')</span>'
     606                        'before'  => '<div class="bbp-reply-ip"><span class="bbp-author-ip">(',
     607                        'after'   => ')</span></div>'
    608608                ), 'get_author_ip' );
    609609
    610610                // Get the author IP meta value
     
    620620                return apply_filters( 'bbp_get_author_ip', $author_ip, $r );
    621621        }
    622622
     623
     624/** User Topic and Reply Display Counts ***************************************/
     625
     626/**
     627 * Output the user topic counts
     628 *
     629 * @since bbPress (r5863)
     630 *
     631 * @param mixed $args Optional. If an integer, it is used as user id.
     632 * @uses bbp_get_author_display_topic_count() To get the user topic counts
     633 */
     634function bbp_author_display_topic_count( $args = '' ) {
     635        echo bbp_get_author_display_topic_count( $args );
     636}
     637        /**
     638         * Return the user topic counts
     639         *
     640         * @since bbPress (r5863)
     641         *
     642         * @param mixed $args Optional. If an integer, it is used as user id.
     643         * @uses apply_filters Calls 'bbp_no_author_display_topic_count' to
     644         *                      not display users topics started counts
     645         * @uses bbp_get_user_id() To get the user id
     646         * @uses bbp_get_user_topic_count To get the users topics started count
     647         * @uses apply_filters() Calls 'bbp_get_author_display_topic_count' with the
     648         *                        topics started count and args
     649         * @return string Users topics started count
     650         */
     651        function bbp_get_author_display_topic_count( $args = '' ) {
     652
     653                // Turn off author displayed topic counts
     654                if ( apply_filters( 'bbp_no_author_display_topic_count', is_front_page() ) ) {
     655                        return;
     656                }
     657
     658                // Parse arguments against default values
     659                $r = bbp_parse_args( $args, array(
     660                        'post_id' => 0,
     661                        'before'  => '<div class="bbp-author-topic-count">',
     662                        'title'   => __( 'Topics Started: ', 'bbpress' ),
     663                        'after'   => '</div>'
     664                ), 'get_author_display_topic_count' );
     665
     666                // Used as user ID
     667                if ( is_numeric( $args ) ) {
     668                        $user_id = bbp_get_user_id( $args );
     669
     670                // Use post ID author
     671                } else {
     672                        $user_id = bbp_get_topic_author_id( $r['post_id'] );
     673                }
     674
     675                // Get the users topic count
     676                if ( ! empty( $user_id ) ) {
     677                        $topic_count = bbp_get_user_topic_count( $user_id );
     678                } else {
     679                        $topic_count = __( 'unknown', 'bbpress' );
     680                }
     681
     682                // Concatenate
     683                $topic_count = $r['before'] . $r['title'] . $topic_count . $r['after'];
     684
     685                return apply_filters( 'bbp_get_author_display_topic_count', $topic_count, $r, $args );
     686        }
     687
     688/**
     689 * Output the user reply counts
     690 *
     691 * @since bbPress (r5863)
     692 *
     693 * @param mixed $args Optional. If an integer, it is used as user id.
     694 * @uses bbp_get_author_display_reply_count() To get the user reply counts
     695 */
     696function bbp_author_display_reply_count( $args = '' ) {
     697        echo bbp_get_author_display_reply_count( $args );
     698}
     699        /**
     700         * Return the user reply counts
     701         *
     702         * @since bbPress (r5863)
     703         *
     704         * @param mixed $args Optional. If an integer, it is used as user id.
     705         * @uses apply_filters Calls 'bbp_no_author_display_reply_count' to
     706         *                      not display user replies created counts
     707         * @uses bbp_get_user_id() To get the user id
     708         * @uses bbp_get_user_reply_count To get the users replies created count
     709         * @uses apply_filters() Calls 'bbp_get_author_display_reply_count' with the
     710         *                        topics started count and args
     711         * @return string Users replies created count
     712         */
     713        function bbp_get_author_display_reply_count( $args = '' ) {
     714
     715                // Turn off author author displayed reply counts
     716                if ( apply_filters( 'bbp_no_author_display_reply_count', is_front_page() ) ) {
     717                        return;
     718                }
     719
     720                // Parse arguments against default values
     721                $r = bbp_parse_args( $args, array(
     722                        'post_id' => 0,
     723                        'before'  => '<div class="bbp-author-reply-count">',
     724                        'title'   => __( 'Replies Created: ', 'bbpress' ),
     725                        'after'   => '</div>'
     726                ), 'get_author_display_reply_count' );
     727
     728                // Used as user ID
     729                if ( is_numeric( $args ) ) {
     730                        $user_id = bbp_get_user_id( $args );
     731
     732                // Use post ID author
     733                } else {
     734                        $user_id = bbp_get_reply_author_id( $r['post_id'] );
     735                }
     736
     737                // Get the users reply count
     738                if ( ! empty( $user_id ) ) {
     739                        $reply_count = bbp_get_user_reply_count( $user_id );
     740                } else {
     741                        $reply_count = __( 'unknown', 'bbpress' );
     742                }
     743
     744                // Concatenate
     745                $reply_count = $r['before'] . $r['title'] . $reply_count . $r['after'];
     746
     747                return apply_filters( 'bbp_get_author_display_reply_count', $reply_count, $r, $args );
     748        }
     749
    623750/** Anonymous Fields **********************************************************/
    624751
    625752/**
     
    14461573                return apply_filters( 'bbp_get_user_topics_created_url', $url, $user_id );
    14471574        }
    14481575
    1449 /** Topics Created ************************************************************/
     1576/** Replies Created ************************************************************/
    14501577
    14511578/**
    14521579 * Output the link to the user's replies
  • templates/default/bbpress/content-single-topic-lead.php

     
    5555
    5656                                        <?php do_action( 'bbp_theme_before_topic_author_admin_details' ); ?>
    5757
    58                                         <div class="bbp-topic-ip"><?php bbp_author_ip( bbp_get_topic_id() ); ?></div>
     58                                        <?php bbp_author_ip( bbp_get_topic_id() ); ?>
    5959
    6060                                        <?php do_action( 'bbp_theme_after_topic_author_admin_details' ); ?>
    6161
    6262                                <?php endif; ?>
    6363
     64                                <?php if ( ! bbp_is_topic_anonymous() ) : ?>
     65
     66                                        <?php do_action( 'bbp_theme_before_topic_author_count_details' ); ?>
     67
     68                                        <?php bbp_author_display_topic_count( bbp_get_topic_author_id() ); ?>
     69
     70                                        <?php bbp_author_display_reply_count( bbp_get_topic_author_id() ); ?>
     71
     72                                        <?php do_action( 'bbp_theme_after_topic_author_count_details' ); ?>
     73
     74                                <?php endif; ?>
     75
    6476                                <?php do_action( 'bbp_theme_after_topic_author_details' ); ?>
    6577
    6678                        </div><!-- .bbp-topic-author -->
  • templates/default/bbpress/loop-single-reply.php

     
    4444
    4545                        <?php do_action( 'bbp_theme_before_reply_author_admin_details' ); ?>
    4646
    47                         <div class="bbp-reply-ip"><?php bbp_author_ip( bbp_get_reply_id() ); ?></div>
     47                        <?php bbp_author_ip( bbp_get_reply_id() ); ?>
    4848
    4949                        <?php do_action( 'bbp_theme_after_reply_author_admin_details' ); ?>
    5050
    5151                <?php endif; ?>
    5252
     53                <?php if ( ! bbp_is_reply_anonymous() ) : ?>
     54
     55                        <?php do_action( 'bbp_theme_before_reply_author_count_details' ); ?>
     56
     57                        <?php bbp_author_display_topic_count( bbp_get_reply_author_id() ); ?>
     58
     59                        <?php bbp_author_display_reply_count( bbp_get_reply_author_id() ); ?>
     60
     61                        <?php do_action( 'bbp_theme_after_reply_author_count_details' ); ?>
     62
     63                <?php endif; ?>
     64
    5365                <?php do_action( 'bbp_theme_after_reply_author_details' ); ?>
    5466
    5567        </div><!-- .bbp-reply-author -->