Extend wordpress-notification-bar wordpress plugin

So.. I was using this nice plugin called wordpress-notification-bar to show a..yea, you guessed it.. a notification bar. My use was to show the bar to tell users that to download premium content, they need to login. Unfortunately, the plugin didnt offer such an option. So I decided to extend it.

First, I tapped into the Settings page and added an option to put a checkbox to allow users to choose whether they wanted such an option:

$seed_wnb->options[ ] = array(
    "type" => "checkbox",
    "id" => "disabledloggedin",
    "label" => __( "Disable for Logged in", 'wordpress-notification-bar' ),
    "desc" => __( "Check if you want to disable the notification bar if the user is logged in.", "wordpress-notification-bar" ),
    "option_values" => array(
        '1' => __( 'Yes', 'wordpress-notification-bar' )
    )
);

Next I needed to check whether the option was enabled, and the user was logged in, and disable the bar in such a case:

if ( isset($options['disabledloggedin']) && is_user_logged_in() ) {
  return false;
}

The final patch is this:

 #diff -rupN wordpress-notification-bar wordpress-notification-bar-patched
diff -rupN wordpress-notification-bar/inc/class-plugin.php wordpress-notification-bar-patched/inc/class-plugin.php
--- wordpress-notification-bar/inc/class-plugin.php     2013-05-29 17:56:26.000000000 +0530
+++ wordpress-notification-bar-patched/inc/class-plugin.php     2016-08-20 23:10:43.000000000 +0530
@@ -17,7 +17,10 @@ class SeedProd_WordPress_Notification_Ba
                $options = get_option('seed_wnb_settings_1');


+
        if(!empty($options)){
+
+

                if(isset($options['enabled'])){
                        add_action( 'wp_enqueue_scripts', array(&$this,'render_notification_bar') );
@@ -32,6 +35,13 @@ class SeedProd_WordPress_Notification_Ba
     function render_notification_bar($hook){
        global $seed_wnb;
         $options = $seed_wnb->get_options();
+       /* Code added by Joel G Mathew, to disable notification bar if user is logged in\
+       // Dont show bar if user is logged in
+       */
+               if ( isset($options['disabledloggedin']) && is_user_logged_in() ) {
+                       return false;
+               }
+       // End of Code to disable bar if logged in

         if($hook == 'settings_page_seed_wnb' || ! is_admin() && isset($options['enabled'])){
                $button_target = '_self';
@@ -51,7 +61,7 @@ class SeedProd_WordPress_Notification_Ba
         }
     }

-    function render_css(){
+    function render_css(){
        global $seed_wnb;
        $options = $seed_wnb->get_options();

diff -rupN wordpress-notification-bar/inc/config.php wordpress-notification-bar-patched/inc/config.php
--- wordpress-notification-bar/inc/config.php   2015-10-02 13:08:38.000000000 +0530
+++ wordpress-notification-bar-patched/inc/config.php   2016-08-20 22:56:35.000000000 +0530
@@ -70,7 +70,19 @@ $seed_wnb->options[ ] = array(
         '1' => __( 'Yes', 'wordpress-notification-bar' )
     )
 );
-
+/* Code added by Joel G Mathew, to disable notification bar if user is logged in\
+        // Dont show bar if user is logged in
+        */
+$seed_wnb->options[ ] = array(
+    "type" => "checkbox",
+    "id" => "disabledloggedin",
+    "label" => __( "Disable for Logged in", 'wordpress-notification-bar' ),
+    "desc" => __( "Check if you want to disable the notification bar if the user is logged in.", "wordpress-notification-bar" ),
+    "option_values" => array(
+        '1' => __( 'Yes', 'wordpress-notification-bar' )
+    )
+);
+// End of Code to disable bar if logged in

 $seed_wnb->options[ ] = array(
     "type" => "textbox",

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.