Skip to content

Instantly share code, notes, and snippets.

@notasausage
Created March 22, 2019 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notasausage/a8dd6ec44746dae3f160991ab94fb468 to your computer and use it in GitHub Desktop.
Save notasausage/a8dd6ec44746dae3f160991ab94fb468 to your computer and use it in GitHub Desktop.
Force WP Engine SSL
<?php
/**
* Plugin Name: Force WP Engine SSL
* Description: Prevent WP Engine's Staging & Development environments from loading via http
* Version: 1.0
* Author: Patrick Haney
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 2, as published by the
* Free Software Foundation. You may NOT assume that you can use any other
* version of the GPL.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE.
*
* Based on Bill Erickson's work: https://www.billerickson.net/force-ssl-on-wpengine/
*
* @package ForceWPEngineSSL
* @since 1.0.0
* @copyright Copyright (c) 2019, Patrick Haney
* @license GPL-2.0+
*/
function force_wpengine_ssl() {
if( !is_ssl() && strpos( home_url(), 'wpengine' ) ) {
wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301 );
exit();
}
}
add_action( 'template_redirect', 'force_wpengine_ssl' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment