Skip to content

Commit

Permalink
Ensure that id_base is defined on widget form prototypes
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Feb 14, 2017
1 parent 067c045 commit 5d7ccb0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions js/widget-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ wp.widgets.Form = (function( api, $, _ ) {
initialize: function initialize( properties ) {
var form = this;

if ( ! form.id_base ) {
throw new Error( 'Missing id_base' );
}

_.extend( form, getValidatedFormProperties( form.config, properties ) );

form.setting = form.model; // @todo Deprecate 'setting' name in favor of 'model'?
Expand Down
5 changes: 5 additions & 0 deletions php/class-wp-adapter-js-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public function enqueue_control_scripts() {
wp_json_encode( $this->id_base ),
wp_json_encode( $this->get_form_config() )
) );
wp_add_inline_script( $handle, sprintf(
'wp.widgets.formConstructor[ %s ].prototype.id_base = %s;',
wp_json_encode( $this->id_base ),
wp_json_encode( $this->id_base )
) );
}

/**
Expand Down

0 comments on commit 5d7ccb0

Please sign in to comment.