Last active
September 30, 2023 02:38
-
-
Save webaware/edba921af11f06bdfd5147bab806f591 to your computer and use it in GitHub Desktop.
change United States to USA in Gravity Forms addresses, with support for Gravity Forms Address Enhanced
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: GF Country USA | |
Plugin URI: https://gist.github.com/webaware/edba921af11f06bdfd5147bab806f591 | |
Description: change United States to USA in Gravity Forms addresses | |
Version: 2 | |
Author: WebAware | |
Author URI: https://shop.webaware.com.au/ | |
*/ | |
/* | |
copyright (c) 2020-2022 WebAware Pty Ltd (email : support@webaware.com.au) | |
This program is free software; you can redistribute it and/or | |
modify it under the terms of the GNU General Public License | |
as published by the Free Software Foundation; either version 2 | |
of the License, or (at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
*/ | |
if (!defined('ABSPATH')) { | |
exit; | |
} | |
/** | |
* change United States to show as USA | |
* @param array $countries | |
* @return array | |
*/ | |
add_filter('gform_countries', function($countries) { | |
$key = array_search('United States', $countries); | |
$countries[$key] = 'USA'; | |
sort($countries); | |
return $countries; | |
}); | |
/** | |
* change GF Address Enhanced's map of country names to country codes | |
* @param array $countries | |
* @return array | |
*/ | |
add_filter('gf_address_enhanced_countries', function($countries) { | |
unset($countries[translate('United States', 'gravityforms')]); | |
$countries['USA'] = 'US'; | |
return $countries; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment