Title: Errors when used with WP-CLI
Last modified: March 6, 2024

---

# Errors when used with WP-CLI

 *  Resolved [Matt Lowe](https://wordpress.org/support/users/squelch/)
 * (@squelch)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/errors-when-used-with-wp-cli/)
 * Hey. There’s a small error in this plugin which triggers when using WP-CLI.
 *     ```wp-block-code
           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:
 *     ```wp-block-code
        if ( strpos( $_SERVER['HTTP_HOST'], "playground.wordpress.net" ) !== false ) {
       ```
   
 * To:
 *     ```wp-block-code
       if ( strpos( $_SERVER['HTTP_HOST'] ?? '', "playground.wordpress.net" ) !== false ) {
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [Matt Lowe](https://wordpress.org/support/users/squelch/)
 * (@squelch)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/errors-when-used-with-wp-cli/#post-17478177)
 * 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:
 *     ```wp-block-code
       if ( strpos( isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '', "playground.wordpress.net" ) !== false ) {
       ```
   
    -  This reply was modified 2 years, 5 months ago by [Matt Lowe](https://wordpress.org/support/users/squelch/).
 *  Plugin Author [Barry Kooij](https://wordpress.org/support/users/barrykooij/)
 * (@barrykooij)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/errors-when-used-with-wp-cli/#post-17493484)
 * Thanks for reporting, this was fixed in 2.2.2
 *  Thread Starter [Matt Lowe](https://wordpress.org/support/users/squelch/)
 * (@squelch)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/errors-when-used-with-wp-cli/#post-17493573)
 * 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.

 * ![](https://ps.w.org/related-posts-for-wp/assets/icon-256x256.png?rev=970117)
 * [Related Posts for WordPress](https://wordpress.org/plugins/related-posts-for-wp/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/related-posts-for-wp/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/related-posts-for-wp/)
 * [Active Topics](https://wordpress.org/support/plugin/related-posts-for-wp/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/related-posts-for-wp/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/related-posts-for-wp/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Matt Lowe](https://wordpress.org/support/users/squelch/)
 * Last activity: [2 years, 5 months ago](https://wordpress.org/support/topic/errors-when-used-with-wp-cli/#post-17493573)
 * Status: resolved