allanext
Forum Replies Created
-
It would be good if the geo-localization would follow WordPress guidelines (as there’s no need for multiple geo-ip requests to external services when it was already done by the core or other modules.
Being able to read the GEO headers from a CDN response would be ideal (thinking of AWS cloudfront or Cloudflare)
For now i’ve just change the following function
get_geoip_data()in the filepublic/class-warehouse-popups-woocommerce-public.php:private function get_geoip_data() { if(is_admin()) { return false; } $geoInfo = geoip_detect2_get_info_from_current_ip(); $geo_country_code=($geoInfo->country->isoCode); $geo_postal_code=($geoInfo->postal->code); $return_arr = array( 'name' => $geoInfo->country->name, 'country_code1' => $geo_country_code, 'country_code2' => $geo_country_code ); return $return_arr; }with a call to the “Geo ip detection” plugin:
private function get_geoip_data() { if(is_admin()) { return false; } $geoInfo = geoip_detect2_get_info_from_current_ip(); $geo_country_code=($geoInfo->country->isoCode); $geo_postal_code=($geoInfo->postal->code); $return_arr = array( 'name' => $geoInfo->country->name, 'country_code1' => $geo_country_code, 'country_code2' => $geo_country_code ); return $return_arr; }“Geo ip detection” plugin enables you to choose IP geo detection from:
- Manual download & update of a Maxmind City or Country database
- Automatic download & update of Maxmind GeoIP Lite City
- Maxmind Precision Web-API
- Special Hosting Providers (Cloudflare, Amazon AWS CloudFront)
- Ipstack Web-API
The module offers also various useful settings, caching options and it rates 5 stars, with 45 reviews, used by more than 20K sites and it’s free.
The page loading is twice as fast!
Why not use something like this?
Thank you !- This reply was modified 5 years, 6 months ago by allanext.
Can you post the error for reference?
Hi @joeleem0n ,
ok, i see that you are trying to read the local ip database from geoip2; not sure why it gives the PHP fatal error:
[Tue Apr 21 15:26:17.743069 2020] [:error] [pid 30871] [client 68.192.44.174:53780] PHP Fatal error: Uncaught Error: Call to undefined method MaxMind\\Db\\Reader::getWithPrefixLen() in /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/vendor/geoip2/geoip2/src/Database/Reader.php:246\nStack trace:\n#0 /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/vendor/geoip2/geoip2/src/Database/Reader.php(217): GeoIp2\\Database\\Reader->getRecord(‘City’, ‘City’, ‘68.192.44.174’)\n#1 /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/vendor/geoip2/geoip2/src/Database/Reader.php(73): GeoIp2\\Database\\Reader->modelFor(‘City’, ‘City’, ‘68.192.44.174’)\n#2 /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/class-warehouse-popups-woocommerce-public.php(368): GeoIp2\\Database\\Reader->city(‘68.192.44.174’)\n#3 /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/class-warehouse-popups-woocommerce-public.php(430): Warehouse_Popups_Woocommerce_Public::auto_warehou in /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/vendor/geoip2/geoip2/src/Database/Reader.php on line 246
I’ve done the following changes to the file “class-warehouse-popups-woocommerce-public.php” to make it work with the “Geo ip detection” plugin (personally i think it’s better than maintain the external library in your plugin):
Beginning of file:
<?php if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } //require 'vendor/autoload.php'; use GeoIp2\Database\Reader;Commented reading the geolite from the local file (that gives the error above) with:
// automatically detect location and switch warehouse private static function auto_warehouse_switch() { global $SHIPPING_ZONES_ENABLED; $found_warehouse = false; //$reader = new Reader(plugin_dir_path( __FILE__ ) . 'GeoLite2-City.mmdb'); if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip_address = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip_address = $_SERVER['REMOTE_ADDR']; } if($ip_address == '127.0.0.1') { self::set_warehouse_cookie($_REQUEST['wh_popups_change_wh_to']); return; } // $record = $reader->city($ip_address); // $geo_country_code = trim(strtoupper($record->country->isoCode)); // $geo_postal_code = trim($record->postal->code); $geoInfo = geoip_detect2_get_info_from_current_ip(); $geo_country_code=($geoInfo->country->isoCode); $geo_postal_code=($geoInfo->postal->code); $alt_warehouses_list = self::get_alt_warehouses_list();what do you think about calling the geoip_detect2_get_info_from_current_ip() instead of opening the ip database file?
Thank you
Hi @joeleem0n,
I’ve updated to 1.3.3:
1 – I can’t see the sentence that states that WP Engine is required to run the geolocation (no bid deal)
2 – First thing that i’ve notice is this PHP fatal error that crashes the site
[Tue Apr 21 15:26:17.743069 2020] [:error] [pid 30871] [client 68.192.44.174:53780] PHP Fatal error: Uncaught Error: Call to undefined method MaxMind\\Db\\Reader::getWithPrefixLen() in /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/vendor/geoip2/geoip2/src/Database/Reader.php:246\nStack trace:\n#0 /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/vendor/geoip2/geoip2/src/Database/Reader.php(217): GeoIp2\\Database\\Reader->getRecord(‘City’, ‘City’, ‘68.192.44.174’)\n#1 /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/vendor/geoip2/geoip2/src/Database/Reader.php(73): GeoIp2\\Database\\Reader->modelFor(‘City’, ‘City’, ‘68.192.44.174’)\n#2 /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/class-warehouse-popups-woocommerce-public.php(368): GeoIp2\\Database\\Reader->city(‘68.192.44.174’)\n#3 /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/class-warehouse-popups-woocommerce-public.php(430): Warehouse_Popups_Woocommerce_Public::auto_warehou in /var/www/html/my_site/wp-content/plugins/warehouse-popups-woocommerce/public/vendor/geoip2/geoip2/src/Database/Reader.php on line 246
3 – I’ve tried wpengine-geoip but the plugin will not work without a subscription:
WP Engine GeoTarget requires a WP Engine account with GeoTarget enabled for full functionality. Only testing queries will work on this site.
4 – Why not use “Geolocation IP Detection” that rates 5 stars, with 44 reviews, used by more than 20K sites and that is free? you would call instead:
geoip_detect2_get_info_from_ip($ip, $locales = array(‘en’), $options = array())
The plugin also updates the ip databases automatically from MaxMind and others.
5 – Oh, i’ve noticed that you are using a database of IP directly in the plugin but i still get the error on point 2
Thank you! I’ve just made the plugin update and verified that the issue is fixed
Forum: Plugins
In reply to: [WP Super Cache] Not caching / 0 cached pages / directory missing?RESOLVED:
check which plugin is setting the variable DONOTCACHEPAGE:
fgrep -R DONOTCACHEPAGE ./wp-content/*
For me it was an option of geo ip plugin:
Disable caching a page that contains a shortcode or API call to geo-dependent functions.
At least WP SuperCache, W3TotalCache and ZenCache are supported.I’ve also added the plugin WPSC Country Caching
Good luck!
- This reply was modified 6 years, 3 months ago by allanext.
Forum: Plugins
In reply to: [WP Super Cache] Not caching / 0 cached pages / directory missing?Some files are created in the directory /var/www/html/site.org/wordpress/wp-content/cache
# ls -la total 1112 drwxr-xr-x 5 apache apache 4096 Apr 15 22:09 . drwxrwxr-x 14 apache centos 4096 Apr 15 22:09 .. -rw-r--r-- 1 apache apache 148363 Apr 15 21:40 0.html -rw-r--r-- 1 apache apache 148341 Apr 15 21:21 1-09a2a06e54a39baec65ea69c3d5a4b5e.txt -rw-r--r-- 1 apache apache 148341 Apr 15 21:20 1-ee89b15df2be0cc0f1782e4e9f79c32e.txt -rw-r--r-- 1 apache apache 148363 Apr 15 21:40 1.html -rw-r--r-- 1 apache apache 148341 Apr 15 21:21 2-1273f1995ed64b17ba4684d543059e63.txt -rw-r--r-- 1 apache apache 148341 Apr 15 21:20 2-95d8821a11d36234120ed073bbfbc203.txt -rw-r--r-- 1 apache apache 148363 Apr 15 21:40 2.html -rw-r--r-- 1 apache apache 61287 Apr 15 22:09 429872dad8d3dfa3c0e538717ee3f9e4.php drwxr-xr-x 2 apache apache 23 Apr 15 21:19 blogs -rw-r--r-- 1 apache apache 523 Apr 15 21:27 .htaccess -rw-r--r-- 1 apache apache 0 Apr 15 18:04 index.html drwxr-xr-x 2 apache apache 23 Apr 15 18:04 meta drwxr-xr-x 2 apache apache 23 Apr 15 21:37 supercache -rw-r--r-- 1 apache apache 2506 Apr 15 21:42 view_429872dad8d3dfa3c0e538717ee3f9e4.php- This reply was modified 6 years, 3 months ago by allanext.
Hi @joeleem0n,
in version 1.2.6 i still have the geo-location issue, what are the requirements to have these two environment variables set?
HTTP_GEOIP_COUNTRY_CODE
HTTP_GEOIP_POSTAL_CODEas did above i’ve added the following lines in the file calss-warehouse-woocommerce-public.php:
// automatically detect location and switch warehouse private static function auto_warehouse_switch() { global $SHIPPING_ZONES_ENABLED; $found_warehouse = false; $geo_country_code = trim(strtoupper(getenv( 'HTTP_GEOIP_COUNTRY_CODE' ))); $geo_postal_code = trim(strtoupper(getenv( 'HTTP_GEOIP_POSTAL_CODE' ))); $geoInfo = geoip_detect2_get_info_from_current_ip(); $geo_country_code=($geoInfo->country->isoCode);Thank you @joeleem0n
- This reply was modified 6 years, 6 months ago by allanext.
ok @joeleem0n, i’m really not sure what is happening but closing and opening those php delimiters tags ( ?> <?php ) is part of the issue, i’ve changed:
?><h2><?php _e( 'Edit Warehouse Details', 'warehouse-popups-woocommerce' );?></h2><?phpto
echo('<h2>Edit Warehouse Details</h2>');as the _e function is only for translation of stringsand the other issue is the opening of the <?php in the abbreviated form, changed:
$current_tab = ( $_GET['tab'] == 'warehouses' ) ? 'nav-tab-active' : ''; ?> <a href="admin.php?page=wc-settings&tab=warehouses" class="nav-tab <?php echo $current_tab?>"><?php echo __( "Warehouses", "warehouse-popups-woocommerce" )?></a> <?to:
$current_tab = ( $_GET['tab'] == 'warehouses' ) ? 'nav-tab-active' : ''; ?> <a href="admin.php?page=wc-settings&tab=warehouses" class="nav-tab <?php echo $current_tab?>"><?php echo __( "Warehouses", "warehouse-popups-woocommerce" )?></a> <?phpmy php version:
PHP 7.0.33 (cli) (built: Jan 9 2019 22:04:26) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies- This reply was modified 6 years, 6 months ago by allanext.
This issue just reappeared in version 1.2.6, do I need to update PHP or add some libraries?
Did the same fix as above but now showing warehouses on all the woocommerce settings tabs
- This reply was modified 6 years, 6 months ago by allanext.
Forum: Plugins
In reply to: [Pods - Custom Content Types and Fields] pods + search&filter plugin@keraweb Thank you for pointing out in the right direction, very appreciated !
Forum: Plugins
In reply to: [Pods - Custom Content Types and Fields] pods + search&filter pluginI haven’t found a great example to bootstrap, there’s some documentation and examples, like:
https://pods.io/tutorials/using-pods-pages-advanced-content-types/
https://pods.io/forums/topic/simple-search-box/
http://webdesignforidiots.net/2013/04/pods-pages-and-templates-and-more-pages-oh-my/For now i’ve roughly created a Pod Page with a form that displays the results on the same page. It looks like it should be better integrated with Pod Templates as it’s giving the following notice:
PHP Notice: Pod Page PHP code has been deprecated, please use WP Page Templates or hook into the pods_content filter instead of embedding PHP. has been deprecated since Pods version 2.1 with no alternative available. in
If somebody could create a proper example it would be great !
Anyways this might give you an idea:
<?php /* Template Name: Pod Page Template */ get_header(); ?> <div id="primary" class="content-area"> <div id="content" class="site-content" role="main"> <header class="banner"> <div class="shadow-wrapper"> <h1 class="banner-title">Byara</h1> </div> </header><!-- .banner --> <div class="block entry-block"> <div class="entry cf px-5"> <h2>Search the collection</h2> </div> <form id="searchform" method="get" action="/new-byara"> <input type="text" class="search-field" name="author" placeholder="Author" value=""> <input type="text" class="search-field" name="title " placeholder="Title" value=""> <input type="text" class="search-field" name="year" placeholder="Year" value=""> <input type="text" class="search-field" name="abstract" placeholder="Abstract" value=""> <input type="text" class="search-field" name="keywords" placeholder="Keywords" value=""> <input type="submit" value="Search"> </form> <div class="entry-content"> <?php $author = $_GET["author"]; $title = $_GET['title']; $year = $_GET['year']; $abstract = $_GET['abstract']; $keywords = $_GET['keywords']; //if(isset($_GET["author"])) echo "\nauthor is set\n"; //print_r($_GET); ?> </div> <?php //this is normally where the WP Loop would be. Instead we add a loop to get pods stuff $mypod = pods('journal'); // Here's how to use find() $params = array( 'limit' => 20, 'page' => 1, // Be sure to sanitize ANY strings going here //'where' =>"author_analytic = '.$author.'" ); $mypod->find($params); ?> <table> <thead> <tr> <th>Author</th> <th>Title</th> <th>Link</th> </tr> </thead> <tbody> <?php // Loop through items found while ( $mypod->fetch() ) { $journal_title= $mypod->field('title_analytic'); $permalink= $mypod->field('permalink'); echo "<tr>"; echo "<td>".$mypod->display( 'author_analytic' )."</td>"; echo "<td>".$mypod->display( 'title_analytic' ) ."</td>"; echo "<td>".$permalink.'</td>'; echo "</tr>"; }?> </tbody> </table> <?php echo $mypod->pagination();?> </div> </div> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>- This reply was modified 6 years, 8 months ago by allanext.
Forum: Plugins
In reply to: [Pods - Custom Content Types and Fields] pods + search&filter pluginHi Jim,
thanks for your response, I think I’ll need to code my search functionality; would you advise doing this with a “Pods Page”?
I’m getting confused.. I’ve looked a bit around but didn’t found a great example.
Thank you
Forum: Plugins
In reply to: [Pods - Custom Content Types and Fields] pods + search&filter pluginWould the general idea be to create a “Pods Template” to display a single Journal2 Custom Post Type?
and then use a “Pods Page” to code a searching form ?
I’ve looked around the tutorials and documentation but it’s a bit confusing as they are covering topics with a random order; might need to spend more time on it !
- This reply was modified 6 years, 8 months ago by allanext.
Forum: Plugins
In reply to: [Pods - Custom Content Types and Fields] pods + search&filter pluginwould you actually recommend to do a post page (Pods Admin->Components->Pages) and use the function find?
as shown in the documentation: https://pods.io/docs/code/pods/find/