-
Notifications
You must be signed in to change notification settings - Fork 21
#55-US State field #231
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
base: develop
Are you sure you want to change the base?
#55-US State field #231
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,65 @@ | ||||||||||||||||||||
| <?php | ||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Registers a States field for the forms. | ||||||||||||||||||||
| * | ||||||||||||||||||||
| * @package wp-user-manager | ||||||||||||||||||||
| * @copyright Copyright (c) 2021, WP User Manager | ||||||||||||||||||||
| * @license https://opensource.org/licenses/GPL-3.0 GNU Public License | ||||||||||||||||||||
| */ | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Exit if accessed directly | ||||||||||||||||||||
| if ( ! defined( 'ABSPATH' ) ) exit; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Register a dropdown field type. | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| class WPUM_Field_States extends WPUM_Field_Type { | ||||||||||||||||||||
|
|
||||||||||||||||||||
| 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'; | ||||||||||||||||||||
|
Comment on lines
+18
to
+25
|
||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| public function get_data_keys() { | ||||||||||||||||||||
| $keys = parent::get_data_keys(); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return array_merge( $keys, array_keys( $this->get_editor_settings()['general'] ) ); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
| * @return array | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| public function get_editor_settings() { | ||||||||||||||||||||
| return [ | ||||||||||||||||||||
| 'general' => [ | ||||||||||||||||||||
| 'allow_multiple' => array( | ||||||||||||||||||||
| 'type' => 'checkbox', | ||||||||||||||||||||
| 'label' => esc_html__( 'Allow multiple selection', 'wp-user-manager' ), | ||||||||||||||||||||
| 'model' => 'allow_multiple', | ||||||||||||||||||||
| 'default' => false, | ||||||||||||||||||||
| ) | ||||||||||||||||||||
| ], | ||||||||||||||||||||
| ]; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Format the output onto the profiles for the taxonomy field. | ||||||||||||||||||||
|
||||||||||||||||||||
| * Format the output onto the profiles for the taxonomy field. | |
| * Format the output onto the profiles for the states field. |
Copilot
AI
May 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <?php | ||
| /** | ||
| * The template for displaying the states field. | ||
| * | ||
| * This template can be overridden by copying it to yourtheme/wpum/form-fields/states-field.php | ||
| * | ||
| * HOWEVER, on occasion WPUM will need to update template files and you | ||
| * (the theme developer) will need to copy the new files to your theme to | ||
| * maintain compatibility. We try to do this as little as possible, but it does | ||
| * happen. When this occurs the version of the template file will be bumped and | ||
| * the readme will list any important changes. | ||
| * | ||
| * @version 1.0.0 | ||
| */ | ||
|
|
||
| // Exit if accessed directly | ||
| if ( ! defined( 'ABSPATH' ) ) exit; | ||
|
|
||
| $field_type = empty( $data->allow_multiple ) ? 'select' : 'multiselect'; | ||
|
|
||
| WPUM()->templates->set_template_data( $data )->get_template_part( 'form-fields/' . $field_type, 'field' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.