|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Bootstraping the Gutenberg Edit Site Page. |
| 4 | + * |
| 5 | + * @package gutenberg |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * The main entry point for the Gutenberg Edit Site Page. |
| 10 | + * |
| 11 | + * @since 7.2.0 |
| 12 | + */ |
| 13 | +function gutenberg_edit_site_page() { |
| 14 | + ?> |
| 15 | + <div |
| 16 | + id="edit-site-editor" |
| 17 | + class="edit-site" |
| 18 | + > |
| 19 | + </div> |
| 20 | + <?php |
| 21 | +} |
| 22 | + |
| 23 | +/** |
| 24 | + * Initialize the Gutenberg Edit Site Page. |
| 25 | + * |
| 26 | + * @since 7.2.0 |
| 27 | + * |
| 28 | + * @param string $hook Page. |
| 29 | + */ |
| 30 | +function gutenberg_edit_site_init( $hook ) { |
| 31 | + if ( 'gutenberg_page_gutenberg-edit-site' !== $hook ) { |
| 32 | + return; |
| 33 | + } |
| 34 | + |
| 35 | + // Get editor settings. |
| 36 | + $max_upload_size = wp_max_upload_size(); |
| 37 | + if ( ! $max_upload_size ) { |
| 38 | + $max_upload_size = 0; |
| 39 | + } |
| 40 | + |
| 41 | + // This filter is documented in wp-admin/includes/media.php. |
| 42 | + $image_size_names = apply_filters( |
| 43 | + 'image_size_names_choose', |
| 44 | + array( |
| 45 | + 'thumbnail' => __( 'Thumbnail', 'gutenberg' ), |
| 46 | + 'medium' => __( 'Medium', 'gutenberg' ), |
| 47 | + 'large' => __( 'Large', 'gutenberg' ), |
| 48 | + 'full' => __( 'Full Size', 'gutenberg' ), |
| 49 | + ) |
| 50 | + ); |
| 51 | + $available_image_sizes = array(); |
| 52 | + foreach ( $image_size_names as $image_size_slug => $image_size_name ) { |
| 53 | + $available_image_sizes[] = array( |
| 54 | + 'slug' => $image_size_slug, |
| 55 | + 'name' => $image_size_name, |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + $settings = array( |
| 60 | + 'disableCustomColors' => get_theme_support( 'disable-custom-colors' ), |
| 61 | + 'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ), |
| 62 | + 'imageSizes' => $available_image_sizes, |
| 63 | + 'isRTL' => is_rtl(), |
| 64 | + 'maxUploadFileSize' => $max_upload_size, |
| 65 | + ); |
| 66 | + |
| 67 | + list( $color_palette, ) = (array) get_theme_support( 'editor-color-palette' ); |
| 68 | + list( $font_sizes, ) = (array) get_theme_support( 'editor-font-sizes' ); |
| 69 | + if ( false !== $color_palette ) { |
| 70 | + $settings['colors'] = $color_palette; |
| 71 | + } |
| 72 | + if ( false !== $font_sizes ) { |
| 73 | + $settings['fontSizes'] = $font_sizes; |
| 74 | + } |
| 75 | + |
| 76 | + // Initialize editor. |
| 77 | + wp_add_inline_script( |
| 78 | + 'wp-edit-site', |
| 79 | + sprintf( |
| 80 | + 'wp.domReady( function() { |
| 81 | + wp.editSite.initialize( "edit-site-editor", %s ); |
| 82 | + } );', |
| 83 | + wp_json_encode( gutenberg_experiments_editor_settings( $settings ) ) |
| 84 | + ) |
| 85 | + ); |
| 86 | + |
| 87 | + // Preload server-registered block schemas. |
| 88 | + wp_add_inline_script( |
| 89 | + 'wp-blocks', |
| 90 | + 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');' |
| 91 | + ); |
| 92 | + |
| 93 | + wp_enqueue_script( 'wp-edit-site' ); |
| 94 | + wp_enqueue_script( 'wp-format-library' ); |
| 95 | + wp_enqueue_style( 'wp-edit-site' ); |
| 96 | + wp_enqueue_style( 'wp-format-library' ); |
| 97 | +} |
| 98 | +add_action( 'admin_enqueue_scripts', 'gutenberg_edit_site_init' ); |
0 commit comments