forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gutenberg.php
151 lines (133 loc) · 4.01 KB
/
gutenberg.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
* Plugin Name: Gutenberg
* Plugin URI: https://github.com/WordPress/gutenberg
* Description: Printing since 1440. This is the development plugin for the new block editor in core.
* Version: 7.5.0-rc.1
* Author: Gutenberg Team
* Text Domain: gutenberg
*
* @package gutenberg
*/
### BEGIN AUTO-GENERATED DEFINES
defined( 'GUTENBERG_DEVELOPMENT_MODE' ) or define( 'GUTENBERG_DEVELOPMENT_MODE', true );
### END AUTO-GENERATED DEFINES
gutenberg_pre_init();
/**
* Gutenberg's Menu.
*
* Adds a new wp-admin menu page for the Gutenberg editor.
*
* @since 0.1.0
*/
function gutenberg_menu() {
global $submenu;
add_menu_page(
'Gutenberg',
'Gutenberg',
'edit_posts',
'gutenberg',
'',
'dashicons-edit'
);
add_submenu_page(
'gutenberg',
__( 'Demo', 'gutenberg' ),
__( 'Demo', 'gutenberg' ),
'edit_posts',
'gutenberg'
);
if ( get_option( 'gutenberg-experiments' ) ) {
if ( array_key_exists( 'gutenberg-widget-experiments', get_option( 'gutenberg-experiments' ) ) ) {
add_submenu_page(
'gutenberg',
__( 'Widgets (beta)', 'gutenberg' ),
__( 'Widgets (beta)', 'gutenberg' ),
'edit_theme_options',
'gutenberg-widgets',
'the_gutenberg_widgets'
);
}
if ( array_key_exists( 'gutenberg-full-site-editing', get_option( 'gutenberg-experiments' ) ) ) {
add_submenu_page(
'gutenberg',
__( 'Site Editor (beta)', 'gutenberg' ),
__( 'Site Editor (beta)', 'gutenberg' ),
'edit_theme_options',
'gutenberg-edit-site',
'gutenberg_edit_site_page'
);
}
}
if ( current_user_can( 'edit_posts' ) ) {
$submenu['gutenberg'][] = array(
__( 'Support', 'gutenberg' ),
'edit_posts',
__( 'https://wordpress.org/support/plugin/gutenberg', 'gutenberg' ),
);
$submenu['gutenberg'][] = array(
__( 'Documentation', 'gutenberg' ),
'edit_posts',
'https://developer.wordpress.org/block-editor/',
);
}
add_submenu_page(
'gutenberg',
__( 'Experiments Settings', 'gutenberg' ),
__( 'Experiments', 'gutenberg' ),
'edit_posts',
'gutenberg-experiments',
'the_gutenberg_experiments'
);
}
add_action( 'admin_menu', 'gutenberg_menu' );
/**
* Display a version notice and deactivate the Gutenberg plugin.
*
* @since 0.1.0
*/
function gutenberg_wordpress_version_notice() {
echo '<div class="error"><p>';
/* translators: %s: Minimum required version */
printf( __( 'Gutenberg requires WordPress %s or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' ), '5.2.0' );
echo '</p></div>';
deactivate_plugins( array( 'gutenberg/gutenberg.php' ) );
}
/**
* Display a build notice.
*
* @since 0.1.0
*/
function gutenberg_build_files_notice() {
echo '<div class="error"><p>';
_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' );
echo '</p></div>';
}
/**
* Verify that we can initialize the Gutenberg editor , then load it.
*
* @since 1.5.0
*/
function gutenberg_pre_init() {
global $wp_version;
if ( defined( 'GUTENBERG_DEVELOPMENT_MODE' ) && GUTENBERG_DEVELOPMENT_MODE && ! file_exists( dirname( __FILE__ ) . '/build/blocks' ) ) {
add_action( 'admin_notices', 'gutenberg_build_files_notice' );
return;
}
// Get unmodified $wp_version.
include ABSPATH . WPINC . '/version.php';
// Strip '-src' from the version string. Messes up version_compare().
$version = str_replace( '-src', '', $wp_version );
if ( version_compare( $version, '5.2.0', '<' ) ) {
add_action( 'admin_notices', 'gutenberg_wordpress_version_notice' );
return;
}
require_once dirname( __FILE__ ) . '/lib/load.php';
}
/**
* Outputs a WP REST API nonce.
*/
function gutenberg_rest_nonce() {
exit( wp_create_nonce( 'wp_rest' ) );
}
add_action( 'wp_ajax_gutenberg_rest_nonce', 'gutenberg_rest_nonce' );