diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index af88d3b06d..9a6938ed64 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -6273,7 +6273,7 @@ function validate_file( $file, $allowed_files = array() ) { * * @since 2.6.0 * - * @param string|bool $force Optional. Whether to force SSL in admin screens. Default null. + * @param string|bool|null $force Optional. Whether to force SSL in admin screens. Default null. * @return bool True if forced, false if not forced. */ function force_ssl_admin( $force = null ) { @@ -6281,7 +6281,7 @@ function force_ssl_admin( $force = null ) { if ( ! is_null( $force ) ) { $old_forced = $forced; - $forced = $force; + $forced = (bool) $force; return $old_forced; } diff --git a/tests/phpunit/tests/functions/forceSslAdmin.php b/tests/phpunit/tests/functions/forceSslAdmin.php new file mode 100644 index 0000000000..a700310443 --- /dev/null +++ b/tests/phpunit/tests/functions/forceSslAdmin.php @@ -0,0 +1,55 @@ + array( null, false, false ), + 'first_call_true' => array( true, false, true ), + 'first_call_false' => array( false, false, false ), + 'first_call_non_empty_string' => array( 'some string', false, true ), + 'empty_string' => array( '', false, false ), + 'first_call_integer_1' => array( 1, false, true ), + 'integer_0' => array( 0, false, false ), + ); + } + + /** + * Tests that force_ssl_admin returns expected values based on various inputs. + * + * @dataProvider data_should_return_expected_value_when_various_inputs_are_passed + * + * @param mixed $input The input value to test. + * @param bool $expected_first_call The expected result for the first call. + * @param bool $expected_subsequent_call The expected result for subsequent calls. + */ + public function test_should_return_expected_value_when_various_inputs_are_passed( $input, $expected_first_call, $expected_subsequent_call ) { + $this->assertSame( $expected_first_call, force_ssl_admin( $input ), 'First call did not return expected value' ); + + // Call again to check subsequent behavior + $this->assertSame( $expected_subsequent_call, force_ssl_admin( $input ), 'Subsequent call did not return expected value' ); + } +}