PluginProbe
Gutenberg / 9.0.0
Gutenberg v9.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 7.4.0 All 402 releases
gutenberg / lib / widgets-page.php

widgets-page.php in Gutenberg 9.0.0, at lib/widgets-page.php

126 lines 3.1 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 widgets page.
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * The main entry point for the Gutenberg widgets page.
10 *
11 * @since 5.2.0
12 *
13 * @param string $page The page name the function is being called for, `'gutenberg_customizer'` for the Customizer.
14 */
15 function the_gutenberg_widgets( $page = 'appearance_page_gutenberg-widgets' ) {
16 ?>
17 <div
18 id="widgets-editor"
19 class="blocks-widgets-container
20 <?php
21 echo 'gutenberg_customizer' === $page
22 ? ' is-in-customizer'
23 : '';
24 ?>
25 "
26 >
27 </div>
28 <?php
29 }
30
31 /**
32 * Initialize the Gutenberg widgets page.
33 *
34 * @since 5.2.0
35 *
36 * @param string $hook Page.
37 */
38 function gutenberg_widgets_init( $hook ) {
39 if ( 'widgets.php' === $hook ) {
40 wp_enqueue_style( 'wp-block-library' );
41 wp_enqueue_style( 'wp-block-library-theme' );
42 wp_add_inline_style(
43 'wp-block-library-theme',
44 '.block-widget-form .widget-control-save { display: none; }'
45 );
46 return;
47 }
48 if ( ! in_array( $hook, array( 'appearance_page_gutenberg-widgets', 'gutenberg_customizer' ), true ) ) {
49 return;
50 }
51
52 $initializer_name = 'appearance_page_gutenberg-widgets' === $hook
53 ? 'initialize'
54 : 'customizerInitialize';
55
56 // Media settings.
57 $max_upload_size = wp_max_upload_size();
58 if ( ! $max_upload_size ) {
59 $max_upload_size = 0;
60 }
61
62 /** This filter is documented in wp-admin/includes/media.php */
63 $image_size_names = apply_filters(
64 'image_size_names_choose',
65 array(
66 'thumbnail' => __( 'Thumbnail', 'gutenberg' ),
67 'medium' => __( 'Medium', 'gutenberg' ),
68 'large' => __( 'Large', 'gutenberg' ),
69 'full' => __( 'Full Size', 'gutenberg' ),
70 )
71 );
72
73 $available_image_sizes = array();
74 foreach ( $image_size_names as $image_size_slug => $image_size_name ) {
75 $available_image_sizes[] = array(
76 'slug' => $image_size_slug,
77 'name' => $image_size_name,
78 );
79 }
80
81 $settings = array_merge(
82 array(
83 'imageSizes' => $available_image_sizes,
84 'isRTL' => is_rtl(),
85 'maxUploadFileSize' => $max_upload_size,
86 ),
87 gutenberg_get_legacy_widget_settings()
88 );
89
90 list( $color_palette, ) = (array) get_theme_support( 'editor-color-palette' );
91 list( $font_sizes, ) = (array) get_theme_support( 'editor-font-sizes' );
92
93 if ( false !== $color_palette ) {
94 $settings['colors'] = $color_palette;
95 }
96
97 if ( false !== $font_sizes ) {
98 $settings['fontSizes'] = $font_sizes;
99 }
100 $settings = gutenberg_experimental_global_styles_settings( $settings );
101
102 wp_add_inline_script(
103 'wp-edit-widgets',
104 sprintf(
105 'wp.domReady( function() {
106 wp.editWidgets.%s( "widgets-editor", %s );
107 } );',
108 $initializer_name,
109 wp_json_encode( gutenberg_experiments_editor_settings( $settings ) )
110 )
111 );
112
113 // Preload server-registered block schemas.
114 wp_add_inline_script(
115 'wp-blocks',
116 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');'
117 );
118
119 wp_enqueue_script( 'wp-edit-widgets' );
120 wp_enqueue_script( 'admin-widgets' );
121 wp_enqueue_script( 'wp-format-library' );
122 wp_enqueue_style( 'wp-edit-widgets' );
123 wp_enqueue_style( 'wp-format-library' );
124 }
125 add_action( 'admin_enqueue_scripts', 'gutenberg_widgets_init' );
126