Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.3.0 #88

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading