lib/experimental/experiments
load.php
9.0 KB
3 months ago
load.php in Gutenberg 23.2.0, at lib/experimental/experiments/load.php
| 1 | <?php |
| 2 | /** |
| 3 | * Bootstraps the Gutenberg experiments page in wp-admin. |
| 4 | * |
| 5 | * @package gutenberg |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Set up the experiments settings. |
| 10 | * |
| 11 | * Registering an experiment here only exposes it on the Experiments screen. |
| 12 | * To actually enable a new experiment in the editor, add a matching bridge |
| 13 | * (e.g. a `window.__experimental*` global) in `gutenberg_enable_experiments()` |
| 14 | * in `lib/experimental/editor-settings.php`. |
| 15 | */ |
| 16 | function gutenberg_initialize_experiments_settings() { |
| 17 | $groups = array( |
| 18 | array( |
| 19 | 'slug' => 'blocks', |
| 20 | 'label' => _x( 'Blocks', 'experiments group name', 'gutenberg' ), |
| 21 | 'items' => array( |
| 22 | array( |
| 23 | 'id' => 'gutenberg-block-experiments', |
| 24 | 'label' => __( 'Experimental blocks', 'gutenberg' ), |
| 25 | 'description' => __( 'Enables experimental blocks on a rolling basis as they are developed. (Warning: these blocks may have significant changes during development that cause validation errors and display issues.)', 'gutenberg' ), |
| 26 | ), |
| 27 | array( |
| 28 | 'id' => 'gutenberg-form-blocks', |
| 29 | 'label' => __( 'Form and input blocks', 'gutenberg' ), |
| 30 | 'description' => __( 'Enables new blocks to allow building forms. You are likely to experience UX issues that are being addressed.', 'gutenberg' ), |
| 31 | ), |
| 32 | array( |
| 33 | 'id' => 'gutenberg-grid-interactivity', |
| 34 | 'label' => __( 'Grid interactivity', 'gutenberg' ), |
| 35 | 'description' => __( 'Enables enhancements to the Grid block that let you move and resize items in the editor canvas.', 'gutenberg' ), |
| 36 | ), |
| 37 | array( |
| 38 | 'id' => 'gutenberg-classic-block-deprecation', |
| 39 | 'label' => __( 'Classic block deprecation', 'gutenberg' ), |
| 40 | 'description' => __( 'Enables UI changes aimed at deprecating the Classic block, including prompts on existing Classic blocks to migrate their content to blocks or to a Custom HTML block.', 'gutenberg' ), |
| 41 | ), |
| 42 | ), |
| 43 | ), |
| 44 | array( |
| 45 | 'slug' => 'media', |
| 46 | 'label' => _x( 'Media', 'experiments group name', 'gutenberg' ), |
| 47 | 'items' => array( |
| 48 | array( |
| 49 | 'id' => 'gutenberg-media-editor', |
| 50 | 'label' => __( 'Media Editor (Route)', 'gutenberg' ), |
| 51 | 'description' => __( 'Enables a dedicated route-based media editor screen for editing media items (metadata and content).', 'gutenberg' ), |
| 52 | ), |
| 53 | array( |
| 54 | 'id' => 'gutenberg-media-editor-modal', |
| 55 | 'label' => __( 'Media Editor Modal', 'gutenberg' ), |
| 56 | 'description' => __( 'Enables an in-place modal for image editing — cropping, adjustments, and metadata — opened from blocks like the image block without navigating away from the current post.', 'gutenberg' ), |
| 57 | ), |
| 58 | array( |
| 59 | 'id' => 'gutenberg-dataviews-media-modal', |
| 60 | 'label' => __( 'Media Upload Modal', 'gutenberg' ), |
| 61 | 'description' => __( 'Replaces the existing WordPress media modal with a new modal powered by Data Views, supporting browsing, selecting, and uploading media.', 'gutenberg' ), |
| 62 | ), |
| 63 | ), |
| 64 | ), |
| 65 | array( |
| 66 | 'slug' => 'data-views', |
| 67 | 'label' => _x( 'Data Views', 'experiments group name', 'gutenberg' ), |
| 68 | 'items' => array( |
| 69 | array( |
| 70 | 'id' => 'gutenberg-content-only-inspector-fields', |
| 71 | 'label' => __( 'Block fields: Show dataform driven inspector fields on blocks that support them', 'gutenberg' ), |
| 72 | 'description' => __( 'Enables editable block inspector fields that are generated using a dataform.', 'gutenberg' ), |
| 73 | ), |
| 74 | array( |
| 75 | 'id' => 'gutenberg-dataform-inspector', |
| 76 | 'label' => __( 'Editor Inspector: Use DataForm', 'gutenberg' ), |
| 77 | 'description' => __( 'Replaces the bespoke editor inspector panels with a unified DataForm-based implementation for Pages and Posts, matching the QuickEdit experience.', 'gutenberg' ), |
| 78 | ), |
| 79 | ), |
| 80 | ), |
| 81 | array( |
| 82 | 'slug' => 'interactivity', |
| 83 | 'label' => _x( 'Interactivity', 'experiments group name', 'gutenberg' ), |
| 84 | 'items' => array( |
| 85 | array( |
| 86 | 'id' => 'gutenberg-full-page-client-side-navigation', |
| 87 | 'label' => __( 'Full-page client-side navigation', 'gutenberg' ), |
| 88 | 'description' => __( 'Enables full-page client-side navigation, powered by the Interactivity API.', 'gutenberg' ), |
| 89 | ), |
| 90 | ), |
| 91 | ), |
| 92 | array( |
| 93 | 'slug' => 'templates', |
| 94 | 'label' => _x( 'Templates', 'experiments group name', 'gutenberg' ), |
| 95 | 'items' => array( |
| 96 | array( |
| 97 | 'id' => 'active_templates', |
| 98 | 'label' => __( 'Template Activation', 'gutenberg' ), |
| 99 | 'description' => __( 'Allows multiple templates of the same type to be created, of which one can be active at a time. (Warning: when you deactivate this experiment, it is best to delete all created templates except for the active ones.)', 'gutenberg' ), |
| 100 | 'separateOption' => true, |
| 101 | ), |
| 102 | ), |
| 103 | ), |
| 104 | array( |
| 105 | 'slug' => 'other', |
| 106 | 'label' => _x( 'Other', 'experiments group name', 'gutenberg' ), |
| 107 | 'items' => array( |
| 108 | array( |
| 109 | 'id' => 'gutenberg-color-randomizer', |
| 110 | 'label' => __( 'Color randomizer', 'gutenberg' ), |
| 111 | 'description' => __( 'Enables the Global Styles color randomizer in the Site Editor; a utility that lets you mix the current color palette pseudo-randomly.', 'gutenberg' ), |
| 112 | ), |
| 113 | array( |
| 114 | 'id' => 'gutenberg-workflow-palette', |
| 115 | 'label' => __( 'Workflow Palette', 'gutenberg' ), |
| 116 | 'description' => __( 'Enables the Workflow Palette for running workflows composed of abilities, from a unified interface.', 'gutenberg' ), |
| 117 | ), |
| 118 | array( |
| 119 | 'id' => 'gutenberg-extensible-site-editor', |
| 120 | 'label' => __( 'Extensible Site Editor', 'gutenberg' ), |
| 121 | 'description' => __( 'Redirects the default site editor (Appearance > Design) to use the extensible site editor page.', 'gutenberg' ), |
| 122 | ), |
| 123 | array( |
| 124 | 'id' => 'gutenberg-guidelines', |
| 125 | 'label' => __( 'Guidelines', 'gutenberg' ), |
| 126 | 'description' => __( 'Enables guidelines feature for managing editorial voice and tone guidelines under Settings.', 'gutenberg' ), |
| 127 | ), |
| 128 | array( |
| 129 | 'id' => 'gutenberg-content-types', |
| 130 | 'label' => __( 'Content types', 'gutenberg' ), |
| 131 | 'description' => __( 'Enables a UI for creating and managing custom taxonomies and custom post types under Settings.', 'gutenberg' ), |
| 132 | ), |
| 133 | array( |
| 134 | 'id' => 'gutenberg-dashboard-widgets', |
| 135 | 'label' => __( 'New Dashboard experience', 'gutenberg' ), |
| 136 | 'description' => __( 'Enables a new dashboard experience with resizable, reorderable widgets that plugins can register and users can personalize.', 'gutenberg' ), |
| 137 | ), |
| 138 | ), |
| 139 | ), |
| 140 | ); |
| 141 | |
| 142 | $properties = array(); |
| 143 | |
| 144 | foreach ( $groups as $group ) { |
| 145 | foreach ( $group['items'] as $experiment ) { |
| 146 | $property = array( |
| 147 | 'type' => 'boolean', |
| 148 | 'title' => $experiment['label'], |
| 149 | 'description' => $experiment['description'], |
| 150 | 'group' => $group['slug'], |
| 151 | 'group_label' => $group['label'], |
| 152 | ); |
| 153 | |
| 154 | // Metadata-only entry: values for separateOption experiments live in |
| 155 | // their own option (e.g. `active_templates`). Surfaced here so the UI |
| 156 | // can render them from the settings schema. |
| 157 | if ( ! empty( $experiment['separateOption'] ) ) { |
| 158 | $property['separate_option'] = true; |
| 159 | $property['option_name'] = $experiment['id']; |
| 160 | } |
| 161 | |
| 162 | $properties[ $experiment['id'] ] = $property; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | register_setting( |
| 167 | 'gutenberg-experiments', |
| 168 | 'gutenberg-experiments', |
| 169 | array( |
| 170 | 'label' => __( 'Gutenberg Experiments', 'gutenberg' ), |
| 171 | 'show_in_rest' => array( |
| 172 | 'schema' => array( |
| 173 | 'type' => 'object', |
| 174 | 'properties' => $properties, |
| 175 | ), |
| 176 | ), |
| 177 | 'default' => array(), |
| 178 | ) |
| 179 | ); |
| 180 | } |
| 181 | |
| 182 | add_action( 'rest_api_init', 'gutenberg_initialize_experiments_settings' ); |
| 183 | |
| 184 | /** |
| 185 | * Registers the Experiments submenu page under the Gutenberg menu. |
| 186 | */ |
| 187 | function gutenberg_experiments_menu() { |
| 188 | add_submenu_page( |
| 189 | 'gutenberg', |
| 190 | __( 'Experiments Settings', 'gutenberg' ), |
| 191 | __( 'Experiments', 'gutenberg' ), |
| 192 | 'manage_options', |
| 193 | 'experiments-wp-admin', |
| 194 | 'gutenberg_experiments_wp_admin_render_page' |
| 195 | ); |
| 196 | } |
| 197 | add_action( 'admin_menu', 'gutenberg_experiments_menu' ); |
| 198 | |
| 199 | /** |
| 200 | * Allows the legacy `gutenberg-experiments` route. Without this, accessing |
| 201 | * `?page=gutenberg-experiments` results in an HTTP 403 error. |
| 202 | * |
| 203 | * Allowing the route is done by adding a wp-admin submenu page that won't be rendered. |
| 204 | */ |
| 205 | function gutenberg_experiments_legacy_menu() { |
| 206 | add_submenu_page( '', '', '', 'manage_options', 'gutenberg-experiments', '__return_empty_string' ); |
| 207 | } |
| 208 | add_action( 'admin_menu', 'gutenberg_experiments_legacy_menu', 9 ); |
| 209 | |
| 210 | /** |
| 211 | * Redirects the legacy `?page=gutenberg-experiments` URL to the new |
| 212 | * `?page=experiments-wp-admin` URL. |
| 213 | */ |
| 214 | function gutenberg_redirect_legacy_experiments_page() { |
| 215 | wp_safe_redirect( admin_url( 'admin.php?page=experiments-wp-admin' ) ); |
| 216 | exit; |
| 217 | } |
| 218 | add_action( 'load-admin_page_gutenberg-experiments', 'gutenberg_redirect_legacy_experiments_page' ); |
| 219 | add_action( 'load-toplevel_page_gutenberg-experiments', 'gutenberg_redirect_legacy_experiments_page' ); |
| 220 | add_action( 'load-gutenberg_page_gutenberg-experiments', 'gutenberg_redirect_legacy_experiments_page' ); |
| 221 |