init_constants(); } public function init_constants(){ $this->settings_fields = THFAQF_Utils::get_settings_fields(); $this->cell_props_L = array( 'label_cell_props' => 'width="20%"', 'input_cell_props' => 'width="27%"', 'input_width' => '250px', ); $this->cell_props_R = array( 'label_cell_props' => 'width="20%"', 'input_cell_props' => 'width="27%"', 'input_width' => '250px', ); $this->cell_props_CB = array( 'label_props' => 'style="margin-right: 40px;"', ); $this->cell_props_CBS = array( 'label_props' => 'style="margin-right: 15px;"', ); $this->cell_props_CBL = array( 'label_props' => 'style="margin-right: 52px;"', ); $this->cell_props_CPL = array( 'label_cell_props' => 'width="20%"', 'input_cell_props' => 'width="27%"', ); $this->cell_props_CPR = array( 'label_cell_props' => 'width="15%"', 'input_cell_props' => 'width="32%"', ); } public function render_form_field_element($field, $settings=array(), $atts=array(), $render_cell=true, $render_tooltip=true){ if($field && is_array($field)){ $ftype = isset($field['type']) ? $field['type'] : 'text'; $name = isset($field['name']) ? $field['name'] : ''; $class = isset($field['class']) ? $field['class'] : ''; if(is_array($settings) && isset($settings[$name])){ if($ftype === 'checkbox' || $ftype === 'switch'){ $field['checked'] = $settings[$name]; }else{ $field['value'] = esc_attr($settings[$name]); } } if($ftype == 'checkbox'){ $this->render_form_field_element_checkbox($name, $field, $atts, $render_cell); return true; } $args = shortcode_atts( array( 'label_cell_props' => '', 'input_cell_props' => '', 'label_cell_th' => false, 'input_width' => '', 'input_name_prefix' => '', 'input_name_suffix' => '' ), $atts ); $input_class = isset($field['class']) ? $field['class'] : array(); if($ftype == 'multiselect'){ $input_class[] = 'thpladmin-enhanced-multi-select'; $args['input_name_suffix'] = $args['input_name_suffix'].'[]'; }else if($ftype == 'colorpicker'){ $input_class[] = 'thpladmin-colorpicker'; } $fname = $args['input_name_prefix'] . $name . $args['input_name_suffix']; $flabel = isset($field['label']) ? $field['label'] : ''; $default_value = isset($field['default_value']) ? $field['default_value'] : 1; $fvalue = isset($field['value']) ? $field['value'] : $default_value; $fwrapper = isset($field['wrapper']) ? $field['wrapper'] : ''; $cols = isset($field['cols']) ? $field['cols'] : ''; $rows = isset($field['rows']) ? $field['rows'] : ''; $id = $fname; $I_id = isset($field['ids']) ? $field['ids'] : array(); $input_width = $args['input_width'] ? 'width:'.$args['input_width'].';' : ''; $fvalue = ($ftype === 'number' && !$fvalue) ? $default_value : $fvalue; // Build escaped field attributes $field_attrs = [ 'id' => esc_attr($id), 'name' => esc_attr($fname), 'value' => esc_attr($fvalue), 'style' => esc_attr($input_width), ]; // Special cases if ($ftype === 'radio_btn' || $ftype === 'iconpicker') { $field_attrs = [ 'name' => esc_attr($fname), 'style'=> esc_attr($input_width), ]; } if ($ftype === 'textarea') { $field_attrs['spellcheck'] = 'false'; $field_attrs['cols'] = esc_attr($cols); $field_attrs['rows'] = esc_attr($rows); } if (!empty($field['placeholder'])) { $field_attrs['placeholder'] = esc_attr($field['placeholder']); } if (!empty($input_class) && is_array($input_class)) { $field_attrs['class'] = esc_attr(implode(' ', $input_class)); } // Convert attributes array to string $field_props = ''; foreach ($field_attrs as $attr => $val) { $field_props .= $attr . '="' . $val . '" '; } $field_props = trim($field_props); $required_html = isset($field['required']) && $field['required'] ? '*' : ''; $field_html = ''; if(isset($field['onchange']) && !empty($field['onchange'])){ $field_props .= ' onchange="'.$field['onchange'].'"'; } if(isset($field['onkeyup']) && !empty($field['onkeyup'])){ $field_props .= ' onkeyup="'.$field['onkeyup'].'"'; } if($ftype === 'radio_btn'){ $F_rvalue = isset($field['rvalue']) ? $field['rvalue'] : array(); $F_icon_path = isset($field['icon_path']) ? $field['icon_path'] : array(); $F_count = count($F_rvalue); $F_path = plugin_dir_url(__FILE__); } if($ftype == 'text'){ $field_html = ''; }else if($ftype == 'number'){ $field_html = ''; }else if($ftype == 'textarea'){ $field_html = ''; }else if($ftype == 'select'){ $field_html = ''; }else if($ftype == 'multiselect'){ $fvalue_arr = $fvalue ? explode(',', $fvalue) : array(); $field_html = '
'; }else if($ftype == 'colorpicker'){ $prev_style = $fvalue ? 'background-color:'.esc_attr($fvalue).';' : ''; $field_html = ''; $field_html .= ''; }else if($ftype == 'switch'){ $field_props .= isset($field['checked']) && $field['checked'] ? ' checked' : ''; $field_html .= ''; }elseif($ftype === 'radio_btn'){ for($i=0; $i<$F_count; $i++){ $selected = $fvalue === $F_rvalue[$i] ? 'checked' : ''; $F_root = $F_path.'icons/'.$F_icon_path[$i]; $field_html .= ''; $field_html .= ''; } }elseif($ftype === 'iconpicker'){ $F_icons = THFAQF_Utils::get_font_awesome_icons(); $count = 0; $field_html .= ''; $field_html .= ''; } if($render_cell){ $label_cell_props = !empty($args['label_cell_props']) ? ' '.$args['label_cell_props'] : ''; $input_cell_props = !empty($args['input_cell_props']) ? ' '.$args['input_cell_props'] : ''; ?>