HTTP_HOST warnings when using WP-CLI
-
This redirect plugin does not know how to “get out of the way” when commands are being run from the WordPress CLI (wp-cli). For example, if this plugin is active and you execute
wp post list | count
from the command line, you will see this response before the actual count:PHP Warning: Undefined array key "HTTP_HOST" in ./wp-content/plugins/quick-pagepost-redirect-plugin/page_post_redirect_plugin.php on line 2053 Warning: Undefined array key "HTTP_HOST" in ./wp-content/plugins/quick-pagepost-redirect-plugin/page_post_redirect_plugin.php on line 2053 PHP Warning: Undefined array key "HTTP_HOST" in ./wp-content/plugins/quick-pagepost-redirect-plugin/page_post_redirect_plugin.php on line 2061 Warning: Undefined array key "HTTP_HOST" in ./wp-content/plugins/quick-pagepost-redirect-plugin/page_post_redirect_plugin.php on line 2061
This is because the plugin assumes that
$_SERVER
includes an item with the keyHTTP_HOST
, which is not true when WordPress is running from the command line (and also not true in a number of other cases).At a minimum, this command should check with
array_key_exists()
before trying to use theHTTP_HOST
key.Better yet, the plugin should probably use the WordPress
get_site_url()
call to determine the host information instead of the$_SERVER
information.Best, the plugin should notice that it is being run from the CLI (check
if ( defined( 'WP_CLI' ) && WP_CLI ) {...}
) before it takes certain actions that just are not needed when running from the command line.
- The topic ‘HTTP_HOST warnings when using WP-CLI’ is closed to new replies.