WordPress can’t use number as page names

Where is what we wanted. A page example.com/404
So we had a page in WordPress so the content was controllable.

But on save the slug was changed to 404-2.

I figured maybe that slug was preserved. So after some digging I found this beautiful *ahem* if statement.

if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug )  || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) { //.......

The part it fails on is the preg_match. No number is accepted.
So it’s not just the slug 404 but every number.

The reason for this because it preserves numbers for pagination (including in-page pagination).

So the solution was to rename the page to example.com/404-page

Source: wp_unique_post_slug

WordPress Action Priority

I wanted to add_action between 2 different actions.
These actions where priority 3 and 4. So I tried 3.5. That didn’t work.

Decimals get rounded down. What did work was the string “3.5”

This got me curious about strings and the sorting in general. Under the hood WP just uses array_keys
To make things easier here is a list of use cases:

WordPress action how a priority is sorted

Bash argument set

Check if a bash argument is set in a script

File varcheck.sh

#!/usr/bin/env bash

if [ ! -z ${1+x} ]; then
    echo "var is set to '$1'";
else
    echo "var is unset";
fi

varcheck.sh will output: var is unset varcheck.sh TADA will output: var is set to 'TADA'

Nginx change default user

Default nginx runs on the user www, www-data of something alike.

You can change it. Be sure that you are aware of the security risks!
Don’t change it to a user that has access to sudo!

In /etc/nginx/nginx.conf on line #1 change the user.

#user www-data;
user deployment;

And change the user for php-fpm (If you’re using php-fpm 😉)

Create a file in /etc/php/7.2/fpm/pool.d/ (check the php version)
I suggest something like zzz-custom-user.conf so it’s loaded last. To that file add.

user = deployment
group = deployment
listen.owner = deployment
listen.group = deployment

Next reload everything, agian check php version.

sudo nginx -t && sudo service php7.2-fpm restart && sudo service nginx restart

Finally change the owner of the webfiles

sudo chown pi:pi /var/www/ -R

All done.

Behat functional tests

During WordCamp Rotterdam I worked on a small bug in WP-CLI. A bug I found roughly six months ago.
The bug itself was a one line fix.
I was asked to create functional tests using behat which I didn’t even heard off.

So after checking the handbook and with help of a few others. It resulted in this pull request.
And now we wait.