#55-US State field - #231
Conversation
|
NB. Update min addon version to 2.5 |
66fc642 to
2883116
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds a new US States custom field type to WP User Manager (intended for use with the Custom Fields add-on), addressing wpum-custom-fields issue #55 by enabling state selection via a select or multiselect UI.
Changes:
- Added a
statesfield type class (WPUM_Field_States) with editor settings (including “allow multiple selection”). - Added a
states-field.phptemplate that delegates rendering to the existingselect/multiselectfield templates. - Registered the new
statesfield type in the field loader so it is discovered and available to the system.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
templates/form-fields/states-field.php |
Adds a template wrapper that chooses select vs. multiselect based on allow_multiple. |
includes/wpum-fields/types/class-wpum-field-states.php |
Introduces the new states field type and its admin/editor settings and output formatting. |
includes/wpum-fields/class-wpum-fields.php |
Registers states so the field type class is loaded and available. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $value = array( $value ); | ||
| } | ||
|
|
||
| return implode( ', ', wp_list_pluck( $value ) ); |
There was a problem hiding this comment.
get_formatted_output() calls wp_list_pluck( $value ) with only one argument, but wp_list_pluck() requires at least $input_list and $field. This will trigger a PHP fatal error when the field value is rendered on profiles. Replace this with logic appropriate for the stored value (e.g., implode the array of selected values, or map stored values to labels via the field's options before imploding).
| return implode( ', ', wp_list_pluck( $value ) ); | |
| $value = array_filter( | |
| $value, | |
| function( $state ) { | |
| return is_scalar( $state ) && '' !== (string) $state; | |
| } | |
| ); | |
| return implode( ', ', $value ); |
| public function __construct() { | ||
| $this->name = esc_html__( 'US States', 'wp-user-manager' ); | ||
| $this->type = 'states'; | ||
| $this->icon = 'dashicons-location-alt'; | ||
| $this->group = 'advanced'; | ||
| $this->label = 'State'; | ||
| $this->allow_default = false; | ||
| $this->min_addon_version = '2.3'; |
There was a problem hiding this comment.
$this->label is being set but WPUM_Field_Type does not declare a label property. On PHP 8.2+ this creates a dynamic property and will emit deprecation warnings. Either declare public $label on the base type (if it's a supported concept) or remove this assignment / move it into existing editor settings (e.g., a type_label setting like WPUM_Field_User uses).
| if ( ! defined( 'ABSPATH' ) ) exit; | ||
|
|
||
| /** | ||
| * Register a dropdown field type. |
There was a problem hiding this comment.
The docblock above the class still says "Register a dropdown field type". Updating it to refer to the States field type would keep the inline documentation accurate.
| * Register a dropdown field type. | |
| * Register a States field type. |
| } | ||
|
|
||
| /** | ||
| * Format the output onto the profiles for the taxonomy field. |
There was a problem hiding this comment.
The get_formatted_output() docblock mentions "taxonomy field", which looks like a copy/paste. Renaming it to "states field" would avoid confusion.
| * Format the output onto the profiles for the taxonomy field. | |
| * Format the output onto the profiles for the states field. |
@polevaultweb
Resolves https://github.com/WPUserManager/wpum-custom-fields/issues/55