Skip to:

Re: Post count-based titles

About two lines of your plugin are counting posts, and if you didn’t write the query into a variable first it would be one. Far more code is taken up with anything else, hence it’s not just a modification.

In my opinion a neat and efficient solution would be to hook onto the new and delete posts hooks, recalculate title, set in usermeta, and let bb grab that title when it’s needed exactly the same as now. This means an additional database query and calculation of the new title only when new posts are made. Your method means that you do that extra work every time a post is fetched.

To make this also be neat, you should have the possibility of setting titles and corresponding post count values in bb admin rather than having to change values across several lines to get the desired modifications (changing/adding one line of code would still be acceptableish, I suppose). You should also (in my opinion, yeah) use a far neater method of comparing the post count and setting the title from a code perspective; I dislike a long list of elseifs (at least use cases if you have to do it in this sort of way). I would, off the top of my head, use

//$postcount already found
foreach( $possibletitles AS $postcountrequired => $title ) {
if( $postcount >= $postcountrequired ) {
$newtitle = $title;

because that’s like five lines of code and it doesn’t matter how many different post count/title combinations are set, it does not increase in complexity. Putting $possibletitles together from the bb admin would not be difficult either.

So the three or four things you have to do to make this plugin as I like it are counting posts, bb admin panel set up, comparing postcount and possible titles and setting this in the usermeta. “All this hate” comes from the fact that I thought I’d just explained that you can’t just modify the post count plugin to have this functionality – you need way more code than there is in counting posts to do all this – and then you came along and said that all you need to do is just modify the post count plugin. That irritated me.

Sam, I don’t agree with this approach in all cases either but I prefer the very small amount of extra (unnecessary) data in the database (maximally one new record per member with one post or more) to re-querying and recalculating every time a post is displayed. :)

Skip to toolbar