Simple Banner - Version 2.0.0

Version Description

  • Added Pro version features.
Download this release

Release Info

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

Code changes from version 1.4.1 to 2.0.0

Files changed (4) hide show
  1. readme.txt +9 -3
  2. simple-banner-pro.js +6 -0
  3. simple-banner.js +11 -11
  4. simple-banner.php +155 -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,9 @@ 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 +86,9 @@ 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.0
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.0 =
49
+ * Added Pro version features.
50
+
51
  = 1.4.1 =
52
  * Fix bugs with preview banner onchange events and escape attributes with Simple Banner Text instead of converting to html codes.
53
 
86
 
87
  == Upgrade Notice ==
88
 
89
+ = 2.0.0 =
90
+ Added Pro version features.
91
+
92
  = 1.4.1 =
93
  Fix preview banner bugs, Simple Banner can accept all formats.
94
 
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,24 +3,23 @@
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
 
@@ -50,11 +49,28 @@ 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 +86,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 +131,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 +141,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 +151,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 +180,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 +310,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 +336,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 +362,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 +387,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.0
7
  * Author: Ryan Petersen
8
  * Author URI: http://rpetersen29.github.io/
9
  * License: GPL2
10
  *
11
  * @package Simple Banner
12
+ * @version 2.0.0
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
 
49
  function simple_banner_custom_text()
50
  {
51
  if (get_option('simple_banner_text') != ""){
52
+ if (!get_option('pro_version_enabled') || (get_option('pro_version_enabled') && !in_array(get_the_ID(), explode(",", get_option('disabled_pages_array'))))){
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
+ }
61
+
62
+ //add Pro version CSS and JS
63
+ add_action( 'wp_head', 'simple_banner_pro');
64
+ function simple_banner_pro()
65
+ {
66
+ if (get_option('site_custom_css') != "" && get_option('pro_version_enabled')) {
67
+ echo '<style type="text/css" media="screen">'. get_option('site_custom_css') . "</style>";
68
+ }
69
+
70
+ if (get_option('site_custom_js') != "" && get_option('pro_version_enabled')) {
71
+ echo '<script type="text/javascript">'. get_option('site_custom_js') . "</script>";
72
+ wp_register_script('simple-banner-pro-script', plugin_dir_url( __FILE__ ) . 'simple-banner-pro.js');
73
+ wp_enqueue_script('simple-banner-pro-script');
74
  }
75
  }
76
 
86
  register_setting( 'simple-banner-settings-group', 'simple_banner_link_color' );
87
  register_setting( 'simple-banner-settings-group', 'simple_banner_text' );
88
  register_setting( 'simple-banner-settings-group', 'simple_banner_custom_css' );
89
+ register_setting( 'simple-banner-settings-group', 'pro_version_activation_code' );
90
+ register_setting( 'simple-banner-settings-group', 'pro_version_enabled' );
91
+ register_setting( 'simple-banner-settings-group', 'disabled_pages_array' );
92
+ register_setting( 'simple-banner-settings-group', 'site_custom_css' );
93
+ register_setting( 'simple-banner-settings-group', 'site_custom_js' );
94
  }
95
 
96
  function simple_banner_settings_page() {
97
  ?>
98
+ <?php
99
+ if (esc_attr( get_option('pro_version_activation_code') ) == "SBPROv1-14315") {
100
+ update_option('pro_version_enabled', true);
101
+ } else {
102
+ update_option('pro_version_enabled', false);
103
+ }
104
+ ?>
105
 
106
  <div class="wrap">
107
+ <a class="button button-secondary button-hero" style="font-weight: 700;" href="https://www.paypal.me/rpetersenDev" target="_blank">DONATE</a>
108
  <h2>Simple Banner Settings</h2>
109
  <p>Use Hex color values for the color fields.</p>
110
  <p>Links in the banner text must be typed in with HTML <code>&lt;a&gt;</code> tags.
131
  <input type="text" id="simple_banner_color" name="simple_banner_color" placeholder="Hex value"
132
  value="<?php echo esc_attr( get_option('simple_banner_color') ); ?>" />
133
  <input style="height: 30px;width: 100px;" type="color" id="simple_banner_color_show"
134
+ value="<?php echo ((get_option('simple_banner_color') == '') ? '#024985' : esc_attr( get_option('simple_banner_color') )); ?>">
 
135
  </td>
136
  </tr>
137
  <!-- Text Color -->
141
  <input type="text" id="simple_banner_text_color" name="simple_banner_text_color" placeholder="Hex value"
142
  value="<?php echo esc_attr( get_option('simple_banner_text_color') ); ?>" />
143
  <input style="height: 30px;width: 100px;" type="color" id="simple_banner_text_color_show"
144
+ value="<?php echo ((get_option('simple_banner_text_color') == '') ? '#ffffff' : esc_attr( get_option('simple_banner_text_color') )); ?>">
 
145
  </td>
146
  </tr>
147
  <!-- Link Color-->
151
  <input type="text" id="simple_banner_link_color" name="simple_banner_link_color" placeholder="Hex value"
152
  value="<?php echo esc_attr( get_option('simple_banner_link_color') ); ?>" />
153
  <input style="height: 30px;width: 100px;" type="color" id="simple_banner_link_color_show"
154
+ value="<?php echo ((get_option('simple_banner_link_color') == '') ? '#f16521' : esc_attr( get_option('simple_banner_link_color') )); ?>">
 
155
  </td>
156
  </tr>
157
  <!-- Text Contents -->
180
  </table>
181
 
182
  <!-- Pro Features -->
183
+ <div style="padding: 0 10px;border: 1px solid #24282e;border-radius: 10px;background-color: #fafafa;">
184
+ <h2>Pro Features
185
+ <?php
186
+ if (!get_option('pro_version_enabled')) {
187
+ echo '<a class="button-primary" href="https://plasso.com/s/vZGWHecoeB-simple-banner" target="_blank">Purchase Pro Version</a>';
188
+ }
189
+ ?>
190
+ </h2>
 
 
191
 
192
+ <table class="form-table">
193
+ <!-- Activation Code -->
194
+ <tr valign="top" style="<?php if (get_option('pro_version_enabled')) { echo 'display: none;'; } ?>">
195
+ <th scope="row">
196
+ Activation Code
197
+ </th>
198
+ <td>
199
+ <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'); ?>" />
200
+ </td>
201
+ </tr>
202
+ <!-- Disabled Pages -->
203
+ <tr valign="top">
204
+ <th scope="row">
205
+ Disabled Pages
206
+ <br><span style="font-weight:400;">Disable Simple Banner on the following pages.</span>
207
+ </th>
208
+ <td>
209
+ <div id="simple_banner_pro_disabled_pages">
210
+ <?php
211
+ $pages = get_pages();
212
+ $disabled = !get_option('pro_version_enabled');
213
+ $disabled_pages_array = get_option('disabled_pages_array');
214
+ $parent_checkbox = '<input type="checkbox" ';
215
+ $parent_checkbox .= $disabled ? 'disabled ' : '';
216
+ $parent_checkbox .= (!$disabled && in_array(1, explode(",", $disabled_pages_array))) ? 'checked ' : '';
217
+ $parent_checkbox .= 'value="1">';
218
+ $parent_checkbox .= get_option( 'blogname' ) . ' | ' . get_site_url() . ' ';
219
+ $parent_checkbox .= '</input><br>';
220
+ echo $parent_checkbox;
221
+ foreach ( $pages as $page ) {
222
+ $checkbox = '<input type="checkbox"';
223
+ $checkbox .= $disabled ? 'disabled ' : '';
224
+ $checkbox .= (!$disabled && in_array($page->ID, explode(",", $disabled_pages_array))) ? 'checked ' : '';
225
+ $checkbox .= 'value="' . $page->ID . '">';
226
+ $checkbox .= $page->post_title . ' | ' . get_page_link( $page->ID ) . ' ';
227
+ $checkbox .= '</input><br>';
228
+ echo $checkbox;
229
+ }
230
+ ?>
231
+ </div>
232
+ <?php
233
+ if (get_option('pro_version_enabled')) {
234
+ echo '<input type="text" hidden id="disabled_pages_array" name="disabled_pages_array" value="'. get_option('disabled_pages_array') . '" />';
235
+ }
236
+ ?>
237
+ </td>
238
+ </tr>
239
+ <!-- Website Custom CSS -->
240
+ <tr valign="top">
241
+ <th scope="row">
242
+ Website Custom CSS
243
+ <br><span style="font-weight:400;">CSS will be applied to the entire website</span>
244
+ </th>
245
+ <td>
246
+ <?php
247
+ if (get_option('pro_version_enabled')) {
248
+ echo '<textarea id="site_custom_css" style="height: 150px;width: 75%;" name="site_custom_css">'. get_option('site_custom_css') . '</textarea>';
249
+ } else {
250
+ echo '<textarea style="height: 150px;width: 75%;" disabled></textarea>';
251
+ }
252
+ ?>
253
+ </td>
254
+ </tr>
255
+ <!-- Website Custom JS -->
256
+ <tr valign="top">
257
+ <th scope="row">
258
+ Website Custom JS
259
+ <br><span style="font-weight:400;">JavaScript will be applied to the entire website</span>
260
+ </th>
261
+ <td>
262
+ <?php
263
+ if (get_option('pro_version_enabled')) {
264
+ echo '<textarea id="site_custom_js" style="height: 150px;width: 75%;" name="site_custom_js">'. get_option('site_custom_js') . '</textarea>';
265
+ } else {
266
+ echo '<textarea style="height: 150px;width: 75%;" disabled></textarea>';
267
+ }
268
+ ?>
269
+ </td>
270
+ </tr>
271
+ </table>
272
+ </div>
273
 
274
  <!-- Save Changes Button -->
275
  <?php submit_button(); ?>
310
  );
311
  document.getElementsByTagName('head')[0].appendChild(style_dynamic);
312
  };
313
+ document.getElementById('simple_banner_color_show').onchange=function(e){
314
+ document.getElementById('simple_banner_color').value = e.target.value;
315
+ document.getElementById('simple_banner_color').dispatchEvent(new Event('change'));
316
+ };
317
 
318
  // Text Color
319
  style_text_color.type = 'text/css';
336
  );
337
  document.getElementsByTagName('head')[0].appendChild(style_dynamic);
338
  };
339
+ document.getElementById('simple_banner_text_color_show').onchange=function(e){
340
+ document.getElementById('simple_banner_text_color').value = e.target.value;
341
+ document.getElementById('simple_banner_text_color').dispatchEvent(new Event('change'));
342
+ };
343
 
344
  // Link Color
345
  style_link_color.type = 'text/css';
362
  );
363
  document.getElementsByTagName('head')[0].appendChild(style_dynamic);
364
  };
365
+ document.getElementById('simple_banner_link_color_show').onchange=function(e){
366
+ document.getElementById('simple_banner_link_color').value = e.target.value;
367
+ document.getElementById('simple_banner_link_color').dispatchEvent(new Event('change'));
368
+ };
369
 
370
+ // Custom CSS
371
  style_custom_css.type = 'text/css';
372
  style_custom_css.id = 'preview_banner_custom_stylesheet'
373
  style_custom_css.appendChild(document.createTextNode('.simple-banner{'+document.getElementById('simple_banner_custom_css').value+'}'));
387
  );
388
  document.getElementsByTagName('head')[0].appendChild(style_dynamic);
389
  };
390
+
391
+ // Disabled Pages
392
+ document.getElementById('simple_banner_pro_disabled_pages').onclick=function(e){
393
+ let disabledPagesArray = [];
394
+ Array.from(document.getElementById('simple_banner_pro_disabled_pages').getElementsByTagName('input')).forEach(function(e) {
395
+ if (e.checked) {
396
+ disabledPagesArray.push(e.value);
397
+ }
398
+ });
399
+ document.getElementById('disabled_pages_array').value = disabledPagesArray;
400
+ };
401
  </script>
402
  <?php
403
  }