From 9e71e8ab2f6adaa913134af3c2f639bac2e3404f Mon Sep 17 00:00:00 2001 From: Michal Czaplinski Date: Mon, 22 Jan 2024 17:57:34 +0000 Subject: [PATCH 01/10] Remove the experimental flag for Block Bindings --- lib/experimental/block-bindings/index.php | 10 ++------ lib/experimental/blocks.php | 30 +++++++++-------------- lib/experimental/editor-settings.php | 5 ---- lib/experiments-page.php | 12 --------- 4 files changed, 14 insertions(+), 43 deletions(-) diff --git a/lib/experimental/block-bindings/index.php b/lib/experimental/block-bindings/index.php index cf9cc318b1c92..7427a5f77026c 100644 --- a/lib/experimental/block-bindings/index.php +++ b/lib/experimental/block-bindings/index.php @@ -7,11 +7,5 @@ require_once __DIR__ . '/class-wp-block-bindings.php'; require_once __DIR__ . '/block-bindings.php'; -// Register the sources. -$gutenberg_experiments = get_option( 'gutenberg-experiments' ); -if ( $gutenberg_experiments ) { - if ( array_key_exists( 'gutenberg-block-bindings', $gutenberg_experiments ) ) { - require_once __DIR__ . '/sources/pattern.php'; - require_once __DIR__ . '/sources/post-meta.php'; - } -} +require_once __DIR__ . '/sources/post-meta.php'; +require_once __DIR__ . '/sources/pattern.php'; diff --git a/lib/experimental/blocks.php b/lib/experimental/blocks.php index 39ac86970367c..da2b74277d358 100644 --- a/lib/experimental/blocks.php +++ b/lib/experimental/blocks.php @@ -78,22 +78,17 @@ function wp_enqueue_block_view_script( $block_name, $args ) { } } -$gutenberg_experiments = get_option( 'gutenberg-experiments' ); -if ( $gutenberg_experiments && ( - array_key_exists( 'gutenberg-block-bindings', $gutenberg_experiments ) -) ) { +require_once __DIR__ . '/block-bindings/index.php'; - require_once __DIR__ . '/block-bindings/index.php'; - - if ( ! function_exists( 'gutenberg_process_block_bindings' ) ) { - /** - * Process the block bindings attribute. - * - * @param string $block_content Block Content. - * @param array $block Block attributes. - * @param WP_Block $block_instance The block instance. - */ - function gutenberg_process_block_bindings( $block_content, $block, $block_instance ) { +if ( ! function_exists( 'gutenberg_process_block_bindings' ) ) { + /** + * Process the block bindings attribute. + * + * @param string $block_content Block Content. + * @param array $block Block attributes. + * @param WP_Block $block_instance The block instance. + */ + function gutenberg_process_block_bindings( $block_content, $block, $block_instance ) { // Allowed blocks that support block bindings. // TODO: Look for a mechanism to opt-in for this. Maybe adding a property to block attributes? @@ -157,8 +152,7 @@ function gutenberg_process_block_bindings( $block_content, $block, $block_instan $modified_block_content = wp_block_bindings_replace_html( $modified_block_content, $block_instance->name, $binding_attribute, $source_value ); } return $modified_block_content; - } } - - add_filter( 'render_block', 'gutenberg_process_block_bindings', 20, 3 ); } + +add_filter( 'render_block', 'gutenberg_process_block_bindings', 20, 3 ); diff --git a/lib/experimental/editor-settings.php b/lib/experimental/editor-settings.php index 24590c5cf3eb0..37774e07b2769 100644 --- a/lib/experimental/editor-settings.php +++ b/lib/experimental/editor-settings.php @@ -25,11 +25,6 @@ function gutenberg_enable_experiments() { if ( $gutenberg_experiments && array_key_exists( 'gutenberg-group-grid-variation', $gutenberg_experiments ) ) { wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableGroupGridVariation = true', 'before' ); } - - if ( $gutenberg_experiments && array_key_exists( 'gutenberg-block-bindings', $gutenberg_experiments ) ) { - wp_add_inline_script( 'wp-block-editor', 'window.__experimentalBlockBindings = true', 'before' ); - } - if ( gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) ) { wp_add_inline_script( 'wp-block-library', 'window.__experimentalDisableTinymce = true', 'before' ); } diff --git a/lib/experiments-page.php b/lib/experiments-page.php index a38b5c4f11fad..bccbed2195958 100644 --- a/lib/experiments-page.php +++ b/lib/experiments-page.php @@ -126,18 +126,6 @@ function gutenberg_initialize_experiments_settings() { ) ); - add_settings_field( - 'gutenberg-custom-fields', - __( 'Block Bindings & Custom Fields', 'gutenberg' ), - 'gutenberg_display_experiment_field', - 'gutenberg-experiments', - 'gutenberg_experiments_section', - array( - 'label' => __( 'Test connecting block attributes to different sources like custom fields', 'gutenberg' ), - 'id' => 'gutenberg-block-bindings', - ) - ); - register_setting( 'gutenberg-experiments', 'gutenberg-experiments' From f51b3afdcbf774af57fa3d8576a697d40617472d Mon Sep 17 00:00:00 2001 From: Michal Czaplinski Date: Tue, 23 Jan 2024 17:10:44 +0000 Subject: [PATCH 02/10] Move block-bindings to `compat/wordpress-6.5` folder. --- .../block-bindings/block-bindings.php | 0 .../class-wp-block-bindings.php | 0 .../wordpress-6.5}/block-bindings/index.php | 0 .../block-bindings/sources/pattern.php | 0 .../block-bindings/sources/post-meta.php | 0 lib/compat/wordpress-6.5/blocks.php | 79 +++++++++++++++++++ lib/experimental/blocks.php | 79 ------------------- 7 files changed, 79 insertions(+), 79 deletions(-) rename lib/{experimental => compat/wordpress-6.5}/block-bindings/block-bindings.php (100%) rename lib/{experimental => compat/wordpress-6.5}/block-bindings/class-wp-block-bindings.php (100%) rename lib/{experimental => compat/wordpress-6.5}/block-bindings/index.php (100%) rename lib/{experimental => compat/wordpress-6.5}/block-bindings/sources/pattern.php (100%) rename lib/{experimental => compat/wordpress-6.5}/block-bindings/sources/post-meta.php (100%) diff --git a/lib/experimental/block-bindings/block-bindings.php b/lib/compat/wordpress-6.5/block-bindings/block-bindings.php similarity index 100% rename from lib/experimental/block-bindings/block-bindings.php rename to lib/compat/wordpress-6.5/block-bindings/block-bindings.php diff --git a/lib/experimental/block-bindings/class-wp-block-bindings.php b/lib/compat/wordpress-6.5/block-bindings/class-wp-block-bindings.php similarity index 100% rename from lib/experimental/block-bindings/class-wp-block-bindings.php rename to lib/compat/wordpress-6.5/block-bindings/class-wp-block-bindings.php diff --git a/lib/experimental/block-bindings/index.php b/lib/compat/wordpress-6.5/block-bindings/index.php similarity index 100% rename from lib/experimental/block-bindings/index.php rename to lib/compat/wordpress-6.5/block-bindings/index.php diff --git a/lib/experimental/block-bindings/sources/pattern.php b/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php similarity index 100% rename from lib/experimental/block-bindings/sources/pattern.php rename to lib/compat/wordpress-6.5/block-bindings/sources/pattern.php diff --git a/lib/experimental/block-bindings/sources/post-meta.php b/lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php similarity index 100% rename from lib/experimental/block-bindings/sources/post-meta.php rename to lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php diff --git a/lib/compat/wordpress-6.5/blocks.php b/lib/compat/wordpress-6.5/blocks.php index f5a9968f9210b..27a5357cb8bb5 100644 --- a/lib/compat/wordpress-6.5/blocks.php +++ b/lib/compat/wordpress-6.5/blocks.php @@ -45,3 +45,82 @@ function gutenberg_register_metadata_attribute( $args ) { return $args; } add_filter( 'register_block_type_args', 'gutenberg_register_metadata_attribute' ); + +require_once __DIR__ . '/block-bindings/index.php'; + +if ( ! function_exists( 'gutenberg_process_block_bindings' ) ) { + /** + * Process the block bindings attribute. + * + * @param string $block_content Block Content. + * @param array $block Block attributes. + * @param WP_Block $block_instance The block instance. + */ + function gutenberg_process_block_bindings( $block_content, $block, $block_instance ) { + + // Allowed blocks that support block bindings. + // TODO: Look for a mechanism to opt-in for this. Maybe adding a property to block attributes? + $allowed_blocks = array( + 'core/paragraph' => array( 'content' ), + 'core/heading' => array( 'content' ), + 'core/image' => array( 'url', 'title', 'alt' ), + 'core/button' => array( 'url', 'text' ), + ); + + // If the block doesn't have the bindings property or isn't one of the allowed block types, return. + if ( ! isset( $block['attrs']['metadata']['bindings'] ) || ! isset( $allowed_blocks[ $block_instance->name ] ) ) { + return $block_content; + } + + // Assuming the following format for the bindings property of the "metadata" attribute: + // + // "bindings": { + // "title": { + // "source": { + // "name": "post_meta", + // "attributes": { "value": "text_custom_field" } + // } + // }, + // "url": { + // "source": { + // "name": "post_meta", + // "attributes": { "value": "text_custom_field" } + // } + // } + // } + // + + $block_bindings_sources = wp_block_bindings_get_sources(); + $modified_block_content = $block_content; + foreach ( $block['attrs']['metadata']['bindings'] as $binding_attribute => $binding_source ) { + + // If the attribute is not in the list, process next attribute. + if ( ! in_array( $binding_attribute, $allowed_blocks[ $block_instance->name ], true ) ) { + continue; + } + // If no source is provided, or that source is not registered, process next attribute. + if ( ! isset( $binding_source['source'] ) || ! isset( $binding_source['source']['name'] ) || ! isset( $block_bindings_sources[ $binding_source['source']['name'] ] ) ) { + continue; + } + + $source_callback = $block_bindings_sources[ $binding_source['source']['name'] ]['apply']; + // Get the value based on the source. + if ( ! isset( $binding_source['source']['attributes'] ) ) { + $source_args = array(); + } else { + $source_args = $binding_source['source']['attributes']; + } + $source_value = $source_callback( $source_args, $block_instance, $binding_attribute ); + // If the value is null, process next attribute. + if ( is_null( $source_value ) ) { + continue; + } + + // Process the HTML based on the block and the attribute. + $modified_block_content = wp_block_bindings_replace_html( $modified_block_content, $block_instance->name, $binding_attribute, $source_value ); + } + return $modified_block_content; + } +} + +add_filter( 'render_block', 'gutenberg_process_block_bindings', 20, 3 ); diff --git a/lib/experimental/blocks.php b/lib/experimental/blocks.php index da2b74277d358..fc67f2c9d4377 100644 --- a/lib/experimental/blocks.php +++ b/lib/experimental/blocks.php @@ -77,82 +77,3 @@ function wp_enqueue_block_view_script( $block_name, $args ) { add_filter( 'render_block', $callback, 10, 2 ); } } - -require_once __DIR__ . '/block-bindings/index.php'; - -if ( ! function_exists( 'gutenberg_process_block_bindings' ) ) { - /** - * Process the block bindings attribute. - * - * @param string $block_content Block Content. - * @param array $block Block attributes. - * @param WP_Block $block_instance The block instance. - */ - function gutenberg_process_block_bindings( $block_content, $block, $block_instance ) { - - // Allowed blocks that support block bindings. - // TODO: Look for a mechanism to opt-in for this. Maybe adding a property to block attributes? - $allowed_blocks = array( - 'core/paragraph' => array( 'content' ), - 'core/heading' => array( 'content' ), - 'core/image' => array( 'url', 'title', 'alt' ), - 'core/button' => array( 'url', 'text', 'linkTarget' ), - ); - - // If the block doesn't have the bindings property or isn't one of the allowed block types, return. - if ( ! isset( $block['attrs']['metadata']['bindings'] ) || ! isset( $allowed_blocks[ $block_instance->name ] ) ) { - return $block_content; - } - - // Assuming the following format for the bindings property of the "metadata" attribute: - // - // "bindings": { - // "title": { - // "source": { - // "name": "post_meta", - // "attributes": { "value": "text_custom_field" } - // } - // }, - // "url": { - // "source": { - // "name": "post_meta", - // "attributes": { "value": "text_custom_field" } - // } - // } - // } - // - - $block_bindings_sources = wp_block_bindings_get_sources(); - $modified_block_content = $block_content; - foreach ( $block['attrs']['metadata']['bindings'] as $binding_attribute => $binding_source ) { - - // If the attribute is not in the list, process next attribute. - if ( ! in_array( $binding_attribute, $allowed_blocks[ $block_instance->name ], true ) ) { - continue; - } - // If no source is provided, or that source is not registered, process next attribute. - if ( ! isset( $binding_source['source'] ) || ! isset( $binding_source['source']['name'] ) || ! isset( $block_bindings_sources[ $binding_source['source']['name'] ] ) ) { - continue; - } - - $source_callback = $block_bindings_sources[ $binding_source['source']['name'] ]['apply']; - // Get the value based on the source. - if ( ! isset( $binding_source['source']['attributes'] ) ) { - $source_args = array(); - } else { - $source_args = $binding_source['source']['attributes']; - } - $source_value = $source_callback( $source_args, $block_instance, $binding_attribute ); - // If the value is null, process next attribute. - if ( is_null( $source_value ) ) { - continue; - } - - // Process the HTML based on the block and the attribute. - $modified_block_content = wp_block_bindings_replace_html( $modified_block_content, $block_instance->name, $binding_attribute, $source_value ); - } - return $modified_block_content; - } -} - -add_filter( 'render_block', 'gutenberg_process_block_bindings', 20, 3 ); From 4dc08cde94e074631bd9fd5f6c51438df49be6a0 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Wed, 24 Jan 2024 14:15:49 +0800 Subject: [PATCH 03/10] Remove the need for the experiment flag in the pattern overrides e2e tests --- test/e2e/specs/editor/various/pattern-overrides.spec.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/e2e/specs/editor/various/pattern-overrides.spec.js b/test/e2e/specs/editor/various/pattern-overrides.spec.js index 56c6b2a7c15f4..ee60091e057c0 100644 --- a/test/e2e/specs/editor/various/pattern-overrides.spec.js +++ b/test/e2e/specs/editor/various/pattern-overrides.spec.js @@ -7,9 +7,6 @@ test.describe( 'Pattern Overrides', () => { test.beforeAll( async ( { requestUtils } ) => { await Promise.all( [ requestUtils.activateTheme( 'emptytheme' ), - requestUtils.setGutenbergExperiments( [ - 'gutenberg-block-bindings', - ] ), requestUtils.deleteAllBlocks(), ] ); } ); @@ -20,7 +17,6 @@ test.describe( 'Pattern Overrides', () => { test.afterAll( async ( { requestUtils } ) => { await Promise.all( [ - requestUtils.setGutenbergExperiments( [] ), requestUtils.activateTheme( 'twentytwentyone' ), ] ); } ); From 4189efd65c9aaa2c2714f91b9637d0607b979fbe Mon Sep 17 00:00:00 2001 From: Michal Czaplinski Date: Wed, 24 Jan 2024 12:12:04 +0000 Subject: [PATCH 04/10] `require` the files in load.php instead --- lib/compat/wordpress-6.5/block-bindings/index.php | 11 ----------- lib/compat/wordpress-6.5/blocks.php | 1 - lib/load.php | 4 ++++ 3 files changed, 4 insertions(+), 12 deletions(-) delete mode 100644 lib/compat/wordpress-6.5/block-bindings/index.php diff --git a/lib/compat/wordpress-6.5/block-bindings/index.php b/lib/compat/wordpress-6.5/block-bindings/index.php deleted file mode 100644 index 7427a5f77026c..0000000000000 --- a/lib/compat/wordpress-6.5/block-bindings/index.php +++ /dev/null @@ -1,11 +0,0 @@ - Date: Wed, 24 Jan 2024 12:21:41 +0000 Subject: [PATCH 05/10] Fix the order of the requires --- lib/load.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/load.php b/lib/load.php index ccf35ed76c85f..9160972c04326 100644 --- a/lib/load.php +++ b/lib/load.php @@ -109,10 +109,10 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/compat/wordpress-6.5/kses.php'; require __DIR__ . '/compat/wordpress-6.5/class-wp-script-modules.php'; require __DIR__ . '/compat/wordpress-6.5/scripts-modules.php'; -require __DIR__ . '/compat/wordpress-6.5/block-bindings/sources/post-meta.php'; -require __DIR__ . '/compat/wordpress-6.5/block-bindings/sources/pattern.php'; require __DIR__ . '/compat/wordpress-6.5/block-bindings/class-wp-block-bindings.php'; require __DIR__ . '/compat/wordpress-6.5/block-bindings/block-bindings.php'; +require __DIR__ . '/compat/wordpress-6.5/block-bindings/sources/post-meta.php'; +require __DIR__ . '/compat/wordpress-6.5/block-bindings/sources/pattern.php'; // Experimental features. require __DIR__ . '/experimental/block-editor-settings-mobile.php'; From 1bfb830852ff06a3655ab6393df66d38a55f7f73 Mon Sep 17 00:00:00 2001 From: Michal Date: Wed, 24 Jan 2024 12:23:51 +0000 Subject: [PATCH 06/10] Update comment fromat in blocks.php Co-authored-by: Carlos Bravo <37012961+c4rl0sbr4v0@users.noreply.github.com> --- lib/compat/wordpress-6.5/blocks.php | 35 +++++++++++++++-------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/compat/wordpress-6.5/blocks.php b/lib/compat/wordpress-6.5/blocks.php index 9bc9d23c55025..352cc8819ce8c 100644 --- a/lib/compat/wordpress-6.5/blocks.php +++ b/lib/compat/wordpress-6.5/blocks.php @@ -71,23 +71,24 @@ function gutenberg_process_block_bindings( $block_content, $block, $block_instan return $block_content; } - // Assuming the following format for the bindings property of the "metadata" attribute: - // - // "bindings": { - // "title": { - // "source": { - // "name": "post_meta", - // "attributes": { "value": "text_custom_field" } - // } - // }, - // "url": { - // "source": { - // "name": "post_meta", - // "attributes": { "value": "text_custom_field" } - // } - // } - // } - // + /* + * Assuming the following format for the bindings property of the "metadata" attribute: + * + * "bindings": { + * "title": { + * "source": { + * "name": "post_meta", + * "attributes": { "value": "text_custom_field" } + * } + * }, + * "url": { + * "source": { + * "name": "post_meta", + * "attributes": { "value": "text_custom_field" } + * } + * } + * } + */ $block_bindings_sources = wp_block_bindings_get_sources(); $modified_block_content = $block_content; From a69d979d7c3db675641f6bca4617d321931b07a0 Mon Sep 17 00:00:00 2001 From: Michal Czaplinski Date: Wed, 24 Jan 2024 15:16:21 +0000 Subject: [PATCH 07/10] Remove changes that sneaked in during the rebase --- .../block-bindings/sources/pattern.php | 19 ++----------------- lib/load.php | 7 ++++--- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php b/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php index 740d1983d6fe8..16bf46f4f06ab 100644 --- a/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php +++ b/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php @@ -9,23 +9,8 @@ if ( ! _wp_array_get( $block_instance->attributes, array( 'metadata', 'id' ), false ) ) { return null; } - $block_id = $block_instance->attributes['metadata']['id']; - $attribute_override = _wp_array_get( $block_instance->context, array( 'pattern/overrides', $block_id, $attribute_name ), null ); - if ( null === $attribute_override ) { - return null; - } - switch ( $attribute_override[0] ) { - case 0: // remove - /** - * TODO: This currently doesn't remove the attribute, but only set it to an empty string. - * It's a temporary solution until the block binding API supports different operations. - */ - return ''; - case 1: // replace - return $attribute_override[1]; - default: - return null; - } + $block_id = $block_instance->attributes['metadata']['id']; + return _wp_array_get( $block_instance->context, array( 'pattern/overrides', $block_id, $attribute_name ), null ); }; wp_block_bindings_register_source( 'pattern_attributes', diff --git a/lib/load.php b/lib/load.php index 9160972c04326..fe11f205bb05a 100644 --- a/lib/load.php +++ b/lib/load.php @@ -106,9 +106,8 @@ function gutenberg_is_experiment_enabled( $name ) { // WordPress 6.5 compat. require __DIR__ . '/compat/wordpress-6.5/blocks.php'; require __DIR__ . '/compat/wordpress-6.5/block-patterns.php'; +require __DIR__ . '/compat/wordpress-6.5/class-wp-navigation-block-renderer.php'; require __DIR__ . '/compat/wordpress-6.5/kses.php'; -require __DIR__ . '/compat/wordpress-6.5/class-wp-script-modules.php'; -require __DIR__ . '/compat/wordpress-6.5/scripts-modules.php'; require __DIR__ . '/compat/wordpress-6.5/block-bindings/class-wp-block-bindings.php'; require __DIR__ . '/compat/wordpress-6.5/block-bindings/block-bindings.php'; require __DIR__ . '/compat/wordpress-6.5/block-bindings/sources/post-meta.php'; @@ -121,7 +120,6 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/experimental/kses.php'; require __DIR__ . '/experimental/l10n.php'; require __DIR__ . '/experimental/synchronization.php'; -require __DIR__ . '/experimental/script-modules.php'; if ( gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) ) { require __DIR__ . '/experimental/disable-tinymce.php'; @@ -140,6 +138,8 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/experimental/interactivity-api/directives/wp-text.php'; require __DIR__ . '/experimental/interactivity-api/directives/wp-interactive.php'; +require __DIR__ . '/experimental/modules/class-gutenberg-modules.php'; + // Fonts API / Font Face. remove_action( 'plugins_loaded', '_wp_theme_json_webfonts_handler' ); // Turns off WordPress 6.0's stopgap handler. @@ -147,6 +147,7 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/experimental/fonts/font-library/class-wp-font-collection.php'; require __DIR__ . '/experimental/fonts/font-library/class-wp-font-library.php'; require __DIR__ . '/experimental/fonts/font-library/class-wp-font-family-utils.php'; +require __DIR__ . '/experimental/fonts/font-library/class-wp-font-family.php'; require __DIR__ . '/experimental/fonts/font-library/class-wp-rest-font-families-controller.php'; require __DIR__ . '/experimental/fonts/font-library/class-wp-rest-font-faces-controller.php'; require __DIR__ . '/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php'; From 15b2f72ede36e0a4319504e597ce3fc5c75953b7 Mon Sep 17 00:00:00 2001 From: Michal Czaplinski Date: Wed, 24 Jan 2024 15:22:17 +0000 Subject: [PATCH 08/10] Remove other changes that sneaked in during rebase --- lib/load.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/load.php b/lib/load.php index fe11f205bb05a..223a817cc51d0 100644 --- a/lib/load.php +++ b/lib/load.php @@ -106,13 +106,15 @@ function gutenberg_is_experiment_enabled( $name ) { // WordPress 6.5 compat. require __DIR__ . '/compat/wordpress-6.5/blocks.php'; require __DIR__ . '/compat/wordpress-6.5/block-patterns.php'; -require __DIR__ . '/compat/wordpress-6.5/class-wp-navigation-block-renderer.php'; require __DIR__ . '/compat/wordpress-6.5/kses.php'; +require __DIR__ . '/compat/wordpress-6.5/class-wp-script-modules.php'; +require __DIR__ . '/compat/wordpress-6.5/scripts-modules.php'; require __DIR__ . '/compat/wordpress-6.5/block-bindings/class-wp-block-bindings.php'; require __DIR__ . '/compat/wordpress-6.5/block-bindings/block-bindings.php'; require __DIR__ . '/compat/wordpress-6.5/block-bindings/sources/post-meta.php'; require __DIR__ . '/compat/wordpress-6.5/block-bindings/sources/pattern.php'; + // Experimental features. require __DIR__ . '/experimental/block-editor-settings-mobile.php'; require __DIR__ . '/experimental/blocks.php'; @@ -120,6 +122,7 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/experimental/kses.php'; require __DIR__ . '/experimental/l10n.php'; require __DIR__ . '/experimental/synchronization.php'; +require __DIR__ . '/experimental/script-modules.php'; if ( gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) ) { require __DIR__ . '/experimental/disable-tinymce.php'; @@ -138,8 +141,6 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/experimental/interactivity-api/directives/wp-text.php'; require __DIR__ . '/experimental/interactivity-api/directives/wp-interactive.php'; -require __DIR__ . '/experimental/modules/class-gutenberg-modules.php'; - // Fonts API / Font Face. remove_action( 'plugins_loaded', '_wp_theme_json_webfonts_handler' ); // Turns off WordPress 6.0's stopgap handler. @@ -147,7 +148,6 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/experimental/fonts/font-library/class-wp-font-collection.php'; require __DIR__ . '/experimental/fonts/font-library/class-wp-font-library.php'; require __DIR__ . '/experimental/fonts/font-library/class-wp-font-family-utils.php'; -require __DIR__ . '/experimental/fonts/font-library/class-wp-font-family.php'; require __DIR__ . '/experimental/fonts/font-library/class-wp-rest-font-families-controller.php'; require __DIR__ . '/experimental/fonts/font-library/class-wp-rest-font-faces-controller.php'; require __DIR__ . '/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php'; From 4205960f2c8995bad94ddebb1da3a9026a1e3406 Mon Sep 17 00:00:00 2001 From: Michal Czaplinski Date: Wed, 24 Jan 2024 15:30:19 +0000 Subject: [PATCH 09/10] One more fix for the bad rebase --- .../block-bindings/sources/pattern.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php b/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php index 16bf46f4f06ab..740d1983d6fe8 100644 --- a/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php +++ b/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php @@ -9,8 +9,23 @@ if ( ! _wp_array_get( $block_instance->attributes, array( 'metadata', 'id' ), false ) ) { return null; } - $block_id = $block_instance->attributes['metadata']['id']; - return _wp_array_get( $block_instance->context, array( 'pattern/overrides', $block_id, $attribute_name ), null ); + $block_id = $block_instance->attributes['metadata']['id']; + $attribute_override = _wp_array_get( $block_instance->context, array( 'pattern/overrides', $block_id, $attribute_name ), null ); + if ( null === $attribute_override ) { + return null; + } + switch ( $attribute_override[0] ) { + case 0: // remove + /** + * TODO: This currently doesn't remove the attribute, but only set it to an empty string. + * It's a temporary solution until the block binding API supports different operations. + */ + return ''; + case 1: // replace + return $attribute_override[1]; + default: + return null; + } }; wp_block_bindings_register_source( 'pattern_attributes', From 0fc32626ba84ec6e25eda6fe87661d3c3f95eb74 Mon Sep 17 00:00:00 2001 From: Michal Czaplinski Date: Wed, 24 Jan 2024 16:16:32 +0000 Subject: [PATCH 10/10] Add 'linkTarget' property to core/button block in $allowed_blocks --- lib/compat/wordpress-6.5/blocks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.5/blocks.php b/lib/compat/wordpress-6.5/blocks.php index 352cc8819ce8c..dccaeba5cc335 100644 --- a/lib/compat/wordpress-6.5/blocks.php +++ b/lib/compat/wordpress-6.5/blocks.php @@ -63,7 +63,7 @@ function gutenberg_process_block_bindings( $block_content, $block, $block_instan 'core/paragraph' => array( 'content' ), 'core/heading' => array( 'content' ), 'core/image' => array( 'url', 'title', 'alt' ), - 'core/button' => array( 'url', 'text' ), + 'core/button' => array( 'url', 'text', 'linkTarget' ), ); // If the block doesn't have the bindings property or isn't one of the allowed block types, return.