将脚本排队以在 Wordpress 的tinyMCE 插件中使用

发布于 2025-01-05 02:37:41 字数 210 浏览 1 评论 0原文

我有一个tinyMCE插件(用于帖子/页面编辑器),我从我的Wordpress插件加载它,需要加载几个外部javascript文件才能让我的tinyMCE插件工作。

在 Wordpress 3.3.1 中,我只需注册 mce_external_plugins 过滤器中的脚本并将其排入队列,但任何低于该版本的 WordPress 版本都不会加载脚本。

有人有这方面的经验吗?

I have a tinyMCE plugin (for the post/page editor) that I am loading from my Wordpress plugin that needs to have several external javascript files loaded in order for my tinyMCE plugin to work.

In Wordpress 3.3.1 I can just register and enqueue the scripts from the mce_external_plugins filter but any Wordpress version below that doesn't load the scripts.

Anybody have experience in this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

︶ ̄淡然 2025-01-12 02:37:41

我发现解决我的问题的方法是挂钩 after_wp_tiny_mce ,然后在回调中直接调用 wp_print_scripts 。它仍然处理脚本的所有依赖项。

另外,由于脚本未排队,wp_localize_script 无法使用此方法,因此我在对 wp_print_scripts 的调用正上方回显我的对象,如下所示:

<script type="text/javascript">
/* <![CDATA[ */
var MyLocalizedData = {"foo": "barito"};
/* ]]> */
</script>

编辑:
此修复仅适用于 Wordpress >= 3.2

The method that I found to work with my problem is by hooking to after_wp_tiny_mce and then in the callback, calling wp_print_scripts directly. It still handles all the dependencies of the scripts.

Also, because wp_localize_script won't work with this method due to the scripts not being enqueued, I am echoing my objects directly above my calls to wp_print_scripts like this:

<script type="text/javascript">
/* <![CDATA[ */
var MyLocalizedData = {"foo": "barito"};
/* ]]> */
</script>

EDIT :
This fix will only work in Wordpress >= 3.2

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文