Support Forum

Display Admin under Top Posters?

ST Stang5_0
Stang5_0
Member

Forgive if this has been answered elsewhere already as I was not able to find mention.

Can the admin be displayed under Top Posters?  I don’t see where that option would be like I do for members and moderators.

Thank You.

23 Answers

New Answer

YS Yellow Swordfish
Yellow Swordfish
Member

There is no option to do allow for it bu a simopel filter can do the trick.

See this post: https://simple-press.com/support-forum/sp5-general-topics/looking-for-a-way-to-stop-excluding-mods-from-top-posters-list/#p163700

This guy wanted to show moderators in the top posters. All you need to do to show admins is remove the bit in the code where it says ‘AND admins=0’. Like this:

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

All you need to do is part 2 of that post. Part 1 is already in the plugin core

ST Stang5_0
Stang5_0
Member

Thanks for the response.

Here is what sp-user-functions.php looks like

<?php
add_filter(‘sph_top_poster_stats_query’, ‘add_mods’);
function add_mods($query) {
$query->where = ‘hide_stats = 0 AND posts > -1’;
return $query;
}
?>

And starting at line 272 of sp-db-statistics.php

function sp_get_top_poster_stats($count) {
$spdb = new spdbComplex;

$spdb->found_rows = true;
$spdb->table = SFMEMBERS;
$spdb->fields = SFMEMBERS.’.user_id, display_name, posts’;
$spdb->join = array(
SFMEMBERSHIPS.’ ON ‘.SFMEMBERS.’.user_id = ‘.SFMEMBERSHIPS.’.user_id’,
SFUSERGROUPS.’ ON ‘.SFMEMBERSHIPS.’.usergroup_id = ‘.SFUSERGROUPS.’.usergroup_id’);
$spdb->where = ‘hide_stats = 0 AND posts > -1’;
$spdb->groupby = SFMEMBERS.’.user_id’;
$spdb->orderby = ‘hide_stats ASC, posts DESC’;
$spdb->limits = “0, $count”;

$topPosters = $spdb->select();
return $topPosters;

I’ve run the cron but it is still not showing up.

Thought I followed it pretty close but maybe not.

Stang

YS Yellow Swordfish
Yellow Swordfish
Member

I did say you should only do part 2 of that original post. Looks to me like you have taken the filter out of the statistics file. You will need to put that back as it was.

ST Stang5_0
Stang5_0
Member

Putting it back in I get the following at the top of the page:

erid, ‘lastvisit’, 0); } ?>

3
 
 

 

 

Warning: Cannot modify header information – headers already sent by (output started at /home/obmcsalt/public_html/wp-content/plugins/simple-press/forum/database/sp-db-statistics.php:412) in /home/obmcsalt/public_html/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 62

Warning: session_start(): Cannot send session cache limiter – headers already sent (output started at /home/obmcsalt/public_html/wp-content/plugins/simple-press/forum/database/sp-db-statistics.php:412) in /home/obmcsalt/public_html/wp-content/plugins/wp-embed-facebook/lib/class-wp-embed-fb-plugin.php on line 221

This also causes my signature to show back up (we’re talking about this in another post)

Capture-1.PNG
YS Yellow Swordfish
Yellow Swordfish
Member

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.

And those error message suggest you have made an error in the coding,

For the record here is the entire function as it should be:

function sp_get_top_poster_stats($count) {
    $spdb = new spdbComplex;

    $spdb->found_rows = true;
    $spdb->table = SFMEMBERS;
    $spdb->fields = SFMEMBERS.’.user_id, display_name, posts’;
    $spdb->join = array(
SFMEMBERSHIPS.’ ON ‘.SFMEMBERS.’.user_id = ‘.SFMEMBERSHIPS.’.user_id’,
SFUSERGROUPS.’ ON ‘.SFMEMBERSHIPS.’.usergroup_id = ‘.SFUSERGROUPS.’.usergroup_id’);
    $spdb->where = ‘hide_stats = 0 AND admin=0 AND moderator=0 AND posts > -1’;
    $spdb->groupby = SFMEMBERS.’.user_id’;
    $spdb->orderby = ‘hide_stats ASC, posts DESC’;
    $spdb->limits = “0, $count”;

    $spdb = apply_filters(‘sph_top_poster_stats_query’, $spdb);
    $topPosters = $spdb->select();
    return $topPosters;
}

