Skip to content

Commit ad4109a

Browse files
committed
Enhance widget visibility conditions to handle array content in Jetpack (#45080)
* Added logic to process $instance['content'] as an array, ensuring compatibility with nested structures and serialization of block arrays. * Improved validation to return early if content is not a valid string after processing.
1 parent 8380dd9 commit ad4109a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,27 @@ public static function filter_widget( $instance ) {
827827
}
828828
return false;
829829
} elseif ( ! empty( $instance['content'] ) && has_blocks( $instance['content'] ) ) {
830-
$scanner = Block_Scanner::create( $instance['content'] );
830+
$content = $instance['content'];
831+
if ( is_array( $content ) ) {
832+
// Handle case where $instance['content'] might be an array instead of string
833+
if ( isset( $content['content'] ) && is_string( $content['content'] ) ) {
834+
// Content is nested in array structure
835+
$content = $content['content'];
836+
} elseif ( ! empty( $content ) ) {
837+
// Try to convert array of blocks back to string using serialize_blocks
838+
$content = serialize_blocks( $content );
839+
} else {
840+
// Empty or invalid array, treat as no blocks
841+
return $instance;
842+
}
843+
}
844+
845+
// Ensure content is still a string after processing
846+
if ( ! is_string( $content ) || empty( $content ) ) {
847+
return $instance;
848+
}
849+
850+
$scanner = Block_Scanner::create( $content );
831851
if ( ! $scanner ) {
832852
// No Rules: Display widget.
833853
return $instance;

0 commit comments

Comments
 (0)