force_ssl_admin()
Whether to force SSL used for the Administration Screens.
Used By: set_url_scheme()
No Hooks.
Return
true|false
. True if forced, false if not forced.
Usage
force_ssl_admin( $force );
- $force(string|true|false)
- Whether to force SSL in admin screens.
Default: null
Examples
#1 Changing the return value
force_ssl_admin( true ); if ( force_ssl_admin() ) echo 'The admin must use SSL'; else echo 'This code will never run'; force_ssl_admin( false ); if ( force_ssl_admin() ) echo 'This code will never run'; else echo 'The admin area should NOT use SSL';
#2 Forced redirection to https
Redirect current page to https if current protocol is http:
if ( force_ssl_admin() && ! is_ssl() ) { if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) { wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) ); exit; } else { wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); exit; } }
#3 Reset to default settings
force_ssl_admin( FORCE_SSL_ADMIN );
Changelog
Since 2.6.0 | Introduced. |
force_ssl_admin() force ssl admin code WP 6.3
function force_ssl_admin( $force = null ) { static $forced = false; if ( ! is_null( $force ) ) { $old_forced = $forced; $forced = $force; return $old_forced; } return $forced; }