wordpress TinyMce扩展(如codesmaple)无法初始化,r不是构造函数

hts6caw3  于 2023-02-03  发布在  WordPress
关注(0)|答案(1)|浏览(159)
    • bounty将在6天后过期**。回答此问题可获得+100声望奖励。NodeX4希望引起更多人关注此问题。

我有一个wordpress网站,我有一个页面,允许用户创建帖子。我已经配置tinymce来寻找表单上的这个特定字段,并将其转换为一个tinymce字段。这工作正常,但一些(大多数)的插件与tinymce不工作。我反复得到这个错误:Failed to initialize plugin: wordcount TypeError: r is not a constructor为每一个插件我已经添加.我尝试了一个空白的wp安装,但错误仍然存在
如果您想亲自查看问题,请访问以下网站:https://tropical.team/articles/create
下面是其中一个插件的错误,该插件不工作;代码示例:

at Ew (wp-tinymce.php?ver=2.0.0-dev1:2:330473)
    at Array.<anonymous> (wp-tinymce.php?ver=2.0.0-dev1:2:332223)
    at Object.jt [as each] (wp-tinymce.php?ver=2.0.0-dev1:2:29356)
    at Aw (wp-tinymce.php?ver=2.0.0-dev1:2:332173)
    at tN.<anonymous> (wp-tinymce.php?ver=2.0.0-dev1:2:333551)
    at Array.<anonymous> (wp-tinymce.php?ver=2.0.0-dev1:2:96969)
    at jt (wp-tinymce.php?ver=2.0.0-dev1:2:29356)
    at u (wp-tinymce.php?ver=2.0.0-dev1:2:96914)
    at n (wp-tinymce.php?ver=2.0.0-dev1:2:96402)
    at l.<computed>.l.<computed>.l.<computed>.o.onload (wp-tinymce.php?ver=2.0.0-dev1:2:96652)

我不确定是什么原因造成的,因为我已经正确地设置了我的init函数afaik:

jQuery(document).ready(function($){
    
    $(window).load(function () {
        tinymce.suffix = '.min';
        tinymce.init({
          selector: '.tinymce>div>div>textarea',
          height: 200,
          plugins: ["codesample", "autosave", "code", "image", "link", "lists", "media", "preview", "searchreplace", "textcolor", "wordcount", "hr", "lists"],
          autosave_restore_when_empty: true,
          autosave_retention: '60m',
          codesample_languages: [
            {text: 'HTML/XML', value: 'markup'},
            {text: 'JavaScript', value: 'javascript'},
            {text: 'CSS', value: 'css'},
            {text: 'PHP', value: 'php'},
            {text: 'Ruby', value: 'ruby'},
            {text: 'Python', value: 'python'},
            {text: 'Java', value: 'java'},
            {text: 'C', value: 'c'},
            {text: 'C#', value: 'csharp'},
            {text: 'C++', value: 'cpp'},
            {text: 'Markup', value: 'markup'},
            {text: 'Arduino', value: 'arduino'},
            {text: 'ARM Assembly', value: 'armasm'},
            {text: 'Batch', value: 'batch'},
            {text: 'Bash', value: 'bash'},
            {text: 'ASP.NET (C#)', value: 'aspnet'},
            {text: 'Brainfuck', value: 'brainfuck'},
            {text: 'JSON', value: 'json'},
            {text: 'Markdown', value: 'markdown'},
            {text: 'PHP', value: 'php'},
            {text: 'TypeScript', value: 'typescript'},
            {text: 'ASP.NET (C#)', value: 'aspnet'},
            {text: 'Rust', value: 'rust'}
          ],
          toolbar: 'preview searchreplace | codesample image link | lists hr | bold italic textcolor | h1 h2 h3 h4 | alignleft aligncenter alignright | bullist numlist outdent indent | undo red | wordcount-',
          // content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:14px }'
        });

    });
});
unguejic

unguejic1#

您可以使用数组指定插件...

tinymce.init({
  // ...
  plugins: ["codesample", "autosave", "code", "image", "link", "lists", "media", "preview", "searchreplace", "textcolor", "wordcount", "hr", "lists"],
  // ...
});

...而TinyMCE需要带有空格的字符串

tinymce.init({
  // ...
  plugins: "codesample autosave code image link lists media preview searchreplace textcolor wordcount hr lists",
  // ...
});
    • 编辑**

另外,要小心。在上面的代码中,lists插件被声明了两次...

相关问题