Plugin throwing TypeError after WordPress 4.5 update

后端 未结 10 1430
甜味超标
甜味超标 2020-12-07 19:06

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.

The error message in the

10条回答
  •  没有蜡笔的小新
    2020-12-07 19:13

    Well, i found the solution in this site: https://wordpress.org/support/topic/visual-composer-is-not-working

    first: edit html2element:.... in in /wp-content/plugins/js_composer/assets/js/backend/composer-view.js

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

    second: However if you open up the frontend editor you'll have this "trim" issue on custom_views.js:101 , and line 467 of another file. I forgot the name, but I think it may be frontend_editor.js.

    edit in: \wp-content\plugins\js_composer\assets\js\frontend_editor\

    • frontend_editor.js
    • custom_views.js

    Bad code:

    this.$controls = $( _.template( template, data, _.extend( {},
                vc.template_options,
                { evaluate: /\{#([\s\S]+?)#}/g } ) ).trim() ).addClass( 'vc_controls' );
    

    Fixed code:

    this.$controls = $( _.template( template, data, _.extend( {},
                vc.template_options,
                { evaluate: /\{#([\s\S]+?)#}/g } ) )().trim() ).addClass( 'vc_controls' );
    

    third: See the black magic.

    Cheers.

提交回复
热议问题