Fixed issues with "key => value" fields (dropdown + multiselect) if 'um_select_options_pair' filter is used;

Added JS filters to member directory functionality;
This commit is contained in:
nikitasinelnikov
2020-02-06 14:54:13 +02:00
parent 52dfdb5d54
commit 067f0d6a78
12 changed files with 193 additions and 83 deletions
+20 -12
View File
@@ -43,6 +43,14 @@ if ( ! class_exists( 'um\core\Builtin' ) ) {
}
/**
* @return array
*/
function get_all_user_fields() {
return apply_filters( 'um_builtin_all_user_fields', $this->all_user_fields );
}
/**
* Regular or multi-select/options
*
@@ -1273,7 +1281,7 @@ if ( ! class_exists( 'um\core\Builtin' ) ) {
$fields_without_metakey = apply_filters( 'um_all_user_fields_without_metakey', $fields_without_metakey );
if ( ! $show_all ) {
$this->fields_dropdown = array('image','file','password','rating');
$this->fields_dropdown = array( 'image', 'file', 'password', 'rating' );
$this->fields_dropdown = array_merge( $this->fields_dropdown, $fields_without_metakey );
} else {
$this->fields_dropdown = $fields_without_metakey;
@@ -1283,41 +1291,41 @@ if ( ! class_exists( 'um\core\Builtin' ) ) {
$predefined = $this->predefined_fields;
if ( $exclude_types ) {
$exclude_types = explode(',', $exclude_types);
$exclude_types = explode( ',', $exclude_types );
}
$all = array( 0 => '' );
if ( is_array( $custom ) ){
if ( is_array( $custom ) ) {
$all = $all + array_merge( $predefined, $custom );
} else {
$all = $all + $predefined;
}
foreach( $all as $k => $arr ) {
foreach ( $all as $k => $arr ) {
if ( $k == 0 ) {
unset($all[$k]);
unset( $all[ $k ] );
}
if ( isset( $arr['title'] ) ){
$all[$k]['title'] = stripslashes( $arr['title'] );
if ( isset( $arr['title'] ) ) {
$all[ $k ]['title'] = stripslashes( $arr['title'] );
}
if ( $exclude_types && isset( $arr['type'] ) && in_array( $arr['type'], $exclude_types ) ) {
unset( $all[$k] );
unset( $all[ $k ] );
}
if ( isset( $arr['account_only'] ) || isset( $arr['private_use'] ) ) {
if ( !$show_all ) {
unset( $all[$k] );
if ( ! $show_all ) {
unset( $all[ $k ] );
}
}
if ( isset( $arr['type'] ) && in_array( $arr['type'], $this->fields_dropdown ) ) {
unset( $all[$k] );
unset( $all[ $k ] );
}
}
$all = UM()->fields()->array_sort_by_column( $all, 'title');
$all = UM()->fields()->array_sort_by_column( $all, 'title' );
return $all;
}
+13 -1
View File
@@ -78,7 +78,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
function show_social_urls() {
$social = array();
$fields = UM()->builtin()->all_user_fields;
$fields = UM()->builtin()->get_all_user_fields();
foreach ( $fields as $field => $args ) {
if ( isset( $args['advanced'] ) && $args['advanced'] == 'social' ) {
$social[ $field ] = $args;
@@ -3105,6 +3105,18 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
$options = apply_filters( "um_multiselect_options_{$data['type']}", $options, $data );
}
/**
* UM hook
*
* @type filter
* @title um_select_option_value
* @description Enable options pair by field $data
* @input_vars
* [{"var":"$options_pair","type":"null","desc":"Enable pairs"},
* {"var":"$data","type":"array","desc":"Field Data"}]
*/
$use_keyword = apply_filters( 'um_select_options_pair', null, $data );
// switch options pair for custom options from a callback function
if ( ! empty( $data['custom_dropdown_options_source'] ) ) {
$use_keyword = true;
+61 -36
View File
@@ -606,10 +606,22 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
$custom_dropdown .= ' data-um-ajax-source="' . esc_attr( $ajax_source ) . '" ';
$attrs['options'] = UM()->fields()->get_options_from_callback( $attrs, $attrs['type'] );
} else {
/**
* UM hook
*
* @type filter
* @title um_select_option_value
* @description Enable options pair by field $data
* @input_vars
* [{"var":"$options_pair","type":"null","desc":"Enable pairs"},
* {"var":"$data","type":"array","desc":"Field Data"}]
*/
$option_pairs = apply_filters( 'um_select_options_pair', null, $attrs );
}
if ( $attrs['metakey'] != 'online_status' ) {
if ( $attrs['metakey'] != 'role_select' && $attrs['metakey'] != 'mycred_rank' && empty( $custom_dropdown ) ) {
if ( $attrs['metakey'] != 'role_select' && $attrs['metakey'] != 'mycred_rank' && empty( $custom_dropdown ) && empty( $option_pairs ) ) {
$attrs['options'] = array_intersect( array_map( 'stripslashes', array_map( 'trim', $attrs['options'] ) ), $values_array );
} elseif ( ! empty( $custom_dropdown ) ) {
$attrs['options'] = array_intersect_key( array_map( 'trim', $attrs['options'] ), array_flip( $values_array ) );
@@ -662,6 +674,10 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
if ( isset( $attrs['custom'] ) ) {
$opt = $k;
}
if ( ! empty( $option_pairs ) ) {
$opt = $k;
} ?>
<option value="<?php echo esc_attr( $opt ); ?>" data-value_label="<?php esc_attr_e( $v, 'ultimate-member' ); ?>"
@@ -2167,48 +2183,57 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
'hook_after_user_name' => preg_replace( '/^\s+/im', '', $hook_after_user_name ),
);
$directory_data['tagline_fields'] = maybe_unserialize( $directory_data['tagline_fields'] );
if ( ! empty( $directory_data['show_tagline'] ) ) {
if ( $directory_data['show_tagline'] && is_array( $directory_data['tagline_fields'] ) ) {
foreach ( $directory_data['tagline_fields'] as $key ) {
if ( ! $key ) {
continue;
if ( ! empty( $directory_data['tagline_fields'] ) ) {
$directory_data['tagline_fields'] = maybe_unserialize( $directory_data['tagline_fields'] );
if ( is_array( $directory_data['tagline_fields'] ) ) {
foreach ( $directory_data['tagline_fields'] as $key ) {
if ( ! $key ) {
continue;
}
$value = um_filtered_value( $key );
if ( ! $value ) {
continue;
}
$data_array[ $key ] = $value;
}
}
$value = um_filtered_value( $key );
if ( ! $value ) {
continue;
}
$data_array[ $key ] = $value;
}
}
if ( $directory_data['show_userinfo'] ) {
$directory_data['reveal_fields'] = maybe_unserialize( $directory_data['reveal_fields'] );
if ( ! empty( $directory_data['show_userinfo'] ) ) {
if ( is_array( $directory_data['reveal_fields'] ) ) {
foreach ( $directory_data['reveal_fields'] as $key ) {
if ( ! $key ) {
continue;
if ( ! empty( $directory_data['reveal_fields'] ) ) {
$directory_data['reveal_fields'] = maybe_unserialize( $directory_data['reveal_fields'] );
if ( is_array( $directory_data['reveal_fields'] ) ) {
foreach ( $directory_data['reveal_fields'] as $key ) {
if ( ! $key ) {
continue;
}
$value = um_filtered_value( $key );
if ( ! $value ) {
continue;
}
$label = UM()->fields()->get_label( $key );
if ( $key == 'role_select' || $key == 'role_radio' ) {
$label = strtr( $label, array(
' (Dropdown)' => '',
' (Radio)' => ''
) );
}
$data_array[ "label_{$key}" ] = __( $label, 'ultimate-member' );
$data_array[ $key ] = $value;
}
$value = um_filtered_value( $key );
if ( ! $value ) {
continue;
}
$label = UM()->fields()->get_label( $key );
if ( $key == 'role_select' || $key == 'role_radio' ) {
$label = strtr( $label, array(
' (Dropdown)' => '',
' (Radio)' => ''
) );
}
$data_array[ "label_{$key}" ] = __( $label, 'ultimate-member' );
$data_array[ $key ] = $value;
}
}
+49 -3
View File
@@ -709,14 +709,60 @@ function um_profile_field_filter_xss_validation( $value, $data, $type = '' ) {
}
}
} elseif ( 'select' == $type || 'radio' == $type ) {
if ( ! empty( $data['options'] ) && ! in_array( $value, array_map( 'trim', $data['options'] ) ) && empty( $data['custom_dropdown_options_source'] ) ) {
/**
* UM hook
*
* @type filter
* @title um_select_option_value
* @description Enable options pair by field $data
* @input_vars
* [{"var":"$options_pair","type":"null","desc":"Enable pairs"},
* {"var":"$data","type":"array","desc":"Field Data"}]
*/
$option_pairs = apply_filters( 'um_select_options_pair', null, $data );
$arr = $data['options'];
if ( $option_pairs ) {
$arr = array_keys( $data['options'] );
}
if ( ! empty( $arr ) && ! in_array( $value, array_map( 'trim', $arr ) ) && empty( $data['custom_dropdown_options_source'] ) ) {
$value = '';
} else {
if ( $option_pairs ) {
$value = $data['options'][ $value ];
}
}
}
} elseif ( ! empty( $value ) && is_array( $value ) ) {
if ( 'multiselect' == $type || 'checkbox' == $type ) {
if ( ! empty( $data['options'] ) && empty( $data['custom_dropdown_options_source'] ) ) {
$value = array_intersect( $value, array_map( 'trim', $data['options'] ) );
/**
* UM hook
*
* @type filter
* @title um_select_option_value
* @description Enable options pair by field $data
* @input_vars
* [{"var":"$options_pair","type":"null","desc":"Enable pairs"},
* {"var":"$data","type":"array","desc":"Field Data"}]
*/
$option_pairs = apply_filters( 'um_select_options_pair', null, $data );
$arr = $data['options'];
if ( $option_pairs ) {
$arr = array_keys( $data['options'] );
}
if ( ! empty( $arr ) && empty( $data['custom_dropdown_options_source'] ) ) {
$value = array_intersect( $value, array_map( 'trim', $arr ) );
}
if ( $option_pairs ) {
foreach ( $value as &$val ) {
$val = $data['options'][ $val ];
}
}
}
}