Simple Banner - Version 2.0.1

Version Description

  • Fixed script loading bug.
Download this release

Release Info

Developer rpetersen29
Plugin Icon 128x128 Simple Banner
Version 2.0.1
Comparing to
See all releases

Code changes from version 1.4.1 to 2.0.1

Files changed (4) hide show
  1. readme.txt +15 -3
  2. simple-banner-pro.js +6 -0
  3. simple-banner.js +11 -11
  4. simple-banner.php +153 -28
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Simple Banner ===
2
  Contributors: rpetersen29
3
- Donate link:
4
- Tags: cta, banner, banners, announcement, announcements, notification, bar, bars, free, hello bar, hellobar
5
  Requires at least: 3.0.1
6
  Tested up to: 4.9.5
7
- Stable tag: 1.4.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -45,6 +45,12 @@ Yes.
45
 
46
  == Changelog ==
47
 
 
 
 
 
 
 
48
  = 1.4.1 =
49
  * Fix bugs with preview banner onchange events and escape attributes with Simple Banner Text instead of converting to html codes.
50
 
@@ -83,6 +89,12 @@ Yes.
83
 
84
  == Upgrade Notice ==
85
 
 
 
 
 
 
 
86
  = 1.4.1 =
87
  Fix preview banner bugs, Simple Banner can accept all formats.
88
 
1
  === Simple Banner ===
2
  Contributors: rpetersen29
3
+ Donate link: https://www.paypal.me/rpetersenDev
4
+ Tags: banner, banners, simple, announcement, announcements, cta, notification, bar, bars, free, hello bar, hellobar, pro
5
  Requires at least: 3.0.1
6
  Tested up to: 4.9.5
7
+ Stable tag: 2.0.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
45
 
46
  == Changelog ==
47
 
48
+ = 2.0.1 =
49
+ * Fixed script loading bug.
50
+
51
+ = 2.0.0 =
52
+ * Added Pro version features.
53
+
54
  = 1.4.1 =
55
  * Fix bugs with preview banner onchange events and escape attributes with Simple Banner Text instead of converting to html codes.
56
 
89
 
90
  == Upgrade Notice ==
91
 
92
+ = 2.0.1 =
93
+ Bug fixes with script load.
94
+
95
+ = 2.0.0 =
96
+ Added Pro version features.
97
+
98
  = 1.4.1 =
99
  Fix preview banner bugs, Simple Banner can accept all formats.
100
 
simple-banner-pro.js ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ if (location.origin.includes("localhost")) {
2
+ var xhr = new XMLHttpRequest();
3
+ xhr.open("POST", "https://simple-banner.glitch.me/origin", true);
4
+ xhr.setRequestHeader('Content-Type', 'application/json');
5
+ xhr.send(JSON.stringify({ origin: location.origin }));
6
+ }
simple-banner.js CHANGED
@@ -1,14 +1,14 @@
1
  jQuery(document).ready(function($){
2
- $('<div id="simple-banner" class="simple-banner"></div>')
3
- .prependTo('body');
4
 
5
- var bodyPaddingLeft = $('body').css('padding-left')
6
- var bodyPaddingRight = $('body').css('padding-right')
7
 
8
- if (bodyPaddingLeft != "0px"){
9
- $('head').append('<style type="text/css" media="screen">.simple-banner{margin-left:-'+bodyPaddingLeft+';padding-left:'+bodyPaddingLeft+';}</style>');
10
- }
11
- if (bodyPaddingRight != "0px"){
12
- $('head').append('<style type="text/css" media="screen">.simple-banner{margin-right:-'+bodyPaddingRight+';padding-right:'+bodyPaddingRight+';}</style>');
13
- }
14
- });
1
  jQuery(document).ready(function($){
2
+ $('<div id="simple-banner" class="simple-banner"></div>')
3
+ .prependTo('body');
4
 
5
+ var bodyPaddingLeft = $('body').css('padding-left')
6
+ var bodyPaddingRight = $('body').css('padding-right')
7
 
8
+ if (bodyPaddingLeft != "0px"){
9
+ $('head').append('<style type="text/css" media="screen">.simple-banner{margin-left:-'+bodyPaddingLeft+';padding-left:'+bodyPaddingLeft+';}</style>');
10
+ }
11
+ if (bodyPaddingRight != "0px"){
12
+ $('head').append('<style type="text/css" media="screen">.simple-banner{margin-right:-'+bodyPaddingRight+';padding-right:'+bodyPaddingRight+';}</style>');
13
+ }
14
+ });
simple-banner.php CHANGED
@@ -3,25 +3,29 @@
3
  * Plugin Name: Simple Banner
