PluginProbe
Gutenberg / 8.9.0
Gutenberg v8.9.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 8.9.0, at lib/widgets-page.php

127 lines 3.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 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 'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
84 'imageSizes' => $available_image_sizes,
85 'isRTL' => is_rtl(),
86 'maxUploadFileSize' => $max_upload_size,
87 ),
88 gutenberg_get_legacy_widget_settings()
89 );
90
91 list( $color_palette, ) = (array) get_theme_support( 'editor-color-palette' );
92 list( $font_sizes, ) = (array) get_theme_support( 'editor-font-sizes' );
93
94 if ( false !== $color_palette ) {
95 $settings['colors'] = $color_palette;
96 }
97
98 if ( false !== $font_sizes ) {
99 $settings['fontSizes'] = $font_sizes;
100 }
101 $settings = gutenberg_experimental_global_styles_settings( $settings );
102
103 wp_add_inline_script(
104 'wp-edit-widgets',
105 sprintf(
106 'wp.domReady( function() {
107 wp.editWidgets.%s( "widgets-editor", %s );
108 } );',
109 $initializer_name,
110 wp_json_encode( gutenberg_experiments_editor_settings( $settings ) )
111 )
112 );
113
114 // Preload server-registered block schemas.
115 wp_add_inline_script(
116 'wp-blocks',
117 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');'
118 );
119
120 wp_enqueue_script( 'wp-edit-widgets' );
121 wp_enqueue_script( 'admin-widgets' );
122 wp_enqueue_script( 'wp-format-library' );
123 wp_enqueue_style( 'wp-edit-widgets' );
124 wp_enqueue_style( 'wp-format-library' );
125 }
126 add_action( 'admin_enqueue_scripts', 'gutenberg_widgets_init' );
127