| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Gutenberg |
| 4 |
* Plugin URI: https://github.com/WordPress/gutenberg |
| 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.7.1 |
| 9 |
* Author: Gutenberg Team |
| 10 |
* Text Domain: gutenberg |
| 11 |
* |
| 12 |
* @package gutenberg |
| 13 |
*/ |
| 14 |
|
| 15 |
### BEGIN AUTO-GENERATED DEFINES |
| 16 |
define( 'GUTENBERG_VERSION', '9.7.1' ); |
| 17 |
define( 'GUTENBERG_GIT_COMMIT', 'ad95a27d0b97a25da883ab60a7bcc94bc4b925ae' ); |
| 18 |
### END AUTO-GENERATED DEFINES |
| 19 |
|
| 20 |
gutenberg_pre_init(); |
| 21 |
|
| 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 |
* Display a version notice and deactivate the Gutenberg plugin. |
| 142 |
* |
| 143 |
* @since 0.1.0 |
| 144 |
*/ |
| 145 |
function gutenberg_wordpress_version_notice() { |
| 146 |
echo '<div class="error"><p>'; |
| 147 |
/* translators: %s: Minimum required version */ |
| 148 |
printf( __( 'Gutenberg requires WordPress %s or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' ), '5.3.0' ); |
| 149 |
echo '</p></div>'; |
| 150 |
|
| 151 |
deactivate_plugins( array( 'gutenberg/gutenberg.php' ) ); |
| 152 |
} |
| 153 |
|
| 154 |
/** |
| 155 |
* Display a build notice. |
| 156 |
* |
| 157 |
* @since 0.1.0 |
| 158 |
*/ |
| 159 |
function gutenberg_build_files_notice() { |
| 160 |
echo '<div class="error"><p>'; |
| 161 |
_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' ); |
| 162 |
echo '</p></div>'; |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* Verify that we can initialize the Gutenberg editor , then load it. |
| 167 |
* |
| 168 |
* @since 1.5.0 |
| 169 |
*/ |
| 170 |
function gutenberg_pre_init() { |
| 171 |
global $wp_version; |
| 172 |
if ( defined( 'GUTENBERG_DEVELOPMENT_MODE' ) && GUTENBERG_DEVELOPMENT_MODE && ! file_exists( __DIR__ . '/build/blocks' ) ) { |
| 173 |
add_action( 'admin_notices', 'gutenberg_build_files_notice' ); |
| 174 |
return; |
| 175 |
} |
| 176 |
|
| 177 |
// Get unmodified $wp_version. |
| 178 |
include ABSPATH . WPINC . '/version.php'; |
| 179 |
|
| 180 |
// Strip '-src' from the version string. Messes up version_compare(). |
| 181 |
$version = str_replace( '-src', '', $wp_version ); |
| 182 |
|
| 183 |
if ( version_compare( $version, '5.3.0', '<' ) ) { |
| 184 |
add_action( 'admin_notices', 'gutenberg_wordpress_version_notice' ); |
| 185 |
return; |
| 186 |
} |
| 187 |
|
| 188 |
require_once __DIR__ . '/lib/load.php'; |
| 189 |
} |
| 190 |
|
| 191 |
/** |
| 192 |
* Outputs a WP REST API nonce. |
| 193 |
*/ |
| 194 |
function gutenberg_rest_nonce() { |
| 195 |
exit( wp_create_nonce( 'wp_rest' ) ); |
| 196 |
} |
| 197 |
add_action( 'wp_ajax_gutenberg_rest_nonce', 'gutenberg_rest_nonce' ); |
| 198 |
|
| 199 |
|
| 200 |
/** |
| 201 |
* Exposes the site icon url to the Gutenberg editor through the WordPress REST |
| 202 |
* API. The site icon url should instead be fetched from the wp/v2/settings |
| 203 |
* endpoint when https://github.com/WordPress/gutenberg/pull/19967 is complete. |
| 204 |
* |
| 205 |
* @since 8.2.1 |
| 206 |
* |
| 207 |
* @param WP_REST_Response $response Response data served by the WordPress REST index endpoint. |
| 208 |
* @return WP_REST_Response |
| 209 |
*/ |
| 210 |
function register_site_icon_url( $response ) { |
| 211 |
$data = $response->data; |
| 212 |
$data['site_icon_url'] = get_site_icon_url(); |
| 213 |
$response->set_data( $data ); |
| 214 |
return $response; |
| 215 |
} |
| 216 |
|
| 217 |
add_filter( 'rest_index', 'register_site_icon_url' ); |
| 218 |
|
| 219 |
add_theme_support( 'widgets-block-editor' ); |
| 220 |
|