Skip to content

Commit ac648a1

Browse files
General: Correct force_ssl_content() to always return a boolean value.
This aims to bring parity with `force_ssl_admin()`. Includes: * Allowing `force_ssl_content()` to properly accept `false` as a value. * Correcting an erroneous `! $force` conditional that should have been reversed. * Adding unit tests to confirm valid behavior. Follow-up to [https://mu.trac.wordpress.org/changeset/1979 mu:1979], [11903], [12603], [47808], [59830]. Props justlevine for initial patch. See #52217. git-svn-id: https://develop.svn.wordpress.org/trunk@60147 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 6511cc0 commit ac648a1

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

src/wp-includes/ms-functions.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,15 +2420,15 @@ function welcome_user_msg_filter( $text ) {
24202420
*
24212421
* @since 2.8.5
24222422
*
2423-
* @param bool $force
2423+
* @param bool|null $force Optional. Whether to force SSL in admin screens. Default null.
24242424
* @return bool True if forced, false if not forced.
24252425
*/
2426-
function force_ssl_content( $force = '' ) {
2426+
function force_ssl_content( $force = null ) {
24272427
static $forced_content = false;
24282428

2429-
if ( ! $force ) {
2429+
if ( ! is_null( $force ) ) {
24302430
$old_forced = $forced_content;
2431-
$forced_content = $force;
2431+
$forced_content = (bool) $force;
24322432
return $old_forced;
24332433
}
24342434

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Test cases for the `force_ssl_content()` function.
4+
*
5+
* @since 6.9.0
6+
*
7+
* @group functions
8+
* @group multisite
9+
* @group ms-required
10+
*
11+
* @covers ::force_ssl_content
12+
*/
13+
class Tests_Functions_ForceSslContent extends WP_UnitTestCase {
14+
15+
public function set_up() {
16+
parent::set_up();
17+
// Reset the `$forced_content` static variable before each test.
18+
force_ssl_content( false );
19+
}
20+
21+
/**
22+
* Tests that force_ssl_content() returns expected values based on various inputs.
23+
*
24+
* @dataProvider data_force_ssl_content
25+
*
26+
* @param mixed $input The input value to test.
27+
* @param bool $expected The expected result for subsequent calls.
28+
*/
29+
public function test_force_ssl_content( $input, $expected ) {
30+
// The first call always returns the previous value.
31+
$this->assertFalse( force_ssl_content( $input ), 'First call did not return the expected value' );
32+
33+
// Call again to check subsequent behavior.
34+
$this->assertSame( $expected, force_ssl_content( $input ), 'Subsequent call did not return the expected value' );
35+
}
36+
37+
/**
38+
* Data provider for testing force_ssl_content().
39+
*
40+
* @return array[]
41+
*/
42+
public function data_force_ssl_content() {
43+
return array(
44+
'default' => array( null, false ),
45+
'true' => array( true, true ),
46+
'false' => array( false, false ),
47+
'non-empty string' => array( 'some string', true ),
48+
'empty string' => array( '', false ),
49+
'integer 1' => array( 1, true ),
50+
'integer 0' => array( 0, false ),
51+
);
52+
}
53+
}

0 commit comments

Comments
 (0)