fix
This commit is contained in:
@@ -326,96 +326,3 @@ add_filter( 'get_the_archive_title', 'water_delivery_category_title' );
|
||||
* Load init.
|
||||
*/
|
||||
require_once get_template_directory() . '/inc/init.php';
|
||||
|
||||
/**
|
||||
* Display the privacy policy page without requiring a database page.
|
||||
*/
|
||||
function water_delivery_privacy_policy_template() {
|
||||
if ( is_admin() || empty( $_SERVER['REQUEST_URI'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$request_path = trim( wp_parse_url( wp_unslash( $_SERVER['REQUEST_URI'] ), PHP_URL_PATH ), '/' );
|
||||
|
||||
if ( 'privacy-policy' === $request_path ) {
|
||||
status_header( 200 );
|
||||
include get_template_directory() . '/privacy-policy.php';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
add_action( 'template_redirect', 'water_delivery_privacy_policy_template', 0 );
|
||||
|
||||
/**
|
||||
* Cookie notice and personal data consent controls.
|
||||
*/
|
||||
function water_delivery_privacy_footer_assets() {
|
||||
$privacy_url = esc_url( home_url( '/privacy-policy/' ) );
|
||||
?>
|
||||
<div class="cookie-consent-banner" data-cookie-consent-banner hidden>
|
||||
<p>
|
||||
<?php esc_html_e( 'Мы используем файлы cookie для улучшения работы сайта. Продолжая использовать сайт, Вы соглашаетесь с нашей', 'water-delivery' ); ?>
|
||||
<a href="<?php echo $privacy_url; ?>"><?php esc_html_e( 'Политикой конфиденциальности', 'water-delivery' ); ?></a>.
|
||||
</p>
|
||||
<button type="button" class="cookie-consent-accept" data-cookie-consent-accept><?php esc_html_e( 'Принять', 'water-delivery' ); ?></button>
|
||||
</div>
|
||||
<script>
|
||||
(function () {
|
||||
var consentKey = 'water_delivery_cookie_consent';
|
||||
var banner = document.querySelector('[data-cookie-consent-banner]');
|
||||
var acceptButton = document.querySelector('[data-cookie-consent-accept]');
|
||||
var privacyUrl = <?php echo wp_json_encode( $privacy_url ); ?>;
|
||||
var consentHtml = 'Согласен(на) на обработку персональных данных и принимаю <a href="' + privacyUrl + '">Политику конфиденциальности</a>';
|
||||
|
||||
if (banner && localStorage.getItem(consentKey) !== 'accepted') {
|
||||
banner.hidden = false;
|
||||
}
|
||||
|
||||
if (acceptButton) {
|
||||
acceptButton.addEventListener('click', function () {
|
||||
localStorage.setItem(consentKey, 'accepted');
|
||||
if (banner) {
|
||||
banner.hidden = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
document.querySelectorAll('form').forEach(function (form, index) {
|
||||
var ignored = form.matches('.search-form, .woocommerce-cart-form, form[role="search"]');
|
||||
var hasPersonalFields = form.querySelector('input[type="email"], input[type="tel"], input[name*="phone"], input[name*="email"], textarea, .wpforms-submit, .wpcf7-submit');
|
||||
|
||||
if (ignored || !hasPersonalFields || form.querySelector('.personal-data-consent')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var field = document.createElement('label');
|
||||
field.className = 'personal-data-consent';
|
||||
field.innerHTML = '<input type="checkbox" name="personal_data_consent_' + index + '" required> <span>' + consentHtml + '</span>';
|
||||
|
||||
var submit = form.querySelector('button[type="submit"], input[type="submit"], .wpforms-submit, .wpcf7-submit');
|
||||
if (submit && submit.parentNode) {
|
||||
submit.parentNode.insertBefore(field, submit);
|
||||
} else {
|
||||
form.appendChild(field);
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
add_action( 'wp_footer', 'water_delivery_privacy_footer_assets', 20 );
|
||||
|
||||
function water_delivery_comment_privacy_consent_field( $fields ) {
|
||||
$fields['privacy_consent'] = '<p class="comment-form-privacy-consent"><label><input type="checkbox" name="privacy_consent" required> ' . sprintf( wp_kses( __( 'Согласен(на) на обработку персональных данных и принимаю <a href="%s">Политику конфиденциальности</a>', 'water-delivery' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( home_url( '/privacy-policy/' ) ) ) . '</label></p>';
|
||||
|
||||
return $fields;
|
||||
}
|
||||
add_filter( 'comment_form_default_fields', 'water_delivery_comment_privacy_consent_field' );
|
||||
|
||||
function water_delivery_comment_privacy_consent_validate( $commentdata ) {
|
||||
if ( empty( $_POST['privacy_consent'] ) ) {
|
||||
wp_die( esc_html__( 'Необходимо согласиться на обработку персональных данных.', 'water-delivery' ) );
|
||||
}
|
||||
|
||||
return $commentdata;
|
||||
}
|
||||
add_filter( 'preprocess_comment', 'water_delivery_comment_privacy_consent_validate' );
|
||||
|
||||
Reference in New Issue
Block a user