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
+1
View File
@@ -42,6 +42,7 @@ GNU Version 2 or Any Later Version
## Releases
[Official Release Version: 2.1.3](https://github.com/ultimatemember/ultimatemember/releases/tag/2.1.3).
[Official Release Candidate Version: 2.1.4-RC1](https://github.com/ultimatemember/ultimatemember/releases/tag/2.1.4-rc.1).
## Changelog
[ From v1.0.0 to latest version ](https://wordpress.org/plugins/ultimate-member/changelog/).
+18 -11
View File
@@ -362,7 +362,7 @@ function um_build_template( directory, data ) {
var header_template = wp.template( 'um-members-header' );
directory.find('.um-members-intro').remove();
var generate_header = wp.hooks.applyFilters( 'um_member_directory_generate_header', false );
var generate_header = wp.hooks.applyFilters( 'um_member_directory_generate_header', false, directory );
if ( ( typeof data.is_search != 'undefined' && data.is_search ) || generate_header ) {
directory.find('.um-members-wrapper').prepend( header_template( data ) );
@@ -591,7 +591,7 @@ function um_run_search( directory ) {
var ignore_after_search = false;
ignore_after_search = wp.hooks.applyFilters( 'um_member_directory_ignore_after_search', ignore_after_search );
ignore_after_search = wp.hooks.applyFilters( 'um_member_directory_ignore_after_search', ignore_after_search, directory );
if ( ! ignore_after_search ) {
var show_after_search = directory.data('must-search');
@@ -1167,7 +1167,7 @@ jQuery(document.body).ready( function() {
}
var ignore_after_search = false;
ignore_after_search = wp.hooks.applyFilters( 'um_member_directory_ignore_after_search', ignore_after_search );
ignore_after_search = wp.hooks.applyFilters( 'um_member_directory_ignore_after_search', ignore_after_search, directory );
if ( ! ignore_after_search ) {
var show_after_search = directory.data('must-search');
@@ -1291,7 +1291,7 @@ jQuery(document.body).ready( function() {
}
var ignore_after_search = false;
ignore_after_search = wp.hooks.applyFilters( 'um_member_directory_ignore_after_search', ignore_after_search );
ignore_after_search = wp.hooks.applyFilters( 'um_member_directory_ignore_after_search', ignore_after_search, directory );
if ( ! ignore_after_search ) {
var show_after_search = directory.data('must-search');
@@ -1586,7 +1586,7 @@ jQuery(document.body).ready( function() {
wp.hooks.doAction( 'um_member_directory_on_init', directory, hash );
var ignore_after_search = false;
ignore_after_search = wp.hooks.applyFilters( 'um_member_directory_ignore_after_search', ignore_after_search );
ignore_after_search = wp.hooks.applyFilters( 'um_member_directory_ignore_after_search', ignore_after_search, directory );
if ( ! ignore_after_search ) {
var show_after_search = directory.data('must-search');
@@ -1599,9 +1599,13 @@ jQuery(document.body).ready( function() {
}
}
um_members_show_preloader( directory );
um_ajax_get_members( directory, {first_load:true} );
um_change_tag( directory );
var prevent_default = wp.hooks.applyFilters( 'um_member_directory_prevent_default_first_loading', false, directory, hash );
if ( ! prevent_default ) {
um_members_show_preloader( directory );
um_ajax_get_members( directory, {first_load:true} );
um_change_tag( directory );
}
});
@@ -1716,7 +1720,7 @@ jQuery(document.body).ready( function() {
});
var ignore_after_search = false;
ignore_after_search = wp.hooks.applyFilters( 'um_member_directory_ignore_after_search', ignore_after_search );
ignore_after_search = wp.hooks.applyFilters( 'um_member_directory_ignore_after_search', ignore_after_search, directory );
if ( ! ignore_after_search ) {
var show_after_search = directory.data('must-search');
@@ -1733,9 +1737,12 @@ jQuery(document.body).ready( function() {
}
}
um_ajax_get_members( directory );
var prevent_default = wp.hooks.applyFilters( 'um_member_directory_prevent_default_first_loading', false, directory, hash );
um_change_tag( directory );
if ( ! prevent_default ) {
um_ajax_get_members( directory );
um_change_tag( directory );
}
});
});
+1 -1
View File
File diff suppressed because one or more lines are too long
+3 -3
View File
@@ -37,7 +37,7 @@ function um_admin_new_modal( id, ajax, size ) {
function um_tinymce_init( id, content ) {
var object = jQuery('#' + id);
if ( typeof(tinyMCE) === 'object' && tinyMCE.get( id ) !== null ) {
if ( typeof( tinyMCE ) === 'object' && tinyMCE.get( id ) !== null ) {
tinyMCE.triggerSave();
tinyMCE.EditorManager.execCommand( 'mceRemoveEditor', true, id );
"4" === tinyMCE.majorVersion ? window.tinyMCE.execCommand( "mceRemoveEditor", !0, id ) : window.tinyMCE.execCommand( "mceRemoveControl", !0, id );
@@ -55,7 +55,7 @@ function um_tinymce_init( id, content ) {
QTags( tinyMCEPreInit.qtInit[ id ] );
QTags._buttonsInit();
}
if ( typeof(window.switchEditors) === 'object' ) {
if ( typeof( window.switchEditors ) === 'object' ) {
window.switchEditors.go( id );
}
tinyMCE.init( init );
@@ -79,7 +79,7 @@ function um_tinymce_init( id, content ) {
jQuery( 'body' ).on( 'click', '.wp-switch-editor', function() {
var target = jQuery(this);
if ( target.hasClass( 'wp-switch-editor' ) && typeof(window.switchEditors) === 'object' ) {
if ( target.hasClass( 'wp-switch-editor' ) && typeof( window.switchEditors ) === 'object' ) {
var mode = target.hasClass( 'switch-tmce' ) ? 'tmce' : 'html';
window.switchEditors.go( id, mode );
}
+9 -7
View File
@@ -652,10 +652,12 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) {
/**
* Print editor scripts if they are not printed by default
* @return type
*/
function admin_footer_scripts() {
$CLASS = '\_WP_Editors';
/**
* @var $class \_WP_Editors
*/
$class = '\_WP_Editors';
if ( did_action( 'print_default_editor_scripts' ) ) {
return;
@@ -663,17 +665,17 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) {
if ( did_action( 'wp_tiny_mce_init' ) ) {
return;
}
if ( has_action( 'admin_print_footer_scripts', array( $CLASS, 'editor_js' ) ) ) {
if ( has_action( 'admin_print_footer_scripts', array( $class, 'editor_js' ) ) ) {
return;
}
if ( !class_exists( $CLASS, false ) ) {
if ( ! class_exists( $class, false ) ) {
require_once( ABSPATH . WPINC . '/class-wp-editor.php' );
}
$CLASS::force_uncompressed_tinymce();
$CLASS::enqueue_scripts();
$CLASS::editor_js();
$class::force_uncompressed_tinymce();
$class::enqueue_scripts();
$class::editor_js();
}
}
+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 ];
}
}
}
}
+5 -5
View File
@@ -773,18 +773,18 @@ function um_user_submitted_registration( $style = false ) {
/**
* Show filtered social link
*
* @param $key
* @param $match
* @param string $key
* @param string $match
*
* @return mixed|string|void
* @return string
*/
function um_filtered_social_link( $key, $match ) {
$value = um_profile( $key );
$submatch = str_replace( 'https://', '', $match );
$submatch = str_replace( 'http://', '', $submatch );
if (strstr( $value, $submatch )) {
if ( strstr( $value, $submatch ) ) {
$value = 'https://' . $value;
} else if (strpos( $value, 'http' ) !== 0) {
} elseif ( strpos( $value, 'http' ) !== 0 ) {
$value = $match . $value;
}
$value = str_replace( 'https://https://', 'https://', $value );
+12 -3
View File
@@ -145,17 +145,26 @@ The plugin works with popular caching plugins by automatically excluding Ultimat
* To learn more about version 2.1 please see this [topic](https://wordpress.org/support/topic/version-2-1-4/)
* UM2.1+ is a significant update to the Member Directories' code base from 2.0.x. Please make sure you take a full-site backup with restore point before updating the plugin
= 2.1.4: January xx, 2020 =
= 2.1.4: February xx, 2020 =
* Enhancements:
- Updated select2 JS library to 4.0.12 version
- Added a few member directories filters for 3rd-party integrations
- Added a few member directories PHP and JS filters for 3rd-party integrations
- Added labels for member directories filters to increase Accessibility points in Audit
* Bugfixes:
- Added labels for member directories filters to increase Accessibility points in Audit
- Fixed activation licenses with sslverify
- Fixed fields' options if they contains spaces in the start and the end of option (added trim)
- Fixed getting range for slider filters
- Fixed 2.1.3-beta3 package upgrade
- Fixed resize image on registration form
- Fixed multiselect field styles
- Fixed issue with not editable fields and their visibility
- Fixed displaying header with member counts
- Fixed JS errors with not defined tinyMCE on Forms builder
- Fixed issues with "key => value" fields (dropdown + multiselect) if 'um_select_options_pair' filter is used
= 2.1.3: January 21, 2020 =
+1 -1
View File
@@ -3,7 +3,7 @@
Plugin Name: Ultimate Member
Plugin URI: http://ultimatemember.com/
Description: The easiest way to create powerful online communities and beautiful user profiles with WordPress
Version: 2.1.4-beta1
Version: 2.1.4-rc.1
Author: Ultimate Member
Author URI: http://ultimatemember.com/
Text Domain: ultimate-member