Category Archives: WordPress

Migrating a WordPress Site From HTTP to HTTPS with WP-CLI

It’s as easy as:

Take a backup

wp db export

Test rewriting from HTTP to HTTPS

wp search-replace '' '' --dry-run

If everything is looking good, it’s time to rewrite:

wp search-replace '' ''

Some tutorials recommend adding the --skip-columns=guid flag. The train of thought is that old posts will be visible to RSS readers as new ones. I don’t think this is a big problem, and it’s much cleaner to not keep non-SSL urls in your database. It can also cause issues if you are using the GUID field to grab image urls/ids from attachments. (It’s a very popular way of mapping a URL to an attachment ID). With that in mind, I find it’s best to omit this flag.

Installing WordPress on a tiny wireless router

I recently got a Gl.Inet 6416 router off AliExpress for about $25. It’s an interesting little box that includes many features that routers ten times more expensive lack. (Thanks OpenWRT and open source!) The box is powered by the Atheros AR9331, an aging MIPS architecture processor clocked at a measly 400mhz with 64MB of RAM and 16MB of storage. In computer years, MIPS is stone-age technology, first launched in 1981(!), and the MIPS 24K standard this particular processor implements was first launched in 2004.


But the router is still quite capable even by 2016 standards! There is an SSH server and a package manager, opkg, which has packages for PHP 5.6. I immediately thought of something crazy to do – namely to install WordPress on this poor little machine.

So let’s see how that works.

Scaling things down

64MB of memory can’t accomodate either Apache or MySQL, so we have to find a way to run without them. Luckily, PHP has a built-in web server since version 5.4 that we can use, and WordPress has a SQLite plugin. This is a truly cool plugin that hooks into the db.php drop-ins and dynamically rewrites all WordPress database calls from MySQL to SQLite-compatible syntax.


Increasing the storage

16 MB of internal storage won’t get us far. Luckily, you can insert a USB drive and it happily mounts it under /mnt/sda1, so let’s do that:

IMG_20160717_031209-01 - Copy

Installing dependencies

Let’s SSH into the router and install SQLite, PHP and some useful tools like wget…

opkg install zoneinfo-core sqlite3-cli sqlite3 wget htop ca-certificates php5-cli php5 php5-mod-session php5-mod-pdo-mysql php5-mod-gd php5-mod-hash php5-mod-mbstring php5-mod-json php5-mod-opcache php5-mod-sqlite3 php5-mod-pdo-sqlite

Installing WordPress

Unfortunately, there is no support for Phar archives and hence no simple way to run WP-CLI or Composer, so let’s install WP manually:

cd /mnt/sda1
mv sqlite-integration wordpress/wp-content/plugins

Now let’s move the db.php drop-in into place:

cp wordpress/wp-content/plugins/sqlite-integration/db.php wordpress/wp-content/db.php

Let’s also create a default wp-config.php file:

cp wordpress/wp-config-sample.php wordpress/wp-config.php

Tweaking the PHP config

Some PHP defaults aren’t a good fit for this ancient architecture. Let’s decrease opcache.memory_consumption from 64MB to 8MB and increase the max_execution_time from 30 to 300 in /etc/php.ini

Booting it up

Now let’s finally start this baby up on the built-in PHP web server:

cd wordpress
php-cli -S

Loading up the browser the router IP on port 8080 gives us a familiar sight:

Thanks to the SQLite adapter, we don’t need to provide database credential, an on-disk database has already been created for us in wordpress/wp-content/database/.ht.sqlite.

After about 40 seconds, the install finally finishes!

2016-07-17 02_52_28-Program Manager

So what’s the speed like?

It comes as no surprise that this is suh-low! A pageload takes 5-15 seconds. Sometimes even longer if you are saving a draft or publishing a post:

2016-07-17 02_56_33-Program Manager

Other than that, it does actually run! Although uploading large images tends to make the built-in server crash with an out-of-memory error. Not surprising, considering we only have about 40 MB of RAM to play with (The operating system takes up approximately 25MB RAM).


Even though this is a silly project it shows that it is not only possible to run WordPress on OpenWRT, but that it is fairly pain-free to set up. There are more powerful MIPS processors out there (like the Qulcomm QCA9531 with 650mhz/128MB RAM) and those might actually make this usable for a real site. Hope you learned about some techniques to use WordPress in low-memory environments!

Disable preview in the WordPress theme Customizer

The WordPress Customizer preview can be notoriously buggy. Here is a snippet for easily disabling the customizer preview:

add_action( 'customize_preview_init', function() {
    die("The customizer is disabled. Please save and preview your site on the frontend.");
}, 1);

After adding this code to your themes functions.php file or a plugin, the live preview will simply show a message that it is disabled.

