Skip to:
Content
Pages
Categories
Search
Top
Bottom

User Statistics

  • @ajtruckle

    Participant

    I know I asked about this before and the decision was to pull the plugin off line. But this is not a solution for me.

    The drawback with the user statistics plugin is that if a user is not logged in they can see the usernames of all logged in people for last 24 hours. The can’t view their profiles though. None-the-less, a non logged in user should not see the user statistics.

    I don’t know how to fix this plugin to rectify that. I need a resolution or an alternative plugin that works and is not commercial.

    Thanks.

Viewing 25 replies - 26 through 50 (of 52 total)
  • @ajtruckle

    Participant

    Yes, I have the code. And originally it was available and after I made my first concern about it exposing usernames when it shouldn’t somebody decided (somehow) to lock it online in the plugin repository.

    This is my current plugin (with my corrected code discussed above):

    https://www.dropbox.com/s/vjovpjnk22gxcct/bbpress-improved-statistics-users-online.zip?dl=0

    @robin-w

    Moderator

    great – thanks for posting that – I’ll add it to my site as well as make available as a download

    @robin-w

    Moderator

    no idea what guidelines it breaks to have been removed, I’ll take a quick look

    @ajtruckle

    Participant

    I think this was why:

    https://wordpress.org/support/topic/bbpress-advanced-statistics-logged-out/

    I have only just noticed this. I use the “bbPress Advanced Statistics” plugin as I like the way it presents the data at the bottom on the forum page.

    However, if I “log out”, it still lists all the names of the users from the last 24 hours. That is not right. It should only list last 24 forum activity if a user is logged in. Technically it is exposing users names for a non logged in user when I don’t want it to.

    @robin-w

    Moderator

    ah, thanks for that !!

    @ajtruckle

    Participant

    You’re welcome. I dunno, maybe you can shoehorn it into bsp as a feature. Thanks for putting it on your site though.

    @ajtruckle

    Participant

    That plugin also has another problem.

    I have a User Approve plugin.

    Even new users who I have not yet approved show at the bottom as new users. They shouldn’t,t be listed.

    @ajtruckle

    Participant

    Further to last message, I don’t know if the code I showed you can be improved?

    As mentioned, I have “WP Approve User” installed. I have checked the meta data for a given user in the database and if “wp-approve-user” is not set to “1” then they should not be listed in the “newest users” bit of the statistics.

    That “build_html” code needs to be modified somehow.

    @robin-w

    Moderator

    you will need to work out what the difference between an approved one and an unapproved on is – start with dashboard>users and see what you can find.

    @ajtruckle

    Participant

    Not sure what you mean. When the user signs up I am sent an email. The meta data for wp-approve-user-email-sent is set to true (1). And wp-approve-user is set to false (0).

    Once I approve them the meta data changes for wp-approve-user to true. I simply need the system to to user get_user_meta with user id and “wp-approve-user” (if the var exists). And if it exists, don’t show the user if the value is false.

    Make sense?

    @ajtruckle

    Participant

    So it calls:

            private function section_latestuser() {
                
                // Grab the latest registered user on the site
                return $this->tag_replace( $this->parent->option["title_text_latestuser"] );
            }
    

    Which in turn calls:

    
            function get_latestuser( $html ) {
                $latest_user = get_users(
                    array(
                        'number' => 1,
                        'fields' => array("user_login", "ID", "display_name"),
                        'orderby' => "registered",
                        'order' => "DESC"
                    )
                );
                
                $latest_user = reset( $latest_user );
                
                // Default display is the full name
                $name = $latest_user->display_name;
                
                if( $this->parent->option['user_display_format'] == "display_as_username" ) {
                    $name = $latest_user->user_login;
                }
                
                if( $html == true ) {
                    return "<a href=\"" . bbp_get_user_profile_url( $latest_user->ID ) . "\">" . $name . "</a>";
                } else {
                    return $name;
                }
            }
    

    I think, if “WP Approve User” is installed then we need to somehow modify the array returned to only include those where the are approved (as per my previous email).

    @robin-w

    Moderator

    that was exactly what I meant – now we know what changes, so to code we need to find out which user is being displayed and get that data.

    so as you say it will be something like

    $approve = get_meta_data ($user_id, 'wp-approve-user', true) ;

    presume you mean ‘latest user’ – not keen to load the plugin to my test site as I’m mid something else – so we just need the latest user who has been approved, or do you mean something else?

    @robin-w

    Moderator

    ok, so does latest user only ever show 1?
    looks like it – come back and I’ll help you with the next step

    @ajtruckle

    Participant

    I have just checked the database and wp-approve-user is always 1 with the exception of one record where it is empty. I assume this is the person that registered on my site this morning whom I have not approved.

    so we just need the latest user who has been approved

    Correct, but, if this will be part of the plugin you sponsor on your site it will need to factor if for the old way I guess too. Unless this becomes a custom code change just for me.

    @robin-w

    Moderator

    ok, so the function within that code that gets the latest user is this

     $latest_user = get_users(
                    array(
                        'number' => 1,
                        'fields' => array("user_login", "ID", "display_name"),
                        'orderby' => "registered",
                        'order' => "DESC"
                    )
                );

    so this function brings users ordered by registered – DESC means latest is listed first, and number=>1 means just retrieve one, so this gets the latest.

    so we just need to add a lookup to say that this must also have meta ‘wp-approve-user’ set to 1 so we amend the function to

     $latest_user = get_users(
                    array(
                        'number' => 1,
                        'fields' => array("user_login", "ID", "display_name"),
                        'orderby' => "registered",
                        'order' => "DESC",
    		'meta_key' => 'wp-approve-user',
    		'meta_value' => '1'
                    )
                );

    This (untested) should work for your site.

    I don’t plan to support this plugin, but am happy to have it on my site to allow others to use it.

    Given that many many other plugins might set meta data it is not possible to cater for all, so I’ll just host the previous version. Anyone downloading will be via this thread so they can see how to update it to cater for the approve plugin.

    @ajtruckle

    Participant

    Thanks. I will try it. Do you think I could try that as is on my staging site?

    @robin-w

    Moderator

    yes that should work.

    If/when it does we’ll do a final amendment to make sure it still works should you deactivate the approve plugin

    @ajtruckle

    Participant

    It works – on both staging and live. 🙂 Now it shows the correct last approved user. Thanks!

    @robin-w

    Moderator

    ok, so final amendment needed, as if you deactivate wp-approve-user then the latest user will be forevermore the last one you approved before decativating the plugin.

    If you open the wp-approve-plugin you’ll see the core file wp-appprove-user.php

    open this and you’ll see a line 29 which says

    class Obenland_Wp_Approve_User extends Obenland_Wp_Plugins_V4 {

    so we know that the wp-approve-plugin sets up a class called ‘Obenland_Wp_Approve_User’, so we can use the existence of this class to know if wp-approve-use is active or not.

    This is common to many plugins and a good way to ensure parts of code that use another plugin only fire if that plugin is active.

    so now we can change the ‘get_uses’ to only add the meta_data is the class exists

    //set up $args with core arguments needed
    $args =  array(
                        'number' => 1,
                        'fields' => array("user_login", "ID", "display_name"),
                        'orderby' => "registered",
                        'order' => "DESC",
    		) ;
    		
    //add additional meta data to $args if wp-approve-user is active
    if (class_exists ('Obenland_Wp_Approve_User')) {
    	$args ['meta_key'] = 'wp-approve-user' ;
    	$args ['meta_value'] = '1' ;
    }	
    
    //then do the lookup
    $latest_user = get_users($args) ;

    @ajtruckle

    Participant

    Sorry, but I can’t see this file in the ZIP I sent you.

    @ajtruckle

    Participant

    Sorry, I was looking in the wrong place! One sec …

    @robin-w

    Moderator

    so in the statsistics plugin you are changing

    $latest_user = get_users(
                    array(
                        'number' => 1,
                        'fields' => array("user_login", "ID", "display_name"),
                        'orderby' => "registered",
                        'order' => "DESC",
    		'meta_key' => 'wp-approve-user',
    		'meta_value' => '1'
                    )
                );

    to

    //set up $args with core arguments needed
    $args =  array(
                        'number' => 1,
                        'fields' => array("user_login", "ID", "display_name"),
                        'orderby' => "registered",
                        'order' => "DESC",
    		) ;
    		
    //add additional meta data to $args if wp-approve-user is active
    if (class_exists ('Obenland_Wp_Approve_User')) {
    	$args ['meta_key'] = 'wp-approve-user' ;
    	$args ['meta_value'] = '1' ;
    }	
    
    //then do the lookup
    $latest_user = get_users($args) ;
    

    @ajtruckle

    Participant

    Understood. Works well. I removed the trailing comma after “DESC”.

    Thanks for your help!

    @robin-w

    Moderator

    I removed the trailing comma after “DESC”.

    good spot !

    great – that should now be fine.

    Since we have now added the ‘wp-approve…’ as a dependency, I’ll amend the version that I put on my site which will then match yours and then add this below.

    @ajtruckle

    Participant

    Great!

Viewing 25 replies - 26 through 50 (of 52 total)
  • You must be logged in to reply to this topic.
Skip to toolbar