diff --git a/assets/js/um-conditional.js b/assets/js/um-conditional.js index 8811a934..8fa153d1 100644 --- a/assets/js/um-conditional.js +++ b/assets/js/um-conditional.js @@ -62,7 +62,7 @@ jQuery(document).ready( function (){ var default_value = ''; var type = um_get_field_type($dom); - switch (type) { + switch ( type ) { case 'text': case 'number': @@ -290,6 +290,12 @@ jQuery(document).ready( function (){ } else { $owners[condition.owner][index] = false; } + } else if ( 'checkbox' == um_get_field_type( $dom.parents('.um-field[data-key]') ) ) { + if ( live_field_value && live_field_value.indexOf( condition.value ) >= 0 ) { + $owners[condition.owner][index] = true; + } else { + $owners[condition.owner][index] = false; + } } else { if ( live_field_value && live_field_value.indexOf( condition.value ) >= 0 && um_in_array( live_field_value, $owners_values[ condition.owner ] ) ) { $owners[condition.owner][index] = true; @@ -444,6 +450,22 @@ jQuery(document).ready( function (){ me.trigger( 'change' ); $dom.addClass( 'um-field-has-changed' ); } + + /* + maybe future fix + if ( me ) { + if ( type == 'radio' || type == 'checkbox' ) { + me.each( function() { + if ( jQuery(this).is(':checked') ) { + jQuery(this).trigger('change'); + } + }); + } else { + me.trigger( 'change' ); + } + + $dom.addClass( 'um-field-has-changed' ); + }*/ } } diff --git a/includes/admin/core/class-admin-builder.php b/includes/admin/core/class-admin-builder.php index 693b70aa..6183f74c 100644 --- a/includes/admin/core/class-admin-builder.php +++ b/includes/admin/core/class-admin-builder.php @@ -5,855 +5,901 @@ namespace um\admin\core; if ( ! defined( 'ABSPATH' ) ) exit; if ( ! class_exists( 'Admin_Builder' ) ) { - class Admin_Builder { - var $form_id; - function __construct() { + /** + * Class Admin_Builder + * @package um\admin\core + */ + class Admin_Builder { - } + /** + * @var + */ + var $form_id; - /*** - *** @update the builder area - ***/ - function update_builder() { - if ( !is_user_logged_in() || !current_user_can('manage_options') ) die('Please login as administrator'); + /** + * Admin_Builder constructor. + */ + function __construct() { - extract($_POST); + } - ob_start(); - $this->form_id = $_POST['form_id']; + /** + * Update the builder area + */ + function update_builder() { - $this->show_builder(); + if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) { + die( 'Please login as administrator' ); + } - $output = ob_get_contents(); - ob_end_clean(); + extract( $_POST ); - if(is_array($output)){ print_r($output); }else{ echo $output; } die; + ob_start(); - } + $this->form_id = $_POST['form_id']; + $this->show_builder(); - /*** - *** @sort array function - ***/ - function array_sort_by_column( $arr, $col, $dir = SORT_ASC ) { - $sort_col = array(); + $output = ob_get_contents(); + ob_end_clean(); - foreach ( $arr as $key => $row ) { - if ( ! empty( $row[$col] ) ) - $sort_col[$key] = $row[$col]; - } + if(is_array($output)){ print_r($output); }else{ echo $output; } die; + } - if ( ! empty( $sort_col ) ) - array_multisort( $sort_col, $dir, $arr ); - return $arr; - } + /** + * Sort array function + * + * @param array $arr + * @param string $col + * @param int $dir + * + * @return array + */ + 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 ]; + } + } - /*** - *** @get fields in row - ***/ - function get_fields_by_row( $row_id ) { + if ( ! empty( $sort_col ) ) { + array_multisort( $sort_col, $dir, $arr ); + } - if( empty( $this->global_fields) || ! is_array( $this->global_fields ) ){ - $this->global_fields = array(); - } + return $arr; + } - 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 in row + * + * @param $row_id + * + * @return string + */ + function get_fields_by_row( $row_id ) { - /*** - *** @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 : ''; - } + 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 ] ); + } + } - /*** - *** @Display the builder - ***/ - function show_builder() { + return ( isset ( $results ) ) ? $results : ''; + } - $fields = UM()->query()->get_attr( 'custom_fields', $this->form_id ); - if ( !isset( $fields ) || empty( $fields ) ) { ?> + /** + * Get fields by sub row + * + * @param $row_fields + * @param $subrow_id + * + * @return string + */ + 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 ) ) { ?> -
+
-
+ +
+ + + +
-
+
+
-
-
+ +
+ + + +
-
+ +
+ +
- +
- } else { +
- if( empty( $fields) || ! is_array( $fields ) ){ - $this->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 ) { + + } else { -
+ if( empty( $fields) || ! is_array( $fields ) ){ + $this->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 + } -
+ } - array( + 'type' => 'row', + 'id' => '_um_row_1', + 'sub_rows' => 1, + 'cols' => 1 + ) + ); + } - $row_fields = $this->get_fields_by_row( $row_id ); + foreach ( $rows as $row_id => $array ) { - $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 ); +
- ?> + +
+ + + + + + +
-
+
- -
+ get_fields_by_row( $row_id ); - if ( !isset( $array['cols'] ) ){ - $col_num = 1; - } else { + $sub_rows = ( isset( $array['sub_rows'] ) ) ? $array['sub_rows'] : 1; + for( $c = 0; $c < $sub_rows; $c++ ) { - $col_split = explode(':', $array['cols'] ); - $col_num = $col_split[$c]; + $subrow_fields = $this->get_fields_in_subrow( $row_fields, $c ); - } + ?> - for ( $i = 1; $i <= 3; $i++ ) { - echo ''; - } +
- ?> + +
-
+ -
- - 0 ) { ?> -
+ if ( !isset( $array['cols'] ) ){ + $col_num = 1; + } else { - -
+ $col_split = explode(':', $array['cols'] ); + $col_num = $col_split[$c]; - '; + } - $subrow_fields = $this->array_sort_by_column( $subrow_fields, 'position'); + ?> - foreach( $subrow_fields as $key => $keyarray ) { - extract( $keyarray ); +
- ?> + +
+ + 0 ) { ?> +
-
+ +
-
- - - - -
- builtin()->core_fields[$type]['name'] ) ? UM()->builtin()->core_fields[$type]['name'] : ''; ?> -
-
+ " data-arg2="form_id; ?>" data-arg3=""> + if ( is_array( $subrow_fields ) ) { - + $subrow_fields = $this->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'] : ''; ?> +
+
-
+ - -
+ -
- + -
+ + - " data-arg2="form_id; ?>"> - } // end foreach + - } // end if +
- ?> + +
-
+
+ -
+
-
+ + } // end foreach - + } // end if -
+ ?> -
+
-
- } // rows loop +
- } // if fields exist +
- } + +
- function update_field() { - if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) - die( __('Please login as administrator','ultimate-member') ); +
- $output['error'] = null; + $_POST['_type'], - 'form_id' => $_POST['post_id'], - 'args' => UM()->builtin()->get_core_field_attrs( $_POST['_type'] ), - 'post' => $_POST - ); + } // rows loop - /** - * 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}" ); + } // if fields exist - $output = ob_get_contents(); - ob_end_clean(); + } - break; - case 'um_admin_fonticon_selector': + /** + * + */ + function update_field() { + if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) + die( __('Please login as administrator','ultimate-member') ); - ob_start(); + $output['error'] = null; - ?> + $array = array( + 'field_type' => $_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 + * @var $arg1 + * @var $arg2 + * @var $arg3 + */ + 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 ) { ?> - - -
+
+ +
- + fonticons()->all as $icon ) { ?> + + +
- $output = ob_get_contents(); - ob_end_clean(); - break; + query()->get_attr( 'custom_fields', $arg2 ); - $form_fields = array_values( array_filter( array_keys( $form_fields ) ) ); - //$form_fields = array_keys( $form_fields ); - ?> + ob_start(); + $form_fields = UM()->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 ) { + builtin()->core_fields ) { + foreach ( UM()->builtin()->core_fields as $field_type => $array ) { - if ( isset( $array['in_fields'] ) && $array['in_fields'] == false ) { } else { - ?> + if ( isset( $array['in_fields'] ) && $array['in_fields'] == false ) { } else { + ?> - + - + -
+
-

-
+

+
- builtin()->predefined_fields ) { - foreach ( UM()->builtin()->predefined_fields as $field_key => $array ) { + builtin()->predefined_fields ) { + foreach ( UM()->builtin()->predefined_fields as $field_key => $array ) { - if ( !isset( $array['account_only'] ) && !isset( $array['private_use'] ) ) {?> + if ( !isset( $array['account_only'] ) && !isset( $array['private_use'] ) ) {?> - data-silent_action="um_admin_add_field_from_predefined" data-arg1="" data-arg2=""> + data-silent_action="um_admin_add_field_from_predefined" data-arg1="" data-arg2=""> - ' . __('None','ultimate-member') . '

'; } ?> + ' . __('None','ultimate-member') . '

'; } ?> -
+
-

-
+

+
- builtin()->custom_fields ) { - foreach ( UM()->builtin()->custom_fields as $field_key => $array ) { + builtin()->custom_fields ) { + foreach ( UM()->builtin()->custom_fields as $field_key => $array ) { - ?> + ?> - data-silent_action="um_admin_add_field_from_list" data-arg1="" data-arg2=""> () + data-silent_action="um_admin_add_field_from_list" data-arg1="" data-arg2=""> () - ' . __('You did not create any custom fields', 'ultimate-member') . '

'; } ?> + ' . __('You did not create any custom fields', 'ultimate-member') . '

'; } ?> -
+
- builtin()->get_core_field_attrs( $arg1 ); - $args = UM()->builtin()->get_core_field_attrs( $arg1 ); + $form_fields = UM()->query()->get_attr( 'custom_fields', $arg2 ); - $form_fields = UM()->query()->get_attr( 'custom_fields', $arg2 ); + $metabox->set_field_type = $arg1; + $metabox->in_edit = true; + $metabox->edit_array = $form_fields[ $arg3 ]; - $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['metakey'] ) ){ - $metabox->edit_array['metakey'] = $metabox->edit_array['id']; - } + if ( !isset( $metabox->edit_array['position'] ) ){ + $metabox->edit_array['position'] = $metabox->edit_array['id']; + } - if ( !isset( $metabox->edit_array['position'] ) ){ - $metabox->edit_array['position'] = $metabox->edit_array['id']; - } + extract( $args ); - extract( $args ); + if ( !isset( $col1 ) ) { - if ( !isset( $col1 ) ) { + echo '

'. __('This field type is not setup correcty.', 'ultimate-member') . '

'; - echo '

'. __('This field type is not setup correcty.', 'ultimate-member') . '

'; + } else { - } else { + ?> - ?> + edit_array['in_group'] ) ) { ?> + + + + + - edit_array['in_group'] ) ) { ?> - - - - - + - + - + - + - + - +
edit_array['content']; ?>
-
edit_array['content']; ?>
+ modal_header(); ?> - 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 ); } ?> +
-
+ 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 ); ?> - modal_footer( $arg2, $args, $metabox ); ?> + builtin()->get_core_field_attrs( $arg1 ); - $args = UM()->builtin()->get_core_field_attrs( $arg1 ); + $metabox->set_field_type = $arg1; - $metabox->set_field_type = $arg1; + /** + * @var $in_row + * @var $in_sub_row + * @var $in_column + * @var $in_group + */ + extract( $args ); - extract( $args ); + if ( ! isset( $col1 ) ) { - if ( !isset( $col1 ) ) { + echo '

'. __( 'This field type is not setup correcty.', 'ultimate-member' ) . '

'; - echo '

'. __('This field type is not setup correcty.', 'ultimate-member') . '

'; + } else { - } else { + if ( $in_column ) { ?> + + + + + - ?> + - - - - - - + - + modal_header(); ?> - +
- modal_header(); ?> + field_input ( $opt ); } ?> -
+
- field_input ( $opt ); } ?> +
-
+ field_input ( $opt ); } ?> -
+
- field_input ( $opt ); } ?> + field_input ( $opt ); } ?> -
+
- field_input ( $opt ); } ?> + field_input ( $opt ); } ?> -
+ modal_footer( $arg2, $args, $metabox ); ?> - field_input ( $opt ); } ?> + modal_footer( $arg2, $args, $metabox ); ?> + } - query()->get_attr('mode', $arg1 ); - case 'um_admin_preview_form': + if ( $mode == 'profile' ) { + UM()->fields()->editing = true; + } - $mode = UM()->query()->get_attr('mode', $arg1 ); + $output = do_shortcode('[ultimatemember form_id='.$arg1.']'); - if ( $mode == 'profile' ) { - UM()->fields()->editing = true; - } + break; - $output = do_shortcode('[ultimatemember form_id='.$arg1.']'); + case 'um_admin_review_registration': + //$user_id = $arg1; + um_fetch_user( $arg1 ); - break; + UM()->user()->preview = true; - case 'um_admin_review_registration': - //$user_id = $arg1; - um_fetch_user( $arg1 ); + $output = um_user_submitted_registration( true ); - UM()->user()->preview = true; + um_reset_user(); - $output = um_user_submitted_registration( true ); + break; - um_reset_user(); + } - break; + if ( is_array( $output ) ) { + print_r( $output ); + } else { + echo $output; + } + die; + } - } - 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' ); + } - } - - /** - * - */ - 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 ); - } - - } + /** + * Modal Footer loading + * + * @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 ); + } + + } } \ No newline at end of file diff --git a/includes/admin/core/class-admin-columns.php b/includes/admin/core/class-admin-columns.php index 457b9db4..7c779aba 100644 --- a/includes/admin/core/class-admin-columns.php +++ b/includes/admin/core/class-admin-columns.php @@ -5,129 +5,151 @@ namespace um\admin\core; if ( ! defined( 'ABSPATH' ) ) exit; if ( ! class_exists( 'Admin_Columns' ) ) { - class Admin_Columns { - function __construct() { - $this->slug = 'ultimatemember'; - - add_filter('manage_edit-um_form_columns', array(&$this, 'manage_edit_um_form_columns') ); - add_action('manage_um_form_posts_custom_column', array(&$this, 'manage_um_form_posts_custom_column'), 10, 3); - - add_filter('manage_edit-um_directory_columns', array(&$this, 'manage_edit_um_directory_columns') ); - add_action('manage_um_directory_posts_custom_column', array(&$this, 'manage_um_directory_posts_custom_column'), 10, 3); - - add_filter('post_row_actions', array(&$this, 'post_row_actions'), 99, 2); - - // Add a post display state for special UM pages. - add_filter( 'display_post_states', array( &$this, 'add_display_post_states' ), 10, 2 ); - } - - /*** - *** @custom row actions - ***/ - function post_row_actions( $actions, $post ) { - //check for your post type - if ( $post->post_type == "um_form" ) { - $actions['um_duplicate'] = '' . __('Duplicate','ultimate-member') . ''; - } - return $actions; - } - - /*** - *** @duplicate a form - ***/ - function duplicate_uri( $id ) { - $url = add_query_arg('um_adm_action', 'duplicate_form', admin_url('edit.php?post_type=um_form') ); - $url = add_query_arg('post_id', $id, $url); - return $url; - } - - /*** - *** @Custom columns for Form - ***/ - function manage_edit_um_form_columns( $columns ) { - - $new_columns['cb'] = ''; - $new_columns['title'] = __( 'Title', 'ulitmatemember' ); - $new_columns['id'] = __('ID', 'ulitmatemember' ); - $new_columns['mode'] = __( 'Type', 'ulitmatemember' ); - $new_columns['shortcode'] = __( 'Shortcode', 'ulitmatemember' ); - $new_columns['date'] = __( 'Date', 'ulitmatemember' ); - - return $new_columns; - - } - - /*** - *** @Custom columns for Directory - ***/ - function manage_edit_um_directory_columns( $columns ) { - - $new_columns['cb'] = ''; - - $new_columns['title'] = __( 'Title', 'ultimate-member' ); - $new_columns['id'] = __( 'ID', 'ultimate-member' ); - $new_columns['shortcode'] = __( 'Shortcode', 'ultimate-member' ); - $new_columns['date'] = __( 'Date', 'ultimate-member' ); - - return $new_columns; - - } - - /*** - *** @Display cusom columns for Form - ***/ - function manage_um_form_posts_custom_column( $column_name, $id ) { - - switch ( $column_name ) { - - case 'id': - echo ''.$id.''; - break; - - case 'shortcode': - echo UM()->shortcodes()->get_shortcode( $id ); - break; - - case 'mode': - $mode = UM()->query()->get_attr( 'mode', $id ); - echo UM()->form()->display_form_type( $mode, $id ); - break; - - } - - } - - /*** - *** @Display cusom columns for Directory - ***/ - function manage_um_directory_posts_custom_column($column_name, $id) { - global $wpdb; - - switch ($column_name) { - - case 'id': - echo ''.$id.''; - break; - - case 'shortcode': - echo UM()->shortcodes()->get_shortcode( $id ); - break; - - } - - } + /** + * Class Admin_Columns + * @package um\admin\core + */ + class Admin_Columns { /** - * Add a post display state for special UM pages in the page list table. - * - * @param array $post_states An array of post display states. - * @param \WP_Post $post The current post object. - * - * @return mixed - */ + * Admin_Columns constructor. + */ + function __construct() { + + add_filter( 'manage_edit-um_form_columns', array( &$this, 'manage_edit_um_form_columns' ) ); + add_action( 'manage_um_form_posts_custom_column', array( &$this, 'manage_um_form_posts_custom_column' ), 10, 3 ); + + add_filter( 'manage_edit-um_directory_columns', array( &$this, 'manage_edit_um_directory_columns' ) ); + add_action( 'manage_um_directory_posts_custom_column', array( &$this, 'manage_um_directory_posts_custom_column' ), 10, 3 ); + + add_filter( 'post_row_actions', array( &$this, 'post_row_actions' ), 99, 2 ); + + // Add a post display state for special UM pages. + add_filter( 'display_post_states', array( &$this, 'add_display_post_states' ), 10, 2 ); + } + + + /** + * Custom row actions + * + * @param array $actions + * @param \WP_Post $post + * + * @return mixed + */ + function post_row_actions( $actions, $post ) { + //check for your post type + if ( $post->post_type == "um_form" ) { + $actions['um_duplicate'] = '' . __( 'Duplicate', 'ultimate-member' ) . ''; + } + return $actions; + } + + + /** + * Duplicate a form + * + * @param int $id + * + * @return string + */ + function duplicate_uri( $id ) { + $url = add_query_arg('um_adm_action', 'duplicate_form', admin_url('edit.php?post_type=um_form') ); + $url = add_query_arg('post_id', $id, $url); + return $url; + } + + + /** + * Custom columns for Form + * + * @param array $columns + * + * @return array + */ + function manage_edit_um_form_columns( $columns ) { + $new_columns['cb'] = ''; + $new_columns['title'] = __( 'Title', 'ulitmatemember' ); + $new_columns['id'] = __('ID', 'ulitmatemember' ); + $new_columns['mode'] = __( 'Type', 'ulitmatemember' ); + $new_columns['shortcode'] = __( 'Shortcode', 'ulitmatemember' ); + $new_columns['date'] = __( 'Date', 'ulitmatemember' ); + + return $new_columns; + } + + + /** + * Custom columns for Directory + * + * @param array $columns + * + * @return array + */ + function manage_edit_um_directory_columns( $columns ) { + $new_columns['cb'] = ''; + $new_columns['title'] = __( 'Title', 'ultimate-member' ); + $new_columns['id'] = __( 'ID', 'ultimate-member' ); + $new_columns['shortcode'] = __( 'Shortcode', 'ultimate-member' ); + $new_columns['date'] = __( 'Date', 'ultimate-member' ); + + return $new_columns; + } + + + /** + * Display custom columns for Form + * + * @param string $column_name + * @param int $id + */ + function manage_um_form_posts_custom_column( $column_name, $id ) { + switch ( $column_name ) { + case 'id': + echo ''.$id.''; + break; + + case 'shortcode': + echo UM()->shortcodes()->get_shortcode( $id ); + break; + + case 'mode': + $mode = UM()->query()->get_attr( 'mode', $id ); + echo UM()->form()->display_form_type( $mode, $id ); + break; + } + } + + + /** + * Display cusom columns for Directory + * + * @param string $column_name + * @param int $id + */ + function manage_um_directory_posts_custom_column( $column_name, $id ) { + switch ( $column_name ) { + case 'id': + echo ''.$id.''; + break; + case 'shortcode': + echo UM()->shortcodes()->get_shortcode( $id ); + break; + } + } + + + /** + * Add a post display state for special UM pages in the page list table. + * + * @param array $post_states An array of post display states. + * @param \WP_Post $post The current post object. + * + * @return mixed + */ public function add_display_post_states( $post_states, $post ) { foreach ( UM()->config()->core_pages as $page_key => $page_value ) { @@ -141,5 +163,5 @@ if ( ! class_exists( 'Admin_Columns' ) ) { return $post_states; } - } + } } \ No newline at end of file diff --git a/includes/admin/core/class-admin-dragdrop.php b/includes/admin/core/class-admin-dragdrop.php index 9f9d7fba..be4f465c 100644 --- a/includes/admin/core/class-admin-dragdrop.php +++ b/includes/admin/core/class-admin-dragdrop.php @@ -5,212 +5,227 @@ namespace um\admin\core; if ( ! defined( 'ABSPATH' ) ) exit; if ( ! class_exists( 'Admin_DragDrop' ) ) { - class Admin_DragDrop { - - function __construct() { - add_action( 'admin_footer', array( &$this, 'load_field_order' ), 9 ); - } - - /*** - *** @update order of fields - ***/ - function update_order() { - - if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) - die( 'Please login as administrator' ); - - extract( $_POST ); - - $fields = UM()->query()->get_attr( 'custom_fields', $form_id ); - - $this->row_data = get_option( 'um_form_rowdata_' . $form_id, array() ); - $this->exist_rows = array(); - - if ( ! empty( $fields ) ) { - foreach ( $fields as $key => $array ) { - if ( $array['type'] == 'row' ) { - $this->row_data[$key] = $array; - unset( $fields[$key] ); - } - } - } else { - $fields = array(); - } - - foreach ( $_POST as $key => $value ) { - - // adding rows - if ( 0 === strpos( $key, '_um_row_' ) ) { - - $update_args = null; - - $row_id = str_replace( '_um_row_', '', $key ); - - $row_array = array( - 'type' => 'row', - 'id' => $value, - 'sub_rows' => $_POST[ '_um_rowsub_'.$row_id .'_rows' ], - 'cols' => $_POST[ '_um_rowcols_'.$row_id .'_cols' ], - 'origin' => $_POST[ '_um_roworigin_'.$row_id . '_val' ], - ); - - $row_args = $row_array; - - if ( isset( $this->row_data[ $row_array['origin'] ] ) ) { - foreach( $this->row_data[ $row_array['origin'] ] as $k => $v ){ - if ( $k != 'position' && $k != 'metakey' ) { - $update_args[$k] = $v; - } - } - if ( isset( $update_args ) ) { - $row_args = array_merge( $update_args, $row_array ); - } - $this->exist_rows[] = $key; - } - - $fields[$key] = $row_args; - - } - - // change field position - if ( 0 === strpos( $key, 'um_position_' ) ) { - $field_key = str_replace('um_position_','',$key); - if ( isset( $fields[$field_key] ) ) { - $fields[$field_key]['position'] = $value; - } - } - - // change field master row - if ( 0 === strpos( $key, 'um_row_' ) ) { - $field_key = str_replace('um_row_','',$key); - if ( isset( $fields[$field_key] ) ) { - $fields[$field_key]['in_row'] = $value; - } - } - - // change field sub row - if ( 0 === strpos( $key, 'um_subrow_' ) ) { - $field_key = str_replace('um_subrow_','',$key); - if ( isset( $fields[$field_key] ) ) { - $fields[$field_key]['in_sub_row'] = $value; - } - } - - // change field column - if ( 0 === strpos( $key, 'um_col_' ) ) { - $field_key = str_replace('um_col_','',$key); - if ( isset( $fields[$field_key] ) ) { - $fields[$field_key]['in_column'] = $value; - } - } - - // add field to group - if ( 0 === strpos( $key, 'um_group_' ) ) { - $field_key = str_replace('um_group_','',$key); - if ( isset( $fields[$field_key] ) ) { - $fields[$field_key]['in_group'] = $value; - } - } - - } - - foreach ( $this->row_data as $k => $v ) { - if ( ! in_array( $k, $this->exist_rows ) ) - unset( $this->row_data[$k] ); - } - - update_option( 'um_existing_rows_' . $form_id, $this->exist_rows ); - - update_option( 'um_form_rowdata_' . $form_id , $this->row_data ); - - UM()->query()->update_attr( 'custom_fields', $form_id, $fields ); - - } - - /*** - *** @load form to maintain form order - ***/ - function load_field_order() { - - $screen = get_current_screen(); - - if ( ! isset( $screen->id ) || $screen->id != 'um_form' ) return; - - ?> - -
- - - - -
+ /** + * Class Admin_DragDrop + * @package um\admin\core + */ + class Admin_DragDrop { - -
+ /** + * Admin_DragDrop constructor. + */ + function __construct() { + add_action( 'admin_footer', array( &$this, 'load_field_order' ), 9 ); + } -
-
+ /** + * Update order of fields + */ + function update_order() { - query()->get_attr( 'custom_fields', $form_id ); + + $this->row_data = get_option( 'um_form_rowdata_' . $form_id, array() ); + $this->exist_rows = array(); + + if ( ! empty( $fields ) ) { + foreach ( $fields as $key => $array ) { + if ( $array['type'] == 'row' ) { + $this->row_data[$key] = $array; + unset( $fields[$key] ); + } + } + } else { + $fields = array(); + } + + foreach ( $_POST as $key => $value ) { + + // adding rows + if ( 0 === strpos( $key, '_um_row_' ) ) { + + $update_args = null; + + $row_id = str_replace( '_um_row_', '', $key ); + + $row_array = array( + 'type' => 'row', + 'id' => $value, + 'sub_rows' => $_POST[ '_um_rowsub_'.$row_id .'_rows' ], + 'cols' => $_POST[ '_um_rowcols_'.$row_id .'_cols' ], + 'origin' => $_POST[ '_um_roworigin_'.$row_id . '_val' ], + ); + + $row_args = $row_array; + + if ( isset( $this->row_data[ $row_array['origin'] ] ) ) { + foreach( $this->row_data[ $row_array['origin'] ] as $k => $v ){ + if ( $k != 'position' && $k != 'metakey' ) { + $update_args[$k] = $v; + } + } + if ( isset( $update_args ) ) { + $row_args = array_merge( $update_args, $row_array ); + } + $this->exist_rows[] = $key; + } + + $fields[$key] = $row_args; + + } + + // change field position + if ( 0 === strpos( $key, 'um_position_' ) ) { + $field_key = str_replace('um_position_','',$key); + if ( isset( $fields[$field_key] ) ) { + $fields[$field_key]['position'] = $value; + } + } + + // change field master row + if ( 0 === strpos( $key, 'um_row_' ) ) { + $field_key = str_replace('um_row_','',$key); + if ( isset( $fields[$field_key] ) ) { + $fields[$field_key]['in_row'] = $value; + } + } + + // change field sub row + if ( 0 === strpos( $key, 'um_subrow_' ) ) { + $field_key = str_replace('um_subrow_','',$key); + if ( isset( $fields[$field_key] ) ) { + $fields[$field_key]['in_sub_row'] = $value; + } + } + + // change field column + if ( 0 === strpos( $key, 'um_col_' ) ) { + $field_key = str_replace('um_col_','',$key); + if ( isset( $fields[$field_key] ) ) { + $fields[$field_key]['in_column'] = $value; + } + } + + // add field to group + if ( 0 === strpos( $key, 'um_group_' ) ) { + $field_key = str_replace('um_group_','',$key); + if ( isset( $fields[$field_key] ) ) { + $fields[$field_key]['in_group'] = $value; + } + } + + } + + foreach ( $this->row_data as $k => $v ) { + if ( ! in_array( $k, $this->exist_rows ) ) + unset( $this->row_data[$k] ); + } + + update_option( 'um_existing_rows_' . $form_id, $this->exist_rows ); + + update_option( 'um_form_rowdata_' . $form_id , $this->row_data ); + + UM()->query()->update_attr( 'custom_fields', $form_id, $fields ); + + } + + + /** + * Load form to maintain form order + */ + function load_field_order() { + + $screen = get_current_screen(); + + if ( ! isset( $screen->id ) || $screen->id != 'um_form' ) return; + + ?> + +
+ + + + + + +
+ + + +
+ +
+ +
+ + slug = 'ultimatemember'; - $this->js_url = um_url . 'includes/admin/assets/js/'; - $this->css_url = um_url . 'includes/admin/assets/css/'; + /** + * Class Admin_Enqueue + * @package um\admin\core + */ + class Admin_Enqueue { + var $js_url; + var $css_url; - add_action('admin_head', array(&$this, 'admin_head'), 9); - add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts') ); + /** + * Admin_Enqueue constructor. + */ + function __construct() { + $this->slug = 'ultimatemember'; - add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ), 999 ); + $this->js_url = um_url . 'includes/admin/assets/js/'; + $this->css_url = um_url . 'includes/admin/assets/css/'; - add_filter('enter_title_here', array(&$this, 'enter_title_here') ); + add_action( 'admin_head', array( &$this, 'admin_head' ), 9 ); - add_action( 'load-user-new.php', array( &$this, 'enqueue_role_wrapper' ) ); - add_action( 'load-user-edit.php', array( &$this, 'enqueue_role_wrapper' ) ); - } + add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); + + add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ), 999 ); + add_filter( 'enter_title_here', array( &$this, 'enter_title_here' ) ); + + add_action( 'load-user-new.php', array( &$this, 'enqueue_role_wrapper' ) ); + add_action( 'load-user-edit.php', array( &$this, 'enqueue_role_wrapper' ) ); + } - function enqueue_role_wrapper() { - add_action( 'admin_enqueue_scripts', array( &$this, 'load_role_wrapper' ) ); - } + function enqueue_role_wrapper() { + add_action( 'admin_enqueue_scripts', array( &$this, 'load_role_wrapper' ) ); + } - /** - * Load js for Add/Edit User form - */ - function load_role_wrapper() { - wp_register_script( 'um_admin_role_wrapper', $this->js_url . 'um-admin-role-wrapper.js', '', '', true ); - wp_enqueue_script( 'um_admin_role_wrapper' ); - - $localize_roles_data = get_option( 'um_roles' ); - - wp_localize_script( 'um_admin_settings', 'um_roles', $localize_roles_data ); - - } - - - /*** - *** @enter title placeholder - ***/ - function enter_title_here( $title ) { - $screen = get_current_screen(); - if ( 'um_directory' == $screen->post_type ){ - $title = 'e.g. Member Directory'; - } - if ( 'um_form' == $screen->post_type ){ - $title = 'e.g. New Registration Form'; - } - return $title; - } - - - /*** - *** @Runs on admin head - ***/ - function admin_head(){ - - if ( UM()->admin()->is_plugin_post_type() ){ - - ?> - - - - css_url . 'um-admin-form.css' ); - wp_enqueue_style( 'um_admin_form' ); - - wp_register_script( 'um_admin_form', $this->js_url . 'um-admin-form.js', '', '', true ); - wp_enqueue_script( 'um_admin_form' ); - - } - - - /*** - *** @Load Form - ***/ - function load_forms() { - - wp_register_style( 'um_admin_forms', $this->css_url . 'um-admin-forms.css' ); - wp_enqueue_style( 'um_admin_forms' ); - - wp_register_script( 'um_admin_forms', $this->js_url . 'um-admin-forms.js', '', '', true ); - wp_enqueue_script( 'um_admin_forms' ); - - $localize_data = array( - 'texts' => array( - 'remove' => __( 'Remove', 'ultimate-member' ), - 'select' => __( 'Select', 'ultimate-member' ) - ) - ); - - wp_localize_script( 'um_admin_forms', 'php_data', $localize_data ); - - } - - - /*** - *** @Load dashboard - ***/ - function load_dashboard() { - - wp_register_style( 'um_admin_dashboard', $this->css_url . 'um-admin-dashboard.css' ); - wp_enqueue_style( 'um_admin_dashboard' ); - - wp_register_script( 'um_admin_dashboard', $this->js_url . 'um-admin-dashboard.js', '', '', true ); - wp_enqueue_script( 'um_admin_dashboard' ); - - } - - - /*** - *** @Load settings - ***/ - function load_settings() { - - wp_register_style( 'um_admin_settings', $this->css_url . 'um-admin-settings.css' ); - wp_enqueue_style( 'um_admin_settings' ); - - wp_register_script( 'um_admin_settings', $this->js_url . 'um-admin-settings.js', '', '', true ); - wp_enqueue_script( 'um_admin_settings' ); - - $localize_data = array( - 'delete_email_template' => UM()->get_ajax_route( 'um\core\Mail', 'delete_email_template' ), - 'onbeforeunload_text' => __( 'Are sure, maybe some settings not saved', 'ultimate-member' ), - 'texts' => array( - 'remove' => __( 'Remove', 'ultimate-member' ), - 'select' => __( 'Select', 'ultimate-member' ) - ) - ); - - wp_localize_script( 'um_admin_settings', 'php_data', $localize_data ); - - } - - - /*** - *** @Load modal - ***/ - function load_modal() { - - wp_register_style( 'um_admin_modal', $this->css_url . 'um-admin-modal.css' ); - wp_enqueue_style( 'um_admin_modal' ); - - wp_register_script( 'um_admin_modal', $this->js_url . 'um-admin-modal.js', '', '', true ); - wp_enqueue_script( 'um_admin_modal' ); - - $localize_data = array( - 'ajax_url' => UM()->get_ajax_route( 'um\admin\core\Admin_Builder', 'dynamic_modal_content' ), - 'dropdown_ajax_url' => UM()->get_ajax_route( 'um\admin\core\Admin_Builder', 'populate_dropdown_options' ), - ); - wp_localize_script( 'um_admin_modal', 'um_admin_modal_data', $localize_data ); - - } - - - /*** - *** @Field Processing - ***/ - function load_field() { - - wp_register_script( 'um_admin_field', $this->js_url . 'um-admin-field.js', '', '', true ); - wp_enqueue_script( 'um_admin_field' ); - - $localize_data = array( - 'ajax_url' => UM()->get_ajax_route( 'um\admin\core\Admin_Builder', 'update_field' ), - 'do_ajax_url' => UM()->get_ajax_route( 'um\core\Fields', 'do_ajax_action' ), - ); - wp_localize_script( 'um_admin_field', 'um_admin_field_data', $localize_data ); - - } - - - /*** - *** @Load Builder - ***/ - function load_builder() { - - wp_register_script( 'um_admin_builder', $this->js_url . 'um-admin-builder.js', '', '', true ); - wp_enqueue_script( 'um_admin_builder' ); - - //hide footer text on add/edit UM Forms - //layouts crashed because we load and hide metaboxes - //and WP calculate page height - $hide_footer = false; - global $pagenow, $post; - if ( ( 'post.php' == $pagenow || 'post-new.php' == $pagenow ) && - ( ( isset( $_GET['post_type'] ) && 'um_form' == $_GET['post_type'] ) || - ( isset( $post->post_type ) && 'um_form' == $post->post_type ) ) ) { - $hide_footer = true; - } - - $localize_data = array( - 'ajax_url' => UM()->get_ajax_route( 'um\admin\core\Admin_Builder', 'update_builder' ), - 'hide_footer' => $hide_footer, - ); - wp_localize_script( 'um_admin_builder', 'um_admin_builder_data', $localize_data ); - - wp_register_script( 'um_admin_dragdrop', $this->js_url . 'um-admin-dragdrop.js', '', '', true ); - wp_enqueue_script( 'um_admin_dragdrop' ); - - - $localize_data = array( - 'ajax_url' => UM()->get_ajax_route( 'um\admin\core\Admin_DragDrop', 'update_order' ), - ); - wp_localize_script( 'um_admin_dragdrop', 'um_admin_dragdrop_data', $localize_data ); - - - wp_register_style( 'um_admin_builder', $this->css_url . 'um-admin-builder.css' ); - wp_enqueue_style( 'um_admin_builder' ); - - } - - - /*** - *** @Load core WP styles/scripts - ***/ - function load_core_wp() { - - wp_enqueue_style( 'wp-color-picker' ); - wp_enqueue_script( 'wp-color-picker' ); - - wp_enqueue_script( 'jquery-ui-draggable' ); - wp_enqueue_script( 'jquery-ui-sortable' ); - - wp_enqueue_script( 'jquery-ui-tooltip' ); - - } - - - /*** - *** @Load Admin Styles - ***/ - function load_css() { - - wp_register_style( 'um_admin_menu', $this->css_url . 'um-admin-menu.css' ); - wp_enqueue_style( 'um_admin_menu' ); - - wp_register_style( 'um_admin_columns', $this->css_url . 'um-admin-columns.css' ); - wp_enqueue_style( 'um_admin_columns' ); - - wp_register_style( 'um_admin_misc', $this->css_url . 'um-admin-misc.css' ); - wp_enqueue_style( 'um_admin_misc' ); - - } - - - /*** - *** @Load functions js - ***/ - function load_functions() { - - wp_register_script('um_functions', um_url . 'assets/js/um-functions' . '.js' ); - wp_enqueue_script('um_functions'); - - } - - - /*** - *** @Load Fonticons - ***/ - function load_fonticons() { - - wp_register_style('um_fonticons_ii', um_url . 'assets/css/um-fonticons-ii.css' ); - wp_enqueue_style('um_fonticons_ii'); - - wp_register_style('um_fonticons_fa', um_url . 'assets/css/um-fonticons-fa.css' ); - wp_enqueue_style('um_fonticons_fa'); - - } - - - /*** - *** @Load global css - ***/ - function load_global_css() { - - wp_register_style( 'um_admin_global', $this->css_url . 'um-admin-global.css' ); - wp_enqueue_style( 'um_admin_global' ); - - } - - - /*** - *** @Load jQuery custom code - ***/ - function load_custom_scripts() { - - wp_register_script( 'um_admin_scripts', $this->js_url . 'um-admin-scripts.js', '', '', true ); - wp_enqueue_script( 'um_admin_scripts' ); - - } - - /*** - *** @Load jQuery custom code - ***/ - function load_nav_manus_scripts() { - - wp_register_script( 'um_admin_nav_manus', $this->js_url . 'um-admin-nav-menu.js', array('jquery','wp-util'), '', true ); - wp_enqueue_script( 'um_admin_nav_manus' ); - - } - - /*** - *** @Load AJAX - ***/ - function load_ajax_js() { - - wp_register_script( 'um_admin_ajax', $this->js_url . 'um-admin-ajax.js', '', '', true ); - wp_enqueue_script( 'um_admin_ajax' ); - - $localize_data = array( - 'ajax_url' => UM()->get_ajax_route( 'um\core\Fields', 'do_ajax_action' ), - ); - wp_localize_script( 'um_admin_ajax', 'um_admin_ajax_data', $localize_data ); - - } - - /** - * Load localize scripts - */ - function load_localize_scripts(){ - - /** - * UM hook - * - * @type filter - * @title um_admin_enqueue_localize_data - * @description Extend localize data at wp-admin side - * @input_vars - * [{"var":"$localize_data","type":"array","desc":"Localize Data"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_admin_enqueue_localize_data', 'function_name', 10, 1 ); - * @example - * - */ - $localize_data = apply_filters('um_admin_enqueue_localize_data', array( - 'ajaxurl' => admin_url( 'admin-ajax.php' ) - ) - ); - - wp_localize_script( 'um_admin_scripts', 'um_admin_scripts', $localize_data ); - } - - - /*** - *** @Boolean check if we're viewing UM backend - ***/ - function is_UM_admin() { - global $current_screen; - - $screen_id = $current_screen->id; - if ( strstr( $screen_id, 'ultimatemember' ) || strstr( $screen_id, 'um_' ) || strstr( $screen_id, 'user' ) || strstr( $screen_id, 'profile' ) || $screen_id == 'nav-menus' ) return true; - - global $post; - if ( isset( $post->post_type ) ) return true; - - global $tax; - if ( isset( $tax->name ) ) return true; - - return false; - } - - /*** - *** @Adds class to our admin pages - ***/ - function admin_body_class($classes){ - if ( $this->is_UM_admin() ) { - return "$classes um-admin"; - } - return $classes; - } - - /*** - *** @Enqueue scripts and styles - ***/ - function admin_enqueue_scripts() { - if ( $this->is_UM_admin() ) { - - /*if ( get_post_type() != 'shop_order' ) { + /** + * Load js for Add/Edit User form + */ + function load_role_wrapper() { + wp_register_script( 'um_admin_role_wrapper', $this->js_url . 'um-admin-role-wrapper.js', '', '', true ); + wp_enqueue_script( 'um_admin_role_wrapper' ); + + $localize_roles_data = get_option( 'um_roles' ); + + wp_localize_script( 'um_admin_settings', 'um_roles', $localize_roles_data ); + } + + + /** + * Enter title placeholder + * + * @param $title + * + * @return string + */ + function enter_title_here( $title ) { + $screen = get_current_screen(); + if ( 'um_directory' == $screen->post_type ){ + $title = 'e.g. Member Directory'; + } + if ( 'um_form' == $screen->post_type ){ + $title = 'e.g. New Registration Form'; + } + return $title; + } + + + /** + * Runs on admin head + */ + function admin_head() { + if ( UM()->admin()->is_plugin_post_type() ) { ?> + + css_url . 'um-admin-form.css' ); + wp_enqueue_style( 'um_admin_form' ); + + wp_register_script( 'um_admin_form', $this->js_url . 'um-admin-form.js', '', '', true ); + wp_enqueue_script( 'um_admin_form' ); + } + + + /** + * Load Forms + */ + function load_forms() { + wp_register_style( 'um_admin_forms', $this->css_url . 'um-admin-forms.css' ); + wp_enqueue_style( 'um_admin_forms' ); + + wp_register_script( 'um_admin_forms', $this->js_url . 'um-admin-forms.js', '', '', true ); + wp_enqueue_script( 'um_admin_forms' ); + + $localize_data = array( + 'texts' => array( + 'remove' => __( 'Remove', 'ultimate-member' ), + 'select' => __( 'Select', 'ultimate-member' ) + ) + ); + + wp_localize_script( 'um_admin_forms', 'php_data', $localize_data ); + } + + + /** + * Load dashboard + */ + function load_dashboard() { + wp_register_style( 'um_admin_dashboard', $this->css_url . 'um-admin-dashboard.css' ); + wp_enqueue_style( 'um_admin_dashboard' ); + + wp_register_script( 'um_admin_dashboard', $this->js_url . 'um-admin-dashboard.js', '', '', true ); + wp_enqueue_script( 'um_admin_dashboard' ); + } + + + /** + * Load settings + */ + function load_settings() { + wp_register_style( 'um_admin_settings', $this->css_url . 'um-admin-settings.css' ); + wp_enqueue_style( 'um_admin_settings' ); + + wp_register_script( 'um_admin_settings', $this->js_url . 'um-admin-settings.js', '', '', true ); + wp_enqueue_script( 'um_admin_settings' ); + + $localize_data = array( + 'delete_email_template' => UM()->get_ajax_route( 'um\core\Mail', 'delete_email_template' ), + 'onbeforeunload_text' => __( 'Are sure, maybe some settings not saved', 'ultimate-member' ), + 'texts' => array( + 'remove' => __( 'Remove', 'ultimate-member' ), + 'select' => __( 'Select', 'ultimate-member' ) + ) + ); + + wp_localize_script( 'um_admin_settings', 'php_data', $localize_data ); + } + + + /** + * Load modal + */ + function load_modal() { + wp_register_style( 'um_admin_modal', $this->css_url . 'um-admin-modal.css' ); + wp_enqueue_style( 'um_admin_modal' ); + + wp_register_script( 'um_admin_modal', $this->js_url . 'um-admin-modal.js', '', '', true ); + wp_enqueue_script( 'um_admin_modal' ); + + $localize_data = array( + 'ajax_url' => UM()->get_ajax_route( 'um\admin\core\Admin_Builder', 'dynamic_modal_content' ), + 'dropdown_ajax_url' => UM()->get_ajax_route( 'um\admin\core\Admin_Builder', 'populate_dropdown_options' ), + ); + wp_localize_script( 'um_admin_modal', 'um_admin_modal_data', $localize_data ); + } + + + /** + * Field Processing + */ + function load_field() { + wp_register_script( 'um_admin_field', $this->js_url . 'um-admin-field.js', '', '', true ); + wp_enqueue_script( 'um_admin_field' ); + + $localize_data = array( + 'ajax_url' => UM()->get_ajax_route( 'um\admin\core\Admin_Builder', 'update_field' ), + 'do_ajax_url' => UM()->get_ajax_route( 'um\core\Fields', 'do_ajax_action' ), + ); + wp_localize_script( 'um_admin_field', 'um_admin_field_data', $localize_data ); + } + + + /** + * Load Builder + */ + function load_builder() { + wp_register_script( 'um_admin_builder', $this->js_url . 'um-admin-builder.js', '', '', true ); + wp_enqueue_script( 'um_admin_builder' ); + + //hide footer text on add/edit UM Forms + //layouts crashed because we load and hide metaboxes + //and WP calculate page height + $hide_footer = false; + global $pagenow, $post; + if ( ( 'post.php' == $pagenow || 'post-new.php' == $pagenow ) && + ( ( isset( $_GET['post_type'] ) && 'um_form' == $_GET['post_type'] ) || + ( isset( $post->post_type ) && 'um_form' == $post->post_type ) ) ) { + $hide_footer = true; + } + + $localize_data = array( + 'ajax_url' => UM()->get_ajax_route( 'um\admin\core\Admin_Builder', 'update_builder' ), + 'hide_footer' => $hide_footer, + ); + wp_localize_script( 'um_admin_builder', 'um_admin_builder_data', $localize_data ); + + wp_register_script( 'um_admin_dragdrop', $this->js_url . 'um-admin-dragdrop.js', '', '', true ); + wp_enqueue_script( 'um_admin_dragdrop' ); + + + $localize_data = array( + 'ajax_url' => UM()->get_ajax_route( 'um\admin\core\Admin_DragDrop', 'update_order' ), + ); + wp_localize_script( 'um_admin_dragdrop', 'um_admin_dragdrop_data', $localize_data ); + + + wp_register_style( 'um_admin_builder', $this->css_url . 'um-admin-builder.css' ); + wp_enqueue_style( 'um_admin_builder' ); + } + + + /** + * Load core WP styles/scripts + */ + function load_core_wp() { + wp_enqueue_style( 'wp-color-picker' ); + wp_enqueue_script( 'wp-color-picker' ); + + wp_enqueue_script( 'jquery-ui-draggable' ); + wp_enqueue_script( 'jquery-ui-sortable' ); + + wp_enqueue_script( 'jquery-ui-tooltip' ); + } + + + /** + * Load Admin Styles + */ + function load_css() { + wp_register_style( 'um_admin_menu', $this->css_url . 'um-admin-menu.css' ); + wp_enqueue_style( 'um_admin_menu' ); + + wp_register_style( 'um_admin_columns', $this->css_url . 'um-admin-columns.css' ); + wp_enqueue_style( 'um_admin_columns' ); + + wp_register_style( 'um_admin_misc', $this->css_url . 'um-admin-misc.css' ); + wp_enqueue_style( 'um_admin_misc' ); + } + + + /** + * Load functions js + */ + function load_functions() { + wp_register_script( 'um_functions', um_url . 'assets/js/um-functions' . '.js' ); + wp_enqueue_script( 'um_functions' ); + } + + + /** + * Load Fonticons + */ + function load_fonticons() { + wp_register_style( 'um_fonticons_ii', um_url . 'assets/css/um-fonticons-ii.css' ); + wp_enqueue_style( 'um_fonticons_ii' ); + + wp_register_style( 'um_fonticons_fa', um_url . 'assets/css/um-fonticons-fa.css' ); + wp_enqueue_style( 'um_fonticons_fa' ); + } + + + /** + * Load global css + */ + function load_global_css() { + wp_register_style( 'um_admin_global', $this->css_url . 'um-admin-global.css' ); + wp_enqueue_style( 'um_admin_global' ); + } + + + /** + * Load jQuery custom code + */ + function load_custom_scripts() { + wp_register_script( 'um_admin_scripts', $this->js_url . 'um-admin-scripts.js', '', '', true ); + wp_enqueue_script( 'um_admin_scripts' ); + } + + + /** + * Load jQuery custom code + */ + function load_nav_manus_scripts() { + wp_register_script( 'um_admin_nav_manus', $this->js_url . 'um-admin-nav-menu.js', array('jquery','wp-util'), '', true ); + wp_enqueue_script( 'um_admin_nav_manus' ); + } + + + /** + * Load AJAX + */ + function load_ajax_js() { + wp_register_script( 'um_admin_ajax', $this->js_url . 'um-admin-ajax.js', '', '', true ); + wp_enqueue_script( 'um_admin_ajax' ); + + $localize_data = array( + 'ajax_url' => UM()->get_ajax_route( 'um\core\Fields', 'do_ajax_action' ), + ); + wp_localize_script( 'um_admin_ajax', 'um_admin_ajax_data', $localize_data ); + } + + + /** + * Load localize scripts + */ + function load_localize_scripts() { + + /** + * UM hook + * + * @type filter + * @title um_admin_enqueue_localize_data + * @description Extend localize data at wp-admin side + * @input_vars + * [{"var":"$localize_data","type":"array","desc":"Localize Data"}] + * @change_log + * ["Since: 2.0"] + * @usage add_filter( 'um_admin_enqueue_localize_data', 'function_name', 10, 1 ); + * @example + * + */ + $localize_data = apply_filters('um_admin_enqueue_localize_data', array( + 'ajaxurl' => admin_url( 'admin-ajax.php' ) + ) + ); + + wp_localize_script( 'um_admin_scripts', 'um_admin_scripts', $localize_data ); + } + + + /** + * Boolean check if we're viewing UM backend + * + * @return bool + */ + function is_UM_admin() { + global $current_screen; + + $screen_id = $current_screen->id; + if ( strstr( $screen_id, 'ultimatemember' ) || strstr( $screen_id, 'um_' ) || strstr( $screen_id, 'user' ) || strstr( $screen_id, 'profile' ) || $screen_id == 'nav-menus' ) return true; + + global $post; + if ( isset( $post->post_type ) ) return true; + + global $tax; + if ( isset( $tax->name ) ) return true; + + return false; + } + + + /** + * Adds class to our admin pages + * + * @param $classes + * + * @return string + */ + function admin_body_class( $classes ) { + if ( $this->is_UM_admin() ) { + return "$classes um-admin"; + } + return $classes; + } + + + /** + * Enqueue scripts and styles + */ + function admin_enqueue_scripts() { + if ( $this->is_UM_admin() ) { + + /*if ( get_post_type() != 'shop_order' ) { UM()->enqueue()->wp_enqueue_scripts(); }*/ - $this->load_functions(); - $this->load_global_css(); - $this->load_form(); - $this->load_forms(); - $this->load_modal(); - $this->load_dashboard(); - $this->load_settings(); - $this->load_field(); - $this->load_builder(); - $this->load_css(); - $this->load_core_wp(); - $this->load_ajax_js(); - $this->load_custom_scripts(); - $this->load_fonticons(); - $this->load_localize_scripts(); + $this->load_functions(); + $this->load_global_css(); + $this->load_form(); + $this->load_forms(); + $this->load_modal(); + $this->load_dashboard(); + $this->load_settings(); + $this->load_field(); + $this->load_builder(); + $this->load_css(); + $this->load_core_wp(); + $this->load_ajax_js(); + $this->load_custom_scripts(); + $this->load_fonticons(); + $this->load_localize_scripts(); - //scripts for frontend preview - UM()->enqueue()->load_imagecrop(); - UM()->enqueue()->load_css(); - UM()->enqueue()->load_tipsy(); - UM()->enqueue()->load_modal(); - UM()->enqueue()->load_responsive(); + //scripts for frontend preview + UM()->enqueue()->load_imagecrop(); + UM()->enqueue()->load_css(); + UM()->enqueue()->load_tipsy(); + UM()->enqueue()->load_modal(); + UM()->enqueue()->load_responsive(); - wp_register_style('um_default_css', um_url . 'assets/css/um-old-default.css', '', ultimatemember_version, 'all' ); - wp_enqueue_style('um_default_css'); + wp_register_style( 'um_default_css', um_url . 'assets/css/um-old-default.css', '', ultimatemember_version, 'all' ); + wp_enqueue_style( 'um_default_css' ); - if ( is_rtl() ) { - wp_register_style( 'um_admin_rtl', $this->css_url . 'um-admin-rtl.css' ); - wp_enqueue_style( 'um_admin_rtl' ); - } + if ( is_rtl() ) { + wp_register_style( 'um_admin_rtl', $this->css_url . 'um-admin-rtl.css' ); + wp_enqueue_style( 'um_admin_rtl' ); + } - } else { + } else { - $this->load_global_css(); + $this->load_global_css(); - } + } - } + } - } + } } \ No newline at end of file diff --git a/includes/admin/core/class-admin-forms.php b/includes/admin/core/class-admin-forms.php index a00f2cb6..fcd080a3 100644 --- a/includes/admin/core/class-admin-forms.php +++ b/includes/admin/core/class-admin-forms.php @@ -5,1025 +5,1135 @@ namespace um\admin\core; if ( ! defined( 'ABSPATH' ) ) exit; if ( ! class_exists( 'Admin_Forms' ) ) { - class Admin_Forms { - - var $form_data; - - /** - * Admin_Forms constructor. - * @param bool $form_data - */ - function __construct( $form_data = false ) { - - if ( $form_data ) - $this->form_data = $form_data; - - } - /** - * Render form - * - * - * @param bool $echo - * @return string - */ - function render_form( $echo = true ) { - - if ( empty( $this->form_data['fields'] ) ) - return ''; - - $class = 'form-table um-form-table ' . ( ! empty( $this->form_data['class'] ) ? $this->form_data['class'] : '' ); - $class_attr = ' class="' . $class . '" '; - - ob_start(); - - foreach ( $this->form_data['fields'] as $field_data ) { - if ( isset( $field_data['type'] ) && 'hidden' == $field_data['type'] ) - echo $this->render_form_row( $field_data ); - } + /** + * Class Admin_Forms + * @package um\admin\core + */ + class Admin_Forms { - if ( empty( $this->form_data['without_wrapper'] ) ) { ?> - - > - - - form_data['fields'] as $field_data ) { - if ( isset( $field_data['type'] ) && 'hidden' != $field_data['type'] ) - echo $this->render_form_row( $field_data ); - } - - if ( empty( $this->form_data['without_wrapper'] ) ) { ?> - - -
- - form_data = $form_data; + } + } - if ( empty( $data['type'] ) ) - return ''; - if ( !empty( $data['value'] ) && $data['type'] != 'email_template' ) { - $data['value'] = wp_unslash( $data['value'] ); + /** + * Render form + * + * + * @param bool $echo + * @return string + */ + function render_form( $echo = true ) { - /*for multi_text*/ - if ( ! is_array( $data['value'] ) && $data['type'] != 'wp_editor' ) { - $data['value'] = esc_attr( $data['value'] ); - } - } + if ( empty( $this->form_data['fields'] ) ) + return ''; - $conditional = ! empty( $data['conditional'] ) ? 'data-conditional="' . esc_attr( json_encode( $data['conditional'] ) ) . '"' : ''; - $prefix_attr = ! empty( $this->form_data['prefix_id'] ) ? ' data-prefix="' . $this->form_data['prefix_id'] . '" ' : ''; + $class = 'form-table um-form-table ' . ( ! empty( $this->form_data['class'] ) ? $this->form_data['class'] : '' ); + $class_attr = ' class="' . $class . '" '; - $type_attr = ' data-field_type="' . $data['type'] . '" '; + ob_start(); - $html = ''; - if ( $data['type'] != 'hidden' ) { + foreach ( $this->form_data['fields'] as $field_data ) { + if ( isset( $field_data['type'] ) && 'hidden' == $field_data['type'] ) + echo $this->render_form_row( $field_data ); + } - if ( ! empty( $this->form_data['div_line'] ) ) { - if ( strpos( $this->form_data['class'], 'um-top-label' ) !== false ) { + if ( empty( $this->form_data['without_wrapper'] ) ) { ?> - $html .= '
' . $this->render_field_label( $data ); + > + - if ( method_exists( $this, 'render_' . $data['type'] ) ) { + form_data['fields'] as $field_data ) { + if ( isset( $field_data['type'] ) && 'hidden' != $field_data['type'] ) + echo $this->render_form_row( $field_data ); + } - } else { + if ( empty( $this->form_data['without_wrapper'] ) ) { ?> - $html .= $this->render_field_by_hook( $data ); + +
- } + ' . $data['description'] . '

'; + if ( $echo ) { + ob_get_flush(); + return ''; + } else { + return ob_get_clean(); + } + } - $html .= '
'; - } else { + /** + * @param array $data + * + * @return string + */ + function render_form_row( $data ) { - if ( ! empty( $data['without_label'] ) ) { + if ( empty( $data['type'] ) ) + return ''; - $html .= '
'; + if ( !empty( $data['value'] ) && $data['type'] != 'email_template' ) { + $data['value'] = wp_unslash( $data['value'] ); - if ( method_exists( $this, 'render_' . $data['type'] ) ) { + /*for multi_text*/ + if ( ! is_array( $data['value'] ) && $data['type'] != 'wp_editor' ) { + $data['value'] = esc_attr( $data['value'] ); + } + } - $html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data ); + $conditional = ! empty( $data['conditional'] ) ? 'data-conditional="' . esc_attr( json_encode( $data['conditional'] ) ) . '"' : ''; + $prefix_attr = ! empty( $this->form_data['prefix_id'] ) ? ' data-prefix="' . $this->form_data['prefix_id'] . '" ' : ''; - } else { + $type_attr = ' data-field_type="' . $data['type'] . '" '; - $html .= $this->render_field_by_hook( $data ); + $html = ''; + if ( $data['type'] != 'hidden' ) { - } + if ( ! empty( $this->form_data['div_line'] ) ) { - if ( ! empty( $data['description'] ) ) - $html .= '

' . $data['description'] . '

'; + if ( strpos( $this->form_data['class'], 'um-top-label' ) !== false ) { - $html .= '
'; + $html .= '
' . $this->render_field_label( $data ); - } else { + if ( method_exists( $this, 'render_' . $data['type'] ) ) { - $html .= '
' . $this->render_field_label( $data ); + $html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data ); - if ( method_exists( $this, 'render_' . $data['type'] ) ) { + } else { - $html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data ); + $html .= $this->render_field_by_hook( $data ); - } else { + } - $html .= $this->render_field_by_hook( $data ); + if ( ! empty( $data['description'] ) ) + $html .= '

' . $data['description'] . '

'; - } + $html .= '
'; - if ( ! empty( $data['description'] ) ) - $html .= '

' . $data['description'] . '

'; + } else { - $html .= '
'; + if ( ! empty( $data['without_label'] ) ) { - } - } + $html .= '
'; - } else { - if ( strpos( $this->form_data['class'], 'um-top-label' ) !== false ) { + if ( method_exists( $this, 'render_' . $data['type'] ) ) { - $html .= ' + $html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data ); + + } else { + + $html .= $this->render_field_by_hook( $data ); + + } + + if ( ! empty( $data['description'] ) ) + $html .= '

' . $data['description'] . '

'; + + $html .= '
'; + + } else { + + $html .= '
' . $this->render_field_label( $data ); + + if ( method_exists( $this, 'render_' . $data['type'] ) ) { + + $html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data ); + + } else { + + $html .= $this->render_field_by_hook( $data ); + + } + + if ( ! empty( $data['description'] ) ) + $html .= '

' . $data['description'] . '

'; + + $html .= '
'; + + } + } + + } else { + if ( strpos( $this->form_data['class'], 'um-top-label' ) !== false ) { + + $html .= ' ' . $this->render_field_label( $data ); - if ( method_exists( $this, 'render_' . $data['type'] ) ) { + if ( method_exists( $this, 'render_' . $data['type'] ) ) { - $html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data ); + $html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data ); - } else { + } else { - $html .= $this->render_field_by_hook( $data ); + $html .= $this->render_field_by_hook( $data ); - } + } - if ( ! empty( $data['description'] ) ) - $html .= '

' . $data['description'] . '

'; + if ( ! empty( $data['description'] ) ) + $html .= '

' . $data['description'] . '

'; - $html .= ''; + $html .= ''; - } else { + } else { - if ( ! empty( $data['without_label'] ) ) { + if ( ! empty( $data['without_label'] ) ) { - $html .= ' + $html .= ' '; - if ( method_exists( $this, 'render_' . $data['type'] ) ) { + if ( method_exists( $this, 'render_' . $data['type'] ) ) { - $html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data ); + $html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data ); - } else { + } else { - $html .= $this->render_field_by_hook( $data ); + $html .= $this->render_field_by_hook( $data ); - } + } - if ( ! empty( $data['description'] ) ) - $html .= '

' . $data['description'] . '

'; + if ( ! empty( $data['description'] ) ) + $html .= '

' . $data['description'] . '

'; - $html .= ''; + $html .= ''; - } else { + } else { - $html .= ' + $html .= ' ' . $this->render_field_label( $data ) . ' '; - if ( method_exists( $this, 'render_' . $data['type'] ) ) { + if ( method_exists( $this, 'render_' . $data['type'] ) ) { - $html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data ); + $html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data ); - } else { + } else { - $html .= $this->render_field_by_hook( $data ); + $html .= $this->render_field_by_hook( $data ); - } + } - if ( ! empty( $data['description'] ) ) - $html .= '

' . $data['description'] . '

'; + if ( ! empty( $data['description'] ) ) + $html .= '

' . $data['description'] . '

'; - $html .= ''; + $html .= ''; - } - } - } + } + } + } - } else { - if ( method_exists( $this, 'render_' . $data['type'] ) ) { + } else { + if ( method_exists( $this, 'render_' . $data['type'] ) ) { - $html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data ); + $html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data ); - } else { + } else { - $html .= $this->render_field_by_hook( $data ); + $html .= $this->render_field_by_hook( $data ); - } - } + } + } - return $html; - } + return $html; + } - function render_field_by_hook( $data ) { - /** - * UM hook - * - * @type filter - * @title um_render_field_type_{$type} - * @description Render admin form field by hook - * @input_vars - * [{"var":"$html","type":"string","desc":"Field's HTML"}, - * {"var":"$data","type":"array","desc":"Field's data"}, - * {"var":"$form_data","type":"array","desc":"Form data"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_render_field_type_{$type}', 'function_name', 10, 3 ); - * @example - * - */ - return apply_filters( 'um_render_field_type_' . $data['type'], '', $data, $this->form_data ); - } + /** + * @param $data + * + * @return mixed|void + */ + function render_field_by_hook( $data ) { + /** + * UM hook + * + * @type filter + * @title um_render_field_type_{$type} + * @description Render admin form field by hook + * @input_vars + * [{"var":"$html","type":"string","desc":"Field's HTML"}, + * {"var":"$data","type":"array","desc":"Field's data"}, + * {"var":"$form_data","type":"array","desc":"Form data"}] + * @change_log + * ["Since: 2.0"] + * @usage add_filter( 'um_render_field_type_{$type}', 'function_name', 10, 3 ); + * @example + * + */ + return apply_filters( 'um_render_field_type_' . $data['type'], '', $data, $this->form_data ); + } - function render_field_label( $data ) { - if ( empty( $data['label'] ) ) - return false; + /** + * @param $data + * + * @return bool|string + */ + function render_field_label( $data ) { + if ( empty( $data['label'] ) ) + return false; - $id = ! empty( $data['id1'] ) ? $data['id1'] : $data['id']; - $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $id; - $for_attr = ' for="' . $id . '" '; + $id = ! empty( $data['id1'] ) ? $data['id1'] : $data['id']; + $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $id; + $for_attr = ' for="' . $id . '" '; - $label = $data['label']; - $tooltip = ! empty( $data['tooltip'] ) ? UM()->tooltip( $data['tooltip'], false, false ) : ''; + $label = $data['label']; + $tooltip = ! empty( $data['tooltip'] ) ? UM()->tooltip( $data['tooltip'], false, false ) : ''; - return ""; - } + return ""; + } - function render_hidden( $field_data ) { + /** + * @param $field_data + * + * @return bool|string + */ + function render_hidden( $field_data ) { - if ( empty( $field_data['id'] ) ) - return false; + if ( empty( $field_data['id'] ) ) + return false; - $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; - $id_attr = ' id="' . $id . '" '; + $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; + $id_attr = ' id="' . $id . '" '; - $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; - $class_attr = ' class="um-forms-field ' . $class . '" '; + $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; + $class_attr = ' class="um-forms-field ' . $class . '" '; - $data = array( - 'field_id' => $field_data['id'] - ); + $data = array( + 'field_id' => $field_data['id'] + ); - $data_attr = ''; - foreach ( $data as $key => $value ) { - $data_attr .= " data-{$key}=\"{$value}\" "; - } + $data_attr = ''; + foreach ( $data as $key => $value ) { + $data_attr .= " data-{$key}=\"{$value}\" "; + } - $name = $field_data['id']; - $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; - $name_attr = ' name="' . $name . '" '; + $name = $field_data['id']; + $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; + $name_attr = ' name="' . $name . '" '; - $value = $this->get_field_value( $field_data ); - $value_attr = ' value="' . $value . '" '; + $value = $this->get_field_value( $field_data ); + $value_attr = ' value="' . $value . '" '; - $html = ""; + $html = ""; - return $html; - } + return $html; + } - function render_text( $field_data ) { + /** + * @param $field_data + * + * @return bool|string + */ + function render_text( $field_data ) { - if ( empty( $field_data['id'] ) ) - return false; + if ( empty( $field_data['id'] ) ) + return false; - $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; - $id_attr = ' id="' . $id . '" '; + $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; + $id_attr = ' id="' . $id . '" '; - $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; - $class .= ! empty( $field_data['size'] ) ? 'um-' . $field_data['size'] . '-field' : 'um-long-field'; - $class_attr = ' class="um-forms-field ' . $class . '" '; + $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; + $class .= ! empty( $field_data['size'] ) ? 'um-' . $field_data['size'] . '-field' : 'um-long-field'; + $class_attr = ' class="um-forms-field ' . $class . '" '; - $data = array( - 'field_id' => $field_data['id'] - ); + $data = array( + 'field_id' => $field_data['id'] + ); - $data_attr = ''; - foreach ( $data as $key => $value ) { - $data_attr .= " data-{$key}=\"{$value}\" "; - } + $data_attr = ''; + foreach ( $data as $key => $value ) { + $data_attr .= " data-{$key}=\"{$value}\" "; + } - $placeholder_attr = ! empty( $field_data['placeholder'] ) ? ' placeholder="' . $field_data['placeholder'] . '"' : ''; + $placeholder_attr = ! empty( $field_data['placeholder'] ) ? ' placeholder="' . $field_data['placeholder'] . '"' : ''; - $name = $field_data['id']; - $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; - $name_attr = ' name="' . $name . '" '; + $name = $field_data['id']; + $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; + $name_attr = ' name="' . $name . '" '; - $value = $this->get_field_value( $field_data ); - $value_attr = ' value="' . $value . '" '; + $value = $this->get_field_value( $field_data ); + $value_attr = ' value="' . $value . '" '; - $html = ""; + $html = ""; - return $html; - } + return $html; + } - function render_color( $field_data ) { + /** + * @param $field_data + * + * @return bool|string + */ + function render_color( $field_data ) { - if ( empty( $field_data['id'] ) ) - return false; + if ( empty( $field_data['id'] ) ) + return false; - $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; - $id_attr = ' id="' . $id . '" '; + $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; + $id_attr = ' id="' . $id . '" '; - $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; - $class .= ! empty( $field_data['size'] ) ? ' um-' . $field_data['size'] . '-field ' : ' um-long-field '; - $class .= ' um-admin-colorpicker '; - $class_attr = ' class="um-forms-field ' . $class . '" '; + $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; + $class .= ! empty( $field_data['size'] ) ? ' um-' . $field_data['size'] . '-field ' : ' um-long-field '; + $class .= ' um-admin-colorpicker '; + $class_attr = ' class="um-forms-field ' . $class . '" '; - $data = array( - 'field_id' => $field_data['id'] - ); + $data = array( + 'field_id' => $field_data['id'] + ); - $data_attr = ''; - foreach ( $data as $key => $value ) { - $data_attr .= " data-{$key}=\"{$value}\" "; - } + $data_attr = ''; + foreach ( $data as $key => $value ) { + $data_attr .= " data-{$key}=\"{$value}\" "; + } - $placeholder_attr = ! empty( $field_data['placeholder'] ) ? ' placeholder="' . $field_data['placeholder'] . '"' : ''; + $placeholder_attr = ! empty( $field_data['placeholder'] ) ? ' placeholder="' . $field_data['placeholder'] . '"' : ''; - $name = $field_data['id']; - $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; - $name_attr = ' name="' . $name . '" '; + $name = $field_data['id']; + $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; + $name_attr = ' name="' . $name . '" '; - $value = $this->get_field_value( $field_data ); - $value_attr = ' value="' . $value . '" '; + $value = $this->get_field_value( $field_data ); + $value_attr = ' value="' . $value . '" '; - $html = ""; + $html = ""; - return $html; - } + return $html; + } - function render_icon( $field_data ) { + /** + * @param $field_data + * + * @return bool|string + */ + function render_icon( $field_data ) { - if ( empty( $field_data['id'] ) ) - return false; + if ( empty( $field_data['id'] ) ) + return false; - $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; - $id_attr = ' id="' . $id . '" '; + $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; + $id_attr = ' id="' . $id . '" '; - $name = $field_data['id']; - $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; - $name_attr = ' name="' . $name . '" '; + $name = $field_data['id']; + $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; + $name_attr = ' name="' . $name . '" '; - $value = $this->get_field_value( $field_data ); - $value_attr = ' value="' . $value . '" '; + $value = $this->get_field_value( $field_data ); + $value_attr = ' value="' . $value . '" '; - $html = '' . __( 'Choose Icon', 'ultimate-member' ) . ' + $html = '' . __( 'Choose Icon', 'ultimate-member' ) . ' '; - if ( ! empty( $value ) ) { - $html .= ''; - } else { - $html .= __( 'No Icon', 'ultimate-member' ); - } + if ( ! empty( $value ) ) { + $html .= ''; + } else { + $html .= __( 'No Icon', 'ultimate-member' ); + } - $html .= ''; + $html .= ''; - if ( get_post_meta( get_the_ID(), '_um_icon', true ) ) { - $html .= ''; - } else { - $html .= ''; - } + if ( get_post_meta( get_the_ID(), '_um_icon', true ) ) { + $html .= ''; + } else { + $html .= ''; + } - $html .= ''; + $html .= ''; - return $html; - } + return $html; + } - function render_datepicker( $field_data ) { + /** + * @param $field_data + * + * @return bool|string + */ + function render_datepicker( $field_data ) { - if ( empty( $field_data['id'] ) ) - return false; + if ( empty( $field_data['id'] ) ) + return false; - $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; - $id_attr = ' id="' . $id . '" '; + $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; + $id_attr = ' id="' . $id . '" '; - $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; - $class .= ! empty( $field_data['size'] ) ? 'um-' . $field_data['size'] . '-field' : 'um-long-field'; - $class_attr = ' class="um-forms-field ' . $class . '" '; + $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; + $class .= ! empty( $field_data['size'] ) ? 'um-' . $field_data['size'] . '-field' : 'um-long-field'; + $class_attr = ' class="um-forms-field ' . $class . '" '; - $data = array( - 'field_id' => $field_data['id'] - ); + $data = array( + 'field_id' => $field_data['id'] + ); - $data_attr = ''; - foreach ( $data as $key => $value ) { - $data_attr .= " data-{$key}=\"{$value}\" "; - } + $data_attr = ''; + foreach ( $data as $key => $value ) { + $data_attr .= " data-{$key}=\"{$value}\" "; + } - $placeholder_attr = ! empty( $field_data['placeholder'] ) ? ' placeholder="' . $field_data['placeholder'] . '"' : ''; + $placeholder_attr = ! empty( $field_data['placeholder'] ) ? ' placeholder="' . $field_data['placeholder'] . '"' : ''; - $name = $field_data['id']; - $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; - $name_attr = ' name="' . $name . '" '; + $name = $field_data['id']; + $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; + $name_attr = ' name="' . $name . '" '; - $value = $this->get_field_value( $field_data ); - $value_attr = ' value="' . $value . '" '; + $value = $this->get_field_value( $field_data ); + $value_attr = ' value="' . $value . '" '; - $html = ""; + $html = ""; - return $html; - } + return $html; + } - function render_inline_texts( $field_data ) { + /** + * @param $field_data + * + * @return bool|string + */ + function render_inline_texts( $field_data ) { - if ( empty( $field_data['id1'] ) ) - return false; + if ( empty( $field_data['id1'] ) ) + return false; - $i = 1; - $fields = array(); - while( ! empty( $field_data['id' . $i] ) ) { - $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id'. $i]; - $id_attr = ' id="' . $id . '" '; + $i = 1; + $fields = array(); + while( ! empty( $field_data['id' . $i] ) ) { + $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id'. $i]; + $id_attr = ' id="' . $id . '" '; - $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; - $class .= ! empty( $field_data['size'] ) ? 'um-' . $field_data['size'] . '-field' : 'um-long-field'; - $class_attr = ' class="um-forms-field ' . $class . '" '; + $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; + $class .= ! empty( $field_data['size'] ) ? 'um-' . $field_data['size'] . '-field' : 'um-long-field'; + $class_attr = ' class="um-forms-field ' . $class . '" '; - $data = array( - 'field_id' => $field_data['id'. $i] - ); + $data = array( + 'field_id' => $field_data['id'. $i] + ); - $data_attr = ''; - foreach ( $data as $key => $value ) { - $data_attr .= " data-{$key}=\"{$value}\" "; - } + $data_attr = ''; + foreach ( $data as $key => $value ) { + $data_attr .= " data-{$key}=\"{$value}\" "; + } - $placeholder_attr = ! empty( $field_data['placeholder'] ) ? ' placeholder="' . $field_data['placeholder'] . '"' : ''; + $placeholder_attr = ! empty( $field_data['placeholder'] ) ? ' placeholder="' . $field_data['placeholder'] . '"' : ''; - $name = $field_data['id'. $i]; - $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; - $name_attr = ' name="' . $name . '" '; + $name = $field_data['id'. $i]; + $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; + $name_attr = ' name="' . $name . '" '; - $value = $this->get_field_value( $field_data, $i ); + $value = $this->get_field_value( $field_data, $i ); - $value_attr = ' value="' . $value . '" '; + $value_attr = ' value="' . $value . '" '; - $fields[$i] = ""; + $fields[$i] = ""; - $i++; - } + $i++; + } - $html = vsprintf( $field_data['mask'], $fields ); + $html = vsprintf( $field_data['mask'], $fields ); - return $html; - } + return $html; + } - function render_textarea( $field_data ) { + /** + * @param $field_data + * + * @return bool|string + */ + function render_textarea( $field_data ) { - if ( empty( $field_data['id'] ) ) - return false; + if ( empty( $field_data['id'] ) ) + return false; - $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; - $id_attr = ' id="' . $id . '" '; + $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; + $id_attr = ' id="' . $id . '" '; - $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; - $class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field'; - $class_attr = ' class="um-forms-field ' . $class . '" '; + $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; + $class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field'; + $class_attr = ' class="um-forms-field ' . $class . '" '; - $data = array( - 'field_id' => $field_data['id'] - ); + $data = array( + 'field_id' => $field_data['id'] + ); - $data_attr = ''; - foreach ( $data as $key => $value ) { - $data_attr .= " data-{$key}=\"{$value}\" "; - } + $data_attr = ''; + foreach ( $data as $key => $value ) { + $data_attr .= " data-{$key}=\"{$value}\" "; + } - $rows = ! empty( $field_data['args']['textarea_rows'] ) ? ' rows="' . $field_data['args']['textarea_rows'] . '" ' : ''; + $rows = ! empty( $field_data['args']['textarea_rows'] ) ? ' rows="' . $field_data['args']['textarea_rows'] . '" ' : ''; - $name = $field_data['id']; - $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; - $name_attr = ' name="' . $name . '" '; + $name = $field_data['id']; + $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; + $name_attr = ' name="' . $name . '" '; - $value = $this->get_field_value( $field_data ); + $value = $this->get_field_value( $field_data ); - $html = ""; + $html = ""; - return $html; - } + return $html; + } - function render_wp_editor( $field_data ) { + /** + * @param $field_data + * + * @return bool|string + */ + function render_wp_editor( $field_data ) { - if ( empty( $field_data['id'] ) ) - return false; + if ( empty( $field_data['id'] ) ) + return false; - $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; + $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; - $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; - $class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field'; + $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; + $class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field'; - $data = array( - 'field_id' => $field_data['id'] - ); + $data = array( + 'field_id' => $field_data['id'] + ); - $data_attr = ''; - foreach ( $data as $key => $value ) { - $data_attr .= " data-{$key}=\"{$value}\" "; - } + $data_attr = ''; + foreach ( $data as $key => $value ) { + $data_attr .= " data-{$key}=\"{$value}\" "; + } - $name = $field_data['id']; - $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; + $name = $field_data['id']; + $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; - $value = $this->get_field_value( $field_data ); + $value = $this->get_field_value( $field_data ); - ob_start(); - wp_editor( $value, - $id, - array( - 'textarea_name' => $name, - 'textarea_rows' => 20, - 'editor_height' => 425, - 'wpautop' => false, - 'media_buttons' => false, - 'editor_class' => $class - ) - ); + ob_start(); + wp_editor( $value, + $id, + array( + 'textarea_name' => $name, + 'textarea_rows' => 20, + 'editor_height' => 425, + 'wpautop' => false, + 'media_buttons' => false, + 'editor_class' => $class + ) + ); - $html = ob_get_clean(); + $html = ob_get_clean(); - return $html; - } + return $html; + } - function render_checkbox( $field_data ) { + /** + * @param $field_data + * + * @return bool|string + */ + function render_checkbox( $field_data ) { - if ( empty( $field_data['id'] ) ) - return false; + if ( empty( $field_data['id'] ) ) + return false; - $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; - $id_attr = ' id="' . $id . '" '; - $id_attr_hidden = ' id="' . $id . '_hidden" '; + $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; + $id_attr = ' id="' . $id . '" '; + $id_attr_hidden = ' id="' . $id . '_hidden" '; - $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; - $class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field'; - $class_attr = ' class="um-forms-field ' . $class . '" '; + $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; + $class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field'; + $class_attr = ' class="um-forms-field ' . $class . '" '; - $data = array( - 'field_id' => $field_data['id'] - ); + $data = array( + 'field_id' => $field_data['id'] + ); - $data_attr = ''; - foreach ( $data as $key => $value ) { - $data_attr .= " data-{$key}=\"{$value}\" "; - } + $data_attr = ''; + foreach ( $data as $key => $value ) { + $data_attr .= " data-{$key}=\"{$value}\" "; + } - $name = $field_data['id']; - $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; - $name_attr = ' name="' . $name . '" '; + $name = $field_data['id']; + $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; + $name_attr = ' name="' . $name . '" '; - $value = $this->get_field_value( $field_data ); + $value = $this->get_field_value( $field_data ); - $html = " + $html = " "; - return $html; - } + return $html; + } - function render_select( $field_data ) { + /** + * @param $field_data + * + * @return bool|string + */ + function render_select( $field_data ) { - if ( empty( $field_data['id'] ) ) - return false; + if ( empty( $field_data['id'] ) ) + return false; - $multiple = ! empty( $field_data['multi'] ) ? 'multiple' : ''; + $multiple = ! empty( $field_data['multi'] ) ? 'multiple' : ''; - $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; - $id_attr = ' id="' . $id . '" '; + $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; + $id_attr = ' id="' . $id . '" '; - $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; - $class .= ! empty( $field_data['size'] ) ? 'um-' . $field_data['size'] . '-field' : 'um-long-field'; - $class_attr = ' class="um-forms-field ' . $class . '" '; + $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; + $class .= ! empty( $field_data['size'] ) ? 'um-' . $field_data['size'] . '-field' : 'um-long-field'; + $class_attr = ' class="um-forms-field ' . $class . '" '; - $data = array( - 'field_id' => $field_data['id'] - ); + $data = array( + 'field_id' => $field_data['id'] + ); - $data_attr = ''; - foreach ( $data as $key => $value ) { - $data_attr .= " data-{$key}=\"{$value}\" "; - } + $data_attr = ''; + foreach ( $data as $key => $value ) { + $data_attr .= " data-{$key}=\"{$value}\" "; + } - $name = $field_data['id']; - $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; - $hidden_name_attr = ' name="' . $name . '" '; - $name = $name . ( ! empty( $field_data['multi'] ) ? '[]' : '' ); - $name_attr = ' name="' . $name . '" '; + $name = $field_data['id']; + $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; + $hidden_name_attr = ' name="' . $name . '" '; + $name = $name . ( ! empty( $field_data['multi'] ) ? '[]' : '' ); + $name_attr = ' name="' . $name . '" '; - $value = $this->get_field_value( $field_data ); + $value = $this->get_field_value( $field_data ); - $options = ''; - foreach ( $field_data['options'] as $key=>$option ) { - if ( ! empty( $field_data['multi'] ) ) { + $options = ''; + foreach ( $field_data['options'] as $key=>$option ) { + if ( ! empty( $field_data['multi'] ) ) { - if ( ! is_array( $value ) || empty( $value ) ) - $value = array(); + if ( ! is_array( $value ) || empty( $value ) ) + $value = array(); - $options .= ''; - } else { - $options .= ''; - } - } + $options .= ''; + } else { + $options .= ''; + } + } - $hidden = ''; - if ( ! empty( $multiple ) ) { - $hidden = ""; - } - $html = "$hidden"; + $hidden = ''; + if ( ! empty( $multiple ) ) { + $hidden = ""; + } + $html = "$hidden"; - return $html; - } + return $html; + } - function render_multi_selects( $field_data ) { + /** + * @param $field_data + * + * @return bool|string + */ + function render_multi_selects( $field_data ) { - if ( empty( $field_data['id'] ) ) - return false; + if ( empty( $field_data['id'] ) ) + return false; - $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; + $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; - $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; - $class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field'; - $class_attr = ' class="um-forms-field ' . $class . '" '; + $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; + $class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field'; + $class_attr = ' class="um-forms-field ' . $class . '" '; - $data = array( - 'field_id' => $field_data['id'], - 'id_attr' => $id - ); + $data = array( + 'field_id' => $field_data['id'], + 'id_attr' => $id + ); - $data_attr = ''; - foreach ( $data as $key => $value ) { - $data_attr .= " data-{$key}=\"{$value}\" "; - } + $data_attr = ''; + foreach ( $data as $key => $value ) { + $data_attr .= " data-{$key}=\"{$value}\" "; + } - $name = $field_data['id']; - $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; - $name = "{$name}[]"; - $name_attr = ' name="' . $name . '" '; + $name = $field_data['id']; + $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; + $name = "{$name}[]"; + $name_attr = ' name="' . $name . '" '; - $values = $this->get_field_value( $field_data ); + $values = $this->get_field_value( $field_data ); - $options = ''; - foreach ( $field_data['options'] as $key=>$option ) { - $options .= ''; - } + $options = ''; + foreach ( $field_data['options'] as $key=>$option ) { + $options .= ''; + } - $html = ""; - $html .= "{$field_data['add_text']}"; - return $html; - } + return $html; + } - function render_multi_checkbox( $field_data ) { + /** + * @param $field_data + * + * @return bool|string + */ + function render_multi_checkbox( $field_data ) { - if ( empty( $field_data['id'] ) ) - return false; + if ( empty( $field_data['id'] ) ) + return false; - $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; + $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; - $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; - $class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field'; - $class_attr = ' class="um-forms-field ' . $class . '" '; + $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; + $class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field'; + $class_attr = ' class="um-forms-field ' . $class . '" '; - $name = $field_data['id']; - $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; + $name = $field_data['id']; + $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; - $values = $this->get_field_value( $field_data ); + $values = $this->get_field_value( $field_data ); - $i = 0; - $html = ''; + $i = 0; + $html = ''; - $columns = ( ! empty( $field_data['columns'] ) && is_numeric( $field_data['columns'] ) ) ? $field_data['columns'] : 1; - while ( $i < $columns ) { - $per_page = ceil( count( $field_data['options'] ) / $columns ); - $section_fields_per_page = array_slice( $field_data['options'], $i*$per_page, $per_page ); - $html .= ''; + $columns = ( ! empty( $field_data['columns'] ) && is_numeric( $field_data['columns'] ) ) ? $field_data['columns'] : 1; + while ( $i < $columns ) { + $per_page = ceil( count( $field_data['options'] ) / $columns ); + $section_fields_per_page = array_slice( $field_data['options'], $i*$per_page, $per_page ); + $html .= ''; - foreach ( $section_fields_per_page as $k => $title ) { - $id_attr = ' id="' . $id . '_' . $k . '" '; - $for_attr = ' for="' . $id . '_' . $k . '" '; - $name_attr = ' name="' . $name . '[' . $k . ']" '; + foreach ( $section_fields_per_page as $k => $title ) { + $id_attr = ' id="' . $id . '_' . $k . '" '; + $for_attr = ' for="' . $id . '_' . $k . '" '; + $name_attr = ' name="' . $name . '[' . $k . ']" '; - $html .= "'; - $i++; - } + $html .= ''; + $i++; + } - return $html; - } + return $html; + } - function render_multi_text( $field_data ) { + /** + * @param $field_data + * + * @return bool|string + */ + function render_multi_text( $field_data ) { - if ( empty( $field_data['id'] ) ) - return false; + if ( empty( $field_data['id'] ) ) + return false; - $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; + $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; - $size = ! empty( $field_data['size'] ) ? 'um-' . $field_data['size'] . '-field' : 'um-long-field'; + $size = ! empty( $field_data['size'] ) ? 'um-' . $field_data['size'] . '-field' : 'um-long-field'; - $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; - $class_attr = ' class="um-forms-field ' . $class . '" '; + $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; + $class_attr = ' class="um-forms-field ' . $class . '" '; - $data = array( - 'field_id' => $field_data['id'], - 'id_attr' => $id - ); + $data = array( + 'field_id' => $field_data['id'], + 'id_attr' => $id + ); - $data_attr = ''; - foreach ( $data as $key => $value ) { - $data_attr .= " data-{$key}=\"{$value}\" "; - } + $data_attr = ''; + foreach ( $data as $key => $value ) { + $data_attr .= " data-{$key}=\"{$value}\" "; + } - $name = $field_data['id']; - $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; - $name = "{$name}[]"; - $name_attr = ' name="' . $name . '" '; + $name = $field_data['id']; + $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; + $name = "{$name}[]"; + $name_attr = ' name="' . $name . '" '; - $values = $this->get_field_value( $field_data ); + $values = $this->get_field_value( $field_data ); - $html = ""; - $html .= "{$field_data['add_text']}"; - return $html; - } + return $html; + } - function render_media( $field_data ) { + /** + * @param $field_data + * + * @return bool|string + */ + function render_media( $field_data ) { - if ( empty( $field_data['id'] ) ) - return false; + if ( empty( $field_data['id'] ) ) + return false; - $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; + $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; - $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; - $class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field'; - $class_attr = ' class="um-forms-field um-media-upload-data-url ' . $class . '"'; + $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; + $class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field'; + $class_attr = ' class="um-forms-field um-media-upload-data-url ' . $class . '"'; - $data = array( - 'field_id' => $field_data['id'], - ); + $data = array( + 'field_id' => $field_data['id'], + ); - if ( ! empty( $field_data['default']['url'] ) ) - $data['default'] = esc_attr( $field_data['default']['url'] ); + if ( ! empty( $field_data['default']['url'] ) ) + $data['default'] = esc_attr( $field_data['default']['url'] ); - $data_attr = ''; - foreach ( $data as $key => $value ) { - $data_attr .= " data-{$key}=\"{$value}\" "; - } + $data_attr = ''; + foreach ( $data as $key => $value ) { + $data_attr .= " data-{$key}=\"{$value}\" "; + } - $name = $field_data['id']; - $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; + $name = $field_data['id']; + $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; - $value = $this->get_field_value( $field_data ); + $value = $this->get_field_value( $field_data ); - $upload_frame_title = ! empty( $field_data['upload_frame_title'] ) ? $field_data['upload_frame_title'] : __( 'Select media', 'ultimate-member' ); + $upload_frame_title = ! empty( $field_data['upload_frame_title'] ) ? $field_data['upload_frame_title'] : __( 'Select media', 'ultimate-member' ); - $image_id = ! empty( $value['id'] ) ? $value['id'] : ''; - $image_width = ! empty( $value['width'] ) ? $value['width'] : ''; - $image_height = ! empty( $value['height'] ) ? $value['height'] : ''; - $image_thumbnail = ! empty( $value['thumbnail'] ) ? $value['thumbnail'] : ''; - $image_url = ! empty( $value['url'] ) ? $value['url'] : ''; + $image_id = ! empty( $value['id'] ) ? $value['id'] : ''; + $image_width = ! empty( $value['width'] ) ? $value['width'] : ''; + $image_height = ! empty( $value['height'] ) ? $value['height'] : ''; + $image_thumbnail = ! empty( $value['thumbnail'] ) ? $value['thumbnail'] : ''; + $image_url = ! empty( $value['url'] ) ? $value['url'] : ''; - $html = "
" . - "" . - "" . - "" . - "" . - ""; + $html = "
" . + "" . + "" . + "" . + "" . + ""; - if ( ! isset( $field_data['preview'] ) || $field_data['preview'] !== false ) { - $html .= '
'; - } + if ( ! isset( $field_data['preview'] ) || $field_data['preview'] !== false ) { + $html .= '
'; + } - if ( ! empty( $field_data['url'] ) ) { - $html .= '
'; - } + if ( ! empty( $field_data['url'] ) ) { + $html .= '
'; + } - $html .= ' + $html .= '
'; - return $html; - } + return $html; + } - function render_email_template( $field_data ) { - if ( empty( $field_data['id'] ) ) - return false; + /** + * @param $field_data + * + * @return bool|string + */ + function render_email_template( $field_data ) { + if ( empty( $field_data['id'] ) ) + return false; - $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; + $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; - $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; - $class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field'; + $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; + $class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field'; - $data = array( - 'field_id' => $field_data['id'] - ); + $data = array( + 'field_id' => $field_data['id'] + ); - $data_attr = ''; - foreach ( $data as $key => $value ) { - $data_attr .= " data-{$key}=\"{$value}\" "; - } + $data_attr = ''; + foreach ( $data as $key => $value ) { + $data_attr .= " data-{$key}=\"{$value}\" "; + } - $name = $field_data['id']; - $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; + $name = $field_data['id']; + $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; - $value = $this->get_field_value( $field_data ); + $value = $this->get_field_value( $field_data ); - ob_start(); ?> + ob_start(); ?> -
- - + - $name, - 'textarea_rows' => 20, - 'editor_height' => 425, - 'wpautop' => false, - 'media_buttons' => false, - 'editor_class' => $class - ) - ); ?> + $name, + 'textarea_rows' => 20, + 'editor_height' => 425, + 'wpautop' => false, + 'media_buttons' => false, + 'editor_class' => $class + ) + ); ?> -
+
- form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; - $id_attr = ' id="' . $id . '" '; + $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id']; + $id_attr = ' id="' . $id . '" '; - $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; - $class_attr = ' class="um-forms-field button ' . $class . '" '; + $class = ! empty( $field_data['class'] ) ? $field_data['class'] : ''; + $class_attr = ' class="um-forms-field button ' . $class . '" '; - $data = array( - 'field_id' => $field_data['id'] - ); + $data = array( + 'field_id' => $field_data['id'] + ); - $data_attr = ''; - foreach ( $data as $key => $value ) { - $data_attr .= " data-{$key}=\"{$value}\" "; - } + $data_attr = ''; + foreach ( $data as $key => $value ) { + $data_attr .= " data-{$key}=\"{$value}\" "; + } - $name = $field_data['id']; - $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; - $name_attr = ' name="' . $name . '" '; + $name = $field_data['id']; + $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name; + $name_attr = ' name="' . $name . '" '; - $value = $this->get_field_value( $field_data ); - $value_attr = ' value="' . $value . '" '; + $value = $this->get_field_value( $field_data ); + $value_attr = ' value="' . $value . '" '; - $html = "
"; + $html = "
"; - return $html; - } + return $html; + } - function render_info_text( $field_data ) { - return $field_data['value']; - } + /** + * @param $field_data + * + * @return mixed + */ + function render_info_text( $field_data ) { + return $field_data['value']; + } - /** - * Get field value - * - * @param array $field_data - * @param string $i - * @return string|array - */ - function get_field_value( $field_data, $i = '' ) { - $default = ( $field_data['type'] == 'multi_checkbox' ) ? array() : ''; - $default = isset( $field_data['default' . $i] ) ? $field_data['default' . $i] : $default; + /** + * Get field value + * + * @param array $field_data + * @param string $i + * @return string|array + */ + function get_field_value( $field_data, $i = '' ) { + $default = ( $field_data['type'] == 'multi_checkbox' ) ? array() : ''; + $default = isset( $field_data['default' . $i] ) ? $field_data['default' . $i] : $default; - if ( $field_data['type'] == 'checkbox' || $field_data['type'] == 'multi_checkbox' ) { - $value = ( isset( $field_data['value' . $i] ) && '' !== $field_data['value' . $i] ) ? $field_data['value' . $i] : $default; - } else { - $value = isset( $field_data['value' . $i] ) ? $field_data['value' . $i] : $default; - } + if ( $field_data['type'] == 'checkbox' || $field_data['type'] == 'multi_checkbox' ) { + $value = ( isset( $field_data['value' . $i] ) && '' !== $field_data['value' . $i] ) ? $field_data['value' . $i] : $default; + } else { + $value = isset( $field_data['value' . $i] ) ? $field_data['value' . $i] : $default; + } - $value = is_string( $value ) ? stripslashes( $value ) : $value; + $value = is_string( $value ) ? stripslashes( $value ) : $value; - return $value; - } - } + return $value; + } + } } \ No newline at end of file diff --git a/includes/admin/core/class-admin-metabox.php b/includes/admin/core/class-admin-metabox.php index f950baad..ccb35a3e 100644 --- a/includes/admin/core/class-admin-metabox.php +++ b/includes/admin/core/class-admin-metabox.php @@ -695,7 +695,7 @@ if ( ! class_exists( 'Admin_Metabox' ) ) { $roles_metaboxes = array( array( - 'id' => 'um-admin-form-admin', + 'id' => 'um-admin-form-admin-permissions', 'title' => __( 'Administrative Permissions', 'ultimate-member' ), 'callback' => $callback, 'screen' => 'um_role_meta', diff --git a/includes/admin/core/list-tables/emails-list-table.php b/includes/admin/core/list-tables/emails-list-table.php index e51b8fe4..2b23a453 100644 --- a/includes/admin/core/list-tables/emails-list-table.php +++ b/includes/admin/core/list-tables/emails-list-table.php @@ -1,171 +1,275 @@ - __( 'item', 'ultimate-member' ), - 'plural' => __( 'items', 'ultimate-member' ), - 'ajax' => false - ) ); - - $this->no_items_message = $args['plural'] . ' ' . __( 'not found.', 'ultimate-member' ); - - parent::__construct( $args ); + /** + * @var string + */ + var $no_items_message = ''; - } - - function __call( $name, $arguments ) { - return call_user_func_array( array( $this, $name ), $arguments ); - } - - function prepare_items() { - $columns = $this->get_columns(); - $hidden = array(); - $sortable = $this->get_sortable_columns(); - $this->_column_headers = array( $columns, $hidden, $sortable ); - } - - function column_default( $item, $column_name ) { - if( isset( $item[ $column_name ] ) ) { - return $item[ $column_name ]; - } else { - return ''; - } - } - - function no_items() { - echo $this->no_items_message; - } - - function set_sortable_columns( $args = array() ) { - $return_args = array(); - foreach( $args as $k=>$val ) { - if( is_numeric( $k ) ) { - $return_args[ $val ] = array( $val, $val == $this->default_sorting_field ); - } else if( is_string( $k ) ) { - $return_args[ $k ] = array( $val, $k == $this->default_sorting_field ); - } else { - continue; - } - } - $this->sortable_columns = $return_args; - return $this; - } - - function get_sortable_columns() { - return $this->sortable_columns; - } - - function set_columns( $args = array() ) { - if ( count( $this->bulk_actions ) ) { - $args = array_merge( array( 'cb' => '' ), $args ); - } - $this->columns = $args; - - return $this; - } - - function get_columns() { - return $this->columns; - } - - function set_actions( $args = array() ) { - $this->actions = $args; - return $this; - } - - function get_actions() { - return $this->actions; - } - - function set_bulk_actions( $args = array() ) { - $this->bulk_actions = $args; - return $this; - } - - function get_bulk_actions() { - return $this->bulk_actions; - } - - function column_email( $item ) { - $active = UM()->options()->get( $item['key'] . '_on' ); - - return ''. $item['title'] . ''; - } + /** + * @var array + */ + var $sortable_columns = array(); - function column_recipients( $item ) { - if ( $item['recipient'] == 'admin' ) - return UM()->options()->get( 'admin_email' ); - else - return __( 'Member', 'ultimate-member' ); - } + /** + * @var string + */ + var $default_sorting_field = ''; - function column_configure( $item ) { - return ''; - } - - function column_icl_translations( $item ) { - return UM()->external_integrations()->wpml_column_content( $item ); - } + /** + * @var array + */ + var $actions = array(); - function wpc_set_pagination_args( $attr = array() ) { - $this->set_pagination_args( $attr ); - } + /** + * @var array + */ + var $bulk_actions = array(); + + + /** + * @var array + */ + var $columns = array(); + + + /** + * UM_Emails_List_Table constructor. + * + * @param array $args + */ + function __construct( $args = array() ){ + $args = wp_parse_args( $args, array( + 'singular' => __( 'item', 'ultimate-member' ), + 'plural' => __( 'items', 'ultimate-member' ), + 'ajax' => false + ) ); + + $this->no_items_message = $args['plural'] . ' ' . __( 'not found.', 'ultimate-member' ); + + parent::__construct( $args ); + } + + + /** + * @param callable $name + * @param array $arguments + * + * @return mixed + */ + function __call( $name, $arguments ) { + return call_user_func_array( array( $this, $name ), $arguments ); + } + + + /** + * + */ + function prepare_items() { + $columns = $this->get_columns(); + $hidden = array(); + $sortable = $this->get_sortable_columns(); + $this->_column_headers = array( $columns, $hidden, $sortable ); + } + + + /** + * @param object $item + * @param string $column_name + * + * @return string + */ + function column_default( $item, $column_name ) { + if( isset( $item[ $column_name ] ) ) { + return $item[ $column_name ]; + } else { + return ''; + } + } + + + /** + * + */ + function no_items() { + echo $this->no_items_message; + } + + + /** + * @param array $args + * + * @return $this + */ + function set_sortable_columns( $args = array() ) { + $return_args = array(); + foreach( $args as $k=>$val ) { + if( is_numeric( $k ) ) { + $return_args[ $val ] = array( $val, $val == $this->default_sorting_field ); + } else if( is_string( $k ) ) { + $return_args[ $k ] = array( $val, $k == $this->default_sorting_field ); + } else { + continue; + } + } + $this->sortable_columns = $return_args; + return $this; + } + + + /** + * @return array + */ + function get_sortable_columns() { + return $this->sortable_columns; + } + + + /** + * @param array $args + * + * @return $this + */ + function set_columns( $args = array() ) { + if ( count( $this->bulk_actions ) ) { + $args = array_merge( array( 'cb' => '' ), $args ); + } + $this->columns = $args; + + return $this; + } + + + /** + * @return array + */ + function get_columns() { + return $this->columns; + } + + + /** + * @param array $args + * + * @return $this + */ + function set_actions( $args = array() ) { + $this->actions = $args; + return $this; + } + + + /** + * @return array + */ + function get_actions() { + return $this->actions; + } + + + /** + * @param array $args + * + * @return $this + */ + function set_bulk_actions( $args = array() ) { + $this->bulk_actions = $args; + return $this; + } + + + /** + * @return array + */ + function get_bulk_actions() { + return $this->bulk_actions; + } + + + /** + * @param $item + * + * @return string + */ + function column_email( $item ) { + $active = UM()->options()->get( $item['key'] . '_on' ); + + return ''. $item['title'] . ''; + } + + + /** + * @param $item + * + * @return mixed|string|void + */ + function column_recipients( $item ) { + if ( $item['recipient'] == 'admin' ) + return UM()->options()->get( 'admin_email' ); + else + return __( 'Member', 'ultimate-member' ); + } + + + /** + * @param $item + * + * @return string + */ + function column_configure( $item ) { + return ''; + } + + + /** + * @param $item + * + * @return string + */ + function column_icl_translations( $item ) { + return UM()->external_integrations()->wpml_column_content( $item ); + } + + + /** + * @param array $attr + */ + function wpc_set_pagination_args( $attr = array() ) { + $this->set_pagination_args( $attr ); + } } $ListTable = new UM_Emails_List_Table( array( - 'singular' => __( 'Email Notification', 'ultimate-member' ), - 'plural' => __( 'Email Notifications', 'ultimate-member' ), - 'ajax' => false + 'singular' => __( 'Email Notification', 'ultimate-member' ), + 'plural' => __( 'Email Notifications', 'ultimate-member' ), + 'ajax' => false )); $per_page = 20; @@ -207,11 +311,11 @@ $ListTable->items = $emails; $ListTable->wpc_set_pagination_args( array( 'total_items' => count( $emails ), 'per_page' => $per_page ) ); ?>
- - - - - + + + + display(); ?> + $ListTable->display(); ?>
\ No newline at end of file diff --git a/includes/admin/core/list-tables/roles-list-table.php b/includes/admin/core/list-tables/roles-list-table.php index 02891b61..0df585c8 100644 --- a/includes/admin/core/list-tables/roles-list-table.php +++ b/includes/admin/core/list-tables/roles-list-table.php @@ -120,15 +120,53 @@ if( ! class_exists( 'WP_List_Table' ) ) require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); +/** + * Class UM_Roles_List_Table + */ class UM_Roles_List_Table extends WP_List_Table { + + /** + * @var string + */ var $no_items_message = ''; + + + /** + * @var array + */ var $sortable_columns = array(); + + + /** + * @var string + */ var $default_sorting_field = ''; + + + /** + * @var array + */ var $actions = array(); + + + /** + * @var array + */ var $bulk_actions = array(); + + + /** + * @var array + */ var $columns = array(); + + /** + * UM_Roles_List_Table constructor. + * + * @param array $args + */ function __construct( $args = array() ){ $args = wp_parse_args( $args, array( 'singular' => __( 'item', 'ultimate-member' ), @@ -139,14 +177,23 @@ class UM_Roles_List_Table extends WP_List_Table { $this->no_items_message = $args['plural'] . ' ' . __( 'not found.', 'ultimate-member' ); parent::__construct( $args ); - - } + + /** + * @param callable $name + * @param array $arguments + * + * @return mixed + */ function __call( $name, $arguments ) { return call_user_func_array( array( $this, $name ), $arguments ); } + + /** + * + */ function prepare_items() { $columns = $this->get_columns(); $hidden = array(); @@ -154,6 +201,13 @@ class UM_Roles_List_Table extends WP_List_Table { $this->_column_headers = array( $columns, $hidden, $sortable ); } + + /** + * @param object $item + * @param string $column_name + * + * @return string + */ function column_default( $item, $column_name ) { if( isset( $item[ $column_name ] ) ) { return $item[ $column_name ]; @@ -162,10 +216,20 @@ class UM_Roles_List_Table extends WP_List_Table { } } + + /** + * + */ function no_items() { echo $this->no_items_message; } + + /** + * @param array $args + * + * @return $this + */ function set_sortable_columns( $args = array() ) { $return_args = array(); foreach( $args as $k=>$val ) { @@ -181,10 +245,20 @@ class UM_Roles_List_Table extends WP_List_Table { return $this; } + + /** + * @return array + */ function get_sortable_columns() { return $this->sortable_columns; } + + /** + * @param array $args + * + * @return $this + */ function set_columns( $args = array() ) { if( count( $this->bulk_actions ) ) { $args = array_merge( array( 'cb' => '' ), $args ); @@ -193,34 +267,68 @@ class UM_Roles_List_Table extends WP_List_Table { return $this; } + + /** + * @return array + */ function get_columns() { return $this->columns; } + + /** + * @param array $args + * + * @return $this + */ function set_actions( $args = array() ) { $this->actions = $args; return $this; } + + /** + * @return array + */ function get_actions() { return $this->actions; } + + /** + * @param array $args + * + * @return $this + */ function set_bulk_actions( $args = array() ) { $this->bulk_actions = $args; return $this; } + + /** + * @return array + */ function get_bulk_actions() { return $this->bulk_actions; } + /** + * @param object $item + * + * @return string + */ function column_cb( $item ) { return sprintf( '', $item['key'] ); } + /** + * @param $item + * + * @return string + */ function column_title( $item ) { $actions = array(); @@ -241,26 +349,44 @@ class UM_Roles_List_Table extends WP_List_Table { return sprintf('%1$s %2$s', '' . $item['name'] . '', $this->row_actions( $actions ) ); } + + /** + * @param $item + * + * @return string + */ function column_roleid( $item ) { return ! empty( $item['_um_is_custom'] ) ? 'um_' . $item['key'] : $item['key']; } + /** + * @param $item + */ function column_core( $item ) { echo ! empty( $item['_um_is_custom'] ) ? __( 'Yes', 'ultimate-member' ) : __( 'No', 'ultimate-member' ); } + /** + * @param $item + */ function column_admin_access( $item ) { echo ! empty( $item['_um_can_access_wpadmin'] ) ? __( 'Yes', 'ultimate-member' ) : __( 'No', 'ultimate-member' ); } + /** + * @param $item + */ function column_priority( $item ) { echo ! empty( $item['_um_priority'] ) ? $item['_um_priority'] : '-'; } + /** + * @param array $attr + */ function um_set_pagination_args( $attr = array() ) { $this->set_pagination_args( $attr ); } @@ -332,17 +458,11 @@ foreach ( $wp_roles->roles as $roleID => $role_data ) { switch( strtolower( $order ) ) { case 'asc': uasort( $roles, function( $a, $b ) { - //$a['name'] = ! empty( $a['_um_is_custom'] ) ? 'UM ' . $a['name'] : $a['name']; - //$b['name'] = ! empty( $b['_um_is_custom'] ) ? 'UM ' . $b['name'] : $b['name']; - return strnatcmp( $a['name'], $b['name'] ); } ); break; case 'desc': uasort( $roles, function( $a, $b ) { - //$a['name'] = ! empty( $a['_um_is_custom'] ) ? 'UM ' . $a['name'] : $a['name']; - //$b['name'] = ! empty( $b['_um_is_custom'] ) ? 'UM ' . $b['name'] : $b['name']; - return strnatcmp( $a['name'], $b['name'] ) * -1; } ); break; @@ -355,7 +475,9 @@ $ListTable->um_set_pagination_args( array( 'total_items' => count( $roles ), 'pe

- + + +

query('INSERT INTO '.$wpdb->usermeta.'(user_id, meta_key, meta_value) - SELECT uu.ID, "_um_last_login", uu.user_registered - FROM '.$wpdb->users.' AS uu - WHERE - uu.ID NOT IN( - SELECT user_id FROM '.$wpdb->usermeta.' - WHERE meta_key = "_um_last_login" - GROUP BY user_id - )' - ); + \ No newline at end of file +/** + * This populates all existing UM users with meta_key `last_login` as `user_registered` if the meta key doesn't exist. + * Target Version: 1.3.39 + */ +global $wpdb; +$wpdb->query( + 'INSERT INTO '.$wpdb->usermeta.'(user_id, meta_key, meta_value) + SELECT uu.ID, "_um_last_login", uu.user_registered + FROM '.$wpdb->users.' AS uu + WHERE uu.ID NOT IN( + SELECT user_id FROM '.$wpdb->usermeta.' + WHERE meta_key = "_um_last_login" + GROUP BY user_id + )' +); \ No newline at end of file diff --git a/includes/admin/core/packages/2.0-beta1.php b/includes/admin/core/packages/2.0-beta1.php index 61d47981..200f993f 100644 --- a/includes/admin/core/packages/2.0-beta1.php +++ b/includes/admin/core/packages/2.0-beta1.php @@ -5,7 +5,7 @@ if ( ! defined( 'ABSPATH' ) ) /** * This populates all existing UM users with meta_key `last_login` as `user_registered` if the meta key doesn't exist. - * Target Version: 1.3.39 + * Target Version: 2.0 */ global $wpdb; diff --git a/includes/admin/templates/role/admin.php b/includes/admin/templates/role/admin-permissions.php similarity index 100% rename from includes/admin/templates/role/admin.php rename to includes/admin/templates/role/admin-permissions.php diff --git a/includes/class-dependencies.php b/includes/class-dependencies.php index bbfc4ff3..8e5d3892 100644 --- a/includes/class-dependencies.php +++ b/includes/class-dependencies.php @@ -35,7 +35,7 @@ if ( ! class_exists( 'um\Dependencies' ) ) { 'private-content' => '2.0', 'profile-completeness' => '2.0.1', 'recaptcha' => '2.0', - 'reviews' => '2.0.1', + 'reviews' => '2.0.2', 'social-activity' => '2.0.1', 'social-login' => '2.0.1', 'terms-conditions' => '2.0', diff --git a/includes/class-init.php b/includes/class-init.php index f4f12cf0..7c631ab0 100644 --- a/includes/class-init.php +++ b/includes/class-init.php @@ -1030,20 +1030,6 @@ if ( ! class_exists( 'UM' ) ) { } - /** - * @since 2.0 - * - * @return um\core\Menu - */ - function menu() { - if ( empty( $this->classes['menu'] ) ) { - $this->classes['menu'] = new um\core\Menu(); - } - - return $this->classes['menu']; - } - - /** * @since 2.0 * diff --git a/includes/core/class-menu.php b/includes/core/class-menu.php deleted file mode 100644 index 53870113..00000000 --- a/includes/core/class-menu.php +++ /dev/null @@ -1,39 +0,0 @@ - - -
-
-
-
    - $v ) { ?> - -
  • - - -
-
-
- - roles()->um_current_user_can( 'edit', $user_id ) ) die( __( 'You can not edit this user' ) ); @@ -31,7 +34,10 @@ if ( ! class_exists( 'Profile' ) ) { function ajax_delete_cover_photo() { - extract($_REQUEST); + /** + * @var $user_id + */ + extract( $_REQUEST ); if ( ! UM()->roles()->um_current_user_can( 'edit', $user_id ) ) die( __( 'You can not edit this user' ) ); @@ -284,5 +290,30 @@ if ( ! class_exists( 'Profile' ) ) { return $output; } + + /** + * New menu + * + * @param string $position + * @param string $element + * @param string $trigger + * @param array $items + */ + function new_ui( $position, $element, $trigger, $items ) { + ?> + +
+
+
+
    + $v ) { ?> +
  • + +
+
+
+ + ' . __( 'Cancel', 'ultimate-member' ) . '', ); - echo UM()->menu()->new_ui( 'bc', 'div.um-cover', 'click', $items ); + echo UM()->profile()->new_ui( 'bc', 'div.um-cover', 'click', $items ); } @@ -749,7 +749,7 @@ add_action( 'um_after_user_updated', 'um_restore_default_roles', 10, 3 ); */ $items = apply_filters( 'um_user_photo_menu_view', $items ); - echo UM()->menu()->new_ui( 'bc', 'div.um-profile-photo', 'click', $items ); + echo UM()->profile()->new_ui( 'bc', 'div.um-profile-photo', 'click', $items ); } else if (UM()->fields()->editing == true) { @@ -782,7 +782,7 @@ add_action( 'um_after_user_updated', 'um_restore_default_roles', 10, 3 ); */ $items = apply_filters( 'um_user_photo_menu_edit', $items ); - echo UM()->menu()->new_ui( 'bc', 'div.um-profile-photo', 'click', $items ); + echo UM()->profile()->new_ui( 'bc', 'div.um-profile-photo', 'click', $items ); } @@ -1117,7 +1117,7 @@ add_action( 'um_after_user_updated', 'um_restore_default_roles', 10, 3 ); } - UM()->menu()->new_ui( $args['header_menu'], 'div.um-profile-edit', 'click', $items ); + UM()->profile()->new_ui( $args['header_menu'], 'div.um-profile-edit', 'click', $items ); ?>