fix(submit): render the configured body placeholder in TinyMCE

WordPress 打包的 TinyMCE 4.9 不含官方 placeholder 插件,tinymce.init 里的
placeholder 配置被静默忽略,投稿页「投稿内容占位符」从未显示过。

新增主题插件 assets/js/front-submit-placeholder.js:正文为空时插入一个
data-mce-bogus 的占位段落,有内容即移除;序列化 / 解析都剔除该段落,
字数统计也跳过它,提示文字不会写进文章。

- 经典投稿表单与创作者工作台都通过 external_plugins 加载
  (WordPress 会丢弃名字已在 plugins 列表里的外部插件)
- 占位样式写进 iframe 的 content CSS:submit-editor.css 与
  editor-content-style.ts

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
kate522andClaude Opus 5 committed 2026-11-09 19:01:28 +08:00
1 parent beb898b1ab
commit 44a03fd5f4
8 files changed
+228 -3

No files matched your search

+9 -1
View File
@@ -55,20 +55,28 @@ $is_can_new = !empty($ctx['is_can_new']);
$toolbar1[] = 'jio_hide';
}
$toolbar1 = implode(',', array_merge($toolbar1, ['jio_quote', 'jio_precode', 'fullscreen', 'wp_adv']));
// jio_placeholder 通过 external_plugins 注册:WordPress 会丢弃
// 名字已出现在 plugins 列表里的外部插件,写在这里反而加载不到。
$plugins = 'paste,link,lists,fullscreen,wordpress,wplink,charmap,colorpicker,textcolor';
$editor_plugin_path = get_template_directory() . '/assets/js/front-submit-editor.js';
$editor_plugin_url = get_template_directory_uri() . '/assets/js/front-submit-editor.js';
if (file_exists($editor_plugin_path)) {
$editor_plugin_url = add_query_arg('ver', (string) filemtime($editor_plugin_path), $editor_plugin_url);
}
$placeholder_plugin_path = get_template_directory() . '/assets/js/front-submit-placeholder.js';
$placeholder_plugin_url = get_template_directory_uri() . '/assets/js/front-submit-placeholder.js';
if (file_exists($placeholder_plugin_path)) {
$placeholder_plugin_url = add_query_arg('ver', (string) filemtime($placeholder_plugin_path), $placeholder_plugin_url);
}
$editor_css_path = get_template_directory() . '/assets/css/frontend/pages/submit-editor.css';
$editor_css_url = get_template_directory_uri() . '/assets/css/frontend/pages/submit-editor.css';
if (file_exists($editor_css_path)) {
$editor_css_url = add_query_arg('ver', (string) filemtime($editor_css_path), $editor_css_url);
}
$external_plugins = static function (array $external, string $editor_id) use ($editor_plugin_url): array {
$external_plugins = static function (array $external, string $editor_id) use ($editor_plugin_url, $placeholder_plugin_url): array {
if ($editor_id === 'post_content') {
$external['jio_editor_tools'] = $editor_plugin_url;
$external['jio_placeholder'] = $placeholder_plugin_url;
}
return $external;
};