Troubleshooting custom WordPress WP-CLI commands running on WP Engine’s SSH Gateway

This is a one line fix if you have missing string/array output from a custom WP-CLI command when using the WP Engine “SSH Gateway”.

Terminology:

    • WP Engine is a WordPress hosting company*.
    • They have an SSH Gateway – where you login to a separate machine and it will pass a limited range of useful commands to your actual server (basic file management, a MySQL console client, WP-CLI)
    • WP-CLI is a timesaving WordPress command line utility.

The problem is the unorthodox way the gateway works suppresses ordinary output from certain commands – e.g. print_r or echo.  Symptom: you run a  WP-CLI command of your own through the SSH gateway and lines of text you’re expecting are missing.

First, you should switch from WP_CLI::line() (deprecated now anyway) to WP_CLI::log() – the line() method doesn’t work because, if you dig into the source code, you’ll see it just echos the output, however log() uses the proper wp-cli Logger class.

That’s fine if you want to output strings. Unfortunately, it doesn’t work if you need to print an array.

This does though:

fwrite( STDOUT, print_r($foo, TRUE) );

To unpack that, we’re using print_r to neatly print the array. The second argument for print_r returns its value as a string.   You need not fopen STDOUT first, as you would for another file handle.

And that’s it.


* Would I recommend WP Engine? No, given I have hosting knowledge myself, and when I asked for their assistance with this particular problem, their support agent told me it was out of scope and I should look at StackOverflow, for which they have earned this mildly passive aggressive paragraph in a blog post that will sink without trace.   However, many people do like them, and if you’re a WordPress developer, you may well inherit a client with a site hosted there one day.

WordPress PSA: disable “Glue for Yoast SEO & AMP” plugin

If you have a site using the AMP plugin in “Reader” (formerly “Classic”) mode – which is to say it uses some simple templates for rendering AMP pages – you should remove Glue for Yoast SEO & AMP:

– it is no longer necessary
– the code in glue-for-yoast-seo-amp/classes/frontend.php adds a duplicate inline CSS selector for

header.amp-wp-header

and

.amp-site-title a

. This means the default colour scheme will override colours you set in Appearance > AMP.

Disabling the plugin fixes this.

(Tested with AMP 1.5.5, WordPress 5.4.2)

Ideas for supermarkets

(File this under things nobody will ever do.)

In store:

  • have a board outside the door listing which sections or products – bread, toilet rolls etc. – are completely sold out.  Have a column indicating roughly when you expect to restock the section.
  • large map of the supermarket aisles posted outside entrance / in car park.  New or less frequent customers can familiarise themselves with the map before they enter, so they do not get confused or unnecessarily interact with other customers while shopping.
  • if entrance has two sets of automatic doors, make one enter only and one exit only
  • sell toilet rolls in smaller pack sizes (1,2,4 etc.) not 16, 24 – to make it easier for people who don’t need or want large packs.
  • have a staff member whose job it to sanitise handles of shopping baskets or trolleys throughout the day
  • purchase UV lamps for each store, to inspect surfaces for germs (staff will need some basic safety training before using these)
  • hand washing station for customers, specifically before/as they enter the store
  • plastic partitions to help protect (and to an extent, reassure) checkout staff, as have already been used in some countries
  • UK Finance (formerly the UK Cards Assocation) to consider raising the £30 contactless limit, to reduce times necessary for customers to touch pin pads
  • Add on screen messaging reminding customers to clean hands after using self-checkout machine or PIN pad. Log frequency of use per checkout, so if staff have limited time, they can clean areas most likely to be infected, and reset the counter
  • coordinated, staggered elderly / key worker staff hours, so they’re available on different times/days at different supermarkets, not the same time everywhere, to help those working varying shifts or relying on public transport.
  • A list of these times to be maintained centrally by council and local press and to be displayed in the supermarket (listing their competitors)
  • once of a week, supermarkets to publish heat map of day and hours, indicating when busy / quiet periods are
  • give loyalty points for people who shop outside of peak or priority hours
  • reverse loyalty points system – award points to people who DON’T panic buy toilet roll or other high demand items, or who regularly buy in smaller quantities.  (Trickier for people to game this system if you apply it only occasionally, averaged over multiple visits rather than at checkout.)
  • reverse multi-buy offers – cheaper prices for buying smaller quantities of high demand items,instead of rewarding buying in bulk
  • suspend Sunday trading restrictions – none of the reasons for having them apply at the moment. It also leads to the policy of ‘letting people in before the tills open’ which again, wasn’t intended for this sort of demand, and will just lead to an increased number of people in close proximity who are unable to leave the store

Home delivery / website:

  • static page (one that specifically does not require registration/login) regenerated at regular intervals showing, per store, remaining available delivery slots by quantity and date
  • a proper system status page for all supermarkets, with website metrics – e.g. page load time and API failure rate, email delivery time – and customer service metrics: outstanding calls/emails and current wait time for both. Let people check status of email tickets.  Heat map showing quiet times to call customer service.  Callback option.
  • make the list of out of stock items mentioned earlier available online too
  • government to provide an API that accepts, say, a postcode and a national insurance number, and will tell you if that person is a key worker. Use this to allow priority choice of online delivery slots etc.
  • If there’s an error, say when attempting to book a delivery slot, don’t immediately redirect people all the way back to the start of the process (time consuming for users and increases server load further)

Revised 12:10pm, 22 March 2020

Text only news websites

TL;DR: As of August 2020, the main sites are still CNN, NPR and The Guardian API, with my news agency recommendation being Reuters.