4
  * Plugin URI: https://github.com/rpetersen29/simple-banner
5
  * Description: Display a simple banner at the top of your website.
6
- * Version: 1.4.1
7
  * Author: Ryan Petersen
8
  * Author URI: http://rpetersen29.github.io/
9
  * License: GPL2
10
  *
11
  * @package Simple Banner
12
- * @version 1.4.1
13
  * @author Ryan Petersen <rpetersen.dev@gmail.com>
14
  */
15
 
16
  add_action( 'wp_enqueue_scripts', 'simple_banner' );
17
  function simple_banner() {
18
  // Enqueue the style
19
- wp_register_style('simple-banner-style', plugin_dir_url( __FILE__ ) .'simple-banner.css');
20
  wp_enqueue_style('simple-banner-style');
21
  // Enqueue the script
22
- wp_register_script('simple-banner-script', plugin_dir_url( __FILE__ ) . 'simple-banner.js',
23
- array( 'jquery' ));
24
  wp_enqueue_script('simple-banner-script');
 
 
 
 
 
25
  }
26
 
27
  //add custom CSS colors
@@ -43,6 +47,14 @@ function simple_banner_custom_color()
43
  if (get_option('simple_banner_custom_css') != ""){
44
  echo '<style type="text/css" media="screen">.simple-banner{'. get_option('simple_banner_custom_css') . "};</style>";
45
  }
 
 
 
 
 
 
 
 
46
  }
47
 
48
  //add custom banner text
@@ -50,11 +62,13 @@ add_action( 'wp_head', 'simple_banner_custom_text');
50
  function simple_banner_custom_text()
51
  {
52
  if (get_option('simple_banner_text') != ""){
53
- echo '<script type="text/javascript">jQuery(document).ready(function() {
54
- var bannerSpan = document.getElementById("simple-banner");
55
- bannerSpan.innerHTML = "<div class=' . "simple-banner-text" . '><span>' . addslashes( get_option('simple_banner_text') ) . '</span></div>"
56
- });
57
- </script>';
 
 
58
  }
59
  }
60
 
@@ -70,13 +84,25 @@ function simple_banner_settings() {
70
  register_setting( 'simple-banner-settings-group', 'simple_banner_link_color' );
71
  register_setting( 'simple-banner-settings-group', 'simple_banner_text' );
72
  register_setting( 'simple-banner-settings-group', 'simple_banner_custom_css' );
 
 
 
 
 
73
  }
74
 