Screen Shot 2016-05-06 at 15.34.11

Use Jetpack without connecting a WordPress account

There is a nifty developer mode that makes it possible to use Jetpack without connecting a account to your site – making it essentially “offline-mode”. If you’re a user of the now deprecated JP Plugins that allowed you to use Jetpack features without Jetpack itself, this is a good alternative.

To enable developer mode, you can either put the following in your wp-config.php file:

define( 'JETPACK_DEV_DEBUG', true);

…or you can add this filter to a plugin or your themes functions.php file:

add_filter( 'jetpack_development_mode', '__return_true' );

This tweak is also available in plugin form! Head over to to download Unplug Jetpack!

When using the development mode, some Jetpack features aren’t available, here is the complete list of available and unavailable features: jetpack-lite

While you don’t connect Jetpack to an account, some of the available features (like Sharing buttons) might still make calls to the Jetpack servers.

Facebook oEmbed support for WordPress

Facebook has now publicly released oEmbed support, and a WordPress core ticket is under way to add support in a future WordPress version.

If you want to try out the new Facebook oEmbed support today, you can download and install this plugin: GitHub project or Direct zip download.

Here is an example of what the embed looks like:

If you prefer the code, here it is in its entirety:

Plugin Name: Facebook oEmbed
Version: 1.1
Author: khromov

add_action('init', function() {

    $endpoints = array(
        '#https?://www\.facebook\.com/video.php.*#i'          => '',
        '#https?://www\.facebook\.com/.*/videos/.*#i'         => '',
        '#https?://www\.facebook\.com/.*/posts/.*#i'          => '',
        '#https?://www\.facebook\.com/.*/activity/.*#i'       => '',
        '#https?://www\.facebook\.com/photo(s/|.php).*#i'     => '',
        '#https?://www\.facebook\.com/permalink.php.*#i'      => '',
        '#https?://www\.facebook\.com/media/.*#i'             => '',
        '#https?://www\.facebook\.com/questions/.*#i'         => '',
        '#https?://www\.facebook\.com/notes/.*#i'             => ''

    foreach($endpoints as $pattern => $endpoint) {
        wp_oembed_add_provider( $pattern, $endpoint, true );

Override default Yoast SEO settings in WordPress

Sometimes the default Yoast SEO settings aren’t quite the way you want. For example, I wanted to enable twitter cards using the “Summary with large image” card type by default on a multisite network. Below you’ll find a snippet that does that, and can also be adapted to change any default option while still letting users override them if desired.

add_filter('wpseo_defaults', function($defaults, $option_name) {
  if($option_name === 'wpseo_social') {
    $defaults['twitter'] = true;
    $defaults['twitter_card_type'] = 'summary_large_image';
  return $defaults;
}, 10, 2);


Looking for the proper $option_name ? If you enable the WP_DEBUG constant in your wp-config.php, it’ll show up on the relevant tab in the Yoast SEO admin:


This snippet was tested with Yoast SEO 2.3.5, but is likely to work for both older and newer versions.

Dynamically control user capabilities on multisite with WordPress

Got an interesting question about dynamically altering capabilities depending on which site the user was on – the goal was to have a global site where everyone had some access, without having to manually add every user to the site in question.

This snippet below will give everyone trying to access blog id = 1 on the multisite the Contributor capabilities. You can easily tweak which site ID and which Role you want to give all users.

add_filter( 'user_has_cap', function($allcaps, $cap, $args) {

  //ID of the "global" site
  if(get_current_blog_id() === 1) {

    //Give everyone admin capabilities
    $admin_caps = get_role('contributor')->capabilities;
    $allcaps = array_merge($allcaps, $admin_caps);

  return $allcaps;
}, 10, 3 );

Remove “Install WPMU DEV Dashboard” nag screen

Screen Shot 2015-10-30 at 16.07.46

If you don’t want to use the WPMU DEV dashboard plugin, you have to tolerate their nag screen. This nag screen, present in most WPMU DEV plugins will also make intermittent external calls to check for updates.

To get rid of it once and for all, create a file called no-wpmudev-nag.php in /wp-content/mu-plugins (Create the folder if it does not exist.)

Then, paste the following code into the file:

 * Plugin Name: Disable WPMU DEV Nag
 * Description: Disables WPMU DEV nagging
 * Version: 1.0
 * Author: khromov

if ( !class_exists('WPMUDEV_Dashboard_Notice3') ) {
   * Dummy class
   * Class WPMUDEV_Dashboard_Notice3
  class WPMUDEV_Dashboard_Notice3 {
    public function __call($name, $arguments) { return null; }
    public static function __callStatic($name, $arguments) { return null; }

Enjoy your nag-free experience!