-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5d07ff
commit 6f56ca3
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
|
||
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 ) ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); |
Note to self, needs to be 2.4