PluginProbe
Gutenberg / 8.5.1
Gutenberg v8.5.1
24.0.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 All 403 releases
← All changes | lib/navigation-page.php +53 -127 12.6.0 → 8.5.1 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2 /**
3 - * Bootstrapping the Gutenberg Navigation page.
3 + * Bootstraping the Gutenberg Navigation page.
4 4 *
5 5 * @package gutenberg
6 6 */
7 7
@@ -20,156 +20,82 @@
20 20 <?php
21 21 }
22 22
23 23 /**
24 - * This function returns an url for the /wp/v2/menus endpoint
24 + * Initialize the Gutenberg Navigation page.
25 25 *
26 - * @since 11.8.0
26 + * @since 7.8.0
27 27 *
28 - * @param int $results_per_page Results per page.
29 - * @return string
28 + * @param string $hook Page.
30 29 */
31 -function gutenberg_navigation_get_menus_endpoint( $results_per_page = 100 ) {
32 - return '/wp/v2/menus?' . build_query(
33 - array(
34 - 'per_page' => $results_per_page,
35 - 'context' => 'edit',
36 - '_locale' => 'user',
37 - )
38 - );
39 -}
30 +function gutenberg_navigation_init( $hook ) {
31 + if ( 'gutenberg_page_gutenberg-navigation' !== $hook ) {
32 + return;
33 + }
40 34
41 -/**
42 - * This function returns an url for the /wp/v2/menu-items endpoint
43 - *
44 - * @since 11.8.0
45 - *
46 - * @param int $menu_id Menu ID.
47 - * @param int $results_per_page Results per page.
48 - * @return string
49 - */
50 -function gutenberg_navigation_get_menu_items_endpoint( $menu_id, $results_per_page = 100 ) {
51 - return '/wp/v2/menu-items?' . build_query(
52 - array(
53 - 'context' => 'edit',
54 - 'menus' => $menu_id,
55 - 'per_page' => $results_per_page,
56 - '_locale' => 'user',
57 - )
58 - );
59 -}
35 + // Media settings.
36 + $max_upload_size = wp_max_upload_size();
37 + if ( ! $max_upload_size ) {
38 + $max_upload_size = 0;
39 + }
60 40
61 -/**
62 - * This function returns an url for the /wp/v2/types endpoint
63 - *
64 - * @since 11.8.0
65 - *
66 - * @return string
67 - */
68 -function gutenberg_navigation_get_types_endpoint() {
69 - return '/wp/v2/types?' . build_query(
41 + /** This filter is documented in wp-admin/includes/media.php */
42 + $image_size_names = apply_filters(
43 + 'image_size_names_choose',
70 44 array(
71 - 'context' => 'edit',
45 + 'thumbnail' => __( 'Thumbnail', 'gutenberg' ),
46 + 'medium' => __( 'Medium', 'gutenberg' ),
47 + 'large' => __( 'Large', 'gutenberg' ),
48 + 'full' => __( 'Full Size', 'gutenberg' ),
72 49 )
73 50 );
74 -}
75 51
76 -/**
77 - * Initialize the Gutenberg Navigation page.
78 - *
79 - * @param string $hook Page.
80 - * @since 7.8.0
81 - */
82 -function gutenberg_navigation_init( $hook ) {
83 - if ( 'gutenberg_page_gutenberg-navigation' !== $hook ) {
84 - return;
52 + $available_image_sizes = array();
53 + foreach ( $image_size_names as $image_size_slug => $image_size_name ) {
54 + $available_image_sizes[] = array(
55 + 'slug' => $image_size_slug,
56 + 'name' => $image_size_name,
57 + );
85 58 }
86 59
87 - $menus = wp_get_nav_menus();
88 - $first_menu_id = ! empty( $menus ) ? $menus[0]->term_id : null;
60 + $settings = array(
61 + 'disableCustomColors' => get_theme_support( 'disable-custom-colors' ),
62 + 'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
63 + 'imageSizes' => $available_image_sizes,
64 + 'isRTL' => is_rtl(),
65 + 'maxUploadFileSize' => $max_upload_size,
66 + );
89 67
90 - $preload_paths = array(
91 - '/wp/v2/menu-locations',
92 - array( '/wp/v2/pages', 'OPTIONS' ),
93 - array( '/wp/v2/posts', 'OPTIONS' ),
94 - gutenberg_navigation_get_types_endpoint(),
95 - );
68 + list( $color_palette, ) = (array) get_theme_support( 'editor-color-palette' );
69 + list( $font_sizes, ) = (array) get_theme_support( 'editor-font-sizes' );
96 70
97 - if ( $first_menu_id ) {
98 - $preload_paths[] = gutenberg_navigation_get_menu_items_endpoint( $first_menu_id );
71 + if ( false !== $color_palette ) {
72 + $settings['colors'] = $color_palette;
99 73 }
100 74
101 - $settings = array_merge(
102 - get_default_block_editor_settings(),
103 - array(
104 - 'blockNavMenus' => false,
105 - // We should uncomment the line below when the block-nav-menus feature becomes stable.
106 - // @see https://github.com/WordPress/gutenberg/issues/34265.
107 - /*'blockNavMenus' => get_theme_support( 'block-nav-menus' ),*/
75 + if ( false !== $font_sizes ) {
76 + $settings['fontSizes'] = $font_sizes;
77 + }
78 +
79 + wp_add_inline_script(
80 + 'wp-edit-navigation',
81 + sprintf(
82 + 'wp.domReady( function() {
83 + wp.editNavigation.initialize( "navigation-editor", %s );
84 + } );',
85 + wp_json_encode( gutenberg_experiments_editor_settings( $settings ) )
108 86 )
109 87 );
110 - $settings = gutenberg_experimental_global_styles_settings( $settings );
111 88
112 - gutenberg_initialize_editor(
113 - 'navigation_editor',
114 - 'edit-navigation',
115 - array(
116 - 'initializer_name' => 'initialize',
117 - 'editor_settings' => $settings,
118 - 'preload_paths' => $preload_paths,
119 - )
89 + // Preload server-registered block schemas.
90 + wp_add_inline_script(
91 + 'wp-blocks',
92 + 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');'
120 93 );
121 94
122 - gutenberg_navigation_editor_preload_menus();
123 -
124 95 wp_enqueue_script( 'wp-edit-navigation' );
125 96 wp_enqueue_style( 'wp-edit-navigation' );
97 + wp_enqueue_style( 'wp-block-library' );
126 98 wp_enqueue_script( 'wp-format-library' );
127 99 wp_enqueue_style( 'wp-format-library' );
128 - do_action( 'enqueue_block_editor_assets' );
129 100 }
130 101 add_action( 'admin_enqueue_scripts', 'gutenberg_navigation_init' );
131 -
132 -/**
133 - * Tells the script loader to load the scripts and styles of custom block on navigation editor screen.
134 - *
135 - * @param bool $is_block_editor_screen Current decision about loading block assets.
136 - * @return bool Filtered decision about loading block assets.
137 - */
138 -function gutenberg_navigation_editor_load_block_editor_scripts_and_styles( $is_block_editor_screen ) {
139 - if ( is_callable( 'get_current_screen' ) && get_current_screen() && 'gutenberg_page_gutenberg-navigation' === get_current_screen()->base ) {
140 - return true;
141 - }
142 -
143 - return $is_block_editor_screen;
144 -}
145 -
146 -add_filter( 'should_load_block_editor_scripts_and_styles', 'gutenberg_navigation_editor_load_block_editor_scripts_and_styles' );
147 -
148 -/**
149 - * This function calls createMenuPreloadingMiddleware middleware because
150 - * we need to use custom preloading logic for menus.
151 - *
152 - * @return void
153 - */
154 -function gutenberg_navigation_editor_preload_menus() {
155 - $menus_data = array_reduce(
156 - array(
157 - gutenberg_navigation_get_menus_endpoint(),
158 - ),
159 - 'rest_preload_api_request',
160 - array()
161 - );
162 -
163 - if ( ! $menus_data ) {
164 - return;
165 - }
166 -
167 - wp_add_inline_script(
168 - 'wp-edit-navigation',
169 - sprintf(
170 - 'wp.apiFetch.use( wp.editNavigation.__unstableCreateMenuPreloadingMiddleware( %s ) );',
171 - wp_json_encode( $menus_data )
172 - ),
173 - 'after'
174 - );
175 -}