From fe80da0bd1a84b93284f96b728bf06909a9e78b3 Mon Sep 17 00:00:00 2001 From: Michal Czaplinski Date: Tue, 30 May 2023 12:00:40 +0200 Subject: [PATCH 1/4] Add the Behaviors UI --- src/wp-includes/behaviors.php | 24 ++++++++++++++++++++++++ src/wp-includes/class-wp-theme-json.php | 2 ++ src/wp-includes/default-filters.php | 3 +++ src/wp-includes/theme.json | 12 ++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 src/wp-includes/behaviors.php diff --git a/src/wp-includes/behaviors.php b/src/wp-includes/behaviors.php new file mode 100644 index 0000000000000..98a2c4bd6b62c --- /dev/null +++ b/src/wp-includes/behaviors.php @@ -0,0 +1,24 @@ +get_data(); + if (array_key_exists('behaviors', $theme_data)) { + $settings['behaviors'] = $theme_data['behaviors']; + } + return $settings; +} diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index f21a32fa41cc1..99ac8e11b1d51 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -321,6 +321,7 @@ class WP_Theme_JSON { 'templateParts', 'title', 'version', + 'behaviors', ); /** @@ -398,6 +399,7 @@ class WP_Theme_JSON { 'textDecoration' => null, 'textTransform' => null, ), + 'behaviors' => null, ); /** diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 063199269c48c..3e36041bda153 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -720,4 +720,7 @@ // User preferences. add_action( 'init', 'wp_register_persisted_preferences_meta' ); +// Behaviors +add_filter( 'block_editor_settings_all', 'wp_add_behaviors' ); + unset( $filter, $action ); diff --git a/src/wp-includes/theme.json b/src/wp-includes/theme.json index af447990608a3..6a76b89e8a5b8 100644 --- a/src/wp-includes/theme.json +++ b/src/wp-includes/theme.json @@ -1,5 +1,12 @@ { "version": 2, + "behaviors": { + "blocks": { + "core/image": { + "lightbox": false + } + } + }, "settings": { "appearanceTools": false, "useRootPaddingAwareAlignments": false, @@ -414,6 +421,11 @@ "style": true, "width": true } + }, + "core/image": { + "behaviors": { + "lightbox": true + } } } }, From a8dfbf647954025985849cabff816f32982796d5 Mon Sep 17 00:00:00 2001 From: Michal Czaplinski Date: Tue, 30 May 2023 17:20:01 +0200 Subject: [PATCH 2/4] Formatting --- src/wp-includes/behaviors.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/behaviors.php b/src/wp-includes/behaviors.php index 98a2c4bd6b62c..f96fba5327359 100644 --- a/src/wp-includes/behaviors.php +++ b/src/wp-includes/behaviors.php @@ -14,7 +14,7 @@ * @param array $editor_settings The array of editor settings. * @return array A filtered array of editor settings. */ -function wp_add_behaviors($settings) +function wp_add_behaviors( $settings ) { $theme_data = WP_Theme_JSON_Resolver::get_merged_data()->get_data(); if (array_key_exists('behaviors', $theme_data)) { From e5cbe9690d9fcad4fec718130040fcac804f84f3 Mon Sep 17 00:00:00 2001 From: Michal Czaplinski Date: Tue, 30 May 2023 18:18:22 +0200 Subject: [PATCH 3/4] Format again --- src/wp-includes/behaviors.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/behaviors.php b/src/wp-includes/behaviors.php index f96fba5327359..623fff7b8d84c 100644 --- a/src/wp-includes/behaviors.php +++ b/src/wp-includes/behaviors.php @@ -14,10 +14,9 @@ * @param array $editor_settings The array of editor settings. * @return array A filtered array of editor settings. */ -function wp_add_behaviors( $settings ) -{ +function wp_add_behaviors( $settings ) { $theme_data = WP_Theme_JSON_Resolver::get_merged_data()->get_data(); - if (array_key_exists('behaviors', $theme_data)) { + if ( array_key_exists( 'behaviors', $theme_data ) ) { $settings['behaviors'] = $theme_data['behaviors']; } return $settings; From f19b18d54a3a1e126c396bdcbdb1d04549755e8c Mon Sep 17 00:00:00 2001 From: Michal Czaplinski Date: Tue, 30 May 2023 18:25:43 +0200 Subject: [PATCH 4/4] Include the `behaviors.php` file --- src/wp-settings.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wp-settings.php b/src/wp-settings.php index 6a7e8098723fe..115a8b96c6070 100644 --- a/src/wp-settings.php +++ b/src/wp-settings.php @@ -344,6 +344,7 @@ require ABSPATH . WPINC . '/style-engine/class-wp-style-engine-css-rule.php'; require ABSPATH . WPINC . '/style-engine/class-wp-style-engine-css-rules-store.php'; require ABSPATH . WPINC . '/style-engine/class-wp-style-engine-processor.php'; +require ABSPATH . WPINC . '/behaviors.php'; $GLOBALS['wp_embed'] = new WP_Embed();