Cookie Consent - Version 1.5

Version Description

Switched the logic so that the bar is initially hidden on the page and only displays if user has not previously dismissed it. Gives a slightly better performance. Thanks to chrisHe for the suggestion.

Download this release

Release Info

Developer Catapult
Plugin Icon 128x128 Cookie Consent
Version 1.5
Comparing to
See all releases

Code changes from version 1.31 to 1.5

js/colour-picker.js ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ jQuery(document).ready(function($){
2
+ $('.my-color-field').wpColorPicker(); //Do the colour picker on theme options
3
+ });
js/uk-cookie-consent-js.js ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //All the cookie setting stuff
2
+ function catapultSetCookie(cookieName, cookieValue, nDays) {
3
+ var today = new Date();
4
+ var expire = new Date();
5
+ if (nDays==null || nDays==0) nDays=1;
6
+ expire.setTime(today.getTime() + 3600000*24*nDays);
7
+ document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString()+"; path=/";
8
+ }
9
+ function catapultReadCookie(cookieName) {
10
+ var theCookie=" "+document.cookie;
11
+ var ind=theCookie.indexOf(" "+cookieName+"=");
12
+ if (ind==-1) ind=theCookie.indexOf(";"+cookieName+"=");
13
+ if (ind==-1 || cookieName=="") return "";
14
+ var ind1=theCookie.indexOf(";",ind+1);
15
+ if (ind1==-1) ind1=theCookie.length;
16
+ return unescape(theCookie.substring(ind+cookieName.length+2,ind1));
17
+ }
18
+ function catapultDeleteCookie(cookieName) {
19
+ var today = new Date();
20
+ var expire = new Date() - 30;
21
+ expire.setTime(today.getTime() - 3600000*24*90);
22
+ document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
23
+ }
24
+ function catapultAcceptCookies() {
25
+ catapultSetCookie('catAccCookies', true, 30);
26
+ jQuery("#catapult-cookie-bar").hide();
27
+ jQuery("html").css("margin-top","0");
28
+ }
languages/uk-cookie-consent.pot ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: UK Cookie Consent\n"
4
+ "POT-Creation-Date: 2013-01-10 07:14-0000\n"
5
+ "PO-Revision-Date: 2013-01-10 07:14-0000\n"
6
+ "Last-Translator: Ben Huson <ben@thewhiteroom.net>\n"
7
+ "Language-Team: \n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=UTF-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "X-Generator: Poedit 1.5.4\n"
12
+ "X-Poedit-KeywordsList: _;gettext;gettext_noop;__;_e\n"
13
+ "X-Poedit-Basepath: .\n"
14
+ "X-Poedit-SearchPath-0: ..\n"
15
+
16
+ #: ../uk-cookie-consent.php:17
17
+ msgid "Cookie Consent"
18
+ msgstr ""
19
+
20
+ #: ../uk-cookie-consent.php:22
21
+ msgid "UK Cookie Consent"
22
+ msgstr ""
23
+
24
+ #: ../uk-cookie-consent.php:26
25
+ msgid "Your settings"
26
+ msgstr ""
27
+
28
+ #: ../uk-cookie-consent.php:30
29
+ msgid "Cookie Policy"
30
+ msgstr ""
31
+
32
+ #: ../uk-cookie-consent.php:35
33
+ msgid ""
34
+ "This site uses cookies - small text files that are placed on your machine to "
35
+ "help the site provide a better user experience. In general, cookies are used "
36
+ "to retain user preferences, store information for things like shopping "
37
+ "carts, and provide anonymised tracking data to third party applications like "
38
+ "Google Analytics."
39
+ msgstr ""
40
+
41
+ #: ../uk-cookie-consent.php:36
42
+ msgid ""
43
+ "As a rule, cookies will make your browsing experience better. However, you "
44
+ "may prefer to disable cookies on this site and on others. The most effective "
45
+ "way to do this is to disable cookies in your browser. We suggest consulting "
46
+ "the Help section of your browser or taking a look at <a href=\"http://www."
47
+ "aboutcookies.org\">the About Cookies website</a> which offers guidance for "
48
+ "all modern browsers."
49
+ msgstr ""
50
+
51
+ #: ../uk-cookie-consent.php:43
52
+ msgid "Failed to create page."
53
+ msgstr ""
54
+
55
+ #: ../uk-cookie-consent.php:45
56
+ msgid "Cookie Policy page successfully created."
57
+ msgstr ""
58
+
59
+ #: ../uk-cookie-consent.php:51
60
+ msgid "Save Changes"
61
+ msgstr ""
62
+
63
+ #: ../uk-cookie-consent.php:57
64
+ #, php-format
65
+ msgid ""
66
+ "Your Cookies Policy page is <a href=\"%s\">here</a>. You may wish to create "
67
+ "a menu item or other link on your site to this page."
68
+ msgstr ""
69
+
70
+ #: ../uk-cookie-consent.php:64
71
+ msgid "Resources"
72
+ msgstr ""
73
+
74
+ #: ../uk-cookie-consent.php:66
75
+ msgid "Information Commissioner's Office Guidance on Cookies"
76
+ msgstr ""
77
+
78
+ #: ../uk-cookie-consent.php:68
79
+ msgid "Our interpretation of the guidance"
80
+ msgstr ""
81
+
82
+ #: ../uk-cookie-consent.php:80
83
+ msgid "Notification text"
84
+ msgstr ""
85
+
86
+ #: ../uk-cookie-consent.php:81
87
+ msgid "Accept text"
88
+ msgstr ""
89
+
90
+ #: ../uk-cookie-consent.php:82
91
+ msgid "More info text"
92
+ msgstr ""
93
+
94
+ #: ../uk-cookie-consent.php:83
95
+ msgid "Info page permalink"
96
+ msgstr ""
97
+
98
+ #: ../uk-cookie-consent.php:87
99
+ msgid ""
100
+ "You can just use these settings as they are or update the text as you wish. "
101
+ "We recommend keeping it brief."
102
+ msgstr ""
103
+
104
+ #: ../uk-cookie-consent.php:88
105
+ msgid ""
106
+ "The plug-in automatically creates a page called \"Cookie Policy\" and sets "
107
+ "the default More Info link to yoursitename.com/cookie-policy."
108
+ msgstr ""
109
+
110
+ #: ../uk-cookie-consent.php:89
111
+ msgid ""
112
+ "If you find the page hasn't been created, hit the Save Changes button on "
113
+ "this page."
114
+ msgstr ""
115
+
116
+ #: ../uk-cookie-consent.php:90
117
+ msgid ""
118
+ "If you would like to change the permalink, just update the Info page "
119
+ "permalink setting, e.g. enter \"?page_id=4\" if you are using the default "
120
+ "permalink settings (and 4 is the id of your new Cookie Policy page)."
121
+ msgstr ""
122
+
123
+ #: ../uk-cookie-consent.php:91
124
+ #, php-format
125
+ msgid ""
126
+ "For any support queries, please post on the <a href=\"%s\">WordPress forum</"
127
+ "a>."
128
+ msgstr ""
129
+
130
+ #: ../uk-cookie-consent.php:92
131
+ #, php-format
132
+ msgid ""
133
+ "And if this plug-in has been helpful to you, then <a href=\"%s\">please rate "
134
+ "it</a>."
135
+ msgstr ""
136
+
137
+ #: ../uk-cookie-consent.php:99 ../uk-cookie-consent.php:154
138
+ msgid "This site uses cookies"
139
+ msgstr ""
140
+
141
+ #: ../uk-cookie-consent.php:107
142
+ msgid "No problem"
143
+ msgstr ""
144
+
145
+ #: ../uk-cookie-consent.php:115
146
+ msgid "More info"
147
+ msgstr ""
148
+
149
+ #: ../uk-cookie-consent.php:123
150
+ msgid "cookie-policy"
151
+ msgstr ""
152
+
153
+ #: ../uk-cookie-consent.php:159
154
+ msgid "Okay, thanks"
155
+ msgstr ""
156
+
157
+ #: ../uk-cookie-consent.php:164
158
+ msgid "Find out more"
159
+ msgstr ""
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Plugin Name ===
2
- Contributors: catapult
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=M2FLCU6Z4A2LA
4
  Tags: cookies, eu, cookie law, implied consent, uk cookie consent
