diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index d238e3c0b9..94d6de3eb5 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -3359,6 +3359,18 @@ function is_ssl() { return false; } +/** + * Determine if the scheme of the given URL is https. + * + * @since 4.0.0 + * + * @param string $url The URL + * @return boolean True if the given URL uses https, false if not (or if the URL is not valid). + */ +function is_https_url( $url ) { + return ( 'https' === parse_url( $url, PHP_URL_SCHEME ) ); +} + /** * Whether SSL login should be forced. * diff --git a/tests/phpunit/tests/functions/isHttpsUrl.php b/tests/phpunit/tests/functions/isHttpsUrl.php new file mode 100644 index 0000000000..22d9d9785c --- /dev/null +++ b/tests/phpunit/tests/functions/isHttpsUrl.php @@ -0,0 +1,22 @@ +assertTrue( is_https_url( 'https://example.com/' ) ); + $this->assertTrue( is_https_url( 'https://localhost/' ) ); + + $this->assertFalse( is_https_url( 'http://example.com' ) ); + $this->assertFalse( is_https_url( 'Hello World!' ) ); + $this->assertFalse( is_https_url( 'httpsinvalid' ) ); + + } + +}