diff --git a/includes/Dashboard/Templates/Settings.php b/includes/Dashboard/Templates/Settings.php index 3d273d6cbc..23fc36ef43 100644 --- a/includes/Dashboard/Templates/Settings.php +++ b/includes/Dashboard/Templates/Settings.php @@ -479,6 +479,23 @@ private function store_validate() { } } + $enable_tnc = isset( $_POST['dokan_store_tnc_enable'] ) && 'on' === sanitize_text_field( wp_unslash( $_POST['dokan_store_tnc_enable'] ) ); + + if ( $enable_tnc ) { + $store_tnc = isset( $_POST['dokan_store_tnc'] ) ? wp_kses_post( wp_unslash( $_POST['dokan_store_tnc'] ) ) : ''; + + $store_tnc_clean = wp_strip_all_tags( $store_tnc ); + $store_tnc_clean = html_entity_decode( $store_tnc_clean, ENT_QUOTES | ENT_HTML5, 'UTF-8' ); + $store_tnc_clean = preg_replace( '/[\s\x{00A0}\x{200B}\x{FEFF}]+/u', '', $store_tnc_clean ); + + if ( empty( $store_tnc_clean ) ) { + $error->add( + 'dokan_tnc_content', + __( 'Please add Terms & Conditions content before enabling this option.', 'dokan-lite' ) + ); + } + } + if ( $error->get_error_codes() ) { return $error; } @@ -639,6 +656,20 @@ public function insert_settings_info() { ]; } + $store_tnc_raw = isset( $_POST['dokan_store_tnc'] ) ? wp_kses_post( wp_unslash( $_POST['dokan_store_tnc'] ) ) : ''; + + $store_tnc_processed = ''; + + if ( ! empty( $store_tnc_raw ) ) { + $store_tnc_clean = wp_strip_all_tags( $store_tnc_raw ); + $store_tnc_clean = html_entity_decode( $store_tnc_clean, ENT_QUOTES | ENT_HTML5, 'UTF-8' ); + $store_tnc_clean = preg_replace( '/[\s\x{00A0}\x{200B}\x{FEFF}]+/u', '', $store_tnc_clean ); + + if ( ! empty( $store_tnc_clean ) ) { + $store_tnc_processed = $store_tnc_raw; + } + } + // Update store settings info. $dokan_settings = [ 'store_name' => isset( $_POST['dokan_store_name'] ) ? sanitize_text_field( wp_unslash( $_POST['dokan_store_name'] ) ) : '', @@ -650,7 +681,7 @@ public function insert_settings_info() { 'show_email' => isset( $_POST['setting_show_email'] ) ? sanitize_text_field( wp_unslash( $_POST['setting_show_email'] ) ) : 'no', 'gravatar' => isset( $_POST['dokan_gravatar'] ) ? absint( $_POST['dokan_gravatar'] ) : 0, 'enable_tnc' => isset( $_POST['dokan_store_tnc_enable'] ) && 'on' === sanitize_text_field( wp_unslash( $_POST['dokan_store_tnc_enable'] ) ) ? 'on' : 'off', - 'store_tnc' => isset( $_POST['dokan_store_tnc'] ) ? wp_kses_post( wp_unslash( $_POST['dokan_store_tnc'] ) ) : '', + 'store_tnc' => $store_tnc_processed, 'dokan_store_time' => apply_filters( 'dokan_store_time', $dokan_store_time ), 'dokan_store_time_enabled' => isset( $_POST['dokan_store_time_enabled'] ) && 'yes' === sanitize_text_field( wp_unslash( $_POST['dokan_store_time_enabled'] ) ) ? 'yes' : 'no', 'dokan_store_open_notice' => isset( $_POST['dokan_store_open_notice'] ) ? sanitize_textarea_field( wp_unslash( $_POST['dokan_store_open_notice'] ) ) : '', diff --git a/templates/settings/store-form.php b/templates/settings/store-form.php index 9d313250f5..e58ad492a8 100644 --- a/templates/settings/store-form.php +++ b/templates/settings/store-form.php @@ -200,7 +200,7 @@
- +