Support Forum
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
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?
YELLOW
SWORDFISH
|
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.
YELLOW
SWORDFISH
|
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?
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 🙂
YELLOW
SWORDFISH
|
good news... thanks for the update...
Visit Cruise Talk Central and Mr Papa's World
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?
1 Guest(s)