PluginProbe
WP EXtra – One Click Optimize / trunk
WP EXtra – One Click Optimize vtrunk
8.7.1 8.6.8 8.7.0 trunk 5.9 8.0 8.5.0 8.5.4 8.5.5 8.6.0 8.6.1 8.6.2 8.6.3 8.6.5
wp-extra / src / Modules / Frontend / Cookie.php

Cookie.php in WP EXtra – One Click Optimize trunk, at src/Modules/Frontend/Cookie.php

86 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WPEXtra\Modules\Frontend;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use WPEXtra\Helper;
9
10 class Cookie {
11
12 public function __construct() {
13 add_action('wp_enqueue_scripts', [$this, 'cookie_enqueue_scripts']);
14 add_action('wp_footer', [$this, 'display_cookie_info']);
15 }
16
17 public function cookie_enqueue_scripts() {
18 if (!is_admin()) {
19 wp_enqueue_style('cookie', plugins_url('/assets/css/cookie.min.css', WPEX_FILE), [], defined('WPEX_VERSION') ? WPEX_VERSION : null);
20 wp_enqueue_script('cookie', plugins_url('/assets/js/cookie.min.js', WPEX_FILE), [], defined('WPEX_VERSION') ? WPEX_VERSION : null, true);
21 }
22 }
23
24 public function display_cookie_info() {
25 if (is_admin()) {
26 return;
27 }
28
29 $preset = Helper::get_option('cookie_preset', 'default');
30
31 // Presets color mapping
32 switch ($preset) {
33 case 'dark_modern':
34 $background_color = '#1e293b';
35 $text_color = '#f8fafc';
36 $button_background_color = '#6366f1';
37 $button_text_color = '#ffffff';
38 break;
39 case 'soft_warm':
40 $background_color = '#fef3c7';
41 $text_color = '#78350f';
42 $button_background_color = '#d97706';
43 $button_text_color = '#ffffff';
44 break;
45 case 'custom':
46 $background_color = Helper::get_option('cookie_bgcolor', '#ffffff');
47 $text_color = Helper::get_option('cookie_textcolor', '#666666');
48 $button_background_color = Helper::get_option('cookie_btnbgcolor', '#1e58b1');
49 $button_text_color = Helper::get_option('cookie_btntextcolor', '#ffffff');
50 break;
51 case 'default':
52 default:
53 $background_color = '#ffffff';
54 $text_color = '#333333';
55 $button_background_color = '#1e58b1';
56 $button_text_color = '#ffffff';
57 break;
58 }
59
60 $cookie_message = Helper::get_option('cookie_message', __('This site uses cookies to improve your online experience, allow you to share content on social media, measure traffic to this website and display customised ads based on your browsing activity.', 'wp-extra'));
61 $cookie_info_button = Helper::get_option('cookie_button', __('Accept Cookies', 'wp-extra'));
62 $show_policy_privacy = Helper::get_option('cookie_privacy');
63 $cookie_info_placement = Helper::get_option('cookie_placement', 'bottom');
64 $cookie_expire_time = Helper::get_option('cookie_expire', '30');
65 $privacy_policy_url = get_privacy_policy_url();
66 $placement_css = ($cookie_info_placement === 'top') ? 'top: 0;' : 'bottom: 0;';
67 ?>
68 <div class="cookie-box cookie-hidden" style="background-color: <?php echo esc_attr($background_color); ?>; <?php echo esc_attr($placement_css); ?>" id="cookie-box">
69 <div id="cookie-form">
70 <div id="extra-cookie-info" style="color: <?php echo esc_attr($text_color); ?>"><?php echo wp_kses_post($cookie_message); ?></div>
71 <div id="cookie-notice-button">
72 <?php if ($show_policy_privacy && !empty($privacy_policy_url)): ?>
73 <a href="<?php echo esc_url($privacy_policy_url); ?>" class="button extra-cookie-privacy-policy" id="cookie-privacy-policy" style="border: 1px solid <?php echo esc_attr($button_background_color); ?>; color: <?php echo esc_attr($button_background_color); ?>">
74 <?php esc_html_e('Privacy Policy'); ?>
75 </a>
76 <?php endif; ?>
77 <a href="#" name="ex-cookie-accept-button" class="button extra-cookie-accept-button" id="cookie-accept-button" style="background-color: <?php echo esc_attr($button_background_color); ?>; color: <?php echo esc_attr($button_text_color); ?>" data-expire="<?php echo esc_attr($cookie_expire_time); ?>">
78 <?php echo esc_html($cookie_info_button); ?>
79 </a>
80 </div>
81 </div>
82 </div>
83 <?php
84 }
85
86 }