Created
March 23, 2021 06:33
-
-
Save fmurdeni/06777aa3d0f97bcc76fefe6673ae0adb to your computer and use it in GitHub Desktop.
Translate cookie notice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('cn_cookie_notice_output', function($output, $options){ | |
//I use text translate because its become constant variable. | |
$options['message_text'] = __('Website ini menggunakan cookie untuk mendapatkan pengalaman online terbaik anda.', 'murdeni'); | |
$options['see_more_opt']['text'] = __('Ketentuan Privasi', 'murdeni'); | |
// then I use lang to switch the privacy policy page ID | |
// I use query var for lang | |
$lang = get_query_var('lang'); | |
if ($lang == 'en') { | |
$options['see_more_opt']['id'] = 125; | |
} | |
$output = '<div id="cookie-notice" role="banner" class="cookie-notice-hidden cookie-revoke-hidden cn-position-' . $options['position'] . '" aria-label="' . $options['aria_label'] . '" style="background-color: rgba(' . implode( ',', Cookie_Notice()->hex2rgb( $options['colors']['bar'] ) ) . ',' . $options['colors']['bar_opacity'] * 0.01 . ');">' | |
. '<div class="cookie-notice-container" style="color: ' . $options['colors']['text'] . ';">' | |
. '<span id="cn-notice-text" class="cn-text-container">'. $options['message_text'] . '</span>' | |
. '<span id="cn-notice-buttons" class="cn-buttons-container"><a href="#" id="cn-accept-cookie" data-cookie-set="accept" class="cn-set-cookie ' . $options['button_class'] . ( $options['css_style'] !== 'none' ? ' ' . $options['css_style'] : '' ) . ( $options['css_class'] !== '' ? ' ' . $options['css_class'] : '' ) . '" aria-label="' . $options['accept_text'] . '">' . $options['accept_text'] . '</a>' | |
. ( $options['refuse_opt'] === true ? '<a href="#" id="cn-refuse-cookie" data-cookie-set="refuse" class="cn-set-cookie ' . $options['button_class'] . ( $options['css_style'] !== 'none' ? ' ' . $options['css_style'] : '' ) . ( $options['css_class'] !== '' ? ' ' . $options['css_class'] : '' ) . '" aria-label="' . $options['refuse_text'] . '">' . $options['refuse_text'] . '</a>' : '' ) | |
. ( $options['see_more'] === true && $options['link_position'] === 'banner' ? '<a href="' . ( $options['see_more_opt']['link_type'] === 'custom' ? $options['see_more_opt']['link'] : get_permalink( $options['see_more_opt']['id'] ) ) . '" target="' . $options['link_target'] . '" id="cn-more-info" class="cn-more-info ' . $options['button_class'] . ( $options['css_style'] !== 'none' ? ' ' . $options['css_style'] : '' ) . ( $options['css_class'] !== '' ? ' ' . $options['css_class'] : '' ) . '" aria-label="' . $options['see_more_opt']['text'] . '">' . $options['see_more_opt']['text'] . '</a>' : '' ) | |
. '</span><a href="javascript:void(0);" id="cn-close-notice" data-cookie-set="accept" class="cn-close-icon" aria-label="' . $options['accept_text'] . '"></a>' | |
. '</div> | |
' . ( $options['refuse_opt'] === true && $options['revoke_cookies'] == true ? | |
'<div class="cookie-revoke-container" style="color: ' . $options['colors']['text'] . ';">' | |
. ( ! empty( $options['revoke_message_text'] ) ? '<span id="cn-revoke-text" class="cn-text-container">'. $options['revoke_message_text'] . '</span>' : '' ) | |
. '<span id="cn-revoke-buttons" class="cn-buttons-container"><a href="#" class="cn-revoke-cookie ' . $options['button_class'] . ( $options['css_style'] !== 'none' ? ' ' . $options['css_style'] : '' ) . ( $options['css_class'] !== '' ? ' ' . $options['css_class'] : '' ) . '" aria-label="' . $options['revoke_text'] . '">' . esc_html( $options['revoke_text'] ) . '</a></span> | |
</div>' : '' ) . ' | |
</div>'; | |
return $output; | |
}, 99, 2); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment