javascript – WordPress 4.5更新后插件抛出TypeError

我正在调试一个视觉作曲家插件,在我将WordPress更新为4.5之后就破坏了,我无法弄清楚它为什么会抛出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的唯一出现位于下面的代码中.我明白这不是很多背景,但是,我该如何解决这个错误呢?

/**
 * 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,修复了一个错误,允许某些代码以不正确的语法运行.我假设插件代码必须具有不正确的语法,但直到现在仍然运行.

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

解决方法:

我能够解决这个问题.事实证明我使用的是旧版本的JS作曲家.更新到最新版本会破坏我的网站,因此我追踪错误并将html2element函数更新为

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()
        },

一切都很适合我!希望这有助于其他人.

相关文章

我们有时候在定制WORDPRESS主题的时候,由于菜单样式的要求我...
很多朋友在做wordpree主题制作的时候会经常遇到一个问题,那...
wordpress后台的模块很多,但并不是每个都经常用到。介绍几段...
从WordPress4.2版本开始,如果我们在MYSQL5.1版本数据中导出...
很多网友会遇到这样一个问题,就是WordPress网站上传图片、附...
对于经常要在文章中出现代码的IT相关博客,安装一个代码高亮...