Open bobbingwide opened 1 week ago
Note: While attempting to simplify the scenario even further I removed everything from the blog home template except the post content block. The problem went away!
The minimum template to produce the problem consists of:
Query loop
Post Template
Content
Before altering the behaviour so that oik-css will no longer fiddle around with hook priorities I plan to investigate where the problem actually occurs when oik-css is activated and to see if there's a simple fix.
In block based themes the problem occurs with the simplest scenario ( image with expand on click and an empty paragraph)
It's bw_wpautop
, hooked in at priority 99, that adds the unwanted end paragraph tags.
With a classic theme, such as Twenty Eleven, the problem will occur if a simplest scenario post is displayed in a post_content
block in a query loop
.
It even occurs within the block editor!
Again, it's bw_wpautop
that causes the problem.
I conclude that we can't just automatically disable bw_wpautop
processing for block based themes...
The problem also occurs with classic themes and we should cater for them too.
Therefore it looks like it's time to consider retiring bw_wpautop altogether.
I made a change in oik-css.php's oik_css_oik_loaded()
function to disable bw_wpautop()
processing when it's a block based theme.
$theme =wp_get_theme();
$is_block_theme=$theme->is_block_theme();
if ( $is_block_theme ) {
bw_better_autop( false );
} else {
$bw_disable_autop=bw_get_option( "bw_autop", "bw_css_options" );
$bw_autop = ! $bw_disable_autop;
bw_better_autop( $bw_autop );
}
Now several of the PHPUnit tests for oik fail. These tests were written when wpautop processing was adding unwanted paragraphs. The following is a comment from test_sc__snippet()
* - The test is dependent upon oik-css being active -
* and for Disable automatic paragraph creation to be deselected; it alters automatic paragraph creation
I don't want to change the tests so that they require a classic theme. There are three options to resolve this:
bw_better_autop( true )
in each of the test cases that fails.bw_better_autop()
in oik_css_oik_loaded()
... if it's a block theme pass true
when PHP is being run in the command line and false
otherwise. I've chosen 3. - the pragmatic option; it's less change. Note: I'll still have to document the Notice that may still be produced for classic themes.
As discovered in seriouslybonkers.com ( see https://github.com/bobbingwide/bobbingwide/issues/137 ) there are situations where
wpautop()
related processing can cause WordPress 6.6 and above to display the following messageNotice: Function WP_Interactivity_API::_process_directives was called incorrectly. Interactivity directives failed to process in "" due to a missing "DIV" end tag. Please see Debugging in WordPress for more information. (This message was added in version 6.6.0.) in C:\apache\htdocs\wp63\wp-includes\functions.php on line 6087
The message wasn't of much help since the problem was actually an extra
</p>
tag before the<figure>
tag.This extra tag was added by the
wpautop()
code run by oik-css in a slightly different order to that run in vanilla WordPress.Steps to reproduce
Workaround
Either
OR
Note: This alternative workaround may only work in this trivial scenario
Proposed solution
wpautop()
has significantly reduced with block based themes.wpautop()
processing is a right pain.Before altering the behaviour so that oik-css will no longer fiddle around with hook priorities I plan to investigate where the problem actually occurs when oik-css is activated and to see if there's a simple fix.