A real ACF phone number field powered by libphonenumber and intl-tel-input
Install via Composer:
$ composer require log1x/acf-phone-number
Download the release .zip
and install into wp-content/plugins
.
If you provision your server using Trellis, it does not come with php-intl
installed out of the box.
To add support for your Trellis projects, simply add the following lines to group_vars/all/main.yml
and reprovision your environment(s).
php_extensions_custom:
php7.4-intl: '{{ apt_package_state }}'
Pretty straight forward usage. You can optionally set a default country.
Calling the field will return an arrayable object containing everything you need about your number:
{
+"number": "+1 405-867-5309"
+"country": "us"
+"uri": "tel:+14058675309"
+"e164": "+14058675309"
+"rfc3966": "tel:+1-405-867-5309"
+"national": "(405) 867-5309"
+"international": "+1 405-867-5309"
+"carrier": ""
+"location": "Oklahoma"
+"timezone": array:1 [▼
0 => "America/Chicago"
]
}
If you are on Sage 10 and using my ACF Composer package:
$field
->addField('my_number_field', 'phone_number')
->setConfig('default_country' => 'us');
If you discover a bug in ACF Phone Number, please open an issue.
Contributing whether it be through PRs, reporting an issue, or suggesting an idea is encouraged and appreciated.
ACF Phone Number is provided under the MIT License.