| 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 |
* Version: 5.1.0 |
| 7 |
* Author: Gutenberg Team |
| 8 |
* |
| 9 |
* @package gutenberg |
| 10 |
*/ |
| 11 |
|
| 12 |
### BEGIN AUTO-GENERATED DEFINES |
| 13 |
define( 'GUTENBERG_VERSION', '5.1.0' ); |
| 14 |
define( 'GUTENBERG_GIT_COMMIT', 'bfe46d67e7870342db2b42393be23736ca75af75' ); |
| 15 |
### END AUTO-GENERATED DEFINES |
| 16 |
|
| 17 |
gutenberg_pre_init(); |
| 18 |
|
| 19 |
/** |
| 20 |
* Project. |
| 21 |
* |
| 22 |
* The main entry point for the Gutenberg editor. Renders the editor on the |
| 23 |
* wp-admin page for the plugin. |
| 24 |
* |
| 25 |
* The gutenberg and gutenberg__editor classNames are left for backward compatibility. |
| 26 |
* |
| 27 |
* @since 0.1.0 |
| 28 |
*/ |
| 29 |
function the_gutenberg_project() { |
| 30 |
global $post_type_object; |
| 31 |
?> |
| 32 |
<noscript> |
| 33 |
<div class="error" style="position:absolute;top:32px;z-index:40"><p> |
| 34 |
<?php |
| 35 |
printf( |
| 36 |
/* translators: %s: https://wordpress.org/plugins/classic-editor/ */ |
| 37 |
__( 'The Block Editor requires JavaScript. Please try the <a href="%s">Classic Editor plugin</a>.', 'gutenberg' ), |
| 38 |
__( 'https://wordpress.org/plugins/classic-editor/', 'gutenberg' ) |
| 39 |
); |
| 40 |
?> |
| 41 |
</p></div> |
| 42 |
</noscript> |
| 43 |
<div class="block-editor gutenberg"> |
| 44 |
<h1 class="screen-reader-text"><?php echo esc_html( $post_type_object->labels->edit_item ); ?></h1> |
| 45 |
<div id="editor" class="block-editor__container gutenberg__editor"></div> |
| 46 |
<div id="metaboxes" class="hidden"> |
| 47 |
<?php the_block_editor_meta_boxes(); ?> |
| 48 |
</div> |
| 49 |
</div> |
| 50 |
<?php |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Gutenberg's Menu. |
| 55 |
* |
| 56 |
* Adds a new wp-admin menu page for the Gutenberg editor. |
| 57 |
* |
| 58 |
* @since 0.1.0 |
| 59 |
*/ |
| 60 |
function gutenberg_menu() { |
| 61 |
global $submenu; |
| 62 |
|
| 63 |
add_menu_page( |
| 64 |
'Gutenberg', |
| 65 |
'Gutenberg', |
| 66 |
'edit_posts', |
| 67 |
'gutenberg', |
| 68 |
'the_gutenberg_project', |
| 69 |
'dashicons-edit' |
| 70 |
); |
| 71 |
|
| 72 |
add_submenu_page( |
| 73 |
'gutenberg', |
| 74 |
__( 'Demo', 'gutenberg' ), |
| 75 |
__( 'Demo', 'gutenberg' ), |
| 76 |
'edit_posts', |
| 77 |
'gutenberg' |
| 78 |
); |
| 79 |
|
| 80 |
if ( current_user_can( 'edit_posts' ) ) { |
| 81 |
$submenu['gutenberg'][] = array( |
| 82 |
__( 'Support', 'gutenberg' ), |
| 83 |
'edit_posts', |
| 84 |
__( 'https://wordpress.org/support/plugin/gutenberg', 'gutenberg' ), |
| 85 |
); |
| 86 |
|
| 87 |
$submenu['gutenberg'][] = array( |
| 88 |
__( 'Documentation', 'gutenberg' ), |
| 89 |
'edit_posts', |
| 90 |
'https://wordpress.org/gutenberg/handbook/', |
| 91 |
); |
| 92 |
} |
| 93 |
} |
| 94 |
add_action( 'admin_menu', 'gutenberg_menu' ); |
| 95 |
|
| 96 |
/** |
| 97 |
* Checks whether we're currently loading a Gutenberg page |
| 98 |
* |
| 99 |
* @return boolean Whether Gutenberg is being loaded. |
| 100 |
* |
| 101 |
* @since 3.1.0 |
| 102 |
*/ |
| 103 |
function is_gutenberg_page() { |
| 104 |
global $post; |
| 105 |
|
| 106 |
if ( ! is_admin() ) { |
| 107 |
return false; |
| 108 |
} |
| 109 |
|
| 110 |
/* |
| 111 |
* There have been reports of specialized loading scenarios where `get_current_screen` |
| 112 |
* does not exist. In these cases, it is safe to say we are not loading Gutenberg. |
| 113 |
*/ |
| 114 |
if ( ! function_exists( 'get_current_screen' ) ) { |
| 115 |
return false; |
| 116 |
} |
| 117 |
|
| 118 |
if ( get_current_screen()->base !== 'post' ) { |
| 119 |
return false; |
| 120 |
} |
| 121 |
|
| 122 |
if ( ! use_block_editor_for_post( $post ) ) { |
| 123 |
return false; |
| 124 |
} |
| 125 |
|
| 126 |
return true; |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* Display a version notice and deactivate the Gutenberg plugin. |
| 131 |
* |
| 132 |
* @since 0.1.0 |
| 133 |
*/ |
| 134 |
function gutenberg_wordpress_version_notice() { |
| 135 |
echo '<div class="error"><p>'; |
| 136 |
/* translators: %s: Minimum required version */ |
| 137 |
printf( __( 'Gutenberg requires WordPress %s or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' ), '5.0.0' ); |
| 138 |
echo '</p></div>'; |
| 139 |
|
| 140 |
deactivate_plugins( array( 'gutenberg/gutenberg.php' ) ); |
| 141 |
} |
| 142 |
|
| 143 |
/** |
| 144 |
* Display a build notice. |
| 145 |
* |
| 146 |
* @since 0.1.0 |
| 147 |
*/ |
| 148 |
function gutenberg_build_files_notice() { |
| 149 |
echo '<div class="error"><p>'; |
| 150 |
_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/CONTRIBUTING.md">contributing</a> file for more information.', 'gutenberg' ); |
| 151 |
echo '</p></div>'; |
| 152 |
} |
| 153 |
|
| 154 |
/** |
| 155 |
* Verify that we can initialize the Gutenberg editor , then load it. |
| 156 |
* |
| 157 |
* @since 1.5.0 |
| 158 |
*/ |
| 159 |
function gutenberg_pre_init() { |
| 160 |
if ( defined( 'GUTENBERG_DEVELOPMENT_MODE' ) && GUTENBERG_DEVELOPMENT_MODE && ! file_exists( dirname( __FILE__ ) . '/build/blocks' ) ) { |
| 161 |
add_action( 'admin_notices', 'gutenberg_build_files_notice' ); |
| 162 |
return; |
| 163 |
} |
| 164 |
|
| 165 |
// Get unmodified $wp_version. |
| 166 |
include ABSPATH . WPINC . '/version.php'; |
| 167 |
|
| 168 |
// Strip '-src' from the version string. Messes up version_compare(). |
| 169 |
$version = str_replace( '-src', '', $wp_version ); |
| 170 |
|
| 171 |
if ( version_compare( $version, '5.0.0', '<' ) ) { |
| 172 |
add_action( 'admin_notices', 'gutenberg_wordpress_version_notice' ); |
| 173 |
return; |
| 174 |
} |
| 175 |
|
| 176 |
require_once dirname( __FILE__ ) . '/lib/load.php'; |
| 177 |
|
| 178 |
add_filter( 'replace_editor', 'gutenberg_init', 10, 2 ); |
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* Initialize Gutenberg. |
| 183 |
* |
| 184 |
* Load API functions, register scripts and actions, etc. |
| 185 |
* |
| 186 |
* @param bool $return Whether to replace the editor. Used in the `replace_editor` filter. |
| 187 |
* @param object $post The post to edit or an auto-draft. |
| 188 |
* @return bool Whether Gutenberg was initialized. |
| 189 |
*/ |
| 190 |
function gutenberg_init( $return, $post ) { |
| 191 |
if ( true === $return && current_filter() === 'replace_editor' ) { |
| 192 |
return $return; |
| 193 |
} |
| 194 |
|
| 195 |
if ( ! is_gutenberg_page() ) { |
| 196 |
return false; |
| 197 |
} |
| 198 |
|
| 199 |
// Instruct WordPress that this is the block editor. Without this, a call |
| 200 |
// to `is_block_editor()` would yield `false` while editing a post with |
| 201 |
// Gutenberg. |
| 202 |
// |
| 203 |
// [TODO]: This is temporary so long as Gutenberg is implemented to use |
| 204 |
// `replace_editor`, rather than allow `edit-form-blocks.php` from core to |
| 205 |
// take effect, where this would otherwise be assigned. |
| 206 |
get_current_screen()->is_block_editor( true ); |
| 207 |
|
| 208 |
add_action( 'admin_enqueue_scripts', 'gutenberg_editor_scripts_and_styles' ); |
| 209 |
add_filter( 'screen_options_show_screen', '__return_false' ); |
| 210 |
|
| 211 |
/* |
| 212 |
* Remove the emoji script as it is incompatible with both React and any |
| 213 |
* contenteditable fields. |
| 214 |
*/ |
| 215 |
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); |
| 216 |
|
| 217 |
/* |
| 218 |
* Ensure meta box functions are available to third-party code; |
| 219 |
* includes/meta-boxes is typically loaded from edit-form-advanced.php. |
| 220 |
*/ |
| 221 |
require_once ABSPATH . 'wp-admin/includes/meta-boxes.php'; |
| 222 |
register_and_do_post_meta_boxes( $post ); |
| 223 |
|
| 224 |
require_once ABSPATH . 'wp-admin/admin-header.php'; |
| 225 |
the_gutenberg_project(); |
| 226 |
|
| 227 |
return true; |
| 228 |
} |
| 229 |
|
| 230 |
/** |
| 231 |
* Adds the filters to register additional links for the Gutenberg editor in |
| 232 |
* the post/page screens. |
| 233 |
* |
| 234 |
* @since 1.5.0 |
| 235 |
* @deprecated 5.0.0 |
| 236 |
*/ |
| 237 |
function gutenberg_add_edit_link_filters() { |
| 238 |
_deprecated_function( __FUNCTION__, '5.0.0' ); |
| 239 |
} |
| 240 |
|
| 241 |
/** |
| 242 |
* Registers an additional link in the post/page screens to edit any post/page in |
| 243 |
* the Classic editor. |
| 244 |
* |
| 245 |
* @since 1.5.0 |
| 246 |
* @deprecated 5.0.0 |
| 247 |
* |
| 248 |
* @param array $actions Post actions. |
| 249 |
* |
| 250 |
* @return array Updated post actions. |
| 251 |
*/ |
| 252 |
function gutenberg_add_edit_link( $actions ) { |
| 253 |
_deprecated_function( __FUNCTION__, '5.0.0' ); |
| 254 |
|
| 255 |
return $actions; |
| 256 |
} |
| 257 |
|
| 258 |
/** |
| 259 |
* Removes the Edit action from the reusable block list's Bulk Actions dropdown. |
| 260 |
* |
| 261 |
* @since 3.8.0 |
| 262 |
* @deprecated 5.0.0 |
| 263 |
* |
| 264 |
* @param array $actions Bulk actions. |
| 265 |
* |
| 266 |
* @return array Updated bulk actions. |
| 267 |
*/ |
| 268 |
function gutenberg_block_bulk_actions( $actions ) { |
| 269 |
_deprecated_function( __FUNCTION__, '5.0.0' ); |
| 270 |
|
| 271 |
return $actions; |
| 272 |
} |
| 273 |
|
| 274 |
/** |
| 275 |
* Prints the JavaScript to replace the default "Add New" button.$_COOKIE |
| 276 |
* |
| 277 |
* @since 1.5.0 |
| 278 |
* @deprecated 5.0.0 |
| 279 |
*/ |
| 280 |
function gutenberg_replace_default_add_new_button() { |
| 281 |
_deprecated_function( __FUNCTION__, '5.0.0' ); |
| 282 |
} |
| 283 |
|
| 284 |
/** |
| 285 |
* Adds the block-editor-page class to the body tag on the Gutenberg page. |
| 286 |
* |
| 287 |
* @since 1.5.0 |
| 288 |
* @deprecated 5.0.0 |
| 289 |
* |
| 290 |
* @param string $classes Space separated string of classes being added to the body tag. |
| 291 |
* @return string The $classes string, with block-editor-page appended. |
| 292 |
*/ |
| 293 |
function gutenberg_add_admin_body_class( $classes ) { |
| 294 |
_deprecated_function( __FUNCTION__, '5.0.0' ); |
| 295 |
|
| 296 |
return $classes; |
| 297 |
} |
| 298 |
|
| 299 |
/** |
| 300 |
* Adds attributes to kses allowed tags that aren't in the default list |
| 301 |
* and that Gutenberg needs to save blocks such as the Gallery block. |
| 302 |
* |
| 303 |
* @deprecated 5.0.0 |
| 304 |
* |
| 305 |
* @param array $tags Allowed HTML. |
| 306 |
* @return array (Maybe) modified allowed HTML. |
| 307 |
*/ |
| 308 |
function gutenberg_kses_allowedtags( $tags ) { |
| 309 |
_deprecated_function( __FUNCTION__, '5.0.0' ); |
| 310 |
|
| 311 |
return $tags; |
| 312 |
} |
| 313 |
|
| 314 |
/** |
| 315 |
* Adds the wp-embed-responsive class to the body tag if the theme has opted in to |
| 316 |
* Gutenberg responsive embeds. |
| 317 |
* |
| 318 |
* @since 4.1.0 |
| 319 |
* @deprecated 5.0.0 |
| 320 |
* |
| 321 |
* @param Array $classes Array of classes being added to the body tag. |
| 322 |
* @return Array The $classes array, with wp-embed-responsive appended. |
| 323 |
*/ |
| 324 |
function gutenberg_add_responsive_body_class( $classes ) { |
| 325 |
_deprecated_function( __FUNCTION__, '5.0.0' ); |
| 326 |
|
| 327 |
return $classes; |
| 328 |
} |
| 329 |
|