Yearly Archives: 2017

How to disable JetPack nag messages in the WordPress Admin interface

I really like WordPress, and I really like JetPack. I use the plugin on many client websites, who usually have their own WordPress.com  account, which is necessary to enable the plugin successfully.

Most of them however choose not to sign up for a payment plan, which as of 2017 leads to (now rather annoyingly frequent) JetPack upsell messages at the top of the admin screen. So I as the administrator, am constantly exposed to such messages, and I was wondering how to suppress them – not being the target audience here.

Thanks to a super helpful article by Matt Medeiros I found a great solution with this one-liner of code he as kindly supplied on his website, together with his opinion on such messages:

Add this to your child theme’s functions.php file and those admin nags are history!

Thanks Matt!

How to find out which version of GNOME you’re using

In the GNOME desktop, there is no obvious way to tell which version you’re running by way of the GUI. Instead, we need to consult the command line and try out a couple of commands to find out more. Here’s how.

Let’s open a Terminal session and do some hacking.

GNOME 2.x

If you’re running GNOME 2.x (under CentOS 6 for example), you need to run the following command:

You may need to prefix this command with sudo, otherwise it will tell you that you’re alrady running a GNOME session.

Should the above not work, you’re likely on GNOME 3 (see next).

GNOME 3.x

GNOME 3 uses a different command, namely this one:

If you don’t know which version of the GNOME panel you’re using (which is likely), try both commands. One of them will work, the other one won’t.

How to fix the Visual Editor or Text Editor in WordPress when it’s not working

I had a weird phenomenon on a Multisite installation the other day. I can’t tell you with which update exactly it happened, as I only write a post on that site once every couple of months, but it must have been around the 4.7 or 4.8 upgrade. Here’s what was happening:

I could log into the site fine, I could display all posts in the backend fine, but editing them, or creating a new post (or page) resulted in an unresponsive editor window. Neither the Visual Editor nor the standard Text Editor wanted to accept any keyboard input. Moreover, none of the buttons could be pressed, including the Publish button.

The rest of the admin interface looked and behaved completely normal. I could even write posts from the iOS app, so fundamentally the installation wasn’t broken, just the editor part of it. Made no sense to me at all.

Things I’ve tried

I tried the usual tricks for getting rid of such a spurious affair:

  • re-install WordPress manually
  • disable all plugins
  • use a different default theme (in fact, I’ve tried several)
  • try logging in as a different user
  • since this was multisite, try writing a post on another site (same issues there)
  • since this was an installation managed from Plesk via the WP Toolkit, try more lax security settings

I probably tried other things, but none of it was making that editor working again. I didn’t understand what was going on.

The Solution

The solution came after extensive research, one part of which lead me to this thread in which Peter Luit explained a related problem that he could fix by defining a constant in the wp-confg.php file. I had never heard of it either:

Turns out that this constant is enabled by default and means that all JavaScript files are loaded with a single call, rather than multiple calls to multiple files. The idea is that, if your site is healthy, and every single JavaScript file is working fine, all of them together will execute and work fine too. However, should one in the middle not work so well, then the rest of them won’t be executing, and I guess that’s what happened on my installation.

By setting this constant to false, each JavaScript file is loaded individually, resulting in more http requests to the server (potentially making the overall load time slower), but every JavaScript file can be executed individually. If one isn’t working, none of the others are impacted. Hence, now my editor is working again, however I still have at least one JavaScript file that has an issue executing. Finding which one would be the next step.

So this constant isn’t a “fix” as such, it’s part of a debug strategy. But it’s great to have my site back up and running so I can continue to write posts.

Thanks for sharing, Peter!

How to use Xcode for C and C++ development

Not only is Xcode an excellent IDE for iOS and macOS apps in both Swift and Objective-C; it does just as fine a job for regular C and C++ code. This includes all the features we know and love, such as code completion, version control, and all the rest of it.

Let’s see how to use Xcode 8.3 for C and C++ development.

Continue reading How to use Xcode for C and C++ development

How to fix “can’t log into YouTube from Safari” on macOS

Something rather strange happened to me today: Safari 10 on macOS Sierra refused to let me login to YouTube. All it did was constantly refresh the page in an endless loop, or just display the front page of YouTube. I cleared the caches, reset the history, but no trick seemed to solve the problem.

When I dug deeper into the Preferences, I found something under Privacy that finally fixed it. Let me share with you what worked on my system.

  • head over to Safari – Preferences
  • select the Privacy tab
  • you’ll see a window like this one:

  • select Manage Website Data
  • after a few moments you’ll see a LONG list of websites that have saved cookies on your machine over time
  • in the top right corner, search for YouTube
  • you’ll see something like this:

  • select the YouTube.com entry and hit Remove, followed by Done
  • now surf back to YouTube and login – this time it’ll work

What we’ve just removed were not just cookies, but also HTML local storage data, as well as cache data specific to the YouTube website. I guess cached stuff can get outdated, or not properly deleted when we close our browser in a hurry.

The principle should work for other websites too, should they give you trouble. If you’re sick and tired of any website saving data to your system, consider switching to the “Always Block” option seen in the first screen shot.

 

How to rename a batch of files in Linux

Bulk renaming files can be done with the rename command. It shares many similarities with cp and mv, but its simplicity can be so staggering that its difficult to figure out how to use it.

If we just type “rename” at the command prompt, all we get is the message

While technically correct, what on earth does it mean? How do we use rename?

Let’s do a little exercise. Imagine we had a batch of files, perhaps something like “Title 101.mp4” to “Title 110.mp4”. Let’s create some empty files with those names in a test directory:

So far so good. Now we’d like to rename those files so they read “New Title 101.mp4” to “New Title 110.mp4”. Here’s how it works:

Technically, this follows what the command showed us earlier: “rename from to files…”. Still I feel a little explanation is in order.

For the rename command to work, we don’t need to specify the full file name, nor that we want to rename a batch of files. The command will rename anything that it encounters. All it needs to know is which string to replace with which other string. Those are the first two parameters we give it, in our case wrapped in single quotes because we have a space character in our titles.

The third parameter tells rename where the files live that we want to rename. In our example it was here in the current directory, but it could be anywhere on the system. By specifying *.mp4, only files with that ending will be renamed, all other files will be left in peace.

I hope this helps to understand rename a little better.

How to exit VI with or without saving

Although many alternatives exist, I like using vi for all my command line editing needs. To save changes, I usually use SHIFT + Z + Z, exiting vi under most circumstances.

But sometimes, this trick doesn’t work because of write permission problems. In such cases, vi doesn’t close with the above command. Instead, we must either stash our changes in another file, or quit the session without saving. Here’s how to do that.

Quit vi without saving:
:q!

Save current file under a different name:
:w newfile

  • https://www.cs.colostate.edu/helpdocs/vi.html

How to read command line parameters in BASH Scripts

Shell Scripts (BASH Scripts) can access command line parameters using the the variables $1, $2, $2 and so forth, up to $9. In fact, more parameters can be accessed by using curly brackets, like ${10}, ${187} and so forth.

Here’s an example:

If we run the script with like this

it will tell us the statement is true. Otherwise, it’ll tell us the opposite.

Note the whitespace around the evaluation: [[ ]] is actually a command (much like the == operator) and therefore needs to be surrounded with whitespace.

How to read command line parameters in PHP Shell Scripts

We can access parameters passed via the command line in our PHP shell scripts. Those are stored as an array in the variable $argv. Consider this:

The first part of the script prints out all parameters that have been given, while the second part checks if the parameter was “x” or not. Note that the first item in the array ($argv[0]) will be the the first item on the command line, i.e. the file name and path to this very script. $argv[1] is the first parameter, $argv[2] the second, and so forth.

We can call the script with

to give it one parameter, or with

to give it three parameters.

  • http://php.net/manual/en/reserved.variables.argv.php

How to extract files from a bz2 archive in Linux

If you’ve ever tried to decompress a file that ends in tar.bz2 using the tar command with the standard -x option, you’ll have noticed that it doesn’t work. That’s because some versions of tar don’t understand the bzip2 codec used in these archives.

However, you can tell tar to use this option by specifying the -j parameter, like so:

If this still doesn’t work, we can use the dedicated bzip2 command like so:

The -d switch stands for “decompress”. Notice that this will extract all files and delete the original .bz2 file by default. Very convenient indeed! If you’d like to keep it, just pass the -k switch (for “keep”), like this:

Checkout man bzip2 for more details, or pass the –help for as quick overview.