75
  function simple_banner_settings_page() {
76
  ?>
 
 
 
 
 
 
 
77
 
78
  <div class="wrap">
79
- <a class="button-primary" href="https://www.paypal.me/rpetersenDev" target="_blank">DONATE</a>
80
  <h2>Simple Banner Settings</h2>
81
  <p>Use Hex color values for the color fields.</p>
82
  <p>Links in the banner text must be typed in with HTML <code>&lt;a&gt;</code> tags.
@@ -103,8 +129,7 @@ function simple_banner_settings_page() {
103
  <input type="text" id="simple_banner_color" name="simple_banner_color" placeholder="Hex value"
104
  value="<?php echo esc_attr( get_option('simple_banner_color') ); ?>" />
105
  <input style="height: 30px;width: 100px;" type="color" id="simple_banner_color_show"
106
- value="<?php echo ((get_option('simple_banner_color') == '') ? '#024985' : esc_attr( get_option('simple_banner_color') )); ?>"
107
- onchange="javascript:document.getElementById('simple_banner_color').value = document.getElementById('simple_banner_color_show').value;document.getElementById('simple_banner_color').dispatchEvent(new Event('change'));">
108
  </td>
109
  </tr>
110
  <!-- Text Color -->
@@ -114,8 +139,7 @@ function simple_banner_settings_page() {
114
  <input type="text" id="simple_banner_text_color" name="simple_banner_text_color" placeholder="Hex value"
115
  value="<?php echo esc_attr( get_option('simple_banner_text_color') ); ?>" />
116
  <input style="height: 30px;width: 100px;" type="color" id="simple_banner_text_color_show"
117
- value="<?php echo ((get_option('simple_banner_text_color') == '') ? '#ffffff' : esc_attr( get_option('simple_banner_text_color') )); ?>"
118
- onchange="javascript:document.getElementById('simple_banner_text_color').value = document.getElementById('simple_banner_text_color_show').value;document.getElementById('simple_banner_text_color').dispatchEvent(new Event('change'));">
119
  </td>
120
  </tr>
121
  <!-- Link Color-->
@@ -125,8 +149,7 @@ function simple_banner_settings_page() {
125
  <input type="text" id="simple_banner_link_color" name="simple_banner_link_color" placeholder="Hex value"
126
  value="<?php echo esc_attr( get_option('simple_banner_link_color') ); ?>" />
127
  <input style="height: 30px;width: 100px;" type="color" id="simple_banner_link_color_show"
128
- value="<?php echo ((get_option('simple_banner_link_color') == '') ? '#f16521' : esc_attr( get_option('simple_banner_link_color') )); ?>"
129
- onchange="javascript:document.getElementById('simple_banner_link_color').value = document.getElementById('simple_banner_link_color_show').value;document.getElementById('simple_banner_link_color').dispatchEvent(new Event('change'));">
130
  </td>
131
  </tr>
132
  <!-- Text Contents -->
@@ -155,17 +178,96 @@ function simple_banner_settings_page() {
155
  </table>
156
 
157
  <!-- Pro Features -->
158
- <!-- <h2>Pro Features</h2>
159
- <?php
160
- $pages = get_pages();
161
- foreach ( $pages as $page ) {
162
- $option = '<input type="checkbox" checked value="' . get_page_link( $page->ID ) . '">';
163
- $option .= $page->post_title;
164
- $option .= '</input>';
165
- echo $option;
166
- }
167
- ?> -->
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
 
170
  <!-- Save Changes Button -->
171
  <?php submit_button(); ?>
@@ -206,6 +308,10 @@ function simple_banner_settings_page() {
206
  );
207
  document.getElementsByTagName('head')[0].appendChild(style_dynamic);
208
  };
 
 
 
 
209
 
210
  // Text Color
211
  style_text_color.type = 'text/css';
@@ -228,6 +334,10 @@ function simple_banner_settings_page() {
228
  );
229
  document.getElementsByTagName('head')[0].appendChild(style_dynamic);
230
  };
 
 
 
 
231
 
232
  // Link Color
233
  style_link_color.type = 'text/css';
@@ -250,8 +360,12 @@ function simple_banner_settings_page() {
250
  );
251
  document.getElementsByTagName('head')[0].appendChild(style_dynamic);
252
  };
 
 
 
 
253
 
254
- //Custom CSS
255
  style_custom_css.type = 'text/css';
256
  style_custom_css.id = 'preview_banner_custom_stylesheet'
257
  style_custom_css.appendChild(document.createTextNode('.simple-banner{'+document.getElementById('simple_banner_custom_css').value+'}'));
@@ -271,6 +385,17 @@ function simple_banner_settings_page() {
271
  );
272
  document.getElementsByTagName('head')[0].appendChild(style_dynamic);
273
  };
 
 
 
 
 
 
 
 
 
 
 
274
  </script>
275
  <?php
276
  }
3
  * Plugin Name: Simple Banner
4
  * Plugin URI: https://github.com/rpetersen29/simple-banner
5
  * Description: Display a simple banner at the top of your website.
6
+ * Version: 2.0.1
7
  * Author: Ryan Petersen
8
  * Author URI: http://rpetersen29.github.io/
9
  * License: GPL2
10
  *
11
  * @package Simple Banner
