Simple Banner - Version 2.2.0

Version Description

  • Optimized scripts for loading banner, added debug mode for troubleshooting.
Download this release

Release Info

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

Code changes from version 2.1.3 to 2.2.0

Files changed (5) hide show
  1. readme.txt +8 -2
  2. simple-banner-pro.js +0 -7
  3. simple-banner.css +3 -3
  4. simple-banner.js +19 -9
  5. simple-banner.php +59 -41
readme.txt CHANGED
@@ -3,8 +3,8 @@ 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: 5.2.3
7
- Stable tag: 2.1.3
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
  = 2.1.3 =
49
  * Change pro version payment link again.
50
 
@@ -119,6 +122,9 @@ Yes.
119
 
120
  == Upgrade Notice ==
121
 
 
 
 
122
  = 2.1.2 =
123
  Changed pro version payment link again.
124
 
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: 5.3.2
7
+ Stable tag: 2.2.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.2.0 =
49
+ * Optimized scripts for loading banner, added debug mode for troubleshooting.
50
+
51
  = 2.1.3 =
52
  * Change pro version payment link again.
53
 
122
 
123
  == Upgrade Notice ==
124
 
125
+ = 2.2.0 =
126
+ Optimized scripts for loading banner, added debug mode for troubleshooting.
127
+
128
  = 2.1.2 =
129
  Changed pro version payment link again.
130
 
simple-banner-pro.js DELETED
@@ -1,7 +0,0 @@
1
- // v2.1.3
2
- if (!window.location.hostname.includes("localhost")) {
3
- var xhr = new XMLHttpRequest();
4
- xhr.open("POST", "https://simple-banner.glitch.me/hostname", true);
5
- xhr.setRequestHeader('Content-Type', 'application/json');
6
- xhr.send(JSON.stringify({ hostname: window.location.hostname }));
7
- }
 
 
 
 
 
 
 
simple-banner.css CHANGED
@@ -2,16 +2,16 @@
2
  width: 100%;
3
  background: #024985;
4
  text-align: center;
5
- z-index: 200000;
6
  position: relative;
7
- display: block;
8
  }
9
 
10
  .simple-banner .simple-banner-text {
11
  color: #ffffff;
12
  font-size: 1.1em;
13
  font-weight: 700;
14
- padding: 10px;
15
  }
16
 
17
  .simple-banner .simple-banner-text a {
2
  width: 100%;
3
  background: #024985;
4
  text-align: center;
5
+ z-index: 99999;
6
  position: relative;
7
+ display: block;
8
  }
9
 
10
  .simple-banner .simple-banner-text {
11
  color: #ffffff;
12
  font-size: 1.1em;
13
  font-weight: 700;
14
+ padding: 10px;
15
  }
16
 
17
  .simple-banner .simple-banner-text a {
simple-banner.js CHANGED
@@ -1,14 +1,24 @@
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
+ if (scriptParams.simple_banner_text != "") {
3
+ if (!scriptParams.pro_version_enabled || (scriptParams.pro_version_enabled && !scriptParams.in_array)) {
4
+ $('<div id="simple-banner" class="simple-banner"><div class="simple-banner-text"><span>' + scriptParams.addslashes_simple_banner_text + '</span></div></div>')
5
+ .prependTo('body');
6
 
7
+ var bodyPaddingLeft = $('body').css('padding-left')
8
+ var bodyPaddingRight = $('body').css('padding-right')
9
 
10
+ if (bodyPaddingLeft != "0px") {
11
+ $('head').append('<style type="text/css" media="screen">.simple-banner{margin-left:-' + bodyPaddingLeft + ';padding-left:' + bodyPaddingLeft + ';}</style>');
12
+ }
13
+ if (bodyPaddingRight != "0px") {
14
+ $('head').append('<style type="text/css" media="screen">.simple-banner{margin-right:-' + bodyPaddingRight + ';padding-right:' + bodyPaddingRight + ';}</style>');
15
+ }
16
+ }
17
  }
18
+
19
+ // Debug Mode
20
+ // Console log all variables
21
+ if (scriptParams.pro_version_enabled && scriptParams.debug_mode) {
22
+ console.log(scriptParams);
23
  }
24
  });
simple-banner.php CHANGED
@@ -3,34 +3,49 @@
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.1.3
7
  * Author: Ryan Petersen
8
  * Author URI: http://rpetersen29.github.io/
9
  * License: GPL2
10
  *
11
  * @package Simple Banner
12
- * @version 2.1.3
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
32
  add_action( 'wp_head', 'simple_banner_custom_color');
