WordPress 4.5 更新后插件抛出 TypeError [英] Plugin throwing TypeError after WordPress 4.5 update

查看:20
本文介绍了WordPress 4.5 更新后插件抛出 TypeError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调试一个可视化作曲家插件,该插件在我将 WordPress 更新到 4.5 后就坏了,我不明白为什么它会抛出 TypeError.

I'm debugging a visual composer plugin that broke after I updated WordPress to 4.5 and I can't figure out why it is throwing a TypeError.

控制台中的错误信息:

JQMIGRATE: Migrate is installed, version 1.4.0              load-scripts.php?....
Uncaught TypeError:     $template.get is not a function     composer-view.js?ver=4.1.1.1:73

$template 仅出现在下面的代码中.我知道这不是很多上下文,但是,我该如何解决此错误?

The only occurrences of $template are found in the code below. I understand that this isn't very much context to go off of but, how can I resolve this error?

/**
 * Convert html into correct element
 * @param html
 */
html2element: function(html) {
  var attributes = {},
    $template;
  if (_.isString(html)) {
    this.template = _.template(html);
    $template = $(this.template(this.model.toJSON()).trim());
  } else {
    this.template = html;
    $template = html;
  }
  _.each($template.get(0).attributes, function(attr) { // **errors on this line**
    attributes[attr.name] = attr.value;
  });
  this.$el.attr(attributes).html($template.html());
  this.setContent();
  this.renderContent();
},


更新:

看起来这可能是 jQuery 的问题.WordPress 4.5 包含 jQuery 1.12,它修复了一个错误,该错误允许某些代码以错误的语法运行.我认为插件代码一定有错误的语法,但仍然运行到现在.

It looks like this might be a problem with jQuery. WordPress 4.5 includes jQuery 1.12 which fixed a bug that allowed certain code to be run with incorrect syntax. I assume that the plugin code must have had incorrect syntax but ran nonetheless until now.

https://wordpress.org/support/topic/read-this-first-wordpress-45-master-list#post-8271654

推荐答案

我解决了这个问题.原来我使用的是旧版本的 JS 作曲家.更新到最新版本破坏了我的网站,所以我追踪了错误并将 html2element 函数更新为

I was able to resolve the issue. Turns out I was using an older version of JS composer. Updating to the newest version broke my site so I tracked down the error and updated the html2element function to

html2element: function(html) {
            var $template, attributes = {},
                template = html;
            $template = $(template(this.model.toJSON()).trim()), _.each($template.get(0).attributes, function(attr) {
                attributes[attr.name] = attr.value
            }), this.$el.attr(attributes).html($template.html()), this.setContent(), this.renderContent()
        },

一切对我来说都很好!希望这对其他人有帮助.

All is working well for me again! Hope this helps others.

这篇关于WordPress 4.5 更新后插件抛出 TypeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