-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Lightbox: allow deactivating from third-party plugins #59797
Comments
Thanks so much for opening this. Tagging in @gziolo as I personally ran into this on a site using Jetpack and found myself confused about what was going on. |
Thanks for opening the issue! I believe that adding a filter in PHP or in JS like outlined in the opening message should be enough to disable the Lightbox. This might be a bug in the implementation, but I would have to dig a bit to confirm. Also pinging @artemiomorales |
@ndiego or @justintadlock, do you know how plugin authors could disable the Lightbox for the Image block in a way that overrides the settings from the theme? |
Therefore, I think it is necessary to disable support at the block level in the default theme.json using a hook like the one below. function custom_wp_theme_json_default( $theme_json ) {
$new_data = array(
'version' => 2,
'settings' => array(
'blocks' => array(
'core/image' => array(
'lightbox' => array(
'allowEditing' => false,
),
),
),
),
);
return $theme_json->update_with( $new_data );
}
add_filter( 'wp_theme_json_data_default', 'custom_wp_theme_json_default' ); |
I would think you'd use the |
Thank you all! I've tried with all 3 filters to set Am I missing something obvious here? Does the code snippet above work for you? |
It looks like the filter itself works. However, the implementation in the editor might be broken. I'm testing against WP 6.5 RC2. This combination isn't disallowing editing:
With those two settings, I'm still able to change the lightbox status of an existing Image block and a newly-added Image block in the editor. Tested with filter: add_filter(
'wp_theme_json_data_theme',
fn($theme_json) => $theme_json->update_with([
'version' => 2,
'settings' => [
'blocks' => [
'core/image' => [
'lightbox' => [
'allowEditing' => false,
'enabled' => true
]
]
]
]
])
); I also tested this without the filter but setting it in {
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 2,
"settings": {
"blocks": {
"core/image": {
"lightbox": {
"allowEditing": false,
"enabled": true
}
}
}
}
} CC: @artemiomorales This is a change in previous behavior from WordPress 6.4 and seems to be a regression and bug to me. I don't know if it's related to a change in the Lightbox toggle in the sidebar to the new location in the Link dropdown. #57608 Or something else altogether. |
This means that the lightbox is enabled by default but does not display any UI. In WP6.4 it was working as expected. It's probably a regression caused by #57608. When deciding whether to display the UI, it only relies on gutenberg/packages/block-editor/src/components/url-popover/image-url-input-ui.js Line 344 in dc648e5
In other words, the problem this time is not that there is no way to completely disable lightbox, but that it is no longer possible to realize the requirement that lightbox be enabled by default, but that the UI should not be displayed. |
This seems to work well for me, thank you! |
Great, thanks for taking a look! |
This fix was released in WordPress 6.5.2. |
What problem does this address?
Image blocks offer an option to "expand on click", via the Lightbox feature developed here:
#51132
Since many other plugins already offer lightbox functionality, it would be useful if those third-party plugins could:
What is your proposed solution?
I do not have a solution today, unfortunately.
theme.json
. That's not an option in plugins though.Hooking into
render_block_core/image
isn't enough because the UI remains in the block editor.Hooking into
blocks.registerBlockType
like so doesn't seem to work:block_type_metadata_settings
doesn't work either:The text was updated successfully, but these errors were encountered: