Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/b-blocks/build/accordion-block/render.php
+++ b/b-blocks/build/accordion-block/render.php
@@ -1,6 +1,11 @@
<?php
+use BBlocksIncSanitize;
+
$id = wp_unique_id( 'bBlocksAccordionBlock-' );
$planClass = BBlocksIncUtils::isPro() ? 'pro' : 'free';
+
+$attributes = Sanitize::attributes($attributes);
+
?>
<div
<?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- get_block_wrapper_attributes() is properly escaped ?>
--- a/b-blocks/build/accordion-block/view.asset.php
+++ b/b-blocks/build/accordion-block/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '29ce1bab2e9069882dc4');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'f6c706d56f9af566dc24');
--- a/b-blocks/build/admin-dashboard.asset.php
+++ b/b-blocks/build/admin-dashboard.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-keyboard-shortcuts'), 'version' => '01ad3e6715e310c7e9ba');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-keyboard-shortcuts'), 'version' => '5dff2872d01e7833c983');
--- a/b-blocks/build/advanced-tabs/view.asset.php
+++ b/b-blocks/build/advanced-tabs/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'd4facb53bcd91463c3ad');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '87a695635ee45061972a');
--- a/b-blocks/build/article-card/view.asset.php
+++ b/b-blocks/build/article-card/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => '65c5396fb9c0226d678d');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => 'b5bef4ee36927ca181c8');
--- a/b-blocks/build/blockquote/render.php
+++ b/b-blocks/build/blockquote/render.php
@@ -1,4 +1,6 @@
<?php
+// Attribute HTML is shown as HTML in the browser: unsafe markup out for authors without unfiltered_html.
+$attributes = BBlocksIncSanitize::attributes( $attributes );
$id = wp_unique_id( 'bBlocksBlockquote-' );
$planClass = BBlocksIncUtils::isPro() ? 'pro' : 'free';
--- a/b-blocks/build/blockquote/view.asset.php
+++ b/b-blocks/build/blockquote/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => '1cba7a42b1c4d58100ee');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => 'aaae8be2954185f0e929');
--- a/b-blocks/build/breadcrumb/view.asset.php
+++ b/b-blocks/build/breadcrumb/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '358f979f8e88374e6777');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '8263467d4631406d90ef');
--- a/b-blocks/build/button/render.php
+++ b/b-blocks/build/button/render.php
@@ -1,4 +1,6 @@
<?php
+// Attribute HTML is shown as HTML in the browser: unsafe markup out for authors without unfiltered_html.
+$attributes = BBlocksIncSanitize::attributes( $attributes );
extract( $attributes );
$id = wp_unique_id( 'bBlocksButton-' );
--- a/b-blocks/build/button/view.asset.php
+++ b/b-blocks/build/button/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch'), 'version' => 'ff38460218e790938dda');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch'), 'version' => 'efb81ec19afe376e6be6');
--- a/b-blocks/build/carousel/view.asset.php
+++ b/b-blocks/build/carousel/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '5c57cb54669383b2ef63');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'e3e827d606087663ffb0');
--- a/b-blocks/build/code-highlight/render.php
+++ b/b-blocks/build/code-highlight/render.php
@@ -1,7 +1,8 @@
<?php
$prefix = 'b-blocks-code-highlight';
-$attributes = BBlocksIncSanitize::attributes( $attributes );
+// `code` is shown as text (escaped by React), never as HTML: a code sample keeps its <script> tags.
+$attributes = BBlocksIncSanitize::attributes( $attributes, [ 'code' ] );
$id = empty( $attributes['blockId'] ) ? wp_unique_id( "$prefix-" ) : "$prefix-" . $attributes['blockId'];
$planClass = BBlocksIncUtils::isPro() ? 'pro' : 'free';
--- a/b-blocks/build/code-highlight/view.asset.php
+++ b/b-blocks/build/code-highlight/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => '7a5b529c5b9bbdea0e0d');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => '451638d70259be9b3a4a');
--- a/b-blocks/build/comparison-table/view.asset.php
+++ b/b-blocks/build/comparison-table/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '63fc874690924dfab6a3');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '8bcc9e2e50ec6e485acd');
--- a/b-blocks/build/container/render.php
+++ b/b-blocks/build/container/render.php
@@ -8,6 +8,9 @@
$innerBlocks = $content;
extract( $attributes );
+// A container saved by an older version can lack some of these (no `height` before November 2024): they print as
+// empty, exactly as before, without a PHP warning on every page view.
+$isFullWidth = $width = $height = $verticalAlign = $horizontalAlign = null;
extract( $content );
$mainSl = "#$id .$prefix";
@@ -15,28 +18,85 @@
$bBlocksContainerCSS = "
#$id{
- min-height: " . Utils::valForZero( $wrapper['minHeight'] ) . ";
+ min-height: " . Utils::valForZero( $wrapper['minHeight'] ?? null ) . ";
}
$mainSl{
align-items: $horizontalAlign;
justify-content: $verticalAlign;
}
$cSl{
- width: " . ( $isFullWidth ? '100%' : Utils::valForZero( $width['desktop'], '100%' ) ) . ";
+ width: " . ( $isFullWidth ? '100%' : Utils::valForZero( $width['desktop'] ?? null, '100%' ) ) . ";
flex-grow: $height;
}
@media only screen and (min-width:641px) and (max-width: 1024px){
$cSl{
- width: " . ( $isFullWidth ? '100%' : Utils::valForZero( $width['tablet'], '100%' ) ) . ";
+ width: " . ( $isFullWidth ? '100%' : Utils::valForZero( $width['tablet'] ?? null, '100%' ) ) . ";
}
}
@media only screen and (max-width: 640px){
$cSl{
- width: " . ( $isFullWidth ? '100%' : Utils::valForZero( $width['mobile'], '100%' ) ) . ";
+ width: " . ( $isFullWidth ? '100%' : Utils::valForZero( $width['mobile'] ?? null, '100%' ) ) . ";
}
}
";
+// Items Layout: direction, justify, align, wrap and gaps of the blocks inside, per device. Every value defaults to
+// empty, and nothing is printed for an empty one — a container saved before these options looks exactly as it did.
+$itemsLayout = $attributes['itemsLayout'] ?? [];
+if ( is_array( $itemsLayout ) && $itemsLayout ) {
+ $itemsAllowed = [
+ 'direction' => [ 'row', 'row-reverse', 'column', 'column-reverse' ],
+ 'justify' => [ 'flex-start', 'center', 'flex-end', 'space-between', 'space-around', 'space-evenly' ],
+ 'align' => [ 'flex-start', 'center', 'flex-end', 'stretch', 'baseline' ],
+ 'wrap' => [ 'nowrap', 'wrap', 'wrap-reverse' ],
+ ];
+ // This container's own content box (not that of a container nested in it) and its direct children — written
+ // without ">", which esc_html() below and the kses of a parent container turn into ">". The children rule
+ // takes off the side margins of the constrained layout and the block gap margin, so the flex gap is the only gap;
+ // in a row the children also size to their content (the 100% width of style.scss would leave nothing to justify or wrap).
+ $itemsBox = "#$id .{$prefix}Content:not(#$id .{$prefix}Content .{$prefix}Content)";
+ $itemsChildren = ":root .wp-block-b-blocks-container .$prefix .{$prefix}Content:where($itemsBox) *:where(:not(#$id .{$prefix}Content * *))";
+ // Separate screen ranges (the same widths as above): a phone never has to undo what the desktop rule did.
+ $itemsRanges = [
+ 'desktop' => '(min-width: 1025px)',
+ 'tablet' => '(min-width: 641px) and (max-width: 1024px)',
+ 'mobile' => '(max-width: 640px)',
+ ];
+ $itemsValue = [ 'direction' => '', 'justify' => '', 'align' => '', 'wrap' => '', 'columnGap' => '', 'rowGap' => '' ];
+ foreach ( $itemsRanges as $itemsDevice => $itemsQuery ) {
+ // Empty on tablet or mobile: the larger screen's value stays.
+ foreach ( $itemsValue as $itemsKey => $itemsOld ) {
+ $itemsNew = $itemsLayout[ $itemsDevice ][ $itemsKey ] ?? '';
+ $itemsNew = is_scalar( $itemsNew ) ? (string) $itemsNew : '';
+ // A gap is 0 or a positive length (a negative gap is not valid CSS). "0" is a real value: it stops the inheritance.
+ if ( isset( $itemsAllowed[ $itemsKey ] ) ? in_array( $itemsNew, $itemsAllowed[ $itemsKey ], true ) : preg_match( '/^(0|d*.?d+(px|em|rem|%|vw|vh))$/', $itemsNew ) ) {
+ $itemsValue[ $itemsKey ] = $itemsNew;
+ }
+ }
+ if ( ! array_filter( $itemsValue, 'strlen' ) ) {
+ continue;
+ }
+ $itemsRow = in_array( $itemsValue['direction'], [ 'row', 'row-reverse' ], true );
+ $bBlocksContainerCSS .= "
+ @media only screen and $itemsQuery{
+ $itemsBox{
+ " . ( $itemsValue['direction'] ? "flex-direction: {$itemsValue['direction']};" : '' ) . "
+ " . ( $itemsValue['justify'] ? "justify-content: {$itemsValue['justify']};" : '' ) . "
+ " . ( $itemsValue['align'] ? "align-items: {$itemsValue['align']};" : '' ) . "
+ " . ( $itemsValue['wrap'] ? "flex-wrap: {$itemsValue['wrap']};" : '' ) . "
+ " . ( '' !== $itemsValue['columnGap'] ? "column-gap: {$itemsValue['columnGap']};" : '' ) . "
+ " . ( '' !== $itemsValue['rowGap'] ? "row-gap: {$itemsValue['rowGap']};" : '' ) . "
+ }
+ $itemsChildren{
+ " . ( $itemsRow ? 'width: auto;' : '' ) . "
+ " . ( $itemsRow || ( $itemsValue['align'] && 'stretch' !== $itemsValue['align'] ) ? ' margin-left: 0 !important; margin-right: 0 !important;' : '' ) . "
+ " . ( $itemsRow || '' !== $itemsValue['rowGap'] ? 'margin-block-start: 0;' : '' ) . "
+ }
+ }
+";
+ }
+}
+
?>
<div
@@ -46,7 +106,7 @@
<style><?php echo esc_html( $bBlocksContainerCSS ); ?></style>
<div class='<?php echo esc_attr( $prefix ) ?>'>
- <?php if( $shape['top']['uploadSvg']['url'] || 'none' !== $shape['top']['type'] ){ ?>
+ <?php if( ( $shape['top']['uploadSvg']['url'] ?? null ) || 'none' !== ( $shape['top']['type'] ?? null ) ){ ?>
<div class='shaped topShaped'></div>
<?php } ?>
@@ -54,7 +114,7 @@
<?php echo wp_kses( $innerBlocks, Utils::allowedInnerHTML() ); ?>
</div>
- <?php if( $shape['bottom']['uploadSvg']['url'] || 'none' !== $shape['bottom']['type'] ){ ?>
+ <?php if( ( $shape['bottom']['uploadSvg']['url'] ?? null ) || 'none' !== ( $shape['bottom']['type'] ?? null ) ){ ?>
<div class='shaped bottomShaped'></div>
<?php } ?>
</div>
--- a/b-blocks/build/countdown/render.php
+++ b/b-blocks/build/countdown/render.php
@@ -1,4 +1,6 @@
<?php
+// Attribute HTML is shown as HTML in the browser: unsafe markup out for authors without unfiltered_html.
+$attributes = BBlocksIncSanitize::attributes( $attributes );
$id = wp_unique_id( 'bBlocksCountdown-' );
$planClass = BBlocksIncUtils::isPro() ? 'pro' : 'free';
?>
--- a/b-blocks/build/countdown/view.asset.php
+++ b/b-blocks/build/countdown/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '2a8b8759375a174aa75a');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '70e12284916c71dc4eee');
--- a/b-blocks/build/cursor/cursor.asset.php
+++ b/b-blocks/build/cursor/cursor.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'aacff72abd81707f9806');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'c6e9ec155d3ac35d1746');
--- a/b-blocks/build/divider/render.php
+++ b/b-blocks/build/divider/render.php
@@ -1,4 +1,6 @@
<?php
+// Attribute HTML is shown as HTML in the browser: unsafe markup out for authors without unfiltered_html.
+$attributes = BBlocksIncSanitize::attributes( $attributes );
$id = wp_unique_id( 'bBlocksDivider-' );
$planClass = BBlocksIncUtils::isPro() ? 'pro' : 'free';
?>
--- a/b-blocks/build/divider/view.asset.php
+++ b/b-blocks/build/divider/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => 'b826f0d1c137c8f1c440');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => '562fc647afdf6d92d661');
--- a/b-blocks/build/dual-color-heading/view.asset.php
+++ b/b-blocks/build/dual-color-heading/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'ce47eebde2e189c10381');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '095bdbb0b0b82d82fa12');
--- a/b-blocks/build/event-card/render.php
+++ b/b-blocks/build/event-card/render.php
@@ -11,6 +11,8 @@
* @var array $attributes Block attributes.
* @var WP_Block $block Block instance.
*/
+// Attribute HTML is shown as HTML in the browser: unsafe markup out for authors without unfiltered_html.
+$attributes = BBlocksIncSanitize::attributes( $attributes );
$id = wp_unique_id( 'bBlocksEventCard-' );
?>
--- a/b-blocks/build/event-card/view.asset.php
+++ b/b-blocks/build/event-card/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => '994dbb28e3cba3a02340');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => 'dc6a8006b550c2fcb002');
--- a/b-blocks/build/google-map/view.asset.php
+++ b/b-blocks/build/google-map/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => '717ff64d52843045ad73');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => '058578d5a5f917de75e2');
--- a/b-blocks/build/hero-section/render.php
+++ b/b-blocks/build/hero-section/render.php
@@ -11,6 +11,8 @@
* @var array $attributes Block attributes.
* @var WP_Block $block Block instance.
*/
+// Attribute HTML is shown as HTML in the browser: unsafe markup out for authors without unfiltered_html.
+$attributes = BBlocksIncSanitize::attributes( $attributes );
$id = wp_unique_id( 'hero-section-' );
?>
--- a/b-blocks/build/hero-section/view.asset.php
+++ b/b-blocks/build/hero-section/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => '2f90b05ba9d60ebd723e');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => '6be9b80635edebb6dd28');
--- a/b-blocks/build/icon-box/view.asset.php
+++ b/b-blocks/build/icon-box/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'a24b12935e95df22a39b');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'a7b97993f3324972677e');
--- a/b-blocks/build/image-comparison/render.php
+++ b/b-blocks/build/image-comparison/render.php
@@ -1,4 +1,6 @@
<?php
+// Attribute HTML is shown as HTML in the browser: unsafe markup out for authors without unfiltered_html.
+$attributes = BBlocksIncSanitize::attributes( $attributes );
$id = wp_unique_id( 'bBlocksImageCompare-' );
$planClass = BBlocksIncUtils::isPro() ? 'pro' : 'free';
?>
--- a/b-blocks/build/image-comparison/view.asset.php
+++ b/b-blocks/build/image-comparison/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-i18n'), 'version' => 'a2f72583a0012545c6e9');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-i18n'), 'version' => '4fd7def247f90c87a9f5');
--- a/b-blocks/build/image-hotspot/view.asset.php
+++ b/b-blocks/build/image-hotspot/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'bf911058eefe6ad378b7');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '7a46688c69a45c7b734e');
--- a/b-blocks/build/index.asset.php
+++ b/b-blocks/build/index.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('jquery', 'react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-blob', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-keyboard-shortcuts', 'wp-primitives', 'wp-rich-text', 'wp-url'), 'version' => '9f5256153d08428a73e5');
+<?php return array('dependencies' => array('jquery', 'react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-blob', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-keyboard-shortcuts', 'wp-primitives', 'wp-rich-text', 'wp-url'), 'version' => '3b7412aad37b4d30c608');
--- a/b-blocks/build/infographic/view.asset.php
+++ b/b-blocks/build/infographic/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => 'c81ec5faee26871c2070');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => '329e507b4b55d3619978');
--- a/b-blocks/build/input-field/render.php
+++ b/b-blocks/build/input-field/render.php
@@ -1,4 +1,6 @@
<?php
+// Attribute HTML is shown as HTML in the browser: unsafe markup out for authors without unfiltered_html.
+$attributes = BBlocksIncSanitize::attributes( $attributes );
$id = wp_unique_id( 'bBlocksInputField-' );
?>
<div <?php echo get_block_wrapper_attributes(); ?> id='<?php echo esc_attr( $id ); ?>' data-attributes='<?php echo esc_attr( wp_json_encode( $attributes ) ); ?>'></div>
No newline at end of file
--- a/b-blocks/build/input-field/view.asset.php
+++ b/b-blocks/build/input-field/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'b63a53f16822101803d4');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '87f67a4ac71ecd8d4e59');
--- a/b-blocks/build/interactive-checklist/render.php
+++ b/b-blocks/build/interactive-checklist/render.php
@@ -9,6 +9,8 @@
*
* @package bBlocks
*/
+// Attribute HTML is shown as HTML in the browser: unsafe markup out for authors without unfiltered_html.
+$attributes = BBlocksIncSanitize::attributes( $attributes );
$id = wp_unique_id( 'bBlocksInteractiveChecklist-' );
$planClass = BBlocksIncUtils::isPro() ? 'pro' : 'free';
--- a/b-blocks/build/interactive-checklist/view.asset.php
+++ b/b-blocks/build/interactive-checklist/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'c6fa79d9693ef08beb62');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '408d14b7e51d5e9b6a7b');
--- a/b-blocks/build/key-takeaways/view.asset.php
+++ b/b-blocks/build/key-takeaways/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => 'a8ec382234944db2f50f');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => '7e45d8dfd819c8d8e14f');
--- a/b-blocks/build/list/view.asset.php
+++ b/b-blocks/build/list/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '6a512f319b65467d767e');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '21d1569c9cc39d403d3c');
--- a/b-blocks/build/logo-slider/render.php
+++ b/b-blocks/build/logo-slider/render.php
@@ -1,4 +1,6 @@
<?php
+// Attribute HTML is shown as HTML in the browser: unsafe markup out for authors without unfiltered_html.
+$attributes = BBlocksIncSanitize::attributes( $attributes );
$id = wp_unique_id( 'bBlocksLogoSlider-' );
$planClass = BBlocksIncUtils::isPro() ? 'pro' : 'free';
?>
--- a/b-blocks/build/logo-slider/view.asset.php
+++ b/b-blocks/build/logo-slider/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '8c672b125e242d453c65');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '1c50d20230da0ee33e5a');
--- a/b-blocks/build/off-canvas/view.asset.php
+++ b/b-blocks/build/off-canvas/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '30cd08618de6d856821c');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'a2241d92d00a7d938414');
--- a/b-blocks/build/one-page-navigation/view.asset.php
+++ b/b-blocks/build/one-page-navigation/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'db351c8733da2478d98d');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'c151015b0983911c04e4');
--- a/b-blocks/build/process-steps/render.php
+++ b/b-blocks/build/process-steps/render.php
@@ -8,6 +8,8 @@
*
* @package bBlocks
*/
+// Attribute HTML is shown as HTML in the browser: unsafe markup out for authors without unfiltered_html.
+$attributes = BBlocksIncSanitize::attributes( $attributes );
$id = wp_unique_id( 'bBlocksProcessSteps-' );
?>
--- a/b-blocks/build/process-steps/view.asset.php
+++ b/b-blocks/build/process-steps/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => '13d3b02c367bec6841f8');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => '1a8942a7e29a28efc12a');
--- a/b-blocks/build/scroll-to-top/view.asset.php
+++ b/b-blocks/build/scroll-to-top/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '64a7da6139a9ffb5528a');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '0b930ed48114ce986e4f');
--- a/b-blocks/build/stat-cards/view.asset.php
+++ b/b-blocks/build/stat-cards/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => 'b476d0b8a4e8709ba831');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-i18n'), 'version' => '8ec340827c92c4df7807');
--- a/b-blocks/build/svg-draw/view.asset.php
+++ b/b-blocks/build/svg-draw/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '875c5050a3c89d4093e3');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'b7ddbf6e4fd434d01de0');
--- a/b-blocks/build/table-body/render.php
+++ b/b-blocks/build/table-body/render.php
@@ -1,4 +1,6 @@
<?php
+// Attribute HTML is shown as HTML in the browser: unsafe markup out for authors without unfiltered_html.
+$attributes = BBlocksIncSanitize::attributes( $attributes );
$id = wp_unique_id( 'bBlocksTableBody-' );
$normalBg = $attributes['styles']['normal']['bg'];
--- a/b-blocks/build/table-of-content/render.php
+++ b/b-blocks/build/table-of-content/render.php
@@ -1,4 +1,6 @@
<?php
+// Attribute HTML is shown as HTML in the browser: unsafe markup out for authors without unfiltered_html.
+$attributes = BBlocksIncSanitize::attributes( $attributes );
if ( !defined( 'ABSPATH' ) ) { exit; }
$id = wp_unique_id( 'tbcnbBlock-' );
--- a/b-blocks/build/table-of-content/view.asset.php
+++ b/b-blocks/build/table-of-content/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'b5cb413ab939c5a59c74');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '0e32e176bc4622ca6bfe');
--- a/b-blocks/build/table-row/render.php
+++ b/b-blocks/build/table-row/render.php
@@ -1,4 +1,6 @@
<?php
+// Attribute HTML is shown as HTML in the browser: unsafe markup out for authors without unfiltered_html.
+$attributes = BBlocksIncSanitize::attributes( $attributes );
$id = wp_unique_id( 'bBlocksTableRow-' );
$normalBg = $attributes['styles']['normal']['bg'];
--- a/b-blocks/build/template-library.asset.php
+++ b/b-blocks/build/template-library.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-dom-ready', 'wp-i18n'), 'version' => 'a3e5d6493bda7d808a3a');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-dom-ready', 'wp-i18n'), 'version' => 'bfa56f21b4a527e05198');
--- a/b-blocks/build/testimonials/render.php
+++ b/b-blocks/build/testimonials/render.php
@@ -1,4 +1,6 @@
<?php
+// Attribute HTML is shown as HTML in the browser: unsafe markup out for authors without unfiltered_html.
+$attributes = BBlocksIncSanitize::attributes( $attributes );
$id = wp_unique_id( 'bBlocksTestimonials-' );
?>
<div
--- a/b-blocks/build/testimonials/view.asset.php
+++ b/b-blocks/build/testimonials/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '8f5b7089bf975f3b1038');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'cd431a76d7e8113fbf65');
--- a/b-blocks/build/woo-product-grid/view.asset.php
+++ b/b-blocks/build/woo-product-grid/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'b71e96fed16881724dc7');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'acab999267c8275d645a');
--- a/b-blocks/build/woo-product-price/view.asset.php
+++ b/b-blocks/build/woo-product-price/view.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => 'd158ea4e3d01437bf23c');
+<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime'), 'version' => '8308e74e624961f1b267');
--- a/b-blocks/includes/Constants.php
+++ b/b-blocks/includes/Constants.php
@@ -7,7 +7,7 @@
$bb_host = isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : '';
$bb_isLocal = $bb_host && ( 0 === strpos( $bb_host, 'localhost' ) || 0 === strpos( $bb_host, '127.0.0.1' ) || preg_match( '/.(local|test|ddev.site)(:d+)?$/', $bb_host ) );
-define( 'B_BLOCKS_VERSION', $bb_isLocal ? time() : '2.1.15' );
+define( 'B_BLOCKS_VERSION', $bb_isLocal ? time() : '2.1.16' );
define( 'B_BLOCKS_DIR_PATH', plugin_dir_path( B_BLOCKS_FILE ) );
define( 'B_BLOCKS_DIR_URL', plugin_dir_url( B_BLOCKS_FILE ) );
define( 'B_BLOCKS_HAS_PRO', 'b-blocks-pro/plugin.php' === plugin_basename( B_BLOCKS_FILE ) );
--- a/b-blocks/includes/Performance.php
+++ b/b-blocks/includes/Performance.php
@@ -0,0 +1,3961 @@
+<?php
+namespace BBlocksInc;
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
+}
+
+/**
+ * Dashboard → Settings → Performance.
+ *
+ * Stores the settings (`bBlocksPerformance` option, saved through the `bblocks_performance`
+ * AJAX action used by src/admin/Dashboard/Pages/Settings/Performance/Performance.js) and runs
+ * every feature they switch on: page cache, image, asset, font and platform optimizations.
+ *
+ * Files written by this class live in wp-content/cache/b-blocks/ (pages/, css/, fonts/).
+ */
+class BBlocksPerformance {
+
+ const OPTION = 'bBlocksPerformance';
+ const FAILS = 'bBlocksPerformancePreloadFails';
+ const HF_VERSION = 'bBlocksPerformanceHFVersion';
+ const PRELOAD_HOOK = 'bblocks_performance_preload';
+ const REBUILD_HOOK = 'bblocks_performance_rebuild';
+ const FONTS_HOOK = 'bblocks_performance_fonts';
+ const ALT_META = '_bblocks_missing_alt';
+ const WEBP_USED = 'bBlocksPerformanceWebpUsed';
+
+ /** @var array Current settings, keyed by tab. */
+ private $s;
+
+ /** Images seen in bBlocks blocks on this request (lazy-load / LCP). */
+ private $imgCount = 0;
+ private $lcp = null;
+
+ /** How many bBlocks blocks are rendering right now — only the outermost one rewrites its images. */
+ private $bbDepth = 0;
+
+ /** Header/footer cache: queue snapshots taken before a template part renders. */
+ private $hfBefore = [];
+
+ /** Set when this page must not be stored (e.g. a Google font is still downloading). */
+ private $skipStore = false;
+
+ /** This page still points at Google because a font download failed: its cached copy must not live forever. */
+ private $fontFallback = false;
+
+ /** Local Google Fonts stylesheets used on this page (for font preloads). */
+ private $localFontCss = [];
+
+ /** Result of the alt-text check for the post being saved. */
+ private $altMissing = null;
+
+ /** Full-page cache on and no other page cache plugin running. */
+ private $pageCache = false;
+
+ /** Permalinks captured before a save/trash, so the old URL's cached copy is purged too. */
+ private $oldLinks = [];
+
+ /** A page's title before a save: a new title renews cached headers and footers that list pages. */
+ private $oldTitles = [];
+
+ /** "author|date" of a blog post before a save: its old author and date archives list it too. */
+ private $oldLists = [];
+
+ /** Posts purged in full in this request, and products whose stock was handled: an order fires several hooks per product. */
+ private $productSeen = [];
+
+ /** A large image (a cover hero, a featured image) rendered before any bBlocks block: it is the page's main image. */
+ private $largeImageSeen = false;
+
+ /** Another plugin flushed the page buffer part way: the rest of this page is passed on untouched and never stored. */
+ private $flushed = false;
+
+ /** Products in the middle of wc_update_product_stock(): their save() is a quantity change. */
+ private $stockOnly = [];
+
+ /** Archive addresses of a term before an edit (edit_terms), purged after it (edited_term): the slug or parent may change. */
+ private $oldTermLinks = [];
+
+ /** Status of each row in a posts list, shared by its row actions and its Cache column. */
+ private $listStatus = [];
+
+ /** The admin bar's "N pages cached" transient was dropped in this request already. */
+ private $statsDropped = false;
+
+ /** True while WordPress processes a new JPEG upload (compression applies only then). */
+ private $uploading = false;
+
+ /** True while the REST API saves a post on a user's behalf (block editor). */
+ private $editorSave = false;
+
+ /** A block that needs the Dashicons font has rendered on this page. */
+ private $needDashicons = false;
+
+ /** Cache key of the template lookup now running (see templates_from_cache()). */
+ private $tplPendingKey = '';
+
+ public function __construct() {
+ $this->s = self::settings();
+ $caching = $this->s['caching'];
+ $images = $this->s['images'];
+ $assets = $this->s['assets'];
+ $fonts = $this->s['fonts'];
+ $platform = $this->s['platform'];
+
+ // Always: the settings screen, and a deactivation clean-up that only clears our own cron event.
+ add_action( 'wp_ajax_bblocks_performance', [ $this, 'ajax' ] );
+ register_deactivation_hook( B_BLOCKS_FILE, [ __CLASS__, 'deactivate' ] );
+
+ // Everything below is registered only when a setting needs it, so with Performance
+ // switched off nothing runs: no output buffer, no DB writes, no cron, no files.
+ $this->pageCache = $caching['fullPage'] && '' === self::page_cache_conflict();
+
+ // ---- Page cache: answer straight from disk before the rest of WordPress loads. ----
+ if ( $this->pageCache ) {
+ $this->serve_cached_page();
+ }
+
+ if ( $this->needs_buffer() ) {
+ add_action( 'template_redirect', [ $this, 'start_buffer' ], 999 );
+ }
+ if ( $this->pageCache && $caching['background'] ) {
+ add_action( 'init', [ $this, 'schedule_preload' ] );
+ add_action( self::PRELOAD_HOOK, [ $this, 'preload' ] );
+ }
+ if ( $this->pageCache && $caching['rebuildOnSave'] ) {
+ add_action( self::REBUILD_HOOK, [ $this, 'rebuild' ] );
+ }
+ if ( $fonts['hostLocal'] && ! $fonts['disableGoogle'] ) {
+ add_action( self::FONTS_HOOK, [ $this, 'download_google_font' ] );
+ }
+
+ // Purging only matters when something is cached.
+ if ( $this->pageCache || $caching['inlineCssFiles'] || $this->header_footer_active() || $this->templates_active() ) {
+ add_action( 'pre_post_update', [ $this, 'remember_permalink' ] );
+ add_action( 'wp_trash_post', [ $this, 'remember_permalink' ] );
+ add_action( 'transition_post_status', [ $this, 'on_post_status' ], 10, 3 );
+ add_action( 'before_delete_post', [ $this, 'on_delete_post' ] );
+ add_action( 'wp_set_comment_status', [ $this, 'on_comment' ] );
+ add_action( 'comment_post', [ $this, 'on_comment' ], 10, 2 );
+ // An approved comment edited, or deleted for good (wp_delete_comment() reports the status only once it is gone).
+ add_action( 'edit_comment', [ $this, 'on_comment' ] );
+ add_action( 'delete_comment', [ $this, 'on_comment' ] );
+ // A category or tag added to (or taken off) a published post: both archives change. The block editor
+ // saves terms after the post, so the save itself still sees the old ones.
+ add_action( 'set_object_terms', [ $this, 'purge_terms' ], 10, 6 );
+ // A term renamed, moved or deleted: its archive (old and new address), its parents, and the posts that name it.
+ add_action( 'edit_terms', [ $this, 'on_term_change' ], 10, 2 );
+ add_action( 'edited_term', [ $this, 'on_term_change' ], 10, 3 );
+ add_action( 'pre_delete_term', [ $this, 'on_term_change' ], 10, 2 );
+ // An author's name or slug: the author archive (old and new address) and the bylines on their posts.
+ add_action( 'profile_update', [ $this, 'on_author_change' ], 10, 2 );
+ // WooCommerce: an order or an import changes stock without saving the product, and a price-only save (a sale,
+ // a scheduled sale starting or ending, the REST API) does not go through wp_update_post() either.
+ // An order line runs wc_update_product_stock(): before_set_stock, then save() (woocommerce_update_product), then
+ // set_stock — the save in between is that quantity change, not an edit.
+ foreach ( [ 'woocommerce_product_before_set_stock', 'woocommerce_variation_before_set_stock', 'woocommerce_product_set_stock', 'woocommerce_variation_set_stock', 'woocommerce_product_set_stock_status', 'woocommerce_variation_set_stock_status', 'woocommerce_update_product', 'woocommerce_update_product_variation' ] as $hook ) {
+ add_action( $hook, [ $this, 'on_product_change' ] );
+ }
+ // A save is over: a later change to the same post in this request (an import setting the featured image at
+ // the end) is purged again.
+ add_action( 'wp_after_insert_post', [ $this, 'on_save_done' ], 999 );
+ foreach ( [ 'switch_theme', 'customize_save_after', 'wp_update_nav_menu', 'upgrader_process_complete', 'activated_plugin', 'deactivated_plugin', 'update_option_sidebars_widgets' ] as $hook ) {
+ add_action( $hook, [ $this, 'purge_all' ] );
+ }
+ // Site-wide settings every page shows (title, permalinks, front page, language, dates…), block widgets, and
+ // sticky posts (stick_post() changes only an option).
+ add_action( 'updated_option', [ $this, 'on_site_option' ] );
+ // The first time a setting is stored (WPLANG on a site still in English, a new widget) is add_option().
+ add_action( 'added_option', [ $this, 'on_site_option' ] );
+ // A featured image set or removed without a post save (imports, plugins, set_post_thumbnail()).
+ foreach ( [ 'added_post_meta', 'updated_post_meta', 'deleted_post_meta' ] as $hook ) {
+ add_action( $hook, [ $this, 'on_post_meta' ], 10, 3 );
+ }
+ // An image deleted from the Media Library: WordPress removes it as the featured image of every post at once
+ // (deleted_post_meta without a post), so the posts that showed it are found here first.
+ add_action( 'delete_attachment', [ $this, 'on_attachment_delete' ] );
+ }
+
+ // "bBlocks Cache" in the admin bar: only while this page cache is the one running.
+ if ( $this->pageCache ) {
+ add_action( 'admin_bar_menu', [ $this, 'admin_bar_cache_menu' ], 100 );
+ add_action( 'admin_post_bblocks_cache', [ $this, 'cache_action' ] );
+ add_action( 'wp_ajax_bblocks_cache', [ $this, 'cache_action' ] );
+ add_action( 'wp_enqueue_scripts', [ $this, 'cache_menu_assets' ] );
+ add_action( 'admin_enqueue_scripts', [ $this, 'cache_menu_assets' ] );
+ add_action( 'admin_notices', [ $this, 'cache_action_notice' ] );
+ add_action( 'wp_footer', [ $this, 'cache_action_notice' ] );
+ // Posts, Pages and other lists: "Cache now" / "Clear cache" per row and as bulk actions.
+ add_action( 'load-edit.php', [ $this, 'cache_list_screen' ] );
+ add_filter( 'removable_query_args', [ $this, 'cache_removable_args' ] );
+ }
+
+ // `wp bblocks-cache …`: the admin bar menu's actions from the command line (deploy scripts, cron, debugging).
+ if ( defined( 'WP_CLI' ) && WP_CLI && class_exists( 'WP_CLI' ) ) {
+ WP_CLI::add_command( 'bblocks-cache status', [ $this, 'cli_status' ], [
+ 'shortdesc' => __( 'Whether a page is cached, and which copies exist.', 'b-blocks' ),
+ 'synopsis' => [ [ 'type' => 'positional', 'name' => 'url', 'description' => __( 'A page of this site: a full address or a path such as /about/.', 'b-blocks' ) ] ],
+ ] );
+ WP_CLI::add_command( 'bblocks-cache purge', [ $this, 'cli_purge' ], [
+ 'shortdesc' => __( 'Clear one page, or the whole page cache with --all.', 'b-blocks' ),
+ 'synopsis' => [
+ [ 'type' => 'positional', 'name' => 'url', 'optional' => true, 'description' => __( 'A page of this site.', 'b-blocks' ) ],
+ [ 'type' => 'flag', 'name' => 'all', 'optional' => true, 'description' => __( 'Clear every cached page.', 'b-blocks' ) ],
+ ],
+ ] );
+ WP_CLI::add_command( 'bblocks-cache preload', [ $this, 'cli_preload' ], [
+ 'shortdesc' => __( 'Cache the pages nobody has visited yet, as the hourly run does.', 'b-blocks' ),
+ 'synopsis' => [ [ 'type' => 'assoc', 'name' => 'limit', 'optional' => true, 'description' => __( 'Page renders in this run (default: "Pages per hour").', 'b-blocks' ) ] ],
+ ] );
+ WP_CLI::add_command( 'bblocks-cache stats', [ $this, 'cli_stats' ], [ 'shortdesc' => __( 'How many copies are cached, and their size on disk.', 'b-blocks' ) ] );
+ }
+
+ if ( $this->header_footer_active() ) {
+ add_filter( 'pre_render_block', [ $this, 'header_footer_from_cache' ], 10, 2 );
+ add_filter( 'render_block_core/template-part', [ $this, 'header_footer_to_cache' ], 10, 2 );
+ }
+
+ // Template lookups only pay off with a persistent object cache (see the notice in the UI).
+ if ( $this->templates_active() ) {
+ add_filter( 'pre_get_block_templates', [ $this, 'templates_from_cache' ], 10, 3 );
+ add_filter( 'get_block_templates', [ $this, 'templates_to_cache' ], 10, 3 );
+ add_filter( 'pre_get_block_template', [ $this, 'template_from_cache' ], 10, 3 );
+ add_filter( 'get_block_template', [ $this, 'template_to_cache' ], 10, 3 );
+ }
+
+ // ---- Images ----
+ if ( $images['lazyLoad'] || $images['dimensions'] || $images['srcset'] || $images['preloadLcp'] ) {
+ add_filter( 'render_block_data', [ $this, 'enter_block' ] );
+ add_filter( 'render_block', [ $this, 'optimize_block_images' ], 10, 2 );
+ }
+ if ( $images['requireFilenames'] ) {
+ add_filter( 'wp_handle_upload_prefilter', [ $this, 'check_filename' ] );
+ }
+ if ( $images['webp'] || $this->upload_quality() ) {
+ add_filter( 'wp_generate_attachment_metadata', [ $this, 'process_upload' ], 20, 3 );
+ }
+ if ( $images['webp'] ) {
+ add_filter( 'wp_update_attachment_metadata', [ $this, 'webp_after_edit' ], 10, 2 );
+ }
+ // WebP copies made earlier are removed with their image even after the option is turned off.
+ // Also after the option is turned off — checked when an image is deleted, not on every request (a missing option
+ // is a database query each time without an object cache).
+ add_action( 'delete_attachment', [ $this, 'delete_webp_copies' ] );
+ if ( $this->upload_quality() ) {
+ // Lower JPEG quality only while a new upload is being processed — never when someone edits an image.
+ add_filter( 'wp_handle_upload', [ $this, 'mark_upload' ] );
+ add_filter( 'wp_editor_set_quality', [ $this, 'editor_quality' ], 10, 2 );
+ }
+ if ( $images['requireAlt'] ) {
+ add_action( 'init', [ $this, 'register_alt_meta' ] );
+ add_action( 'rest_api_init', [ $this, 'watch_rest_saves' ] );
+ add_filter( 'wp_insert_post_data', [ $this, 'check_alt_text' ], 10, 2 );
+ add_action( 'wp_insert_post', [ $this, 'save_alt_result' ] );
+ add_action( 'enqueue_block_editor_assets', [ $this, 'alt_editor_notice' ] );
+ add_action( 'wp_enqueue_media', [ $this, 'alt_media_guard' ] );
+ add_action( 'admin_notices', [ $this, 'alt_admin_notice' ] );
+ }
+
+ // ---- Assets ----
+ if ( $assets['assetFiles'] ) {
+ add_filter( 'render_block', [ $this, 'mark_block_styles' ], 20, 2 );
+ add_action( 'save_post', [ $this, 'delete_post_asset_files' ] );
+ // Deleted for good (Empty Trash, or straight away): its file would be left behind forever.
+ add_action( 'before_delete_post', [ $this, 'delete_post_asset_files' ] );
+ }
+ if ( $assets['combineCss'] ) {
+ add_filter( 'should_load_separate_core_block_assets', [ $this, 'separate_block_assets' ] );
+ add_filter( 'styles_inline_size_limit', [ $this, 'inline_size_limit' ] );
+ }
+ if ( $assets['cssPerBlock'] ) {
+ add_filter( 'should_load_separate_core_block_assets', [ $this, 'separate_block_assets' ] );
+ add_filter( 'should_load_block_assets_on_demand', [ $this, 'separate_block_assets' ] );
+ }
+ if ( $assets['deferScripts'] ) {
+ add_action( 'wp_print_scripts', [ $this, 'defer_scripts' ], 1 );
+ add_action( 'wp_print_footer_scripts', [ $this, 'defer_scripts' ], 1 );
+ }
+ if ( $assets['removeQuery'] ) {
+ add_filter( 'style_loader_src', [ $this, 'remove_version' ], 20 );
+ add_filter( 'script_loader_src', [ $this, 'remove_version' ], 20 );
+ // Script modules (navigation, Interactivity API…) get their URLs from a separate filter.
+ add_filter( 'script_module_loader_src', [ $this, 'remove_version' ], 20 );
+ }
+ if ( '' !== trim( $assets['preconnect'] ) || $fonts['disableGoogle'] || $platform['disableEmojis'] ) {
+ add_filter( 'wp_resource_hints', [ $this, 'resource_hints' ], 10, 2 );
+ }
+
+ // ---- Platform (front-end pages only; the admin, feeds and emails are left alone) ----
+ if ( $platform['disableEmojis'] ) {
+ remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
+ remove_action( 'wp_enqueue_scripts', 'wp_enqueue_emoji_styles' );
+ remove_action( 'wp_print_styles', 'print_emoji_styles' );
+ }
+ if ( $platform['disableEmbeds'] ) {
+ remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 4 );
+ remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
+ remove_action( 'wp_head', 'wp_oembed_add_host_js' );
+ remove_filter( 'embed_oembed_html', 'wp_maybe_enqueue_oembed_host_js' );
+ add_action( 'wp_enqueue_scripts', [ $this, 'dequeue_embed' ], 100 );
+ }
+ if ( $platform['disableDashicons'] ) {
+ add_filter( 'render_block', [ $this, 'watch_dashicons' ], 10, 2 );
+ add_action( 'wp_enqueue_scripts', [ $this, 'dequeue_dashicons' ], 100 );
+ }
+ if ( $platform['removeJqueryMigrate'] ) {
+ add_action( 'wp_default_scripts', [ $this, 'remove_jquery_migrate' ] );
+ }
+ if ( $platform['heartbeat'] ) {
+ add_filter( 'heartbeat_settings', [ $this, 'heartbeat_settings' ] );
+ }
+ if ( $platform['touchTargets'] ) {
+ add_action( 'wp_head', [ $this, 'touch_targets_css' ], 100 );
+ }
+ }
+
+ /** Any setting that rewrites front-end HTML needs the output buffer. */
+ private function needs_buffer() {
+ $c = $this->s['caching'];
+ $i = $this->s['images'];
+ $a = $this->s['assets'];
+ $f = $this->s['fonts'];
+ return $this->pageCache || $c['inlineCssFiles'] || $a['minifyInline'] || $a['delayJs'] || $i['webp'] || $i['preloadLcp']
+ || $a['assetFiles'] || $a['criticalCss'] || $a['asyncCss']
+ || $f['preloadFonts'] || $f['fontSwap'] || $f['hostLocal'] || $f['usedWeights'] || $f['disableGoogle'];
+ }
+
+ /**
+ * Name of another page cache already running here, or ''. Two page caches would serve each
+ * other's stale copies, so bBlocks then leaves page caching to that one.
+ * Read from the active-plugins list: at this point most other plugins are not loaded yet.
+ */
+ public static function page_cache_conflict() {
+ if ( defined( 'WP_CACHE' ) && WP_CACHE && file_exists( WP_CONTENT_DIR . '/advanced-cache.php' ) ) {
+ return __( 'Another page cache (advanced-cache.php)', 'b-blocks' );
+ }
+ $known = [
+ 'wp-rocket/wp-rocket.php' => 'WP Rocket',
+ 'litespeed-cache/litespeed-cache.php' => 'LiteSpeed Cache',
+ 'w3-total-cache/w3-total-cache.php' => 'W3 Total Cache',
+ 'wp-super-cache/wp-cache.php' => 'WP Super Cache',
+ 'wp-fastest-cache/wpFastestCache.php' => 'WP Fastest Cache',
+ 'cache-enabler/cache-enabler.php' => 'Cache Enabler',
+ 'breeze/breeze.php' => 'Breeze',
+ 'sg-cachepress/sg-cachepress.php' => 'SiteGround Speed Optimizer',
+ 'hummingbird-performance/wp-hummingbird.php' => 'Hummingbird',
+ 'wp-optimize/wp-optimize.php' => 'WP-Optimize',
+ 'comet-cache/comet-cache.php' => 'Comet Cache',
+ 'swift-performance-lite/performance.php' => 'Swift Performance',
+ ];
+ $active = (array) get_option( 'active_plugins', [] );
+ if ( is_multisite() ) {
+ $active = array_merge( $active, array_keys( (array) get_site_option( 'active_sitewide_plugins', [] ) ) );
+ }
+ foreach ( $known as $file => $name ) {
+ if ( in_array( $file, $active, true ) ) {
+ return $name;
+ }
+ }
+ return '';
+ }
+
+ /**
+ * Header/footer caching needs WordPress 6.8+: before that, layout class names are counters
+ * (a cached header would clash with the page), and script modules cannot be replayed.
+ */
+ private static function header_footer_supported() {
+ return function_exists( 'wp_unique_id_from_values' ) && function_exists( 'wp_script_modules' ) && method_exists( 'WP_Script_Modules', 'get_queue' ) && function_exists( 'wp_interactivity_state' );
+ }
+
+ /**
+ * Block themes only. In a classic theme the content renders after <head>, so per-block CSS is printed
+ * in the footer and the page flashes unstyled — unless WordPress itself moves it up (6.9+ does, and
+ * then turns this on by its own rules, respecting a theme that opts out). Either way: leave it to WordPress.
+ */
+ public function separate_block_assets( $load ) {
+ return wp_is_block_theme() ? true : $load;
+ }
+
+ private function header_footer_active() {
+ return $this->s['caching']['headerFooter'] && self::header_footer_supported();
+ }
+
+ private function templates_active() {
+ return $this->s['caching']['templateLookups'] && wp_using_ext_object_cache();
+ }
+
+ /* =====================================================================
+ * Settings + AJAX
+ * ===================================================================== */
+
+ /** Defaults — same shape and string-number values as the React screen. */
+ public static function defaults() {
+ // The settings this plugin is tuned and tested with — also what "Apply recommended settings" switches to
+ // (src/admin/Dashboard/Pages/Settings/Performance/Performance.js, `recommended`: keep the two in step).
+ return [
+ 'caching' => [ 'fullPage' => true, 'cacheWhich' => 'all', 'expireHours' => '0', 'allowedQuery' => '', 'neverCache' => '', 'neverCookies' => '', 'alwaysPurge' => '', 'preloadUrls' => '', 'rebuildOnSave' => false, 'compressed' => true, 'separateMobile' => true, 'background' => true, 'pagesPerHour' => '20', 'inlineCssFiles' => true, 'inlineBelow' => '2048', 'headerFooter' => true, 'headerFooterExpire' => '43200', 'templateLookups' => true ],
+ 'images' => [ 'lazyLoad' => true, 'eagerCount' => '1', 'dimensions' => true, 'srcset' => true, 'preloadLcp' => true, 'compression' => '5', 'webp' => true, 'optimizeUploads' => true, 'requireFilenames' => true, 'requireAlt' => true ],
+ 'assets' => [ 'assetFiles' => true, 'criticalCss' => true, 'criticalBlocks' => '15', 'asyncCss' => true, 'asyncCssMin' => '8192', 'combineCss' => true, 'inlineThreshold' => '80000', 'cssPerBlock' => true, 'deferScripts' => true, 'deferExclude' => '', 'delayJs' => true, 'delayTimeout' => '5', 'minifyInline' => true, 'removeQuery' => true, 'preconnect' => '' ],
+ 'fonts' => [ 'fontSwap' => true, 'preloadFonts' => true, 'preloadMax' => '2', 'hostLocal' => true, 'disableGoogle' => false, 'usedWeights' => true ],
+ 'platform' => [ 'disableEmojis' => true, 'disableEmbeds' => true, 'disableDashicons' => true, 'removeJqueryMigrate' => true, 'heartbeat' => true, 'heartbeatInterval' => '60', 'touchTargets' => true ],
+ ];
+ }
+
+ /** Every toggle off, Compression strength "off": how Performance behaved before it had on-by-default options. */
+ public static function all_off() {
+ $s = self::defaults();
+ foreach ( $s as $tab => $keys ) {
+ foreach ( $keys as $key => $value ) {
+ if ( is_bool( $value ) ) {
+ $s[ $tab ][ $key ] = false;
+ }
+ }
+ }
+ $s['images']['compression'] = 'off';
+ return $s;
+ }
+
+ /**
+ * A fresh install (gets the on-by-default options), as opposed to a site that ran bBlocks before
+ * (keeps everything off until its owner saves the Performance screen). Read from the install data
+ * Freemius keeps for bBlocks: no previous plugin version, and installed within the last day.
+ * Missing or odd data counts as an existing install — the side where nothing changes.
+ */
+ public static function is_new_install( $fs ) {
+ if ( ! is_array( $fs ) || empty( $fs['install_timestamp'] ) ) {
+ return false;
+ }
+ if ( ! empty( $fs['plugin_last_version'] ) || ! empty( $fs['plugin_upgrade_mode'] ) ) {
+ return false;
+ }
+ return time() - (int) $fs['install_timestamp'] < DAY_IN_SECONDS;
+ }
+
+ /** Saved settings, each tab filled in with defaults for keys it does not have yet. */
+ public static function settings() {
+ $stored = get_option( self::OPTION, null );
+
+ // First run on this site: decide once which defaults it gets, and keep that decision, so a
+ // new install is not reclassified as "existing" a day later.
+ if ( ! is_array( $stored ) ) {
+ $accounts = get_option( 'fs_accounts', [] );
+ $stored = self::is_new_install( $accounts['plugin_data']['b-blocks'] ?? null ) ? self::defaults() : self::all_off();
+ update_option( self::OPTION, $stored, true );
+ }
+
+ // Same rules as a save: missing keys get defaults, and a value stored by other code ("false", an array…) gets its proper type.
+ return self::sanitize( $stored );
+ }
+
+ private static function sanitize( $raw ) {
+ $choices = [
+ 'caching.cacheWhich' => [ 'all', 'bblocks' ],
+ 'images.compression' => [ 'off', '1', '2', '3', '5' ],
+ ];
+ $out = [];
+ foreach ( self::defaults() as $tab => $keys ) {
+ foreach ( $keys as $key => $default ) {
+ $value = $raw[ $tab ][ $key ] ?? $default;
+ if ( ! is_scalar( $value ) ) {
+ $value = $default;
+ }
+ if ( is_bool( $default ) ) {
+ $out[ $tab ][ $key ] = filter_var( $value, FILTER_VALIDATE_BOOLEAN );
+ } elseif ( isset( $choices[ "$tab.$key" ] ) ) {
+ $out[ $tab ][ $key ] = in_array( (string) $value, $choices[ "$tab.$key" ], true ) ? (string) $value : $default;
+ } elseif ( is_numeric( $default ) ) {
+ $out[ $tab ][ $key ] = '' === $value ? $default : (string) absint( $value );
+ } elseif ( in_array( "$tab.$key", [ 'caching.neverCache', 'caching.alwaysPurge', 'caching.preloadUrls' ], true ) ) {
+ // Addresses: sanitize_text_field() deletes %XX, so one pasted from the address bar (a Bengali slug) is kept
+ // as readable text instead of losing its letters.
+ $out[ $tab ][ $key ] = sanitize_text_field( rawurldecode( (string) $value ) );
+ } else {
+ $out[ $tab ][ $key ] = sanitize_text_field( (string) $value );
+ }
+ }
+ }
+ $out['platform']['heartbeatInterval'] = (string) min( 300, max( 15, (int) $out['platform']['heartbeatInterval'] ) );
+ $out['assets']['delayTimeout'] = (string) min( 30, max( 1, (int) $out['assets']['delayTimeout'] ) );
+ $out['caching']['pagesPerHour'] = (string) max( 1, (int) $out['caching']['pagesPerHour'] );
+ $out['assets']['criticalBlocks'] = (string) min( 50, max( 1, (int) $out['assets']['criticalBlocks'] ) );
+ $out['assets']['asyncCssMin'] = (string) max( 1024, (int) $out['assets']['asyncCssMin'] );
+ // The same ranges as the screen's controls.
+ $out['images']['eagerCount'] = (string) min( 10, (int) $out['images']['eagerCount'] );
+ $out['fonts']['preloadMax'] = (string) min( 6, max( 1, (int) $out['fonts']['preloadMax'] ) );
+ $out['caching']['headerFooterExpire'] = (string) max( 60, (int) $out['caching']['headerFooterExpire'] );
+ return $out;
+ }
+
+ /**
+ * POST bblocks_performance { _wpnonce, do: get|save|purge, settings?: JSON }.
+ * Always answers with { settings, stats, objectCache }.
+ */
+ public function ajax() {
+ $nonce = sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ?? '' ) );
+ if ( ! wp_verify_nonce( $nonce, 'wp_ajax' ) ) {
+ wp_send_json_error( [ 'message' => __( 'Invalid Request', 'b-blocks' ) ] );
+ }
+ if ( ! current_user_can( 'manage_options' ) ) {
+ wp_send_json_error( [ 'message' => __( 'Unauthorized', 'b-blocks' ) ] );
+ }
+
+ $do = sanitize_key( wp_unslash( $_POST['do'] ?? 'get' ) );
+
+ if ( 'save' === $do ) {
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- JSON, every value is sanitized in sanitize().
+ $raw = json_decode( wp_unslash( $_POST['settings'] ?? '' ), true );
+ if ( ! is_array( $raw ) ) {
+ wp_send_json_error( [ 'message' => __( 'Settings could not be read.', 'b-blocks' ) ] );
+ }
+ $this->s = self::sanitize( $raw );
+ // update_option() is also false when nothing changed; only a value that is not stored now (read from the database,
+ // not this request's startup copy) is a failed save.
+ if ( ! update_option( self::OPTION, $this->s, true ) ) {
+ wp_cache_delete( 'alloptions', 'options' );
+ wp_cache_delete( self::OPTION, 'options' );
+ if ( self::settings() !== $this->s ) {
+ wp_send_json_error( [ 'message' => __( 'The settings could not be saved. Try again.', 'b-blocks' ) ] );
+ }
+ }
+ $this->schedule_preload();
+ $this->purge_all();
+ }
+
+ if ( 'purge' === $do ) {
+ $this->purge_all();
+ }
+ // After a save or "Purge Cache", the next preload a minute later rather than within the hour (one run: WordPress
+ // drops a duplicate within 10 minutes). Only while the page cache with background caching is on now.
+ if ( in_array( $do, [ 'save', 'purge' ], true ) && $this->s['caching']['fullPage'] && $this->s['caching']['background'] && '' === self::page_cache_conflict() ) {
+ wp_schedule_single_event( time() + MINUTE_IN_SECONDS, self::PRELOAD_HOOK, [ 'warm' ] );
+ }
+
+ wp_send_json_success( [
+ 'settings' => $this->s,
+ 'stats' => $this->stats(),
+ 'objectCache' => wp_using_ext_object_cache(),
+ 'status' => [
+ 'pageCacheConflict' => self::page_cache_conflict(),
+ 'headerFooterSupported' => self::header_footer_supported(),
+ 'blockTheme' => wp_is_block_theme(),
+ ],
+ ] );
+ }
+
+ /**
+ * One-click fix from the Site Scanner: switch one toggle on with the same rules as a save on the
+ * Performance screen — sanitize, store, then reschedule and purge exactly as ajax() does.
+ * An instance is made without the constructor, so no hook is registered a second time.
+ */
+ public static function enable( $group, $key ) {
+ // Start from the stored row, not the copy this request loaded at startup: another tab may have saved since.
+ wp_cache_delete( 'alloptions', 'options' );
+ wp_cache_delete( self::OPTION, 'options' );
+ $s = self::settings();
+ if ( ! isset( $s[ $group ][ $key ] ) || ! is_bool( $s[ $group ][ $key ] ) ) {
+ return false;
+ }
+ $s[ $group ][ $key ] = true;
+
+ $perf = ( new ReflectionClass( self::class ) )->newInstanceWithoutConstructor();
+ $written = update_option( self::OPTION, self::sanitize( $s ), true );
+
+ // Judge by what is stored now: update_option() is also false when this is stored already (switched on in another
+ // tab), and a filter can change or refuse what gets stored.
+ wp_cache_delete( 'alloptions', 'options' );
+ wp_cache_delete( self::OPTION, 'options' );
+ $perf->s = self::settings();
+ if ( empty( $perf->s[ $group ][ $key ] ) ) {
+ return false;
+ }
+ if ( $written ) {
+ $perf->schedule_preload();
+ $perf->purge_all();
+ }
+ return true;
+ }
+
+ public static function deactivate() {
+ wp_clear_scheduled_hook( self::PRELOAD_HOOK );
+ }
+
+ /* =====================================================================
+ * Page cache
+ * ===================================================================== */
+
+ private static function cache_dir() {
+ return WP_CONTENT_DIR . '/cache/b-blocks/';
+ }
+
+ private static function cache_url() {
+ return content_url( '/cache/b-blocks/' );
+ }
+
+ private function request_host() {
+ return strtolower( preg_replace( '/[^A-Za-z0-9.:-]/', '', sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ?? '' ) ) ) );
+ }
+
+ /** Folder that holds every cached variant of one URL path. */
+ private function page_dir( $host, $path ) {
+ $segments = [];
+ foreach ( explode( '/', trim( $path, '/' ) ) as $segment ) {
+ if ( '' === $segment ) {
+ continue;
+ }
+ // One folder whatever the letter case: %E0 and %e0 are the same character, and WordPress serves /About/ as /about/
+ // (pages are looked up case-insensitively, without a redirect) — a save then purges what a typed address cached.
+ $segment = preg_replace( '/[^a-z0-9._~%-]/', '_', strtolower( $segment ) );
+ $segments[] = in_array( $segment, [ '.', '..' ], true ) ? '_' : $segment;
+ }
+ $host = preg_replace( '/[^a-z0-9