PluginProbe
Gutenberg / 20.0.2
Gutenberg v20.0.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 / experimental / posts / load.php

load.php in Gutenberg 20.0.2, at lib/experimental/posts/load.php

90 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Bootstraps the new posts dashboard page.
4 *
5 * @package Gutenberg
6 */
7
8 add_action( 'admin_menu', 'gutenberg_replace_posts_dashboard' );
9
10 if ( isset( $_GET['page'] ) && 'gutenberg-posts-dashboard' === $_GET['page'] ) {
11 // Default to is-fullscreen-mode to avoid jumps in the UI.
12 add_filter(
13 'admin_body_class',
14 static function ( $classes ) {
15 return "$classes is-fullscreen-mode";
16 }
17 );
18 }
19
20 /**
21 * Renders the new posts dashboard page.
22 */
23 function gutenberg_posts_dashboard() {
24 $block_editor_context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) );
25 $custom_settings = array(
26 'siteUrl' => site_url(),
27 'styles' => get_block_editor_theme_styles(),
28 'supportsLayout' => wp_theme_has_theme_json(),
29 );
30
31 $editor_settings = get_block_editor_settings( $custom_settings, $block_editor_context );
32 $active_global_styles_id = WP_Theme_JSON_Resolver_Gutenberg::get_user_global_styles_post_id();
33 $active_theme = get_stylesheet();
34
35 $preload_paths = array(
36 array( '/wp/v2/media', 'OPTIONS' ),
37 '/wp/v2/types?context=view',
38 '/wp/v2/global-styles/' . $active_global_styles_id . '?context=edit',
39 '/wp/v2/global-styles/' . $active_global_styles_id,
40 '/wp/v2/global-styles/themes/' . $active_theme,
41 );
42 block_editor_rest_api_preload( $preload_paths, $block_editor_context );
43
44 // Preload server-registered block schemas.
45 wp_add_inline_script(
46 'wp-blocks',
47 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');'
48 );
49
50 /** This action is documented in wp-admin/edit-form-blocks.php */
51 do_action( 'enqueue_block_editor_assets' );
52 wp_register_style(
53 'wp-gutenberg-posts-dashboard',
54 gutenberg_url( 'build/edit-site/posts.css' ),
55 array( 'wp-components', 'wp-commands', 'wp-edit-site' )
56 );
57 wp_enqueue_style( 'wp-gutenberg-posts-dashboard' );
58 wp_add_inline_script(
59 'wp-edit-site',
60 sprintf(
61 'wp.domReady( function() {
62 wp.editSite.initializePostsDashboard( "gutenberg-posts-dashboard", %s );
63 } );',
64 wp_json_encode( $editor_settings )
65 )
66 );
67 wp_enqueue_script( 'wp-edit-site' );
68 wp_enqueue_media();
69 echo '<div id="gutenberg-posts-dashboard"></div>';
70 }
71
72 /**
73 * Replaces the default posts menu item with the new posts dashboard.
74 */
75 function gutenberg_replace_posts_dashboard() {
76 $gutenberg_experiments = get_option( 'gutenberg-experiments' );
77 if ( ! $gutenberg_experiments || ! array_key_exists( 'gutenberg-new-posts-dashboard', $gutenberg_experiments ) || ! $gutenberg_experiments['gutenberg-new-posts-dashboard'] ) {
78 return;
79 }
80 $ptype_obj = get_post_type_object( 'post' );
81 add_submenu_page(
82 'gutenberg',
83 $ptype_obj->labels->name,
84 $ptype_obj->labels->name,
85 'edit_posts',
86 'gutenberg-posts-dashboard',
87 'gutenberg_posts_dashboard'
88 );
89 }
90