The method has_masonry_v1_block() produces a fatal error on PHP 8.0.22 and above
-
A call to
get_the_content()
inhas_masonry_v1_block()
(coblocks/includes/class-coblocks-block-assets.php) produces a fatal error on PHP 8.0.22 and above.Error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given
For some reason,
get_the_content()
does not return a string on some pages, but specifying the post ID fixes the error. See below:preg_match_all( $v1_regex, get_the_content( null, false, get_the_ID() ), $matches );
There is a conflict with the current version of Timber v1.22.1, but specifying the ID in your code is an easy fix for this problem. Using a global $post object and $post->post_content instead of get_the_content() also works. My guess is that the underlying problem lies on Timber, and not Coblocks itself.
Fix:
/** * Determine if the given post content contains any v1 Masonry block. * * @access public * @since 2.22.0 * * @return boolean True when post content contains a v1 Masonry block. */ public function has_masonry_v1_block() { $v1_regex = '/<!-- wp:coblocks\/gallery-masonry.*|\n*(coblocks-gallery--item).*|\n*<!-- \/wp:coblocks\/gallery-masonry -->/m'; preg_match_all( $v1_regex, get_the_content( null, false, get_the_ID() ), $matches ); return isset( $matches[0] ) && isset( $matches[0][2] ) && ! empty( $matches[0][2] ); }
Using WP 6.1.1.
Hopefully this little fix can be implemented, since version 2 of Timber is not out yet.
- The topic ‘The method has_masonry_v1_block() produces a fatal error on PHP 8.0.22 and above’ is closed to new replies.