fix(gutenberg): 修复 MediaUpload 未定义与无效块分类
声明 MediaUpload、服务端注册 aksrt-blocks 分类、默认 apiVersion 3,避免编辑器脚本中断与 WP 6.9 弃用警告。
This commit is contained in:
1 parent
b7dc3d170d
commit
a4cd5276e2
2 files changed
+66
-21
No files matched your search
@@ -104,6 +104,34 @@ add_action('pre_get_posts', function ($query) {
|
||||
// Gutenberg 自定义块注册
|
||||
// ============================================================
|
||||
|
||||
// Register category server-side so it exists before JS registerBlockType runs.
|
||||
// Keep untyped + defensive: some plugins pass unexpected shapes; typed params can 500 the editor.
|
||||
add_filter('block_categories_all', static function ($categories, $context = null) {
|
||||
if (!is_array($categories)) {
|
||||
return $categories;
|
||||
}
|
||||
|
||||
foreach ($categories as $category) {
|
||||
$slug = '';
|
||||
if (is_array($category)) {
|
||||
$slug = (string) ($category['slug'] ?? '');
|
||||
} elseif (is_object($category) && isset($category->slug)) {
|
||||
$slug = (string) $category->slug;
|
||||
}
|
||||
if ($slug === 'aksrt-blocks') {
|
||||
return $categories;
|
||||
}
|
||||
}
|
||||
|
||||
$categories[] = [
|
||||
'slug' => 'aksrt-blocks',
|
||||
'title' => 'AKSRT',
|
||||
'icon' => null,
|
||||
];
|
||||
|
||||
return $categories;
|
||||
}, 10, 2);
|
||||
|
||||
add_action('enqueue_block_editor_assets', function () {
|
||||
$base_uri = get_template_directory_uri();
|
||||
$version = wp_get_theme()->get('Version');
|
||||
@@ -113,7 +141,8 @@ add_action('enqueue_block_editor_assets', function () {
|
||||
wp_enqueue_script(
|
||||
'aksrt-gutenberg-blocks',
|
||||
$base_uri . '/assets/js/gutenberg-blocks.js',
|
||||
['wp-blocks', 'wp-element', 'wp-components', 'wp-block-editor', 'wp-hooks'],
|
||||
// wp-media-utils: MediaUpload for carousel block
|
||||
['wp-blocks', 'wp-element', 'wp-components', 'wp-block-editor', 'wp-hooks', 'wp-media-utils'],
|
||||
(string) filemtime($blocks_js),
|
||||
true
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user