Simple Banner - Version 2.3.0

Version Description

  • Added permissions adding and updated documentation.
Download this release

Release Info

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

Code changes from version 2.2.3 to 2.3.0

Files changed (2) hide show
  1. readme.txt +48 -6
  2. simple-banner.php +107 -25
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.3.2
7
- Stable tag: 2.2.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -32,17 +32,39 @@ This plugin makes it easy to display a simple announcement banner or bar at the
32
 
33
  == Frequently Asked Questions ==
34
 
35
- = Can I create my own CSS for the banner? =
36
 
37
- Yes.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  = Is there a Pro version? =
40
 
41
- Yes.
42
 
43
  = How do I disable the banner in my posts? =
44
 
45
- This feature is being acitvely developed, in the meantime you can use this custom JavaScript:
46
 
47
  `document.addEventListener('DOMContentLoaded', function(){
48
  if (window.location.pathname.includes("post")){
@@ -51,6 +73,20 @@ This feature is being acitvely developed, in the meantime you can use this custo
51
  }, false);
52
  `
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  == Screenshots ==
55
 
56
  1. This is the first screen shot.
@@ -60,6 +96,9 @@ This feature is being acitvely developed, in the meantime you can use this custo
60
 
61
  == Changelog ==
62
 
 
 
 
63
  = 2.2.3 =
64
  * CSS Changes.
65
 
@@ -146,6 +185,9 @@ This feature is being acitvely developed, in the meantime you can use this custo
146
 
147
  == Upgrade Notice ==
148
 
 
 
 
149
  = 2.2.3 =
150
  * CSS Changes.
151
 
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.4.0
7
+ Stable tag: 2.3.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
32
 
33
  == Frequently Asked Questions ==
34
 
35
+ = What does the banner look like in my DOM? =
36
 
37
+ This is how the banner will look in your HTML:
38
+
39
+ `<code>
40
+ <div id="simple-banner" class="simple-banner">
41
+ <div class="simple-banner-text">
42
+ <span>
43
+ YOUR SIMPLE BANNER TEXT HERE
44
+ </span>
45
+ </div>
46
+ </div>
47
+ </code>
48
+ `
49
+
50
+ = The banner or changes to the banner aren't showing up, what's wrong? =
51
+
52
+ Your browser frequently caches scripts associated with a website in order to improve speed and performance. There are also some
53
+ wordpress plugins that cache scripts to improve performance. If you aren't seeing your banner or the changes you made to the banner,
54
+ first clear your browser cache and if that doesn't work, look for any plugin that bundles or caches scripts and clear that as well.
55
+
56
+ = Why is my banner covering my header or behind my header? =
57
+
58
+ Your theme probably uses absolute positioning for its header in this case. That is fine, but it also means you need a custom solution for your banner.
59
+ You can either try to find another plugin that suits your needs or you can purchase the pro version and open a support ticket to fix your situation.
60
 
61
  = Is there a Pro version? =
62
 
63
+ Yes, but you should look through the support topics before you decide if you need the pro version.
64
 
65
  = How do I disable the banner in my posts? =
66
 
67
+ This feature is being actively developed, in the meantime you can use this custom JavaScript:
68
 
69
  `document.addEventListener('DOMContentLoaded', function(){
70
  if (window.location.pathname.includes("post")){
73
  }, false);
74
  `
75
 
76
+ == Known Bugs ==
77
+
78
+ = Disabling banner on homepage. =
79
+
80
+ Some themes use a page id of 1 for the homepage, other themes make that id dynamic, which is not accounted for currently.
81
+ In the meantime you can use the following custom JavaScript to disable on your homepage:
82
+
83
+ `document.addEventListener('DOMContentLoaded', function(){
84
+ if (window.location.href === "YOUR_WEBSITE_URL_HERE"){
85
+ document.getElementById('simple-banner').remove();
86
+ }
87
+ }, false);
88
+ `
89
+
90
  == Screenshots ==
91
 
92
  1. This is the first screen shot.
96
 
97
  == Changelog ==
98
 
99
+ = 2.3.0 =
100
+ * Added permissions adding and updated documentation.
101
+
102
  = 2.2.3 =
103
  * CSS Changes.
104
 
185
 
186
  == Upgrade Notice ==
187
 
188
+ = 2.3.0 =
189
+ * Added permissions adding and updated documentation.
190
+
191
  = 2.2.3 =
192
  * CSS Changes.
193
 
simple-banner.php CHANGED
@@ -3,43 +3,43 @@
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.3
7
  * Author: Ryan Petersen