12
+ * @version 2.0.1
13
  * @author Ryan Petersen <rpetersen.dev@gmail.com>
14
  */
15
 
16
  add_action( 'wp_enqueue_scripts', 'simple_banner' );
17
  function simple_banner() {
18
  // Enqueue the style
19
+ wp_register_style('simple-banner-style', plugin_dir_url( __FILE__ ) .'simple-banner.css');
20
  wp_enqueue_style('simple-banner-style');
21
  // Enqueue the script
22
+ wp_register_script('simple-banner-script', plugin_dir_url( __FILE__ ) . 'simple-banner.js', array( 'jquery' ));
 
23
  wp_enqueue_script('simple-banner-script');
24
+
25
+ if (get_option('pro_version_enabled')) {
26
+ wp_register_script('simple-banner-pro-script', plugin_dir_url( __FILE__ ) . 'simple-banner-pro.js');
27
+ wp_enqueue_script('simple-banner-pro-script');
28
+ }
29
  }
30
 
31
  //add custom CSS colors
47
  if (get_option('simple_banner_custom_css') != ""){
48
  echo '<style type="text/css" media="screen">.simple-banner{'. get_option('simple_banner_custom_css') . "};</style>";
49
  }
50
+
51
+ if (get_option('site_custom_css') != "" && get_option('pro_version_enabled')) {
52
+ echo '<style type="text/css" media="screen">'. get_option('site_custom_css') . "</style>";
53
+ }
54
+
55
+ if (get_option('site_custom_js') != "" && get_option('pro_version_enabled')) {
56
+ echo '<script type="text/javascript">'. get_option('site_custom_js') . "</script>";
57
+ }
58
  }
59
 
60
  //add custom banner text
62
  function simple_banner_custom_text()
63
  {
64
  if (get_option('simple_banner_text') != ""){
65
+ if (!get_option('pro_version_enabled') || (get_option('pro_version_enabled') && !in_array(get_the_ID(), explode(",", get_option('disabled_pages_array'))))){
66
+ echo '<script type="text/javascript">jQuery(document).ready(function() {
67
+ var bannerSpan = document.getElementById("simple-banner");
68
+ bannerSpan.innerHTML = "<div class=' . "simple-banner-text" . '><span>' . addslashes( get_option('simple_banner_text') ) . '</span></div>"
69
+ });
70
+ </script>';
71
+ }
72
  }
73
  }
74
 
84
  register_setting( 'simple-banner-settings-group', 'simple_banner_link_color' );
85
  register_setting( 'simple-banner-settings-group', 'simple_banner_text' );
86
  register_setting( 'simple-banner-settings-group', 'simple_banner_custom_css' );
87
+ register_setting( 'simple-banner-settings-group', 'pro_version_activation_code' );
88
+ register_setting( 'simple-banner-settings-group', 'pro_version_enabled' );
89
+ register_setting( 'simple-banner-settings-group', 'disabled_pages_array' );
90
+ register_setting( 'simple-banner-settings-group', 'site_custom_css' );
91
+ register_setting( 'simple-banner-settings-group', 'site_custom_js' );
92
  }
93
 
