Skip to content

#55-US State field - #231

Open
reygcalantaol wants to merge 1 commit into
developfrom
#55-US-State-field
Open

#55-US State field#231
reygcalantaol wants to merge 1 commit into
developfrom
#55-US-State-field

Conversation

@reygcalantaol

Copy link
Copy Markdown
Collaborator

@polevaultweb

polevaultweb commented Jun 28, 2021

Copy link
Copy Markdown
Contributor

NB. Update min addon version to 2.5

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 states field type class (WPUM_Field_States) with editor settings (including “allow multiple selection”).
  • Added a states-field.php template that delegates rendering to the existing select/multiselect field templates.
  • Registered the new states field 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 ) );

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.
Comment on lines +18 to +25
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';

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

/**
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants