form_id = $_POST['form_id'];
$this->show_builder();
$output = ob_get_contents();
ob_end_clean();
if(is_array($output)){ print_r($output); }else{ echo $output; } die;
}
/***
*** @sort array function
***/
function array_sort_by_column( $arr, $col, $dir = SORT_ASC ) {
$sort_col = array();
foreach ( $arr as $key => $row ) {
if ( ! empty( $row[$col] ) )
$sort_col[$key] = $row[$col];
}
if ( ! empty( $sort_col ) )
array_multisort( $sort_col, $dir, $arr );
return $arr;
}
/***
*** @get fields in row
***/
function get_fields_by_row( $row_id ) {
if( empty( $this->global_fields) || ! is_array( $this->global_fields ) ){
$this->global_fields = array();
}
foreach( $this->global_fields as $key => $array ) {
if ( !isset( $array['in_row'] ) || ( isset( $array['in_row'] ) && $array['in_row'] == $row_id ) ) {
$results[$key] = $array;
unset( $this->global_fields[$key] );
}
}
return ( isset ( $results ) ) ? $results : '';
}
/***
*** @get fields by sub row
***/
function get_fields_in_subrow( $row_fields, $subrow_id ) {
if ( !is_array( $row_fields ) ) return '';
foreach( $row_fields as $key => $array ) {
if ( !isset( $array['in_sub_row'] ) || ( isset( $array['in_sub_row'] ) && $array['in_sub_row'] == $subrow_id ) ) {
$results[$key] = $array;
unset( $this->global_fields[$key] );
}
}
return ( isset ( $results ) ) ? $results : '';
}
/***
*** @Display the builder
***/
function show_builder() {
$fields = UM()->query()->get_attr( 'custom_fields', $this->form_id );
if ( !isset( $fields ) || empty( $fields ) ) { ?>
global_fields = array();
}else{
$this->global_fields = $fields;
}
foreach( $this->global_fields as $key => $array ) {
if ( $array['type'] == 'row' ) {
$rows[$key] = $array;
unset( $this->global_fields[ $key ] ); // not needed now
}
}
if ( !isset( $rows ) ){
$rows = array( '_um_row_1' => array(
'type' => 'row',
'id' => '_um_row_1',
'sub_rows' => 1,
'cols' => 1
)
);
}
foreach ( $rows as $row_id => $array ) {
?>
get_fields_by_row( $row_id );
$sub_rows = ( isset( $array['sub_rows'] ) ) ? $array['sub_rows'] : 1;
for( $c = 0; $c < $sub_rows; $c++ ) {
$subrow_fields = $this->get_fields_in_subrow( $row_fields, $c );
?>
';
}
?>
array_sort_by_column( $subrow_fields, 'position');
foreach( $subrow_fields as $key => $keyarray ) {
extract( $keyarray );
?>
builtin()->core_fields[$type]['name'] ) ? UM()->builtin()->core_fields[$type]['name'] : ''; ?>
$_POST['_type'],
'form_id' => $_POST['post_id'],
'args' => UM()->builtin()->get_core_field_attrs( $_POST['_type'] ),
'post' => $_POST
);
/**
* UM hook
*
* @type filter
* @title um_admin_pre_save_fields_hook
* @description Filter field data before save
* @input_vars
* [{"var":"$array","type":"array","desc":"Save Field data"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_admin_pre_save_fields_hook', 'function_name', 10, 1 );
* @example
*
*/
$array = apply_filters( "um_admin_pre_save_fields_hook", $array );
/**
* UM hook
*
* @type filter
* @title um_admin_field_update_error_handling
* @description Change error string on save field
* @input_vars
* [{"var":"$error","type":"string","desc":"Error String"},
* {"var":"$array","type":"array","desc":"Save Field data"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_admin_field_update_error_handling', 'function_name', 10, 2 );
* @example
*
*/
$output['error'] = apply_filters( 'um_admin_field_update_error_handling', $output['error'], $array );
extract( $array['post'] );
if ( empty( $output['error'] ) ){
$save = array();
$save[ $_metakey ] = null;
foreach( $array['post'] as $key => $val){
if ( substr( $key, 0, 1) === '_' && $val != '' ) { // field attribute
$new_key = ltrim ($key,'_');
if ( $new_key == 'options' ) {
//$save[ $_metakey ][$new_key] = explode(PHP_EOL, $val);
$save[ $_metakey ][$new_key] = preg_split('/[\r\n]+/', $val, -1, PREG_SPLIT_NO_EMPTY);
} else {
$save[ $_metakey ][$new_key] = $val;
}
} else if ( strstr( $key, 'um_editor' ) ) {
$save[ $_metakey ]['content'] = $val;
}
}
$field_ID = $_metakey;
$field_args = $save[ $_metakey ];
/**
* UM hook
*
* @type filter
* @title um_admin_pre_save_field_to_form
* @description Change field options before save to form
* @input_vars
* [{"var":"$field_args","type":"array","desc":"Field Options"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_admin_pre_save_field_to_form', 'function_name', 10, 1 );
* @example
*
*/
$field_args = apply_filters("um_admin_pre_save_field_to_form", $field_args );
UM()->fields()->update_field( $field_ID, $field_args, $post_id );
/**
* UM hook
*
* @type filter
* @title um_admin_pre_save_field_to_db
* @description Change field options before save to DB
* @input_vars
* [{"var":"$field_args","type":"array","desc":"Field Options"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_admin_pre_save_field_to_db', 'function_name', 10, 1 );
* @example
*
*/
$field_args = apply_filters("um_admin_pre_save_field_to_db", $field_args );
if ( ! isset( $array['args']['form_only'] ) ) {
if ( ! isset( UM()->builtin()->predefined_fields[ $field_ID ] ) ) {
UM()->fields()->globally_update_field( $field_ID, $field_args );
}
}
}
$output = json_encode( $output );
if ( is_array( $output ) ) {
print_r( $output );
} else {
echo $output;
}
die;
}
function dynamic_modal_content() {
$metabox = UM()->metabox();
if ( !is_user_logged_in() || !current_user_can('manage_options') ) die( __('Please login as administrator','ultimate-member') );
/**
* @var $act_id
*/
extract( $_POST );
switch ( $act_id ) {
default:
ob_start();
/**
* UM hook
*
* @type action
* @title um_admin_ajax_modal_content__hook
* @description Integration hook on ajax popup admin builder modal content
* @input_vars
* [{"var":"$act_id","type":"string","desc":"Ajax Action"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_admin_ajax_modal_content__hook', 'function_name', 10, 1 );
* @example
*
*/
do_action( 'um_admin_ajax_modal_content__hook', $act_id );
/**
* UM hook
*
* @type action
* @title um_admin_ajax_modal_content__hook_{$act_id}
* @description Integration hook on ajax popup admin builder modal content
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_admin_ajax_modal_content__hook_{$act_id}', 'function_name', 10 );
* @example
*
*/
do_action( "um_admin_ajax_modal_content__hook_{$act_id}" );
$output = ob_get_contents();
ob_end_clean();
break;
case 'um_admin_fonticon_selector':
ob_start();
?>
fonticons()->all as $icon ) { ?>
query()->get_attr( 'custom_fields', $arg2 );
$form_fields = array_values( array_filter( array_keys( $form_fields ) ) );
//$form_fields = array_keys( $form_fields );
?>
builtin()->core_fields ) {
foreach ( UM()->builtin()->core_fields as $field_type => $array ) {
if ( isset( $array['in_fields'] ) && $array['in_fields'] == false ) { } else {
?>
builtin()->get_core_field_attrs( $arg1 );
$form_fields = UM()->query()->get_attr( 'custom_fields', $arg2 );
$metabox->set_field_type = $arg1;
$metabox->in_edit = true;
$metabox->edit_array = $form_fields[ $arg3 ];
if ( !isset( $metabox->edit_array['metakey'] ) ){
$metabox->edit_array['metakey'] = $metabox->edit_array['id'];
}
if ( !isset( $metabox->edit_array['position'] ) ){
$metabox->edit_array['position'] = $metabox->edit_array['id'];
}
extract( $args );
if ( !isset( $col1 ) ) {
echo ''. __('This field type is not setup correcty.', 'ultimate-member') . '
';
} else {
?>
edit_array['in_group'] ) ) { ?>
edit_array['content']; ?>
modal_header(); ?>
field_input ( $opt, null, $metabox->edit_array ); } ?>
field_input ( $opt, null, $metabox->edit_array ); } ?>
field_input ( $opt, null, $metabox->edit_array ); } ?>
field_input ( $opt, null, $metabox->edit_array ); } ?>
modal_footer( $arg2, $args, $metabox ); ?>
builtin()->get_core_field_attrs( $arg1 );
$metabox->set_field_type = $arg1;
extract( $args );
if ( !isset( $col1 ) ) {
echo ''. __('This field type is not setup correcty.', 'ultimate-member') . '
';
} else {
?>
modal_header(); ?>
field_input ( $opt ); } ?>
field_input ( $opt ); } ?>
field_input ( $opt ); } ?>
field_input ( $opt ); } ?>
modal_footer( $arg2, $args, $metabox ); ?>
query()->get_attr('mode', $arg1 );
if ( $mode == 'profile' ) {
UM()->fields()->editing = true;
}
$output = do_shortcode('[ultimatemember form_id='.$arg1.']');
break;
case 'um_admin_review_registration':
//$user_id = $arg1;
um_fetch_user( $arg1 );
UM()->user()->preview = true;
$output = um_user_submitted_registration( true );
um_reset_user();
break;
}
if ( is_array( $output ) ) {
print_r( $output );
} else {
echo $output;
}
die;
}
/**
*
*/
function modal_header() {
/**
* UM hook
*
* @type action
* @title um_admin_field_modal_header
* @description Modal Window Header
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_admin_field_modal_header', 'function_name', 10 );
* @example
*
*/
do_action( 'um_admin_field_modal_header' );
}
/**
* @param $arg2
* @param $args
* @param $metabox
*/
function modal_footer( $arg2, $args, $metabox ) {
/**
* UM hook
*
* @type action
* @title um_admin_field_modal_footer
* @description Modal Window Footer
* @input_vars
* [{"var":"$arg2","type":"string","desc":"Ajax Action"},
* {"var":"$args","type":"array","desc":"Modal window arguments"},
* {"var":"$in_edit","type":"bool","desc":"Is edit mode?"},
* {"var":"$edit_array","type":"array","desc":"Edit Array"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_admin_field_modal_footer', 'function_name', 10, 4 );
* @example
*
*/
do_action( 'um_admin_field_modal_footer', $arg2, $args, $metabox->in_edit, ( isset( $metabox->edit_array ) ) ? $metabox->edit_array : '' );
}
/**
* Retrieves dropdown/multi-select options from a callback function
*/
function populate_dropdown_options(){
$arr_options = array();
if( ! current_user_can('manage_options') ){
wp_die( __( 'This is not possible for security reasons.','ultimate-member') );
}
$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 );
}
}
}