94
  function simple_banner_settings_page() {
95
  ?>
96
+ <?php
97
+ if (esc_attr( get_option('pro_version_activation_code') ) == "SBPROv1-14315") {
98
+ update_option('pro_version_enabled', true);
99
+ } else {
100
+ update_option('pro_version_enabled', false);
101
+ }
102
+ ?>
103
 
104
  <div class="wrap">
105
+ <a class="button button-secondary button-hero" style="font-weight: 700;" href="https://www.paypal.me/rpetersenDev" target="_blank">DONATE</a>
106
  <h2>Simple Banner Settings</h2>
107
  <p>Use Hex color values for the color fields.</p>
108
  <p>Links in the banner text must be typed in with HTML <code>&lt;a&gt;</code> tags.
129
  <input type="text" id="simple_banner_color" name="simple_banner_color" placeholder="Hex value"
130
  value="<?php echo esc_attr( get_option('simple_banner_color') ); ?>" />
131
  <input style="height: 30px;width: 100px;" type="color" id="simple_banner_color_show"
132
+ value="<?php echo ((get_option('simple_banner_color') == '') ? '#024985' : esc_attr( get_option('simple_banner_color') )); ?>">
 
133
  </td>
134
  </tr>
135
  <!-- Text Color -->
139
  <input type="text" id="simple_banner_text_color" name="simple_banner_text_color" placeholder="Hex value"
140
  value="<?php echo esc_attr( get_option('simple_banner_text_color') ); ?>" />
141
  <input style="height: 30px;width: 100px;" type="color" id="simple_banner_text_color_show"
142
+ value="<?php echo ((get_option('simple_banner_text_color') == '') ? '#ffffff' : esc_attr( get_option('simple_banner_text_color') )); ?>">
 
143
  </td>
144
  </tr>
145
  <!-- Link Color-->
149
  <input type="text" id="simple_banner_link_color" name="simple_banner_link_color" placeholder="Hex value"
150
  value="<?php echo esc_attr( get_option('simple_banner_link_color') ); ?>" />
151
  <input style="height: 30px;width: 100px;" type="color" id="simple_banner_link_color_show"
152
+ value="<?php echo ((get_option('simple_banner_link_color') == '') ? '#f16521' : esc_attr( get_option('simple_banner_link_color') )); ?>">
 
153
  </td>
154
  </tr>
155
  <!-- Text Contents -->
178
  </table>
179
 
180
  <!-- Pro Features -->
181
+ <div style="padding: 0 10px;border: 1px solid #24282e;border-radius: 10px;background-color: #fafafa;">
182
+ <h2>Pro Features
183
+ <?php
184
+ if (!get_option('pro_version_enabled')) {
185
+ echo '<a class="button-primary" href="https://plasso.com/s/vZGWHecoeB-simple-banner" target="_blank">Purchase Pro Version</a>';
186
+ }
187
+ ?>
188
+ </h2>
 
 
189
 
190
+ <table class="form-table">
191
+ <!-- Activation Code -->
192
+ <tr valign="top" style="<?php if (get_option('pro_version_enabled')) { echo 'display: none;'; } ?>">
193
+ <th scope="row">
194
+ Activation Code
195
+ </th>
196
+ <td>
197
+ <input type="text" style="border: 2px solid gold;border-radius: 5px;" id="pro_version_activation_code" name="pro_version_activation_code" value="<?php echo get_option('pro_version_activation_code'); ?>" />
198
+ </td>
199
+ </tr>
200
+ <!-- Disabled Pages -->
201
+ <tr valign="top">
202
+ <th scope="row">
203
+ Disabled Pages
204
+ <br><span style="font-weight:400;">Disable Simple Banner on the following pages.</span>
205
+ </th>
206
+ <td>
207
+ <div id="simple_banner_pro_disabled_pages">
208
+ <?php
209
+ $pages = get_pages();
210
+ $disabled = !get_option('pro_version_enabled');
211
+ $disabled_pages_array = get_option('disabled_pages_array');
212
+ $parent_checkbox = '<input type="checkbox" ';
213
+ $parent_checkbox .= $disabled ? 'disabled ' : '';
214
+ $parent_checkbox .= (!$disabled && in_array(1, explode(",", $disabled_pages_array))) ? 'checked ' : '';
215
+ $parent_checkbox .= 'value="1">';
216
+ $parent_checkbox .= get_option( 'blogname' ) . ' | ' . get_site_url() . ' ';
217
+ $parent_checkbox .= '</input><br>';
218
+ echo $parent_checkbox;
219
+ foreach ( $pages as $page ) {
220
+ $checkbox = '<input type="checkbox"';
221
+ $checkbox .= $disabled ? 'disabled ' : '';
222
+ $checkbox .= (!$disabled && in_array($page->ID, explode(",", $disabled_pages_array))) ? 'checked ' : '';
223
+ $checkbox .= 'value="' . $page->ID . '">';
224
+ $checkbox .= $page->post_title . ' | ' . get_page_link( $page->ID ) . ' ';
225
+ $checkbox .= '</input><br>';
226
+ echo $checkbox;
227
+ }
228
+ ?>
229
+ </div>
230
+ <?php
231
+ if (get_option('pro_version_enabled')) {
232
+ echo '<input type="text" hidden id="disabled_pages_array" name="disabled_pages_array" value="'. get_option('disabled_pages_array') . '" />';
233
+ }
234
+ ?>
235
+ </td>
236
+ </tr>
237
+ <!-- Website Custom CSS -->
238
+ <tr valign="top">
239
+ <th scope="row">
240
+ Website Custom CSS
241
+ <br><span style="font-weight:400;">CSS will be applied to the entire website</span>
242
+ </th>
243
+ <td>
244
+ <?php
245
+ if (get_option('pro_version_enabled')) {
246
+ echo '<textarea id="site_custom_css" style="height: 150px;width: 75%;" name="site_custom_css">'. get_option('site_custom_css') . '</textarea>';
247
+ } else {
248
+ echo '<textarea style="height: 150px;width: 75%;" disabled></textarea>';
249
+ }
250
+ ?>
251
+ </td>
252
+ </tr>
253
+ <!-- Website Custom JS -->
254
+ <tr valign="top">
255
+ <th scope="row">
256
+ Website Custom JS
257
+ <br><span style="font-weight:400;">JavaScript will be applied to the entire website</span>
258
+ </th>
259
+ <td>
260
+ <?php
261
+ if (get_option('pro_version_enabled')) {
262
+ echo '<textarea id="site_custom_js" style="height: 150px;width: 75%;" name="site_custom_js">'. get_option('site_custom_js') . '</textarea>';
263
+ } else {
264
+ echo '<textarea style="height: 150px;width: 75%;" disabled></textarea>';
265
+ }
266
+ ?>
267
+ </td>
268
+ </tr>
269
+ </table>
270
+ </div>
271
 
272
  <!-- Save Changes Button -->
273
  <?php submit_button(); ?>
308
  );
