From 1c20eb500176075acc45f864fe90167a55ee0ef4 Mon Sep 17 00:00:00 2001 From: Shreya Shrivastava Date: Tue, 12 May 2026 16:17:43 +0530 Subject: [PATCH] fix: align server-side negation truthiness with JavaScript for arrays and string zero --- .../interactivity-api/class-wp-interactivity-api.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php index 0ee2ba8eff20c..2f3dd978baa50 100644 --- a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php +++ b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php @@ -747,7 +747,15 @@ private function evaluate( $entry ) { } // Returns the opposite if it contains a negation operator (!). - return $should_negate_value ? ! $current : $current; + // Uses JavaScript-compatible truthiness rules to ensure server and client + // rendering agree. PHP and JavaScript differ on two values: + // - [] (empty array): falsy in PHP, truthy in JavaScript. + // - '0' (string zero): falsy in PHP, truthy in JavaScript. + if ( $should_negate_value ) { + $is_truthy = is_array( $current ) || '0' === $current ? true : (bool) $current; + return ! $is_truthy; + } + return $current; } /**