Title: Activating GeoIP collection programmatically
Last modified: May 13, 2024

---

# Activating GeoIP collection programmatically

 *  Resolved [motivmedia](https://wordpress.org/support/users/motivmedia/)
 * (@motivmedia)
 * [2 years ago](https://wordpress.org/support/topic/activating-geoip-collection-programmatically/)
 * 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-block-code
       $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](https://wordpress.org/support/users/amirfallah/)
 * (@amirfallah)
 * [2 years ago](https://wordpress.org/support/topic/activating-geoip-collection-programmatically/#post-17752632)
 * Hi [@motivmedia](https://wordpress.org/support/users/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-block-code
       \WP_STATISTICS\GeoIP::download('country', "update");
       ```
   
 * Please let me know if you have any further questions or need assistance.
   Regards,
 *  Thread Starter [motivmedia](https://wordpress.org/support/users/motivmedia/)
 * (@motivmedia)
 * [2 years ago](https://wordpress.org/support/topic/activating-geoip-collection-programmatically/#post-17752677)
 * Hi [@amirfallah](https://wordpress.org/support/users/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](https://wordpress.org/support/users/amirfallah/)
 * (@amirfallah)
 * [2 years ago](https://wordpress.org/support/topic/activating-geoip-collection-programmatically/#post-17754031)
 * 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](https://wordpress.org/support/users/motivmedia/)
 * (@motivmedia)
 * [2 years ago](https://wordpress.org/support/topic/activating-geoip-collection-programmatically/#post-17754153)
 * 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](https://wordpress.org/support/users/amirfallah/)
 * (@amirfallah)
 * [2 years ago](https://wordpress.org/support/topic/activating-geoip-collection-programmatically/#post-17754315)
 * 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/](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](https://wordpress.org/support/users/motivmedia/)
 * (@motivmedia)
 * [2 years ago](https://wordpress.org/support/topic/activating-geoip-collection-programmatically/#post-17755879)
 * 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](https://wordpress.org/support/users/motivmedia/).

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

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

 * ![](https://ps.w.org/wp-statistics/assets/icon.svg?rev=3081064)
 * [WP Statistics – Simple, privacy-friendly Google Analytics alternative](https://wordpress.org/plugins/wp-statistics/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-statistics/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-statistics/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-statistics/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-statistics/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-statistics/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [motivmedia](https://wordpress.org/support/users/motivmedia/)
 * Last activity: [2 years ago](https://wordpress.org/support/topic/activating-geoip-collection-programmatically/#post-17755879)
 * Status: resolved