| author | ymh <ymh.work@gmail.com> |
| Fri, 05 Sep 2025 18:40:08 +0200 | |
| changeset 21 | 48c4eec2b7e6 |
| parent 19 | 3d72ae0968f4 |
| child 22 | 8c2e4d02f4ef |
| permissions | -rw-r--r-- |
| 18 | 1 |
<?php |
2 |
/** |
|
3 |
* The block-based widgets editor, for use in widgets.php. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
9 |
// Don't load directly. |
|
10 |
if ( ! defined( 'ABSPATH' ) ) { |
|
11 |
die( '-1' ); |
|
12 |
} |
|
13 |
||
14 |
// Flag that we're loading the block editor. |
|
15 |
$current_screen = get_current_screen(); |
|
16 |
$current_screen->is_block_editor( true ); |
|
17 |
||
| 19 | 18 |
$block_editor_context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-widgets' ) ); |
| 18 | 19 |
|
20 |
$preload_paths = array( |
|
| 19 | 21 |
array( rest_get_route_for_post_type_items( 'attachment' ), 'OPTIONS' ), |
22 |
'/wp/v2/widget-types?context=edit&per_page=-1', |
|
| 18 | 23 |
'/wp/v2/sidebars?context=edit&per_page=-1', |
24 |
'/wp/v2/widgets?context=edit&per_page=-1&_embed=about', |
|
25 |
); |
|
26 |
block_editor_rest_api_preload( $preload_paths, $block_editor_context ); |
|
27 |
||
28 |
$editor_settings = get_block_editor_settings( |
|
29 |
array_merge( get_legacy_widget_block_editor_settings(), array( 'styles' => get_block_editor_theme_styles() ) ), |
|
30 |
$block_editor_context |
|
31 |
); |
|
32 |
||
33 |
// The widgets editor does not support the Block Directory, so don't load any of |
|
34 |
// its assets. This also prevents 'wp-editor' from being enqueued which we |
|
35 |
// cannot load in the widgets screen because many widget scripts rely on `wp.editor`. |
|
36 |
remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' ); |
|
37 |
||
38 |
wp_add_inline_script( |
|
39 |
'wp-edit-widgets', |
|
40 |
sprintf( |
|
41 |
'wp.domReady( function() { |
|
42 |
wp.editWidgets.initialize( "widgets-editor", %s ); |
|
43 |
} );', |
|
44 |
wp_json_encode( $editor_settings ) |
|
45 |
) |
|
46 |
); |
|
47 |
||
48 |
// Preload server-registered block schemas. |
|
49 |
wp_add_inline_script( |
|
50 |
'wp-blocks', |
|
51 |
'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');' |
|
52 |
); |
|
53 |
||
54 |
wp_add_inline_script( |
|
55 |
'wp-blocks', |
|
56 |
sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( $block_editor_context ) ) ), |
|
57 |
'after' |
|
58 |
); |
|
59 |
||
60 |
wp_enqueue_script( 'wp-edit-widgets' ); |
|
61 |
wp_enqueue_script( 'admin-widgets' ); |
|
62 |
wp_enqueue_style( 'wp-edit-widgets' ); |
|
63 |
||
64 |
/** This action is documented in wp-admin/edit-form-blocks.php */ |
|
65 |
do_action( 'enqueue_block_editor_assets' ); |
|
66 |
||
67 |
/** This action is documented in wp-admin/widgets-form.php */ |
|
68 |
do_action( 'sidebar_admin_setup' ); |
|
69 |
||
70 |
require_once ABSPATH . 'wp-admin/admin-header.php'; |
|
71 |
||
72 |
/** This action is documented in wp-admin/widgets-form.php */ |
|
73 |
do_action( 'widgets_admin_page' ); |
|
74 |
?> |
|
75 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
76 |
<div id="widgets-editor" class="blocks-widgets-container"> |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
77 |
<?php // JavaScript is disabled. ?> |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
78 |
<div class="wrap hide-if-js widgets-editor-no-js"> |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
79 |
<h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1> |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
80 |
<?php |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
81 |
if ( file_exists( WP_PLUGIN_DIR . '/classic-widgets/classic-widgets.php' ) ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
82 |
// If Classic Widgets is already installed, provide a link to activate the plugin. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
83 |
$installed = true; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
84 |
$plugin_activate_url = wp_nonce_url( 'plugins.php?action=activate&plugin=classic-widgets/classic-widgets.php', 'activate-plugin_classic-widgets/classic-widgets.php' ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
85 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
86 |
/* translators: %s: Link to activate the Classic Widgets plugin. */ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
87 |
__( 'The block widgets require JavaScript. Please enable JavaScript in your browser settings, or activate the <a href="%s">Classic Widgets plugin</a>.' ), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
88 |
esc_url( $plugin_activate_url ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
89 |
); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
90 |
} else { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
91 |
// If Classic Widgets is not installed, provide a link to install it. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
92 |
$installed = false; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
93 |
$plugin_install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=classic-widgets' ), 'install-plugin_classic-widgets' ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
94 |
$message = sprintf( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
95 |
/* translators: %s: A link to install the Classic Widgets plugin. */ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
96 |
__( 'The block widgets require JavaScript. Please enable JavaScript in your browser settings, or install the <a href="%s">Classic Widgets plugin</a>.' ), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
97 |
esc_url( $plugin_install_url ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
98 |
); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
99 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
100 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
101 |
* Filters the message displayed in the block widget interface when JavaScript is |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
102 |
* not enabled in the browser. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
103 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
104 |
* @since 6.4.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
105 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
106 |
* @param string $message The message being displayed. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
107 |
* @param bool $installed Whether the Classic Widget plugin is installed. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
108 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
109 |
$message = apply_filters( 'block_widgets_no_javascript_message', $message, $installed ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
110 |
wp_admin_notice( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
111 |
$message, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
112 |
array( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
113 |
'type' => 'error', |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
114 |
'additional_classes' => array( 'hide-if-js' ), |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
115 |
) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
116 |
); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
117 |
?> |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
118 |
</div> |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
119 |
</div> |
| 18 | 120 |
|
121 |
<?php |
|
122 |
/** This action is documented in wp-admin/widgets-form.php */ |
|
123 |
do_action( 'sidebar_admin_page' ); |
|
124 |
||
125 |
require_once ABSPATH . 'wp-admin/admin-footer.php'; |