5
- Requires at least: 3.3.2
6
- Tested up to: 3.4.1
7
- Stable tag: 1.31
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -48,6 +48,23 @@ You will find more details of the regulations on the [Information Commissioner's
48
 
49
  == Changelog ==
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  = 1.3 =
52
  Reinstated user-defined permalink field
53
 
1
  === Plugin Name ===
2
+ Contributors: catapult, husobj
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=M2FLCU6Z4A2LA
4
  Tags: cookies, eu, cookie law, implied consent, uk cookie consent
5
+ Requires at least: 3.5.0
6
+ Tested up to: 3.5.1
7
+ Stable tag: 1.4.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
48
 
49
  == Changelog ==
50
 
51
+ = 1.5 =
52
+ Switched the logic so that the bar is initially hidden on the page and only displays if user has not previously dismissed it.
53
+ Gives a slightly better performance.
54
+ Thanks to chrisHe for the suggestion.
55
+
56
+ = 1.4.2. =
57
+ Policy page created on register_activation_hook now
58
+
59
+ = 1.4.1 =
60
+ Tweak to ensure jQuery is a dependency
61
+
62
+ = 1.4 =
63
+ This plug-in now uses JavaScript to test whether the user has dismissed the front-end notification in order to solve issues with caching plug-ins.
64
+ Added configuration options for colour and position of bar.
65
+ Set notification button and link to first element in tab list.
66
+ Thanks to husobj for contributions and suggestions including localisation and enqueueing scripts and stylesheets
67
+
68
  = 1.3 =
69
  Reinstated user-defined permalink field
70
 
uk-cookie-consent.php CHANGED
@@ -4,70 +4,48 @@ Plugin Name: UK Cookie Consent
4
  Plugin URI: http://catapultdesign.co.uk/plugin/uk-cookie-consent/
5
  Description: Simple plug-in to help compliance with the UK interpretation of the EU regulations regarding usage of website cookies. A user to your site is presented with a clear yet unobtrusive notification that the site is using cookies and may then acknowledge and dismiss the notification or click to find out more. The plug-in does not disable cookies on your site or prevent the user from continuing to browse the site - it comes with standard wording on what cookies are and advice on how to disable them in the browser. The plug-in follows the notion of "implied consent" as described by the UK's Information Commissioner and makes the assumption that most users who choose not to accept cookies will do so for all websites.
6
  Author: Catapult
7
- Version: 1.31
8
  Author URI: http://catapultdesign.co.uk/
9
  */
10
 
11
- $options = get_option('catapult_cookie_options');
12
-
13
- $wp_content_url = get_option( 'siteurl' ) . '/wp-content';
14
- $wp_plugin_url = plugins_url() . '/catapult-cookie-consent';
15
 
16
  //Add an option page for the settings
17
  add_action('admin_menu', 'catapult_cookie_plugin_menu');
18
  function catapult_cookie_plugin_menu() {
19
- add_options_page('Cookie Consent', 'Cookie Consent', 'manage_options', 'catapult_cookie_consent', 'catapult_cookie_options_page');
20
  }
21
 
22
  function catapult_cookie_options_page() { ?>
23
  <div class="wrap">
24
- <h2>UK Cookie Consent</h2>
25
  <div id="poststuff" class="metabox-holder has-right-sidebar">
26
  <div class="meta-box-sortabless">
27
  <div class="postbox">
28
- <h3 class="hndle">Your settings</h3>
29
  <div class="inside">
30
- <?php //Check to see if the info page has been created
31
- $options = get_option('catapult_cookie_options');
32
- $pagename = 'Cookie Policy';
33
- $cpage = get_page_by_title ( $pagename );
34
- if ( !$cpage ) {
35
- global $user_ID;
36
- $page['post_type'] = 'page';
37
- $page['post_content'] = '<p>This site uses cookies - small text files that are placed on your machine to help the site provide a better user experience. In general, cookies are used to retain user preferences, store information for things like shopping carts, and provide anonymised tracking data to third party applications like Google Analytics.</p>
38
- <p>As a rule, cookies will make your browsing experience better. However, you may prefer to disable cookies on this site and on others. The most effective way to do this is to disable cookies in your browser. We suggest consulting the Help section of your browser or taking a look at <a href="http://www.aboutcookies.org">the About Cookies website</a> which offers guidance for all modern browsers.</p>';
39
- $page['post_parent'] = 0;
40
- $page['post_author'] = $user_ID;
41
- $page['post_status'] = 'publish';
42
- $page['post_title'] = $pagename;
43
- $pageid = wp_insert_post ( $page );
44
- if ( $pageid == 0 ) {
45
- echo '<div class="updated settings-error">Failed to create page.</div>';
46
- } else {
47
- echo '<div class="updated">Cookie Policy page successfully created.</div>';
48
- }
49
- } ?>
50
  <form action="options.php" method="post">
51
  <?php settings_fields('catapult_cookie_options'); ?>
52
  <?php do_settings_sections('catapult_cookie'); ?>
53
- <input name="cat_submit" type="submit" id="submit" class="button-primary" style="margin-top:30px;" value="<?php esc_attr_e('Save Changes'); ?>" />
54
  <?php $options = get_option('catapult_cookie_options');
55
  $value = htmlentities ( $options['catapult_cookie_link_settings'], ENT_QUOTES );
56
  if ( !$value ) {
57
  $value = 'cookie-policy';
58
  } ?>
59
- <p>Your Cookies Policy page is <a href="<?php bloginfo ( 'url' ); ?>/<?php echo $value; ?>/">here</a>. You may wish to create a menu item or other link on your site to this page.</p>
60
  </form>
61
  </div>
62
  </div>
63
  </div>
64
  <div class="meta-box-sortabless ui-sortable" style="position:relative;">
65
  <div class="postbox">
66
- <h3 class="hndle">Resources</h3>
67
  <div class="inside">
68
- <p><a href="http://www.ico.gov.uk/for_organisations/privacy_and_electronic_communications/the_guide/cookies.aspx">Information Commissioner's Office Guidance on Cookies</a></p>
69
  <p><a href="http://www.aboutcookies.org/default.aspx">AboutCookies.org</a></p>
70
- <p><a href="http://catapultdesign.co.uk/uk-cookie-consent/">Our interpretation of the guidance</a></p>
71
  </div>
72
  </div>
73
  </div>
@@ -76,51 +54,123 @@ function catapult_cookie_options_page() { ?>
76
  <?php }
77
 
78
  add_action('admin_init', 'catapult_cookie_admin_init');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  function catapult_cookie_admin_init(){
80
  register_setting( 'catapult_cookie_options', 'catapult_cookie_options', 'catapult_cookie_options_validate' );
81
  add_settings_section('catapult_cookie_main', '', 'catapult_cookie_section_text', 'catapult_cookie', 'catapult_cookie_main' );
82
- add_settings_field('catapult_cookie_text', 'Notification text', 'catapult_cookie_text_settings', 'catapult_cookie', 'catapult_cookie_main' );
83
- add_settings_field('catapult_cookie_accept', 'Accept text', 'catapult_cookie_accept_settings', 'catapult_cookie', 'catapult_cookie_main' );
84
- add_settings_field('catapult_cookie_more', 'More info text', 'catapult_cookie_more_settings', 'catapult_cookie', 'catapult_cookie_main' );
85
- add_settings_field('catapult_cookie_link', 'Info page permalink', 'catapult_cookie_link_settings', 'catapult_cookie', 'catapult_cookie_main' );
 
 
 
 
 
86
  }
87
 
88
  function catapult_cookie_section_text() {
89
- echo '<p>You can just use these settings as they are or update the text as you wish. We recommend keeping it brief.</p><p>The plug-in automatically creates a page called "Cookie Policy" and sets the default More Info link to yoursitename.com/cookie-policy.</p><p>If you find the page hasn\'t been created, hit the Save Changes button on this page.</p><p>If you would like to change the permalink, just update the Info page permalink setting, e.g. enter "?page_id=4" if you are using the default permalink settings (and 4 is the id of your new Cookie Policy page).</p><p>For any support queries, please post on the <a href="http://wordpress.org/extend/plugins/uk-cookie-consent/">WordPress forum</a>.</p><p><strong>And if this plug-in has been helpful to you, then <a href="http://wordpress.org/extend/plugins/uk-cookie-consent/">please rate it</a>.</strong></p>';
 
 
 
 
 
90
  }
91
 
92
  function catapult_cookie_text_settings() {
93
  $options = get_option( 'catapult_cookie_options' );
94
- $value = htmlentities ( $options['catapult_cookie_text_settings'], ENT_QUOTES );
95
  if ( !$value ) {
96
- $value = 'This site uses cookies';
97
  }
98
- echo "<input id='catapult_cookie_text_settings' name='catapult_cookie_options[catapult_cookie_text_settings]' size='50' type='text' value='{$value}' />";
99
  }
100
  function catapult_cookie_accept_settings() {
101
  $options = get_option('catapult_cookie_options');
102
- $value = htmlentities ( $options['catapult_cookie_accept_settings'], ENT_QUOTES );
103
  if ( !$value ) {
104
- $value = 'No problem';
105
  }
106
- echo "<input id='catapult_cookie_accept_settings' name='catapult_cookie_options[catapult_cookie_accept_settings]' size='50' type='text' value='{$value}' />";
107
  }
108
  function catapult_cookie_more_settings() {
109
  $options = get_option('catapult_cookie_options');
110
- $value = htmlentities ( $options['catapult_cookie_more_settings'], ENT_QUOTES );
111
  if ( !$value ) {
112
- $value = 'More info';
113
  }
114
- echo "<input id='catapult_cookie_more_settings' name='catapult_cookie_options[catapult_cookie_more_settings]' size='50' type='text' value='{$value}' />";
115
  }
116
  function catapult_cookie_link_settings() {
117
  $options = get_option('catapult_cookie_options');
118
- $value = htmlentities ( $options['catapult_cookie_link_settings'], ENT_QUOTES );
119
  if ( !$value ) {
120
- $value = 'cookie-policy';
121
  }
122
- echo "<input id='catapult_cookie_link_settings' name='catapult_cookie_options[catapult_cookie_link_settings]' size='50' type='text' value='{$value}' />";
123
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
 
125
  function catapult_cookie_options_validate($input) {
126
  $options = get_option( 'catapult_cookie_options' );
@@ -128,105 +178,129 @@ function catapult_cookie_options_validate($input) {
128
  $options['catapult_cookie_accept_settings'] = trim($input['catapult_cookie_accept_settings']);
129
  $options['catapult_cookie_more_settings'] = trim($input['catapult_cookie_more_settings']);
130
  $options['catapult_cookie_link_settings'] = trim($input['catapult_cookie_link_settings']);
 
 
 
 
 
131
  return $options;
132
  }
 
 
 
 
 
 
 
133
 
134
  //Enqueue jquery
135
  function catapult_cookie_jquery() {
136
  wp_enqueue_script( 'jquery' );
137
- }
 
138
  add_action('wp_enqueue_scripts', 'catapult_cookie_jquery');
139
 
140
- //Add CSS and JS if the cookie is not set
 
 
141
  function catapult_add_cookie_css() {
142
- if ( !isset ( $_COOKIE["catAccCookies"] ) ) {
143
- echo '<style type="text/css" media="screen">
144
- html { margin-top: 32px; }
145
- * html body { margin-top: 32px; }
146
- #catapult-cookie-bar {
147
- direction: ltr;
148
- color: #DDD;
149
- font: normal 13px/28px sans-serif;
150
- height: 30px;
151
- position: fixed;
152
- top: 0;
153
- left: 0;
154
- width: 100%;
155
- min-width: 600px;
156
- z-index: 99999;
157
- padding:2px 20px 0;
158
- background-color: #464646;
159
- background-image: -ms-linear-gradient(bottom, #373737, #464646 5px);
160
- background-image: -moz-linear-gradient(bottom, #373737, #464646 5px);
161
- background-image: -o-linear-gradient(bottom, #373737, #464646 5px);
162
- background-image: -webkit-gradient(linear,left bottom,left top,from( #373737),to(#464646));
163
- background-image: -webkit-linear-gradient(bottom, #373737, #464646 5px);
164
- background-image: linear-gradient(bottom, #373737, #464646 5px);
165
- text-align:left;
166
- }
167
- #catapult-cookie-bar a {
168
- color:#fff;
169
- }
170
- button#catapultCookie {
171
- margin:0 20px;
172
- line-height:20px;
173
- background:#45AE52;
174
- border:none;
175
- color:#fff;
176
- padding:0 12px;
177
- border-radius: 3px;
178
- cursor: pointer;
179
- font-size: 13px;
180
- font-weight: bold;
181
- font-family: sans-serif;
182
- text-shadow: #555 1px 1px;
183
- }
184
- button#catapultCookie:hover {
185
- background:#5EC544;
186
- }
187
- </style>
188
- <script type="text/javascript">
189
- function catapultAcceptCookies() {
190
- days = 30;
191
- var date = new Date();
192
- date.setTime(date.getTime()+(days*24*60*60*1000));
193
- var expires = "; expires="+date.toGMTString();
194
- document.cookie = "catAccCookies=true"+expires+"; path=/";
195
- jQuery("#catapult-cookie-bar").hide();
196
- jQuery("html").css("margin-top","0");
197
- }
198
- </script>';
199
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  }
201
  add_action ( 'wp_head', 'catapult_add_cookie_css' );
202
 
203
- //Add the notification bar if the cookie is not set
 
 
 
 
 
 
 
 
 
 
 
 
204
  function catapult_add_cookie_bar() {
205
- if ( !isset ( $_COOKIE["catAccCookies"] ) ) {
206
- $options = get_option('catapult_cookie_options');
207
- if ( $options['catapult_cookie_text_settings'] ) {
208
- $current_text = $options['catapult_cookie_text_settings'];
209
- } else {
210
- $current_text = "This site uses cookies";
211
- }
212
- if ( $options['catapult_cookie_accept_settings'] ) {
213
- $accept_text = $options['catapult_cookie_accept_settings'];
214
- } else {
215
- $accept_text = "Okay, thanks";
216
- }
217
- if ( $options['catapult_cookie_more_settings'] ) {
218
- $more_text = $options['catapult_cookie_more_settings'];
219
- } else {
220
- $more_text = "Find out more";
221
- }
222
- if ( $options['catapult_cookie_link_settings'] ) {
223
- $link_text = strtolower ( $options['catapult_cookie_link_settings'] );
224
- } else {
225
- $link_text = "cookie-policy";
226
- }
227
- echo '<div id="catapult-cookie-bar">' . htmlspecialchars ( $current_text ) . '<button id="catapultCookie" onclick="catapultAcceptCookies()">' . htmlspecialchars ( $accept_text ) . '</button><a href="' . get_bloginfo ( 'url' ) . '/' . $link_text . '/">' . htmlspecialchars ( $more_text ) . '</a></div>';
228
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
  }
230
- add_action ( 'wp_footer', 'catapult_add_cookie_bar', 1000 );
231
-
232
-
4
  Plugin URI: http://catapultdesign.co.uk/plugin/uk-cookie-consent/
5
  Description: Simple plug-in to help compliance with the UK interpretation of the EU regulations regarding usage of website cookies. A user to your site is presented with a clear yet unobtrusive notification that the site is using cookies and may then acknowledge and dismiss the notification or click to find out more. The plug-in does not disable cookies on your site or prevent the user from continuing to browse the site - it comes with standard wording on what cookies are and advice on how to disable them in the browser. The plug-in follows the notion of "implied consent" as described by the UK's Information Commissioner and makes the assumption that most users who choose not to accept cookies will do so for all websites.
6
  Author: Catapult
7
+ Version: 1.5
8
  Author URI: http://catapultdesign.co.uk/
9
  */
10
 
11
+ // Language
12
+ load_plugin_textdomain( 'uk-cookie-consent', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
 
 
13
 
14
  //Add an option page for the settings
15
  add_action('admin_menu', 'catapult_cookie_plugin_menu');
16
  function catapult_cookie_plugin_menu() {
17
+ add_options_page( __( 'Cookie Consent', 'uk-cookie-consent' ), __( 'Cookie Consent', 'uk-cookie-consent' ), 'manage_options', 'catapult_cookie_consent', 'catapult_cookie_options_page' );
18
  }
19
 
20
  function catapult_cookie_options_page() { ?>
21
  <div class="wrap">
22
+ <h2><?php _e( 'UK Cookie Consent', 'uk-cookie-consent' ); ?></h2>
23
  <div id="poststuff" class="metabox-holder has-right-sidebar">
24
  <div class="meta-box-sortabless">
25
  <div class="postbox">
26
+ <h3 class="hndle"><?php _e( 'Your settings', 'uk-cookie-consent' ); ?></h3>
27
  <div class="inside">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  <form action="options.php" method="post">
29
  <?php settings_fields('catapult_cookie_options'); ?>
30
  <?php do_settings_sections('catapult_cookie'); ?>
31
+ <input name="cat_submit" type="submit" id="submit" class="button-primary" style="margin-top:30px;" value="<?php esc_attr_e( __( 'Save Changes', 'uk-cookie-consent' ) ); ?>" />
32
  <?php $options = get_option('catapult_cookie_options');
33
  $value = htmlentities ( $options['catapult_cookie_link_settings'], ENT_QUOTES );
34
  if ( !$value ) {
35
  $value = 'cookie-policy';
36
  } ?>
37
+ <p><?php echo sprintf( __( 'Your Cookies Policy page is <a href="%s">here</a>. You may wish to create a menu item or other link on your site to this page.', 'uk-cookie-consent' ), home_url( $value ) ); ?></p>
38
  </form>
39
  </div>
40
  </div>
41
  </div>
42
  <div class="meta-box-sortabless ui-sortable" style="position:relative;">
43
  <div class="postbox">
44
+ <h3 class="hndle"><?php _e( 'Resources', 'uk-cookie-consent' ); ?></h3>
45
  <div class="inside">
46
+ <p><a href="http://www.ico.gov.uk/for_organisations/privacy_and_electronic_communications/the_guide/cookies.aspx"><?php _e( 'Information Commissioner\'s Office Guidance on Cookies', 'uk-cookie-consent' ); ?></a></p>
47
  <p><a href="http://www.aboutcookies.org/default.aspx">AboutCookies.org</a></p>
48
+ <p><a href="http://catapultdesign.co.uk/uk-cookie-consent/"><?php _e( 'Our interpretation of the guidance', 'uk-cookie-consent' ); ?></a></p>
49
  </div>
50
  </div>
51
  </div>
54
  <?php }
55
 
56
  add_action('admin_init', 'catapult_cookie_admin_init');
57
+
58
+ function catapult_create_policy_page() {
59
+ //Check to see if the info page has been created
60
+ $options = get_option('catapult_cookie_options');
61
+ $pagename = __( 'Cookie Policy', 'uk-cookie-consent' );
62
+ $cpage = get_page_by_title ( $pagename );
63
+ if ( !$cpage ) {
64
+ global $user_ID;
65
+ $page['post_type'] = 'page';
66
+ $page['post_content'] = '<p>' . __( 'This site uses cookies - small text files that are placed on your machine to help the site provide a better user experience. In general, cookies are used to retain user preferences, store information for things like shopping carts, and provide anonymised tracking data to third party applications like Google Analytics. As a rule, cookies will make your browsing experience better. However, you may prefer to disable cookies on this site and on others. The most effective way to do this is to disable cookies in your browser. We suggest consulting the Help section of your browser or taking a look at <a href="http://www.aboutcookies.org">the About Cookies website</a> which offers guidance for all modern browsers', 'uk-cookie-consent' ) . '</p>';
67
+ $page['post_parent'] = 0;
68
+ $page['post_author'] = $user_ID;
69
+ $page['post_status'] = 'publish';
70
+ $page['post_title'] = $pagename;
71
+ $pageid = wp_insert_post ( $page );
72
+ }
73
+ }
74
+ register_activation_hook( __FILE__, 'catapult_create_policy_page' );
75
+
76
  function catapult_cookie_admin_init(){
77
  register_setting( 'catapult_cookie_options', 'catapult_cookie_options', 'catapult_cookie_options_validate' );
78
  add_settings_section('catapult_cookie_main', '', 'catapult_cookie_section_text', 'catapult_cookie', 'catapult_cookie_main' );
79
+ add_settings_field('catapult_cookie_text', __( 'Notification text', 'uk-cookie-consent' ), 'catapult_cookie_text_settings', 'catapult_cookie', 'catapult_cookie_main' );
80
+ add_settings_field('catapult_cookie_accept', __( 'Accept text', 'uk-cookie-consent' ), 'catapult_cookie_accept_settings', 'catapult_cookie', 'catapult_cookie_main' );
81
+ add_settings_field('catapult_cookie_more', __( 'More info text', 'uk-cookie-consent' ), 'catapult_cookie_more_settings', 'catapult_cookie', 'catapult_cookie_main' );
82
+ add_settings_field('catapult_cookie_link', __( 'Info page permalink', 'uk-cookie-consent' ), 'catapult_cookie_link_settings', 'catapult_cookie', 'catapult_cookie_main' );
83
+ add_settings_field('catapult_cookie_text_colour', __( 'Text colour', 'uk-cookie-consent' ), 'catapult_cookie_text_colour_settings', 'catapult_cookie', 'catapult_cookie_main' );
84
+ add_settings_field('catapult_cookie_link_colour', __( 'Link colour', 'uk-cookie-consent' ), 'catapult_cookie_link_colour_settings', 'catapult_cookie', 'catapult_cookie_main' );
85
+ add_settings_field('catapult_cookie_bg_colour', __( 'Bar colour', 'uk-cookie-consent' ), 'catapult_cookie_bg_colour_settings', 'catapult_cookie', 'catapult_cookie_main' );
86
+ add_settings_field('catapult_cookie_button_colour', __( 'Button colour', 'uk-cookie-consent' ), 'catapult_cookie_button_colour_settings', 'catapult_cookie', 'catapult_cookie_main' );
87
+ add_settings_field('catapult_cookie_bar_position', __( 'Notification position', 'uk-cookie-consent' ), 'catapult_cookie_bar_position_settings', 'catapult_cookie', 'catapult_cookie_main' );
88
  }
89
 
90
  function catapult_cookie_section_text() {
91
+ echo '<p>' . __( 'You can just use these settings as they are or update the text as you wish. We recommend keeping it brief.', 'uk-cookie-consent' ) . '</p>
92
+ <p>' . __( 'The plug-in automatically creates a page called "Cookie Policy" and sets the default More Info link to yoursitename.com/cookie-policy.', 'uk-cookie-consent' ) . '</p>
93
+ <p>' . __( 'If you find the page hasn\'t been created, hit the Save Changes button on this page.', 'uk-cookie-consent' ) . '</p>
94
+ <p>' . __( 'If you would like to change the permalink, just update the Info page permalink setting, e.g. enter "?page_id=4" if you are using the default permalink settings (and 4 is the id of your new Cookie Policy page).', 'uk-cookie-consent' ) . '</p>
95
+ <p>' . sprintf( __( 'For any support queries, please post on the <a href="%s">WordPress forum</a>.', 'uk-cookie-consent' ), 'http://wordpress.org/extend/plugins/uk-cookie-consent/' ) . '</p>
96
+ <p><strong>' . sprintf( __( 'And if this plug-in has been helpful to you, then <a href="%s">please rate it</a>.', 'uk-cookie-consent' ), 'http://wordpress.org/extend/plugins/uk-cookie-consent/' ) . '</strong></p>';
97
  }
98
 
99
  function catapult_cookie_text_settings() {
100
  $options = get_option( 'catapult_cookie_options' );
101
+ $value = $options['catapult_cookie_text_settings'];
102
  if ( !$value ) {
103
+ $value = __( 'This site uses cookies', 'uk-cookie-consent' );
104
  }
105
+ echo '<input id="catapult_cookie_text_settings" name="catapult_cookie_options[catapult_cookie_text_settings]" size="50" type="text" value="' . esc_attr( $value ) . '" />';
106
  }
107
  function catapult_cookie_accept_settings() {
108
  $options = get_option('catapult_cookie_options');
109
+ $value = $options['catapult_cookie_accept_settings'];
110
  if ( !$value ) {
111
+ $value = __( 'No problem', 'uk-cookie-consent' );
112
  }
113
+ echo '<input id="catapult_cookie_accept_settings" name="catapult_cookie_options[catapult_cookie_accept_settings]" size="50" type="text" value="' . esc_attr( $value ) . '" />';
114
  }
115
  function catapult_cookie_more_settings() {
116
  $options = get_option('catapult_cookie_options');
117
+ $value = $options['catapult_cookie_more_settings'];
118
  if ( !$value ) {
119
+ $value = __( 'More info', 'uk-cookie-consent' );
120
  }
121
+ echo '<input id="catapult_cookie_more_settings" name="catapult_cookie_options[catapult_cookie_more_settings]" size="50" type="text" value="' . esc_attr( $value ) . '" />';
122
  }
123
  function catapult_cookie_link_settings() {
124
  $options = get_option('catapult_cookie_options');
125
+ $value = $options['catapult_cookie_link_settings'];
126
  if ( !$value ) {
127
+ $value = __( 'cookie-policy', 'uk-cookie-consent' );
128
  }
129
+ echo '<input id="catapult_cookie_link_settings" name="catapult_cookie_options[catapult_cookie_link_settings]" size="50" type="text" value="' . esc_attr( $value ) . '" />';
130
  }
131
+ function catapult_cookie_text_colour_settings() {
132
+ $options = get_option('catapult_cookie_options');
133
+ $value = $options['catapult_cookie_text_colour_settings'];
134
+ if ( !$value ) {
135
+ $value = '#dddddd';
136
+ } ?>
137
+ <input type="text" id="catapult_cookie_text_colour" name="catapult_cookie_options[catapult_cookie_text_colour_settings]" value="<?php echo $value; ?>" class="my-color-field" />
138
+ <?php }
139
+ function catapult_cookie_link_colour_settings() {
140
+ $options = get_option('catapult_cookie_options');
141
+ $value = $options['catapult_cookie_link_colour_settings'];
142
+ if ( !$value ) {
143
+ $value = '#dddddd';
144
+ } ?>
145
+ <input type="text" name="catapult_cookie_options[catapult_cookie_link_colour_settings]" value="<?php echo $value; ?>" class="my-color-field" />
146
+ <?php }
147
+ function catapult_cookie_bg_colour_settings() {
148
+ $options = get_option('catapult_cookie_options');
149
+ $value = $options['catapult_cookie_bg_colour_settings'];
150
+ if ( !$value ) {
151
+ $value = '#464646';
152
+ } ?>
153
+ <input type="text" name="catapult_cookie_options[catapult_cookie_bg_colour_settings]" value="<?php echo $value; ?>" class="my-color-field" />
154
+ <?php }
155
+ function catapult_cookie_button_colour_settings() {
156
+ $options = get_option('catapult_cookie_options');
157
+ $value = $options['catapult_cookie_button_colour_settings'];
158
+ if ( !$value ) {
159
+ $value = '#45AE52';
160
+ } ?>
161
+ <input type="text" name="catapult_cookie_options[catapult_cookie_button_colour_settings]" value="<?php echo $value; ?>" class="my-color-field" />
162
+ <?php }
163
+ function catapult_cookie_bar_position_settings() {
164
+ $options = get_option('catapult_cookie_options');
165
+ $value = $options['catapult_cookie_bar_position_settings'];
166
+ if ( !$value ) {
167
+ $value = 'top';
168
+ } ?>
169
+ <select id="catapult_cookie_bar_position_settings" name="catapult_cookie_options[catapult_cookie_bar_position_settings]" >';
170
+ <option value="top" <?php if ( $value == 'top' ) { ?> selected="selected" <?php } ?>>Top</option>;
171
+ <option value="bottom" <?php if ( $value == 'bottom' ) { ?> selected="selected" <?php } ?>>Bottom</option>;
172
+ </select>
173
+ <?php }
174
 
175
  function catapult_cookie_options_validate($input) {
176
  $options = get_option( 'catapult_cookie_options' );
178
  $options['catapult_cookie_accept_settings'] = trim($input['catapult_cookie_accept_settings']);
179
  $options['catapult_cookie_more_settings'] = trim($input['catapult_cookie_more_settings']);
180
  $options['catapult_cookie_link_settings'] = trim($input['catapult_cookie_link_settings']);
181
+ $options['catapult_cookie_text_colour_settings'] = trim($input['catapult_cookie_text_colour_settings']);
182
+ $options['catapult_cookie_link_colour_settings'] = trim($input['catapult_cookie_link_colour_settings']);
183
+ $options['catapult_cookie_bg_colour_settings'] = trim($input['catapult_cookie_bg_colour_settings']);
184
+ $options['catapult_cookie_button_colour_settings'] = trim($input['catapult_cookie_button_colour_settings']);
185
+ $options['catapult_cookie_bar_position_settings'] = trim($input['catapult_cookie_bar_position_settings']);
186
  return $options;
187
  }
188
+ //Enqueue color-picker script for admin
189
+ function catapult_color_picker() {
190
+ wp_enqueue_style( 'wp-color-picker' );
191
+ wp_enqueue_script( 'uk-cookie-consent-colour-picker', plugins_url ( 'js/colour-picker.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
192
+ }
193
+ add_action( 'admin_enqueue_scripts', 'catapult_color_picker' );
194
+
195
 
196
  //Enqueue jquery
197
  function catapult_cookie_jquery() {
198
  wp_enqueue_script( 'jquery' );
199
+ wp_enqueue_script( 'uk-cookie-consent-js', plugins_url ( 'js/uk-cookie-consent-js.js', __FILE__ ), array ( 'jquery' ) );
200
+ }
201
  add_action('wp_enqueue_scripts', 'catapult_cookie_jquery');
202
 
203
+
204
+ //Add CSS and JS
205
+ //Add some JS to the header to test whether the cookie option has been set
206
  function catapult_add_cookie_css() {
207
+ $options = get_option( 'catapult_cookie_options' );
208
+ if ( $options['catapult_cookie_text_colour_settings'] ) {
209
+ $text_colour = $options['catapult_cookie_text_colour_settings'];
210
+ } else {
211
+ $text_colour = "#ddd";
212
+ }
213
+ if ( $options['catapult_cookie_link_colour_settings'] ) {
214
+ $link_colour = $options['catapult_cookie_link_colour_settings'];
215
+ } else {
216
+ $link_colour = "#fff;";
217
+ }
218
+ if ( $options['catapult_cookie_bg_colour_settings'] ) {
219
+ $bg_colour = $options['catapult_cookie_bg_colour_settings'];
220
+ } else {
221
+ $bg_colour = "#464646";
222
+ }
223
+ if ( $options['catapult_cookie_button_colour_settings'] ) {
224
+ $button_colour = $options['catapult_cookie_button_colour_settings'];
225
+ } else {
226
+ $button_colour = "#45AE52";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  }
228
+ if ( $options['catapult_cookie_bar_position_settings'] ) {
229
+ $position = $options['catapult_cookie_bar_position_settings'];
230
+ } else {
231
+ $position = "top";
232
+ }
233
+ echo '
234
+ <style type="text/css" media="screen">
235
+ #catapult-cookie-bar {
236
+ display: none;
237
+ direction: ltr;
238
+ color: ' . $text_colour . ';
239
+ min-height: 30px;
240
+ position: fixed;
241
+ left: 0;
242
+ ' . $position . ': 0;
243
+ width: 100%;
244
+ z-index: 99999;
245
+ padding:6px 20px 4px;
246
+ background-color: ' . $bg_colour . ';
247
+ text-align:left;
248
+ }
249
+ #catapult-cookie-bar a {
250
+ color: ' . $link_colour . ';
251
+ }
252
+ button#catapultCookie {
253
+ margin:0 20px;
254
+ line-height:20px;
255
+ background:' . $button_colour . ';
256
+ border:none;
257
+ color: ' . $link_colour . ';
258
+ padding:4px 12px;
259
+ border-radius: 3px;
260
+ cursor: pointer;
261
+ font-size: 13px;
262
+ font-weight: bold;
263
+ }
264
+ </style>';
265
  }
266
  add_action ( 'wp_head', 'catapult_add_cookie_css' );
267
 
268
+ function catapult_add_cookie_js() { ?>
269
+ <script type="text/javascript">
270
+ jQuery(document).ready(function(){
271
+ if(!catapultReadCookie("catAccCookies")){//If the cookie has been set
272
+ jQuery("#catapult-cookie-bar").show();
273
+ jQuery("html").css("margin-top","0");
274
+ }
275
+ });
276
+ </script>
277
+ <?php }
278
+ add_action ( 'wp_head', 'catapult_add_cookie_js' );
279
+
280
+ //Add the notification bar
281
  function catapult_add_cookie_bar() {
282
+ $options = get_option('catapult_cookie_options');
283
+ if ( $options['catapult_cookie_text_settings'] ) {
284
+ $current_text = $options['catapult_cookie_text_settings'];
285
+ } else {
286
+ $current_text = "This site uses cookies";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287
  }
288
+ if ( $options['catapult_cookie_accept_settings'] ) {
289
+ $accept_text = $options['catapult_cookie_accept_settings'];
290
+ } else {
291
+ $accept_text = "Okay, thanks";
292
+ }
293
+ if ( $options['catapult_cookie_more_settings'] ) {
294
+ $more_text = $options['catapult_cookie_more_settings'];
295
+ } else {
296
+ $more_text = "Find out more";
297
+ }
298
+ if ( $options['catapult_cookie_link_settings'] ) {
299
+ $link_text = strtolower ( $options['catapult_cookie_link_settings'] );
300
+ } else {
301
+ $link_text = "cookie-policy";
302
+ }
303
+ $content = sprintf( '<div id="catapult-cookie-bar">%s<button id="catapultCookie" tabindex=1 onclick="catapultAcceptCookies();">%s</button><a tabindex=1 href="%s">%s</a></div>', htmlspecialchars( $current_text ), htmlspecialchars( $accept_text ), home_url( $link_text ), htmlspecialchars( $more_text ) );
304
+ echo apply_filters( 'catapult_cookie_content', $content, $options );
305
  }
306
+ add_action ( 'wp_footer', 'catapult_add_cookie_bar', 1000 );