Skip to:
Content

bbPress.org

Opened 11 years ago

Last modified 8 years ago

#2519 new enhancement

Add Replies & Topics Count To bbPress Core

Reported by: hardeepasrani's profile hardeepasrani Owned by: netweb's profile netweb
Milestone: 2.7 Priority: normal
Severity: normal Version:
Component: Component - Users Keywords: has-patch
Cc: hardeepasrani@…, pericam@…, espellcaste@…

Description

I previously posted this on WordPress forum at this link so I'm just copying it from that post.

I'm not a huge php expert but I wanna change something in bbPress. A reader of my website (trickspanda.com) suggest this idea to me & I really loved it so I worked on it. Every top forum software has or should have Replies Created and Topics Started type thing below the user reply.

I don't want to confuse you, so here's is the pic of what I'm trying to say: http://www.trickspanda.com/2014/01/add-replies-topics-count-bbpress/

I'm new to this contribute thing so I'm simply putting the code and stuff I wanted to add to the core of bbPress.

Putting this code in the bbPress loop-single-reply.php file below:

<?php bbp_reply_author_link( array( 'sep' => '<br />', 'show_role' => true ) ); ?>

will do the job:

<?php
// delete or comment out these lines to stop displaying topic count
$topic_count = bbp_get_user_topic_count_raw( bbp_get_reply_author_id( $reply_id )) ;
echo "<br>Topics Started : " ;
echo $topic_count ;
echo "</br>" ;

// delete or comment out these lines to stop displaying replies count

$reply_count = bbp_get_user_reply_count_raw( bbp_get_reply_author_id( $reply_id )) ;
echo "<br>Replies Created : " ;
echo $reply_count ;
echo "</br>" ;
?>

What's your thoughts? Is it a right place and way to post it?

Attachments (8)

loop-single-reply.patch (751 bytes) - added by hardeepasrani 11 years ago.
loop-single-reply and content-single-topic-lead.patch (1.3 KB) - added by hardeepasrani 11 years ago.
loop-single-reply and content-single-topic-lead.2.patch (1.5 KB) - added by hardeepasrani 11 years ago.
loop-single-reply and content-single-topic-lead.3.patch (1.6 KB) - added by hardeepasrani 11 years ago.
2519.5.patch (1.6 KB) - added by netweb 11 years ago.
2519.6.patch (6.9 KB) - added by netweb 11 years ago.
2519.7.patch (7.2 KB) - added by johnjamesjacoby 9 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
2519.8.patch (7.2 KB) - added by netweb 8 years ago.
Refresh of 2519.7.patch against /trunk

Download all attachments as: .zip

Change History (48)

#1 @hardeepasrani
11 years ago

  • Cc hardeepasrani@… added
  • Keywords has-patch added; needs-patch removed

#2 follow-up: @netweb
11 years ago

  • Component changed from Code Improvements to Users
  • Keywords needs-patch added; has-patch removed
  • Priority changed from highest to normal
  • Type changed from defect to enhancement

Thanks for the awesome report, a pretty good first effort. :)

Related #1694

We will probably need to wait for #1694 to be finished before adding this to loop-single-reply.php and we will also most probably need to use bbp_get_user_topic_count and bbp_get_user_reply_count rather than the 'raw' functions in your above code.

I removed 'has-patch' as it is the code but not quite what we use as a patch.

To get started and learn about how to create a patch that is in the format we use here (and the entire WordPress Trac ecosystem) here are a couple of docs to get you on your way:

#3 in reply to: ↑ 2 ; follow-up: @hardeepasrani
11 years ago

Replying to netweb:
Thanks for the reply. I'll read all the articles you shared later today to get started and contribute to bbPress. But can you tell me what I have to do now? I need to submit a patch or anything else?

Thanks again!

#4 in reply to: ↑ 3 ; follow-up: @netweb
11 years ago

Replying to hardeepasrani:

Replying to netweb:
Thanks for the reply. I'll read all the articles you shared later today to get started and contribute to bbPress. But can you tell me what I have to do now? I need to submit a patch or anything else?

Thanks again!

Yes, a patch is what is needed :)

