| @@ -1,16 +1,18 @@ | ||
| 1 | 1 | <?php |
| 2 | -namespace WP_Improved_Settings; | |
| 2 | +namespace wpdeepl_WP_Improved_Settings; | |
| 3 | +if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 3 | 4 | /** |
| 4 | 5 | * Abstract Settings API Class |
| 5 | 6 | * From abstract-wc-settings-api.php |
| 6 | 7 | * |
| 7 | 8 | * |
| 8 | - * @package WP_Improved_Settings | |
| 9 | - * @version 20200320 | |
| 9 | + * @package wpdeepl_WP_Improved_Settings | |
| 10 | + * @version 20251205 | |
| 10 | 11 | * |
| 12 | + * 20251205 Version 2.0 - PCP compliant, architecture extensible | |
| 11 | 13 | * 20200320 ajout des setting en tableau |
| 12 | - * * 20190705 : default value for text field | |
| 14 | + * 20190705 : default value for text field | |
| 13 | 15 | */ |
| 14 | 16 | |
| 15 | 17 | defined( 'ABSPATH' ) || exit; |
| 16 | 18 | |
| @@ -16,9 +18,9 @@ | ||
| 16 | 18 | |
| 17 | 19 | /** |
| 18 | 20 | * WC_Improved_Settings_API class. |
| 19 | 21 | */ |
| 20 | -if ( !class_exists( 'WP_Improved_Settings\WC_Improved_Settings_API' ) ) { | |
| 22 | +if ( !class_exists( 'wpdeepl_WP_Improved_Settings\WC_Improved_Settings_API' ) ) { | |
| 21 | 23 | class WC_Improved_Settings_API { |
| 22 | 24 | /** |
| 23 | 25 | * The plugin ID. Used for option names. |
| 24 | 26 | * |
| @@ -33,13 +35,24 @@ | ||
| 33 | 35 | */ |
| 34 | 36 | public $id = ''; |
| 35 | 37 | |
| 36 | 38 | /** |
| 39 | + * Feature flags for version control | |
| 40 | + * | |
| 41 | + * @var array | |
| 42 | + */ | |
| 43 | + protected $features = array( | |
| 44 | + 'cache_enabled' => false, // v2.1+ | |
| 45 | + 'export_enabled' => false, // Sécurité WordPress.org | |
| 46 | + 'advanced_crons' => false, // v2.2+ | |
| 47 | + ); | |
| 48 | + | |
| 49 | + /** | |
| 37 | 50 | * Validation errors. |
| 38 | 51 | * |
| 39 | 52 | * @var array of strings |
| 40 | 53 | */ |
| 41 | - public $errors = array(); | |
| 54 | + protected $errors = array(); | |
| 42 | 55 | |
| 43 | 56 | /** |
| 44 | 57 | * Setting values. |
| 45 | 58 | * |
| @@ -44,9 +57,9 @@ | ||
| 44 | 57 | * Setting values. |
| 45 | 58 | * |
| 46 | 59 | * @var array |
| 47 | 60 | */ |
| 48 | - public $settings = array(); | |
| 61 | + protected $settings = array(); | |
| 49 | 62 | |
| 50 | 63 | /** |
| 51 | 64 | * Form option fields. |
| 52 | 65 | * |
| @@ -51,9 +64,9 @@ | ||
| 51 | 64 | * Form option fields. |
| 52 | 65 | * |
| 53 | 66 | * @var array |
| 54 | 67 | */ |
| 55 | - public $form_fields = array(); | |
| 68 | + protected $form_fields = array(); | |
| 56 | 69 | |
| 57 | 70 | /** |
| 58 | 71 | * The posted settings data. When empty, $_POST data will be used. |
| 59 | 72 | * |
| @@ -60,19 +73,42 @@ | ||
| 60 | 73 | * @var array |
| 61 | 74 | */ |
| 62 | 75 | protected $data = array(); |
| 63 | 76 | |
| 64 | - public $settingsStructure = array(); | |
| 77 | + /** | |
| 78 | + * Settings structure from configuration | |
| 79 | + * | |
| 80 | + * @var array | |
| 81 | + */ | |
| 82 | + protected $settingsStructure = array(); | |
| 65 | 83 | |
| 66 | 84 | public function __construct( $plugin_id , $settingsStructure ) { |
| 67 | 85 | $this->plugin_id = $plugin_id .'_'; |
| 68 | 86 | $this->settingsStructure = $settingsStructure; |
| 69 | 87 | $this->init_form_fields(); |
| 70 | - //add_action( 'woocommerce_update_options_' . $this->id, array( $this, 'process_admin_options' ) ); | |
| 71 | -// add_action( 'woocommerce_update_options', array( $this, 'test_action' ) ); | |
| 72 | 88 | } |
| 73 | 89 | |
| 74 | -/** | |
| 90 | + /** | |
| 91 | + * Get feature flag status | |
| 92 | + * | |
| 93 | + * @param string $feature Feature name | |
| 94 | + * @return bool Feature enabled status | |
| 95 | + */ | |
| 96 | + public function is_feature_enabled( $feature ) { | |
| 97 | + return isset( $this->features[$feature] ) ? $this->features[$feature] : false; | |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * Set feature flag | |
| 102 | + * | |
| 103 | + * @param string $feature Feature name | |
| 104 | + * @param bool $enabled Feature status | |
| 105 | + */ | |
| 106 | + public function set_feature( $feature, $enabled ) { | |
| 107 | + $this->features[$feature] = (bool) $enabled; | |
| 108 | + } | |
| 109 | + | |
| 110 | + /** | |
| 75 | 111 | * Initialise settings form fields. |
| 76 | 112 | * |
| 77 | 113 | * Add an array of fields to be displayed on the gateway's settings screen. |
| 78 | 114 | * |
| @@ -77,15 +113,13 @@ | ||
| 77 | 113 | * Add an array of fields to be displayed on the gateway's settings screen. |
| 78 | 114 | * |
| 79 | 115 | * @since 1.0.0 |
| 80 | 116 | */ |
| 81 | - | |
| 82 | - | |
| 83 | - public function init_form_fields() { | |
| 117 | + protected function init_form_fields() { | |
| 84 | 118 | if ( !$this->settingsStructure || !count($this->settingsStructure) ) { |
| 85 | 119 | return false; |
| 86 | 120 | } |
| 87 | - //plouf( $this->settingsStructure );die('okozerkozerk'); | |
| 121 | + //wpdeepl_debug_display( $this->settingsStructure );die('okozerkozerk'); | |
| 88 | 122 | foreach ( $this->settingsStructure as $tab_id => $tab_data ) { |
| 89 | 123 | foreach ( $tab_data['sections'] as $section_id => $section_data ) { |
| 90 | 124 | if( isset( $section_data['fields'] ) ) foreach ( $section_data['fields'] as $field ) { |
| 91 | 125 | $this->id = $tab_id; |
| @@ -102,18 +136,26 @@ | ||
| 102 | 136 | } |
| 103 | 137 | } |
| 104 | 138 | } |
| 105 | 139 | |
| 106 | - function process_admin_options() { | |
| 140 | + public function process_admin_options() { | |
| 141 | + // Vérification nonce pour méthode publique | |
| 142 | + if ( ! $this->verify_settings_nonce() ) { | |
| 143 | + wp_die( esc_html__( 'Security check failed', 'wpdeepl' ) ); | |
| 144 | + } | |
| 145 | + | |
| 107 | 146 | $post_data = $this->get_post_data(); |
| 108 | 147 | |
| 109 | - $current_tab = $post_data['tab']; | |
| 148 | + $current_tab = sanitize_key( $post_data['tab'] ?? '' ); | |
| 149 | + if ( empty( $current_tab ) ) { | |
| 150 | + return false; | |
| 151 | + } | |
| 110 | 152 | |
| 111 | 153 | if ( method_exists( $this, 'before_save' ) ) { |
| 112 | 154 | $this->before_save(); |
| 113 | 155 | } |
| 114 | 156 | |
| 115 | - //plouf($this->form_fields, "fields"); plouf($post_data, "POST"); die('oaz4ea6zea4e6a846ek'); | |
| 157 | + //wpdeepl_debug_display($this->form_fields, "fields"); wpdeepl_debug_display($post_data, "POST"); die('oaz4ea6zea4e6a846ek'); | |
| 116 | 158 | |
| 117 | 159 | |
| 118 | 160 | foreach ( $this->form_fields as $field_key => $field ) { |
| 119 | 161 | if ($field['tab'] != $current_tab) { |
| @@ -119,42 +161,69 @@ | ||
| 119 | 161 | if ($field['tab'] != $current_tab) { |
| 120 | 162 | continue; |
| 121 | 163 | } |
| 122 | 164 | |
| 123 | - //echo "\n tab ok ... key $field_key "; plouf($post_data[$field_key]); | |
| 124 | 165 | if ( isset( $post_data[$field_key] ) ) { |
| 125 | - $field_value = $post_data[$field_key]; | |
| 126 | - | |
| 127 | - if ( $field['type'] == 'checkbox' && $field_value == 1 ) { | |
| 128 | - $field_value = 'yes'; | |
| 129 | - } | |
| 130 | - if ( $field['type'] == 'array' ) { | |
| 131 | - //plouf($post_data); | |
| 132 | - foreach ( $field_value as $i => $field_input ) { | |
| 133 | - if ( strlen( implode( '', $field_input )) == 0 ) { | |
| 134 | - unset( $field_value[$i] ); | |
| 135 | - } | |
| 136 | - } | |
| 137 | - | |
| 138 | - } | |
| 139 | - if ( $field['type'] == 'textarea' || $field['type'] == 'text' ) { | |
| 140 | - $field_value = stripslashes( $field_value ); | |
| 141 | - } | |
| 166 | + $field_value = $this->sanitize_field_value( $post_data[$field_key], $field ); | |
| 142 | 167 | update_option( $field_key, $field_value ); |
| 143 | - } | |
| 144 | - else { | |
| 168 | + } else { | |
| 145 | 169 | update_option($field_key, false); |
| 146 | 170 | } |
| 147 | 171 | } |
| 148 | 172 | |
| 149 | - //plouf($post_data, " post data"); plouf( $this->form_fields );die('okaz8e7aze7a57ea65e'); | |
| 150 | - | |
| 151 | 173 | if ( method_exists( $this, 'on_save' ) ) { |
| 152 | 174 | $this->on_save(); |
| 153 | 175 | } |
| 154 | - //plouf( $post_data ); plouf( $this->form_fields ); die( 'okzeprjio' ); | |
| 176 | + return true; | |
| 155 | 177 | } |
| 156 | 178 | |
| 179 | + /** | |
| 180 | + * Sanitize field value based on field type | |
| 181 | + * | |
| 182 | + * @param mixed $value Field value | |
| 183 | + * @param array $field Field configuration | |
| 184 | + * @return mixed Sanitized value | |
| 185 | + */ | |
| 186 | + protected function sanitize_field_value( $value, $field ) { | |
| 187 | + $field_type = $field['type'] ?? 'text'; | |
| 188 | + | |
| 189 | + switch ( $field_type ) { | |
| 190 | + case 'checkbox': | |
| 191 | + return $value == 1 ? 'yes' : 'no'; | |
| 192 | + case 'multiselect': | |
| 193 | + case 'array': | |
| 194 | + if ( is_array( $value ) ) { | |
| 195 | + // Sanitize each array element and remove empty entries | |
| 196 | + $sanitized = array(); | |
| 197 | + foreach ( $value as $i => $field_input ) { | |
| 198 | + if ( is_array( $field_input ) ) { | |
| 199 | + if ( strlen( implode( '', $field_input ) ) > 0 ) { | |
| 200 | + $sanitized[$i] = array_map( 'sanitize_text_field', $field_input ); | |
| 201 | + } | |
| 202 | + } else { | |
| 203 | + $sanitized_value = sanitize_text_field( $field_input ); | |
| 204 | + if ( strlen( $sanitized_value ) > 0 ) { | |
| 205 | + $sanitized[] = $sanitized_value; | |
| 206 | + } | |
| 207 | + } | |
| 208 | + } | |
| 209 | + return $sanitized; | |
| 210 | + } | |
| 211 | + return $value; | |
| 212 | + case 'textarea': | |
| 213 | + return sanitize_textarea_field( $value ); | |
| 214 | + case 'select': | |
| 215 | + case 'radio': | |
| 216 | + case 'text': | |
| 217 | + default: | |
| 218 | + // Handle arrays that might slip through (shouldn't happen normally) | |
| 219 | + if ( is_array( $value ) ) { | |
| 220 | + return array_map( 'sanitize_text_field', $value ); | |
| 221 | + } | |
| 222 | + return sanitize_text_field( $value ); | |
| 223 | + } | |
| 224 | + } | |
| 225 | + | |
| 157 | 226 | /** |
| 158 | 227 | * Prefix key for settings. |
| 159 | 228 | * |
| 160 | 229 | * @param string $key Field key. |
| @@ -159,27 +228,23 @@ | ||
| 159 | 228 | * |
| 160 | 229 | * @param string $key Field key. |
| 161 | 230 | * @return string |
| 162 | 231 | */ |
| 163 | - public function get_field_key( $key ) { | |
| 164 | - //echo "<br /> KEY de $key = " . $this->plugin_id . $this->id . '_' . $key; | |
| 165 | - //return $this->plugin_id . $this->id . '_' . $key; | |
| 166 | - | |
| 232 | + protected function get_field_key( $key ) { | |
| 167 | 233 | if ( preg_match('#^([\w_]+)\[\d+\]$#', $key, $match ) ) { |
| 168 | 234 | $key = $match[1]; |
| 169 | 235 | } |
| 170 | 236 | return $this->plugin_id . $key; |
| 171 | - // return $this->plugin_id . $this->id . '_' . $key; | |
| 172 | 237 | } |
| 173 | 238 | |
| 174 | - public function get_sub_field_key( $key ) { | |
| 239 | + protected function get_sub_field_key( $key ) { | |
| 175 | 240 | if ( preg_match('#^([\w_]+)\[(\d+)\]$#', $key, $match ) ) { |
| 176 | 241 | return $match[2]; |
| 177 | 242 | } |
| 178 | 243 | return false; |
| 179 | - | |
| 180 | 244 | } |
| 181 | - public function get_raw_field_key( $key ) { | |
| 245 | + | |
| 246 | + protected function get_raw_field_key( $key ) { | |
| 182 | 247 | return $this->plugin_id . $key; |
| 183 | 248 | } |
| 184 | 249 | |
| 185 | 250 | public function update_option( $key, $value = '' ) { |
| @@ -189,9 +254,9 @@ | ||
| 189 | 254 | } |
| 190 | 255 | |
| 191 | 256 | $this->settings[ $key ] = $value; |
| 192 | 257 | |
| 193 | - return update_option( $this->get_option_key(), apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings ), 'yes' );*/ | |
| 258 | + return update_option( $this->get_option_key(), apply_filters( 'wpimproved_settings_api_sanitized_fields_' . $this->id, $this->settings ), 'yes' );*/ | |
| 194 | 259 | return update_option( $this->get_field_key( $key ), $value ); |
| 195 | 260 | } |
| 196 | 261 | |
| 197 | 262 | /** |
| @@ -202,28 +267,10 @@ | ||
| 202 | 267 | * @param string $key Option key. |
| 203 | 268 | * @param mixed $empty_value Value when empty. |
| 204 | 269 | * @return string The value specified for the option or a default value for the option. |
| 205 | 270 | */ |
| 206 | - | |
| 207 | 271 | public function get_option( $key, $empty_value = null ) { |
| 208 | - //echo "\n<br /> vALUE de '$key' ( option = '" . $this->get_field_key( $key ) . '" ) = "' . get_option( $this->get_field_key( $key ) ).'"'; | |
| 209 | 272 | return get_option( $this->get_field_key( $key ) ); |
| 210 | - | |
| 211 | - /* if ( empty( $this->settings ) ) { | |
| 212 | - $this->init_settings(); | |
| 213 | - } | |
| 214 | - | |
| 215 | - // Get option default if unset. | |
| 216 | - if ( ! isset( $this->settings[ $key ] ) ) { | |
| 217 | - $form_fields = $this->get_form_fields(); | |
| 218 | - $this->settings[ $key ] = isset( $form_fields[ $key ] ) ? $this->get_field_default( $form_fields[ $key ] ) : ''; | |
| 219 | - } | |
| 220 | - | |
| 221 | - if ( ! is_null( $empty_value ) && '' === $this->settings[ $key ] ) { | |
| 222 | - $this->settings[ $key ] = $empty_value; | |
| 223 | - } | |
| 224 | - | |
| 225 | - return $this->settings[ $key ];*/ | |
| 226 | 273 | } |
| 227 | 274 | |
| 228 | 275 | public function generate_radio_html( $key, $data ) { |
| 229 | 276 | $field_key = $this->get_field_key( $key ); |
| @@ -248,9 +295,9 @@ | ||
| 248 | 295 | ob_start(); |
| 249 | 296 | ?> |
| 250 | 297 | <tr valign="top"> |
| 251 | 298 | <th scope="row" class="titledesc"> |
| 252 | - <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); ?></label> | |
| 299 | + <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo wp_kses_post( $this->get_tooltip_html( $data ) ); ?></label> | |
| 253 | 300 | </th> |
| 254 | 301 | <td class="forminp"> |
| 255 | 302 | <fieldset> |
| 256 | 303 | <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> |
| @@ -255,21 +302,19 @@ | ||
| 255 | 302 | <fieldset> |
| 256 | 303 | <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> |
| 257 | 304 | <?php |
| 258 | 305 | $stored_value = $this->get_option( $key ); |
| 259 | - if ( !$stored_value && isset( $data['default'] ) ) { | |
| 260 | - $stored_value = $data['default']; | |
| 306 | + if ( !$stored_value && isset( $data['wpdeepl'] ) ) { | |
| 307 | + $stored_value = $data['wpdeepl']; | |
| 261 | 308 | } |
| 262 | 309 | |
| 263 | 310 | if ( isset( $data['values'] ) ) foreach ( $data['values'] as $value => $label ) : |
| 264 | - //echo " V $value / S $stored_value"; | |
| 265 | - | |
| 266 | 311 | ?> |
| 267 | - <input <?php disabled( $data['disabled'], true ); ?> class="<?php echo esc_attr( $data['class'] ); ?>" type="radio" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ) . '_' . sanitize_title( $value );?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr($value); ?>" <?php checked( $stored_value, $value ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> /> | |
| 312 | + <input <?php disabled( $data['disabled'], true ); ?> class="<?php echo esc_attr( $data['class'] ); ?>" type="radio" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ) . '_' . esc_attr( sanitize_title( $value ) );?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr($value); ?>" <?php checked( $stored_value, $value ); ?> <?php echo wp_kses_post( $this->get_custom_attribute_html( $data ) ); ?> /> | |
| 268 | 313 | <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $label ); ?></label> |
| 269 | 314 | <br /> |
| 270 | 315 | <?php endforeach; ?> |
| 271 | - <?php echo $this->get_description_html( $data ); ?> | |
| 316 | + <?php echo wp_kses_post( $this->get_description_html( $data ) ); ?> | |
| 272 | 317 | </fieldset> |
| 273 | 318 | </td> |
| 274 | 319 | </tr> |
| 275 | 320 | <?php |
| @@ -296,9 +341,9 @@ | ||
| 296 | 341 | ob_start(); |
| 297 | 342 | ?> |
| 298 | 343 | <tr valign="top"> |
| 299 | 344 | <th scope="row" class="titledesc"> |
| 300 | - <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); ?></label> | |
| 345 | + <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo wp_kses_post( $this->get_tooltip_html( $data ) ); ?></label> | |
| 301 | 346 | </th> |
| 302 | 347 | <td class="forminp"> |
| 303 | 348 | <fieldset> |
| 304 | 349 | <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> |
| @@ -303,15 +348,15 @@ | ||
| 303 | 348 | <fieldset> |
| 304 | 349 | <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> |
| 305 | 350 | <?php |
| 306 | 351 | $stored_value = $this->get_option( $key ); |
| 307 | - if ( !$stored_value && isset( $data['default'] ) ) { | |
| 308 | - $stored_value = $data['default']; | |
| 352 | + if ( !$stored_value && isset( $data['wpdeepl'] ) ) { | |
| 353 | + $stored_value = $data['wpdeepl']; | |
| 309 | 354 | } |
| 310 | 355 | |
| 311 | - echo ( $data['raw_html'] ); ?> | |
| 356 | + echo wp_kses_post( $data['raw_html'] ); ?> | |
| 312 | 357 | <br/> |
| 313 | - <?php echo $this->get_description_html( $data ); ?> | |
| 358 | + <?php echo wp_kses_post( $this->get_description_html( $data ) ); ?> | |
| 314 | 359 | </fieldset> |
| 315 | 360 | </td> |
| 316 | 361 | </tr> |
| 317 | 362 | <?php |
| @@ -324,10 +369,10 @@ | ||
| 324 | 369 | * Get the form fields after they are initialized. |
| 325 | 370 | * |
| 326 | 371 | * @return array of options |
| 327 | 372 | */ |
| 328 | - public function get_form_fields() { | |
| 329 | - return apply_filters( 'woocommerce_settings_api_form_fields_' . $this->id, array_map( array( $this, 'set_defaults' ), $this->form_fields ) ); | |
| 373 | + protected function get_form_fields() { | |
| 374 | + return apply_filters( 'wpdeepl_wpimproved_settings_api_form_fields_' . $this->id, array_map( array( $this, 'set_defaults' ), $this->form_fields ) ); | |
| 330 | 375 | } |
| 331 | 376 | |
| 332 | 377 | /** |
| 333 | 378 | * Set default required properties for each field. |
| @@ -345,8 +390,9 @@ | ||
| 345 | 390 | /** |
| 346 | 391 | * Output the admin options table. |
| 347 | 392 | */ |
| 348 | 393 | public function admin_options() { |
| 394 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- generate_settings_html retourne du HTML déjà sécurisé | |
| 349 | 395 | echo '<table class="form-table">' . $this->generate_settings_html( $this->get_form_fields(), false ) . '</table>'; |
| 350 | 396 | } |
| 351 | 397 | |
| 352 | 398 | |
| @@ -366,9 +412,9 @@ | ||
| 366 | 412 | * |
| 367 | 413 | * @param array $field Field key. |
| 368 | 414 | * @return string |
| 369 | 415 | */ |
| 370 | - public function get_field_type( $field ) { | |
| 416 | + protected function get_field_type( $field ) { | |
| 371 | 417 | return empty( $field['type'] ) ? 'text' : $field['type']; |
| 372 | 418 | } |
| 373 | 419 | |
| 374 | 420 | /** |
| @@ -376,10 +422,10 @@ | ||
| 376 | 422 | * |
| 377 | 423 | * @param array $field Field key. |
| 378 | 424 | * @return string |
| 379 | 425 | */ |
| 380 | - public function get_field_default( $field ) { | |
| 381 | - return empty( $field['default'] ) ? '' : $field['default']; | |
| 426 | + protected function get_field_default( $field ) { | |
| 427 | + return empty( $field['wpdeepl'] ) ? '' : $field['wpdeepl']; | |
| 382 | 428 | } |
| 383 | 429 | |
| 384 | 430 | /** |
| 385 | 431 | * Get a field's posted and validated value. |
| @@ -391,9 +437,9 @@ | ||
| 391 | 437 | */ |
| 392 | 438 | public function get_field_value( $key, $field, $post_data = array() ) { |
| 393 | 439 | $type = $this->get_field_type( $field ); |
| 394 | 440 | $field_key = $this->get_field_key( $key ); |
| 395 | - $post_data = empty( $post_data ) ? $_POST : $post_data; // WPCS: CSRF ok, input var ok. | |
| 441 | + $post_data = empty( $post_data ) ? $this->get_post_data() : $post_data; | |
| 396 | 442 | $value = isset( $post_data[ $field_key ] ) ? $post_data[ $field_key ] : null; |
| 397 | 443 | |
| 398 | 444 | if ( isset( $field['sanitize_callback'] ) && is_callable( $field['sanitize_callback'] ) ) { |
| 399 | 445 | return call_user_func( $field['sanitize_callback'], $value ); |
| @@ -422,56 +468,43 @@ | ||
| 422 | 468 | $this->data = $data; |
| 423 | 469 | } |
| 424 | 470 | |
| 425 | 471 | /** |
| 426 | - * Returns the POSTed data, to be used to save the settings. | |
| 472 | + * Verify settings nonce for security | |
| 427 | 473 | * |
| 428 | - * @return array | |
| 474 | + * @return bool | |
| 429 | 475 | */ |
| 430 | - public function get_post_data() { | |
| 431 | - if ( ! empty( $this->data ) && is_array( $this->data ) ) { | |
| 432 | - return $this->data; | |
| 433 | - } | |
| 434 | - | |
| 435 | - return $_POST; // WPCS: CSRF ok, input var ok. | |
| 476 | + protected function verify_settings_nonce() { | |
| 477 | + return isset( $_POST['_wpdeepl_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpdeepl_nonce'] ) ), 'wpdeepl_save_settings' ); | |
| 436 | 478 | } |
| 437 | 479 | |
| 438 | 480 | /** |
| 439 | - * Update a single option. | |
| 481 | + * Recursively sanitize POST data | |
| 440 | 482 | * |
| 441 | - * @since 3.4.0 | |
| 442 | - * @param string $key Option key. | |
| 443 | - * @param mixed $value Value to set. | |
| 444 | - * @return bool was anything saved? | |
| 483 | + * @param mixed $data Data to sanitize. | |
| 484 | + * @return mixed Sanitized data. | |
| 445 | 485 | */ |
| 486 | + protected function sanitize_post_data_recursive( $data ) { | |
| 487 | + if ( is_array( $data ) ) { | |
| 488 | + return array_map( array( $this, 'sanitize_post_data_recursive' ), $data ); | |
| 489 | + } | |
| 490 | + return sanitize_text_field( $data ); | |
| 491 | + } | |
| 446 | 492 | |
| 447 | 493 | /** |
| 448 | - * Processes and saves options. | |
| 449 | - * If there is an error thrown, will continue to save and validate fields, but will leave the erroring field out. | |
| 494 | + * Returns the POSTed data, to be used to save the settings. | |
| 450 | 495 | * |
| 451 | - * @return bool was anything saved? | |
| 496 | + * @return array | |
| 452 | 497 | */ |
| 453 | - /* | |
| 454 | - public function process_admin_options() { | |
| 455 | - $this->init_settings(); | |
| 456 | - | |
| 457 | - $post_data = $this->get_post_data(); | |
| 458 | - | |
| 459 | - //plouf($post_data); die('ijzeirj'); | |
| 460 | - | |
| 461 | - foreach ( $this->get_form_fields() as $key => $field ) { | |
| 462 | - if ( 'title' !== $this->get_field_type( $field ) ) { | |
| 463 | - try { | |
| 464 | - $this->settings[ $key ] = $this->get_field_value( $key, $field, $post_data ); | |
| 465 | - } catch ( Exception $e ) { | |
| 466 | - $this->add_error( $e->getMessage() ); | |
| 467 | - } | |
| 468 | - } | |
| 498 | + public function get_post_data() { | |
| 499 | + if ( ! empty( $this->data ) && is_array( $this->data ) ) { | |
| 500 | + return $this->data; | |
| 469 | 501 | } |
| 502 | + | |
| 503 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing -- this here is where we clean POST data | |
| 504 | + return $this->sanitize_post_data_recursive( wp_unslash( $_POST ) ); | |
| 505 | + } | |
| 470 | 506 | |
| 471 | - return update_option( $this->get_option_key(), apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings ), 'yes' ); | |
| 472 | - } | |
| 473 | -*/ | |
| 474 | 507 | /** |
| 475 | 508 | * Add an error message for display in admin on save. |
| 476 | 509 | * |
| 477 | 510 | * @param string $error Error message. |
| @@ -515,9 +548,9 @@ | ||
| 515 | 548 | |
| 516 | 549 | // If there are no settings defined, use defaults. |
| 517 | 550 | if ( ! is_array( $this->settings ) ) { |
| 518 | 551 | $form_fields = $this->get_form_fields(); |
| 519 | - $this->settings = array_merge( array_fill_keys( array_keys( $form_fields ), '' ), wp_list_pluck( $form_fields, 'default' ) ); | |
| 552 | + $this->settings = array_merge( array_fill_keys( array_keys( $form_fields ), '' ), wp_list_pluck( $form_fields, 'wpdeepl' ) ); | |
| 520 | 553 | } |
| 521 | 554 | } |
| 522 | 555 | |
| 523 | 556 | /** |
| @@ -535,14 +568,14 @@ | ||
| 535 | 568 | if ( empty( $form_fields ) ) { |
| 536 | 569 | //$form_fields = $this->get_form_fields(); |
| 537 | 570 | } |
| 538 | 571 | |
| 539 | - //plouf($form_fields, " form fields"); | |
| 572 | + //wpdeepl_debug_display($form_fields, " form fields"); | |
| 540 | 573 | |
| 541 | 574 | $html = ''; |
| 542 | 575 | foreach ( $form_fields as $field ) { |
| 543 | 576 | $type = $this->get_field_type( $field ); |
| 544 | - //plouf($field, " DONC TYPE = '$type'"); | |
| 577 | + //wpdeepl_debug_display($field, " DONC TYPE = '$type'"); | |
| 545 | 578 | |
| 546 | 579 | if ( method_exists( $this, 'generate_' . $type . '_html' ) ) { |
| 547 | 580 | $html .= $this->{'generate_' . $type . '_html'}( $field['id'], $field ); |
| 548 | 581 | } else { |
| @@ -550,10 +583,10 @@ | ||
| 550 | 583 | } |
| 551 | 584 | } |
| 552 | 585 | |
| 553 | 586 | if ( $echo ) { |
| 554 | - // not escaped | |
| 555 | - echo ( $html ); | |
| 587 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML already escaped in generate_*_html methods | |
| 588 | + echo $html; | |
| 556 | 589 | } else { |
| 557 | 590 | return $html; |
| 558 | 591 | } |
| 559 | 592 | } |
| @@ -563,9 +596,9 @@ | ||
| 563 | 596 | * |
| 564 | 597 | * @param array $data Data for the tooltip. |
| 565 | 598 | * @return string |
| 566 | 599 | */ |
| 567 | - public function get_tooltip_html( $data ) { | |
| 600 | + protected function get_tooltip_html( $data ) { | |
| 568 | 601 | if ( true === $data['desc_tip'] ) { |
| 569 | 602 | $tip = $data['description']; |
| 570 | 603 | } elseif ( ! empty( $data['desc_tip'] ) ) { |
| 571 | 604 | $tip = $data['desc_tip']; |
| @@ -581,9 +614,9 @@ | ||
| 581 | 614 | * |
| 582 | 615 | * @param array $data Data for the description. |
| 583 | 616 | * @return string |
| 584 | 617 | */ |
| 585 | - public function get_description_html( $data ) { | |
| 618 | + protected function get_description_html( $data ) { | |
| 586 | 619 | if ( true === $data['desc_tip'] ) { |
| 587 | 620 | $description = ''; |
| 588 | 621 | } elseif ( ! empty( $data['desc_tip'] ) ) { |
| 589 | 622 | $description = $data['description']; |
| @@ -601,9 +634,9 @@ | ||
| 601 | 634 | * |
| 602 | 635 | * @param array $data Field data. |
| 603 | 636 | * @return string |
| 604 | 637 | */ |
| 605 | - public function get_custom_attribute_html( $data ) { | |
| 638 | + protected function get_custom_attribute_html( $data ) { | |
| 606 | 639 | $custom_attributes = array(); |
| 607 | 640 | |
| 608 | 641 | if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) ) { |
| 609 | 642 | foreach ( $data['custom_attributes'] as $attribute => $attribute_value ) { |
| @@ -626,9 +659,9 @@ | ||
| 626 | 659 | $field_key = $this->get_field_key( $key ); |
| 627 | 660 | $defaults = array( |
| 628 | 661 | 'title' => '', |
| 629 | 662 | 'disabled' => false, |
| 630 | - 'default' => false, | |
| 663 | + 'wpdeepl' => false, | |
| 631 | 664 | 'class' => '', |
| 632 | 665 | 'css' => '', |
| 633 | 666 | 'placeholder' => '', |
| 634 | 667 | 'type' => 'text', |
| @@ -642,22 +675,21 @@ | ||
| 642 | 675 | ob_start(); |
| 643 | 676 | ?> |
| 644 | 677 | <tr valign="top"> |
| 645 | 678 | <th scope="row" class="titledesc"> |
| 646 | - <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); ?></label> | |
| 679 | + <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo wp_kses_post( $this->get_tooltip_html( $data ) ); ?></label> | |
| 647 | 680 | </th> |
| 648 | 681 | <td class="forminp"> |
| 649 | 682 | <fieldset> |
| 650 | 683 | <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> |
| 651 | 684 | <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_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php |
| 652 | - if ( esc_attr( $this->get_option( $key ) ) ) { | |
| 685 | + if ( $this->get_option( $key ) ) { | |
| 653 | 686 | echo esc_attr( $this->get_option( $key ) ); |
| 654 | 687 | } |
| 655 | - elseif ( $data['default'] ) { | |
| 656 | - // not escaped | |
| 657 | - echo ( $data['default'] ); | |
| 658 | - } ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> /> | |
| 659 | - <?php echo $this->get_description_html( $data ); ?> | |
| 688 | + elseif ( $data['wpdeepl'] ) { | |
| 689 | + echo esc_attr( $data['wpdeepl'] ); | |
| 690 | + } ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo wp_kses_post( $this->get_custom_attribute_html( $data ) ); ?> /> | |
| 691 | + <?php echo wp_kses_post( $this->get_description_html( $data ) ); ?> | |
| 660 | 692 | </fieldset> |
| 661 | 693 | </td> |
| 662 | 694 | </tr> |
| 663 | 695 | <?php |
| @@ -675,14 +707,14 @@ | ||
| 675 | 707 | */ |
| 676 | 708 | public function generate_array_html( $key, $data ) { |
| 677 | 709 | |
| 678 | 710 | $field_key = $this->get_field_key( $key ); |
| 679 | - //plouf($data, "data pzeijezpi"); | |
| 680 | - //plouf($key, "key, field key $field_key"); | |
| 711 | + //wpdeepl_debug_display($data, "data pzeijezpi"); | |
| 712 | + //wpdeepl_debug_display($key, "key, field key $field_key"); | |
| 681 | 713 | $defaults = array( |
| 682 | 714 | 'title' => '', |
| 683 | 715 | 'disabled' => false, |
| 684 | - 'default' => false, | |
| 716 | + 'wpdeepl' => false, | |
| 685 | 717 | 'class' => '', |
| 686 | 718 | 'css' => '', |
| 687 | 719 | 'placeholder' => '', |
| 688 | 720 | 'type' => 'text', |
| @@ -697,9 +729,9 @@ | ||
| 697 | 729 | ob_start(); |
| 698 | 730 | ?> |
| 699 | 731 | <tr valign="top"> |
| 700 | 732 | <th scope="row" class="titledesc"> |
| 701 | - <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); ?></label> | |
| 733 | + <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo wp_kses_post( $this->get_tooltip_html( $data ) ); ?></label> | |
| 702 | 734 | </th> |
| 703 | 735 | <?php foreach ( $data['keys'] as $input_key => $input_type ) : |
| 704 | 736 | $main_class = "input-" . $input_type; |
| 705 | 737 | $main_type = $input_type; |
| @@ -707,9 +739,9 @@ | ||
| 707 | 739 | $main_type = 'text'; |
| 708 | 740 | } |
| 709 | 741 | ?> |
| 710 | 742 | |
| 711 | - <td class="forminp <?php echo sanitize_key( $field_key ); ?> <?php echo sanitize_key( $field_key ) .'_' . $input_key; ?>"> | |
| 743 | + <td class="forminp <?php echo esc_attr( sanitize_key( $field_key ) ); ?> <?php echo esc_attr( sanitize_key( $field_key ) .'_' . $input_key ); ?>"> | |
| 712 | 744 | <fieldset> |
| 713 | 745 | <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> |
| 714 | 746 | <input class="<?php echo esc_attr( $main_class );; ?> regular-input <?php echo esc_attr( $data['class'] ); ?>" type="<?php echo esc_attr( $input_type ); ?>" name="<?php echo esc_attr( $field_key ); ?>[<?php echo esc_attr( $data['index'] ); ?>][<?php echo esc_attr( $input_key ); ?>]" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php |
| 715 | 747 | if ( isset( $data['values'][$input_key] ) ) { |
| @@ -714,17 +746,17 @@ | ||
| 714 | 746 | <input class="<?php echo esc_attr( $main_class );; ?> regular-input <?php echo esc_attr( $data['class'] ); ?>" type="<?php echo esc_attr( $input_type ); ?>" name="<?php echo esc_attr( $field_key ); ?>[<?php echo esc_attr( $data['index'] ); ?>][<?php echo esc_attr( $input_key ); ?>]" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php |
| 715 | 747 | if ( isset( $data['values'][$input_key] ) ) { |
| 716 | 748 | echo esc_attr( $data['values'][$input_key] ); |
| 717 | 749 | } |
| 718 | - elseif ( $data['default'] ) { | |
| 719 | - echo esc_attr( $data['default'] ); | |
| 720 | - } ?>" placeholder="<?php echo isset( $data['placeholders'][$input_key] ) ? esc_attr( $data['placeholders'][$input_key] ) : ''; ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> /> | |
| 721 | - <?php echo $this->get_description_html( $data ); ?> | |
| 750 | + elseif ( $data['wpdeepl'] ) { | |
| 751 | + echo esc_attr( $data['wpdeepl'] ); | |
| 752 | + } ?>" placeholder="<?php echo isset( $data['placeholders'][$input_key] ) ? esc_attr( $data['placeholders'][$input_key] ) : ''; ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo wp_kses_post( $this->get_custom_attribute_html( $data ) ); ?> /> | |
| 753 | + <?php echo wp_kses_post( $this->get_description_html( $data ) ); ?> | |
| 722 | 754 | </fieldset> |
| 723 | 755 | |
| 724 | 756 | </td> |
| 725 | 757 | <?php endforeach; ?> |
| 726 | - <td><a href="#" class="delete_row" onclick="jQuery(this).parent('td').parent('tr').remove(); return false;"><?php _e('Delete' ); ?></a></td> | |
| 758 | + <td><a href="#" class="delete_row" onclick="jQuery(this).parent('td').parent('tr').remove(); return false;"><?php esc_html_e( 'Delete', 'wpdeepl' ); ?></a></td> | |
| 727 | 759 | </tr> |
| 728 | 760 | <?php |
| 729 | 761 | |
| 730 | 762 | return ob_get_clean(); |
| @@ -756,15 +788,15 @@ | ||
| 756 | 788 | ob_start(); |
| 757 | 789 | ?> |
| 758 | 790 | <tr valign="top"> |
| 759 | 791 | <th scope="row" class="titledesc"> |
| 760 | - <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); ?></label> | |
| 792 | + <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo wp_kses_post( $this->get_tooltip_html( $data ) ); ?></label> | |
| 761 | 793 | </th> |
| 762 | 794 | <td class="forminp"> |
| 763 | 795 | <fieldset> |
| 764 | 796 | <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> |
| 765 | - <input class="wc_input_price input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" 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 ); ?> /> | |
| 766 | - <?php echo $this->get_description_html( $data ); ?> | |
| 797 | + <input class="wc_input_price input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" 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 wp_kses_post( $this->get_custom_attribute_html( $data ) ); ?> /> | |
| 798 | + <?php echo wp_kses_post( $this->get_description_html( $data ) ); ?> | |
| 767 | 799 | </fieldset> |
| 768 | 800 | </td> |
| 769 | 801 | </tr> |
| 770 | 802 | <?php |
| @@ -799,15 +831,15 @@ | ||
| 799 | 831 | ob_start(); |
| 800 | 832 | ?> |
| 801 | 833 | <tr valign="top"> |
| 802 | 834 | <th scope="row" class="titledesc"> |
| 803 | - <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); ?></label> | |
| 835 | + <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo wp_kses_post( $this->get_tooltip_html( $data ) ); ?></label> | |
| 804 | 836 | </th> |
| 805 | 837 | <td class="forminp"> |
| 806 | 838 | <fieldset> |
| 807 | 839 | <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> |
| 808 | - <input class="wc_input_decimal input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" 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 ); ?> /> | |
| 809 | - <?php echo $this->get_description_html( $data ); ?> | |
| 840 | + <input class="wc_input_decimal input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" 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 wp_kses_post( $this->get_custom_attribute_html( $data ) ); ?> /> | |
| 841 | + <?php echo wp_kses_post( $this->get_description_html( $data ) ); ?> | |
| 810 | 842 | </fieldset> |
| 811 | 843 | </td> |
| 812 | 844 | </tr> |
| 813 | 845 | <?php |
| @@ -854,17 +886,21 @@ | ||
| 854 | 886 | ob_start(); |
| 855 | 887 | ?> |
| 856 | 888 | <tr valign="top"> |
| 857 | 889 | <th scope="row" class="titledesc"> |
| 858 | - <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); ?></label> | |
| 890 | + | |
| 891 | + <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php | |
| 892 | + // get_tooltip_html returns safe HTML | |
| 893 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 894 | + echo $this->get_tooltip_html( $data ); ?></label> | |
| 859 | 895 | </th> |
| 860 | 896 | <td class="forminp"> |
| 861 | 897 | <fieldset> |
| 862 | 898 | <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> |
| 863 | 899 | <span class="colorpickpreview" style="background:<?php echo esc_attr( $this->get_option( $key ) ); ?>;"> </span> |
| 864 | - <input class="colorpick <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" 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 ); ?> /> | |
| 900 | + <input class="colorpick <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" 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 wp_kses_post( $this->get_custom_attribute_html( $data ) ); ?> /> | |
| 865 | 901 | <div id="colorPickerDiv_<?php echo esc_attr( $field_key ); ?>" class="colorpickdiv" style="z-index: 100; background: #eee; border: 1px solid #ccc; position: absolute; display: none;"></div> |
| 866 | - <?php echo $this->get_description_html( $data ); ?> | |
| 902 | + <?php echo wp_kses_post( $this->get_description_html( $data ) ); ?> | |
| 867 | 903 | </fieldset> |
| 868 | 904 | </td> |
| 869 | 905 | </tr> |
| 870 | 906 | <?php |
| @@ -899,15 +935,17 @@ | ||
| 899 | 935 | ob_start(); |
| 900 | 936 | ?> |
| 901 | 937 | <tr valign="top"> |
| 902 | 938 | <th scope="row" class="titledesc"> |
| 903 | - <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); ?></label> | |
| 939 | + <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php | |
| 940 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- get_tooltip_html retourne HTML déjà sécurisé | |
| 941 | + echo $this->get_tooltip_html( $data ); ?></label> | |
| 904 | 942 | </th> |
| 905 | 943 | <td class="forminp"> |
| 906 | 944 | <fieldset> |
| 907 | 945 | <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> |
| 908 | - <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_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" 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 $this->get_option( $key ) ? esc_textarea( $this->get_option( $key ) ) : esc_attr( $data['placeholder']); ?></textarea> | |
| 909 | - <?php echo $this->get_description_html( $data ); ?> | |
| 946 | + <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_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo wp_kses_post( $this->get_custom_attribute_html( $data ) ); ?>><?php echo $this->get_option( $key ) ? esc_textarea( $this->get_option( $key ) ) : esc_attr( $data['placeholder']); ?></textarea> | |
| 947 | + <?php echo wp_kses_post( $this->get_description_html( $data ) ); ?> | |
| 910 | 948 | </fieldset> |
| 911 | 949 | </td> |
| 912 | 950 | </tr> |
| 913 | 951 | <?php |
| @@ -946,16 +984,18 @@ | ||
| 946 | 984 | ob_start(); |
| 947 | 985 | ?> |
| 948 | 986 | <tr valign="top"> |
| 949 | 987 | <th scope="row" class="titledesc"> |
| 950 | - <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); ?></label> | |
| 988 | + <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php | |
| 989 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- get_tooltip_html retourne HTML déjà sécurisé | |
| 990 | + echo $this->get_tooltip_html( $data ); ?></label> | |
| 951 | 991 | </th> |
| 952 | 992 | <td class="forminp"> |
| 953 | 993 | <fieldset> |
| 954 | 994 | <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> |
| 955 | 995 | <label for="<?php echo esc_attr( $field_key ); ?>"> |
| 956 | - <input <?php disabled( $data['disabled'], true ); ?> class="<?php echo esc_attr( $data['class'] ); ?>" type="checkbox" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" 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/> | |
| 957 | - <?php echo $this->get_description_html( $data ); ?> | |
| 996 | + <input <?php disabled( $data['disabled'], true ); ?> class="<?php echo esc_attr( $data['class'] ); ?>" type="checkbox" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="1" <?php checked( filter_var( $this->get_option( $key ), FILTER_VALIDATE_BOOLEAN ) ); ?> <?php echo wp_kses_post( $this->get_custom_attribute_html( $data ) ); ?> /> <?php echo wp_kses_post( $data['label'] ); ?></label><br/> | |
| 997 | + <?php echo wp_kses_post( $this->get_description_html( $data ) ); ?> | |
| 958 | 998 | </fieldset> |
| 959 | 999 | </td> |
| 960 | 1000 | </tr> |
| 961 | 1001 | <?php |
| @@ -977,9 +1017,9 @@ | ||
| 977 | 1017 | $selected_value = $this->get_option($key); |
| 978 | 1018 | if ( $sub_field_key ) { |
| 979 | 1019 | $selected_value = $selected_value[$sub_field_key]; |
| 980 | 1020 | } |
| 981 | - //plouf($selected_value, " seleizehri pour key $key / field key $field_key"); | |
| 1021 | + //wpdeepl_debug_display($selected_value, " seleizehri pour key $key / field key $field_key"); | |
| 982 | 1022 | $defaults = array( |
| 983 | 1023 | 'title' => '', |
| 984 | 1024 | 'disabled' => false, |
| 985 | 1025 | 'class' => '', |
| @@ -993,9 +1033,9 @@ | ||
| 993 | 1033 | ); |
| 994 | 1034 | |
| 995 | 1035 | $data = wp_parse_args( $data, $defaults ); |
| 996 | 1036 | |
| 997 | - //plouf($data, "pour key $key"); | |
| 1037 | + //wpdeepl_debug_display($data, "pour key $key"); | |
| 998 | 1038 | |
| 999 | 1039 | |
| 1000 | 1040 | ob_start(); |
| 1001 | 1041 | ?> |
| @@ -1000,19 +1040,24 @@ | ||
| 1000 | 1040 | ob_start(); |
| 1001 | 1041 | ?> |
| 1002 | 1042 | <tr valign="top"> |
| 1003 | 1043 | <th scope="row" class="titledesc"> |
| 1004 | - <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); ?></label> | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + <label for="<?php echo esc_attr( $field_key ); ?>"><?php | |
| 1047 | + // get_tooltip_html return safe HTML. Output needs no escaping. | |
| 1048 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1049 | + echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); ?></label> | |
| 1005 | 1050 | </th> |
| 1006 | 1051 | <td class="forminp"> |
| 1007 | 1052 | <fieldset> |
| 1008 | 1053 | <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> |
| 1009 | - <select class="select <?php echo esc_attr( $data['class'] ); ?>" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?>> | |
| 1054 | + <select class="select <?php echo esc_attr( $data['class'] ); ?>" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo wp_kses_post( $this->get_custom_attribute_html( $data ) ); ?>> | |
| 1010 | 1055 | <?php foreach ( ( array ) $data['options'] as $option_key => $option_value ) : ?> |
| 1011 | 1056 | <option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( ( string ) $option_key, esc_attr( $selected_value ) ); ?>><?php echo esc_attr( $option_value ); ?></option> |
| 1012 | 1057 | <?php endforeach; ?> |
| 1013 | 1058 | </select> |
| 1014 | - <?php echo $this->get_description_html( $data ); ?> | |
| 1059 | + <?php echo wp_kses_post( $this->get_description_html( $data ) ); ?> | |
| 1015 | 1060 | </fieldset> |
| 1016 | 1061 | </td> |
| 1017 | 1062 | </tr> |
| 1018 | 1063 | <?php |
| @@ -1046,20 +1091,25 @@ | ||
| 1046 | 1091 | |
| 1047 | 1092 | $data = wp_parse_args( $data, $defaults ); |
| 1048 | 1093 | $value = ( array ) $this->get_option( $key, array() ); |
| 1049 | 1094 | |
| 1050 | - //plouf($data['options'], 'options'); | |
| 1095 | + //wpdeepl_debug_display($data['options'], 'options'); | |
| 1051 | 1096 | |
| 1052 | 1097 | ob_start(); |
| 1053 | 1098 | ?> |
| 1054 | 1099 | <tr valign="top"> |
| 1055 | 1100 | <th scope="row" class="titledesc"> |
| 1056 | - <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); ?></label> | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + <label for="<?php echo esc_attr( $field_key ); ?>"><?php | |
| 1104 | + // get_tooltip_html return safe HTML. Output needs no escaping. | |
| 1105 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1106 | + echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); ?></label> | |
| 1057 | 1107 | </th> |
| 1058 | 1108 | <td class="forminp"> |
| 1059 | 1109 | <fieldset> |
| 1060 | 1110 | <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> |
| 1061 | - <select multiple="multiple" class="multiselect <?php echo esc_attr( $data['class'] ); ?>" name="<?php echo esc_attr( $field_key ); ?>[]" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?>> | |
| 1111 | + <select multiple="multiple" class="multiselect <?php echo esc_attr( $data['class'] ); ?>" name="<?php echo esc_attr( $field_key ); ?>[]" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo wp_kses_post( $this->get_custom_attribute_html( $data ) ); ?>> | |
| 1062 | 1112 | <?php foreach ( ( array ) $data['options'] as $option_key => $option_value ) : ?> |
| 1063 | 1113 | <?php if ( is_array( $option_value ) ) : ?> |
| 1064 | 1114 | <optgroup label="<?php echo esc_attr( $option_key ); ?>"> |
| 1065 | 1115 | <?php foreach ( $option_value as $option_key_inner => $option_value_inner ) : ?> |
| @@ -1070,11 +1120,11 @@ | ||
| 1070 | 1120 | <option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( in_array( ( string ) $option_key, $value, true ), true ); ?>><?php echo esc_attr( $option_value ); ?></option> |
| 1071 | 1121 | <?php endif; ?> |
| 1072 | 1122 | <?php endforeach; ?> |
| 1073 | 1123 | </select> |
| 1074 | - <?php echo $this->get_description_html( $data ); ?> | |
| 1124 | + <?php echo wp_kses_post( $this->get_description_html( $data ) ); ?> | |
| 1075 | 1125 | <?php if ( $data['select_buttons'] ) : ?> |
| 1076 | - <br/><a class="select_all button" href="#"><?php esc_html_e( 'Select all', 'default' ); ?></a> <a class="select_none button" href="#"><?php esc_html_e( 'Select none', 'default' ); ?></a> | |
| 1126 | + <br/><a class="select_all button" href="#"><?php esc_htmlesc_html_e( 'Select all', 'wpdeepl' ); ?></a> <a class="select_none button" href="#"><?php esc_htmlesc_html_e( 'Select none', 'wpdeepl' ); ?></a> | |
| 1077 | 1127 | <?php endif; ?> |
| 1078 | 1128 | </fieldset> |
| 1079 | 1129 | </td> |
| 1080 | 1130 | </tr> |
| @@ -1095,13 +1145,14 @@ | ||
| 1095 | 1145 | |
| 1096 | 1146 | $data = wp_parse_args( $data, $defaults ); |
| 1097 | 1147 | |
| 1098 | 1148 | ob_start(); |
| 1099 | - $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() ); | |
| 1149 | + $bytes = apply_filters( 'wpdeepl_import_upload_size_limit', wp_max_upload_size() ); | |
| 1100 | 1150 | $size = size_format( $bytes ); |
| 1101 | 1151 | $upload_dir = wp_upload_dir(); |
| 1102 | 1152 | if ( ! empty( $upload_dir['error'] ) ) : |
| 1103 | - ?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p> | |
| 1153 | + ?><div class="error"><p><?php | |
| 1154 | + esc_html_e('Before you can upload your import file, you will need to fix the following error:', 'wpdeepl' ); ?></p> | |
| 1104 | 1155 | <p><strong><?php echo esc_html( $upload_dir['error'] ); ?></strong></p></div><?php |
| 1105 | 1156 | else : |
| 1106 | 1157 | ?> |
| 1107 | 1158 | <form enctype="multipart/form-data" id="import-adr-form" method="post" class="wp-upload-form" action="?page='<?php echo esc_attr( $data['page'] ); ?>'"> |
| @@ -1108,9 +1159,11 @@ | ||
| 1108 | 1159 | |
| 1109 | 1160 | <input type="hidden" name="page" value="<?php echo esc_attr( $data['page'] ); ?>" /> |
| 1110 | 1161 | <h3><?php echo esc_html( $data['title'] ); ?></h3> |
| 1111 | 1162 | <p> |
| 1112 | - <label for="filename"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>) | |
| 1163 | + <label for="filename"><?php esc_html_e( 'Choose a file from your computer:', 'wpdeepl' ); ?></label> (<?php | |
| 1164 | + /* translators: size of the maximum upload */ | |
| 1165 | + printf( esc_html__( 'Maximum size: %s', 'wpdeepl' ), esc_html( $size ) ); ?>) | |
| 1113 | 1166 | <input type="file" id="filename" name="filename" size="25" /> |
| 1114 | 1167 | </p> |
| 1115 | 1168 | |
| 1116 | 1169 | <input type="hidden" name="action" value="<?php echo esc_attr( $data['action'] ) ; ?>" /> |
| @@ -1115,9 +1168,9 @@ | ||
| 1115 | 1168 | |
| 1116 | 1169 | <input type="hidden" name="action" value="<?php echo esc_attr( $data['action'] ) ; ?>" /> |
| 1117 | 1170 | <input type="hidden" name="max_file_size" value="<?php echo esc_attr( $bytes ); ?>" /> |
| 1118 | 1171 | </p> |
| 1119 | - <?php submit_button( __('Upload file and import'), 'primary' ); ?> | |
| 1172 | + <?php submit_button( __( 'Upload file and import', 'wpdeepl' ), 'primary' ); ?> | |
| 1120 | 1173 | </form> |
| 1121 | 1174 | <?php |
| 1122 | 1175 | endif; |
| 1123 | 1176 | |
| @@ -1289,5 +1342,5 @@ | ||
| 1289 | 1342 | wc_deprecated_function( 'format_settings', '2.6' ); |
| 1290 | 1343 | return $value; |
| 1291 | 1344 | } |
| 1292 | 1345 | } |
| 1293 | -} | |
| 1346 | +} | |