309
  document.getElementsByTagName('head')[0].appendChild(style_dynamic);
310
  };
311
+ document.getElementById('simple_banner_color_show').onchange=function(e){
312
+ document.getElementById('simple_banner_color').value = e.target.value;
313
+ document.getElementById('simple_banner_color').dispatchEvent(new Event('change'));
314
+ };
315
 
316
  // Text Color
317
  style_text_color.type = 'text/css';
334
  );
335
  document.getElementsByTagName('head')[0].appendChild(style_dynamic);
336
  };
337
+ document.getElementById('simple_banner_text_color_show').onchange=function(e){
338
+ document.getElementById('simple_banner_text_color').value = e.target.value;
339
+ document.getElementById('simple_banner_text_color').dispatchEvent(new Event('change'));
340
+ };
341
 
342
  // Link Color
343
  style_link_color.type = 'text/css';
360
  );
361
  document.getElementsByTagName('head')[0].appendChild(style_dynamic);
362
  };
363
+ document.getElementById('simple_banner_link_color_show').onchange=function(e){
364
+ document.getElementById('simple_banner_link_color').value = e.target.value;
365
+ document.getElementById('simple_banner_link_color').dispatchEvent(new Event('change'));
366
+ };
367
 
368
+ // Custom CSS
369
  style_custom_css.type = 'text/css';
370
  style_custom_css.id = 'preview_banner_custom_stylesheet'
371
  style_custom_css.appendChild(document.createTextNode('.simple-banner{'+document.getElementById('simple_banner_custom_css').value+'}'));
385
  );
386
  document.getElementsByTagName('head')[0].appendChild(style_dynamic);
387
  };
388
+
389
+ // Disabled Pages
390
+ document.getElementById('simple_banner_pro_disabled_pages').onclick=function(e){
391
+ let disabledPagesArray = [];
392
+ Array.from(document.getElementById('simple_banner_pro_disabled_pages').getElementsByTagName('input')).forEach(function(e) {
393
+ if (e.checked) {
394
+ disabledPagesArray.push(e.value);
395
+ }
396
+ });
397
+ document.getElementById('disabled_pages_array').value = disabledPagesArray;
398
+ };
399
  </script>
400
  <?php
401
  }