assets
3 months ago
class-thwcfd-admin-form-block-field.php
3 months ago
class-thwcfd-admin-form-block-section.php
3 months ago
class-thwcfd-admin-form-field.php
3 months ago
class-thwcfd-admin-form.php
3 months ago
class-thwcfd-admin-settings-advanced.php
3 months ago
class-thwcfd-admin-settings-block-fields.php
3 months ago
class-thwcfd-admin-settings-general.php
3 months ago
class-thwcfd-admin-settings-pro.php
3 months ago
class-thwcfd-admin-settings-themehigh-plugins.php
3 months ago
class-thwcfd-admin-settings.php
3 months ago
class-thwcfd-admin.php
3 months ago
thwcfd-landing-page.php
3 months ago
class-thwcfd-admin-settings.php
279 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The admin settings page functionality of the plugin. |
| 4 | * |
| 5 | * @link https://themehigh.com |
| 6 | * |
| 7 | * @package woo-checkout-field-editor-pro |
| 8 | * @subpackage woo-checkout-field-editor-pro/admin |
| 9 | */ |
| 10 | |
| 11 | if(!defined('WPINC')){ die; } |
| 12 | |
| 13 | if(!class_exists('THWCFD_Admin_Settings')): |
| 14 | |
| 15 | abstract class THWCFD_Admin_Settings{ |
| 16 | protected $page_id = ''; |
| 17 | protected $c_type = ''; |
| 18 | protected $section_id = ''; |
| 19 | |
| 20 | protected $tabs = ''; |
| 21 | protected $sections = ''; |
| 22 | |
| 23 | public function __construct() { |
| 24 | $this->tabs = array( |
| 25 | 'fields' => __('Checkout Fields', 'woo-checkout-field-editor-pro'), |
| 26 | //'block_fields' => __('Block Checkout Fields', 'woo-checkout-field-editor-pro'), |
| 27 | 'advanced_settings' => __('Advanced Settings', 'woo-checkout-field-editor-pro'), |
| 28 | 'pro' => __('Premium Features', 'woo-checkout-field-editor-pro'), |
| 29 | 'themehigh_plugins' => __('Other Free Plugins', 'woo-checkout-field-editor-pro'), |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | public function get_tabs(){ |
| 34 | return $this->tabs; |
| 35 | } |
| 36 | |
| 37 | public function get_current_tab(){ |
| 38 | return $this->page_id; |
| 39 | } |
| 40 | |
| 41 | public function get_current_c_type(){ |
| 42 | return isset( $_GET['c_type'] ) ? sanitize_key( $_GET['c_type'] ) : 'classic'; |
| 43 | } |
| 44 | |
| 45 | public function get_current_section(){ |
| 46 | return isset( $_GET['section'] ) ? sanitize_key( $_GET['section'] ) : $this->section_id; |
| 47 | } |
| 48 | |
| 49 | public function render_tabs(){ |
| 50 | $current_tab = $this->get_current_tab(); |
| 51 | $tabs = $this->get_tabs(); |
| 52 | |
| 53 | if(empty($tabs)){ |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | echo '<h2 class="thpladmin-tabs nav-tab-wrapper woo-nav-tab-wrapper">'; |
| 58 | foreach( $tabs as $id => $label ){ |
| 59 | $active = ( $current_tab == $id ) ? 'nav-tab-active' : ''; |
| 60 | //$label = esc_html__($label, 'woo-checkout-field-editor-pro'); |
| 61 | echo '<a class="nav-tab '.esc_attr($active).'" href="'. esc_url($this->get_admin_url($id)) .'">'.esc_html($label).'</a>'; |
| 62 | } |
| 63 | echo '</h2>'; |
| 64 | } |
| 65 | |
| 66 | // public function render_sections() { |
| 67 | // $current_section = $this->get_current_section(); |
| 68 | // $sections = $this->get_sections(); |
| 69 | |
| 70 | // if(empty($sections)){ |
| 71 | // return; |
| 72 | // } |
| 73 | |
| 74 | // $array_keys = array_keys( $sections ); |
| 75 | |
| 76 | // echo '<ul class="thpladmin-sections">'; |
| 77 | // foreach( $sections as $id => $label ){ |
| 78 | // $label = wp_strip_all_tags(__($label, 'woo-checkout-field-editor-pro')); |
| 79 | // $url = $this->get_admin_url($this->page_id, sanitize_title($id)); |
| 80 | // echo '<li><a href="'. $url .'" class="'. ( $current_section == $id ? 'current' : '' ) .'">'. $label .'</a> '. (end( $array_keys ) == $id ? '' : '|') .' </li>'; |
| 81 | // } |
| 82 | // echo '</ul>'; |
| 83 | // } |
| 84 | |
| 85 | public function get_admin_url($tab = false, $c_type = false,$section = false){ |
| 86 | $url = 'admin.php?page=checkout_form_designer'; |
| 87 | if($tab && !empty($tab)){ |
| 88 | $url .= '&tab='. $tab; |
| 89 | } |
| 90 | if($c_type && !empty($c_type)){ |
| 91 | $url .= '&c_type='. $c_type; |
| 92 | } |
| 93 | if($section && !empty($section)){ |
| 94 | $url .= '§ion='. $section; |
| 95 | } |
| 96 | return admin_url($url); |
| 97 | } |
| 98 | |
| 99 | public function print_notices($msg, $type='updated', $return=false){ |
| 100 | |
| 101 | // $notice = '<div class="thwcfd-notice '. $type .'"><p>'. $msg .'</p></div>'; |
| 102 | // if(!$return){ |
| 103 | // echo $notice; |
| 104 | // } |
| 105 | // return $notice; |
| 106 | ?> |
| 107 | <div class="thwcfd-notice <?php echo esc_attr($type); ?>"><p><?php echo esc_html($msg); ?></p></div> |
| 108 | <?php |
| 109 | |
| 110 | } |
| 111 | |
| 112 | /******************************************* |
| 113 | *-------- HTML FORM FRAGMENTS - START ----- |
| 114 | *******************************************/ |
| 115 | |
| 116 | public function render_form_element_tooltip($tooltip=''){ |
| 117 | $tooltip_html = ''; |
| 118 | |
| 119 | if($tooltip){ |
| 120 | // $icon = THWCFD_ASSETS_URL_ADMIN.'/images/help.png'; |
| 121 | // $tooltip_html = '<a href="javascript:void(0)" title="'. $tooltip .'" class="thpladmin_tooltip"><img src="'. $icon .'" alt="" title=""/></a>'; |
| 122 | } |
| 123 | ?> |
| 124 | <td style="width: 26px; padding:0px;"><?php esc_html($tooltip_html); ?></td> |
| 125 | <?php |
| 126 | } |
| 127 | |
| 128 | public function render_form_element_empty_cell(){ |
| 129 | ?> |
| 130 | <td width="13%"> </td> |
| 131 | <?php $this->render_form_element_tooltip(false); ?> |
| 132 | <td width="34%"> </td> |
| 133 | <?php |
| 134 | } |
| 135 | |
| 136 | public function render_form_element_h_separator($padding = 5, $colspan = 6){ |
| 137 | ?> |
| 138 | <tr><td colspan="<?php echo esc_attr($colspan); ?>" style="border-bottom: 1px dashed #e6e6e6; padding-top: <?php echo esc_attr($padding) ?>px;"></td></tr> |
| 139 | <?php |
| 140 | } |
| 141 | |
| 142 | public function render_form_element_h_spacing($padding = 5, $colspan = 6){ |
| 143 | ?> |
| 144 | <tr><td colspan="<?php echo esc_attr($colspan); ?>" style="padding-top:<?php echo esc_attr($padding) ?>px;"></td></tr> |
| 145 | <?php |
| 146 | } |
| 147 | |
| 148 | public function render_form_field_element($field, $atts = array(), $render_cell = true){ |
| 149 | |
| 150 | if($field && is_array($field)){ |
| 151 | $args = shortcode_atts( array( |
| 152 | 'label_cell_props' => '', |
| 153 | 'input_cell_props' => '', |
| 154 | 'label_cell_colspan' => '', |
| 155 | 'input_cell_colspan' => '', |
| 156 | ), $atts ); |
| 157 | |
| 158 | $ftype = isset($field['type']) ? $field['type'] : 'text'; |
| 159 | $flabel = isset($field['label']) && !empty($field['label']) ? $field['label'] : ''; |
| 160 | $sub_label = isset($field['sub_label']) && !empty($field['sub_label']) ? $field['sub_label'] : ''; |
| 161 | $tooltip = isset($field['hint_text']) && !empty($field['hint_text']) ? $field['hint_text'] : ''; |
| 162 | |
| 163 | $field_html = ''; |
| 164 | |
| 165 | if($ftype == 'text'){ |
| 166 | $field_html = $this->render_form_field_element_inputtext($field, $atts); |
| 167 | |
| 168 | }else if($ftype == 'textarea'){ |
| 169 | $field_html = $this->render_form_field_element_textarea($field, $atts); |
| 170 | |
| 171 | }else if($ftype == 'checkbox'){ |
| 172 | $field_html = $this->render_form_field_element_checkbox($field, $atts, $render_cell); |
| 173 | $flabel = ' '; |
| 174 | } |
| 175 | |
| 176 | if($render_cell){ |
| 177 | $required_html = isset($field['required']) && $field['required'] ? '<abbr class="required" title="required">*</abbr>' : ''; |
| 178 | |
| 179 | $label_cell_props = !empty($args['label_cell_props']) ? $args['label_cell_props'] : ''; |
| 180 | $input_cell_props = !empty($args['input_cell_props']) ? $args['input_cell_props'] : ''; |
| 181 | ?> |
| 182 | <td <?php echo wp_kses($label_cell_props, array('class' => true)) ?> > |
| 183 | <?php echo esc_html($flabel); echo wp_kses($required_html, array('abbr' => true)); |
| 184 | if($sub_label){ |
| 185 | ?> |
| 186 | <br/><span class="thpladmin-subtitle"><?php echo esc_html($sub_label); ?></span> |
| 187 | <?php |
| 188 | } |
| 189 | ?> |
| 190 | </td> |
| 191 | <?php $this->render_form_element_tooltip($tooltip); ?> |
| 192 | <td <?php echo wp_kses($input_cell_props, array('class' => true)) ?> ><?php echo wp_kses($field_html, THWCFD_Utils::get_allowed_html()); ?></td> |
| 193 | <?php |
| 194 | }else{ |
| 195 | echo wp_kses($field_html, THWCFD_Utils::get_allowed_html()); |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | private function prepare_form_field_props($field, $atts = array()){ |
| 201 | $field_props = ''; |
| 202 | $args = shortcode_atts( array( |
| 203 | 'input_width' => '', |
| 204 | 'input_name_prefix' => 'i_', |
| 205 | 'input_name_suffix' => '', |
| 206 | ), $atts ); |
| 207 | |
| 208 | $ftype = isset($field['type']) ? $field['type'] : 'text'; |
| 209 | |
| 210 | if($ftype == 'multiselect'){ |
| 211 | $args['input_name_suffix'] = $args['input_name_suffix'].'[]'; |
| 212 | } |
| 213 | |
| 214 | $fname = $args['input_name_prefix'].$field['name'].$args['input_name_suffix']; |
| 215 | $fvalue = isset($field['value']) ? esc_html($field['value']) : ''; |
| 216 | |
| 217 | $input_width = $args['input_width'] ? 'width:'.$args['input_width'].';' : ''; |
| 218 | $field_props = 'name="'. $fname .'" value="'. $fvalue .'" style="'. $input_width .'"'; |
| 219 | $field_props .= ( isset($field['placeholder']) && !empty($field['placeholder']) ) ? ' placeholder="'.$field['placeholder'].'"' : ''; |
| 220 | $field_props .= ( isset($field['onchange']) && !empty($field['onchange']) ) ? ' onchange="'.$field['onchange'].'"' : ''; |
| 221 | |
| 222 | return $field_props; |
| 223 | } |
| 224 | |
| 225 | private function render_form_field_element_inputtext($field, $atts = array()){ |
| 226 | $field_html = ''; |
| 227 | if($field && is_array($field)){ |
| 228 | $field_props = $this->prepare_form_field_props($field, $atts); |
| 229 | $field_html = '<input type="text" '. wp_kses_post($field_props) .' />'; |
| 230 | } |
| 231 | return $field_html; |
| 232 | } |
| 233 | |
| 234 | private function render_form_field_element_textarea($field, $atts = array()){ |
| 235 | $field_html = ''; |
| 236 | if($field && is_array($field)){ |
| 237 | $args = shortcode_atts( array( |
| 238 | 'rows' => '5', |
| 239 | 'cols' => '100', |
| 240 | ), $atts ); |
| 241 | |
| 242 | $fvalue = isset($field['value']) ? $field['value'] : ''; |
| 243 | $field_props = $this->prepare_form_field_props($field, $atts); |
| 244 | $field_html = '<textarea '. wp_kses_post($field_props) .' rows="'.esc_attr($args['rows']).'" cols="'.esc_attr($args['cols']).'" >'.esc_html($fvalue).'</textarea>'; |
| 245 | } |
| 246 | return $field_html; |
| 247 | } |
| 248 | |
| 249 | private function render_form_field_element_checkbox($field, $atts = array(), $render_cell = true){ |
| 250 | |
| 251 | $field_html = ''; |
| 252 | if($field && is_array($field)){ |
| 253 | $args = shortcode_atts( array( |
| 254 | 'label_props' => '', |
| 255 | 'cell_props' => 3, |
| 256 | 'render_input_cell' => false, |
| 257 | ), $atts ); |
| 258 | |
| 259 | $fid = 'a_f'. $field['name']; |
| 260 | $flabel = isset($field['label']) && !empty($field['label']) ? $field['label'] : ''; |
| 261 | |
| 262 | $field_props = $this->prepare_form_field_props($field, $atts); |
| 263 | $field_props .= isset($field['checked']) && $field['checked'] === 1 ? ' checked' : ''; |
| 264 | |
| 265 | $field_html = '<input type="checkbox" id="'. esc_attr($fid) .'" '. wp_kses_post($field_props) .' />'; |
| 266 | $field_html .= '<label for="'. esc_attr($fid) .'" '. wp_kses_post($args['label_props']) .' > '. esc_html($flabel) .'</label>'; |
| 267 | } |
| 268 | if(!$render_cell && $args['render_input_cell']){ |
| 269 | return '<td '. wp_kses_post($args['cell_props']) .' >'. wp_kses($field_html, THWCFD_Utils::get_allowed_html()) .'</td>'; |
| 270 | }else{ |
| 271 | return wp_kses($field_html,THWCFD_Utils::get_allowed_html()); |
| 272 | } |
| 273 | } |
| 274 | /******************************************* |
| 275 | *-------- HTML FORM FRAGMENTS - END ----- |
| 276 | *******************************************/ |
| 277 | } |
| 278 | |
| 279 | endif; |