PluginProbe
Gutenberg / 5.2.0
Gutenberg v5.2.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / gutenberg.php

gutenberg.php in Gutenberg 5.2.0, at gutenberg.php

239 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.2.0
7 * Author: Gutenberg Team
8 * Text Domain: gutenberg
9 *
10 * @package gutenberg
11 */
12
13 ### BEGIN AUTO-GENERATED DEFINES
14 define( 'GUTENBERG_VERSION', '5.2.0' );
15 define( 'GUTENBERG_GIT_COMMIT', '6de5263995fb574229fdd4b388f38a1006710746' );
16 ### END AUTO-GENERATED DEFINES
17
18 gutenberg_pre_init();
19
20 /**
21 * Project.
22 *
23 * The main entry point for the Gutenberg editor. Renders the editor on the
24 * wp-admin page for the plugin.
25 *
26 * The gutenberg and gutenberg__editor classNames are left for backward compatibility.
27 *
28 * @since 0.1.0
29 */
30 function the_gutenberg_project() {
31 global $post_type_object;
32 ?>
33 <noscript>
34 <div class="error" style="position:absolute;top:32px;z-index:40"><p>
35 <?php
36 printf(
37 /* translators: %s: https://wordpress.org/plugins/classic-editor/ */
38 __( 'The Block Editor requires JavaScript. Please try the <a href="%s">Classic Editor plugin</a>.', 'gutenberg' ),
39 __( 'https://wordpress.org/plugins/classic-editor/', 'gutenberg' )
40 );
41 ?>
42 </p></div>
43 </noscript>
44 <div class="block-editor gutenberg">
45 <h1 class="screen-reader-text"><?php echo esc_html( $post_type_object->labels->edit_item ); ?></h1>
46 <div id="editor" class="block-editor__container gutenberg__editor"></div>
47 <div id="metaboxes" class="hidden">
48 <?php the_block_editor_meta_boxes(); ?>
49 </div>
50 </div>
51 <?php
52 }
53
54 /**
55 * Gutenberg's Menu.
56 *
57 * Adds a new wp-admin menu page for the Gutenberg editor.
58 *
59 * @since 0.1.0
60 */
61 function gutenberg_menu() {
62 global $submenu;
63
64 add_menu_page(
65 'Gutenberg',
66 'Gutenberg',
67 'edit_posts',
68 'gutenberg',
69 'the_gutenberg_project',
70 'dashicons-edit'
71 );
72
73 add_submenu_page(
74 'gutenberg',
75 __( 'Demo', 'gutenberg' ),
76 __( 'Demo', 'gutenberg' ),
77 'edit_posts',
78 'gutenberg'
79 );
80
81 add_submenu_page(
82 'gutenberg',
83 __( 'Widgets (beta)', 'gutenberg' ),
84 __( 'Widgets (beta)', 'gutenberg' ),
85 'edit_theme_options',
86 'gutenberg-widgets',
87 'the_gutenberg_widgets'
88 );
89
90 if ( current_user_can( 'edit_posts' ) ) {
91 $submenu['gutenberg'][] = array(
92 __( 'Support', 'gutenberg' ),
93 'edit_posts',
94 __( 'https://wordpress.org/support/plugin/gutenberg', 'gutenberg' ),
95 );
96
97 $submenu['gutenberg'][] = array(
98 __( 'Documentation', 'gutenberg' ),
99 'edit_posts',
100 'https://wordpress.org/gutenberg/handbook/',
101 );
102 }
103 }
104 add_action( 'admin_menu', 'gutenberg_menu' );
105
106 /**
107 * Checks whether we're currently loading a Gutenberg page
108 *
109 * @return boolean Whether Gutenberg is being loaded.
110 *
111 * @since 3.1.0
112 */
113 function is_gutenberg_page() {
114 global $post;
115
116 if ( ! is_admin() ) {
117 return false;
118 }
119
120 /*
121 * There have been reports of specialized loading scenarios where `get_current_screen`
122 * does not exist. In these cases, it is safe to say we are not loading Gutenberg.
123 */
124 if ( ! function_exists( 'get_current_screen' ) ) {
125 return false;
126 }
127
128 if ( get_current_screen()->base !== 'post' ) {
129 return false;
130 }
131
132 if ( ! use_block_editor_for_post( $post ) ) {
133 return false;
134 }
135
136 return true;
137 }
138
139 /**
140 * Display a version notice and deactivate the Gutenberg plugin.
141 *
142 * @since 0.1.0
143 */
144 function gutenberg_wordpress_version_notice() {
145 echo '<div class="error"><p>';
146 /* translators: %s: Minimum required version */
147 printf( __( 'Gutenberg requires WordPress %s or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' ), '5.0.0' );
148 echo '</p></div>';
149
150 deactivate_plugins( array( 'gutenberg/gutenberg.php' ) );
151 }
152
153 /**
154 * Display a build notice.
155 *
156 * @since 0.1.0
157 */
158 function gutenberg_build_files_notice() {
159 echo '<div class="error"><p>';
160 _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' );
161 echo '</p></div>';
162 }
163
164 /**
165 * Verify that we can initialize the Gutenberg editor , then load it.
166 *
167 * @since 1.5.0
168 */
169 function gutenberg_pre_init() {
170 if ( defined( 'GUTENBERG_DEVELOPMENT_MODE' ) && GUTENBERG_DEVELOPMENT_MODE && ! file_exists( dirname( __FILE__ ) . '/build/blocks' ) ) {
171 add_action( 'admin_notices', 'gutenberg_build_files_notice' );
172 return;
173 }
174
175 // Get unmodified $wp_version.
176 include ABSPATH . WPINC . '/version.php';
177
178 // Strip '-src' from the version string. Messes up version_compare().
179 $version = str_replace( '-src', '', $wp_version );
180
181 if ( version_compare( $version, '5.0.0', '<' ) ) {
182 add_action( 'admin_notices', 'gutenberg_wordpress_version_notice' );
183 return;
184 }
185
186 require_once dirname( __FILE__ ) . '/lib/load.php';
187
188 add_filter( 'replace_editor', 'gutenberg_init', 10, 2 );
189 }
190
191 /**
192 * Initialize Gutenberg.
193 *
194 * Load API functions, register scripts and actions, etc.
195 *
196 * @param bool $return Whether to replace the editor. Used in the `replace_editor` filter.
197 * @param object $post The post to edit or an auto-draft.
198 * @return bool Whether Gutenberg was initialized.
199 */
200 function gutenberg_init( $return, $post ) {
201 if ( true === $return && current_filter() === 'replace_editor' ) {
202 return $return;
203 }
204
205 if ( ! is_gutenberg_page() ) {
206 return false;
207 }
208
209 // Instruct WordPress that this is the block editor. Without this, a call
210 // to `is_block_editor()` would yield `false` while editing a post with
211 // Gutenberg.
212 //
213 // [TODO]: This is temporary so long as Gutenberg is implemented to use
214 // `replace_editor`, rather than allow `edit-form-blocks.php` from core to
215 // take effect, where this would otherwise be assigned.
216 get_current_screen()->is_block_editor( true );
217
218 add_action( 'admin_enqueue_scripts', 'gutenberg_editor_scripts_and_styles' );
219 add_filter( 'screen_options_show_screen', '__return_false' );
220
221 /*
222 * Remove the emoji script as it is incompatible with both React and any
223 * contenteditable fields.
224 */
225 remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
226
227 /*
228 * Ensure meta box functions are available to third-party code;
229 * includes/meta-boxes is typically loaded from edit-form-advanced.php.
230 */
231 require_once ABSPATH . 'wp-admin/includes/meta-boxes.php';
232 register_and_do_post_meta_boxes( $post );
233
234 require_once ABSPATH . 'wp-admin/admin-header.php';
235 the_gutenberg_project();
236
237 return true;
238 }
239