PHP warnings when SERVER_NAME is empty
-
Hello, found one more bug, which happens when $_SERVER[‘SERVER_NAME’] variable is empty (this could happen when some server side cron tasks are being executed).
PHP Warning: Undefined array key "SERVER_NAME" in /home/xxxxx/public_html/wp-content/plugins/woo-save-abandoned-carts/admin/class-cartbounty-admin.php on line 1923I’d suggest that you replace this line:
$sender = 'WordPress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));with the following:
if(!empty($_SERVER['SERVER_NAME'])) { $server_name = $_SERVER['SERVER_NAME']; } else { $site_url_parsed = parse_url(site_url()); $server_name = !empty($site_url_parsed) && !empty($site_url_parsed['host']) ? $site_url_parsed['host'] : 'system'; } $sender = 'WordPress@' . preg_replace('#^www\.#', '', strtolower($server_name));This uses a hostname from site URL as a primary fallback (secondary fallback – just a string “system”) in cases when SERVER_NAME is empty.
The topic ‘PHP warnings when SERVER_NAME is empty’ is closed to new replies.