-
Notifications
You must be signed in to change notification settings - Fork 1
/
wp-cookie-banner.php
188 lines (149 loc) · 6.22 KB
/
wp-cookie-banner.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
/*
Plugin Name: WP Cookie Banner
Plugin URI: https://www.creare.co.uk/services/wp-cookie-banner
Description: Customise and display a subtle, implied consent EU Cookie Law banner on your Wordpress site.
Author: Creare
Version: 0.1
Author URI: https://www.creare.co.uk/
*/
/* Copyright 2013 CREAREGROUP (email : [email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
define('CREARE_EU_COOKIE_DIR',plugin_dir_path( __FILE__ ));
define('CREARE_EU_COOKIE_URL',plugin_dir_url( __FILE__ ));
if ( is_admin() ){
add_action('admin_menu', 'wp_cookie_banner_admin_actions');
add_action('admin_init', 'wp_cookie_banner_theme_options_init' );
}
function wp_cookie_banner_admin_actions() {
$page = add_options_page("EU Cookie Banner Options", "WP Cookie Banner", "administrator", "wp_cookie_banner", "wp_cookie_banner_admin");
}
function wp_cookie_banner_settings_link($links, $file) {
$plugin_file = basename(__FILE__);
if (basename($file) == $plugin_file) {
$settings_link = '<a href="options-general.php?page=wp_cookie_banner">Settings</a>';
array_unshift($links, $settings_link);
}
return $links;
}
add_filter('plugin_action_links', 'wp_cookie_banner_settings_link', 10, 2);
function wp_cookie_banner_theme_options_init(){
register_setting( 'wp_cookie_banner_option_group', 'wp_cookie_banner_test_mode' );
register_setting( 'wp_cookie_banner_option_group', 'wp_cookie_banner_duration' );
register_setting( 'wp_cookie_banner_option_group', 'wp_cookie_banner_seconds' );
register_setting( 'wp_cookie_banner_option_group', 'wp_cookie_banner_privacy_message' );
register_setting( 'wp_cookie_banner_option_group', 'wp_cookie_banner_default_css' );
register_setting( 'wp_cookie_banner_option_group', 'wp_cookie_banner_linked_page' );
$plugindirectory = CREARE_EU_COOKIE_URL;
$css_data = "#cookie-law {
position: fixed;
bottom: 0px;
left: 0;
right: 0;
text-align: center;
z-index:9999;
}
#cookie-law > div {
background:#fff;
opacity:0.95;
width:75% !important;
padding:20px;
max-width: 600px;
margin:auto;
display: inline-block;
text-align: left !important;
border-radius:5px 5px 0 0;
-moz-border-radius:5px 5px 0 0;
-webkit-border-radius:5px 5px 0 0;
-o-border-radius:5px 5px 0 0;
box-shadow: 0px 0px 20px #A1A1A1;
-webkit-box-shadow: 0px 0px 20px #A1A1A1;
-moz-box-shadow: 0px 0px 20px #A1A1A1;
-o-box-shadow: 0px 0px 20px #A1A1A1;
position:relative;
}
#cookie-law h4 { padding: 0 !important; margin:0 0 8px !important; text-align:left !important; font-size:13px !important; color:#444;
}
#cookie-law p { padding: 0 !important; margin:0 !important; text-align:left !important; font-size:12px !important; line-height: 18px !important; color:#888;
}
a.close-cookie-banner {
position: absolute;
top:0px;
right:0px;
margin:10px;
display:block;
width:20px;
height:20px;
background:url(".$plugindirectory."images/close.png) no-repeat;
background-size: 20px !important;
}
a.close-cookie-banner span {
display:none !important;
}";
$sitename = get_bloginfo('name');
$defaultmessage = "<h4>$sitename Cookies Policy</h4>
<p>Our Website uses cookies to improve your experience. Please visit our [cookiepage] page for more information about cookies and how we use them.</p>";
add_option('wp_cookie_banner_duration','14');
add_option('wp_cookie_banner_seconds','5000');
add_option('wp_cookie_banner_privacy_message',$defaultmessage);
add_option('wp_cookie_banner_default_css',$css_data);
}
function wp_cookie_banner_admin() {
include('wp-cookie-banner-settings.php');
}
function wp_cookie_banner_script() {
$linkedPageID = get_option('wp_cookie_banner_linked_page');
if(get_option('wp_cookie_banner_duration') && get_option('wp_cookie_banner_privacy_message') && $linkedPageID !=="0"):
?>
<script type="text/javascript">
var dropCookie = true;
var cookieDuration = <?php echo get_option('wp_cookie_banner_duration') ?>;
var cookieName = 'complianceCookie';
var cookieValue = 'on';
<?php
$message = get_option('wp_cookie_banner_privacy_message');
// now replace link with our page and text
$message = str_replace("[cookiepage]",'<a rel="nofollow" href="'.get_page_link("$linkedPageID").'">'.get_the_title("$linkedPageID").'</a>',$message);
?>
var privacyMessage = "";
jQuery(document).ready(function($) {
privacyMessage = jQuery('#hidden-cookie-message').html();
<?php if (get_option('wp_cookie_banner_test_mode') == 1) { ?>eraseCookie('complianceCookie');<?php } ?>
if(checkCookie(window.cookieName) != window.cookieValue){
createDiv(<?php if (get_option('wp_cookie_banner_test_mode') == 1 ) { echo "false"; } else { echo "true" ; } ?>);
window.setTimeout(function() {
$('#cookie-law').fadeOut();
}, <?php echo get_option('wp_cookie_banner_seconds'); ?>);
}
});
</script>
<div id="hidden-cookie-message" style="display:none;">
<div>
<?php echo $message; ?>
<a class="close-cookie-banner" href="javascript:void(0);" onclick="jQuery(this).parent().parent().hide();"><span>Close</span></a>
</div>
</div>
<?php endif; }
add_action( 'wp_footer', 'wp_cookie_banner_script' );
function wp_cookie_banner_jquery() {
wp_enqueue_script('eu-cookie-law', CREARE_EU_COOKIE_URL.'js/eu-cookie-law.js', array('jquery'), null, true);
}
add_action( 'wp_enqueue_scripts', 'wp_cookie_banner_jquery' );
if (get_option('wp_cookie_banner_default_css') !="" && !isset($_COOKIE['complianceCookie'])) {
add_action('wp_head', 'add_css_to_head', '10');
}
function add_css_to_head() { ?>
<style type="text/css" media="screen">
<?php echo get_option('wp_cookie_banner_default_css'); ?>
</style>
<?php }