Fix for PHP warnings re SERVER_NAME and SERVER_PORT when using WP-CLI
-
When using WP-CLI on a site with WP-Cassify, I was seeing this kind of output on each command:
Notice: Undefined index: SERVER_NAME in /data/web/app/plugins/wp-cassify/classes/wp_cassify_utils.php on line 98 Notice: Undefined index: SERVER_PORT in /data/web/app/plugins/wp-cassify/classes/wp_cassify_utils.php on line 101 Notice: Undefined index: SERVER_PORT in /data/web/app/plugins/wp-cassify/classes/wp_cassify_utils.php on line 102 Notice: Undefined index: SERVER_PORT in /data/web/app/plugins/wp-cassify/classes/wp_cassify_utils.php on line 105
I found I could remove these warnings by adding a couple of checks in wp_cassify_utils.php for this situation:
// If cassified application is hosted behind reverse proxy. if ( isset( $_SERVER[ 'HTTP_X_FORWARDED_HOST' ] ) ) { $current_url .= $_SERVER[ 'HTTP_X_FORWARDED_HOST' ]; } elseif (isset( $_ENV['PANTHEON_SITE'] )) { // Are we on Pantheon? Use HTTP_HOST $current_url .= $_SERVER['HTTP_HOST']; } elseif ( isset( $_SERVER[ 'SERVER_NAME' ] ) ) { $current_url .= $_SERVER[ 'SERVER_NAME' ]; } if ( isset( $_SERVER[ 'SERVER_PORT' ] ) ) { if( ( $_SERVER[ 'SERVER_PORT' ] != $wp_cassify_default_wordpress_blog_http_port ) && ( $_SERVER[ 'SERVER_PORT' ] != $wp_cassify_default_wordpress_blog_https_port ) && !isset( $_ENV['PANTHEON_SITE'] ) ) // Don't use the port if we're on Pantheon { $current_url .= ':' . $_SERVER[ 'SERVER_PORT' ]; } }
- The topic ‘Fix for PHP warnings re SERVER_NAME and SERVER_PORT when using WP-CLI’ is closed to new replies.