33
- function simple_banner_custom_color()
34
  {
35
  if (get_option('simple_banner_color') != ""){
36
  echo '<style type="text/css" media="screen">.simple-banner{background:' . get_option('simple_banner_color') . "};</style>";
@@ -57,21 +72,6 @@ function simple_banner_custom_color()
57
  }
58
  }
59
 
60
- //add custom banner text
61
- add_action( 'wp_head', 'simple_banner_custom_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
-
75
  add_action('admin_menu', 'simple_banner_menu');
76
  function simple_banner_menu() {
77
  add_menu_page('Simple Banner Settings', 'Simple Banner', 'administrator', 'simple-banner-settings', 'simple_banner_settings_page', 'dashicons-admin-generic');
@@ -89,11 +89,12 @@ function simple_banner_settings() {
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 {
@@ -106,10 +107,10 @@ function simple_banner_settings_page() {
106
  <h2>Simple Banner Settings</h2>
107
  <a class="button button-primary button-hero" style="font-weight: 700;" href="https://www.paypal.me/rpetersenDev" target="_blank">DONATE</a>
108
  </div>
109
-
110
-
111
  <p>Use Hex color values for the color fields.</p>
112
- <p>Links in the banner text must be typed in with HTML <code>&lt;a&gt;</code> tags.
113
  <br />e.g. <code>This is a &lt;a href=&#34;http:&#47;&#47;www.wordpress.com&#34;&gt;Link to Wordpress&lt;&#47;a&gt;</code>.</p>
114
 
115
  <!-- Preview Banner -->
@@ -130,9 +131,9 @@ function simple_banner_settings_page() {
130
  <tr valign="top">
131
  <th scope="row">Simple Banner Background Color<br><span style="font-weight:400;">(Leaving this blank sets the color to the default value #024985)</span></th>
132
  <td style="vertical-align:top;">
133
- <input type="text" id="simple_banner_color" name="simple_banner_color" placeholder="Hex value"
134
  value="<?php echo esc_attr( get_option('simple_banner_color') ); ?>" />
135
- <input style="height: 30px;width: 100px;" type="color" id="simple_banner_color_show"
136
  value="<?php echo ((get_option('simple_banner_color') == '') ? '#024985' : esc_attr( get_option('simple_banner_color') )); ?>">
137
  </td>
138
  </tr>
@@ -140,9 +141,9 @@ function simple_banner_settings_page() {
140
  <tr valign="top">
141
  <th scope="row">Simple Banner Text Color<br><span style="font-weight:400;">(Leaving this blank sets the color to the default value white)</span></th>
142
  <td style="vertical-align:top;">
143
- <input type="text" id="simple_banner_text_color" name="simple_banner_text_color" placeholder="Hex value"
144
  value="<?php echo esc_attr( get_option('simple_banner_text_color') ); ?>" />
145
- <input style="height: 30px;width: 100px;" type="color" id="simple_banner_text_color_show"
146
  value="<?php echo ((get_option('simple_banner_text_color') == '') ? '#ffffff' : esc_attr( get_option('simple_banner_text_color') )); ?>">
147
  </td>
148
  </tr>
@@ -150,9 +151,9 @@ function simple_banner_settings_page() {
150
  <tr valign="top">
151
  <th scope="row">Simple Banner Link Color<br><span style="font-weight:400;">(Leaving this blank sets the color to the default value #f16521)</span></th>
152
  <td style="vertical-align:top;">
153
- <input type="text" id="simple_banner_link_color" name="simple_banner_link_color" placeholder="Hex value"
154
  value="<?php echo esc_attr( get_option('simple_banner_link_color') ); ?>" />
155
- <input style="height: 30px;width: 100px;" type="color" id="simple_banner_link_color_show"
156
  value="<?php echo ((get_option('simple_banner_link_color') == '') ? '#f16521' : esc_attr( get_option('simple_banner_link_color') )); ?>">
157
  </td>
158
  </tr>
@@ -183,8 +184,8 @@ function simple_banner_settings_page() {
183
 
184
  <!-- Pro Features -->
185
  <div style="padding: 0 10px;border: 1px solid #24282e;border-radius: 10px;background-color: #fafafa;">
186
- <h2>Pro Features
187
- <?php
188
  if (!get_option('pro_version_enabled')) {
189
  echo '<a class="button-primary" href="https://simple-banner.square.site/" target="_blank">Purchase Pro Version</a>';
190
  }
@@ -209,7 +210,7 @@ function simple_banner_settings_page() {
209
  </th>
210
  <td>
211
  <div id="simple_banner_pro_disabled_pages">
212
- <?php
213
  $pages = get_pages();
214
  $disabled = !get_option('pro_version_enabled');
215
  $disabled_pages_array = get_option('disabled_pages_array');
@@ -231,7 +232,7 @@ function simple_banner_settings_page() {
231
  }
232
  ?>
233
  </div>
234
- <?php
235
  if (get_option('pro_version_enabled')) {
236
  echo '<input type="text" hidden id="disabled_pages_array" name="disabled_pages_array" value="'. get_option('disabled_pages_array') . '" />';
237
  }
@@ -245,7 +246,7 @@ function simple_banner_settings_page() {
245
  <br><span style="font-weight:400;">CSS will be applied to the entire website</span>
246
  </th>
247
  <td>
248
- <?php
249
  if (get_option('pro_version_enabled')) {
250
  echo '<textarea id="site_custom_css" style="height: 150px;width: 75%;" name="site_custom_css">'. get_option('site_custom_css') . '</textarea>';
251
  } else {
@@ -261,7 +262,7 @@ function simple_banner_settings_page() {
261
  <br><span style="font-weight:400;">JavaScript will be applied to the entire website</span>
262
  </th>
263
  <td>
264
- <?php
265
  if (get_option('pro_version_enabled')) {
266
  echo '<textarea id="site_custom_js" style="height: 150px;width: 75%;" name="site_custom_js">'. get_option('site_custom_js') . '</textarea>';
267
  } else {
@@ -270,6 +271,23 @@ function simple_banner_settings_page() {
270
  ?>
271
  </td>
272
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
  </table>
274
  </div>
275
 
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.2.0
7
  * Author: Ryan Petersen
8
  * Author URI: http://rpetersen29.github.io/
9
  * License: GPL2
10
  *
11
  * @package Simple Banner
12
+ * @version 2.2.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
+ // Set Script parameters
22
+ $script_params = array(
23
+ // script specific parameters
24
+ 'simple_banner_text' => get_option('simple_banner_text'),
25
+ 'addslashes_simple_banner_text' => addslashes( get_option('simple_banner_text') ),
26
+ 'pro_version_enabled' => get_option('pro_version_enabled'),
27
+ 'in_array' => in_array(get_the_ID(), explode(",", get_option('disabled_pages_array'))),
28
+ // debug specific parameters
29
+ 'debug_mode' => get_option('debug_mode'),
30
+ 'id' => get_the_ID(),
31
+ 'disabled_pages_array' => explode(",", get_option('disabled_pages_array')),
32
+ 'simple_banner_color' => get_option('simple_banner_color'),
33
+ 'simple_banner_text_color' => get_option('simple_banner_text_color'),
34
+ 'simple_banner_link_color' => get_option('simple_banner_link_color'),
35
+ 'simple_banner_text' => get_option('simple_banner_text'),
36
+ 'simple_banner_custom_css' => get_option('simple_banner_custom_css'),
37
+ 'site_custom_css' => get_option('site_custom_css'),
38
+ 'site_custom_js' => get_option('site_custom_js')
39
+ );
40
+ // Enqueue the script
41
  wp_register_script('simple-banner-script', plugin_dir_url( __FILE__ ) . 'simple-banner.js', array( 'jquery' ));
42
+ wp_localize_script('simple-banner-script', 'scriptParams', $script_params);
43
  wp_enqueue_script('simple-banner-script');
 
 
 
 
 
44
  }
45
 
46
  //add custom CSS colors
47
  add_action( 'wp_head', 'simple_banner_custom_color');
48
+ function simple_banner_custom_color()
49
  {
50
  if (get_option('simple_banner_color') != ""){
51
  echo '<style type="text/css" media="screen">.simple-banner{background:' . get_option('simple_banner_color') . "};</style>";
72
  }
73
  }
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  add_action('admin_menu', 'simple_banner_menu');
76
  function simple_banner_menu() {
77
  add_menu_page('Simple Banner Settings', 'Simple Banner', 'administrator', 'simple-banner-settings', 'simple_banner_settings_page', 'dashicons-admin-generic');
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
+ register_setting( 'simple-banner-settings-group', 'debug_mode' );
93
  }
94
 
95
  function simple_banner_settings_page() {
96
  ?>
97
+ <?php
98
  if (esc_attr( get_option('pro_version_activation_code') ) == "SBPROv1-14315") {
99
  update_option('pro_version_enabled', true);
100
  } else {
107
  <h2>Simple Banner Settings</h2>
108
  <a class="button button-primary button-hero" style="font-weight: 700;" href="https://www.paypal.me/rpetersenDev" target="_blank">DONATE</a>
109
  </div>
110
+
111
+
112
  <p>Use Hex color values for the color fields.</p>
113
+ <p>Links in the banner text must be typed in with HTML <code>&lt;a&gt;</code> tags.
114
  <br />e.g. <code>This is a &lt;a href=&#34;http:&#47;&#47;www.wordpress.com&#34;&gt;Link to Wordpress&lt;&#47;a&gt;</code>.</p>
115
 
116
  <!-- Preview Banner -->
131
  <tr valign="top">
132
  <th scope="row">Simple Banner Background Color<br><span style="font-weight:400;">(Leaving this blank sets the color to the default value #024985)</span></th>
133
  <td style="vertical-align:top;">
134
+ <input type="text" id="simple_banner_color" name="simple_banner_color" placeholder="Hex value"
135
  value="<?php echo esc_attr( get_option('simple_banner_color') ); ?>" />
136
+ <input style="height: 30px;width: 100px;" type="color" id="simple_banner_color_show"
137
  value="<?php echo ((get_option('simple_banner_color') == '') ? '#024985' : esc_attr( get_option('simple_banner_color') )); ?>">
138
  </td>
139
  </tr>
141
  <tr valign="top">
142
  <th scope="row">Simple Banner Text Color<br><span style="font-weight:400;">(Leaving this blank sets the color to the default value white)</span></th>
143
  <td style="vertical-align:top;">
144
+ <input type="text" id="simple_banner_text_color" name="simple_banner_text_color" placeholder="Hex value"
145
  value="<?php echo esc_attr( get_option('simple_banner_text_color') ); ?>" />
146
+ <input style="height: 30px;width: 100px;" type="color" id="simple_banner_text_color_show"
147
  value="<?php echo ((get_option('simple_banner_text_color') == '') ? '#ffffff' : esc_attr( get_option('simple_banner_text_color') )); ?>">
148
  </td>
149
  </tr>
151
  <tr valign="top">
152
  <th scope="row">Simple Banner Link Color<br><span style="font-weight:400;">(Leaving this blank sets the color to the default value #f16521)</span></th>
153
  <td style="vertical-align:top;">
154
+ <input type="text" id="simple_banner_link_color" name="simple_banner_link_color" placeholder="Hex value"
155
  value="<?php echo esc_attr( get_option('simple_banner_link_color') ); ?>" />
156
+ <input style="height: 30px;width: 100px;" type="color" id="simple_banner_link_color_show"
157
  value="<?php echo ((get_option('simple_banner_link_color') == '') ? '#f16521' : esc_attr( get_option('simple_banner_link_color') )); ?>">
158
  </td>
159
  </tr>
184
 
185
  <!-- Pro Features -->
186
  <div style="padding: 0 10px;border: 1px solid #24282e;border-radius: 10px;background-color: #fafafa;">
187
+ <h2>Pro Features
188
+ <?php
189
  if (!get_option('pro_version_enabled')) {
190
  echo '<a class="button-primary" href="https://simple-banner.square.site/" target="_blank">Purchase Pro Version</a>';
191
  }
210
  </th>
211
  <td>
212
  <div id="simple_banner_pro_disabled_pages">
213
+ <?php
214
  $pages = get_pages();
215
  $disabled = !get_option('pro_version_enabled');
216
  $disabled_pages_array = get_option('disabled_pages_array');
232
  }
233
  ?>
234
  </div>
235
+ <?php
236
  if (get_option('pro_version_enabled')) {
237
  echo '<input type="text" hidden id="disabled_pages_array" name="disabled_pages_array" value="'. get_option('disabled_pages_array') . '" />';
238
  }
246
  <br><span style="font-weight:400;">CSS will be applied to the entire website</span>
247
  </th>
248
  <td>
249
+ <?php
250
  if (get_option('pro_version_enabled')) {
251
  echo '<textarea id="site_custom_css" style="height: 150px;width: 75%;" name="site_custom_css">'. get_option('site_custom_css') . '</textarea>';
252
  } else {
262
  <br><span style="font-weight:400;">JavaScript will be applied to the entire website</span>
263
  </th>
264
  <td>
265
+ <?php
266
  if (get_option('pro_version_enabled')) {
267
  echo '<textarea id="site_custom_js" style="height: 150px;width: 75%;" name="site_custom_js">'. get_option('site_custom_js') . '</textarea>';
268
  } else {
271
  ?>
272
  </td>
273
  </tr>
274
+ <!-- Debug Mode -->
275
+ <tr valign="top">
276
+ <th scope="row">
277
+ Debug Mode
278
+ <br><span style="font-weight:400;">If enabled, will log all variables in the console of your browser</span>
279
+ </th>
280
+ <td>
281
+ <?php
282
+ if (get_option('pro_version_enabled')) {
283
+ $checked = get_option('debug_mode') ? 'checked ' : '';
284
+ echo '<input type="checkbox" id="debug_mode" '. $checked . ' name="debug_mode" />';
285
+ } else {
286
+ echo '<input type="checkbox" disabled />';
287
+ }
288
+ ?>
289
+ </td>
290
+ </tr>
291
  </table>
292
  </div>
293