Created
March 22, 2019 15:02
-
-
Save notasausage/a8dd6ec44746dae3f160991ab94fb468 to your computer and use it in GitHub Desktop.
Force WP Engine SSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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