Plugin Directory

Changeset 3225561


Ignore:
Timestamp:
01/20/2025 12:16:16 PM (14 months ago)
Author:
hellomanaf
Message:

Security update

Location:
just-cookie-consent-popup/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • just-cookie-consent-popup/trunk/just-cookie-consent-popup.php

    r3225423 r3225561  
    44 * Text Domain: just-cookie-consent-popup
    55 * Description: A simple plugin to display a cookie consent popup with settings managed in the admin panel.
    6  * Version: 1.0.1
     6 * Version: 1.0.2
    77 * Requires at least: 6.4
    88 * Requires PHP: 7.2
     
    2020}
    2121
    22 DEFINE('JCCPOPUP_PLUGIN_PATH', plugin_dir_path( __FILE__ ));
    23 DEFINE('JCCPOPUP_PLUGIN_URL', plugin_dir_url( __FILE__ ));
    2422
    2523// Add default options on plugin activation
     
    2725    $default_options = [
    2826        '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',
    3030    ];
    3131    add_option('jccpopup_cookie_popup_settings', $default_options);
    3232}
    3333register_activation_hook(__FILE__, 'jccpopup_cookie_popup_activate');
     34
     35// Clean options on plugin uninstall
     36function jccpopup_cookie_popup_uninstall() {
     37    delete_option('jccpopup_cookie_popup_settings');
     38}
     39register_uninstall_hook(__FILE__, 'jccpopup_cookie_popup_uninstall');
     40
    3441
    3542// Add the settings page to the admin menu
     
    5259        $new_settings = [
    5360            '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'])) : '',
    5564        ];
    5665
     
    7483                    <td><input type="text" name="jccpopup_button_text" id="button_text" value="<?php echo esc_attr($settings['button_text']); ?>" class="regular-text" /></td>
    7584                </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>
    7693            </table>
    7794            <p class="submit">
     
    83100}
    84101
    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
     103function 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            }
    90139
    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
    93147}
     148add_action('wp_footer', 'jccpopup_cookie_popup_enqueue_scripts');
    94149
    95150// Display the popup in the footer
  • just-cookie-consent-popup/trunk/readme.txt

    r3225423 r3225561  
    55Tested up to: 6.7.1
    66Requires PHP: 7.2
    7 Stable tag: 1.0.1
     7Stable tag: 1.0.2
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    1515
    1616== Changelog ==
     17
     18= 1.0.2 =
     19* Security fixes.
     20
    1721= 1.0.1 =
    1822* Security fixes.
Note: See TracChangeset for help on using the changeset viewer.