Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Contributor dudo

    (@dudo)

    Hi Cassie, thank you for using yasr!

    At the moment it’s no possible anonimyze the IP-addresses, but if you’re able I can suggest some edit in the code.

    Please note that only admin can see that log widget in the dashboard.

    Best,
    dario

    Thread Starter Jasper Steuerberater

    (@jasper-steuerberater)

    Hi Dudo,

    thanks for the quick reply.

    I would be able to edit the code, if you could make some suggestions? That would be awesome!

    Just so I know: Would I have to edit the code every time there is a update? That wouldn’t be a problem.

    Thanks again.
    Cassie

    Plugin Contributor dudo

    (@dudo)

    In the plugin dir, open file /lib/yasr-db-functions and on line 359 change this

    <span id=\"yasr-log-ip\">" . __("Ip address" , "yasr") . ": <span style=\"color:blue\">$column->ip</span></span>

    with this

    <span id=\"yasr-log-ip\">" . __("Ip address" , "yasr") . ": <span style=\"color:blue\">XXX</span></span>

    Yes, you should do this after every update.

    Best,
    Dario

    Thread Starter Jasper Steuerberater

    (@jasper-steuerberater)

    Hey Dario,

    that was easy enough.
    Thank you very much for your help. Gave you a 5 star-rating!

    Best, Cassie

    Plugin Contributor dudo

    (@dudo)

    Thank you for your rating, it’s a big help for me!

    Best,
    Dario

    @JasperSteuerberater

    Instead of editing the plugin after each update, you could simply remove the dashboard widget with:

    /**
     * Remove the YASR dashboard widget log
     */
    add_action( 'plugins_loaded', function()
    {
        remove_action (
             'wp_dashboard_setup',
            'yasr_add_dashboard_widget_log'
        );
    }, 11 );

    and then just add your own modified dashboard widget, without the IP numbers.

    You could also take the lazy road with:

    /**
     * Replace IPs with xxx in the YASR dashboard widget log
     */
    add_action( 'plugins_loaded', function()
    {
        // Remove the current YASR widget log:
        remove_action (
             'wp_dashboard_setup',
            'yasr_add_dashboard_widget_log'
        );
    
        // Add our modified YASR widget log:
        add_action(	'wp_dashboard_setup', function()
        {
             wp_add_dashboard_widget (
                 'yasr_widget_log_dashboard',
                 'Recent Ratings',
                 'jasper_remove_ips'
             );
        } );
    }, 11 );
    
    function jasper_remove_ips()
    {
        if( function_exists( 'yasr_display_dashboard_log_wiget' ) )
        {
            ob_start();
     	yasr_display_dashboard_log_wiget();
            echo preg_replace(
                 '#(<span style="color:blue">)([^<]*)(</span>)#',
                '\1xxx\3',
                ob_get_clean()
            );
        }
    }

    You could then try to modify the above regex in a more general way, to keep it more future proof.

    Well this would be easier if there would be a filter to handle this ??

    Thread Starter Jasper Steuerberater

    (@jasper-steuerberater)

    Hi Birgir Erlendsson,

    sorry I didn’t reply earlier – I just saw your message.

    Thank you for your suggestion and your effort!

    I added your first code in the /lib/yasr-db-functions. It worked, the widget was gone. Since I don’t know how to add a modified widget in the Dashboard, I really would like to try out your second option.

    Can you tell me please,where to add it to? I added it in the /lib/yasr-db-functions as well, but my website was gone, saying “internal error”, so I removed the code again. Maybe I did something wrong and I have to add it somewhere else?

    I am a beginner in php, but able to modify smaller parts.

    Greetings to Iceland ??

    Ulrich

    (@grapplerulrich)

    @jasper-steuerberater I came across this as I was searching for something similar. The code examples that you got only hide the IP addresses being displayed to you. From the looks of the code I would say the ip addresses are still in your database.

    Plugin Contributor dudo

    (@dudo)

    Yes, data is still on _yasr_log table.

    @jasper-steuerberater

    Thanks and greetings to K?ln ??

    But you shouldn’t edit the plugin code directly and try this as a separate plugin instead. The Codex has some good examples on how to do that.

    @ulrich To avoid registering actual IPs, maybe it would be beneficial to some users if there was a filter inside the yasr_get_ip() function?

    Example:

    $REMOTE_ADDR = apply_filters( 'yasr_ip', $REMOTE_ADDR );

    Then users could adjust that to their needs,

    Example:

    add_filter( 'yasr_ip', function( $ip )
    {
        return '127.0.0.1';
    } );

    But we can’t have it empty because of how the field is defined:

    ip varchar(45) COLLATE utf8_unicode_ci NOT NULL,

    otherwise we could simply use:

    add_filter( 'yasr_ip', '__return_null' );

    ps: I see you use

    CREATE TABLE IF NOT EXISTS

    but then you’re not using the powers of dbDelta() if you later want to modify your db schema

    I did recently some unrelated dbDelta testing here:

    https://wordpress.stackexchange.com/a/213373/26350

    Plugin Contributor dudo

    (@dudo)

    Hi Birgir, I’m the plugin author and not Ulrich ??

    Yes, I’ve just added a filter on yasr_get_ip (will be avaible on next version)

    $ip = NULL;
    
        $ip = apply_filters ('yasr_filter_ip');
    
        if (isset($ip)) {
    
            return $ip;
    
        }

    you can hook on yasr_filter_ip, and on the callback function you can return an empty string or even false

    I will take a look at that link, thank you!

    sorry @dudo for that typo, these suggestions were of course for you ??

    That’s great and hopefully it will help others that have problems with storing real IP addresses.

    Have a nice weekend.

    ps: we must have the second input argument for apply_filters() to avoid warnings.

    Plugin Contributor dudo

    (@dudo)

    Yeah I’ll fix it ??

    … and just one thing more to watch out for ??

    Maybe add a check to avoid the case of trying to store empty/null IPs, since that might give db error.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Anonymize IP-Addresses?’ is closed to new replies.