Plugin Directory

Changeset 3393945


Ignore:
Timestamp:
11/11/2025 11:43:04 PM (5 months ago)
Author:
websolutionnetwork
Message:

Update to version 1.0.2 – new customizable button texts + improvements

Location:
ws-cookie-consent-light-by-web-solution-network/tags/1.0.1
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ws-cookie-consent-light-by-web-solution-network/tags/1.0.1/admin/class-ws-cookie-admin.php

    r3387376 r3393945  
    159159            'ws_cookie_setting_section'
    160160        );
    161     }
    162 
    163     public function sanitize( $input ) {
    164         $new_input = array();
    165         $new_input['enabled'] = isset($input['enabled']) && $input['enabled'] === '1' ? '1' : '0';
    166         $new_input['message'] = sanitize_text_field( $input['message'] );
    167         $new_input['background'] = sanitize_text_field( $input['background'] );
    168         $new_input['text_color'] = sanitize_text_field( $input['text_color'] );
    169         $new_input['position'] = in_array($input['position'], array('bottom','top')) ? $input['position'] : 'bottom';
    170         $new_input['privacy_link'] = esc_url_raw( $input['privacy_link'] );
    171         $new_input['branding'] = isset($input['branding']) && $input['branding'] === '1' ? '1' : '0';
    172         $new_input['expire_days'] = intval( $input['expire_days'] ) ?: 30;
    173         return $new_input;
    174     }
     161       
     162        add_settings_field(
     163    'accept_text',
     164    'Accept button text',
     165    array( $this, 'accept_text_callback' ),
     166    'ws-cookie-consent-admin',
     167    'ws_cookie_setting_section'
     168);
     169
     170add_settings_field(
     171    'reject_text',
     172    'Decline button text',
     173    array( $this, 'reject_text_callback' ),
     174    'ws-cookie-consent-admin',
     175    'ws_cookie_setting_section'
     176);
     177
     178add_settings_field(
     179    'settings_text',
     180    'Privacy Policy button text',
     181    array( $this, 'settings_text_callback' ),
     182    'ws-cookie-consent-admin',
     183    'ws_cookie_setting_section'
     184);
     185
     186    }
     187
     188 public function sanitize( $input ) {
     189    $new_input = array();
     190
     191    // βασικά πεδία
     192    $new_input['enabled']      = ( isset( $input['enabled'] ) && $input['enabled'] === '1' ) ? '1' : '0';
     193    $new_input['message']      = isset( $input['message'] ) ? sanitize_text_field( $input['message'] ) : '';
     194    $new_input['background']   = isset( $input['background'] ) ? sanitize_text_field( $input['background'] ) : '#0b3d91';
     195    $new_input['text_color']   = isset( $input['text_color'] ) ? sanitize_text_field( $input['text_color'] ) : '#ffffff';
     196    $new_input['position']     = ( isset( $input['position'] ) && in_array( $input['position'], array( 'bottom','top' ), true ) )
     197                                 ? $input['position'] : 'bottom';
     198    $new_input['privacy_link'] = isset( $input['privacy_link'] ) ? esc_url_raw( $input['privacy_link'] ) : '';
     199    $new_input['branding']     = ( isset( $input['branding'] ) && $input['branding'] === '1' ) ? '1' : '0';
     200    $new_input['expire_days']  = isset( $input['expire_days'] ) ? max( 1, intval( $input['expire_days'] ) ) : 30;
     201
     202    // ✅ ΝΕΑ πεδία κουμπιών – ΠΡΙΝ το return
     203    $new_input['accept_text']   = isset( $input['accept_text'] )   ? sanitize_text_field( $input['accept_text'] )   : 'Accept All';
     204    $new_input['reject_text']   = isset( $input['reject_text'] )   ? sanitize_text_field( $input['reject_text'] )   : 'Reject';
     205    $new_input['settings_text'] = isset( $input['settings_text'] ) ? sanitize_text_field( $input['settings_text'] ) : 'Privacy Policy';
     206
     207    return $new_input;
     208}
     209
     210public function accept_text_callback() {
     211    $val = isset($this->options['accept_text']) ? $this->options['accept_text'] : 'Accept All';
     212    echo '<input type="text" style="width:100%" name="' . esc_attr( WS_COOKIE_OPTION ) . '[accept_text]" value="' . esc_attr( $val ) . '" />';
     213}
     214
     215public function reject_text_callback() {
     216    $val = isset($this->options['reject_text']) ? $this->options['reject_text'] : 'Reject';
     217    echo '<input type="text" style="width:100%" name="' . esc_attr( WS_COOKIE_OPTION ) . '[reject_text]" value="' . esc_attr( $val ) . '" />';
     218}
     219
     220public function settings_text_callback() {
     221    // αν θες να το λες Privacy Policy στο UI, κράτα το name settings_text για συμβατότητα
     222    $val = isset($this->options['settings_text']) ? $this->options['settings_text'] : 'Privacy Policy';
     223    echo '<input type="text" style="width:100%" name="' . esc_attr( WS_COOKIE_OPTION ) . '[settings_text]" value="' . esc_attr( $val ) . '" />';
     224}
    175225
    176226    public function enabled_callback() {
  • ws-cookie-consent-light-by-web-solution-network/tags/1.0.1/public/js/ws-cookie.js

    r3387376 r3393945  
    1 (function($){
    2     function setCookie(name, value, days) {
    3         var d = new Date();
    4         d.setTime(d.getTime() + (days*24*60*60*1000));
    5         var expires = "expires="+ d.toUTCString();
    6         document.cookie = name + "=" + value + ";" + expires + ";path=/";
     1(function ($) {
     2  'use strict';
     3
     4  function setCookie(name, value, days) {
     5    var d = new Date();
     6    d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));
     7    var expires = 'expires=' + d.toUTCString();
     8    document.cookie = name + '=' + value + ';' + expires + ';path=/;SameSite=Lax';
     9  }
     10
     11  function getCookie(name) {
     12    var cname = name + '=';
     13    var ca = document.cookie.split(';');
     14    for (var i = 0; i < ca.length; i++) {
     15      var c = ca[i].trim();
     16      if (c.indexOf(cname) === 0) return c.substring(cname.length, c.length);
    717    }
    8     function getCookie(name) {
    9         var cname = name + "=";
    10         var ca = document.cookie.split(';');
    11         for(var i=0;i<ca.length;i++) {
    12             var c = ca[i].trim();
    13             if (c.indexOf(cname) === 0) return c.substring(cname.length,c.length);
    14         }
    15         return "";
    16     }
    17     function showBanner(data){
    18         var $b = $('#ws-cookie-consent');
    19         var $msg = $('#ws-cookie-message');
    20         $msg.text(data.message);
    21         $('#ws-cookie-accept').text(data.accept_text);
    22         $('#ws-cookie-reject').text(data.reject_text);
    23         $('#ws-cookie-settings').text(data.settings_text || 'Privacy Policy');
    24         $b.css('background', data.background);
    25         $b.css('color', data.text_color);
    26         if(data.position === 'top') {
    27             $b.addClass('ws-top').removeClass('ws-bottom');
    28         } else {
    29             $b.addClass('ws-bottom').removeClass('ws-top');
    30         }
     18    return '';
     19  }
    3120
    32         // ✅ FIX: Only show branding if user explicitly enabled it
    33         if (data.branding && data.branding === '1') {
    34             if (!$b.find('.ws-branding').length) {
    35                 $b.append('<div class="ws-branding" style="font-size:12px;opacity:0.8;margin-top:8px;">Powered by Web Solution Network</div>');
    36             }
    37         }
     21  function safeText(v, fallback) {
     22    return (typeof v === 'string' && v.length) ? v : fallback;
     23  }
    3824
    39         $b.show();
     25  function showBanner(data) {
     26    var $b = $('#ws-cookie-consent');
     27    if (!$b.length) return; // no markup, bail
     28
     29    var $msg = $('#ws-cookie-message');
     30    var acceptText   = safeText(data.accept_text, 'Accept All');
     31    var rejectText   = safeText(data.reject_text, 'Reject');
     32    var settingsText = safeText(data.settings_text, 'Privacy Policy');
     33
     34    if ($msg.length) $msg.text(safeText(data.message, 'This website uses cookies.'));
     35
     36    $('#ws-cookie-accept').text(acceptText).attr('aria-label', acceptText);
     37    $('#ws-cookie-reject').text(rejectText).attr('aria-label', rejectText);
     38    $('#ws-cookie-settings').text(settingsText).attr('aria-label', settingsText);
     39
     40    if (data.background) $b.css('background', data.background);
     41    if (data.text_color) $b.css('color', data.text_color);
     42
     43    if (data.position === 'top') {
     44      $b.addClass('ws-top').removeClass('ws-bottom');
     45    } else {
     46      $b.addClass('ws-bottom').removeClass('ws-top');
    4047    }
    4148
    42     $(function(){
    43         var data = window.WS_COOKIE_DATA || {};
    44         if(!data.enabled || data.enabled !== '1') return;
    45         var consent = getCookie('ws_cookie_consent');
    46         if(consent === 'accepted' || consent === 'rejected') {
    47             return;
    48         }
    49         showBanner(data);
     49    // Show branding only if explicitly enabled
     50    if (String(data.branding) === '1' && !$b.find('.ws-branding').length) {
     51      $b.append(
     52        '<div class="ws-branding" style="font-size:12px;opacity:.8;margin-top:8px;">' +
     53          'Powered by Web Solution Network' +
     54        '</div>'
     55      );
     56    }
    5057
    51         $('#ws-cookie-accept').on('click', function(){
    52             setCookie('ws_cookie_consent','accepted', parseInt(data.expire_days) || 30);
    53             $('#ws-cookie-consent').slideUp();
    54         });
     58    $b.attr('role', 'region').attr('aria-live', 'polite').show();
     59  }
    5560
    56         $('#ws-cookie-reject').on('click', function(){
    57             setCookie('ws_cookie_consent','rejected', parseInt(data.expire_days) || 30);
    58             $('#ws-cookie-consent').slideUp();
    59         });
     61  $(function () {
     62    var data = window.WS_COOKIE_DATA || {};
     63    if (String(data.enabled) !== '1') return;
    6064
    61         $('#ws-cookie-settings').on('click', function(){
    62             if(data.privacy_link){
    63                 window.open(data.privacy_link, '_blank');
    64             } else {
    65                 alert('No privacy policy URL set in plugin settings.');
    66             }
    67         });
     65    var consent = getCookie('ws_cookie_consent');
     66    if (consent === 'accepted' || consent === 'rejected') return;
     67
     68    showBanner(data);
     69
     70    $('#ws-cookie-accept').on('click', function () {
     71      setCookie('ws_cookie_consent', 'accepted', parseInt(data.expire_days, 10) || 30);
     72      $('#ws-cookie-consent').slideUp(150);
    6873    });
     74
     75    $('#ws-cookie-reject').on('click', function () {
     76      setCookie('ws_cookie_consent', 'rejected', parseInt(data.expire_days, 10) || 30);
     77      $('#ws-cookie-consent').slideUp(150);
     78    });
     79
     80    $('#ws-cookie-settings').on('click', function () {
     81      var url = safeText(data.privacy_link, '');
     82      if (url) {
     83        window.open(url, '_blank', 'noopener');
     84      } else {
     85        alert('No privacy policy URL set in plugin settings.');
     86      }
     87    });
     88  });
    6989})(jQuery);
  • ws-cookie-consent-light-by-web-solution-network/tags/1.0.1/readme.txt

    r3387376 r3393945  
    11=== WS Cookie Consent Light ===
    22Contributors: websolutionnetwork
    3 Tags: cookies, gdpr, cookie consent, privacy, eu law, cookie banner
     3Tags: cookies, gdpr, cookie consent, privacy
    44Requires at least: 5.0
    55Tested up to: 6.8
    6 Stable tag: 1.0.1
     6Stable tag: 1.0.2
    77Requires PHP: 7.2
    88License: GPLv2 or later
     
    5555== Changelog ==
    5656
     57
     58= 1.0.2 =
     59* Added custom text fields for Accept / Reject / Privacy buttons
     60* Improved admin settings
     61* Minor fixes and optimizations
     62
     63
    5764= 1.0.1 =
    5865* Changed the “Settings” button label to “Privacy Policy” on the frontend
  • ws-cookie-consent-light-by-web-solution-network/tags/1.0.1/ws-cookie-consent.php

    r3387376 r3393945  
    44 * Plugin URI:  https://web-solution.gr/ws-cookie-consent-light
    55 * Description: Lightweight and customizable GDPR cookie consent banner with admin panel and optional branding by Web Solution Network.
    6  * Version: 1.0.1
     6 * Version: 1.0.2
    77 * Author: Web Solution Network
    88 * Author URI: https://web-solution.gr
     
    1818
    1919// Define plugin constants
    20 define( 'WS_COOKIE_VERSION', '1.0.1' );
     20define( 'WS_COOKIE_VERSION', '1.0.2' );
    2121define( 'WS_COOKIE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
    2222define( 'WS_COOKIE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
Note: See TracChangeset for help on using the changeset viewer.