PluginProbe
Gutenberg / 9.6.2
Gutenberg v9.6.2
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 / lib / edit-site-page.php

edit-site-page.php in Gutenberg 9.6.2, at lib/edit-site-page.php

206 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Bootstraping the Gutenberg Edit Site Page.
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * The main entry point for the Gutenberg Edit Site Page.
10 *
11 * @since 7.2.0
12 */
13 function gutenberg_edit_site_page() {
14 ?>
15 <div
16 id="edit-site-editor"
17 class="edit-site"
18 >
19 </div>
20 <?php
21 }
22
23 /**
24 * Checks whether the provided page is one of allowed Site Editor pages.
25 *
26 * @param string $page Page to check.
27 *
28 * @return bool True for Site Editor pages, false otherwise.
29 */
30 function gutenberg_is_edit_site_page( $page ) {
31 return 'toplevel_page_gutenberg-edit-site' === $page;
32 }
33
34 /**
35 * Load editor styles (this is copied from edit-form-blocks.php).
36 * Ideally the code is extracted into a reusable function.
37 *
38 * @return array Editor Styles Setting.
39 */
40 function gutenberg_get_editor_styles() {
41 global $editor_styles;
42
43 // Ideally the code is extracted into a reusable function.
44 $styles = array(
45 array(
46 'css' => file_get_contents(
47 ABSPATH . WPINC . '/css/dist/editor/editor-styles.css'
48 ),
49 ),
50 );
51
52 /* translators: Use this to specify the CSS font family for the default font. */
53 $locale_font_family = esc_html_x( 'Noto Serif', 'CSS Font Family for Editor Font', 'gutenberg' );
54 $styles[] = array(
55 'css' => "body { font-family: '$locale_font_family' }",
56 );
57
58 if ( $editor_styles && current_theme_supports( 'editor-styles' ) ) {
59 foreach ( $editor_styles as $style ) {
60 if ( preg_match( '~^(https?:)?//~', $style ) ) {
61 $response = wp_remote_get( $style );
62 if ( ! is_wp_error( $response ) ) {
63 $styles[] = array(
64 'css' => wp_remote_retrieve_body( $response ),
65 );
66 }
67 } else {
68 $file = get_theme_file_path( $style );
69 if ( is_file( $file ) ) {
70 $styles[] = array(
71 'css' => file_get_contents( $file ),
72 'baseURL' => get_theme_file_uri( $style ),
73 );
74 }
75 }
76 }
77 }
78
79 return $styles;
80 }
81
82 /**
83 * Initialize the Gutenberg Edit Site Page.
84 *
85 * @since 7.2.0
86 *
87 * @param string $hook Page.
88 */
89 function gutenberg_edit_site_init( $hook ) {
90 global $current_screen, $post;
91
92 if ( ! gutenberg_is_edit_site_page( $hook ) ) {
93 return;
94 }
95
96 /**
97 * Make the WP Screen object aware that this is a block editor page.
98 * Since custom blocks check whether the screen is_block_editor,
99 * this is required for custom blocks to be loaded.
100 * See wp_enqueue_registered_block_scripts_and_styles in wp-includes/script-loader.php
101 */
102 $current_screen->is_block_editor( true );
103
104 $settings = array_merge(
105 gutenberg_get_common_block_editor_settings(),
106 array(
107 'alignWide' => get_theme_support( 'align-wide' ),
108 'siteUrl' => site_url(),
109 'postsPerPage' => get_option( 'posts_per_page' ),
110 'styles' => gutenberg_get_editor_styles(),
111 'defaultTemplateTypes' => gutenberg_get_indexed_default_template_types(),
112 )
113 );
114 $settings = gutenberg_experimental_global_styles_settings( $settings );
115 $settings = gutenberg_extend_settings_block_patterns( $settings );
116
117 // Preload block editor paths.
118 // most of these are copied from edit-forms-blocks.php.
119 $preload_paths = array(
120 '/?context=edit',
121 '/wp/v2/types?context=edit',
122 '/wp/v2/taxonomies?context=edit',
123 '/wp/v2/pages?context=edit',
124 '/wp/v2/themes?status=active',
125 array( '/wp/v2/media', 'OPTIONS' ),
126 );
127 $preload_data = array_reduce(
128 $preload_paths,
129 'rest_preload_api_request',
130 array()
131 );
132 wp_add_inline_script(
133 'wp-api-fetch',
134 sprintf( 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );', wp_json_encode( $preload_data ) ),
135 'after'
136 );
137
138 // Initialize editor.
139 wp_add_inline_script(
140 'wp-edit-site',
141 sprintf(
142 'wp.domReady( function() {
143 wp.editSite.initialize( "edit-site-editor", %s );
144 } );',
145 wp_json_encode( $settings )
146 )
147 );
148
149 wp_add_inline_script(
150 'wp-blocks',
151 sprintf( 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions( %s );', wp_json_encode( get_block_editor_server_block_settings() ) ),
152 'after'
153 );
154
155 wp_add_inline_script(
156 'wp-blocks',
157 sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( $post ) ) ),
158 'after'
159 );
160
161 /**
162 * Fires after block assets have been enqueued for the editing interface.
163 *
164 * Call `add_action` on any hook before 'admin_enqueue_scripts'.
165 *
166 * In the function call you supply, simply use `wp_enqueue_script` and
167 * `wp_enqueue_style` to add your functionality to the block editor.
168 *
169 * @since 5.0.0
170 */
171
172 do_action( 'enqueue_block_editor_assets' );
173
174 wp_enqueue_script( 'wp-edit-site' );
175 wp_enqueue_script( 'wp-format-library' );
176 wp_enqueue_style( 'wp-edit-site' );
177 wp_enqueue_style( 'wp-format-library' );
178 }
179 add_action( 'admin_enqueue_scripts', 'gutenberg_edit_site_init' );
180
181 /**
182 * Register a core site setting for front page information.
183 */
184 function register_site_editor_homepage_settings() {
185 register_setting(
186 'reading',
187 'show_on_front',
188 array(
189 'show_in_rest' => true,
190 'type' => 'string',
191 'description' => __( 'What to show on the front page', 'gutenberg' ),
192 )
193 );
194
195 register_setting(
196 'reading',
197 'page_on_front',
198 array(
199 'show_in_rest' => true,
200 'type' => 'number',
201 'description' => __( 'The ID of the page that should be displayed on the front page', 'gutenberg' ),
202 )
203 );
204 }
205 add_action( 'init', 'register_site_editor_homepage_settings', 10 );
206