To create the patch you will need to install SVN or Git on your PC/Mac/Unix computer and the articles I linked to above should point you in the right directions to get this setup.

Are you using a PC or Mac?

#5 in reply to: ↑ 4 ; follow-up: @hardeepasrani
11 years ago

Replying to netweb:

Replying to hardeepasrani:

Replying to netweb:
Thanks for the reply. I'll read all the articles you shared later today to get started and contribute to bbPress. But can you tell me what I have to do now? I need to submit a patch or anything else?

Thanks again!

Yes, a patch is what is needed :)

To create the patch you will need to install SVN or Git on your PC/Mac/Unix computer and the articles I linked to above should point you in the right directions to get this setup.

Are you using a PC or Mac?

Sorry for late reply but I had to attend my school. I'm using Windows PC with TurtoiseSVN. I don't have much SVN experience but I know about uploading and stuff with TurtoiseSVN to WordPress Plugin and Google Code repository.

#6 in reply to: ↑ 5 ; follow-ups: @netweb
11 years ago

Replying to hardeepasrani:

Sorry for late reply but I had to attend my school. I'm using Windows PC with TurtoiseSVN. I don't have much SVN experience but I know about uploading and stuff with TurtoiseSVN to WordPress Plugin and Google Code repository.

Cool, all you need to do is follow this tutorial and use the following URL for the bbPress SVN source

http://bbpress.svn.wordpress.org/trunk

And with all that said rather than the code you used in your original ticket we will end up using the following code instead, in the same place your current code is.

<div class="bbp-user-topic-count"><?php printf( __( 'Topics Started: %s',  'bbpress' ), bbp_get_user_topic_count( bbp_get_reply_author_id( $reply_id ) ) ); ?></div>
<div class="bbp-user-reply-count"><?php printf( __( 'Replies Created: %s', 'bbpress' ), bbp_get_user_reply_count( bbp_get_reply_author_id( $reply_id ) ) ); ?></div>

This is based on the upcoming improvements in #1694, so it doesn't quite work yet, but it will :)

#7 in reply to: ↑ 6 @hardeepasrani
11 years ago

Replying to netweb:

Replying to hardeepasrani:

Sorry for late reply but I had to attend my school. I'm using Windows PC with TurtoiseSVN. I don't have much SVN experience but I know about uploading and stuff with TurtoiseSVN to WordPress Plugin and Google Code repository.

Cool, all you need to do is follow this tutorial and use the following URL for the bbPress SVN source

http://bbpress.svn.wordpress.org/trunk

And with all that said rather than the code you used in your original ticket we will end up using the following code instead, in the same place your current code is.

<div class="bbp-user-topic-count"><?php printf( __( 'Topics Started: %s',  'bbpress' ), bbp_get_user_topic_count( bbp_get_reply_author_id( $reply_id ) ) ); ?></div>
<div class="bbp-user-reply-count"><?php printf( __( 'Replies Created: %s', 'bbpress' ), bbp_get_user_reply_count( bbp_get_reply_author_id( $reply_id ) ) ); ?></div>

This is based on the upcoming improvements in #1694, so it doesn't quite work yet, but it will :)

Got it! One more thing, do I have to upload the patch on this post as well after updating in on SVN?

#8 in reply to: ↑ 6 ; follow-up: @hardeepasrani
11 years ago

Replying to netweb:

Replying to hardeepasrani:

Sorry for late reply but I had to attend my school. I'm using Windows PC with TurtoiseSVN. I don't have much SVN experience but I know about uploading and stuff with TurtoiseSVN to WordPress Plugin and Google Code repository.

Cool, all you need to do is follow this tutorial and use the following URL for the bbPress SVN source

http://bbpress.svn.wordpress.org/trunk

And with all that said rather than the code you used in your original ticket we will end up using the following code instead, in the same place your current code is.

<div class="bbp-user-topic-count"><?php printf( __( 'Topics Started: %s',  'bbpress' ), bbp_get_user_topic_count( bbp_get_reply_author_id( $reply_id ) ) ); ?></div>
<div class="bbp-user-reply-count"><?php printf( __( 'Replies Created: %s', 'bbpress' ), bbp_get_user_reply_count( bbp_get_reply_author_id( $reply_id ) ) ); ?></div>

