diff --git a/includes/wpum-fields/class-wpum-fields.php b/includes/wpum-fields/class-wpum-fields.php index 655182bb..2cdcb564 100644 --- a/includes/wpum-fields/class-wpum-fields.php +++ b/includes/wpum-fields/class-wpum-fields.php @@ -66,6 +66,7 @@ public function load() { 'hidden', 'taxonomy', 'user', + 'states', ] ); foreach ( $fields as $field ) { diff --git a/includes/wpum-fields/types/class-wpum-field-states.php b/includes/wpum-fields/types/class-wpum-field-states.php new file mode 100644 index 00000000..387fea80 --- /dev/null +++ b/includes/wpum-fields/types/class-wpum-field-states.php @@ -0,0 +1,65 @@ +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'; + } + + 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. + * + * @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 ) ); + } + +} diff --git a/templates/form-fields/states-field.php b/templates/form-fields/states-field.php new file mode 100644 index 00000000..ba90feef --- /dev/null +++ b/templates/form-fields/states-field.php @@ -0,0 +1,21 @@ +allow_multiple ) ? 'select' : 'multiselect'; + +WPUM()->templates->set_template_data( $data )->get_template_part( 'form-fields/' . $field_type, 'field' );