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