Skip to content

Commit 6f56ca3

Browse files
committed
1 parent f5d07ff commit 6f56ca3

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

includes/wpum-fields/class-wpum-fields.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function load() {
6666
'hidden',
6767
'taxonomy',
6868
'user',
69+
'states',
6970
] );
7071

7172
foreach ( $fields as $field ) {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Registers a States field for the forms.
4+
*
5+
* @package wp-user-manager
6+
* @copyright Copyright (c) 2021, WP User Manager
7+
* @license https://opensource.org/licenses/GPL-3.0 GNU Public License
8+
*/
9+
10+
// Exit if accessed directly
11+
if ( ! defined( 'ABSPATH' ) ) exit;
12+
13+
/**
14+
* Register a dropdown field type.
15+
*/
16+
class WPUM_Field_States extends WPUM_Field_Type {
17+
18+
public function __construct() {
19+
$this->name = esc_html__( 'US States', 'wp-user-manager' );
20+
$this->type = 'states';
21+
$this->icon = 'dashicons-location-alt';
22+
$this->group = 'advanced';
23+
$this->label = 'State';
24+
$this->allow_default = false;
25+
$this->min_addon_version = '2.3';
26+
}
27+
28+
public function get_data_keys() {
29+
$keys = parent::get_data_keys();
30+
31+
return array_merge( $keys, array_keys( $this->get_editor_settings()['general'] ) );
32+
}
33+
34+
/**
35+
* @return array
36+
*/
37+
public function get_editor_settings() {
38+
return [
39+
'general' => [
40+
'allow_multiple' => array(
41+
'type' => 'checkbox',
42+
'label' => esc_html__( 'Allow multiple selection', 'wp-user-manager' ),
43+
'model' => 'allow_multiple',
44+
'default' => false,
45+
)
46+
],
47+
];
48+
}
49+
50+
/**
51+
* Format the output onto the profiles for the taxonomy field.
52+
*
53+
* @param object $field
54+
* @param mixed $value
55+
* @return string
56+
*/
57+
function get_formatted_output( $field, $value ) {
58+
if ( ! is_array( $value ) ) {
59+
$value = array( $value );
60+
}
61+
62+
return implode( ', ', wp_list_pluck( $value ) );
63+
}
64+
65+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* The template for displaying the states field.
4+
*
5+
* This template can be overridden by copying it to yourtheme/wpum/form-fields/states-field.php
6+
*
7+
* HOWEVER, on occasion WPUM will need to update template files and you
8+
* (the theme developer) will need to copy the new files to your theme to
9+
* maintain compatibility. We try to do this as little as possible, but it does
10+
* happen. When this occurs the version of the template file will be bumped and
11+
* the readme will list any important changes.
12+
*
13+
* @version 1.0.0
14+
*/
15+
16+
// Exit if accessed directly
17+
if ( ! defined( 'ABSPATH' ) ) exit;
18+
19+
$field_type = empty( $data->allow_multiple ) ? 'select' : 'multiselect';
20+
21+
WPUM()->templates->set_template_data( $data )->get_template_part( 'form-fields/' . $field_type, 'field' );

0 commit comments

Comments
 (0)