Conversation
supportHey. There’s a small error in this plugin which triggers when using WP-CLI. PHP Warning: Undefined array key "HTTP_HOST" in /var/www/vhosts/example.com/htdocs/wp-content/plugins/related-posts-for-wp/classes/class-playground.php on line 9 Warning: Undefined array key "HTTP_HOST" in /var/www/vhosts/example.com/htdocs/wp-content/plugins/related-posts-for-wp/classes/class-playground.php on line 9 The error appears to be harmless, but it emits the error twice for every execution of WP-CLI, which is polluting the logs of our automated processes. On one website with Related Posts for WP installed that error message appears in the logs over 50 times every day when a number of automated tasks are executed. All it needs is to change: if ( strpos( $_SERVER['HTTP_HOST'], "playground.wordpress.net" ) !== false ) { To: if ( strpos( $_SERVER['HTTP_HOST'] ?? '', "playground.wordpress.net" ) !== false ) {
Actually, I’ve just noticed you support PHP5.3 upwards, so the null coalescing operator can’t be used. Somethng like this ought to do it: if ( strpos( isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '', "playground.wordpress.net" ) !== false ) { This reply was modified 2 years, 2 months ago by Matt Lowe .
Thanks for reporting, this was fixed in 2.2.2
Just upgraded to 2.2.2 and, sure enough, no more errors. Thanks for the swift fix!
Actually, I’ve just noticed you support PHP5.3 upwards, so the null coalescing operator can’t be used. Somethng like this ought to do it: if ( strpos( isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '', "playground.wordpress.net" ) !== false ) { This reply was modified 2 years, 2 months ago by Matt Lowe .
Thanks for reporting, this was fixed in 2.2.2
Just upgraded to 2.2.2 and, sure enough, no more errors. Thanks for the swift fix!