- code review;

This commit is contained in:
nikitasinelnikov
2019-07-16 14:35:57 +03:00
parent 77a98acc2f
commit b5f4cd723e
3 changed files with 48 additions and 47 deletions
+27 -29
View File
@@ -1066,21 +1066,21 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
* @param array $data
* @param string $type
*
* @return json
* @return string
*/
function get_option_value_from_callback( $value, $data, $type ) {
if ( in_array( $type, array( 'select', 'multiselect' ) ) && ! empty( $data['custom_dropdown_options_source'] ) ) {
$has_custom_source = apply_filters("um_has_dropdown_options_source__{$data['metakey']}", false );
$has_custom_source = apply_filters( "um_has_dropdown_options_source__{$data['metakey']}", false );
if( $has_custom_source ){
if ( $has_custom_source ) {
$opts = apply_filters("um_get_field__{$data['metakey']}", array() );
$opts = apply_filters( "um_get_field__{$data['metakey']}", array() );
$arr_options = $opts['options'];
}else if ( function_exists( $data['custom_dropdown_options_source'] ) ) {
} elseif ( function_exists( $data['custom_dropdown_options_source'] ) ) {
$arr_options = call_user_func(
$data['custom_dropdown_options_source'],
@@ -1088,34 +1088,32 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
);
}
if( $has_custom_source || function_exists( $data['custom_dropdown_options_source'] ) ){
if ( $has_custom_source || function_exists( $data['custom_dropdown_options_source'] ) ) {
if ( $type == 'select' ) {
if ( ! empty( $arr_options[ $value ] ) ) {
return $arr_options[ $value ];
} elseif ( ! empty( $data['default'] ) && empty( $arr_options[ $value ] ) ) {
return $arr_options[ $data['default'] ];
} else {
return '';
if ( ! empty( $arr_options[ $value ] ) ) {
return $arr_options[ $value ];
} elseif ( ! empty( $data['default'] ) && empty( $arr_options[ $value ] ) ) {
return $arr_options[ $data['default'] ];
} else {
return '';
}
} elseif ( $type == 'multiselect' ) {
if ( is_array( $value ) ) {
$values = $value;
} else {
$values = explode( ', ', $value );
}
$arr_paired_options = array();
foreach ( $values as $option ) {
if ( isset( $arr_options[ $option ] ) ) {
$arr_paired_options[] = $arr_options[ $option ];
}
}
if ( $type == 'multiselect' ) {
if ( is_array( $value ) ) {
$values = $value;
} else {
$values = explode( ', ', $value );
}
$arr_paired_options = array();
foreach ( $values as $option ) {
if ( isset( $arr_options[ $option ] ) ) {
$arr_paired_options[] = $arr_options[ $option ];
}
}
return implode( ', ', $arr_paired_options );
return implode( ', ', $arr_paired_options );
}
}
+12 -12
View File
@@ -215,8 +215,8 @@ function um_user_edit_profile( $args ) {
*/
do_action( 'um_user_before_updating_profile', $userinfo );
if ( !empty( $args[ 'custom_fields' ] ) ) {
$fields = apply_filters( 'um_user_edit_profile_fields', unserialize( $args[ 'custom_fields' ] ), $args );
if ( ! empty( $args['custom_fields'] ) ) {
$fields = apply_filters( 'um_user_edit_profile_fields', unserialize( $args['custom_fields'] ), $args );
}
// loop through fields
@@ -251,19 +251,19 @@ function um_user_edit_profile( $args ) {
* Returns dropdown/multi-select options keys from a callback function
* @since 2019-05-30
*/
$has_custom_source = apply_filters("um_has_dropdown_options_source__{$key}", false );
if ( isset( $array[ 'options' ] ) && in_array( $array[ 'type' ], array( 'select', 'multiselect' ) ) ) {
if ( !empty( $array[ 'custom_dropdown_options_source' ] ) && function_exists( $array[ 'custom_dropdown_options_source' ] ) && ! $has_custom_source ) {
$options = call_user_func( $array[ 'custom_dropdown_options_source' ], $array[ 'options' ] );
if( is_array( $options ) ){
$array[ 'options' ] = apply_filters("um_custom_dropdown_options__{$key}", array_keys( $options ) );
$has_custom_source = apply_filters( "um_has_dropdown_options_source__{$key}", false );
if ( isset( $array['options'] ) && in_array( $array['type'], array( 'select', 'multiselect' ) ) ) {
$options = array();
if ( ! empty( $array['custom_dropdown_options_source'] ) && function_exists( $array['custom_dropdown_options_source'] ) && ! $has_custom_source ) {
$callback_result = call_user_func( $array['custom_dropdown_options_source'], $array['options'] );
if ( is_array( $callback_result ) ) {
$options = array_keys( $callback_result );
}
}else{
$array[ 'options' ] = apply_filters("um_custom_dropdown_options__{$key}", array() );
}
$array['options'] = apply_filters( "um_custom_dropdown_options__{$key}", $options );
}
+9 -6
View File
@@ -310,7 +310,9 @@ add_filter( 'um_profile_field_filter_hook__image', 'um_profile_field_filter_hook
* @return string
*/
function um_profile_field_filter_hook__( $value, $data, $type = '' ) {
if ( !$value ) return '';
if ( ! $value ) {
return '';
}
if ( ( isset( $data['validate'] ) && $data['validate'] != '' && strstr( $data['validate'], 'url' ) ) || ( isset( $data['type'] ) && $data['type'] == 'url' ) ) {
$alt = ( isset( $data['url_text'] ) && !empty( $data['url_text'] ) ) ? $data['url_text'] : $value;
@@ -360,11 +362,12 @@ function um_profile_field_filter_hook__( $value, $data, $type = '' ) {
}
if ( !is_array( $value ) ) {
if ( is_email( $value ) )
if ( ! is_array( $value ) ) {
if ( is_email( $value ) ) {
$value = '<a href="mailto:'. $value.'" title="'.$value.'">'.$value.'</a>';
}
} else {
$value = implode(', ', $value);
$value = implode( ', ', $value );
}
$value = str_replace('https://https://','https://',$value);
@@ -679,13 +682,13 @@ function um_profile_field_filter_xss_validation( $value, $data, $type = '' ) {
}
}
} elseif ( 'select' == $type || 'radio' == $type ) {
if ( ! empty( $data['options'] ) && ! in_array( $value, $data['options'] ) && empty( $data[ 'custom_dropdown_options_source' ] ) ) {
if ( ! empty( $data['options'] ) && ! in_array( $value, $data['options'] ) && empty( $data['custom_dropdown_options_source'] ) ) {
$value = '';
}
}
} elseif ( ! empty( $value ) && is_array( $value ) ) {
if ( 'multiselect' == $type || 'checkbox' == $type ) {
if ( ! empty( $data['options'] ) && empty( $data[ 'custom_dropdown_options_source' ] ) ) {
if ( ! empty( $data['options'] ) && empty( $data['custom_dropdown_options_source'] ) ) {
$value = array_intersect( $value, $data['options'] );
}
}