WordPress at a glance

is_ssl() WP 2.6.0

Checks whether secure HTTPS (SSL) connection is used. A conditional tag.

The function returns true if SSL is used on the current page. Checks protocol (HTTPS) and port (443).

This is one of the fundamental functions and it is available at an early stage of WP loading, even before SHORTINIT constant. Sometimes it can be very useful.

Возвращает

true/false. True if SSL, otherwise false.

Basis of: set_url_scheme()
1 time = 0.000012s = very fast | 50000 times = 0.02s = speed of light

Хуков нет.

Usage

if( is_ssl() ){
	// ...
}

Examples

#1 Check the connection protocol

Check what protocol the user use to get a page content, if it is SSL, then display some message:

if( is_ssl() ){
	echo "You are in a protected area. All requests between you and the server are protected.";
}

Changelog

Since 2.6.0 Introduced.
Since 4.6.0 Moved from functions.php to load.php.

Код is_ssl() WP 5.5.1

<?php
function is_ssl() {
	if ( isset( $_SERVER['HTTPS'] ) ) {
		if ( 'on' === strtolower( $_SERVER['HTTPS'] ) ) {
			return true;
		}

		if ( '1' == $_SERVER['HTTPS'] ) {
			return true;
		}
	} elseif ( isset( $_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
		return true;
	}
	return false;
}

From tag: Site security (safety)

More from tag: Conditional tags (page type and request)

More from tag: Conditional tags (all)

More from category: Site Options (settings)

More from Template Tags: Main Functions

vladlu 100vlad.lu
Editors: kama 100
No comments
    Log In . Register