| @@ -8,9 +8,9 @@ | ||
| 8 | 8 | /** |
| 9 | 9 | * Extends the block editor with settings that are only in the plugin. |
| 10 | 10 | * |
| 11 | 11 | * This is a temporary solution until the Gutenberg plugin sets |
| 12 | - * the required WordPress version to 5.9. | |
| 12 | + * the required WordPress version to 5.8. | |
| 13 | 13 | * |
| 14 | 14 | * @see https://core.trac.wordpress.org/ticket/52920 |
| 15 | 15 | * |
| 16 | 16 | * @param array $settings Existing editor settings. |
| @@ -17,17 +17,26 @@ | ||
| 17 | 17 | * |
| 18 | 18 | * @return array Filtered settings. |
| 19 | 19 | */ |
| 20 | 20 | function gutenberg_extend_post_editor_settings( $settings ) { |
| 21 | - $settings['__unstableEnableFullSiteEditingBlocks'] = current_theme_supports( 'block-templates' ); | |
| 21 | + $image_default_size = get_option( 'image_default_size', 'large' ); | |
| 22 | + $image_sizes = wp_list_pluck( $settings['imageSizes'], 'slug' ); | |
| 22 | 23 | |
| 23 | - if ( wp_is_block_theme() ) { | |
| 24 | + $settings['imageDefaultSize'] = in_array( $image_default_size, $image_sizes, true ) ? $image_default_size : 'large'; | |
| 25 | + $settings['__unstableEnableFullSiteEditingBlocks'] = gutenberg_supports_block_templates(); | |
| 26 | + | |
| 27 | + if ( gutenberg_is_fse_theme() ) { | |
| 24 | 28 | $settings['defaultTemplatePartAreas'] = get_allowed_block_template_part_areas(); |
| 25 | 29 | } |
| 26 | 30 | |
| 27 | 31 | return $settings; |
| 28 | 32 | } |
| 29 | -add_filter( 'block_editor_settings_all', 'gutenberg_extend_post_editor_settings' ); | |
| 33 | +// This can be removed when plugin support requires WordPress 5.8.0+. | |
| 34 | +if ( function_exists( 'get_block_editor_settings' ) ) { | |
| 35 | + add_filter( 'block_editor_settings_all', 'gutenberg_extend_post_editor_settings' ); | |
| 36 | +} else { | |
| 37 | + add_filter( 'block_editor_settings', 'gutenberg_extend_post_editor_settings' ); | |
| 38 | +} | |
| 30 | 39 | |
| 31 | 40 | /** |
| 32 | 41 | * Initialize a block-based editor. |
| 33 | 42 | * |