Skip to content

Instantly share code, notes, and snippets.

@charmoney
Forked from ltitus210/M&D wp-config.php
Last active May 1, 2018 16:24
Show Gist options
  • Save charmoney/a85719866488db6929b50c9a2c152c8b to your computer and use it in GitHub Desktop.
Save charmoney/a85719866488db6929b50c9a2c152c8b to your computer and use it in GitHub Desktop.
Support http and https concurrently in wp-config
<?php
/**
* Determine if the current request is SSL. Set $_SERVER['HTTPS'] for WordPress' build in is_ssl().
*
* @return True if the site uses ssl directly or through a load balancer
*/
function greenpeace_is_ssl() {
$is_ssl = (isset( $_SERVER['HTTPS'] ) && 'on' === $_SERVER['HTTPS'] )
|| (isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO'])
|| $_SERVER['SERVER_PORT'] == 443;
// https://codex.wordpress.org/Function_Reference/is_ssl
// Set the server HTTPS flag for WP's built in is_ssl() function
if ( $is_ssl ) {
$_SERVER['HTTPS'] = 'on';
}
return $is_ssl;
}
$web_site = $_SERVER['HTTP_HOST'];
$schema = greenpeace_is_ssl() ? 'https://' : 'http://';
$web_site_url = $schema . $web_site;
define( 'WP_HOME', $web_site_url );
define( 'WP_SITEURL', $web_site_url );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment