【问题标题】:Plugin Error after Wordpress updateWordpress 更新后插件错误
【发布时间】:2016-09-02 14:27:22
【问题描述】:

我的托管服务提供商自动更新到 4.5,导致 Visual Composer 插件出错。

我确实阅读了这些帖子: Plugin throwing TypeError after Wordpress 4.5 update

Visual composer doesn't load and gives TypeError: _.template(...).trim is not a function

Uncaught 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

有人知道怎么解决吗?

感谢您的帮助

【问题讨论】:

    标签: javascript jquery wordpress


    【解决方案1】:

    在 4.5 更新时遇到了同样的问题,并尝试了我找到的所有方法,但仍然无法正常工作。

    最后,我用最近的一个(4.11.2,google js_composer.zip)替换了我的主题视觉作曲家插件(v4.7 的东西)。

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

    【讨论】:

    • 你是救生员!
    • 这个有效,但它基本上是安装在一个站点上的独立可视化作曲家插件的一个版本,您应该付费而不是从另一个站点复制。我在您的答案中下载了 zip 文件进行测试,它有效。然后我购买了插件(大约 30 美元)(vc.wpbakery.com/visual-composer-license),这样我也可以在晚上睡觉 :-) 这取决于人们如何做到这一点,但我认为这很高兴。
    • @bestprogrammerintheworld 你确定你没有付过两次钱吗?它出现在您的主题中是有原因的,主题和插件制造商之间经常有协议。但你是对的,这是一个紧急补丁。我让每个人都解决许可证问题:)
    • @FLX - 实际上,我确实支付了比我需要的更多的钱,但我不在乎。与主题制作者一起让他们解决问题会花费我更多的时间。最新版本的 Bridge 主题不包含正确版本的 Visual Composer,反正现在也不包含。
    • 为我工作。很难找到新版本的 VC。截至今天的工作链接是solidfiles.com/v/43XgaXWwYV6AZ/dl。您将需要一个 VPN 才能访问此页面。在少数国家,它受到限制。您还需要一个 rar 实用程序来提取其内容。然后使用 js_composer.zip 文件就完成了。谢谢。
    【解决方案2】:

    格雷厄姆,嗨

    我认为问题不在 jquery 中,而是在下划线中使用 js_composer。

    在渲染方法中,将错误的 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()));
    

    这2个方法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;
            }
    

    到:

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

    【讨论】:

    • 这只是“有点”。您可以编辑元素,但不能添加任何元素。
    猜你喜欢
    • 1970-01-01
    • 2017-03-17
    • 2013-06-19
    • 2015-11-14
    • 1970-01-01
    • 2012-02-28
    • 2016-08-04
    • 1970-01-01
    相关资源
    最近更新 更多