| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: Gutenberg |
| 4 | 4 | * Plugin URI: https://github.com/WordPress/gutenberg |
| 5 | - * Description: Printing since 1440. This is the development plugin for the block editor, site editor, and other future WordPress core functionality. | |
| 6 | - * Requires at least: 6.8 | |
| 7 | - * Requires PHP: 7.4 | |
| 8 | - * Version: 23.2.0 | |
| 5 | + * Description: Printing since 1440. This is the development plugin for the new block editor in core. | |
| 6 | + * Requires at least: 5.3 | |
| 7 | + * Requires PHP: 5.6 | |
| 8 | + * Version: 9.8.0 | |
| 9 | 9 | * Author: Gutenberg Team |
| 10 | 10 | * Text Domain: gutenberg |
| 11 | 11 | * |
| 12 | 12 | * @package gutenberg |
| @@ -11,13 +11,159 @@ | ||
| 11 | 11 | * |
| 12 | 12 | * @package gutenberg |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -defined( 'GUTENBERG_MINIMUM_WP_VERSION' ) or define( 'GUTENBERG_MINIMUM_WP_VERSION', '6.8' ); | |
| 15 | +### BEGIN AUTO-GENERATED DEFINES | |
| 16 | +define( 'GUTENBERG_VERSION', '9.8.0' ); | |
| 17 | +define( 'GUTENBERG_GIT_COMMIT', 'd1cd03958a707b0a7d003f8f8e9e589f7db51d28' ); | |
| 18 | +### END AUTO-GENERATED DEFINES | |
| 16 | 19 | |
| 17 | 20 | gutenberg_pre_init(); |
| 18 | 21 | |
| 19 | 22 | /** |
| 23 | + * Gutenberg's Menu. | |
| 24 | + * | |
| 25 | + * Adds a new wp-admin menu page for the Gutenberg editor. | |
| 26 | + * | |
| 27 | + * @since 0.1.0 | |
| 28 | + */ | |
| 29 | +function gutenberg_menu() { | |
| 30 | + add_menu_page( | |
| 31 | + 'Gutenberg', | |
| 32 | + 'Gutenberg', | |
| 33 | + 'edit_posts', | |
| 34 | + 'gutenberg', | |
| 35 | + '', | |
| 36 | + 'dashicons-edit' | |
| 37 | + ); | |
| 38 | + | |
| 39 | + add_submenu_page( | |
| 40 | + 'gutenberg', | |
| 41 | + __( 'Demo', 'gutenberg' ), | |
| 42 | + __( 'Demo', 'gutenberg' ), | |
| 43 | + 'edit_posts', | |
| 44 | + 'gutenberg' | |
| 45 | + ); | |
| 46 | + | |
| 47 | + if ( gutenberg_use_widgets_block_editor() ) { | |
| 48 | + add_theme_page( | |
| 49 | + __( 'Widgets', 'gutenberg' ), | |
| 50 | + __( 'Widgets', 'gutenberg' ), | |
| 51 | + 'edit_theme_options', | |
| 52 | + 'gutenberg-widgets', | |
| 53 | + 'the_gutenberg_widgets' | |
| 54 | + ); | |
| 55 | + remove_submenu_page( 'themes.php', 'widgets.php' ); | |
| 56 | + } | |
| 57 | + | |
| 58 | + if ( get_option( 'gutenberg-experiments' ) ) { | |
| 59 | + if ( array_key_exists( 'gutenberg-navigation', get_option( 'gutenberg-experiments' ) ) ) { | |
| 60 | + add_submenu_page( | |
| 61 | + 'gutenberg', | |
| 62 | + __( 'Navigation (beta)', 'gutenberg' ), | |
| 63 | + __( 'Navigation (beta)', 'gutenberg' ), | |
| 64 | + 'edit_theme_options', | |
| 65 | + 'gutenberg-navigation', | |
| 66 | + 'gutenberg_navigation_page' | |
| 67 | + ); | |
| 68 | + } | |
| 69 | + } | |
| 70 | + if ( current_user_can( 'edit_posts' ) ) { | |
| 71 | + add_submenu_page( | |
| 72 | + 'gutenberg', | |
| 73 | + __( 'Support', 'gutenberg' ), | |
| 74 | + __( 'Support', 'gutenberg' ), | |
| 75 | + 'edit_posts', | |
| 76 | + __( 'https://wordpress.org/support/plugin/gutenberg/', 'gutenberg' ) | |
| 77 | + ); | |
| 78 | + add_submenu_page( | |
| 79 | + 'gutenberg', | |
| 80 | + __( 'Documentation', 'gutenberg' ), | |
| 81 | + __( 'Documentation', 'gutenberg' ), | |
| 82 | + 'edit_posts', | |
| 83 | + 'https://developer.wordpress.org/block-editor/' | |
| 84 | + ); | |
| 85 | + } | |
| 86 | + | |
| 87 | + add_submenu_page( | |
| 88 | + 'gutenberg', | |
| 89 | + __( 'Experiments Settings', 'gutenberg' ), | |
| 90 | + __( 'Experiments', 'gutenberg' ), | |
| 91 | + 'edit_posts', | |
| 92 | + 'gutenberg-experiments', | |
| 93 | + 'the_gutenberg_experiments' | |
| 94 | + ); | |
| 95 | +} | |
| 96 | +add_action( 'admin_menu', 'gutenberg_menu', 9 ); | |
| 97 | + | |
| 98 | +/** | |
| 99 | + * Site editor's Menu. | |
| 100 | + * | |
| 101 | + * Adds a new wp-admin menu item for the Site editor. | |
| 102 | + * | |
| 103 | + * @since 9.4.0 | |
| 104 | + */ | |
| 105 | +function gutenberg_site_editor_menu() { | |
| 106 | + if ( gutenberg_is_fse_theme() ) { | |
| 107 | + add_menu_page( | |
| 108 | + __( 'Site Editor (beta)', 'gutenberg' ), | |
| 109 | + sprintf( | |
| 110 | + /* translators: %s: "beta" label. */ | |
| 111 | + __( 'Site Editor %s', 'gutenberg' ), | |
| 112 | + '<span class="awaiting-mod">' . __( 'beta', 'gutenberg' ) . '</span>' | |
| 113 | + ), | |
| 114 | + 'edit_theme_options', | |
| 115 | + 'gutenberg-edit-site', | |
| 116 | + 'gutenberg_edit_site_page', | |
| 117 | + 'dashicons-layout' | |
| 118 | + ); | |
| 119 | + } | |
| 120 | +} | |
| 121 | +add_action( 'admin_menu', 'gutenberg_site_editor_menu', 9 ); | |
| 122 | + | |
| 123 | +/** | |
| 124 | + * Modify WP admin bar. | |
| 125 | + * | |
| 126 | + * @param WP_Admin_Bar $wp_admin_bar Core class used to implement the Toolbar API. | |
| 127 | + */ | |
| 128 | +function modify_admin_bar( $wp_admin_bar ) { | |
| 129 | + if ( gutenberg_use_widgets_block_editor() ) { | |
| 130 | + $wp_admin_bar->add_menu( | |
| 131 | + array( | |
| 132 | + 'id' => 'widgets', | |
| 133 | + 'href' => admin_url( 'themes.php?page=gutenberg-widgets' ), | |
| 134 | + ) | |
| 135 | + ); | |
| 136 | + } | |
| 137 | +} | |
| 138 | +add_action( 'admin_bar_menu', 'modify_admin_bar', 40 ); | |
| 139 | + | |
| 140 | + | |
| 141 | +remove_action( 'welcome_panel', 'wp_welcome_panel' ); | |
| 142 | +/** | |
| 143 | + * Modify Dashboard welcome panel. | |
| 144 | + * | |
| 145 | + * When widgets are merged in core this should go into `wp-admin/includes/dashboard.php` | |
| 146 | + * and replace the widgets link in the `wp_welcome_panel` checking for the same condition, | |
| 147 | + * because then `gutenberg_use_widgets_block_editor` will exist in core. | |
| 148 | + */ | |
| 149 | +function modify_welcome_panel() { | |
| 150 | + ob_start(); | |
| 151 | + wp_welcome_panel(); | |
| 152 | + $welcome_panel = ob_get_clean(); | |
| 153 | + if ( gutenberg_use_widgets_block_editor() ) { | |
| 154 | + echo str_replace( | |
| 155 | + admin_url( 'widgets.php' ), | |
| 156 | + admin_url( 'themes.php?page=gutenberg-widgets' ), | |
| 157 | + $welcome_panel | |
| 158 | + ); | |
| 159 | + } else { | |
| 160 | + echo $welcome_panel; | |
| 161 | + } | |
| 162 | +} | |
| 163 | +add_action( 'welcome_panel', 'modify_welcome_panel', 40 ); | |
| 164 | + | |
| 165 | +/** | |
| 20 | 166 | * Display a version notice and deactivate the Gutenberg plugin. |
| 21 | 167 | * |
| 22 | 168 | * @since 0.1.0 |
| 23 | 169 | */ |
| @@ -23,9 +169,9 @@ | ||
| 23 | 169 | */ |
| 24 | 170 | function gutenberg_wordpress_version_notice() { |
| 25 | 171 | echo '<div class="error"><p>'; |
| 26 | 172 | /* translators: %s: Minimum required version */ |
| 27 | - printf( __( 'Gutenberg requires WordPress %s or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' ), GUTENBERG_MINIMUM_WP_VERSION ); | |
| 173 | + printf( __( 'Gutenberg requires WordPress %s or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' ), '5.3.0' ); | |
| 28 | 174 | echo '</p></div>'; |
| 29 | 175 | |
| 30 | 176 | deactivate_plugins( array( 'gutenberg/gutenberg.php' ) ); |
| 31 | 177 | } |
| @@ -36,9 +182,9 @@ | ||
| 36 | 182 | * @since 0.1.0 |
| 37 | 183 | */ |
| 38 | 184 | function gutenberg_build_files_notice() { |
| 39 | 185 | echo '<div class="error"><p>'; |
| 40 | - _e( 'Gutenberg development mode requires files to be built. Run <code>npm install</code> to install dependencies, <code>npm run build</code> to build the files or <code>npm run dev</code> to build the files and watch for changes. Read the <a href="https://github.com/WordPress/gutenberg/blob/HEAD/docs/contributors/code/getting-started-with-code-contribution.md">contributing</a> file for more information.', 'gutenberg' ); | |
| 186 | + _e( 'Gutenberg development mode requires files to be built. Run <code>npm install</code> to install dependencies, <code>npm run build</code> to build the files or <code>npm run dev</code> to build the files and watch for changes. Read the <a href="https://github.com/WordPress/gutenberg/blob/master/docs/contributors/getting-started.md">contributing</a> file for more information.', 'gutenberg' ); | |
| 41 | 187 | echo '</p></div>'; |
| 42 | 188 | } |
| 43 | 189 | |
| 44 | 190 | /** |
| @@ -44,15 +190,12 @@ | ||
| 44 | 190 | /** |
| 45 | 191 | * Verify that we can initialize the Gutenberg editor , then load it. |
| 46 | 192 | * |
| 47 | 193 | * @since 1.5.0 |
| 48 | - * | |
| 49 | - * @global string $wp_version The WordPress version string. | |
| 50 | - * | |
| 51 | 194 | */ |
| 52 | 195 | function gutenberg_pre_init() { |
| 53 | 196 | global $wp_version; |
| 54 | - if ( ! file_exists( __DIR__ . '/build/scripts/blocks' ) ) { | |
| 197 | + if ( defined( 'GUTENBERG_DEVELOPMENT_MODE' ) && GUTENBERG_DEVELOPMENT_MODE && ! file_exists( __DIR__ . '/build/blocks' ) ) { | |
| 55 | 198 | add_action( 'admin_notices', 'gutenberg_build_files_notice' ); |
| 56 | 199 | return; |
| 57 | 200 | } |
| 58 | 201 | |
| @@ -61,12 +204,9 @@ | ||
| 61 | 204 | |
| 62 | 205 | // Strip '-src' from the version string. Messes up version_compare(). |
| 63 | 206 | $version = str_replace( '-src', '', $wp_version ); |
| 64 | 207 | |
| 65 | - // Compare against major release versions (X.Y) rather than minor (X.Y.Z) | |
| 66 | - // unless a minor release is the actual minimum requirement. WordPress reports | |
| 67 | - // X.Y for its major releases. | |
| 68 | - if ( version_compare( $version, GUTENBERG_MINIMUM_WP_VERSION, '<' ) ) { | |
| 208 | + if ( version_compare( $version, '5.3.0', '<' ) ) { | |
| 69 | 209 | add_action( 'admin_notices', 'gutenberg_wordpress_version_notice' ); |
| 70 | 210 | return; |
| 71 | 211 | } |
| 72 | 212 | |
| @@ -71,4 +211,34 @@ | ||
| 71 | 211 | } |
| 72 | 212 | |
| 73 | 213 | require_once __DIR__ . '/lib/load.php'; |
| 74 | 214 | } |
| 215 | + | |
| 216 | +/** | |
| 217 | + * Outputs a WP REST API nonce. | |
| 218 | + */ | |
| 219 | +function gutenberg_rest_nonce() { | |
| 220 | + exit( wp_create_nonce( 'wp_rest' ) ); | |
| 221 | +} | |
| 222 | +add_action( 'wp_ajax_gutenberg_rest_nonce', 'gutenberg_rest_nonce' ); | |
| 223 | + | |
| 224 | + | |
| 225 | +/** | |
| 226 | + * Exposes the site icon url to the Gutenberg editor through the WordPress REST | |
| 227 | + * API. The site icon url should instead be fetched from the wp/v2/settings | |
| 228 | + * endpoint when https://github.com/WordPress/gutenberg/pull/19967 is complete. | |
| 229 | + * | |
| 230 | + * @since 8.2.1 | |
| 231 | + * | |
| 232 | + * @param WP_REST_Response $response Response data served by the WordPress REST index endpoint. | |
| 233 | + * @return WP_REST_Response | |
| 234 | + */ | |
| 235 | +function register_site_icon_url( $response ) { | |
| 236 | + $data = $response->data; | |
| 237 | + $data['site_icon_url'] = get_site_icon_url(); | |
| 238 | + $response->set_data( $data ); | |
| 239 | + return $response; | |
| 240 | +} | |
| 241 | + | |
| 242 | +add_filter( 'rest_index', 'register_site_icon_url' ); | |
| 243 | + | |
| 244 | +add_theme_support( 'widgets-block-editor' ); | |