WordPress更新后的插件错误
我的托管服务提供商自动更新到4.5,导致Visual Composer插件出错。
我阅读了这些post: WordPress 4.5更新后插件抛出TypeError
Visual composer不加载并给出TypeError:_. trylate(…)。trim不是函数
未捕获的TypeError:$ template.get不是函数
并将html2element函数替换为提供的函数。 但是,由于很多人对这些post发表了评论,我收到了一个新错误:
composer-view.js?ver=4.6.1:139 Uncaught TypeError: Cannot read property 'attributes' of undefined
这是我的function:
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() },
错误似乎来自这一行:
$template.get(0).attributes
有没有人想出如何解决它?
谢谢你的帮助
有4.5更新同样的问题,并尝试了我发现的一切,但它仍然无法正常工作。
最后,我用最近的一个(4.11.2,google js_composer.zip)替换了我的主题视觉composer php插件(v4.7的东西)。
我只是替换了整个目录内容,它运行正常。
格雷厄姆,嗨
我认为问题不在于jquery,而是强调在js_composer中使用。
在render方法中将错误的html对象传递给html2element方法,如下所示:
this.html2element(_.template($shortcode_template_el.html(), this.model.toJSON(), vc.templateOptions.default));
但是这段代码发送到html2element方法的html对象作为没有任何属性或其他东西的函数。 这是因为下划线库中的_.template函数在第二个arg没有第一个arg的有效变量之前不会呈现第一个arg(html模板)。
在我看来解决这个问题需要这样做:
this.html2element(_.template($shortcode_template_el.html()));
这两个方法渲染和html2element https://gist.github.com/maximspokoiny/34ad60ad90944f8a80c6fc093873a807/9fb041d2b12249fe4391f986f4e7e6a08f57c6b3#file-gistfile1-txt
我使用js_composer 4.7.4和wordpress 4.5.2来解决这个问题。
谢谢!
更新:抱歉,在html2element中需要进行一次更改,来自:
if ( _.isString( html ) ) { this.template = _.template( html ); $template = $( this.template( this.model.toJSON(), vc.templateOptions.default ).trim() ); } else { this.template = html; $template = html; }
至:
if ( _.isString( html ) ) { this.template = _.template( html ); $template = $( this.template( this.model.toJSON(), vc.templateOptions.default ).trim() ); } else { this.template = html; $template = $( this.template( this.model.toJSON(), vc.templateOptions.default ).trim() ); }