Reasons to use text only sites:

  • Save time
  • Save bandwidth / access conveniently in poor connectivity situations
  • Increase battery life on mobile devices (little or no JS to load/process)
  • Less distraction / more immersion in content (like reading a book)
  • No iframes / social media oEmbeds
  • Usually no advertising
  • Overall, much less stressful

Sites

CNN

Advantages:

  • plenty of stories (40)+
    fast and clean presentation
    few HTML->text conversion issues

Disadvantages:

  • no author name(s)
  • no direct link back to full versions of each item
  • live audio stream hasn’t worked for a long time
  • slightly too many stories on Trump for my liking
    (though we are in the middle of an election cycle)

Today’s Guardian – this is absolutely beautiful (also includes photos).  Swipe right to navigate stories.  Not made by The Guardian – uses their API. Blog post on how it was built.

NPR – formatting is a bit cruder and only 10 stories on homepage (tip: click ‘News’ and you get 15)

Apps:

The Reuters app isn’t strictly text only but it does have an offline mode and supports iOS dark mode.

It is still available for old devices too – e.g. iPod Touch 4th generation – supports offline mode. Not strictly text only, as there are photos at the top (imho, Reuters has the best/fastest range of news photos).  Still loads quickly on hardware that was released in 2010.  Most content sections still working. iPod Touch only weighs 100g so comfortable to read for long periods and easily slips in a bag (just don’t use it for anything that requires up to date security).  Turn javascript off in Safari settings to make websites bearable.

Tip for debugging complex MySQL queries if you have PhpStorm

  • Start a new scratch file (Mac: shift-cmd-N)
  • choose ‘MySQL’
  • Paste your query in
  • Reformat code (Mac: opt-cmd-L)

It’ll colour code and tidy everything, including lining up all the field names and aliases, neatly arranging the joins and the where clauses, plus you can hover over opening or closing brackets and see the opposite bracket highlighted.

This is useful when previewing raw Drupal view SQL and trying to understand it.

Troubleshooting ‘The provided URL does not represent a valid oEmbed resource.’ with YouTube videos

If you are trying to add a YouTube video using media > remote video in Drupal 8.7 (media is now part of core) and you stumble across this error – which is not discussed anywhere in the core issue queue that I can see…

The provided URL does not represent a valid oEmbed resource.

the fix is to add this line in settings.php:

$settings['http_client_config']['force_ip_resolve'] = 'v4';

Debugging / cause:

– First verify it’s not a private video (unlisted is fine)
– Optionally you can manually test the oEmbed response in your browser (you should get some JSON data back) – the URL needs to be:
https://www.youtube.com/ombed?url=[an encoded full YouTube URL]

It’s as quick/quicker to look in Recent Log Messages in Drupal first, you may be seeing errors like this:

Client error: `GET https://www.youtube.com/oembed?url=https%3A//www.youtube.com/watch%3Fv%3Dyoutubeid` resulted in a `429 Too Many Requests` response:

and also:

Could not retrieve the oEmbed resource.

(which doesn’t tell you anything).

oEmbed requests in Drupal are simple, unauthenticated HTTP GETs – i.e. they don’t use the YouTube API.  Nothing particularly wrong about this.  However the trouble is YouTube has started blocking IPv6 blocks en-mass; apparently because it’s too easy for people to keep changing IPv6 addresses (if ISPs provide a large pool of them) and use them for spam.   Therefore all and any requests over IPv6 may simply be blocked, regardless of how few you’ve made (I can confirm this for Linode servers.)

First, verify this is true for your server by manually grabbing the URL at the command line via wget, with the  -6 and -4 switches.

Assuming IPv4 works, you now need to tell Drupal to make Drupal use it.  This is easier than expected.   Drupal uses the Guzzle HTTP client library, specifically as an HTTP client factory – but as this StackExchange answer explains  – part of the default setup automatically merges in values from $settings, i.e. anything you add under $settings[‘http_client_config’].

So make your $settings.php writeable, and configure the force_ip_resolve setting as shown at the beginning of this post.

YouTube queries should then start working immediately.

 

 

 

 

PSA – Safari 13.0.1 breaks multiple extensions

Even if you’re still running macOS High Sierrra (I’m on 10.13.6) you’ll receive a Safari update (from 12 to 13).  This will break a number of extensions – including most adblocking – also a vim-based keyboard extension I was using called Vimmy.

So you may want to avoid upgrading, or do as I’ve done and switch your default browser to Firefox etc. for the time being.

macOS Catalina 10.15 – things to be aware/wary of

  • 32-bit apps will no longer be supported at all (currently that still includes Acquia DevDesktop – for running Drupal development sites)
  • the default shell is going to change from Bash to Zsh
  • scripting languages won’t be installed by default (Apple gave Python, Ruby and Perl as examples in a support document, but didn’t specifically mention PHP).  It’ll mean Homebrew will need to be installed differently.   Presumably it won’t be an issue if you’re upgrading a previous macOS version, but, also presumably, it will be if you’re using a new computer, even with Migration Assistant.
  • iTunes has been removed and the Apple Music replacement apparently doesn’t support column view of your music library.
  • John Gruber writes that Catalina is a pain to use due to (a) bugs but also (b) excessive permission alert dialogs.

(As usual, my own policy is not to upgrade to a new macOS release until 9-12 months after it’s come out, to allow everything to settle. I write this – post updated Feb 2020 – on a machine that’s still running High Sierra, which should still get support until late 2020 – although again, Apple have never announced support lifecycle dates.)