fonts-api
1 year ago
interactivity-api
1 year ago
block-editor-settings-mobile.php
1 year ago
block-editor-settings.php
1 year ago
blocks.php
1 year ago
class-gutenberg-rest-global-styles-revisions-controller.php
1 year ago
class-wp-classic-to-block-menu-converter.php
1 year ago
class-wp-navigation-fallback-gutenberg.php
1 year ago
class-wp-rest-block-editor-settings-controller.php
1 year ago
class-wp-rest-customizer-nonces.php
1 year ago
class-wp-rest-navigation-fallback-controller.php
1 year ago
editor-settings.php
1 year ago
kses.php
1 year ago
l10n.php
1 year ago
navigation-fallback.php
1 year ago
navigation-theme-opt-in.php
1 year ago
rest-api.php
1 year ago
editor-settings.php
108 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Utilities to manage editor settings. |
| 4 | * |
| 5 | * @package gutenberg |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Initialize a block-based editor. |
| 10 | * |
| 11 | * @param string $editor_name Editor name. |
| 12 | * @param string $editor_script_handle Editor script handle. |
| 13 | * @param array $settings { |
| 14 | * Elements to initialize a block-based editor. |
| 15 | * |
| 16 | * @type array $preload_paths Array of paths to preload. |
| 17 | * @type string $initializer_name Editor initialization function name. |
| 18 | * @type array $editor_settings Editor settings. |
| 19 | * } |
| 20 | * @return void |
| 21 | */ |
| 22 | function gutenberg_initialize_editor( $editor_name, $editor_script_handle, $settings ) { |
| 23 | |
| 24 | $defaults = array( |
| 25 | 'preload_paths' => array(), |
| 26 | 'initializer_name' => 'initialize', |
| 27 | 'editor_settings' => array(), |
| 28 | ); |
| 29 | |
| 30 | $settings = wp_parse_args( $settings, $defaults ); |
| 31 | |
| 32 | /** |
| 33 | * Preload common data by specifying an array of REST API paths that will be preloaded. |
| 34 | * |
| 35 | * Filters the array of paths that will be preloaded. |
| 36 | * |
| 37 | * @param string[] $preload_paths Array of paths to preload. |
| 38 | */ |
| 39 | $preload_paths = apply_filters( "{$editor_name}_preload_paths", $settings['preload_paths'] ); |
| 40 | |
| 41 | $preload_data = array_reduce( |
| 42 | $preload_paths, |
| 43 | 'rest_preload_api_request', |
| 44 | array() |
| 45 | ); |
| 46 | |
| 47 | wp_add_inline_script( |
| 48 | 'wp-api-fetch', |
| 49 | sprintf( |
| 50 | 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );', |
| 51 | wp_json_encode( $preload_data ) |
| 52 | ), |
| 53 | 'after' |
| 54 | ); |
| 55 | wp_add_inline_script( |
| 56 | "wp-{$editor_script_handle}", |
| 57 | sprintf( |
| 58 | 'wp.domReady( function() { |
| 59 | wp.%s.%s( "%s", %s ); |
| 60 | } );', |
| 61 | lcfirst( str_replace( '-', '', ucwords( $editor_script_handle, '-' ) ) ), |
| 62 | $settings['initializer_name'], |
| 63 | str_replace( '_', '-', $editor_name ), |
| 64 | wp_json_encode( $settings['editor_settings'] ) |
| 65 | ) |
| 66 | ); |
| 67 | |
| 68 | // Preload server-registered block schemas. |
| 69 | wp_add_inline_script( |
| 70 | 'wp-blocks', |
| 71 | 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');' |
| 72 | ); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Sets a global JS variable used to trigger the availability of each Gutenberg Experiment. |
| 77 | */ |
| 78 | function gutenberg_enable_experiments() { |
| 79 | $gutenberg_experiments = get_option( 'gutenberg-experiments' ); |
| 80 | if ( $gutenberg_experiments && array_key_exists( 'gutenberg-zoomed-out-view', $gutenberg_experiments ) ) { |
| 81 | wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableZoomedOutView = true', 'before' ); |
| 82 | } |
| 83 | if ( $gutenberg_experiments && array_key_exists( 'gutenberg-color-randomizer', $gutenberg_experiments ) ) { |
| 84 | wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableColorRandomizer = true', 'before' ); |
| 85 | } |
| 86 | if ( $gutenberg_experiments && array_key_exists( 'gutenberg-command-center', $gutenberg_experiments ) ) { |
| 87 | wp_add_inline_script( 'wp-edit-site', 'window.__experimentalEnableCommandCenter = true', 'before' ); |
| 88 | } |
| 89 | if ( $gutenberg_experiments && array_key_exists( 'gutenberg-command-center', $gutenberg_experiments ) ) { |
| 90 | wp_add_inline_script( 'wp-edit-post', 'window.__experimentalEnableCommandCenter = true', 'before' ); |
| 91 | } |
| 92 | if ( $gutenberg_experiments && array_key_exists( 'gutenberg-group-grid-variation', $gutenberg_experiments ) ) { |
| 93 | wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableGroupGridVariation = true', 'before' ); |
| 94 | } |
| 95 | if ( $gutenberg_experiments && array_key_exists( 'gutenberg-details-blocks', $gutenberg_experiments ) ) { |
| 96 | wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableDetailsBlocks = true', 'before' ); |
| 97 | } |
| 98 | if ( $gutenberg_experiments && array_key_exists( 'gutenberg-interactivity-api-navigation-block', $gutenberg_experiments ) ) { |
| 99 | wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableNavigationBlockInteractivity = true', 'before' ); |
| 100 | } |
| 101 | if ( $gutenberg_experiments && array_key_exists( 'gutenberg-theme-previews', $gutenberg_experiments ) ) { |
| 102 | wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableThemePreviews = true', 'before' ); |
| 103 | } |
| 104 | |
| 105 | } |
| 106 | |
| 107 | add_action( 'admin_init', 'gutenberg_enable_experiments' ); |
| 108 |