Skip to content

Commit

Permalink
fix(field): Properly use acf_register_field_type() for registering …
Browse files Browse the repository at this point in the history
…field type (#62)

enhance(field):  Format field value in Rest API
  • Loading branch information
Dathix authored Nov 18, 2022
1 parent 78fe785 commit b2c1c69
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 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.1
* Version: 1.2.2
* Author: Brandon Nifong
* Author URI: https://github.com/log1x
*/
Expand Down Expand Up @@ -45,14 +45,16 @@ public function __invoke()
*/
protected function register()
{
foreach (['acf/include_field_types', 'acf/register_fields'] as $hook) {
add_filter($hook, function () {
return new PhoneNumberField(
plugin_dir_url(__FILE__) . $this->assetPath,
plugin_dir_path(__FILE__) . $this->assetPath
);
});
}
$field = new PhoneNumberField(
plugin_dir_url(__FILE__) . $this->assetPath,
plugin_dir_path(__FILE__) . $this->assetPath
);

acf_register_field_type($field);

add_filter("acf/rest/format_value_for_rest/type={$field->name}", function ($formatted, $post, $field, $value) {
return (new PhoneNumber($value))->toArray();
}, 10, 4);
}

/**
Expand Down

0 comments on commit b2c1c69

Please sign in to comment.