| 1 |
<?php |
| 2 |
/** |
| 3 |
* Utilities to manage editor settings. |
| 4 |
* |
| 5 |
* @package gutenberg |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Returns editor settings that are common to all editors: |
| 10 |
* post, site, widgets, and navigation. |
| 11 |
* |
| 12 |
* All these settings are already part of core, |
| 13 |
* see edit-form-blocks.php |
| 14 |
* |
| 15 |
* @return array Common editor settings. |
| 16 |
*/ |
| 17 |
function gutenberg_get_common_block_editor_settings() { |
| 18 |
$max_upload_size = wp_max_upload_size(); |
| 19 |
if ( ! $max_upload_size ) { |
| 20 |
$max_upload_size = 0; |
| 21 |
} |
| 22 |
|
| 23 |
$available_image_sizes = array(); |
| 24 |
// This filter is documented in wp-admin/includes/media.php. |
| 25 |
$image_size_names = apply_filters( |
| 26 |
'image_size_names_choose', |
| 27 |
array( |
| 28 |
'thumbnail' => __( 'Thumbnail', 'gutenberg' ), |
| 29 |
'medium' => __( 'Medium', 'gutenberg' ), |
| 30 |
'large' => __( 'Large', 'gutenberg' ), |
| 31 |
'full' => __( 'Full Size', 'gutenberg' ), |
| 32 |
) |
| 33 |
); |
| 34 |
foreach ( $image_size_names as $image_size_slug => $image_size_name ) { |
| 35 |
$available_image_sizes[] = array( |
| 36 |
'slug' => $image_size_slug, |
| 37 |
'name' => $image_size_name, |
| 38 |
); |
| 39 |
}; |
| 40 |
|
| 41 |
$settings = array( |
| 42 |
'__unstableEnableFullSiteEditingBlocks' => gutenberg_is_fse_theme(), |
| 43 |
'disableCustomColors' => get_theme_support( 'disable-custom-colors' ), |
| 44 |
'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ), |
| 45 |
'disableCustomGradients' => get_theme_support( 'disable-custom-gradients' ), |
| 46 |
'enableCustomLineHeight' => get_theme_support( 'custom-line-height' ), |
| 47 |
'enableCustomUnits' => get_theme_support( 'custom-units' ), |
| 48 |
'imageSizes' => $available_image_sizes, |
| 49 |
'isRTL' => is_rtl(), |
| 50 |
'maxUploadFileSize' => $max_upload_size, |
| 51 |
); |
| 52 |
|
| 53 |
$color_palette = current( (array) get_theme_support( 'editor-color-palette' ) ); |
| 54 |
if ( false !== $color_palette ) { |
| 55 |
$settings['colors'] = $color_palette; |
| 56 |
} |
| 57 |
|
| 58 |
$font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) ); |
| 59 |
if ( false !== $font_sizes ) { |
| 60 |
$settings['fontSizes'] = $font_sizes; |
| 61 |
} |
| 62 |
|
| 63 |
$gradient_presets = current( (array) get_theme_support( 'editor-gradient-presets' ) ); |
| 64 |
if ( false !== $gradient_presets ) { |
| 65 |
$settings['gradients'] = $gradient_presets; |
| 66 |
} |
| 67 |
|
| 68 |
return $settings; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Extends the block editor with settings that are only in the plugin. |
| 73 |
* |
| 74 |
* @param array $settings Existing editor settings. |
| 75 |
* |
| 76 |
* @return array Filtered settings. |
| 77 |
*/ |
| 78 |
function gutenberg_extend_post_editor_settings( $settings ) { |
| 79 |
$settings['__unstableEnableFullSiteEditingBlocks'] = gutenberg_is_fse_theme(); |
| 80 |
return $settings; |
| 81 |
} |
| 82 |
add_filter( 'block_editor_settings', 'gutenberg_extend_post_editor_settings' ); |
| 83 |
|