1 <?php
  2 /**
  3  * Admin Settings API used by Shipping Methods and Payment Gateways
  4  *
  5  * @class       WC_Settings_API
  6  * @version     2.1.0
  7  * @package     WooCommerce/Abstracts
  8  * @category    Abstract Class
  9  * @author      WooThemes
 10  */
 11 abstract class WC_Settings_API {
 12 
 13     /** @var string The plugin ID. Used for option names. */
 14     public $plugin_id = 'woocommerce_';
 15 
 16     /** @var array Array of setting values. */
 17     public $settings = array();
 18 
 19     /** @var array Array of form option fields. */
 20     public $form_fields = array();
 21 
 22     /** @var array Array of validation errors. */
 23     public $errors = array();
 24 
 25     /** @var array Sanitized fields after validation. */
 26     public $sanitized_fields = array();
 27 
 28     /**
 29      * Admin Options
 30      *
 31      * Setup the gateway settings screen.
 32      * Override this in your gateway.
 33      *
 34      * @since 1.0.0
 35      * @access public
 36      * @return void
 37      */
 38     public function admin_options() { ?>
 39         <h3><?php echo ( ! empty( $this->method_title ) ) ? $this->method_title : __( 'Settings', 'woocommerce' ) ; ?></h3>
 40 
 41         <?php echo ( ! empty( $this->method_description ) ) ? wpautop( $this->method_description ) : ''; ?>
 42 
 43         <table class="form-table">
 44             <?php $this->generate_settings_html(); ?>
 45         </table><?php
 46     }
 47 
 48     /**
 49      * Initialise Settings Form Fields
 50      *
 51      * Add an array of fields to be displayed
 52      * on the gateway's settings screen.
 53      *
 54      * @since 1.0.0
 55      * @access public
 56      * @return string
 57      */
 58     public function init_form_fields() {}
 59 
 60     /**
 61      * Get the form fields after they are initialized
 62      * 
 63      * @return array of options
 64      */
 65     public function get_form_fields() {
 66         return apply_filters( 'woocommerce_settings_api_form_fields_' . $this->id, $this->form_fields );
 67     }
 68 
 69     /**
 70      * Admin Panel Options Processing
 71      * - Saves the options to the DB
 72      *
 73      * @since 1.0.0
 74      * @access public
 75      * @return bool
 76      */
 77     public function process_admin_options() {
 78         $this->validate_settings_fields();
 79 
 80         if ( count( $this->errors ) > 0 ) {
 81             $this->display_errors();
 82             return false;
 83         } else {
 84             update_option( $this->plugin_id . $this->id . '_settings', apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->sanitized_fields ) );
 85             $this->init_settings();
 86             return true;
 87         }
 88     }
 89 
 90     /**
 91      * Display admin error messages.
 92      *
 93      * @since 1.0.0
 94      * @access public
 95      * @return void
 96      */
 97     public function display_errors() {}
 98 
 99     /**
100      * Initialise Gateway Settings
101      *
102      * Store all settings in a single database entry
103      * and make sure the $settings array is either the default
104      * or the settings stored in the database.
105      *
106      * @since 1.0.0
107      * @uses get_option(), add_option()
108      * @access public
109      * @return void
110      */
111     public function init_settings() {
112         // Load form_field settings
113         $this->settings = get_option( $this->plugin_id . $this->id . '_settings', null );
114 
115         if ( ! $this->settings || ! is_array( $this->settings ) ) {
116 
117             $this->settings = array();
118 
119             // If there are no settings defined, load defaults
120             if ( $form_fields = $this->get_form_fields() )
121                 foreach ( $form_fields as $k => $v )
122                     $this->settings[ $k ] = isset( $v['default'] ) ? $v['default'] : '';
123         }
124 
125         if ( $this->settings && is_array( $this->settings ) ) {
126             $this->settings = array_map( array( $this, 'format_settings' ), $this->settings );
127             $this->enabled  = isset( $this->settings['enabled'] ) && $this->settings['enabled'] == 'yes' ? 'yes' : 'no';
128         }
129     }
130 
131     /**
132      * get_option function.
133      *
134      * Gets and option from the settings API, using defaults if necessary to prevent undefined notices.
135      *
136      * @access public
137      * @param string $key
138      * @param mixed $empty_value
139      * @return string The value specified for the option or a default value for the option
140      */
141     public function get_option( $key, $empty_value = null ) {
142         if ( empty( $this->settings ) )
143             $this->init_settings();
144 
145         // Get option default if unset
146         if ( ! isset( $this->settings[ $key ] ) ) {
147             $form_fields            = $this->get_form_fields();
148             $this->settings[ $key ] = isset( $form_fields[ $key ]['default'] ) ? $form_fields[ $key ]['default'] : '';
149         }
150 
151         if ( ! is_null( $empty_value ) && empty( $this->settings[ $key ] ) )
152             $this->settings[ $key ] = $empty_value;
153 
154         return $this->settings[ $key ];
155     }
156 
157     /**
158      * Decode values for settings.
159      *
160      * @access public
161      * @param mixed $value
162      * @return array
163      */
164     public function format_settings( $value ) {
165         return is_array( $value ) ? $value : $value;
166     }
167 
168     /**
169      * Generate Settings HTML.
170      *
171      * Generate the HTML for the fields on the "settings" screen.
172      *
173      * @access public
174      * @param bool $form_fields (default: false)
175      * @since 1.0.0
176      * @uses method_exists()
177      * @access public
178      * @return string the html for the settings
179      */
180     public function generate_settings_html( $form_fields = false ) {
181         if ( ! $form_fields )
182             $form_fields = $this->get_form_fields();
183 
184         $html = '';
185         foreach ( $form_fields as $k => $v ) {
186             if ( ! isset( $v['type'] ) || ( $v['type'] == '' ) )
187                 $v['type'] = 'text'; // Default to "text" field type.
188 
189             if ( method_exists( $this, 'generate_' . $v['type'] . '_html' ) ) {
190                 $html .= $this->{'generate_' . $v['type'] . '_html'}( $k, $v );
191             } else {
192                 $html .= $this->{'generate_text_html'}( $k, $v );
193             }
194         }
195 
196         echo $html;
197     }
198 
199     /**
200      * Get HTML for tooltips
201      * @param  array $data
202      * @return string
203      */
204     public function get_tooltip_html( $data ) {
205         if ( $data['desc_tip'] === true ) {
206             $tip = $data['description'];
207         } elseif ( ! empty( $data['desc_tip'] ) ) {
208             $tip = $data['desc_tip'];
209         } else {
210             $tip = '';
211         }
212 
213         return $tip ? '<img class="help_tip" data-tip="' . esc_attr( $tip ) . '" src="' . WC()->plugin_url() . '/assets/images/help.png" height="16" width="16" />' : '';
214     }
215 
216     /**
217      * Get HTML for descriptions
218      * @param  array $data
219      * @return string
220      */
221     public function get_description_html( $data ) {
222         if ( $data['desc_tip'] === true ) {
223             $description = '';
224         } elseif ( ! empty( $data['desc_tip'] ) ) {
225             $description = $data['description'];
226         } elseif ( ! empty( $data['description'] ) ) {
227             $description = $data['description'];
228         } else {
229             $description = '';
230         }
231 
232         return $description ? '<p class="description">' . wp_kses_post( $description ) . '</p>' . "\n" : '';
233     }
234 
235     /**
236      * Get custom attributes
237      * @param  array $data
238      * @return string
239      */
240     public function get_custom_attribute_html( $data ) {
241         $custom_attributes = array();
242 
243         if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) )
244             foreach ( $data['custom_attributes'] as $attribute => $attribute_value )
245                 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
246 
247         return implode( ' ', $custom_attributes );
248     }
249 
250     /**
251      * Generate Text Input HTML.
252      *
253      * @access public
254      * @param mixed $key
255      * @param mixed $data
256      * @since 1.0.0
257      * @return string
258      */
259     public function generate_text_html( $key, $data ) {
260         $field    = $this->plugin_id . $this->id . '_' . $key;
261         $defaults = array(
262             'title'             => '',
263             'disabled'          => false,
264             'class'             => '',
265             'css'               => '',
266             'placeholder'       => '',
267             'type'              => 'text',
268             'desc_tip'          => false,
269             'description'       => '',
270             'custom_attributes' => array()
271         );
272 
273         $data = wp_parse_args( $data, $defaults );
274 
275         ob_start();
276         ?>
277         <tr valign="top">
278             <th scope="row" class="titledesc">
279                 <label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
280                 <?php echo $this->get_tooltip_html( $data ); ?>
281             </th>
282             <td class="forminp">
283                 <fieldset>
284                     <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
285                     <input class="input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="<?php echo esc_attr( $data['type'] ); ?>" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( $this->get_option( $key ) ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> />
286                     <?php echo $this->get_description_html( $data ); ?>
287                 </fieldset>
288             </td>
289         </tr>
290         <?php
291         return ob_get_clean();
292     }
293 
294     /**
295      * Generate Password Input HTML.
296      *
297      * @access public
298      * @param mixed $key
299      * @param mixed $data
300      * @since 1.0.0
301      * @return string
302      */
303     public function generate_price_html( $key, $data ) {
304         $field    = $this->plugin_id . $this->id . '_' . $key;
305         $defaults = array(
306             'title'             => '',
307             'disabled'          => false,
308             'class'             => '',
309             'css'               => '',
310             'placeholder'       => '',
311             'type'              => 'text',
312             'desc_tip'          => false,
313             'description'       => '',
314             'custom_attributes' => array()
315         );
316 
317         $data = wp_parse_args( $data, $defaults );
318 
319         ob_start();
320         ?>
321         <tr valign="top">
322             <th scope="row" class="titledesc">
323                 <label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
324                 <?php echo $this->get_tooltip_html( $data ); ?>
325             </th>
326             <td class="forminp">
327                 <fieldset>
328                     <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
329                     <input class="wc_input_price input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( wc_format_localized_price( $this->get_option( $key ) ) ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> />
330                     <?php echo $this->get_description_html( $data ); ?>
331                 </fieldset>
332             </td>
333         </tr>
334         <?php
335         return ob_get_clean();
336     }
337 
338     /**
339      * Generate Password Input HTML.
340      *
341      * @access public
342      * @param mixed $key
343      * @param mixed $data
344      * @since 1.0.0
345      * @return string
346      */
347     public function generate_decimal_html( $key, $data ) {
348         $field    = $this->plugin_id . $this->id . '_' . $key;
349         $defaults = array(
350             'title'             => '',
351             'disabled'          => false,
352             'class'             => '',
353             'css'               => '',
354             'placeholder'       => '',
355             'type'              => 'text',
356             'desc_tip'          => false,
357             'description'       => '',
358             'custom_attributes' => array()
359         );
360 
361         $data = wp_parse_args( $data, $defaults );
362 
363         ob_start();
364         ?>
365         <tr valign="top">
366             <th scope="row" class="titledesc">
367                 <label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
368                 <?php echo $this->get_tooltip_html( $data ); ?>
369             </th>
370             <td class="forminp">
371                 <fieldset>
372                     <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
373                     <input class="wc_input_decimal input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( wc_format_localized_decimal( $this->get_option( $key ) ) ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> />
374                     <?php echo $this->get_description_html( $data ); ?>
375                 </fieldset>
376             </td>
377         </tr>
378         <?php
379         return ob_get_clean();
380     }
381 
382     /**
383      * Generate Password Input HTML.
384      *
385      * @access public
386      * @param mixed $key
387      * @param mixed $data
388      * @since 1.0.0
389      * @return string
390      */
391     public function generate_password_html( $key, $data ) {
392         $data['type'] = 'password';
393         return $this->generate_text_html( $key, $data );
394     }
395 
396     /**
397      * Generate Textarea HTML.
398      *
399      * @access public
400      * @param mixed $key
401      * @param mixed $data
402      * @since 1.0.0
403      * @return string
404      */
405     public function generate_textarea_html( $key, $data ) {
406         $field    = $this->plugin_id . $this->id . '_' . $key;
407         $defaults = array(
408             'title'             => '',
409             'disabled'          => false,
410             'class'             => '',
411             'css'               => '',
412             'placeholder'       => '',
413             'type'              => 'text',
414             'desc_tip'          => false,
415             'description'       => '',
416             'custom_attributes' => array()
417         );
418 
419         $data = wp_parse_args( $data, $defaults );
420 
421         ob_start();
422         ?>
423         <tr valign="top">
424             <th scope="row" class="titledesc">
425                 <label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
426                 <?php echo $this->get_tooltip_html( $data ); ?>
427             </th>
428             <td class="forminp">
429                 <fieldset>
430                     <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
431                     <textarea rows="3" cols="20" class="input-text wide-input <?php echo esc_attr( $data['class'] ); ?>" type="<?php echo esc_attr( $data['type'] ); ?>" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?>><?php echo esc_textarea( $this->get_option( $key ) ); ?></textarea>
432                     <?php echo $this->get_description_html( $data ); ?>
433                 </fieldset>
434             </td>
435         </tr>
436         <?php
437         return ob_get_clean();
438     }
439 
440     /**
441      * Generate Checkbox HTML.
442      *
443      * @access public
444      * @param mixed $key
445      * @param mixed $data
446      * @since 1.0.0
447      * @return string
448      */
449     public function generate_checkbox_html( $key, $data ) {
450         $field    = $this->plugin_id . $this->id . '_' . $key;
451         $defaults = array(
452             'title'             => '',
453             'label'             => '',
454             'disabled'          => false,
455             'class'             => '',
456             'css'               => '',
457             'type'              => 'text',
458             'desc_tip'          => false,
459             'description'       => '',
460             'custom_attributes' => array()
461         );
462 
463         $data = wp_parse_args( $data, $defaults );
464 
465         if ( ! $data['label'] )
466             $data['label'] = $data['title'];
467 
468         ob_start();
469         ?>
470         <tr valign="top">
471             <th scope="row" class="titledesc">
472                 <label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
473                 <?php echo $this->get_tooltip_html( $data ); ?>
474             </th>
475             <td class="forminp">
476                 <fieldset>
477                     <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
478                     <label for="<?php echo esc_attr( $field ); ?>">
479                     <input <?php disabled( $data['disabled'], true ); ?> class="<?php echo esc_attr( $data['class'] ); ?>" type="checkbox" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="1" <?php checked( $this->get_option( $key ), 'yes' ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> /> <?php echo wp_kses_post( $data['label'] ); ?></label><br/>
480                     <?php echo $this->get_description_html( $data ); ?>
481                 </fieldset>
482             </td>
483         </tr>
484         <?php
485         return ob_get_clean();
486     }
487 
488     /**
489      * Generate Select HTML.
490      *
491      * @access public
492      * @param mixed $key
493      * @param mixed $data
494      * @since 1.0.0
495      * @return string
496      */
497     public function generate_select_html( $key, $data ) {
498         $field    = $this->plugin_id . $this->id . '_' . $key;
499         $defaults = array(
500             'title'             => '',
501             'disabled'          => false,
502             'class'             => '',
503             'css'               => '',
504             'placeholder'       => '',
505             'type'              => 'text',
506             'desc_tip'          => false,
507             'description'       => '',
508             'custom_attributes' => array(),
509             'options'           => array()
510         );
511 
512         $data = wp_parse_args( $data, $defaults );
513 
514         ob_start();
515         ?>
516         <tr valign="top">
517             <th scope="row" class="titledesc">
518                 <label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
519                 <?php echo $this->get_tooltip_html( $data ); ?>
520             </th>
521             <td class="forminp">
522                 <fieldset>
523                     <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
524                     <select class="select <?php echo esc_attr( $data['class'] ); ?>" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?>>
525                         <?php foreach ( (array) $data['options'] as $option_key => $option_value ) : ?>
526                             <option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $option_key, esc_attr( $this->get_option( $key ) ) ); ?>><?php echo esc_attr( $option_value ); ?></option>
527                         <?php endforeach; ?>
528                     </select>
529                     <?php echo $this->get_description_html( $data ); ?>
530                 </fieldset>
531             </td>
532         </tr>
533         <?php
534         return ob_get_clean();
535     }
536 
537     /**
538      * Generate Multiselect HTML.
539      *
540      * @access public
541      * @param mixed $key
542      * @param mixed $data
543      * @since 1.0.0
544      * @return string
545      */
546     public function generate_multiselect_html( $key, $data ) {
547         $field    = $this->plugin_id . $this->id . '_' . $key;
548         $defaults = array(
549             'title'             => '',
550             'disabled'          => false,
551             'class'             => '',
552             'css'               => '',
553             'placeholder'       => '',
554             'type'              => 'text',
555             'desc_tip'          => false,
556             'description'       => '',
557             'custom_attributes' => array(),
558             'options'           => array()
559         );
560 
561         $data = wp_parse_args( $data, $defaults );
562 
563         ob_start();
564         ?>
565         <tr valign="top">
566             <th scope="row" class="titledesc">
567                 <label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
568                 <?php echo $this->get_tooltip_html( $data ); ?>
569             </th>
570             <td class="forminp">
571                 <fieldset>
572                     <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
573                     <select multiple="multiple" class="multiselect <?php echo esc_attr( $data['class'] ); ?>" name="<?php echo esc_attr( $field ); ?>[]" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?>>
574                         <?php foreach ( (array) $data['options'] as $option_key => $option_value ) : ?>
575                             <option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( in_array( $option_key, $this->get_option( $key, array() ) ), true ); ?>><?php echo esc_attr( $option_value ); ?></option>
576                         <?php endforeach; ?>
577                     </select>
578                     <?php echo $this->get_description_html( $data ); ?>
579                 </fieldset>
580             </td>
581         </tr>
582         <?php
583         return ob_get_clean();
584     }
585 
586     /**
587      * Generate Title HTML.
588      *
589      * @access public
590      * @param mixed $key
591      * @param mixed $data
592      * @since 1.6.2
593      * @return string
594      */
595     public function generate_title_html( $key, $data ) {
596         $defaults = array(
597             'title'             => '',
598             'class'             => '',
599             'css'               => ''
600         );
601 
602         $data = wp_parse_args( $data, $defaults );
603 
604         ob_start();
605         ?>
606             </table>
607             <h4 class="<?php echo esc_attr( $data['class'] ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></h4>
608             <?php if ( ! empty( $data['description'] ) ) : ?>
609                 <p><?php echo wp_kses_post( $data['description'] ); ?></p>
610             <?php endif; ?>
611             <table class="form-table">
612         <?php
613         return ob_get_clean();
614     }
615 
616     /**
617      * Validate Settings Field Data.
618      *
619      * Validate the data on the "Settings" form.
620      *
621      * @since 1.0.0
622      * @uses method_exists()
623      * @param bool $form_fields (default: false)
624      */
625     public function validate_settings_fields( $form_fields = false ) {
626         if ( ! $form_fields )
627             $form_fields = $this->get_form_fields();
628 
629         $this->sanitized_fields = array();
630 
631         foreach ( $form_fields as $k => $v ) {
632             if ( empty( $v['type'] ) )
633                 $v['type'] = 'text'; // Default to "text" field type.
634 
635             // Look for a validate_FIELDID_field method for special handling
636             if ( method_exists( $this, 'validate_' . $k . '_field' ) ) {
637                 $field = $this->{'validate_' . $k . '_field'}( $k );
638                 $this->sanitized_fields[ $k ] = $field;
639 
640             // Look for a validate_FIELDTYPE_field method
641             } elseif ( method_exists( $this, 'validate_' . $v['type'] . '_field' ) ) {
642                 $field = $this->{'validate_' . $v['type'] . '_field'}( $k );
643                 $this->sanitized_fields[ $k ] = $field;
644             
645             // Default to text
646             } else {
647                 $field = $this->{'validate_text_field'}( $k );
648                 $this->sanitized_fields[ $k ] = $field;
649             }
650         }
651     }
652 
653     /**
654      * Validate Checkbox Field.
655      *
656      * If not set, return "no", otherwise return "yes".
657      *
658      * @access public
659      * @param mixed $key
660      * @since 1.0.0
661      * @return string
662      */
663     public function validate_checkbox_field( $key ) {
664         $status = 'no';
665         if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) && ( 1 == $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) {
666             $status = 'yes';
667         }
668 
669         return $status;
670     }
671 
672     /**
673      * Validate Text Field.
674      *
675      * @param mixed $key
676      * @return string
677      */
678     public function validate_text_field( $key ) {
679         $text = $this->get_option( $key );
680 
681         if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) )
682             $text = wp_kses_post( trim( stripslashes( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) );
683 
684         return $text;
685     }
686 
687     /**
688      * Validate Price Field.
689      *
690      * @param mixed $key
691      * @return string
692      */
693     public function validate_price_field( $key ) {
694         $text = $this->get_option( $key );
695 
696         if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) {
697             if ( $_POST[ $this->plugin_id . $this->id . '_' . $key ] !== '' )
698                 $text = wc_format_decimal( trim( stripslashes( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) );
699             else
700                 $text = '';
701         }
702 
703         return $text;
704     }   
705 
706     /**
707      * Validate Price Field.
708      *
709      * @param mixed $key
710      * @return string
711      */
712     public function validate_decimal_field( $key ) {
713         $text = $this->get_option( $key );
714 
715         if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) {
716             if ( $_POST[ $this->plugin_id . $this->id . '_' . $key ] !== '' )
717                 $text = wc_format_decimal( trim( stripslashes( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) );
718             else
719                 $text = '';
720         }
721 
722         return $text;
723     }  
724 
725     /**
726      * Validate Password Field.
727      *
728      * Make sure the data is escaped correctly, etc.
729      *
730      * @access public
731      * @param mixed $key
732      * @since 1.0.0
733      * @return string
734      */
735     public function validate_password_field( $key ) {
736         $text = $this->get_option( $key );
737 
738         if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) {
739             $text = wc_clean( stripslashes( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) );
740         }
741 
742         return $text;
743     }
744 
745     /**
746      * Validate Textarea Field.
747      *
748      * Make sure the data is escaped correctly, etc.
749      *
750      * @access public
751      * @param mixed $key
752      * @since 1.0.0
753      * @return string
754      */
755     public function validate_textarea_field( $key ) {
756         $text = $this->get_option( $key );
757 
758         if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) {
759             $text = wp_kses( trim( stripslashes( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ),
760                 array_merge(
761                     array(
762                         'iframe' => array( 'src' => true, 'style' => true, 'id' => true, 'class' => true )
763                     ),
764                     wp_kses_allowed_html( 'post' )
765                 )
766             );
767         }
768 
769         return $text;
770     }
771 
772     /**
773      * Validate Select Field.
774      *
775      * Make sure the data is escaped correctly, etc.
776      *
777      * @access public
778      * @param mixed $key
779      * @since 1.0.0
780      * @return string
781      */
782     public function validate_select_field( $key ) {
783         $value = $this->get_option( $key );
784 
785         if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) {
786             $value = wc_clean( stripslashes( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) );
787         }
788 
789         return $value;
790     }
791 
792     /**
793      * Validate Multiselect Field.
794      *
795      * Make sure the data is escaped correctly, etc.
796      *
797      * @access public
798      * @param mixed $key
799      * @since 1.0.0
800      * @return string
801      */
802     public function validate_multiselect_field( $key ) {
803         $value = $this->get_option( $key );
804 
805         if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) {
806             $value = array_map( 'wc_clean', array_map( 'stripslashes', (array) $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) );
807         } else {
808             $value = '';
809         }
810 
811         return $value;
812     }
813 }
WooCommerce API documentation generated by ApiGen 2.8.0