Skip to content
Open
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
1 change: 1 addition & 0 deletions includes/wpum-fields/class-wpum-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function load() {
'hidden',
'taxonomy',
'user',
'states',
] );

foreach ( $fields as $field ) {
Expand Down
65 changes: 65 additions & 0 deletions includes/wpum-fields/types/class-wpum-field-states.php
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.

Copilot AI May 1, 2026

Copy link

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.

Suggested change
* Register a dropdown field type.
* Register a States field type.

Copilot uses AI. Check for mistakes.
*/
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

Copilot AI May 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$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).

Copilot uses AI. Check for mistakes.
}

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.

Copilot AI May 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The get_formatted_output() docblock mentions "taxonomy field", which looks like a copy/paste. Renaming it to "states field" would avoid confusion.

Suggested change
* Format the output onto the profiles for the taxonomy field.
* Format the output onto the profiles for the states field.

Copilot uses AI. Check for mistakes.
*
* @param object $field
* @param mixed $value
* @return string
*/
function get_formatted_output( $field, $value ) {
if ( ! is_array( $value ) ) {
$value = array( $value );
}

return implode( ', ', wp_list_pluck( $value ) );

Copilot AI May 1, 2026

Copy link

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).

Suggested change
return implode( ', ', wp_list_pluck( $value ) );
$value = array_filter(
$value,
function( $state ) {
return is_scalar( $state ) && '' !== (string) $state;
}
);
return implode( ', ', $value );

Copilot uses AI. Check for mistakes.
}

}
21 changes: 21 additions & 0 deletions templates/form-fields/states-field.php
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' );