• Resolved Matt Lowe

    (@squelch)


    Hey. 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 ) {
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Matt Lowe

    (@squelch)

    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 1 year ago by Matt Lowe.
    Plugin Author Barry Kooij

    (@barrykooij)

    Thanks for reporting, this was fixed in 2.2.2

    Thread Starter Matt Lowe

    (@squelch)

    Just upgraded to 2.2.2 and, sure enough, no more errors. Thanks for the swift fix!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Errors when used with WP-CLI’ is closed to new replies.