This is based on the upcoming improvements in #1694, so it doesn't quite work yet, but it will :)

I added the patch file and updated the svn as instructed in the tutorial you shared. I also added the patch file to the attachment of this ticket. Do I need to SVN Commit now?

#9 in reply to: ↑ 8 ; follow-up: @netweb
11 years ago

Replying to hardeepasrani:

I added the patch file and updated the svn as instructed in the tutorial you shared. I also added the patch file to the attachment of this ticket.

Awesome, your doing it right :)

Do I need to SVN Commit now?

Ha, you DO NOT have 'commit' access ;)

Only @Matt @JJJ, @JMDodd & Myself have 'commit' access, if you did have commit access that is exactly what you would do though.


A couple of things on your patch, lets change it slightly, rather than where you inserted those lines of code, lets move it down a couple of lines down so it is below the IP address.

Instead of where it is added at line 47 move it down to line #57 after the line with:
<?php endif; ?>

And line before with:
<?php do_action( 'bbp_theme_after_reply_author_details' ); ?>

We also need to patch the file content-single-topic-lead.php with a slightly different version of the code already used. This is for the template that is used when using bbp_show_lead_topic as per this codex article.

It needs to go after line 68
<?php endif; ?>

And before line 70
<?php do_action( 'bbp_theme_after_topic_author_details' ); ?>

<div class="bbp-user-topic-count"><?php printf( __( 'Topics Started: %s',  'bbpress' ), bbp_get_user_topic_count( bbp_get_topic_author_id( $topic_id ) ) ); ?></div>
<div class="bbp-user-reply-count"><?php printf( __( 'Replies Created: %s', 'bbpress' ), bbp_get_user_reply_count( bbp_get_topic_author_id( $topic_id ) ) ); ?></div>
Last edited 11 years ago by netweb (previous) (diff)

#10 in reply to: ↑ 9 @hardeepasrani
11 years ago

Replying to netweb:

Replying to hardeepasrani:

I added the patch file and updated the svn as instructed in the tutorial you shared. I also added the patch file to the attachment of this ticket.

Awesome, your doing it right :)

Do I need to SVN Commit now?

Ha, you DO NOT have 'commit' access ;)

Only @Matt @JJJ, @JMDodd & Myself have 'commit' access, if you did have commit access that is exactly what you would do though.


A couple of things on your patch, lets change it slightly, rather than where you inserted those lines of code, lets move it down a couple of lines down so it is below the IP address.

Instead of where it is added at line 47 move it down to line #57 after the line with:
<?php endif; ?>

And line before with:
<?php do_action( 'bbp_theme_after_reply_author_details' ); ?>

We also need to patch the file content-single-topic-lead.php with a slightly different version of the code already used. This is for the template that is used when using bbp_show_lead_topic as per this codex article.

It needs to go after line 68
<?php endif; ?>

And before line 70
<?php do_action( 'bbp_theme_after_topic_author_details' ); ?>

<div class="bbp-user-topic-count"><?php printf( __( 'Topics Started: %s',  'bbpress' ), bbp_get_user_topic_count( bbp_get_topic_author_id( $topic_id ) ) ); ?></div>
<div class="bbp-user-reply-count"><?php printf( __( 'Replies Created: %s', 'bbpress' ), bbp_get_user_reply_count( bbp_get_topic_author_id( $topic_id ) ) ); ?></div>

The things you described in last comment is something for you to change or me?

And yea, the only the users of SVN can only have the access to commit as I forgot that my plugin repository and this are differ. Thanks for reminding :)

#11 follow-up: @netweb
11 years ago

I added it so that you can make those changes and submit those also, basically it makes the patch for this ticket complete with all the required changes that are needed in all relevent sections of bbPress.

Bonus points if you include all the changes to both files in a single patch :)

#12 in reply to: ↑ 11 @hardeepasrani
11 years ago

Replying to netweb:

I added it so that you can make those changes and submit those also, basically it makes the patch for this ticket complete with all the required changes that are needed in all relevent sections of bbPress.

Bonus points if you include all the changes to both files in a single patch :)

I patched, updated & attached the patched file to this ticket. Anything else left & is it right?

