diff --git a/packages/block-library/src/gallery/index.php b/packages/block-library/src/gallery/index.php index 4aed9cfed051b..ff7b5880c2b92 100644 --- a/packages/block-library/src/gallery/index.php +++ b/packages/block-library/src/gallery/index.php @@ -50,9 +50,13 @@ function block_core_gallery_render( $attributes, $content ) { // because we only want to match against the value, not the CSS attribute. if ( is_array( $gap ) ) { foreach ( $gap as $key => $value ) { + // Make sure $value is a string to avoid PHP 8.1 deprecation error in preg_match() when the value is null. + $value = is_string( $value ) ? $value : ''; $gap[ $key ] = $value && preg_match( '%[\\\(&=}]|/\*%', $value ) ? null : $value; } } else { + // Make sure $gap is a string to avoid PHP 8.1 deprecation error in preg_match() when the value is null. + $gap = is_string( $gap ) ? $gap : ''; $gap = $gap && preg_match( '%[\\\(&=}]|/\*%', $gap ) ? null : $gap; }