Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport: Add the Behaviors UI #4526

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/wp-includes/behaviors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* Block Behaviors.
*
* @package WordPress
* @since 6.3.0
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*

*/

/**
* Updates the block editor settings with the theme's behaviors.
*
* @since 6.3.0
* @param array $editor_settings The array of editor settings.
Comment on lines +13 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @since 6.3.0
* @param array $editor_settings The array of editor settings.
* @since 6.3.0
*
* @param array $editor_settings The array of editor settings.

* @return array A filtered array of editor settings.
*/
function wp_add_behaviors( $settings ) {
$theme_data = WP_Theme_JSON_Resolver::get_merged_data()->get_data();
if ( array_key_exists( 'behaviors', $theme_data ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead if array_key_exists use isset

$settings['behaviors'] = $theme_data['behaviors'];
}
return $settings;
}
2 changes: 2 additions & 0 deletions src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ class WP_Theme_JSON {
'templateParts',
'title',
'version',
'behaviors',
);

/**
Expand Down Expand Up @@ -398,6 +399,7 @@ class WP_Theme_JSON {
'textDecoration' => null,
'textTransform' => null,
),
'behaviors' => null,
);

/**
Expand Down
3 changes: 3 additions & 0 deletions src/wp-includes/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -720,4 +720,7 @@
// User preferences.
add_action( 'init', 'wp_register_persisted_preferences_meta' );

// Behaviors
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Behaviors
// Behaviors.

add_filter( 'block_editor_settings_all', 'wp_add_behaviors' );

unset( $filter, $action );
12 changes: 12 additions & 0 deletions src/wp-includes/theme.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"version": 2,
"behaviors": {
"blocks": {
"core/image": {
"lightbox": false
}
}
},
"settings": {
"appearanceTools": false,
"useRootPaddingAwareAlignments": false,
Expand Down Expand Up @@ -414,6 +421,11 @@
"style": true,
"width": true
}
},
"core/image": {
"behaviors": {
"lightbox": true
}
}
}
},
Expand Down
1 change: 1 addition & 0 deletions src/wp-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down