#13 follow-up: @netweb
11 years ago

  • Keywords has-patch added; needs-patch removed

Perfect, congrats and thanks :)

We just need to wait for #1694 to be fixed and we'll come back to this ticket.

#14 in reply to: ↑ 13 @hardeepasrani
11 years ago

Replying to netweb:

Perfect, congrats and thanks :)

We just need to wait for #1694 to be fixed and we'll come back to this ticket.

LOL, any idea when #1694 will be finished, cuz I see that you guys are working on it from last 2 years!

And thanks for your help to guide me through this thing & I learned a lot from it.

#15 follow-up: @netweb
11 years ago

Your welcome and thanks for contributing :)

I've been testing and updating #1694 this afternoon, hopefully tomorrow it will be updated and good to go.

#16 in reply to: ↑ 15 ; follow-up: @hardeepasrani
11 years ago

Replying to netweb:

Your welcome and thanks for contributing :)

I've been testing and updating #1694 this afternoon, hopefully tomorrow it will be updated and good to go.

I'm 17 & using WordPress from about 8-9 months. I never thought that I'd be one of its contributors. But I love open-source!! :)

#17 in reply to: ↑ 16 ; follow-up: @netweb
11 years ago

Replying to hardeepasrani:

I'm 17 & using WordPress from about 8-9 months. I never thought that I'd be one of its contributors. But I love open-source!! :)

Awesome :)

We need to make another change to the patch as we don't keep a count of 'Anonymous Users' topic and reply counts so we don't want to show this if the topic or reply author is an anonymous user.

In loop-single-reply.php the current code needs to be wrapped in the following code:

Before: <?php if ( ! bbp_is_reply_anonymous() ) : ?>
After: <?php endif; ?>

In content-single-topic-lead.php the current code needs to be wrapped in the following code:
Before: <?php if ( ! bbp_is_topic_anonymous() ) : ?>
After: <?php endif; ?>

The indentation also need match the WordPress coding standards as shown here with a perfect example.
http://make.wordpress.org/core/handbook/coding-standards/html/#indentation

#18 in reply to: ↑ 17 ; follow-up: @hardeepasrani
11 years ago

Replying to netweb:

Replying to hardeepasrani:

I'm 17 & using WordPress from about 8-9 months. I never thought that I'd be one of its contributors. But I love open-source!! :)

Awesome :)

We need to make another change to the patch as we don't keep a count of 'Anonymous Users' topic and reply counts so we don't want to show this if the topic or reply author is an anonymous user.

In loop-single-reply.php the current code needs to be wrapped in the following code:

Before: <?php if ( ! bbp_is_reply_anonymous() ) : ?>
After: <?php endif; ?>

In content-single-topic-lead.php the current code needs to be wrapped in the following code:
Before: <?php if ( ! bbp_is_topic_anonymous() ) : ?>
After: <?php endif; ?>

The indentation also need match the WordPress coding standards as shown here with a perfect example.
http://make.wordpress.org/core/handbook/coding-standards/html/#indentation

Added it. Hope it's right.

#19 in reply to: ↑ 18 ; follow-up: @netweb
11 years ago

Replying to hardeepasrani:

Added it. Hope it's right.

Yes, perfect again, thanks :)

#20 in reply to: ↑ 19 ; follow-up: @hardeepasrani
11 years ago

Replying to netweb:

Replying to hardeepasrani:

Added it. Hope it's right.

Yes, perfect again, thanks :)

Thank you, again, lol. Any idea when I will be able to see a working update of bbPress with this code?

#21 in reply to: ↑ 20 ; follow-up: @netweb
11 years ago

Replying to hardeepasrani:

Thank you, again, lol. Any idea when I will be able to see a working update of bbPress with this code?

I'm pretty sure I got #1694 sorted today and added a new patch to the ticket. As long as that is good we should be fine for these in bbPress 2.6.

#22 in reply to: ↑ 21 @hardeepasrani
11 years ago

Replying to netweb:

Replying to hardeepasrani:

Thank you, again, lol. Any idea when I will be able to see a working update of bbPress with this code?

I'm pretty sure I got #1694 sorted today and added a new patch to the ticket. As long as that is good we should be fine for these in bbPress 2.6.

