News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Can I make the post count display below the users avatar visible only to admins

Started by Bruce the Shark, January 09, 2015, 03:53:20 PM

Previous topic - Next topic

Bruce the Shark


Antechinus

Code (Find) Select
// Show how many posts they have made.
if (!isset($context['disabled_fields']['posts']))
echo '
<li class="postcount">', $txt['member_postcount'], ': ', $message['member']['posts'], '</li>';



Code (Replace) Select
// Show how many posts they have made.
if ($context['user']['is_admin'])
echo '
<li class="postcount">', $txt['member_postcount'], ': ', $message['member']['posts'], '</li>';

Bruce the Shark

Helloooooo..........Hey Antechinus have you forgotten something???
What file is it...

Deaks

~~~~
Former SMF Project Manager
Former SMF Customizer

"For as lang as hunner o us is in life, in nae wey
will we thole the Soothron tae owergang us. In truth it isna for glory, or wealth, or
honours that we fecht, but for freedom alane, that nae honest cheil gies up but wi life
itsel."

Antechinus

Quote from: Bruce the Shark on January 09, 2015, 04:06:39 PM
Helloooooo..........Hey Antechinus have you forgotten something???
What file is it...

I didn't forget anything. I already knew it which file it was in. :D

Ok, what Runic said.

Bruce the Shark

Thanks Antechinus and Runic that worked good.
But i should mention to you that.
i have logged in as admin and now i cant see any counts at all even when i look at the members profile.

Antechinus

That's another problem then, since edits to that template wouldn't affect profile at all.

Bruce the Shark

i can see the members profile but their post counts are not increasing

Hristo

There is a small typo in Ant's replace code: "is admin" should be "is_admin" IMO.

I will take the opportunity to ask something I wanted to ask for quite some time.  How taxing on performance are these... rules (sorry I'm not a coder and do not know the proper term :)), like:
if ($context['user']['is_owner'] || $context['user']['is_admin'])

Some time ago I wrote a simple mod "Post Count, Registration Date and Email Visible Only to Admin and Owner" which hides them everywhere they exist. Ever since then I wonder whether or not this is a significant performance hit.

P.S. If someone is interested I will upload the mod here.

Arantor

It's not the if branching (if a OR b) that's expensive in itself; it's the expression to be evaluated as to whether it is expensive performance.

In your case you're doing if (variable is basically true OR othervariable is basically true) which is as cheap as it gets. When you start doing functions, though, it becomes a little more important.

if (variable OR expensive_function()) is not the same in performance as if (expensive_function() OR variable) for example. But your stuff is lightweight and assuming the variables at least exist, it's cheap to do.

Hristo


Antechinus

Oops. Thanks Hristo. Fixed the typo.

That's what I get for throwing out answers without thinking about them, because I know them off by heart. :D

Hj Ahmad Rasyid Hj Ismail

I think this code should not be simply replaced too.

if (!isset($context['disabled_fields']['posts']))

Otherwise, admin will no longer be able to disable it later without direct modification. Adding && will suffice or && ( || ) as per code suggested by Hristo.

Again, I don't know about performance wise. Let Arantor comment on that.

Arantor

Again, this stuff is all simple variable truth tests, cheap to drop in.

Antechinus

I was assuming he wouldn't want to see it if he was planning on disabling it. ;)

Hj Ahmad Rasyid Hj Ismail

True. But he can disable it anyway when he change his mind especially if he is using the code provided by Hristo. ;)

Bruce the Shark

Quote from: Hristo on January 09, 2015, 06:11:19 PM
There is a small typo in Ant's replace code: "is admin" should be "is_admin" IMO.

I will take the opportunity to ask something I wanted to ask for quite some time.  How taxing on performance are these... rules (sorry I'm not a coder and do not know the proper term :)), like:
if ($context['user']['is_owner'] || $context['user']['is_admin'])

Some time ago I wrote a simple mod "Post Count, Registration Date and Email Visible Only to Admin and Owner" which hides them everywhere they exist. Ever since then I wonder whether or not this is a significant performance hit.

P.S. If someone is interested I will upload the mod here.

Thanks you, the code is working good. I can see it as an admin and members and guest are hidden which is what i want.

However there still is an issue as the post counts are not increasing?

Would you know what else is needed to amend this.

Hristo

I use exactly same code as those Antechinus provided plus similar changes to other places (other than Display.template.php) and there is no such a problem for me. Are you sure that this change caused your problem? Is there such problem if you revert the change?

Bruce the Shark

I'll have to do a search here somewhere to see if i have disable something.
Technically speaking there shouldn't be anything really stopping this from counting.

Deaks

Post count not increasing owuld not be effected by the code ant gave, multiple things to try, firstly make sure the boards allow posts to increase, like you can post 100 times in chit chat here but your post count wont rise. Their is an option  that shopuld be left unchecked in modify board.

~~~~
Former SMF Project Manager
Former SMF Customizer

"For as lang as hunner o us is in life, in nae wey
will we thole the Soothron tae owergang us. In truth it isna for glory, or wealth, or
honours that we fecht, but for freedom alane, that nae honest cheil gies up but wi life
itsel."

Bruce the Shark

Apologies for the late reply.
In the board permission as mentioned by you Runic where it says Post Counts it was not checked.
I set this before thinking it would make this invisible to all so this was a mistake on my behalf.
I just never thought of going back there and to see if it was enabled.
I just left it as is and this was the main issue form stopping it from increasing in value
It all works good now.
Thanks

Advertisement: