Make a query variable public

In case you are messing with custom rewrite rules in WordPress and especially creating new ones with the generate_rewrite_rules hook, you should know how to make a private (or a custom, which is by default – non-public) query variable public in order to have it working correctly in the rewrite rule.

It’s actually pretty simple – you just need to add a new element in the array, that is filtered by the query_vars filter. Like so:

That’s all.

“Nulled” WP Rocket when I got the original?!

Now here’s what happened to me last night. Follow me closely, as this will explain why you might get a very specific error message upon activating the plugin on staging or production environment one day, that would imply you have a nulled unlicensed plugin.

I installed my original licensed WP Rocket on my local development environment. As it was an older package, I decided to update it first, and then push it to staging. And so I did.

Once I pulled the latest code from my repo on staging and activated WP Rocket, I tried to configure the plugin, but got this message instead:

License validation failed. You may be using a nulled version of the plugin.

A tiny detail I need to mention here – the staging environment is not reachable publicly, as I’ve protected it behind a basic authentication wall.

So, it turns out that if you install WP Rocket in one place and then move it to another, protected WordPress instance, the plugin will not be able to work, as it will assume that the user is trying to configure a compromised plugin with malicious code inside.

How did I fix this?

I removed the new version of the plugin, then installed the original one, without activating or updating it on my local environment. Activated it staging and it worked just fine there.

Expired transients don’t get deleted on protected sites

I found it the hard way.

My database is rather small. It’s actually less than 20 Mb in total. That’s of course, if I exclude the 1.4Gb of data that I have in wp_options alone. Most of if being transients. Most of which have expired some time ago.

I’ll spare you the story of how I came to the conclusion, but will skip straight to it:

If the whole site is hiden behind a basic authentication (htpasswd) wall, then there is a very good chance the wp-cron will not be running. And if it’s not running, it will not run the process for deleting expired transients, which would lead to causing the database clogging.

Generating a new administrator user in WordPress through SQL

If you need access to a website, built on WordPress, but you have SSH access only, you could still cope with the situation with a few line in the command line.

Here are the steps you need to follow:

  1. Find the database credentials. They are usually in wp-config.php file under the web-root directory of your WordPress based website.
  2. Connect to the database, using the credentials from the configuration file, using the following command
  3.  Switch to your database:
  4. Create your user:
  5. Check the id of the newly created user. Try to guess the right SELECT, and if you can’t, go standing face to the wall and repeat a hundred times “I should not mess with the database if I don’t understand basic SQL.”. Seriously.
  6. Make your user an administator with this:

    Now you should be able to login with your username and password.

Recovering missing Facebook comments (and like counts) after switching to SSL

You might notice that you are missing your Facebook comments once you switch to HTTPS from serving your site initially on HTTP. The problem is with Facebook not linking the old URLs with the new ones, which is why you might have to do some additional work in order to have your comments back.

It’s important to notice that you’ll still have your Facebook comments form and you might even have some new comments there from after you switched to using SSL, but the old ones from before that would be gone. Not irreversibly, though.

Here is the solution I found in a couple of WordPress.org Forum threads. It worked great for me:

  1. Install and activate Really Simple SSL plugin (https://wordpress.org/plugins/really-simple-ssl/);
  2. See if your dashboard breaks. It did on one of my sites due to some weird environment edge case.
  3. Add a custom replacement for HTML attributes that would contain  the address of the website with HTTPS, instead of HTTP:

Oh, it’s usually the same problem with Facebook likes, so don’t worry that much if all of a sudden you lost all your Facebook like stats on your like buttons in the site. Same solution should fix this too.

Some good sources for starting your knowledge path in SEO

A friend of mine sent a list of resources to a client of mine and CC’ed me in the conversation. I do find these resources really helpful, which is why I decided to put them here. We are not affiliated to any of the sources.

SEO 101: 
WordPress SEO hints by the authors of the most popular WordPress SEO plugin: https://yoast.com/wordpress-seo/
SEO Blogs:
 

“Sorry, you are not allowed to access this page.” on News Cherry theme options page

The problem

It happened to a client of mine just recently – they tried to change something in the theme options, but they couldn’t, as reaching out to http://their-site.com/wp-admin/admin.php?page=options.php produced

“Sorry, you are not allowed to access this page.”

message. The theme is News Cherry by Bdaia, found on ThemeForest.

The solution

Turns out the theme is using the native WordPress file editor, which is used for editing themes and plugins through  the admin panel. So once we’ve disabled this through iThemes Security -> WordPress Tweaks, it stopped working for accessing the theme options. If iThemes Security is not present or the option there is disabled, it would be a good idea to check your wp-config.php file for

and set it to false. It’s a good setting to be enabled, so News Cherry is to be blamed for forcing you to lower your guard.