Skip to content

Commit

Permalink
feat(field): Add compatibility when changing from a different field t…
Browse files Browse the repository at this point in the history
…ype (e.g. text field) to the phone number field.
  • Loading branch information
Log1x committed Aug 5, 2020
1 parent 2f5d6c9 commit 22138a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 46 deletions.
2 changes: 1 addition & 1 deletion 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.0.1
* Version: 1.0.2
* Author: Brandon Nifong
* Author URI: https://github.com/log1x
*/
Expand Down
52 changes: 7 additions & 45 deletions src/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ public function __construct($settings)
*/
public function render_field($field)
{
if (is_string($value = $field['value']) && ! empty(trim($value))) {
$field['value'] = [
'number' => $value,
'country' => '',
];
}

echo sprintf(
'<input type="tel" name="%s[number]" value="%s" />',
$field['name'],
Expand Down Expand Up @@ -153,49 +160,4 @@ public function validate_value($valid, $value, $field, $input)
return $this->phone->isValidNumber($phone) ?
$valid : 'The phone number entered is not valid.';
}

/**
* This action is fired after a value has been deleted from the database.
*
* @param mixed $post_id
* @param string $key
* @return void
*/
// public function delete_value($post_id, $key)
// {
//
// }

/**
* This filter is applied to the $field after it is loaded from the database.
*
* @param array $field
* @return array
*/
// public function load_field($field)
// {
// return $field;
// }

/**
* This filter is applied to the $field before it is saved to the database.
*
* @param array $field
* @return array
*/
// public function update_field($field)
// {
// return $field;
// }

/**
* This action is fired after a field is deleted from the database.
*
* @param array $field
* @return void
*/
// public function delete_field($field)
// {
// return $field;
// }
}

0 comments on commit 22138a1

Please sign in to comment.