Skip to content

Commit

Permalink
v1.3.0 (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x authored Oct 24, 2024
2 parents 821539f + f1c7b42 commit 1f05c68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
26 changes: 1 addition & 25 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -36,10 +36,6 @@ public function __invoke()
}

$this->register();

if (defined('ACP_FILE')) {
$this->hookAdminColumns();
}
}

/**
Expand All @@ -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);
}
});
20 changes: 19 additions & 1 deletion src/PhoneNumberField.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class PhoneNumberField extends \acf_field
public $defaults = [
'country' => 'us',
'placeholder' => '+1 555-555-5555',
'return_format' => 'object',
];

/**
Expand Down Expand Up @@ -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'],
]);
}

/**
Expand All @@ -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,
};
}

/**
Expand Down

0 comments on commit 1f05c68

Please sign in to comment.