diff --git a/assets/js/um-scripts.js b/assets/js/um-scripts.js index 91913505..f3132f48 100644 --- a/assets/js/um-scripts.js +++ b/assets/js/um-scripts.js @@ -4,416 +4,422 @@ });*/ jQuery(document).ready(function() { - jQuery(document).on('click', '.um-dropdown a', function(e){ - - return false; - }); - - jQuery(document).on('click', '.um-dropdown a.real_url', function(e){ - - window.location = jQuery(this).attr('href'); - }); - - jQuery(document).on('click', '.um-trigger-menu-on-click', function(e){ - jQuery('.um-dropdown').hide(); - menu = jQuery(this).find('.um-dropdown'); - menu.show(); - return false; - }); - - jQuery(document).on('click', '.um-dropdown-hide', function(e){ - - UM_hide_menus(); - }); - - jQuery(document).on('click', 'a.um-manual-trigger', function(){ - var child = jQuery(this).attr('data-child'); - var parent = jQuery(this).attr('data-parent'); - jQuery(this).parents( parent ).find( child ).trigger('click'); - }); - - jQuery('.um-tip-n').tipsy({gravity: 'n', opacity: 1, live: 'a.live', offset: 3 }); - jQuery('.um-tip-w').tipsy({gravity: 'w', opacity: 1, live: 'a.live', offset: 3 }); - jQuery('.um-tip-e').tipsy({gravity: 'e', opacity: 1, live: 'a.live', offset: 3 }); - jQuery('.um-tip-s').tipsy({gravity: 's', opacity: 1, live: 'a.live', offset: 3 }); - - jQuery(document).on('change', '.um-field-area input[type=radio]', function(){ - var field = jQuery(this).parents('.um-field-area'); - var this_field = jQuery(this).parents('label'); - field.find('.um-field-radio').removeClass('active'); - field.find('.um-field-radio').find('i').removeClass().addClass('um-icon-android-radio-button-off'); - this_field.addClass('active'); - this_field.find('i').removeClass().addClass('um-icon-android-radio-button-on'); - }); - - jQuery(document).on('change', '.um-field-area input[type=checkbox]', function(){ - - var field = jQuery(this).parents('.um-field-area'); - var this_field = jQuery(this).parents('label'); - if ( this_field.hasClass('active') ) { - this_field.removeClass('active'); - this_field.find('i').removeClass().addClass('um-icon-android-checkbox-outline-blank'); - } else { - this_field.addClass('active'); - this_field.find('i').removeClass().addClass('um-icon-android-checkbox-outline'); - } - }); - - jQuery('.um-datepicker').each(function(){ - elem = jQuery(this); - - if ( elem.attr('data-disabled_weekdays') != '' ) { - var disable = JSON.parse( elem.attr('data-disabled_weekdays') ); - } else { - var disable = false; - } - - var years_n = elem.attr('data-years'); - - var minRange = elem.attr('data-date_min'); - var maxRange = elem.attr('data-date_max'); - - var minSplit = minRange.split(","); - var maxSplit = maxRange.split(","); - - var min = minSplit.length ? new Date(minSplit) : null; - var max = minSplit.length ? new Date(maxSplit) : null; - - // fix min date for safari - if(min && min.toString() == 'Invalid Date' && minSplit.length == 3) { - var minDateString = minSplit[1] + '/' + minSplit[2] + '/' + minSplit[0]; - min = new Date(Date.parse(minDateString)); - } - - // fix max date for safari - if(max && max.toString() == 'Invalid Date' && maxSplit.length == 3) { - var maxDateString = maxSplit[1] + '/' + maxSplit[2] + '/' + maxSplit[0]; - max = new Date(Date.parse(maxDateString)); - } - - elem.pickadate({ - selectYears: years_n, - min: min, - max: max, - disable: disable, - format: elem.attr('data-format'), - formatSubmit: 'yyyy/mm/dd', - hiddenName: true, - onOpen: function() { elem.blur(); }, - onClose: function() { elem.blur(); } - }); - }); - - jQuery('.um-timepicker').each(function(){ - elem = jQuery(this); - - elem.pickatime({ - format: elem.attr('data-format'), - interval: parseInt( elem.attr('data-intervals') ), - formatSubmit: 'HH:i', - hiddenName: true, - onOpen: function() { elem.blur(); }, - onClose: function() { elem.blur(); } - }); - }); - - jQuery('.um-rating').um_raty({ - half: false, - starType: 'i', - number: function() {return jQuery(this).attr('data-number');}, - score: function() {return jQuery(this).attr('data-score');}, - scoreName: function(){return jQuery(this).attr('data-key');}, - hints: false, - click: function(score, evt) { - live_field = this.id; - live_value = score; - um_conditional(); - } - }); - - jQuery('.um-rating-readonly').um_raty({ - half: false, - starType: 'i', - number: function() {return jQuery(this).attr('data-number');}, - score: function() {return jQuery(this).attr('data-score');}, - scoreName: function(){return jQuery(this).attr('data-key');}, - hints: false, - readOnly: true - }); - - jQuery(document).on('click', '.um .um-single-image-preview a.cancel', function(e){ - e.preventDefault(); - var parent = jQuery(this).parents('.um-field'); - var src = jQuery(this).parents('.um-field').find('.um-single-image-preview img').attr('src'); - parent.find('.um-single-image-preview img').attr('src',''); - parent.find('.um-single-image-preview').hide(); - parent.find('.um-btn-auto-width').html('Upload'); - parent.find('input[type=hidden]').val('empty_file'); - - jQuery.ajax({ - url: um_scripts.remove_file, - type: 'post', - data: { - src: src - } - }); - - return false; - }); - - jQuery(document).on('click', '.um .um-single-file-preview a.cancel', function(e){ - e.preventDefault(); - var parent = jQuery(this).parents('.um-field'); - var src = jQuery(this).parents('.um-field').find('.um-single-fileinfo a').attr('href'); - parent.find('.um-single-file-preview').hide(); - parent.find('.um-btn-auto-width').html('Upload'); - parent.find('input[type=hidden]').val('empty_file'); - - jQuery.ajax({ - url: um_scripts.remove_file, - type: 'post', - data: { - src: src - } - }); - - return false; - }); - - jQuery('.um-s1,.um-s2').css({'display':'block'}); - - jQuery(".um-s1").select2({ - - allowClear: true, - }); - - jQuery(".um-s2").select2({ - allowClear: false, - minimumResultsForSearch: 10 - }); - - jQuery(document).on('click', '.um-field-group-head:not(.disabled)', function(){ - var field = jQuery(this).parents('.um-field-group'); - var limit = field.data('max_entries'); - - if ( field.find('.um-field-group-body').is(':hidden')){ - field.find('.um-field-group-body').show(); - } else { - field.find('.um-field-group-body:first').clone().appendTo( field ); - } - - increase_id = 0; - field.find('.um-field-group-body').each(function(){ - increase_id++; - jQuery(this).find('input').each(function(){ - var input = jQuery(this); - input.attr('id', input.data('key') + '-' + increase_id ); - input.attr('name', input.data('key') + '-' + increase_id ); - input.parent().parent().find('label').attr('for', input.data('key') + '-' + increase_id ); - }); - }); - - if ( limit > 0 && field.find('.um-field-group-body').length == limit ) { - - jQuery(this).addClass('disabled'); - - } - }); - - jQuery(document).on('click', '.um-field-group-cancel', function(e){ - e.preventDefault(); - var field = jQuery(this).parents('.um-field-group'); - - var limit = field.data('max_entries'); - - if ( field.find('.um-field-group-body').length > 1 ) { - jQuery(this).parents('.um-field-group-body').remove(); - } else { - jQuery(this).parents('.um-field-group-body').hide(); - } - - if ( limit > 0 && field.find('.um-field-group-body').length < limit ) { - field.find('.um-field-group-head').removeClass('disabled'); - } - - return false; - }); - - jQuery(document).on('click', '.um-ajax-paginate', function(e){ - e.preventDefault(); - var parent = jQuery(this).parent(); - parent.addClass('loading'); - var args = jQuery(this).data('args'); - var hook = jQuery(this).data('hook'); - var container = jQuery(this).parents('.um').find('.um-ajax-items'); - jQuery.ajax({ - url: um_scripts.ajax_paginate, - type: 'post', - data: { - hook: hook, - args: args - }, - complete: function(){ - parent.removeClass('loading'); - }, - success: function(data){ - parent.remove(); - container.append( data ); - } - }); - return false; - }); - - jQuery(document).on('click', '.um-ajax-action', function(e){ - e.preventDefault(); - var hook = jQuery(this).data('hook'); - var user_id = jQuery(this).data('user_id'); - var arguments = jQuery(this).data('arguments'); - - if ( jQuery(this).data('js-remove') ){ - jQuery(this).parents('.'+jQuery(this).data('js-remove')).fadeOut('fast'); - } - - jQuery.ajax({ - url: um_scripts.muted_action, - type: 'post', - data: { - hook: hook, - user_id: user_id, - arguments: arguments - }, - success: function(data){ - - } - }); - return false; - }); - - jQuery(document).on('click', '#um-search-button', function() { - - jQuery(this).parents('form').submit(); - }); - - jQuery('.um-form input[class=um-button][type=submit]').removeAttr('disabled'); - - jQuery(document).one('click', '.um:not(.um-account) .um-form input[class=um-button][type=submit]:not(.um-has-recaptcha)', function() { - jQuery(this).attr('disabled','disabled'); - jQuery(this).parents('form').submit(); - - }); - - - var um_select_options_cache = {}; - - /** - * Find all select fields with parent select fields - */ - jQuery('select[data-um-parent]').each(function(){ - - var me = jQuery(this); - var parent_option = me.data('um-parent'); - var um_ajax_url = me.data('um-ajax-url'); - var um_ajax_source = me.data('um-ajax-source'); - var original_value = me.val(); - - me.attr('data-um-init-field', true ); - - jQuery(document).on('change','select[name="'+parent_option+'"]',function(){ - var parent = jQuery(this); - var form_id = parent.closest('form').find('input[type=hidden][name=form_id]').val(); - var arr_key = parent.val(); - - if( parent.val() != '' && typeof um_select_options_cache[ arr_key ] != 'object' ){ - - jQuery.ajax({ - url: um_scripts.ajax_select_options, - type: 'post', - data: { - parent_option_name: parent_option, - parent_option: parent.val(), - child_callback: um_ajax_source, - child_name: me.attr('name'), - form_id: form_id, - }, - success: function( data ){ - - if( data.status == 'success' && parent.val() != '' ){ - um_field_populate_child_options( me, data, arr_key); - } - - if( typeof data.debug !== 'undefined' ){ - console.log( data ); - } - }, - error: function( e ){ - console.log( e ); - } - }); - - - } - - if( parent.val() != '' && typeof um_select_options_cache[ arr_key ] == 'object' ){ - var data = um_select_options_cache[ arr_key ]; - um_field_populate_child_options( me, data, arr_key ); - } - - if( parent.val() == '' ){ - me.find('option[value!=""]').remove(); - me.val('').trigger('change'); - } - - }); - - jQuery('select[name="'+parent_option+'"]').trigger('change'); - - }); - - /** - * Populates child options and cache ajax response - * @param DOM me child option elem - * @param array data - * @param string key - */ - function um_field_populate_child_options( me, data, arr_key, arr_items ){ - - - var parent_option = me.data('um-parent'); - var child_name = me.attr('name'); - var parent_dom = jQuery('select[name="'+parent_option+'"]'); - me.find('option[value!=""]').remove(); - - if( ! me.hasClass('um-child-option-disabled') ){ - me.removeAttr('disabled'); - } - - var arr_items = []; - - jQuery.each( data.items, function(k,v){ - arr_items.push({id: k, text: v}); - }); - - me.select2('destroy'); - me.select2({ - data: arr_items, - allowClear: true, - minimumResultsForSearch: 10, - }); - - if( typeof data.field.default !== 'undefined' && ! me.data('um-original-value') ){ - me.val( data.field.default ).trigger('change'); - }else if( me.data('um-original-value') != '' ){ - me.val( me.data('um-original-value') ).trigger('change'); - } - - if( data.field.editable == 0 ){ - me.addClass('um-child-option-disabled'); - me.attr('disabled','disabled'); - } - - um_select_options_cache[ arr_key ] = data; - - - } + jQuery(document).on('click', '.um-dropdown a', function(e){ + + return false; + }); + + jQuery(document).on('click', '.um-dropdown a.real_url', function(e){ + + window.location = jQuery(this).attr('href'); + }); + + jQuery(document).on('click', '.um-trigger-menu-on-click', function(e){ + jQuery('.um-dropdown').hide(); + menu = jQuery(this).find('.um-dropdown'); + menu.show(); + return false; + }); + + jQuery(document).on('click', '.um-dropdown-hide', function(e){ + + UM_hide_menus(); + }); + + jQuery(document).on('click', 'a.um-manual-trigger', function(){ + var child = jQuery(this).attr('data-child'); + var parent = jQuery(this).attr('data-parent'); + jQuery(this).parents( parent ).find( child ).trigger('click'); + }); + + jQuery('.um-tip-n').tipsy({gravity: 'n', opacity: 1, live: 'a.live', offset: 3 }); + jQuery('.um-tip-w').tipsy({gravity: 'w', opacity: 1, live: 'a.live', offset: 3 }); + jQuery('.um-tip-e').tipsy({gravity: 'e', opacity: 1, live: 'a.live', offset: 3 }); + jQuery('.um-tip-s').tipsy({gravity: 's', opacity: 1, live: 'a.live', offset: 3 }); + + jQuery(document).on('change', '.um-field-area input[type=radio]', function(){ + var field = jQuery(this).parents('.um-field-area'); + var this_field = jQuery(this).parents('label'); + field.find('.um-field-radio').removeClass('active'); + field.find('.um-field-radio').find('i').removeClass().addClass('um-icon-android-radio-button-off'); + this_field.addClass('active'); + this_field.find('i').removeClass().addClass('um-icon-android-radio-button-on'); + }); + + jQuery(document).on('change', '.um-field-area input[type=checkbox]', function(){ + + var field = jQuery(this).parents('.um-field-area'); + var this_field = jQuery(this).parents('label'); + if ( this_field.hasClass('active') ) { + this_field.removeClass('active'); + this_field.find('i').removeClass().addClass('um-icon-android-checkbox-outline-blank'); + } else { + this_field.addClass('active'); + this_field.find('i').removeClass().addClass('um-icon-android-checkbox-outline'); + } + }); + + jQuery('.um-datepicker').each(function(){ + elem = jQuery(this); + + if ( elem.attr('data-disabled_weekdays') != '' ) { + var disable = JSON.parse( elem.attr('data-disabled_weekdays') ); + } else { + var disable = false; + } + + var years_n = elem.attr('data-years'); + + var minRange = elem.attr('data-date_min'); + var maxRange = elem.attr('data-date_max'); + + var minSplit = minRange.split(","); + var maxSplit = maxRange.split(","); + + var min = minSplit.length ? new Date(minSplit) : null; + var max = minSplit.length ? new Date(maxSplit) : null; + + // fix min date for safari + if(min && min.toString() == 'Invalid Date' && minSplit.length == 3) { + var minDateString = minSplit[1] + '/' + minSplit[2] + '/' + minSplit[0]; + min = new Date(Date.parse(minDateString)); + } + + // fix max date for safari + if(max && max.toString() == 'Invalid Date' && maxSplit.length == 3) { + var maxDateString = maxSplit[1] + '/' + maxSplit[2] + '/' + maxSplit[0]; + max = new Date(Date.parse(maxDateString)); + } + + elem.pickadate({ + selectYears: years_n, + min: min, + max: max, + disable: disable, + format: elem.attr('data-format'), + formatSubmit: 'yyyy/mm/dd', + hiddenName: true, + onOpen: function() { elem.blur(); }, + onClose: function() { elem.blur(); } + }); + }); + + jQuery('.um-timepicker').each(function(){ + elem = jQuery(this); + + elem.pickatime({ + format: elem.attr('data-format'), + interval: parseInt( elem.attr('data-intervals') ), + formatSubmit: 'HH:i', + hiddenName: true, + onOpen: function() { elem.blur(); }, + onClose: function() { elem.blur(); } + }); + }); + + jQuery('.um-rating').um_raty({ + half: false, + starType: 'i', + number: function() {return jQuery(this).attr('data-number');}, + score: function() {return jQuery(this).attr('data-score');}, + scoreName: function(){return jQuery(this).attr('data-key');}, + hints: false, + click: function(score, evt) { + live_field = this.id; + live_value = score; + um_conditional(); + } + }); + + jQuery('.um-rating-readonly').um_raty({ + half: false, + starType: 'i', + number: function() {return jQuery(this).attr('data-number');}, + score: function() {return jQuery(this).attr('data-score');}, + scoreName: function(){return jQuery(this).attr('data-key');}, + hints: false, + readOnly: true + }); + + jQuery(document).on('click', '.um .um-single-image-preview a.cancel', function(e){ + e.preventDefault(); + var parent = jQuery(this).parents('.um-field'); + var src = jQuery(this).parents('.um-field').find('.um-single-image-preview img').attr('src'); + parent.find('.um-single-image-preview img').attr('src',''); + parent.find('.um-single-image-preview').hide(); + parent.find('.um-btn-auto-width').html('Upload'); + parent.find('input[type=hidden]').val('empty_file'); + + jQuery.ajax({ + url: um_scripts.remove_file, + type: 'post', + data: { + src: src + } + }); + + return false; + }); + + jQuery(document).on('click', '.um .um-single-file-preview a.cancel', function(e){ + e.preventDefault(); + var parent = jQuery(this).parents('.um-field'); + var src = jQuery(this).parents('.um-field').find('.um-single-fileinfo a').attr('href'); + parent.find('.um-single-file-preview').hide(); + parent.find('.um-btn-auto-width').html('Upload'); + parent.find('input[type=hidden]').val('empty_file'); + + jQuery.ajax({ + url: um_scripts.remove_file, + type: 'post', + data: { + src: src + } + }); + + return false; + }); + + jQuery('.um-s1,.um-s2').css({'display':'block'}); + + jQuery(".um-s1").select2({ + + allowClear: true, + }); + + jQuery(".um-s2").select2({ + allowClear: false, + minimumResultsForSearch: 10 + }); + + jQuery(document).on('click', '.um-field-group-head:not(.disabled)', function(){ + var field = jQuery(this).parents('.um-field-group'); + var limit = field.data('max_entries'); + + if ( field.find('.um-field-group-body').is(':hidden')){ + field.find('.um-field-group-body').show(); + } else { + field.find('.um-field-group-body:first').clone().appendTo( field ); + } + + increase_id = 0; + field.find('.um-field-group-body').each(function(){ + increase_id++; + jQuery(this).find('input').each(function(){ + var input = jQuery(this); + input.attr('id', input.data('key') + '-' + increase_id ); + input.attr('name', input.data('key') + '-' + increase_id ); + input.parent().parent().find('label').attr('for', input.data('key') + '-' + increase_id ); + }); + }); + + if ( limit > 0 && field.find('.um-field-group-body').length == limit ) { + + jQuery(this).addClass('disabled'); + + } + }); + + jQuery(document).on('click', '.um-field-group-cancel', function(e){ + e.preventDefault(); + var field = jQuery(this).parents('.um-field-group'); + + var limit = field.data('max_entries'); + + if ( field.find('.um-field-group-body').length > 1 ) { + jQuery(this).parents('.um-field-group-body').remove(); + } else { + jQuery(this).parents('.um-field-group-body').hide(); + } + + if ( limit > 0 && field.find('.um-field-group-body').length < limit ) { + field.find('.um-field-group-head').removeClass('disabled'); + } + + return false; + }); + + jQuery(document).on('click', '.um-ajax-paginate', function(e){ + e.preventDefault(); + var parent = jQuery(this).parent(); + parent.addClass('loading'); + var args = jQuery(this).data('args'); + var hook = jQuery(this).data('hook'); + var container = jQuery(this).parents('.um').find('.um-ajax-items'); + jQuery.ajax({ + url: um_scripts.ajax_paginate, + type: 'post', + data: { + hook: hook, + args: args + }, + complete: function(){ + parent.removeClass('loading'); + }, + success: function(data){ + parent.remove(); + container.append( data ); + } + }); + return false; + }); + + jQuery(document).on('click', '.um-ajax-action', function(e){ + e.preventDefault(); + var hook = jQuery(this).data('hook'); + var user_id = jQuery(this).data('user_id'); + var arguments = jQuery(this).data('arguments'); + + if ( jQuery(this).data('js-remove') ){ + jQuery(this).parents('.'+jQuery(this).data('js-remove')).fadeOut('fast'); + } + + jQuery.ajax({ + url: um_scripts.muted_action, + type: 'post', + data: { + hook: hook, + user_id: user_id, + arguments: arguments + }, + success: function(data){ + + } + }); + return false; + }); + + jQuery(document).on('click', '#um-search-button', function() { + + jQuery(this).parents('form').submit(); + }); + + jQuery('.um-form input[class=um-button][type=submit]').removeAttr('disabled'); + + jQuery(document).one('click', '.um:not(.um-account) .um-form input[class=um-button][type=submit]:not(.um-has-recaptcha)', function() { + jQuery(this).attr('disabled','disabled'); + jQuery(this).parents('form').submit(); + + }); + + + var um_select_options_cache = {}; + + /** + * Find all select fields with parent select fields + */ + jQuery('select[data-um-parent]').each(function(){ + + var me = jQuery(this); + var parent_option = me.data('um-parent'); + var um_ajax_url = me.data('um-ajax-url'); + var um_ajax_source = me.data('um-ajax-source'); + var original_value = me.val(); + + me.attr('data-um-init-field', true ); + + jQuery(document).on('change','select[name="'+parent_option+'"]',function(){ + var parent = jQuery(this); + var form_id = parent.closest('form').find('input[type=hidden][name=form_id]').val(); + var arr_key = parent.val(); + + if( parent.val() != '' && typeof um_select_options_cache[ arr_key ] != 'object' ){ + + jQuery.ajax({ + url: um_scripts.ajax_select_options, + type: 'post', + data: { + parent_option_name: parent_option, + parent_option: parent.val(), + child_callback: um_ajax_source, + child_name: me.attr('name'), + members_directory: me.attr('data-mebers-directory'), + form_id: form_id, + }, + success: function( data ){ + if( data.status == 'success' && parent.val() != '' ){ + um_field_populate_child_options( me, data, arr_key); + } + + if( typeof data.debug !== 'undefined' ){ + console.log( data ); + } + }, + error: function( e ){ + console.log( e ); + } + }); + + + } + + if( parent.val() != '' && typeof um_select_options_cache[ arr_key ] == 'object' ) { + var data = um_select_options_cache[ arr_key ]; + um_field_populate_child_options( me, data, arr_key ); + } + + if( parent.val() == '' ){ + me.find('option[value!=""]').remove(); + me.val('').trigger('change'); + } + + }); + + jQuery('select[name="'+parent_option+'"]').trigger('change'); + + }); + + /** + * Populates child options and cache ajax response + * @param DOM me child option elem + * @param array data + * @param string key + */ + function um_field_populate_child_options( me, data, arr_key, arr_items ){ + + + var parent_option = me.data('um-parent'); + var child_name = me.attr('name'); + var parent_dom = jQuery('select[name="'+parent_option+'"]'); + me.find('option[value!=""]').remove(); + + if( ! me.hasClass('um-child-option-disabled') ){ + me.removeAttr('disabled'); + } + + var arr_items = [], + search_get = ''; + + if ( data.post.members_directory === 'yes' ) { + var urlParams = new URLSearchParams(window.location.search); + search_get = urlParams.get(data.post.child_name); + } + jQuery.each( data.items, function(k,v){ + arr_items.push({id: k, text: v, selected: (v === search_get) }); + }); + + me.select2('destroy'); + me.select2({ + data: arr_items, + allowClear: true, + minimumResultsForSearch: 10 + }); + + if ( data.post.members_directory !== 'yes' ) { + if( typeof data.field.default !== 'undefined' && ! me.data('um-original-value') ){ + me.val( data.field.default ).trigger('change'); + }else if( me.data('um-original-value') != '' ){ + me.val( me.data('um-original-value') ).trigger('change'); + } + + if( data.field.editable == 0 ){ + me.addClass('um-child-option-disabled'); + me.attr('disabled','disabled'); + } + } + um_select_options_cache[ arr_key ] = data; + + + } }); diff --git a/includes/core/class-form.php b/includes/core/class-form.php index 39f6887a..ccebba66 100644 --- a/includes/core/class-form.php +++ b/includes/core/class-form.php @@ -87,6 +87,7 @@ if ( ! class_exists( 'um\core\Form' ) ) { */ function ajax_select_options() { + $arr_options = array(); $arr_options['status'] = 'success'; $arr_options['post'] = $_POST; @@ -96,57 +97,66 @@ if ( ! class_exists( 'um\core\Form' ) ) { $form_fields = UM()->fields()->get_fields(); $arr_options['fields'] = $form_fields; - /** - * UM hook - * - * @type filter - * @title um_ajax_select_options__debug_mode - * @description Activate debug mode for AJAX select options - * @input_vars - * [{"var":"$debug_mode","type":"bool","desc":"Enable Debug mode"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $debug = apply_filters('um_ajax_select_options__debug_mode', false ); - if( $debug ){ - $arr_options['debug'] = array( - $_POST, - $form_fields, - ); - } - - if( isset( $_POST['child_callback'] ) && ! empty( $_POST['child_callback'] ) && isset( $form_fields[ $_POST['child_name'] ] ) ){ - + if ( $arr_options['post']['members_directory'] == 'yes' ) { $ajax_source_func = $_POST['child_callback']; - - // If the requested callback function is added in the form or added in the field option, execute it with call_user_func. - if( isset( $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] ) && - ! empty( $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] ) && - $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] == $ajax_source_func ){ - - $arr_options['field'] = $form_fields[ $_POST['child_name'] ]; - if( function_exists( $ajax_source_func ) ){ - $arr_options['items'] = call_user_func( $ajax_source_func, $arr_options['field']['parent_dropdown_relationship'] ); - } - - }else{ - $arr_options['status'] = 'error'; - $arr_options['message'] = __( 'This is not possible for security reasons.','ultimate-member'); + if( function_exists( $ajax_source_func ) ){ + $arr_options['items'] = call_user_func( $ajax_source_func, $arr_options['field']['parent_dropdown_relationship'] ); + wp_send_json( $arr_options ); + } + } else { + /** + * UM hook + * + * @type filter + * @title um_ajax_select_options__debug_mode + * @description Activate debug mode for AJAX select options + * @input_vars + * [{"var":"$debug_mode","type":"bool","desc":"Enable Debug mode"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $debug = apply_filters('um_ajax_select_options__debug_mode', false ); + if( $debug ){ + $arr_options['debug'] = array( + $_POST, + $form_fields, + ); } - } + if( isset( $_POST['child_callback'] ) && ! empty( $_POST['child_callback'] ) && isset( $form_fields[ $_POST['child_name'] ] ) ){ - wp_send_json( $arr_options ); + $ajax_source_func = $_POST['child_callback']; + + // If the requested callback function is added in the form or added in the field option, execute it with call_user_func. + if ( isset( $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] ) && + ! empty( $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] ) && + $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] == $ajax_source_func ) { + + $arr_options['field'] = $form_fields[ $_POST['child_name'] ]; + + if( function_exists( $ajax_source_func ) ){ + $arr_options['items'] = call_user_func( $ajax_source_func, $arr_options['field']['parent_dropdown_relationship'] ); + } + + } else { + $arr_options['status'] = 'error'; + $arr_options['message'] = __( 'This is not possible for security reasons.','ultimate-member'); + } + + } + + wp_send_json( $arr_options ); + } } @@ -312,7 +322,7 @@ if ( ! class_exists( 'um\core\Form' ) ) { $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) ); if ( ! empty( $role ) && - ( ! in_array( $role , $custom_field_roles ) || in_array( $role , $exclude_roles ) ) ) { + ( ! in_array( $role , $custom_field_roles ) || in_array( $role , $exclude_roles ) ) ) { wp_die( __( 'This is not possible for security reasons.','ultimate-member') ); } diff --git a/includes/core/class-members.php b/includes/core/class-members.php index 15d83c16..3c3e0f7a 100644 --- a/includes/core/class-members.php +++ b/includes/core/class-members.php @@ -88,14 +88,14 @@ if ( ! class_exists( 'um\core\Members' ) ) { return $string; } - /** + /** * Prepare filter data * * @param $filter - * @return array + * @return array */ function prepare_filter( $filter ) { - $fields = UM()->builtin()->all_user_fields; + $fields = UM()->builtin()->all_user_fields; if ( isset( $fields[ $filter ] ) ) { $attrs = $fields[ $filter ]; @@ -223,7 +223,7 @@ if ( ! class_exists( 'um\core\Members' ) ) { } return compact( 'type', 'attrs' ); - } + } /** * Show filter @@ -231,11 +231,11 @@ if ( ! class_exists( 'um\core\Members' ) ) { * @param $filter */ function show_filter( $filter ) { - /** - * @var $type - * @var $attrs - */ - extract( $this->prepare_filter( $filter ) ); + /** + * @var $type + * @var $attrs + */ + extract( $this->prepare_filter( $filter ) ); switch ( $type ) { @@ -243,9 +243,9 @@ if ( ! class_exists( 'um\core\Members' ) ) { ?> - - + $testfilter ){ if ($testfilter && !in_array( $testfilter, (array)$search_filters ) ) { @@ -49,48 +49,47 @@ function um_members_directory_search( $args ) { $count = count( $search_filters ); ?> -