• Resolved motivmedia

    (@motivmedia)


    With a custom plugin I occasionally roll out changes where I don’t want to go through our sites manually. There’s rarely issues with that approach and I’ve done this with WP Statistics settings before as well. However, one option I seemingly can’t change this way is “GeoIP Collection” and I wonder why:

    $wp_statistics = (array)get_option('wp_statistics');
    $wp_statistics['geoip'] = 'on';
    update_option('wp_statistics', $wp_statistics);

    “on” is the literal value the plugin itself sets if the checkbox is activated. The only other corresponding value, “GeoIP Database Update Source”, is on JSDeliver from the get-go by default. I could imagine that just by setting the value the database wouldn’t be initially downloaded; is that it? Is there a way to activate this programmatically to the same effect as if it were activated manually?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Amir

    (@amirfallah)

    Hi @motivmedia

    I tested the code you sent, and it works correctly, enabling and disabling the GeoIP Collection option without any issues. However, you can use the code below to download.

    \WP_STATISTICS\GeoIP::download('country', "update");

    Please let me know if you have any further questions or need assistance.
    Regards,

    Thread Starter motivmedia

    (@motivmedia)

    Hi @amirfallah

    thanks for the quick reply! I think I might have missed some critical info: My code does work if I put it in functions.php or anything I trigger by manually accessing it but this is run by wp-cron. And then it seemingly does nothing. Will try out the download code, though. Thank you!

    Amir

    (@amirfallah)

    We also tested the above code using Cron, and there were no issues. Please make sure there are no problems with your WP Cron in WordPress.

    Thread Starter motivmedia

    (@motivmedia)

    Well, it performs all the other actions in there. WP Cron does work. I suspect that I need to load something as it seems to make a difference if it runs when I’m logged in vs. when I’m not.

    Amir

    (@amirfallah)

    Cron Jobs in WordPress are request-based. This means that whenever a user accesses the website, WordPress checks if it’s time to run any cron jobs. If the time has come, the respective task or operation is executed.

    However, if your website has low traffic, Cron Jobs may be executed with significant delays. In this case, you can use Cron Job management plugins like WP Cron Control or implement Cron traditionally through the server’s command line.

    For further information, you can refer to these link:
    https://easyengine.io/tutorials/wordpress/wp-cron-crontab/

    Please let me know if you have any further questions or need assistance.
    Regards,

    Thread Starter motivmedia

    (@motivmedia)

    Thank you. I do know how cron jobs in WordPress work, though. This is within a custom plugin with its own scheduled task which, for testing, I increased the frequency of and trigger by calling wp-cron.php?doing_wp_cron while not logged in. As mentioned, other changes in there get performed, even other options for WP Statistics. It is just the geoip option that doesn’t get changed – for whatever reason.

    Edit: Hold that, it just did work. Still is the case that geoip out of several other options was the only one that didn’t change before. Now it did and I’ll have to figure out how I managed to mess that up before. Thanks for your patience, much apreciated!

    • This reply was modified 2 years ago by motivmedia.
Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Activating GeoIP collection programmatically’ is closed to new replies.