Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
general-topic
Looking for a way to stop excluding mods from Top Posters list
Avatar
Hulk1977
Member
sp_UserOfflineSmall Offline
Oct 31, 2016 - 1:52 am

Hello,

I want to stop moderators from being excluded from the Top Posters list at the bottom of the forum (at the same time, if possible, I'd like to remain excluded myself). Reason - they were top posters until appointed moderators and I think the position in the Top motivates them to post more (currently they post much less and lurk more, and I really value them as posters). How do I do this?

Thanks

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Oct 31, 2016 - 3:43 am

Sadly - there is no built in way to do this. This may or may not be considered an oversight but you are the first to ever ask for this.

However - we can use a WordPress style filter to accomplish it. Currently the code does not have a filter hook but I can tell you how to add it and we would add it too so that on the next update it will be a part of the core.

If this interests you it will mean making 1 small edit to a code file and creating one new code file with some code I can give you. Very easy. Do you want to do this?

andy-signature.png
YELLOW
SWORDFISH
Avatar
Hulk1977
Member
sp_UserOfflineSmall Offline
Oct 31, 2016 - 3:52 am

Yes, I am willing to try.

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Oct 31, 2016 - 4:23 am

Excellent. A simple rule if you do not know it. All edits must be made in plain text - using tools like Notepad (Win) or TextEdit (macOS). To edit existing files on your server, your hosting control panel will usually come with a simple editor.

1: Editing existing code file:

The file is /wp-content/plugins/simple-press/forum/database/sp-db-statistics.php

About two thirds down - on line 272 you will find the function sp_get_top_poster_stats()

Immediately before the line of code...

$topPosters = $spdb->select();

add the following - so the last 3 lines looks like:

$spdb = apply_filters('sph_top_poster_stats_query', $spdb);
$topPosters = $spdb->select();
return $topPosters;

Use the 'raw code' button on the code and copy from the popup.

2: Add new code file:

Create a new code file with the code below. The file needs to be named sp-user-functions.php and needs to reside in the 'wp-content' folder. NOT in a plugin folder. Simple:Press will find it in wp-content and will never overwrite it or change it.

This is the code function:

add_filter('sph_top_poster_stats_query', 'add_mods');
function add_mods($query) {
    $query->where = 'hide_stats = 0 AND admin=0 AND posts > -1';
    return $query;
}

Now... this code has to be surrounded by php opening and closing tags which I can't easily show in the code box. So - first line of the file show the opening tag <?php and at the end of the file the closing tag ?> - but remember that there must be no empty lines at the top or bottom. The tags must be on first and last lines. It really is easy!

Finally - remember that the stats are cached and only refresh themselves about once an hour so you will not necessarily see an instant change. If you want to update them then you can do so in the forum admin > toolbox > cron panel and run the sph_stats_cron task in the run box provided.

And we will add that filter to the code in the next update.

andy-signature.png
YELLOW
SWORDFISH
Avatar
Hulk1977
Member
sp_UserOfflineSmall Offline
Nov 1, 2016 - 4:16 am

Thanks! Works great. My moderators are now back at the top of the list.

I have set the permissions of the new sp-user-functions.php file to 775, is that correct?

Also, I don't really understand what exactly will you do in the next update - will there be an option in the admin menu, or not excluding mods will be the default behaviour, or what, exactly?

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Nov 1, 2016 - 4:23 am

File permissions would more normally be 664. 775 is usual for folders.

The only change we will make to the core for the next update - actually already made and committed - is that filter hook in the stats php file. So as long as you used the same name for the filter as I gave you then it will continue to work for you after you update in the future,

And for everyone else - it will remain the same as now as they will not have the code that actually changes the query -which is what that function does you put into the new code file.

Hope that makes sense 🙂

andy-signature.png
YELLOW
SWORDFISH
Avatar
Hulk1977
Member
sp_UserOfflineSmall Offline
Nov 1, 2016 - 4:28 am

Yes, now it's perfectly clear. Thank you.

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Nov 1, 2016 - 8:41 pm

good news... thanks for the update...

Avatar
Hulk1977
Member
sp_UserOfflineSmall Offline
Dec 17, 2016 - 11:18 am

Yellow Swordfish said
...
The only change we will make to the core for the next update - actually already made and committed - is that filter hook in the stats php file. So as long as you used the same name for the filter as I gave you then it will continue to work for you after you update in the future ...

According to this post,

Yellow Swordfish said
I was just checking as you posted. Seems I was wrong. The filter has not yet gone into the core code because that post and request was made since the last update and the filter is still waiting to be released so my apologies, but you DO need to do part one of that old post as well. 

the filter was still not implemented in the core as of Nov 21st 2016.

The above information is to not make this topic misleading for people with similar issues.

Has the filter been implemented in the latest (5.7.3) release?

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Dec 17, 2016 - 11:25 am

yes - as was promised

andy-signature.png
YELLOW
SWORDFISH
Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 617
Members: 17359
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10125
Posts: 79620