Sounds good!

#23 follow-up: @netweb
11 years ago

My bad, need another update ;)

$topic_id and $reply_id shouldn't be in the code and all instances in the patch needs to be removed. :(

content-single-topic-lead.php
Before:
bbp_get_topic_author_id( $topic_id )

After:
bbp_get_topic_author_id()

loop-single-reply.php
Before:
bbp_get_reply_author_id( $reply_id )

After:
bbp_get_reply_author_id()

#24 in reply to: ↑ 23 ; follow-up: @hardeepasrani
11 years ago

Replying to netweb:

My bad, need another update ;)

$topic_id and $reply_id shouldn't be in the code and all instances in the patch needs to be removed. :(

content-single-topic-lead.php
Before:
bbp_get_topic_author_id( $topic_id )

After:
bbp_get_topic_author_id()

loop-single-reply.php
Before:
bbp_get_reply_author_id( $reply_id )

After:
bbp_get_reply_author_id()

Okay. I added to patch. Is it right now?

#25 in reply to: ↑ 24 @hardeepasrani
11 years ago

Replying to netweb:

Please tell me if it's right or not as soon as you come online. I'll not be around for next 5-6 hours as I have to attend my school now. Good morning from this side of the world.

@netweb
11 years ago

#26 follow-up: @netweb
11 years ago

Again your patch is good :)

In the 2519.5.patch I just uploaded it is functionally the same as yours though it uses:

  • Uses 'tabs' not 'spaces' for code indentation
  • Removes trailing 'whitespace'

Your indentation should always reflect logical structure. Use real tabs and not spaces, as this allows the most flexibility across clients.

http://make.wordpress.org/core/handbook/coding-standards/php/#indentation

Remove trailing whitespace at the end of each line of code.

http://make.wordpress.org/core/handbook/coding-standards/php/#remove-trailing-spaces

This stuff can be a little tricky to get your editor configured correctly to use 'all the coding standards' correctly so that's why I uploaded the patch so you can open it in your editor and see the 'tabs' indentation and no trailing 'whitespace'.

Last edited 11 years ago by netweb (previous) (diff)

#27 in reply to: ↑ 26 @hardeepasrani
11 years ago

Replying to netweb:

Again your patch is good :)

In the 2519.5.patch I just uploaded it is functionally the same as yours though it uses:

  • Uses 'tabs' not 'spaces' for code indentation
  • Removes trailing 'whitespace'

Your indentation should always reflect logical structure. Use real tabs and not spaces, as this allows the most flexibility across clients.

http://make.wordpress.org/core/handbook/coding-standards/php/#indentation

Remove trailing whitespace at the end of each line of code.

http://make.wordpress.org/core/handbook/coding-standards/php/#remove-trailing-spaces

This stuff can be a little tricky to get your editor configured correctly to use 'all the coding standards' correctly so that's why I uploaded the patch so you can open it in your editor and see the 'tabs' indentation and no trailing 'whitespace'.

So, do I need to update the patch with proper formatting?

#28 follow-ups: @GDragoN
11 years ago

This is not the best solution for this, because I see many potential customization problems. In many cases, you would need a way to disable this, and right now this solution doesn't allow for that. It would be better to have something like it is done for breadcrumbs. Function that uses filter to check if we should display it or not.

#29 in reply to: ↑ 28 @hardeepasrani
11 years ago

Replying to GDragoN:

This is not the best solution for this, because I see many potential customization problems. In many cases, you would need a way to disable this, and right now this solution doesn't allow for that. It would be better to have something like it is done for breadcrumbs. Function that uses filter to check if we should display it or not.

Yea, it makes sense. There should be a filter to remove this from appearing in bbPress. Do you have any idea how we can do that? I'm a newbie, so I can press with core, but heavy coding is not my thing...yet.

#30 in reply to: ↑ 28 ; follow-up: @netweb
11 years ago

Replying to GDragoN:

This is not the best solution for this, because I see many potential customization problems. In many cases, you would need a way to disable this, and right now this solution doesn't allow for that. It would be better to have something like it is done for breadcrumbs. Function that uses filter to check if we should display it or not.

