Skip to content

Instantly share code, notes, and snippets.

@levantoan
Last active November 29, 2020 12:11
Show Gist options
  • Save levantoan/519bb0d42c9f7bd6c4d78ef1686bb848 to your computer and use it in GitHub Desktop.
Save levantoan/519bb0d42c9f7bd6c4d78ef1686bb848 to your computer and use it in GitHub Desktop.
Fix $template.get is not a function in VC when updated WordPress to 4.5
<?php
/*
Find html2element in
Version < 4.8: /wp-content/plugins/js_composer/assets/js/backend/composer-view.js
Version > 4.9: wp-content/plugins/js_composer/assets/js/dist/backend-actions.min.js
*/
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();
},
/*
Then replace to 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()
},
/*by http://levantoan.com/cach-sua-loi-uncaught-typeerror-template-get-not-function-cua-plugin-visual-composer-khi-update-wordpress-len-4-5/*/
@segebee
Copy link

segebee commented Nov 29, 2020

This was really helpful...replacing htmlelement worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment