Description
This filter is executed when creating the address field (admin and front end). Use it to add support for a new address type.
Usage
The following would apply to all forms:
add_filter( 'gform_address_types', 'brazilian_address', 10, 2 );
To target a specific form, append the form id to the hook name. (format: gform_address_types_FORMID)
add_filter( 'gform_address_types_5', 'brazilian_address', 10, 2 );
Parameters
- $address_types array
A list of all configured address types to be filtered. Following is the default declaration of this array.
$addressTypes = array( 'international' => array( 'label' => 'International', 'zip_label' => 'Zip / Postal Code', 'state_label' => 'State/Province/Region' ), 'us' => array( 'label' => 'United States', 'zip_label' => 'Zip Code', 'state_label' => 'State', 'country' => 'United States', 'states' => GF_Fields::get( 'address' )->get_us_states(), ), 'canadian' => array( 'label' => 'Canadian', 'zip_label' => 'Postal Code', 'state_label' => 'Province', 'country' => 'Canada', 'states' => GF_Fields::get( 'address' )->get_canadian_provinces() ) );
-
$form_id integer
The current form ID.
Examples
1. Brasil
This example adds a Brazilian address type to the list.
add_filter( 'gform_address_types', 'brazilian_address', 10, 2 ); function brazilian_address( $address_types, $form_id ) { $address_types['brazil'] = array( 'label' => 'Brasil', 'country' => 'Brasil', 'zip_label' => 'CEP', 'state_label' => 'Estado', 'states' => array( '', 'Acre', 'Alagoas', 'Amapa', 'Amazonas', 'Bahia', 'Ceara', 'Distrito Federal', 'Espirito Santo', 'Goias', 'Maranhao', 'Mato Grosso', 'Mato Grosso do Sul', 'Minas Gerais', 'Para', 'Paraiba', 'Parana', 'Pernambuco', 'Piaui', 'Roraima', 'Rondonia', 'Rio de Janeiro', 'Rio Grande do Norte', 'Rio Grande do Sul', 'Santa Catarina', 'Sao Paulo', 'Sergipe', 'Tocantins' ) ); return $address_types; }
2. Australia
This example adds an Australian address type.
add_filter( 'gform_address_types', 'australian_address_type' ); function australian_address_type( $address_types ) { $address_types['australia'] = array( 'label' => 'Australian', 'country' => 'Australia', 'zip_label' => 'Postcode', 'state_label' => 'State', 'states' => array( 'ACT' => 'Australian Capital Territory', 'NT' => 'Northern Territory', 'NSW' => 'New South Wales', 'QLD' => 'Queensland', 'SA' => 'South Australia', 'TAS' => 'Tasmania', 'VIC' => 'Victoria', 'WA' => 'Western Australia', ) ); return $address_types; }
3. United Kingdom
This example uses optgroups for the counties, a feature added in Gravity Forms 2.0-beta-2.2.
add_filter( 'gform_address_types', 'uk_address', 10, 2 ); function uk_address( $address_types, $form_id ) { $address_types['uk'] = array( 'label' => 'UK', 'country' => 'United Kingdom', 'zip_label' => 'Postcode', 'state_label' => 'County', 'states' => array( '', 'England' => array( 'Avon', 'Bedfordshire', 'Berkshire', 'Buckinghamshire', 'Cambridgeshire', 'Cheshire', 'Cleveland', 'Cornwall', 'Cumbria', 'Derbyshire', 'Devon', 'Dorset', 'Durham', 'East Sussex', 'Essex', 'Gloucestershire', 'Hampshire', 'Herefordshire', 'Hertfordshire', 'Isle of Wight', 'Kent', 'Lancashire', 'Leicestershire', 'Lincolnshire', 'London', 'Merseyside', 'Middlesex', 'Norfolk', 'Northamptonshire', 'Northumberland', 'North Humberside', 'North Yorkshire', 'Nottinghamshire', 'Oxfordshire', 'Rutland', 'Shropshire', 'Somerset', 'South Humberside', 'South Yorkshire', 'Staffordshire', 'Suffolk', 'Surrey', 'Tyne and Wear', 'Warwickshire', 'West Midlands', 'West Sussex', 'West Yorkshire', 'Wiltshire', 'Worcestershire', ), 'Wales' => array( 'Clwyd', 'Dyfed', 'Gwent', 'Gwynedd', 'Mid Glamorgan', 'Powys', 'South Glamorgan', 'West Glamorgan', ), 'Scotland' => array( 'Aberdeenshire', 'Angus', 'Argyll', 'Ayrshire', 'Banffshire', 'Berwickshire', 'Bute', 'Caithness', 'Clackmannanshire', 'Dumfriesshire', 'Dunbartonshire', 'East Lothian', 'Fife', 'Inverness-shire', 'Kincardineshire', 'Kinross-shire', 'Kirkcudbrightshire', 'Lanarkshire', 'Midlothian', 'Moray', 'Nairnshire', 'Orkney', 'Peeblesshire', 'Perthshire', 'Renfrewshire', 'Ross-shire', 'Roxburghshire', 'Selkirkshire', 'Shetland', 'Stirlingshire', 'Sutherland', 'West Lothian', 'Wigtownshire', ), 'Northern Ireland' => array( 'Antrim', 'Armagh', 'Down', 'Fermanagh', 'Londonderry', 'Tyrone', ), ), ); return $address_types; }
Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms version 1.4.
Source Code
This action hook is located in GF_Field_Address::get_address_types() in includes/fields/class-gf-field-address.php.