I thought about this recently and thought the same, patch incoming.

#31 in reply to: ↑ 30 @hardeepasrani
11 years ago

Replying to netweb:

Replying to GDragoN:

This is not the best solution for this, because I see many potential customization problems. In many cases, you would need a way to disable this, and right now this solution doesn't allow for that. It would be better to have something like it is done for breadcrumbs. Function that uses filter to check if we should display it or not.

I thought about this recently and thought the same, patch incoming.

Shall we mark this ticket as "needs-patch" or something?

@netweb
11 years ago

#32 follow-up: @netweb
11 years ago

  • Milestone changed from Awaiting Review to 2.6

In 2519.6.patch:

  • Adds bbp_author_display_topic_count and bbp_author_display_reply_count functions in /includes/users/template.php with bbp_parse_args for before and after and title.
  • Adds bbp_author_display_topic_count and bbp_author_display_reply_count to content-single-topic-lead.php and loop-single-reply.php templates
  • Both bbp_author_display_topic_count and bbp_author_display_reply_count can be removed from the content-single-topic-lead.php and loop-single-reply.php templates using:
    • apply_filters( 'bbp_no_author_display_topic_count', '__return_true' );
    • apply_filters( 'bbp_no_author_display_reply_count', '__return_true' );
  • Moves bbp_author_ip html from content-single-topic-lead.php and loop-single-reply.php to before/after $args of bbp_get_author_ip so that all the html can be manipulated with bbp_parse_args

#33 in reply to: ↑ 32 @hardeepasrani
11 years ago

Replying to netweb:

In 2519.6.patch:

  • Adds bbp_author_display_topic_count and bbp_author_display_reply_count functions in /includes/users/template.php with bbp_parse_args for before and after and title.
  • Adds bbp_author_display_topic_count and bbp_author_display_reply_count to content-single-topic-lead.php and loop-single-reply.php templates
  • Both bbp_author_display_topic_count and bbp_author_display_reply_count can be removed from the content-single-topic-lead.php and loop-single-reply.php templates using:
    • apply_filters( 'bbp_no_author_display_topic_count', '__return_true' );
    • apply_filters( 'bbp_no_author_display_reply_count', '__return_true' );
  • Moves bbp_author_ip html from content-single-topic-lead.php and loop-single-reply.php to before/after $args of bbp_get_author_ip so that all the html can be manipulated with bbp_parse_args

Yikes! Thanks for working on this page as it gave me idea for a future WordPress tutorial for my website. Do you have any links where I can learn some heavy PHP coding? I mean, I love WordPress & tech stuff, but I was never into coding, but I want to get into the WordPress core & more plugin stuff.

#34 @netweb
11 years ago

There are many PHP tutorials, courses, manuals online, I could not recommend one, use your favorite search engine and start exploring. I can and do throughly recommend bbPress, the code as it is extremely well documented with PHPDoc along with inline comments. Also WordPress' Core Handbook is helpful.

And that said, Trac is not the place to have this discussion, forums are though ;)

This ticket was mentioned in IRC in #bbpress-dev by netweb. View the logs.


10 years ago

#36 @netweb
10 years ago

  • Owner set to netweb

#37 @Stagger Lee
9 years ago

  • Cc pericam@… added

@johnjamesjacoby
9 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

#38 @espellcaste
9 years ago

  • Cc espellcaste@… added

@netweb
8 years ago

Refresh of 2519.7.patch against /trunk

#39 @netweb
8 years ago

Note: With 2519.8.patch the test_bbp_get_author_ip() unit test will need updating

#40 @johnjamesjacoby
8 years ago

  • Milestone changed from 2.6 to 2.7

Thanks everyone for the work so far.

At this point, I don't love the amount of code this changes, so I'm going to bump it to 2.7.

I'd prefer that we have a more sane function for the author-area of a post, and the output of that template function be easily filtered to allow for things such as this, without it being a core feature.

Specifically, post-counts aren't hugely useful across the WordPress.org forums, and bbPress hasn't historically considered a post-count as a clear-enough indication of contributor quality to include it in core (no different than a blog post count doesn't directly indicate a positive reputation, either.)

Note: See TracTickets for help on using tickets.