ST Stang5_0
Stang5_0
Member

So starting fresh now with cache turned off and whatnot, to accomplish what I am trying to accomplish should I go to that other post and follow all steps?  Thanks, I’m just trying to clarify what  I need to do.

Regards,

Stang

YS Yellow Swordfish
Yellow Swordfish
Member

Correct – with the one exception of this line:

$query->where = 'hide_stats = 0 AND posts > -1';

which you will need to change from the one used in that other topic.

And apologies for the confusion.

ST Stang5_0
Stang5_0
Member

No problem at all confusion happens.  🙂

OK, so here is what my sp-user-functions.php looks like:

<?php
add_filter(‘sph_top_poster_stats_query’, ‘add_mods’);
function add_mods($query) {
$query->where = ‘hide_stats = 0 AND posts > -1’;
return $query;
}
?>

And from sp-db-statistics.php I have this:

function sp_get_top_poster_stats($count) {
$spdb = new spdbComplex;
$spdb->found_rows = true;
$spdb->table = SFMEMBERS;
$spdb->fields = SFMEMBERS.’.user_id, display_name, posts’;
$spdb->join = array(
SFMEMBERSHIPS.’ ON ‘.SFMEMBERS.’.user_id = ‘.SFMEMBERSHIPS.’.user_id’,
SFUSERGROUPS.’ ON ‘.SFMEMBERSHIPS.’.usergroup_id = ‘.SFUSERGROUPS.’.usergroup_id’);
$spdb->where = ‘hide_stats = 0 AND moderator=0 AND posts > -1’;
$spdb->groupby = SFMEMBERS.’.user_id’;
$spdb->orderby = ‘hide_stats ASC, posts DESC’;
$spdb->limits = “0, $count”;
$spdb = apply_filters(‘sph_top_poster_stats_query’, $spdb);
$topPosters = $spdb->select();
return $topPosters;
}

I have nothing showing up under my Top Posters yet so I’m wondering did I miss something here that you can see?  I did run my chron but still no change.

Thank you!

Stang

YS Yellow Swordfish
Yellow Swordfish
Member

Looks good as far as I can see. So – nothing showing at all? Can you go to the toolbox > Error Log. Clear it using the button at the bottom. Then run the CRON job for the user stats and check back on the log to see if there is anything reported?

YS Yellow Swordfish
Yellow Swordfish
Member

Hold on… There may be more to this. It might not be quite as easy as that. I am investigating…

YS Yellow Swordfish
Yellow Swordfish
Member

No – this is going to need more than this. Sorry. I was overlooking the fact that admins do not belong to user groups. I think I have an answer for you but I need to do a little more research and testing. Afraid it might be tomorrow morning now before I can confirm but if I can work it out tonight I will.

The stumbling block is that the forum admin (i.e., you) can set a user group to NOT be included in the stats. If you want to use that facility then I don’t think we can do what you want with the top posters list. If you are NOT going to use that option then we can.

YS Yellow Swordfish
Yellow Swordfish
Member

Right – this works as long as (see above) you are happy to sacrifice the ‘hide stats’ option for user groups. Below is the code you need to out into the user file to replace what we did before.

add_filter('sph_top_poster_stats_query', 'add_mods');
function add_mods($query) {
    $query->join = '';
    $query->left_join = array(
 SFMEMBERSHIPS.' ON '.SFMEMBERS.'.user_id = '.SFMEMBERSHIPS.'.user_id',
 SFUSERGROUPS.' ON '.SFMEMBERSHIPS.'.usergroup_id = '.SFUSERGROUPS.'.usergroup_id');
    $query->where = 'posts > -1';
    $query->orderby = 'posts DESC';
return $query;
}

Note – it is better copy from the ‘raw Code’ popup and then paste into the code text file. In particular note that this part – $query->join = ”;  – is not a double quote but two single quotes with no space.

YS Yellow Swordfish
Yellow Swordfish
Member

I can confirm that this code does work. In fact I still have it active on my development system here. So – did you check the error log as described earlier?