AREOI_Styles::add_block_styles() can fail in some non-single contexts
-
Hi @areoimiles,
There appears to be a need for some logic for
add_block_styles()
on line 179 of fileclass.areoi.styles.php
whereparse_blocks( )
attempts toget_the_content()
. In my case, which may be a bit of an edge case, I get the following when I attempt to load a taxonomy archive which has a custom search parameter applied to it:Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /var/www/web/wp/wp-includes/post-template.php:321
In
post-template.php
on 290 there’s an$elements
array that’s created if$post
is null (which it is in my case) which includes the global$page
, which is also null in my case. On line 321 there’s acount()
on$page
that throws the fatal error.I’m not sure whether
post-template.php
would benefit from some conditionals or whether it’s designed to fail loudly, but in any case here’s a potential fix, or at least a starting point for one, inclass.areoi.styles.php
:Replace line 179 with:
global $page; if ( null === $page ) { $standard_blocks = false; } else { $standard_blocks = parse_blocks( get_the_content() ); }
Replace line 227 with:
if ( ! $standard_blocks ) { $blocks = array_merge( $page_reuseable_blocks, $reuseable_blocks, $template_blocks, $widget_blocks ); } else { $blocks = array_merge( $standard_blocks, $page_reuseable_blocks, $reuseable_blocks, $template_blocks, $widget_blocks ); }
This solves it for me. I’m not sure if it introduces any other issues as I haven’t tested it extensively, but it seems to work fine.
If you’d prefer to get pull requests for this sort of thing, is the plugin repo hosted anywhere public?
Thanks for all the maintenance on this plugin. It’s truly great.
- The topic ‘AREOI_Styles::add_block_styles() can fail in some non-single contexts’ is closed to new replies.