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.

Extending wordpress-notification-bar to hide notification bar if user is logged in

So I needed a notification bar to warn users that they were not logged in. This plugin was useful but it didnt have an option to hide the bar for logged-in users. So I edited it to add this functionality:

diff -rupN wordpress-notification-bar/inc/class-plugin.php wordpress-notification-bar-patched/inc/class-plugin.php
--- wordpress-notification-bar/inc/class-plugin.php 2016-08-20 20:44:25.000000000 +0530
+++ wordpress-notification-bar-patched/inc/class-plugin.php 2016-08-20 20:42:23.000000000 +0530
@@ -30,6 +30,15 @@ class SeedProd_WordPress_Notification_Ba
}

function render_notification_bar($hook){
+ /* Code added by Joel G Mathew, to disable notification bar if user is logged in\
+
+ // We need to disable in this function.
+ // Dont show bar if user is logged in
+ if ( is_user_logged_in() ) {
+ return false;
+ }
+ */
+
global $seed_wnb;
$options = $seed_wnb->get_options();

You can patch with patch -1


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.
A review of Reliance Jio, the upcoming 4G behemoth

A review of Reliance Jio, the upcoming 4G behemoth

Reliance-Jio

Reliance Jio is an upcoming 4G service provider. Though the name Jio isnt a household name, the brand is far from being unknown. It’s a subsidiary of Reliance Industries, headed by the Mukesh Ambani. Though it may sound like yet another 4G provider in a market saturated by existing ventures, Jio is exciting for one reason-VOLTE, or voice over LTE. While existing telecom providers offer voice through the existing 2G spectrum, calls originating in Jio network travel as data packets through 4G network. As such, theoretically the calls ought to be crisper (since more high quality voice data can be transferred when the medium is high bandwidth 4G network) and cheaper. I read that Jio’s vision is to provide LTE data that’s affordable to everyone. Gauging by the prelaunch offers Jio provides, one can definitely expect something awesome.

Having a friend who works in Jio, I had early bird access to a Jio sim. My experience with the fledgeling service was nothing short of enthralling. Awesome download speeds and great clarity were the norm with the occasional disconnection. Initially I could use only data on my Oneplus One, since the phone didn’t support VOLTE. But Jio soon rectified this and paved the way for the masses to experience firsthand, something than can be described as nothing short of exciting. For the first time, one could experience excellent data speeds which Indians had hitherto only dreamed of.

IMG_20160729_215809-01

Jio is now impeding launch, and tens of thousands of Indians are now putting Jio’s bandwidth to the ultimate test. Jio initially offered its preview offer to employee sims, and thereafter open the doors to owners of selected Samsung high value phones. Then, knowingly or unknowingly, they left open a “bug” which allowed owners of other brands 4G handsets to register to the service and experience the “in-thing”. If you ask me, it was not a bug. Most probably at some high level of the management, they may have made a conscious decision to allow other customers access to the service. For the best way to engender curiosity and improve market presence by marketing is passive marketing, by word of mouth. Jio didnt even need to launch ads, already there’s a huge demand for their sim cards.

Word is rife in Whatsapp and Telegram groups that people are even reselling employee sims at a huge price because of the sheer demand for a Jio sim!

Anyway, the speeds of Jio have been excellent. The following is a speedtest that I did today at Kochi. Let the figures speak for themselves:

Screenshot_20160729-133119

Anyway, one thing is clear, Reliance Jio will give the rest of the service providers a nightmare once it releases! For consumers, it’s a dream come true.

It’s not fair to be critical of Jio at this point of time when it has not yet commercially launched. However, the following sum up my experience with Jio:

Call quality: Calls on Jio require either a VOLTE supported handset. If you don’t have one, don’t despair, because the company has launched an Android app, Jiojoin which helps non-VOLTE handset users make calls (including video calls), send sms and more. The app does its work, but it could have been better designed. The fonts are small, and the interface unintuitive. It also seems to hold wakelocks, which are never a good idea, since it drains your battery quickly. Once the app is redesigned and the bugs removed, everyone can join the VOLTE bandwagon. Oh and did I mention that as a preview offer, All India calls are free for 90 days?

Data: This is the awesome part of Jio. Internet connectivity is excellent, barring the occasional disconnection (location specific no doubt). In Trivandrum at least disconnection rate is very high, and it’s difficult to make calls without getting disconnected very soon. By the looks of it, Jio is working hard to fix their network.

Jio may very well deliver on its promises of “shaping the future of India by providing end-to-end digital solutions for businesses, institutions and households and seamlessly bridging the rural-urban divide.”.

 


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

Enabling mega.nz download in plowshare

plowmod -i [email protected]:droidzone/plowshare-module-mega.git
cd ~/.config/plowshare/modules.d/mega.git
./autogen.sh
./configure --enable-local
sudo make install

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

Cleaning a virus that makes the whole removable disk read-only.

Once before, I’ve encountered a virus that transfers the entire contents of the usb removable disk to a folder with a blank filename, and then creates a self-running link in the root directory that copies the virus to the hard disk, so that it propogates itself to any new removable disk that is connected. But this was a new breed that made the removable usb drive read-only, so much so that most except the most hard core linux utilities would fail to fix it. A friend had handed the disk over to me, requesting me to see if my “linux PC can fix it”.

The command which fixed the write protect status was:

sudo blockdev --setrw /dev/sdc1

This allowed me to remount it as read-write:

sudo mount -o rw,remount /dev/sdc1 /home/joel/usb

so that I could finally run clamscan and fix it:

clamscan --remove /home/joel/usb

To rename the folder with a blank space as name, I simply used:

mv '/home/joel/usb/ ' /home/joel/usb/ab

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

Combining multiple parts of a single huge image, with Adobe Photoshop

This is also called Panoramic merge. For me, the purpose was to join parts of a large marksheet, which unfortunately was not in A4 size, and hence could not be scanned by my SOHO scanner. Hence I had scanned three different parts of the huge image, and needed to combine them together into a single image.

The correct function to use in Photoshop is File>Automate>Photmerge (Photoshop CS6). Unfortunately, my Photoshop crashed when I used that function. So I searched for and found another function that did the same thing, even better.

Open the images you want to merge.
Create a new image with size larger than each. This canvas can be reused for multiple tasks.
Now, copy and paste each image to be merged, within the larger canvas.
Select all images, and then use: Edit>Autoalign layers>Perspective
This will create a fused image with correct dimensions. Save the file as some name. Redo the task.


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

Invalid SSL Certificate error after upgrading i-mscp to 1.2.17

There’s a bug in 1.17:
We need to change the following line at line number 233 in /var/www/imscp/engine/PerlLib/iMSCP/OpenSSL.pm:

return 0 unless $self->{'ca_bundle_container_path'} eq '';

to:

return 0 if $self->{'ca_bundle_container_path'} eq '';

Then, restart the panel with:

service imscp_panel restart

And now, sel generate each certificate again from the panel.


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

Recover or reset mysql root password when locked out

/etc/init.d/mysql stop

[ ok ] Stopping mysql (via systemctl): mysql.service.
[[email protected]] ~ #mysqld_safe --skip-grant-tables --skip-networking &
[1] 25335
[[email protected]] ~ #160619 00:45:55 mysqld_safe Can't log to error log and syslog at the same time. Remove all --log-error configuration options for --syslog to take effect.
160619 00:45:55 mysqld_safe Logging to '/var/log/mysql/error.log'.
160619 00:45:55 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

mysql mysql -uroot
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.49-0+deb8u1 (Debian)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>UPDATE user SET password=PASSWORD("MYNEWPASSWORD") WHERE User="root";
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 0
mysql>FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> \q
Bye

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

Reset a forgotten Windows 7 administrator password

This post describes how to reset a forgotten Windows 7 administrator password:

First create a Windows 7 installation disc or pen drive. For pen drive, you can use Rufus.

Once you have an installation medium, boot off it. You may need to tweak the bios settings at boot to enable booting from this.

Once installation starts, choose “Repair your computer” option. Get to the command prompt, and execute the following command:

copy c:\windows\system32\sethc.exe c:\
copy c:\windows\system32\cmd.exe c:\windows\system32\sethc.exe

Reboot PC. Start windows, get to the login screen, and press Shift key 5 times to get an admin (elevated permissions) command prompt. Execute the following:

net user myuser newpwd

to change the password for the user “myuser”.

If you dont have an admin user installed, create one now:

net user /add [username] [password]

This creates the user account.

Add the new user to Admin group:

net localgroup administrators [username] /add

As a security precaution (even though Windows is inherently a security risk), always set a bios password to prevent novices from accessing your system internals. Of course, they could always open the chassis, reinsert the battery to disable the bios password. 😉


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.
Renaming multiple pdf files via A-pdf on Linux or Windows

Renaming multiple pdf files via A-pdf on Linux or Windows

A-PDF is an excellent software, extremely useful to rename multiple pdf files. Imagine a scenario where you have a lot of pdf files which are named incorrectly and you would like to assign them file names based on their actual title, which is available in the pdf file. It so happens that I’ve got some medical ebooks lying around which have titles within them, but the file names have no relation to the title within. Therein, A-PDF comes to the rescue.

My primary OS is Ubuntu 16.05, and though A-PDF is available officially only for Windows, A-PDF easily runs under Wine application layer in Linux. The following steps detail how to install and run it in Ubuntu.

First, download the latest A-PDF version from the manufacturer. Note that it is available as a shareware which needs to be purchased if you wish to use it beyond 15 days of trial period.

Unzip a-pdf-rn.zip.

Right click the extracted file, a-pdf-rn.exe, and choose “Open with > Wine windows program loader”.

From the standard Windows installation package which opens, choose a location to install it. Once installed, you get a shortcut on your desktop. Double click it to get started.

In the main program window, drag pdf files from a folder.

1

 

 

 

 

 

In my example, my files are named x001.pdf, x002.pdf etc.

In the main A-PDF window, it displays metadata about the file. You can see the title.

2

 

 

 

 

 

 

 

I enter the following in the Rename Filename as box: %Title%.pdf

Choose “Preview and Rename”. Now the program will batch execute renaming. You can view the results as a summary.

3

Alternative Command line script to rename pdfs by their title
If renaming pdfs by title is all you require, you may use the script I wrote, to suit you. It takes arguments as individual filenames and directories, and renames pdfs, giving them the title.pdf filenames. Clone the git project located here, and use the script named renpdf.


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