Adds new select/multi-select options to retrieve options from a callback

This commit is contained in:
Champ Camba
2016-11-06 19:36:22 +08:00
parent 71ef64623d
commit 06983833af
9 changed files with 226 additions and 15 deletions
+80 -8
View File
@@ -368,27 +368,27 @@ class UM_Fields {
global $ultimatemember;
if ( isset($_SESSION) && isset($_SESSION['um_social_profile'][$key]) && isset( $this->set_mode ) && $this->set_mode == 'register' )
return $_SESSION['um_social_profile'][$key];
if ( isset( $_SESSION ) && isset( $_SESSION['um_social_profile'][ $key ] ) && isset( $this->set_mode ) && $this->set_mode == 'register' )
return $_SESSION['um_social_profile'][ $key ];
$type = (isset($data['type']))?$data['type']:'';
$type = ( isset( $data['type'] ) ) ? $data['type'] : '';
// preview in backend
if ( isset( $ultimatemember->user->preview ) && $ultimatemember->user->preview ) {
$submitted = um_user('submitted');
if ( isset( $submitted[$key] ) && !empty( $submitted[$key] ) ) {
return $submitted[$key];
if ( isset( $submitted[ $key ] ) && ! empty( $submitted[ $key ] ) ) {
return $submitted[ $key ];
} else {
return 'Undefined';
}
}
// normal state
if ( isset($ultimatemember->form->post_form[$key]) ) {
if ( isset( $ultimatemember->form->post_form[ $key ] ) ) {
if ( strstr( $key, 'user_pass' ) && $this->set_mode != 'password' ) return '';
return $ultimatemember->form->post_form[$key];
return $ultimatemember->form->post_form[ $key ];
} else if ( um_user( $key ) && $this->editing == true ) {
@@ -396,7 +396,7 @@ class UM_Fields {
return apply_filters( "um_edit_{$key}_field_value", um_user( $key ), $key );
} else if ( ( um_user( $key ) || isset($data['show_anyway']) ) && $this->viewing == true ) {
} else if ( ( um_user( $key ) || isset( $data['show_anyway'] ) ) && $this->viewing == true ) {
$value = um_filtered_value( $key, $data );
return $value;
@@ -556,6 +556,67 @@ class UM_Fields {
return '';
}
/**
* Get selected option from a callback function
*/
function get_option_value_from_callback( $value, $data, $type ){
if( in_array( $type , array('select','multiselect') ) && isset( $data['custom_dropdown_options_source'] ) && ! empty( $data['custom_dropdown_options_source'] ) ){
if( function_exists( $data['custom_dropdown_options_source'] ) ){
$arr_options = call_user_func( $data['custom_dropdown_options_source'] );
if( $type == 'select' ){
return isset( $arr_options[ $value ] ) ? $arr_options[ $value ]: '' ;
}
if( $type == 'multiselect' ){
if( is_array( $value ) ){
$values = $value;
}else{
$values = explode(', ', $value );
}
$arr_paired_options = array();
foreach ( $values as $option ) {
$arr_paired_options[] = $arr_options[ $option ];
}
return implode( ', ' , $arr_paired_options );
}
}
}
return $value;
}
/**
* Get select options from a callback function
*/
function get_options_from_callback( $data, $type ){
if( in_array( $type , array('select','multiselect') ) && isset( $data['custom_dropdown_options_source'] ) && ! empty( $data['custom_dropdown_options_source'] ) ){
if( function_exists( $data['custom_dropdown_options_source'] ) ){
$arr_options = call_user_func( $data['custom_dropdown_options_source'] );
}
}
return $arr_options;
}
/***
*** @Get Field Type
***/
@@ -1653,6 +1714,11 @@ class UM_Fields {
$output .= '<option value=""></option>';
$field_value = '';
// switch options pair for custom options from a callback function
if( isset( $data['custom_dropdown_options_source'] ) && ! empty( $data['custom_dropdown_options_source'] ) ){
$options_pair = true;
}
// add options
foreach($options as $k => $v) {
@@ -1743,6 +1809,11 @@ class UM_Fields {
$options = apply_filters("um_multiselect_options_{$key}", $options );
$options = apply_filters("um_multiselect_options_{$data['type']}", $options, $data );
}
// switch options pair for custom options from a callback function
if( isset( $data['custom_dropdown_options_source'] ) && ! empty( $data['custom_dropdown_options_source'] ) ){
$use_keyword = true;
}
// add an empty option!
$output .= '<option value=""></option>';
@@ -2279,6 +2350,7 @@ class UM_Fields {
$res = stripslashes( $res );
}
$res = apply_filters("um_view_field", $res, $data, $type );
$res = apply_filters("um_view_field_value_{$type}", $res, $data );
$output .= '<div class="um-field-area">';