06 Mar

Fruitful Code Theme Warnings

I use the fruitful theme by fruitfulcode on my WordPress blog. After a recent change of environment, which meant that non-fatal PHP warnings would be displayed, I noticed warnings being displayed at the top of the blog

I navigated to the code highlighted in the warning (line 756 of inc/metaboxes/init.php) and found this

elseif ( is_array( $meta_box['pages'] ) && count( $meta_box['pages'] === 1 ) )

It is the second condition in this if statement that causes a problem. As we are invoking count on a boolean (the results of $meta_box['pages'] === 1) rather than on an array or countable object PHP will emit this warning. I assume that the developer actually wanted to compare the number of pages to 1 and so I moved the close parenthesis so that we are invoking count on $meta_box['pages'], which we know is an array from the first condition in the if statement.

elseif ( is_array( $meta_box['pages'] ) && count( $meta_box['pages'] ) === 1 )

After this code update the warnings disappeared. As I do not find it best practice to modify third party code I reverted my change and instead submitted it as a pull request to the fruitful theme developers.

06 Mar

WordPress Docker containers and display of PHP warnings

I use a Docker container to host a WordPress blog and I recently upgraded the Docker image to one based on an image which used PHP 7.2. I had previously been using one based on Apache with PHP 5.6.

I immediately noticed warnings being displayed at the top of the blog

The warnings where from PHP letting a developer know that their code had a non fatal error. The cause of the error is a subject for another blog post. I just wanted to turn off the display of these warning messages.

To do this you can set the display_errors configuration variable to Off in php.ini

Create a file called hide_errors.ini with the following content

display_errors = Off

I then proceeded to recreate my WordPress docker container with the same volume as the current container used, as well as mounting hide_errors.ini to /usr/local/etc/php/conf.d/hide_errors.ini inside the container.

After this the warnings were no longer displayed.