WordPress 更新后插件错误

3
我的托管提供商自动更新到了4.5版本,这导致Visual Composer插件出现错误。
我已经阅读了以下帖子:Plugin throwing TypeError after Wordpress 4.5 updateVisual composer doesn't load and gives TypeError: _.template(...).trim is not a functionUncaught TypeError: $template.get is not a function,并用提供的函数替换了html2element函数。然而,正如许多人在这些帖子中评论的那样,我得到了一个新的错误。
composer-view.js?ver=4.6.1:139 Uncaught TypeError: Cannot read property 'attributes' of undefined

这是我的函数:

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

有人想出了如何修复它的方法吗?

感谢您的帮助。

2个回答

17

我在更新4.5版本时也遇到了同样的问题,尝试了所有我找到的方法,但仍然无法解决。

最终,我将主题视觉编辑器插件(v4.7)替换为较新的版本(4.11.2,google js_composer.zip)。

我只是替换了整个目录内容,现在它可以正常工作了。


你真是个救命恩人! - Amir Khademi
这个有效,但基本上它是一个独立的可视化编辑器插件的版本,应该在网站上付费购买而不是从其他网站复制。我下载了你回答中的zip文件进行测试,它有效。然后我购买了插件(大约30美元)(https://vc.wpbakery.com/visual-composer-license/),这样我也可以安心入睡 :-) 怎样处理由人决定,但我认为这很重要。 - bestprogrammerintheworld
1
@bestprogrammerintheworld 你确定你没有支付两次吗?这是有原因的,主题和插件制造商之间经常有协议。但你是对的,这是一个紧急补丁。我让许可问题交给大家 :) - FLX
@FLX - 我实际上支付了比我需要的更多,但我不在乎。与主题制作者合作解决这个问题会花费我更多的时间。目前,Bridge主题的最新版本并没有包含正确的Visual Composer版本。 - bestprogrammerintheworld
适用于我。找到新版本VC很难。截至今天的可用链接是http://www.solidfiles.com/v/43XgaXWwYV6AZ/dl。您将需要VPN才能访问此页面。在一些国家受限制。您还需要一个rar实用程序来提取其内容。然后使用js_composer.zip文件,您就完成了。谢谢。 - Alvin Chettiar

4

Graham,你好

我认为问题不在jQuery中,而是在js_composer中使用的underscore上。

在渲染方法中,将错误的HTML对象传递给html2element方法,就像这样:

 this.html2element(_.template($shortcode_template_el.html(),
            this.model.toJSON(),
             vc.templateOptions.default));

但是这段代码将一个没有任何属性或其他内容的函数作为html2element方法的html对象发送。这是因为underscore库中的_.template函数在第二个参数没有有效的变量之前不会呈现第一个参数(HTML模板)。

我认为要解决这个问题需要做以下几点:

this.html2element(_.template($shortcode_template_el.html()));

这两种方法是render和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;
        }

to:

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

2
这只能“有点儿”起作用。你可以编辑元素,但不能添加任何元素。 - bestprogrammerintheworld

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接