8
  * Author URI: http://rpetersen29.github.io/
9
  * License: GPL2
10
  *
11
  * @package Simple Banner
12
- * @version 2.2.3
13
  * @author Ryan Petersen <rpetersen.dev@gmail.com>
14
  */
15
- define ('VERSION', '2.2.3');
16
 
17
  add_action( 'wp_enqueue_scripts', 'simple_banner' );
18
  function simple_banner() {
19
  // Enqueue the style
20
- wp_register_style('simple-banner-style', plugin_dir_url( __FILE__ ) .'simple-banner.css', '', VERSION);
21
  wp_enqueue_style('simple-banner-style');
22
- // Set Script parameters
23
- $script_params = array(
24
- // script specific parameters
25
- 'simple_banner_text' => 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' ), VERSION);
42
- wp_localize_script('simple-banner-script', 'scriptParams', $script_params);
43
  wp_enqueue_script('simple-banner-script');
44
  }
45
 
@@ -80,7 +80,27 @@ function simple_banner_custom_color()
80
 
81
  add_action('admin_menu', 'simple_banner_menu');
82
  function simple_banner_menu() {
83
- add_menu_page('Simple Banner Settings', 'Simple Banner', 'administrator', 'simple-banner-settings', 'simple_banner_settings_page', 'dashicons-admin-generic');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  }
85
 
86
  add_action( 'admin_init', 'simple_banner_settings' );
@@ -93,6 +113,7 @@ function simple_banner_settings() {
93
  register_setting( 'simple-banner-settings-group', 'pro_version_activation_code' );
94
  register_setting( 'simple-banner-settings-group', 'pro_version_enabled' );
95
  register_setting( 'simple-banner-settings-group', 'disabled_pages_array' );
 
96
  register_setting( 'simple-banner-settings-group', 'site_custom_css' );
97
  register_setting( 'simple-banner-settings-group', 'site_custom_js' );
98
  register_setting( 'simple-banner-settings-group', 'debug_mode' );
@@ -188,8 +209,21 @@ function simple_banner_settings_page() {
188
  </tr>
189
  </table>
190
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  <!-- Pro Features -->
192
  <div style="padding: 0 10px;border: 1px solid #24282e;border-radius: 10px;background-color: #fafafa;">
 
193
  <h2>Pro Features
194
  <?php
195
  if (!get_option('pro_version_enabled')) {
@@ -208,6 +242,43 @@ function simple_banner_settings_page() {
208
  <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'); ?>" />
209
  </td>
210
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  <!-- Disabled Pages -->
212
  <tr valign="top">
213
  <th scope="row">
@@ -414,6 +485,17 @@ function simple_banner_settings_page() {
414
  document.getElementsByTagName('head')[0].appendChild(style_dynamic);
415
  };
416
 
 
 
 
 
 
 
 
 
 
 
 
417
  // Disabled Pages
418
  document.getElementById('simple_banner_pro_disabled_pages').onclick=function(e){
419
  let disabledPagesArray = [];
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.3.0
7
  * Author: Ryan Petersen
8
  * Author URI: http://rpetersen29.github.io/
9
  * License: GPL2
10
  *
11
  * @package Simple Banner
12
+ * @version 2.3.0
13
  * @author Ryan Petersen <rpetersen.dev@gmail.com>
14
  */
15
+ define ('VERSION', '2.3.0');
16
 
17
  add_action( 'wp_enqueue_scripts', 'simple_banner' );
18
  function simple_banner() {
19
  // Enqueue the style
20
+ wp_register_style('simple-banner-style', plugin_dir_url( __FILE__ ) .'simple-banner.css', '', VERSION);
21
  wp_enqueue_style('simple-banner-style');
22
+ // Set Script parameters
23
+ $script_params = array(
24
+ // script specific parameters
25
+ 'simple_banner_text' => 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' ), VERSION);
42
+ wp_localize_script('simple-banner-script', 'scriptParams', $script_params);
43
  wp_enqueue_script('simple-banner-script');
44
  }
45
 
80
 
81
  add_action('admin_menu', 'simple_banner_menu');
82
  function simple_banner_menu() {
83
+ $manage_simple_banner = 'manage_simple_banner';
84
+ // Add admin access
85
+ $admin = get_role( 'administrator' );
86
+ $admin->add_cap( $manage_simple_banner );
87
+
88
+ $permissions_array = get_option('permissions_array');
89
+
90
+ // Add permissions for other roles
91
+ foreach (get_editable_roles() as $role_name => $role_info) {
92
+ if ( $role_name !== 'administrator') {
93
+ if (in_array($role_name, explode(",", $permissions_array))) {
94
+ $add_role = get_role( $role_name );
95
+ $add_role->add_cap( $manage_simple_banner );
96
+ } else {
97
+ $remove_role = get_role( $role_name );
98
+ $remove_role->remove_cap( $manage_simple_banner );
99
+ }
100
+ }
101
+ }
102
+
103
+ add_menu_page('Simple Banner Settings', 'Simple Banner', $manage_simple_banner, 'simple-banner-settings', 'simple_banner_settings_page', 'dashicons-admin-generic');
104
  }
105
 
106
  add_action( 'admin_init', 'simple_banner_settings' );
113
  register_setting( 'simple-banner-settings-group', 'pro_version_activation_code' );
114
  register_setting( 'simple-banner-settings-group', 'pro_version_enabled' );
115
  register_setting( 'simple-banner-settings-group', 'disabled_pages_array' );
116
+ register_setting( 'simple-banner-settings-group', 'permissions_array' );
117
  register_setting( 'simple-banner-settings-group', 'site_custom_css' );
118
  register_setting( 'simple-banner-settings-group', 'site_custom_js' );
119
  register_setting( 'simple-banner-settings-group', 'debug_mode' );
209
  </tr>
210
  </table>
211
 
212
+ <div style="padding: 10px;
213
+ margin: 10px 0;
214
+ border: 2px solid red;
215
+ border-radius: 10px;
216
+ background-color: white;
217
+ color: red;
218
+ font-size: medium;
219
+ font-weight: bold;
220
+ text-align: center;">
221
+ Always make sure you test your banner in mobile views, theme headers often change up their css for mobile.
222
+ </div>
223
+
224
  <!-- Pro Features -->
225
  <div style="padding: 0 10px;border: 1px solid #24282e;border-radius: 10px;background-color: #fafafa;">
226
+
227
  <h2>Pro Features
228
  <?php
229
  if (!get_option('pro_version_enabled')) {
242
  <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'); ?>" />
243
  </td>
244
  </tr>
245
+ <!-- Permissions -->
246
+ <?php if ( in_array( 'administrator', (array) wp_get_current_user()->roles ) ): ?>
247
+ <tr valign="top">
248
+ <th scope="row">
249
+ Permissions
250
+ <br><span style="font-weight:400;">Allow roles to edit Simple Banner.</span>
251
+ </th>
252
+ <td>
253
+ <div id="simple_banner_pro_permissions">
254
+ <?php
255
+ $roles = get_editable_roles();
256
+ $disabled = !get_option('pro_version_enabled');
257
+ $permissions_array = get_option('permissions_array');
258
+ foreach (get_editable_roles() as $role_name => $role_info) {
259
+ if ($role_name == 'administrator') {
260
+ continue;
261
+ }
262
+ $allowed = current_user_can( 'manage_simple_banners' );
263
+ $checkbox = '<input type="checkbox"';
264
+ $checkbox .= $disabled ? 'disabled ' : '';
265
+ $checkbox .= (!$disabled && in_array($role_name, explode(",", $permissions_array))) ? 'checked ' : '';
266
+ $checkbox .= 'value="' . $role_name . '">';
267
+ $checkbox .= $role_name;
268
+ $checkbox .= '</input><br>';
269
+ echo $checkbox;
270
+ }
271
+ ?>
272
+ </dl>
273
+ </div>
274
+ <?php
275
+ if (get_option('pro_version_enabled')) {
276
+ echo '<input type="text" hidden id="permissions_array" name="permissions_array" value="'. get_option('permissions_array') . '" />';
277
+ }
278
+ ?>
279
+ </td>
280
+ </tr>
281
+ <?php endif; ?>
282
  <!-- Disabled Pages -->
283
  <tr valign="top">
284
  <th scope="row">
485
  document.getElementsByTagName('head')[0].appendChild(style_dynamic);
486
  };
487
 
488
+ // Permissions
489
+ document.getElementById('simple_banner_pro_permissions').onclick=function(e){
490
+ let permissionsArray = [];
491
+ Array.from(document.getElementById('simple_banner_pro_permissions').getElementsByTagName('input')).forEach(function(e) {
492
+ if (e.checked) {
493
+ permissionsArray.push(e.value);
494
+ }
495
+ });
496
+ document.getElementById('permissions_array').value = permissionsArray;
497
+ };
498
+
499
  // Disabled Pages
500
  document.getElementById('simple_banner_pro_disabled_pages').onclick=function(e){
501
  let disabledPagesArray = [];