Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Internal/Settings
File: OptionSanitizer.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* FormatValidator class.
[2] Fix | Delete
*/
[3] Fix | Delete
[4] Fix | Delete
namespace Automattic\WooCommerce\Internal\Settings;
[5] Fix | Delete
[6] Fix | Delete
defined( 'ABSPATH' ) || exit;
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* This class handles sanitization of core options that need to conform to certain format.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 6.6.0
[12] Fix | Delete
*/
[13] Fix | Delete
class OptionSanitizer {
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* OptionSanitizer constructor.
[17] Fix | Delete
*/
[18] Fix | Delete
public function __construct() {
[19] Fix | Delete
// Sanitize color options.
[20] Fix | Delete
$color_options = array(
[21] Fix | Delete
'woocommerce_email_base_color',
[22] Fix | Delete
'woocommerce_email_background_color',
[23] Fix | Delete
'woocommerce_email_body_background_color',
[24] Fix | Delete
'woocommerce_email_text_color',
[25] Fix | Delete
);
[26] Fix | Delete
[27] Fix | Delete
foreach ( $color_options as $option_name ) {
[28] Fix | Delete
add_filter(
[29] Fix | Delete
"woocommerce_admin_settings_sanitize_option_{$option_name}",
[30] Fix | Delete
array( $this, 'sanitize_color_option' ),
[31] Fix | Delete
10,
[32] Fix | Delete
2
[33] Fix | Delete
);
[34] Fix | Delete
}
[35] Fix | Delete
// Cast "Out of stock threshold" field to absolute integer to prevent storing empty value.
[36] Fix | Delete
add_filter( 'woocommerce_admin_settings_sanitize_option_woocommerce_notify_no_stock_amount', 'absint' );
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Sanitizes values for options of type 'color' before persisting to the database.
[41] Fix | Delete
* Falls back to previous/default value for the option if given an invalid value.
[42] Fix | Delete
*
[43] Fix | Delete
* @since 6.6.0
[44] Fix | Delete
* @param string $value Option value.
[45] Fix | Delete
* @param array $option Option data.
[46] Fix | Delete
* @return string Color in hex format.
[47] Fix | Delete
*
[48] Fix | Delete
* @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
[49] Fix | Delete
*/
[50] Fix | Delete
public function sanitize_color_option( $value, $option ) {
[51] Fix | Delete
$value = sanitize_hex_color( $value );
[52] Fix | Delete
[53] Fix | Delete
// If invalid, try the current value.
[54] Fix | Delete
if ( ! $value && ! empty( $option['id'] ) ) {
[55] Fix | Delete
$value = sanitize_hex_color( get_option( $option['id'] ) );
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
// If still invalid, try the default.
[59] Fix | Delete
if ( ! $value && ! empty( $option['default'] ) ) {
[60] Fix | Delete
$value = sanitize_hex_color( $option['default'] );
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
return (string) $value;
[64] Fix | Delete
}
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function