From 3c77cf11407fcaaf5dd3b10c13c3fd92d3779279 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sun, 29 Jun 2014 11:31:25 +0000 Subject: [PATCH] Introduce `is_https_url()` for testing whether the scheme for a given URL is `https`. See #28487. git-svn-id: https://develop.svn.wordpress.org/trunk@28894 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 12 +++++++++++ tests/phpunit/tests/functions/isHttpsUrl.php | 22 ++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/phpunit/tests/functions/isHttpsUrl.php 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' ) ); + + } + +}