Changeset 3225561
- Timestamp:
- 01/20/2025 12:16:16 PM (14 months ago)
- Location:
- just-cookie-consent-popup/trunk
- Files:
-
- 2 edited
-
just-cookie-consent-popup.php (modified) (6 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
just-cookie-consent-popup/trunk/just-cookie-consent-popup.php
r3225423 r3225561 4 4 * Text Domain: just-cookie-consent-popup 5 5 * Description: A simple plugin to display a cookie consent popup with settings managed in the admin panel. 6 * Version: 1.0. 16 * Version: 1.0.2 7 7 * Requires at least: 6.4 8 8 * Requires PHP: 7.2 … … 20 20 } 21 21 22 DEFINE('JCCPOPUP_PLUGIN_PATH', plugin_dir_path( __FILE__ ));23 DEFINE('JCCPOPUP_PLUGIN_URL', plugin_dir_url( __FILE__ ));24 22 25 23 // Add default options on plugin activation … … 27 25 $default_options = [ 28 26 'message' => 'We use cookies to improve your experience on our site.', 29 'button_text' => 'Accept' 27 'button_text' => 'Accept', 28 'background_color' => '#333333', 29 'text_color' => '#FFFFFF', 30 30 ]; 31 31 add_option('jccpopup_cookie_popup_settings', $default_options); 32 32 } 33 33 register_activation_hook(__FILE__, 'jccpopup_cookie_popup_activate'); 34 35 // Clean options on plugin uninstall 36 function jccpopup_cookie_popup_uninstall() { 37 delete_option('jccpopup_cookie_popup_settings'); 38 } 39 register_uninstall_hook(__FILE__, 'jccpopup_cookie_popup_uninstall'); 40 34 41 35 42 // Add the settings page to the admin menu … … 52 59 $new_settings = [ 53 60 'message' => !empty($_POST['jccpopup_message']) ? sanitize_text_field(wp_unslash($_POST['jccpopup_message'])) : '', 54 'button_text' => !empty($_POST['jccpopup_button_text']) ? sanitize_text_field(wp_unslash($_POST['jccpopup_button_text'])) : '' 61 'button_text' => !empty($_POST['jccpopup_button_text']) ? sanitize_text_field(wp_unslash($_POST['jccpopup_button_text'])) : '', 62 'background_color' => !empty($_POST['jccpopup_background_color']) ? sanitize_hex_color(wp_unslash($_POST['jccpopup_background_color'])) : '', 63 'text_color' => !empty($_POST['jccpopup_text_color']) ? sanitize_hex_color(wp_unslash($_POST['jccpopup_text_color'])) : '', 55 64 ]; 56 65 … … 74 83 <td><input type="text" name="jccpopup_button_text" id="button_text" value="<?php echo esc_attr($settings['button_text']); ?>" class="regular-text" /></td> 75 84 </tr> 85 <tr> 86 <th scope="row"><label for="background_color">Background Color</label></th> 87 <td><input type="text" name="jccpopup_background_color" id="background_color" value="<?php echo esc_attr($settings['background_color']); ?>" class="regular-text" /></td> 88 </tr> 89 <tr> 90 <th scope="row"><label for="text_color">Text Color</label></th> 91 <td><input type="text" name="jccpopup_text_color" id="text_color" value="<?php echo esc_attr($settings['text_color']); ?>" class="regular-text" /></td> 92 </tr> 76 93 </table> 77 94 <p class="submit"> … … 83 100 } 84 101 85 // Enqueue the popup styles and scripts 86 add_action( 'wp_enqueue_scripts', 'jccpopup_cookie_popup_assets' ); 87 function jccpopup_cookie_popup_assets() { 88 wp_register_style( 'jccpopup-cookie-popup-style', JCCPOPUP_PLUGIN_URL . "assets/just-cookie-consent-popup-style.css", "", time() ); 89 wp_enqueue_style( 'jccpopup-cookie-popup-style' ); 102 // Enqueue the popup styles and script 103 function jccpopup_cookie_popup_enqueue_scripts() { 104 $settings = get_option('jccpopup_cookie_popup_settings'); 105 ?> 106 <style> 107 #cookie-popup { 108 position: fixed; 109 bottom: 20px; 110 left: 20px; 111 right: 20px; 112 background-color: <?php echo esc_attr($settings['background_color']); ?>; 113 color: <?php echo esc_attr($settings['text_color']); ?>; 114 padding: 15px; 115 border-radius: 5px; 116 display: none; 117 z-index: 9999; 118 } 119 #cookie-popup p { 120 padding: 0; 121 margin: 0; 122 display: inline-block; 123 color: #ffffff; 124 } 125 #cookie-popup button { 126 background-color: <?php echo esc_attr($settings['text_color']); ?>; 127 color: <?php echo esc_attr($settings['background_color']); ?>; 128 border: none; 129 padding: 10px 20px; 130 border-radius: 5px; 131 cursor: pointer; 132 } 133 </style> 134 <script> 135 document.addEventListener('DOMContentLoaded', function () { 136 if (!localStorage.getItem('JustcookiePopupAccepted')) { 137 document.getElementById('cookie-popup').style.display = 'block'; 138 } 90 139 91 wp_register_script( 'jccpopup-cookie-popup-script', JCCPOPUP_PLUGIN_URL . "assets/just-cookie-consent-popup-script.js", [],time(),true ); 92 wp_enqueue_script( 'jccpopup-cookie-popup-script' ); 140 document.getElementById('cookie-popup-button').addEventListener('click', function () { 141 localStorage.setItem('JustcookiePopupAccepted', 'true'); 142 document.getElementById('cookie-popup').style.display = 'none'; 143 }); 144 }); 145 </script> 146 <?php 93 147 } 148 add_action('wp_footer', 'jccpopup_cookie_popup_enqueue_scripts'); 94 149 95 150 // Display the popup in the footer -
just-cookie-consent-popup/trunk/readme.txt
r3225423 r3225561 5 5 Tested up to: 6.7.1 6 6 Requires PHP: 7.2 7 Stable tag: 1.0. 17 Stable tag: 1.0.2 8 8 License: GPLv3 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 15 15 16 16 == Changelog == 17 18 = 1.0.2 = 19 * Security fixes. 20 17 21 = 1.0.1 = 18 22 * Security fixes.
Note: See TracChangeset
for help on using the changeset viewer.