diff --git a/plugin.php b/plugin.php index d398962..0995070 100644 --- a/plugin.php +++ b/plugin.php @@ -4,7 +4,7 @@ * Plugin Name: Advanced Custom Fields: Phone Number * Plugin URI: https://github.com/log1x/acf-phone-number * Description: A real ACF phone number field. - * Version: 1.2.6 + * Version: 1.3.0 * Author: Brandon Nifong * Author URI: https://github.com/log1x */ @@ -36,10 +36,6 @@ public function __invoke() } $this->register(); - - if (defined('ACP_FILE')) { - $this->hookAdminColumns(); - } } /** @@ -60,24 +56,4 @@ protected function register() return (new PhoneNumber($value))->toArray(); }, 10, 4); } - - /** - * Hook the Admin Columns Pro plugin to provide basic field support - * if detected on the current WordPress installation. - * - * @return void - */ - protected function hookAdminColumns() - { - add_filter('ac/column/value', function ($value, $id, $column) { - if ( - ! is_a($column, '\ACA\ACF\Column') || - $column->get_acf_field_option('type') !== 'phone_number' - ) { - return $value; - } - - return get_field($column->get_meta_key())->national ?? $value; - }, 10, 3); - } }); diff --git a/src/PhoneNumberField.php b/src/PhoneNumberField.php index 294515f..252fdf5 100644 --- a/src/PhoneNumberField.php +++ b/src/PhoneNumberField.php @@ -33,6 +33,7 @@ class PhoneNumberField extends \acf_field public $defaults = [ 'country' => 'us', 'placeholder' => '+1 555-555-5555', + 'return_format' => 'object', ]; /** @@ -121,6 +122,18 @@ public function render_field_settings($field) 'name' => 'placeholder', 'default_value' => $this->defaults['placeholder'], ]); + + acf_render_field_setting($field, [ + 'label' => __('Return Format', 'acf-phone-number'), + 'instructions' => __('The format that the phone number will be returned in.', 'acf-phone-number'), + 'type' => 'select', + 'name' => 'return_format', + 'choices' => [ + 'object' => __('Object', 'acf-phone-number'), + 'array' => __('Array', 'acf-phone-number'), + ], + 'default_value' => $this->defaults['return_format'], + ]); } /** @@ -146,7 +159,12 @@ public function input_admin_enqueue_scripts() */ public function format_value($value, $post_id, $field) { - return new PhoneNumber($value); + $number = new PhoneNumber($value); + + return match ($field['return_format'] ?? $this->defaults['return_format']) { + 'array' => $number->toArray(), + default => $number, + }; } /**