From 81c791a518324054a191e46225326fa79a551209 Mon Sep 17 00:00:00 2001 From: jonfalcon Date: Sat, 2 Jan 2016 15:27:52 -0800 Subject: [PATCH] Add hook to field values when editing --- core/um-fields.php | 1174 ++++++++++++++++++++++---------------------- 1 file changed, 590 insertions(+), 584 deletions(-) diff --git a/core/um-fields.php b/core/um-fields.php index 0b97b9dc..8b8bf24f 100644 --- a/core/um-fields.php +++ b/core/um-fields.php @@ -3,18 +3,18 @@ class UM_Fields { function __construct() { - + $this->editing = false; $this->viewing = false; } - + /*** *** @standard checkbox field ***/ function checkbox( $id, $title ) { ?> - +
- + $arr ) { if ( um_profile( $k ) ) { ?> - + - + '; - + $fields = $ultimatemember->builtin->get_specific_fields( $field ); - + $output = null; - + foreach( $fields as $key => $data ) { $output .= $ultimatemember->fields->edit_field( $key, $data ); } - + echo $output; - + echo ''; } - + /*** *** @update a field globally ***/ function globally_update_field($id, $args){ global $ultimatemember; $fields = $ultimatemember->builtin->saved_fields; - + $fields[$id] = $args; unset( $fields[ $id ]['in_row'] ); @@ -82,17 +82,17 @@ class UM_Fields { unset( $fields[ $id ]['in_column'] ); unset( $fields[ $id ]['in_group'] ); unset( $fields[ $id ]['position'] ); - + update_option('um_fields', $fields ); } - + /*** *** @update a field in form only ***/ function update_field($id, $args, $form_id){ global $ultimatemember; $fields = $ultimatemember->query->get_attr( 'custom_fields', $form_id ); - + if ( $args['type'] == 'row' ) { if ( isset( $fields[$id] ) ){ $old_args = $fields[$id]; @@ -104,22 +104,22 @@ class UM_Fields { $args = array_merge( $old_args, $args ); } } - + // custom fields support if ( isset( $ultimatemember->builtin->predefined_fields[$id] ) && isset( $ultimatemember->builtin->predefined_fields[$id]['custom'] ) ) { $args = array_merge( $ultimatemember->builtin->predefined_fields[$id], $args); } - + $fields[$id] = $args; - + // for group field only if ( $args['type'] == 'group' ){ $fields[$id]['in_group'] = ''; } - + $ultimatemember->query->update_attr( 'custom_fields', $form_id, $fields ); } - + /*** *** @delete a field in form only ***/ @@ -131,7 +131,7 @@ class UM_Fields { $ultimatemember->query->update_attr( 'custom_fields', $form_id, $fields ); } } - + /*** *** @delete the field from custom fields ***/ @@ -143,7 +143,7 @@ class UM_Fields { update_option('um_fields', $fields ); } } - + /*** *** @quickly add field from custom fields ***/ @@ -151,61 +151,61 @@ class UM_Fields { global $ultimatemember; $fields = $ultimatemember->query->get_attr( 'custom_fields', $form_id ); $field_scope = $ultimatemember->builtin->saved_fields; - + if ( !isset( $fields[$global_id] ) ) { - + $count = 1; if ( isset( $fields ) && !empty( $fields) ) $count = count($fields)+1; - + $fields[$global_id] = $field_scope[$global_id]; $fields[$global_id]['position'] = $count; - + // set position if ( $position ) { foreach( $position as $key => $val ) { $fields[$global_id][$key] = $val; } } - + // add field to form $ultimatemember->query->update_attr( 'custom_fields', $form_id, $fields ); - + } } - + /*** *** @quickly add field from predefined fields ***/ function add_field_from_predefined( $global_id, $form_id, $position = array() ) { global $ultimatemember; - + $fields = $ultimatemember->query->get_attr( 'custom_fields', $form_id ); $field_scope = $ultimatemember->builtin->predefined_fields; - + if ( !isset( $fields[$global_id] ) ) { - + $count = 1; if ( isset( $fields ) && !empty( $fields) ) $count = count($fields)+1; - + $fields[$global_id] = $field_scope[$global_id]; $fields[$global_id]['position'] = $count; - + // set position if ( $position ) { foreach( $position as $key => $val ) { $fields[$global_id][$key] = $val; } } - + // add field to form $ultimatemember->query->update_attr( 'custom_fields', $form_id, $fields ); - + // add field to db //$this->globally_update_field( $global_id, $fields[$global_id] ); - + } } - + /*** *** @Duplicates a field by meta key *** @requires form id and meta key @@ -214,34 +214,34 @@ class UM_Fields { global $ultimatemember; $fields = $ultimatemember->query->get_attr( 'custom_fields', $form_id ); $all_fields = $ultimatemember->builtin->saved_fields; - + $inc = count( $fields ) + 1; - + $duplicate = $fields[ $id ]; - + $new_metakey = $id . "_" . $inc; $new_title = $fields[ $id ]['title'] . " #" . $inc; $new_position = $inc; - + $duplicate['title'] = $new_title; $duplicate['metakey'] = $new_metakey; $duplicate['position'] = $new_position; $fields[ $new_metakey ] = $duplicate; $all_fields[ $new_metakey ] = $duplicate; - + // not global attributes unset( $all_fields[ $new_metakey ]['in_row'] ); unset( $all_fields[ $new_metakey ]['in_sub_row'] ); unset( $all_fields[ $new_metakey ]['in_column'] ); unset( $all_fields[ $new_metakey ]['in_group'] ); unset( $all_fields[ $new_metakey ]['position'] ); - + $ultimatemember->query->update_attr( 'custom_fields', $form_id, $fields ); update_option('um_fields', $all_fields ); - + } - + /*** *** @Print field error ***/ @@ -256,13 +256,13 @@ class UM_Fields { } else { $output = ''; } - + if ( !$ultimatemember->form->processing ) { $output = '
'.$text.'
'; } return $output; } - + /*** *** @Check if field has a server side error ***/ @@ -270,7 +270,7 @@ class UM_Fields { global $ultimatemember; return $ultimatemember->form->has_error($key); } - + /*** *** @Return field error ***/ @@ -278,7 +278,7 @@ class UM_Fields { global $ultimatemember; return $ultimatemember->form->errors[$key]; } - + /*** *** @Display field label ***/ @@ -286,36 +286,36 @@ class UM_Fields { global $ultimatemember; $output = null; $output .= '
'; - + if ( isset($data['icon']) && $data['icon'] != '' && isset( $this->field_icons ) && $this->field_icons != 'off' && ( $this->field_icons == 'label' || $this->viewing == true ) ) { $output .= '
'; } - + if ( $this->viewing == true ) { $label = apply_filters("um_view_label_{$key}", $label ); } else { $label = apply_filters("um_edit_label_{$key}", $label ); $label = apply_filters("um_edit_label_all_fields", $label, $data ); } - + $output .= ''; - + if ( isset( $data['help'] ) && !empty( $data['help'] ) && $this->viewing == false && !strstr($key, 'confirm_user_pass') ) { - + if ( !$ultimatemember->mobile->isMobile() ) { if ( !isset( $this->disable_tooltips ) ) { $output .= ''; } } - + if ( $ultimatemember->mobile->isMobile() || isset( $this->disable_tooltips ) ) { $output .= ''. $data['help'] . ''; } - + } - + $output .= '
'; - + return $output; } @@ -324,27 +324,27 @@ class UM_Fields { ***/ function get_class($key, $data, $add = null) { $classes = null; - + $classes .= 'um-form-field '; - + if ( $this->is_error($key) ) { $classes .= 'um-error '; } else { $classes .= 'valid '; } - + if ( !isset($data['required']) ) { $classes .= 'not-required '; } - + if ( $data['type'] == 'date' ) { $classes .= 'um-datepicker '; } - + if ( $data['type'] == 'time' ) { $classes .= 'um-timepicker '; } - + if ( isset($data['icon']) && $data['icon'] && isset( $this->field_icons ) && $this->field_icons == 'field' ) { $classes .= 'um-iconed'; } @@ -352,21 +352,21 @@ class UM_Fields { if ($add) { $classes .= $add . ' '; } - + return $classes; } - + /*** *** @Get field value ***/ function field_value( $key, $default = false, $data = null ) { global $ultimatemember; - + if ( isset($_SESSION) && isset($_SESSION['um_social_profile'][$key]) && isset( $this->set_mode ) && $this->set_mode == 'register' ) return $_SESSION['um_social_profile'][$key]; - + $type = (isset($data['type']))?$data['type']:''; - + // preview in backend if ( isset( $ultimatemember->user->preview ) && $ultimatemember->user->preview ) { $submitted = um_user('submitted'); @@ -376,81 +376,87 @@ class UM_Fields { return 'Undefined'; } } - + // normal state if ( isset($ultimatemember->form->post_form[$key]) ) { - + if ( strstr( $key, 'user_pass' ) && $this->set_mode != 'password' ) return ''; - + return $ultimatemember->form->post_form[$key]; - + } else if ( um_user( $key ) && $this->editing == true ) { - + if ( strstr( $key, 'user_pass' ) ) return ''; - - return um_user( $key ); - + + return apply_filters( "um_edit_{$key}_field_value", um_user( $key ), $key ); + } else if ( ( um_user( $key ) || isset($data['show_anyway']) ) && $this->viewing == true ) { - + $value = um_filtered_value( $key, $data ); return $value; - - } else if ($default) { + + } else if ( $default ) { + return $default; + + } else if ( $this->editing == true ) { + + return apply_filters( "um_edit_{$key}_field_value", '', $key); + } return ''; } - + /*** *** @Check if option is selected ***/ function is_selected($key, $value, $data){ global $ultimatemember; - + if ( isset( $ultimatemember->form->post_form[$key] ) && is_array( $ultimatemember->form->post_form[$key] ) ) { - + if ( in_array( $value, $ultimatemember->form->post_form[$key] ) ){ return true; } - + } else { - + if ( !isset( $ultimatemember->form->post_form ) ) { - + if ( um_user( $key ) && $this->editing == true && is_array( um_user( $key ) ) && in_array($value, um_user( $key ) ) ) { return true; } - + if ( um_user( $key ) && $this->editing == true && !is_array( um_user( $key ) ) && um_user( $key ) == $value ) { return true; } - + if ( strstr( $data['default'], ', ') ) { $data['default'] = explode(', ', $data['default']); } - + if ( isset($data['default']) && !is_array($data['default']) && $data['default'] == $value ) { return true; } - + if ( isset($data['default']) && is_array($data['default']) && in_array($value, $data['default'] ) ){ return true; } - + } else { - + if ( isset( $ultimatemember->form->post_form[$key] ) && $value == $ultimatemember->form->post_form[$key] ) { return true; } - + } - + } - + return false; } - + /*** *** @Check if radio button is checked ***/ @@ -458,43 +464,43 @@ class UM_Fields { global $ultimatemember; if ( isset( $ultimatemember->form->post_form[$key] ) && is_array( $ultimatemember->form->post_form[$key] ) ) { - + if ( in_array( $value, $ultimatemember->form->post_form[$key] ) ){ return true; } - + } else { - + if ( !isset( $ultimatemember->form->post_form ) ) { - + if ( um_user( $key ) && $this->editing == true ) { - + if ( strstr($key, 'role_') ) { $key = 'role'; } - + if ( um_user( $key ) == $value ) { return true; } - + } else { - + if ( isset($data['default']) && $data['default'] == $value ) { return true; } - + } - + } else { - + if ( isset( $ultimatemember->form->post_form[$key] ) && $value == $ultimatemember->form->post_form[$key] ) { return true; } - + } - + } - + return false; } @@ -508,7 +514,7 @@ class UM_Fields { return $fields[$key]['icon']; return ''; } - + /*** *** @Get Field Type ***/ @@ -519,7 +525,7 @@ class UM_Fields { return $fields[$key]['type']; return ''; } - + /*** *** @Get Field Label ***/ @@ -532,7 +538,7 @@ class UM_Fields { return $fields[$key]['title']; return ''; } - + /*** *** @Get Field Title ***/ @@ -545,7 +551,7 @@ class UM_Fields { return $fields[$key]['label']; return __('Custom Field','ultimatemember'); } - + /*** *** @Get form fields ***/ @@ -554,13 +560,13 @@ class UM_Fields { $this->fields = apply_filters("um_get_form_fields", $this->fields ); return $this->fields; } - + /*** *** @Get Field ***/ function get_field( $key ) { global $ultimatemember; - + $fields = $this->get_fields(); if ( isset( $fields ) && is_array( $fields ) && isset( $fields[$key] ) ) { @@ -571,30 +577,30 @@ class UM_Fields { } $array = (isset( $ultimatemember->builtin->predefined_fields[$key] ) ) ? $ultimatemember->builtin->predefined_fields[$key] : $ultimatemember->builtin->all_user_fields[$key]; } - + $array['classes'] = null; if (!isset($array['placeholder'])) $array['placeholder'] = null; if (!isset($array['required'])) $array['required'] = null; if (!isset($array['validate'])) $array['validate'] = null; if (!isset($array['default'])) $array['default'] = null; - + if ( isset( $array['conditions'] ) && is_array( $array['conditions'] ) && !$this->viewing ) { $array['conditional'] = ''; foreach( $array['conditions'] as $cond_id => $cond ) { $array['conditional'] .= ' data-cond-'.$cond_id.'-action="'. $cond[0] . '" data-cond-'.$cond_id.'-field="'. $cond[1] . '" data-cond-'.$cond_id.'-operator="'. $cond[2] . '" data-cond-'.$cond_id.'-value="'. $cond[3] . '"'; } - + $array['classes'] .= ' um-is-conditional'; - + } else { $array['conditional'] = null; } - + $array['classes'] .= ' um-field-' . $key; $array['classes'] .= ' um-field-' . $array['type']; - + switch( $array['type'] ) { case 'googlemap': @@ -604,25 +610,25 @@ class UM_Fields { $array['disabled'] = ''; $array['input'] = 'text'; break; - + case 'text': - + $array['disabled'] = ''; - + if ( $key == 'user_login' && $this->set_mode == 'account' ) { $array['disabled'] = 'disabled="disabled"'; } - + $array['input'] = 'text'; break; - + case 'password': - + $array['input'] = 'password'; break; - + case 'number': $array['disabled'] = ''; @@ -630,17 +636,17 @@ class UM_Fields { break; case 'url': - + $array['input'] = 'text'; break; - + case 'date': - + $array['input'] = 'text'; - + if ( !isset( $array['format'] ) ) $array['format'] = 'j M Y'; - + switch( $array['format'] ) { case 'j M Y': $js_format = 'd mmm yyyy'; @@ -655,68 +661,68 @@ class UM_Fields { $js_format = 'mmmm d yyyy'; break; } - + $array['js_format'] = $js_format; - + if ( !isset( $array['range'] ) ) $array['range'] = 'years'; if ( !isset( $array['years'] ) ) $array['years'] = 100; if ( !isset( $array['years_x'] ) ) $array['years_x'] = 'past'; if ( !isset( $array['disabled_weekdays'] ) ) $array['disabled_weekdays'] = ''; - + if ( !empty( $array['disabled_weekdays'] ) ) { $array['disabled_weekdays'] = '[' . implode(',',$array['disabled_weekdays']) . ']'; } - + // When date range is strictly defined if ( $array['range'] == 'date_range' ) { - + $array['date_min'] = str_replace('/',',',$array['range_start']); $array['date_max'] = str_replace('/',',',$array['range_end']); - + } else { - + if ( $array['years_x'] == 'past' ) { $date = new DateTime( date('Y-n-d') ); $past = $date->modify('-'.$array['years'].' years'); $past = $date->format('Y,n,d'); - + $array['date_min'] = $past; $array['date_max'] = date('Y,n,d'); - + } else if ( $array['years_x'] == 'future' ) { - + $date = new DateTime( date('Y-n-d') ); $future = $date->modify('+'.$array['years'].' years'); $future = $date->format('Y,n,d'); - - $array['date_min'] = date('Y,n,d'); + + $array['date_min'] = date('Y,n,d'); $array['date_max'] = $future; - + } else { - + $date = new DateTime( date('Y-n-d') ); $date_f = new DateTime( date('Y-n-d') ); $past = $date->modify('-'. ( $array['years'] / 2 ).' years'); $past = $date->format('Y,n,d'); $future = $date_f->modify('+'. ( $array['years'] / 2 ).' years'); $future = $date_f->format('Y,n,d'); - - $array['date_min'] = $past; + + $array['date_min'] = $past; $array['date_max'] = $future; } } - + break; - + case 'time': - + $array['input'] = 'text'; - + if ( !isset( $array['format'] ) ) $array['format'] = 'g:i a'; - + switch( $array['format'] ) { case 'g:i a': $js_format = 'h:i a'; @@ -728,63 +734,63 @@ class UM_Fields { $js_format = 'HH:i'; break; } - + $array['js_format'] = $js_format; - + if ( !isset( $array['intervals'] ) ) $array['intervals'] = 60; break; - + case 'textarea': - + if (!isset($array['height'])) $array['height'] = '100px'; - + break; case 'rating': - + if (!isset($array['number'])) $array['number'] = 5; - + break; case 'spacing': - + if ( !isset($array['spacing'])){ $array['spacing'] = '20px'; } - + break; - + case 'divider': - + if (isset($array['width'])){ $array['borderwidth'] = $array['width']; } else { $array['borderwidth'] = 4; } - + if (isset($array['color'])){ $array['bordercolor'] = $array['color']; } else { $array['bordercolor'] = '#eee'; } - + if (isset($array['style'])){ $array['borderstyle'] = $array['style']; } else { $array['borderstyle'] = 'solid'; } - + if ( !isset( $array['divider_text'] ) ) { $array['divider_text'] = ''; } - + break; case 'image': - + if ( !isset( $array['crop'] ) ) $array['crop'] = 0; - + if ( $array['crop'] == 0 ) { $array['crop_data'] = 0; } else if ( $array['crop'] == 1 ) { @@ -794,26 +800,26 @@ class UM_Fields { } else { $array['crop_data'] = 'user'; } - + if ( !isset( $array['modal_size'] ) ) $array['modal_size'] = 'normal'; - + if ( $array['crop'] > 0 ) { $array['crop_class'] = 'crop'; } else { $array['crop_class'] = ''; } - + if ( !isset( $array['ratio'] ) ) $array['ratio'] = 1.0; - + if ( !isset( $array['min_width'] ) ) $array['min_width'] = ''; if ( !isset( $array['min_height'] ) ) $array['min_height'] = ''; - + if ( $array['min_width'] == '' && $array['crop'] == 1 ) $array['min_width'] = 600; if ( $array['min_height'] == '' && $array['crop'] == 1 ) $array['min_height'] = 600; - + if ( $array['min_width'] == '' && $array['crop'] == 3 ) $array['min_width'] = 600; if ( $array['min_height'] == '' && $array['crop'] == 3 ) $array['min_height'] = 600; - + if (!isset($array['invalid_image'])) $array['invalid_image'] = __("Please upload a valid image!",'ultimatemember'); if (!isset($array['allowed_types'])) { $array['allowed_types'] = "gif,jpg,jpeg,png"; @@ -833,9 +839,9 @@ class UM_Fields { break; case 'file': - + if ( !isset( $array['modal_size'] ) ) $array['modal_size'] = 'normal'; - + if (!isset($array['allowed_types'])) { $array['allowed_types'] = "pdf,txt"; } else { @@ -854,57 +860,57 @@ class UM_Fields { break; case 'select': - + break; - + case 'multiselect': - + break; - + case 'group': - + if ( !isset( $array['max_entries'] ) ) $array['max_entries'] = 0; - + break; - + } - + if ( !isset( $array['visibility'] ) ) $array['visibility'] = 'all'; - + return $array; } - + /*** *** @a field in input mode ***/ function edit_field( $key, $data, $rule=false ) { global $ultimatemember; - + $output = null; - + // get whole field data if ( isset( $data ) && is_array( $data ) ) { $data = $this->get_field($key); extract($data); } - + if ( !isset( $data['type'] ) ) return; - + if ( isset( $data['in_group'] ) && $data['in_group'] != '' && $rule != 'group' ) return; - + if ( $visibility == 'view' ) return; - + if ( !um_can_view_field( $data ) ) return; if ( !um_can_edit_field( $data ) ) return; - + // fields that need to be disabled in edit mode (profile) if ( in_array( $key, array('user_email','username','user_login','user_password') ) && $this->editing == true && $this->set_mode == 'profile' ) { return; } - + // forbidden in edit mode? if ( isset( $data['edit_forbidden'] ) ) return; - + // required option if ( isset( $data['required_opt'] ) ) { $opt = $data['required_opt']; @@ -912,14 +918,14 @@ class UM_Fields { return; } } - + // required user permission if ( isset( $data['required_perm'] ) ) { if ( !um_user( $data['required_perm'] ) ) { return; } } - + // do not show passwords if ( isset( $ultimatemember->user->preview ) && $ultimatemember->user->preview ) { if ( $data['type'] == 'password' ){ @@ -931,13 +937,13 @@ class UM_Fields { /* Begin by field type */ switch( $type ) { - + /* Default: Integration */ default: $mode = (isset($this->set_mode))?$this->set_mode:'no_mode'; $output .= apply_filters("um_edit_field_{$mode}_{$type}", $output, $data); break; - + /* Other fields */ case 'googlemap': case 'youtube_video': @@ -945,27 +951,27 @@ class UM_Fields { case 'soundcloud_track': $output .= '
'; - + if ( isset( $data['label'] ) ) { $output .= $this->field_label($label, $key, $data); } $output .= '
'; - + if ( isset($icon) && $icon && isset( $this->field_icons ) && $this->field_icons == 'field' ) { - + $output .= '
'; - + } - + $output .= ' - +
'; - + if ( $this->is_error($key) ) { $output .= $this->field_error( $this->show_error($key) ); } - + $output .= '
'; break; @@ -973,27 +979,27 @@ class UM_Fields { case 'text': $output .= '
'; - + if ( isset( $data['label'] ) ) { $output .= $this->field_label($label, $key, $data); } $output .= '
'; - + if ( isset($icon) && $icon && isset( $this->field_icons ) && $this->field_icons == 'field' ) { - + $output .= '
'; - + } - + $output .= ' - +
'; - + if ( $this->is_error($key) ) { $output .= $this->field_error( $this->show_error($key) ); } - + $output .= '
'; break; @@ -1001,39 +1007,39 @@ class UM_Fields { case 'number': $output .= '
'; - + if ( isset( $data['label'] ) ) { $output .= $this->field_label($label, $key, $data); } $output .= '
'; - + if ( isset($icon) && $icon && isset( $this->field_icons ) && $this->field_icons == 'field' ) { - + $output .= '
'; - + } - + $output .= ' - +
'; - + if ( $this->is_error($key) ) { $output .= $this->field_error( $this->show_error($key) ); } - + $output .= '
'; break; - + /* Password */ case 'password': - + $original_key = $key; - + if ( $key == 'single_user_password' ) { - + $key = $original_key; - + $output .= '
'; if ( isset( $data['label'] ) ) { @@ -1041,277 +1047,277 @@ class UM_Fields { } $output .= '
'; - + if ( isset($icon) && $icon && $this->field_icons == 'field' ) { - + $output .= '
'; - + } - + $output .= ' - +
'; - + if ( $this->is_error($key) ) { $output .= $this->field_error( $this->show_error($key) ); } - + $output .= '
'; - + } else { - + if ( $this->set_mode == 'account' && um_is_core_page('account') ) { $key = 'current_' . $original_key; $output .= '
'; - + if ( isset( $data['label'] ) ) { $output .= $this->field_label( __('Current Password','ultimatemember'), $key, $data); } - + $output .= '
'; - + if ( isset($icon) && $icon && $this->field_icons == 'field' ) { - + $output .= '
'; - + } - + $output .= ' - +
'; - + if ( $this->is_error($key) ) { $output .= $this->field_error( $this->show_error($key) ); } - + $output .= '
'; - + } $key = $original_key; - + $output .= '
'; if ( $this->set_mode == 'account' && um_is_core_page('account') || $this->set_mode == 'password' && um_is_core_page('password-reset') ) { - + $output .= $this->field_label( __('New Password','ultimatemember'), $key, $data); - + } else if ( isset( $data['label'] ) ) { - + $output .= $this->field_label($label, $key, $data); - + } $output .= '
'; - + if ( isset($icon) && $icon && $this->field_icons == 'field' ) { - + $output .= '
'; - + } - + $output .= ' - +
'; - + if ( $this->is_error($key) ) { $output .= $this->field_error( $this->show_error($key) ); } - + $output .= '
'; - + if ( $this->set_mode != 'login' && isset( $data['force_confirm_pass'] ) && $data['force_confirm_pass'] == 1 ) { $key = 'confirm_' . $original_key; $output .= '
'; - + if ( isset( $data['label'] ) ) { $output .= $this->field_label( sprintf(__('Confirm %s','ultimatemember'), $data['label'] ), $key, $data); } - + $output .= '
'; - + if ( isset($icon) && $icon && $this->field_icons == 'field' ) { - + $output .= '
'; - + } - + $output .= ' - +
'; - + if ( $this->is_error($key) ) { $output .= $this->field_error( $this->show_error($key) ); } - + $output .= '
'; - + } - + } - + break; - + /* URL */ case 'url': - + $output .= '
'; - + if ( isset( $data['label'] ) ) { $output .= $this->field_label($label, $key, $data); } $output .= '
'; - + if ( isset($icon) && $icon && isset($this->field_icons) && $this->field_icons == 'field' ) { - + $output .= '
'; - + } - + $output .= ' - +
'; - + if ( $this->is_error($key) ) { $output .= $this->field_error( $this->show_error($key) ); } - + $output .= '
'; break; - + /* Date */ case 'date': - + $output .= '
'; - + if ( isset( $data['label'] ) ) { $output .= $this->field_label($label, $key, $data); } $output .= '
'; - + if ( isset($icon) && $icon && isset( $this->field_icons ) && $this->field_icons == 'field' ) { - + $output .= '
'; - + } - + $output .= ' - +
'; - + if ( $this->is_error($key) ) { $output .= $this->field_error( $this->show_error($key) ); } - + $output .= '
'; break; - + /* Time */ case 'time': - + $output .= '
'; - + if ( isset( $data['label'] ) ) { $output .= $this->field_label($label, $key, $data); } $output .= '
'; - + if ( isset($icon) && $icon && $this->field_icons == 'field' ) { - + $output .= '
'; - + } - + $output .= ' - +
'; - + if ( $this->is_error($key) ) { $output .= $this->field_error( $this->show_error($key) ); } - + $output .= '
'; break; - + /* Row */ case 'row': $output .= ''; break; - + /* Textarea */ case 'textarea': $output .= '
'; - + if ( isset( $data['label'] ) ) { $output .= $this->field_label($label, $key, $data); } - + $output .= '
'; if ( isset( $data['html'] ) && $data['html'] != 0 && $key != "description" ) { - - $textarea_settings = array( - 'media_buttons' => false, - 'wpautop' => false, + + $textarea_settings = array( + 'media_buttons' => false, + 'wpautop' => false, 'editor_class' => $this->get_class($key, $data), 'editor_height' => $height, 'tinymce'=> array( 'toolbar1' => 'formatselect,bullist,numlist,bold,italic,underline,forecolor,blockquote,hr,removeformat,link,unlink,undo,redo', 'toolbar2' => '' - ) + ) ); - + // turn on the output buffer ob_start(); - + // echo the editor to the buffer wp_editor( $this->field_value( $key, $default, $data ) , $key, $textarea_settings ); - + // add the contents of the buffer to the output variable $output .= ob_get_clean(); - + } else $output .= ''; - $output .= ' + $output .= '
'; - + if ( $this->is_error($key) ) { $output .= $this->field_error( $this->show_error($key) ); } - + $output .= '
'; break; - + /* Rating */ case 'rating': $output .= '
'; - + if ( isset( $data['label'] ) ) { $output .= $this->field_label($label, $key, $data); } - + $output .= '
'; - + $output .= '
'; - + $output .= '
'; - + $output .= '
'; - + break; - + /* Gap/Space */ case 'spacing': $output .= '
'; break; - + /* A line divider */ case 'divider': $output .= '
'; @@ -1320,29 +1326,29 @@ class UM_Fields { } $output .= '
'; break; - + /* Single Image Upload */ case 'image': $output .= '
'; - + if ( in_array( $key, array('profile_photo','cover_photo') ) ) { $field_value = ''; } else { $field_value = $this->field_value( $key, $default, $data ); } - + $output .= ''; - + if ( isset( $data['label'] ) ) { $output .= $this->field_label($label, $key, $data); } - + $modal_label = ( isset( $data['label'] ) ) ? $data['label'] : __('Upload Photo','ultimatemember'); $output .= '
'; - + if ( $this->field_value( $key, $default, $data ) ) { - + if ( !in_array( $key, array('profile_photo','cover_photo') ) ) { if ( isset( $this->set_mode ) && $this->set_mode == 'register' ) { $imgValue = $this->field_value( $key, $default, $data ); @@ -1353,29 +1359,29 @@ class UM_Fields { } else { $img = ''; } - + $output .= '
' . $img . '
'. __('Change photo','ultimatemember') . ''; - + } else { - + $output .= '
'. $button_text . ''; - + } - + $output .= '
'; /* modal hidden */ $output .= '
'; $output .= '
' . $modal_label . '
'; - + $output .= '
'; - + if ( isset( $this->set_id ) ) { $set_id = $this->set_id; $set_mode = $this->set_mode; @@ -1383,10 +1389,10 @@ class UM_Fields { $set_id = 0; $set_mode = ''; } - + $output .= '
'; $output .= '
'.$button_text.'
'; - + $output .= ''; - + $output .= '
'; - + $output .= '
'; - + /* end */ - + if ( $this->is_error($key) ) { $output .= $this->field_error( $this->show_error($key) ); } - + $output .= '
'; - + break; - + /* Single File Upload */ case 'file': $output .= '
'; - + $output .= ''; - + if ( isset( $data['label'] ) ) { $output .= $this->field_label($label, $key, $data); } - + $modal_label = ( isset( $data['label'] ) ) ? $data['label'] : __('Upload Photo','ultimatemember'); - + $output .= '
'; - + if ( $this->field_value( $key, $default, $data ) ) { - + $extension = pathinfo( $this->field_value( $key, $default, $data ), PATHINFO_EXTENSION); - + $output .= '
@@ -1436,12 +1442,12 @@ class UM_Fields {
'. __('Change file','ultimatemember') . ''; - + } else { - + $output .= '
'. $button_text . ''; - + } $output .= '
'; @@ -1450,9 +1456,9 @@ class UM_Fields { $output .= '
'; $output .= '
' . $modal_label . '
'; - + $output .= '
'; - + if ( isset( $this->set_id ) ) { $set_id = $this->set_id; $set_mode = $this->set_mode; @@ -1460,7 +1466,7 @@ class UM_Fields { $set_id = 0; $set_mode = ''; } - + $output .= '
@@ -1471,7 +1477,7 @@ class UM_Fields {
'; $output .= '
'.$button_text.'
'; - + $output .= ''; - + $output .= '
'; - + $output .= '
'; - + /* end */ - + if ( $this->is_error($key) ) { $output .= $this->field_error( $this->show_error($key) ); } - + $output .= '
'; - + break; - + /* Select dropdown */ case 'select': - + $form_key = str_replace('role_select','role',$key); - + $output .= '
'; if ( isset( $data['allowclear'] ) && $data['allowclear'] == 0 ) { @@ -1506,31 +1512,31 @@ class UM_Fields { } else { $class = 'um-s1'; } - + if ( isset( $data['label'] ) ) { $output .= $this->field_label($label, $key, $data); } $output .= '
'; - + $output .= ''; - + $output .= '
'; - + if ( $this->is_error($form_key) ) { $output .= $this->field_error( $this->show_error($form_key) ); } - + $output .= '
'; break; - + /* Multi-Select dropdown */ case 'multiselect': - + $max_selections = ( isset( $max_selections ) ) ? absint( $max_selections ) : 0; - + $output .= '
'; if ( isset( $data['allowclear'] ) && $data['allowclear'] == 0 ) { @@ -1594,15 +1600,15 @@ class UM_Fields { } else { $class = 'um-s1'; } - + if ( isset( $data['label'] ) ) { $output .= $this->field_label($label, $key, $data); } $output .= '
'; - + $output .= ''; - + $output .= '
'; - + if ( $this->is_error($key) ) { $output .= $this->field_error( $this->show_error($key) ); } - + $output .= '
'; break; - + /* Radio */ case 'radio': - + $form_key = str_replace('role_radio','role',$key); - + if ( isset( $options ) ) { $options = apply_filters('um_radio_field_options', $options, $data ); $options = apply_filters("um_radio_field_options_{$key}", $options ); } - + $output .= '
'; - + if ( isset( $data['label'] ) ) { $output .= $this->field_label($label, $key, $data); } - + $output .= '
'; // role field if ( $form_key == 'role' ) { - + global $wpdb; foreach($options as $key => $val ) { $val = (string) $val; @@ -1682,30 +1688,30 @@ class UM_Fields { $new_roles[$_role->post_name] = $_role->post_title; wp_reset_postdata(); } - + $options = $new_roles; } - + // add options $i = 0; foreach($options as $k => $v) { - + $v = rtrim($v); - + if ( !is_numeric( $k ) && in_array($form_key, array('role') ) ) { $option_value = $k; } else { $option_value = $v; } - + $i++; if ($i % 2 == 0 ) { $col_class = 'right'; } else { $col_class = ''; } - + if ( $this->is_radio_checked($key, $option_value, $data) ) { $active = 'active'; $class = "um-icon-android-radio-button-on"; @@ -1713,10 +1719,10 @@ class UM_Fields { $active = ''; $class = "um-icon-android-radio-button-off"; } - + $output .= ''; - + if ($i % 2 == 0) { $output .= '
'; } } - + $output .= '
'; - + $output .= '
'; - + if ( $this->is_error($form_key) ) { $output .= $this->field_error( $this->show_error($form_key) ); } - + $output .= '
'; break; - + /* Checkbox */ case 'checkbox': - + if ( isset( $options ) ) { $options = apply_filters('um_checkbox_field_options', $options, $data ); $options = apply_filters("um_checkbox_field_options_{$key}", $options ); } - + $output .= '
'; - + if ( isset( $data['label'] ) ) { $output .= $this->field_label($label, $key, $data); } - + $output .= '
'; - + // add options $i = 0; - + foreach($options as $k => $v) { - + $v = rtrim($v); - + $i++; if ($i % 2 == 0 ) { $col_class = 'right'; } else { $col_class = ''; } - + if ( $this->is_selected($key, $v, $data) ) { $active = 'active'; $class = "um-icon-android-checkbox-outline"; @@ -1780,85 +1786,85 @@ class UM_Fields { $active = ''; $class = "um-icon-android-checkbox-outline-blank"; } - + $output .= ''; - + if ($i % 2 == 0) { $output .= '
'; } - + } - + $output .= '
'; - + $output .= '
'; - + if ( $this->is_error($key) ) { $output .= $this->field_error( $this->show_error($key) ); } - + $output .= '
'; break; - + /* HTML */ case 'block': $output .= '
'.$content.'
'; break; - + /* Shortcode */ case 'shortcode': - + $content = str_replace('{profile_id}', um_profile_id(), $content ); - + $output .= '
' . do_shortcode($content) . '
'; break; - + /* Unlimited Group */ case 'group': - + $fields = $this->get_fields_in_group( $key ); if ( !empty( $fields ) ) { - + $output .= '
'.$label.'
'; $output .= '
'; - + foreach($fields as $subkey => $subdata) { $output .= $this->edit_field( $subkey, $subdata, 'group' ); } - + $output .= '
'; $output .= '
'; - + } - + break; - + } - + // Custom filter for field output if ( isset( $this->set_mode ) ) { $output = apply_filters("um_{$key}_form_edit_field", $output, $this->set_mode); } - + return $output; } - + /*** *** @sort array function ***/ @@ -1873,7 +1879,7 @@ class UM_Fields { array_multisort($sort_col, $dir, $arr); return $arr; } - + /*** *** @get fields in row ***/ @@ -1885,7 +1891,7 @@ class UM_Fields { } return ( isset ( $results ) ) ? $results : ''; } - + /*** *** @get fields by sub row ***/ @@ -1898,7 +1904,7 @@ class UM_Fields { } return ( isset ( $results ) ) ? $results : ''; } - + /*** *** @get fields in group ***/ @@ -1910,7 +1916,7 @@ class UM_Fields { } return ( isset ( $results ) ) ? $results : ''; } - + /*** *** @get fields in column ***/ @@ -1922,28 +1928,28 @@ class UM_Fields { } return ( isset ( $results ) ) ? $results : ''; } - + /*** *** @display fields ***/ function display( $mode, $args ) { global $ultimatemember; $output = null; - + $this->global_args = $args; - + $ultimatemember->form->form_suffix = '-' . $this->global_args['form_id']; - + $this->set_mode = $mode; $this->set_id = $this->global_args['form_id']; - + $this->field_icons = ( isset( $this->global_args['icons'] ) ) ? $this->global_args['icons'] : 'label'; - + // start output here $this->get_fields = $this->get_fields(); if ( !empty( $this->get_fields ) ) { - + // find rows foreach( $this->get_fields as $key => $array ) { if ( $array['type'] == 'row' ) { @@ -1951,26 +1957,26 @@ class UM_Fields { unset( $this->get_fields[ $key ] ); // not needed anymore } } - + // rows fallback if ( !isset( $this->rows ) ){ $this->rows = array( '_um_row_1' => array( - 'type' => 'row', + 'type' => 'row', 'id' => '_um_row_1', 'sub_rows' => 1, 'cols' => 1 ) ); } - + // master rows foreach ( $this->rows as $row_id => $row_array ) { - + $row_fields = $this->get_fields_by_row( $row_id ); if ( $row_fields ) { - + $output .= $this->new_row_output( $row_id, $row_array ); - + $sub_rows = ( isset( $row_array['sub_rows'] ) ) ? $row_array['sub_rows'] : 1; for( $c = 0; $c < $sub_rows; $c++ ) { @@ -1986,154 +1992,154 @@ class UM_Fields { // sub row fields $subrow_fields = null; $subrow_fields = $this->get_fields_in_subrow( $row_fields, $c ); - + if ( is_array( $subrow_fields ) ) { - + $subrow_fields = $this->array_sort_by_column( $subrow_fields, 'position'); if ( $cols_num == 1 ) { - + $output .= '
'; $col1_fields = $this->get_fields_in_column( $subrow_fields, 1 ); if ( $col1_fields ) { foreach( $col1_fields as $key => $data ) {$output .= $this->edit_field( $key, $data );} } $output .= '
'; - + } else if ( $cols_num == 2 ) { - + $output .= '
'; $col1_fields = $this->get_fields_in_column( $subrow_fields, 1 ); if ( $col1_fields ) { foreach( $col1_fields as $key => $data ) {$output .= $this->edit_field( $key, $data );} } $output .= '
'; - + $output .= '
'; $col2_fields = $this->get_fields_in_column( $subrow_fields, 2 ); if ( $col2_fields ) { foreach( $col2_fields as $key => $data ) {$output .= $this->edit_field( $key, $data );} } $output .= '
'; - + } else { - + $output .= '
'; $col1_fields = $this->get_fields_in_column( $subrow_fields, 1 ); if ( $col1_fields ) { foreach( $col1_fields as $key => $data ) {$output .= $this->edit_field( $key, $data );} } $output .= '
'; - + $output .= '
'; $col2_fields = $this->get_fields_in_column( $subrow_fields, 2 ); if ( $col2_fields ) { foreach( $col2_fields as $key => $data ) {$output .= $this->edit_field( $key, $data );} } $output .= '
'; - + $output .= '
'; $col3_fields = $this->get_fields_in_column( $subrow_fields, 3 ); if ( $col3_fields ) { foreach( $col3_fields as $key => $data ) {$output .= $this->edit_field( $key, $data );} } $output .= '
'; - + } - + } - + } - + $output .= ''; - + } - + } } - + return $output; } - + /*** *** @a field in view mode ***/ function view_field( $key, $data, $rule=false ) { global $ultimatemember; - + $output = null; - + // get whole field data if (is_array($data)) { $data = $this->get_field($key); extract($data); } - + if ( !isset( $data['type'] ) ) return; - + if ( isset( $data['in_group'] ) && $data['in_group'] != '' && $rule != 'group' ) return; if ( $visibility == 'edit' ) return; - + if ( in_array( $type, array('block','shortcode','spacing','divider','group') ) ) { } else { if ( ! $this->field_value( $key, $default, $data ) ) return; } - + if ( !um_can_view_field( $data ) ) return; - + // disable these fields in profile view only if ( in_array( $key, array('user_password') ) && $this->set_mode == 'profile' ) { return; } - + if ( !um_field_conditions_are_met( $data ) ) return; - + switch( $type ) { /* Default */ default: - + $output .= '
'; - + if ( isset( $data['label'] ) ) { $output .= $this->field_label($label, $key, $data); } - + $res = stripslashes( $this->field_value( $key, $default, $data ) ); $output .= '
'; $output .= '
' . $res . '
'; $output .= '
'; - + $output .= '
'; - + break; - + /* HTML */ case 'block': $output .= '
'.$content.'
'; break; - + /* Shortcode */ case 'shortcode': - + $content = str_replace('{profile_id}', um_profile_id(), $content ); - + $output .= '
' . do_shortcode($content) . '
'; break; - + /* Gap/Space */ case 'spacing': $output .= '
'; break; - + /* A line divider */ case 'divider': $output .= '
'; @@ -2142,12 +2148,12 @@ class UM_Fields { } $output .= '
'; break; - + /* Rating */ case 'rating': - + $output .= '
'; - + if ( isset( $data['label'] ) ) { $output .= $this->field_label($label, $key, $data); } @@ -2157,58 +2163,58 @@ class UM_Fields {
'; $output .= ''; - + $output .= ''; - + break; - + } - + // Custom filter for field output if ( isset( $this->set_mode ) ) { $output = apply_filters("um_{$key}_form_show_field", $output, $this->set_mode); } - + return $output; } - + /*** *** @display fields (view mode) ***/ function display_view( $mode, $args ) { global $ultimatemember; $output = null; - + $this->global_args = $args; - + $ultimatemember->form->form_suffix = '-' . $this->global_args['form_id']; - + $this->set_mode = $mode; $this->set_id = $this->global_args['form_id']; - + $this->field_icons = ( isset( $this->global_args['icons'] ) ) ? $this->global_args['icons'] : 'label'; - + // start output here $this->get_fields = $this->get_fields(); if ( um_get_option('profile_empty_text') ) { - + $emo = um_get_option('profile_empty_text_emo'); if ( $emo ) { $emo = ''; } else { $emo = false; } - + if ( um_is_myprofile() ) { $output .= '

' . $emo .'' . sprintf(__('Your profile is looking a little empty. Why not add some information!','ultimatemember'), um_edit_profile_url() ) . '

'; } else { $output .= '

'. $emo . '' . __('This user has not added any information to their profile yet.','ultimatemember') . '

'; } } - + if ( !empty( $this->get_fields ) ) { - + // find rows foreach( $this->get_fields as $key => $array ) { if ( $array['type'] == 'row' ) { @@ -2216,24 +2222,24 @@ class UM_Fields { unset( $this->get_fields[ $key ] ); // not needed anymore } } - + // rows fallback if ( !isset( $this->rows ) ){ $this->rows = array( '_um_row_1' => array( - 'type' => 'row', + 'type' => 'row', 'id' => '_um_row_1', 'sub_rows' => 1, 'cols' => 1 ) ); } - + // master rows foreach ( $this->rows as $row_id => $row_array ) { - + $row_fields = $this->get_fields_by_row( $row_id ); if ( $row_fields ) { - + $output .= $this->new_row_output( $row_id, $row_array ); $sub_rows = ( isset( $row_array['sub_rows'] ) ) ? $row_array['sub_rows'] : 1; @@ -2251,83 +2257,83 @@ class UM_Fields { // sub row fields $subrow_fields = null; $subrow_fields = $this->get_fields_in_subrow( $row_fields, $c ); - + if ( is_array( $subrow_fields ) ) { - + $subrow_fields = $this->array_sort_by_column( $subrow_fields, 'position'); if ( $cols_num == 1 ) { - + $output .= '
'; $col1_fields = $this->get_fields_in_column( $subrow_fields, 1 ); if ( $col1_fields ) { foreach( $col1_fields as $key => $data ) {$output .= $this->view_field( $key, $data );} } $output .= '
'; - + } else if ( $cols_num == 2 ) { - + $output .= '
'; $col1_fields = $this->get_fields_in_column( $subrow_fields, 1 ); if ( $col1_fields ) { foreach( $col1_fields as $key => $data ) {$output .= $this->view_field( $key, $data );} } $output .= '
'; - + $output .= '
'; $col2_fields = $this->get_fields_in_column( $subrow_fields, 2 ); if ( $col2_fields ) { foreach( $col2_fields as $key => $data ) {$output .= $this->view_field( $key, $data );} } $output .= '
'; - + } else { - + $output .= '
'; $col1_fields = $this->get_fields_in_column( $subrow_fields, 1 ); if ( $col1_fields ) { foreach( $col1_fields as $key => $data ) {$output .= $this->view_field( $key, $data );} } $output .= '
'; - + $output .= '
'; $col2_fields = $this->get_fields_in_column( $subrow_fields, 2 ); if ( $col2_fields ) { foreach( $col2_fields as $key => $data ) {$output .= $this->view_field( $key, $data );} } $output .= '
'; - + $output .= '
'; $col3_fields = $this->get_fields_in_column( $subrow_fields, 3 ); if ( $col3_fields ) { foreach( $col3_fields as $key => $data ) {$output .= $this->view_field( $key, $data );} } $output .= '
'; - + } - + } - + } - + $output .= ''; - + } - + } } - + return $output; } - + /*** *** @begin new row in form ***/ function new_row_output( $row_id, $row_array ) { $output = null; extract($row_array); - + $padding = (isset($padding))?$padding:''; $margin = (isset($margin))?$margin:''; $background = (isset($background))?$background:''; @@ -2337,7 +2343,7 @@ class UM_Fields { $borderstyle = (isset($borderstyle))?$borderstyle:''; $heading = (isset($heading))?$heading:''; $css_class = (isset($css_class))?$css_class:''; - + $css_padding = ''; $css_margin = ''; $css_background = ''; @@ -2349,7 +2355,7 @@ class UM_Fields { $css_heading_padding = ''; $css_heading_text_color = ''; $css_heading_borderradius = ''; - + // row css rules if ( $padding ) $css_padding = 'padding: ' . $padding .';'; if ( $margin ) { @@ -2357,19 +2363,19 @@ class UM_Fields { } else { $css_margin = 'margin: 0 0 30px 0;'; } - + if ( $background ) $css_background = 'background-color: ' . $background .';'; if ( $borderradius ) $css_borderradius = 'border-radius: 0px 0px ' . $borderradius . ' ' . $borderradius . ';'; if ( $border ) $css_border = 'border-width: ' . $border . ';'; if ( $bordercolor ) $css_bordercolor = 'border-color: ' . $bordercolor . ';'; if ( $borderstyle ) $css_borderstyle = 'border-style: ' . $borderstyle . ';'; - + // show the heading if ( $heading ) { $heading_background_color = (isset($heading_background_color))?$heading_background_color:''; $heading_text_color = (isset($heading_text_color))?$heading_text_color:''; - + if ( $heading_background_color ) { $css_heading_background_color = 'background-color: ' . $heading_background_color .';'; $css_heading_padding = 'padding: 10px 15px;'; @@ -2377,21 +2383,21 @@ class UM_Fields { if ( $heading_text_color ) $css_heading_text_color = 'color: ' . $heading_text_color .';'; if ( $borderradius ) $css_heading_borderradius = 'border-radius: ' . $borderradius . ' ' . $borderradius . ' 0px 0px;'; - + $output .= '
'; if ( isset($icon) ) $output .= ''; $output .= $heading_text .'
'; - + } else { - + // no heading if ( $borderradius ) $css_borderradius = 'border-radius: ' . $borderradius . ';'; - + } $output .= '
'; - + return $output; } -} \ No newline at end of file +}