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
+34 -1
View File
@@ -328,4 +328,37 @@ jQuery(document).ready(function() {
um_admin_modal_responsive();
});
});
/**
* Retrieve options from a callback function
*/
jQuery(document).on('blur',"#_custom_dropdown_options_source", function(){
var me = jQuery(this);
var _options = jQuery('textarea[id=_options]');
if( me.val() != '' ){
var um_option_callback = me.val();
jQuery.ajax({
url: ultimatemember_ajax_url,
type: 'POST',
data: {action: 'ultimatemember_populate_dropdown_options', um_option_callback: um_option_callback },
complete: function(){
},
success: function( response ){
var arr_opts = [];
for (var key in response.data ){
arr_opts.push( response.data[ key ] );
}
_options.val( arr_opts.join('\n') );
}
});
}
});
}); // end jQuery(document).ready
+28 -1
View File
@@ -48,4 +48,31 @@
if(is_array($output)){ print_r($output); }else{ echo $output; } die;
}
}
/**
* Retrieves dropdown/multi-select options from a callback function
*/
add_action('wp_ajax_nopriv_ultimatemember_populate_dropdown_options', 'ultimatemember_populate_dropdown_options');
add_action('wp_ajax_ultimatemember_populate_dropdown_options', 'ultimatemember_populate_dropdown_options');
function ultimatemember_populate_dropdown_options(){
$arr_options = array();
$um_callback_func = $_POST['um_option_callback'];
if( empty( $um_callback_func ) ){
$arr_options['status'] = 'empty';
$arr_options['function_name'] = $um_callback_func;
$arr_options['function_exists'] = function_exists( $um_callback_func );
}
$arr_options['data'] = array();
if( function_exists( $um_callback_func ) ){
$arr_options['data'] = call_user_func( $um_callback_func );
}
wp_send_json( $arr_options );
}
+11
View File
@@ -1505,6 +1505,17 @@ class UM_Admin_Metabox {
<?php
break;
case '_custom_dropdown_options_source':
?>
<p><label for="_placeholder">Options Callback<?php $this->tooltip('Add a callback source to retrieve options.'); ?></label>
<input type="text" name="_custom_dropdown_options_source" id="_custom_dropdown_options_source" value="<?php echo htmlspecialchars($this->edit_mode_value, ENT_QUOTES); ?>" />
</p>
<?php
break;
}