Skip to content

Commit 54f599a

Browse files
committed
Use a unique sentinel instead of null to detect the absent option
null as the get_option default is ambiguous with a stored value that resolves to null, which would re-seed on every request. Use a stdClass sentinel checked by identity so only a genuinely absent option is seeded. Per review feedback on the sibling PR (#50961).
1 parent 15f9c38 commit 54f599a

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

projects/packages/connection/src/class-terms-of-service.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ protected function is_offline_mode() {
9090
* @return bool
9191
*/
9292
protected function get_raw_has_agreed() {
93-
// Use null as the default so we can tell an unset option apart from a stored `false`.
94-
$has_agreed = \Jetpack_Options::get_option( self::OPTION_NAME, null );
93+
// Use a unique sentinel as the default so an absent option can't be confused with a
94+
// stored value (a legitimately stored null/false would otherwise be treated as absent).
95+
$sentinel = new \stdClass();
96+
$has_agreed = \Jetpack_Options::get_option( self::OPTION_NAME, $sentinel );
9597

96-
if ( null === $has_agreed ) {
98+
if ( $sentinel === $has_agreed ) {
9799
// The option has never been stored. Persist the default as an autoloaded row so it
98100
// isn't re-queried on every request on sites without a persistent object cache
99101
// (JETPACK-1539). add_option (not update_option) is required because update_option

0 commit comments

Comments
 (0)