<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[27652] trunk/src: Widget Customizer: Improve error handling.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/27652">27652</a></dd>
<dt>Author</dt> <dd>ocean90</dd>
<dt>Date</dt> <dd>2014-03-22 20:54:17 +0000 (Sat, 22 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Widget Customizer: Improve error handling. First pass.

* Replace Widget_Customizer_Exception with WP_Error
* Call Previewer.cheatin() to show the cheating message if a user can't change widgets
* Call Previewer.login() to show the login form if a user is logged out
* Show a generic error message on failures

see <a href="http://core.trac.wordpress.org/ticket/27419">#27419</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminjscustomizewidgetsjs">trunk/src/wp-admin/js/customize-widgets.js</a></li>
<li><a href="#trunksrcwpincludesclasswpcustomizewidgetsphp">trunk/src/wp-includes/class-wp-customize-widgets.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminjscustomizewidgetsjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/js/customize-widgets.js (27651 => 27652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/js/customize-widgets.js       2014-03-22 10:53:10 UTC (rev 27651)
+++ trunk/src/wp-admin/js/customize-widgets.js  2014-03-22 20:54:17 UTC (rev 27652)
</span><span class="lines">@@ -16,7 +16,8 @@
</span><span class="cx">                  save_btn_label: '',
</span><span class="cx">                  save_btn_tooltip: '',
</span><span class="cx">                  remove_btn_label: '',
</span><del>-                       remove_btn_tooltip: ''
</del><ins>+                        remove_btn_tooltip: '',
+                       error: '',
</ins><span class="cx">           },
</span><span class="cx">          available_widgets: [], // available widgets for instantiating
</span><span class="cx">          registered_widgets: [], // all widgets registered
</span><span class="lines">@@ -1172,6 +1173,9 @@
</span><span class="cx"> 
</span><span class="cx">                  widget_content = control.container.find( '.widget-content' );
</span><span class="cx"> 
</span><ins>+                       // Remove a previous error message
+                       widget_content.find( '.widget-error' ).remove();
+
</ins><span class="cx">                   // @todo Support more selectors than IDs?
</span><span class="cx">                  if ( $.contains( control.container[0], document.activeElement ) && $( document.activeElement ).is( '[id]' ) ) {
</span><span class="cx">                          element_id_to_refocus = $( document.activeElement ).prop( 'id' );
</span><span class="lines">@@ -1219,6 +1223,22 @@
</span><span class="cx">                                  has_same_inputs_in_response,
</span><span class="cx">                                  is_instance_identical;
</span><span class="cx"> 
</span><ins>+                               // Check if the user is logged out.
+                               if ( '0' === r ) {
+                                       self.previewer.preview.iframe.hide();
+                                       self.previewer.login().done( function() {
+                                               control.updateWidget( args );
+                                               self.previewer.preview.iframe.show();
+                                       } );
+                                       return;
+                               }
+
+                               // Check for cheaters.
+                               if ( '-1' === r ) {
+                                       self.previewer.cheatin();
+                                       return;
+                               }
+
</ins><span class="cx">                           if ( r.success ) {
</span><span class="cx">                                  sanitized_form = $( '<div>' + r.data.form + '</div>' );
</span><span class="cx"> 
</span><span class="lines">@@ -1274,9 +1294,7 @@
</span><span class="cx">                                   * preview finishing loading.
</span><span class="cx">                                   */
</span><span class="cx">                                  is_instance_identical = _( control.setting() ).isEqual( r.data.instance );
</span><del>-                                       if ( is_instance_identical ) {
-                                               control.container.removeClass( 'previewer-loading' );
-                                       } else {
</del><ins>+                                        if ( ! is_instance_identical ) {
</ins><span class="cx">                                           control.is_widget_updating = true; // suppress triggering another updateWidget
</span><span class="cx">                                          control.setting( r.data.instance );
</span><span class="cx">                                          control.is_widget_updating = false;
</span><span class="lines">@@ -1286,26 +1304,24 @@
</span><span class="cx">                                          complete_callback.call( control, null, { no_change: is_instance_identical, ajax_finished: true } );
</span><span class="cx">                                  }
</span><span class="cx">                          } else {
</span><del>-                                       window.console && window.console.log( r );
-                                       message = 'FAIL';
</del><ins>+                                        message = self.i18n.error;
</ins><span class="cx">                                   if ( r.data && r.data.message ) {
</span><span class="cx">                                          message = r.data.message;
</span><span class="cx">                                  }
</span><span class="cx">                                  if ( complete_callback ) {
</span><span class="cx">                                          complete_callback.call( control, message );
</span><span class="cx">                                  } else {
</span><del>-                                               throw new Error( message );
</del><ins>+                                                widget_content.prepend( '<p class="widget-error"><strong>' + message + '</strong></p>' );
</ins><span class="cx">                                   }
</span><span class="cx">                          }
</span><span class="cx">                  } );
</span><span class="cx">                  jqxhr.fail( function ( jqXHR, textStatus ) {
</span><span class="cx">                          if ( complete_callback ) {
</span><span class="cx">                                  complete_callback.call( control, textStatus );
</span><del>-                               } else {
-                                       throw new Error( textStatus );
</del><span class="cx">                           }
</span><span class="cx">                  } );
</span><span class="cx">                  jqxhr.always( function () {
</span><ins>+                               control.container.removeClass( 'previewer-loading' );
</ins><span class="cx">                           control.container.removeClass( 'widget-form-loading' );
</span><span class="cx">                          inputs.each( function () {
</span><span class="cx">                                  $( this ).removeData( 'state' + update_number );
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpcustomizewidgetsphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/class-wp-customize-widgets.php (27651 => 27652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/class-wp-customize-widgets.php     2014-03-22 10:53:10 UTC (rev 27651)
+++ trunk/src/wp-includes/class-wp-customize-widgets.php        2014-03-22 20:54:17 UTC (rev 27652)
</span><span class="lines">@@ -424,17 +424,14 @@
</span><span class="cx">  /**
</span><span class="cx">   * Convert a widget setting ID (option path) to its id_base and number components
</span><span class="cx">   *
</span><del>-        * @throws Widget_Customizer_Exception
-        * @throws Exception
-        *
</del><span class="cx">    * @param string $setting_id
</span><del>-        * @param array
-        * @return array
</del><ins>+         * @return WP_Error|array
</ins><span class="cx">    */
</span><span class="cx">  static function parse_widget_setting_id( $setting_id ) {
</span><span class="cx">          if ( ! preg_match( '/^(widget_(.+?))(?:\[(\d+)\])?$/', $setting_id, $matches ) ) {
</span><del>-                       throw new Widget_Customizer_Exception( sprintf( 'Invalid widget setting ID: %s', $setting_id ) );
</del><ins>+                        return new WP_Error( 'invalid_setting_id', 'Invalid widget setting ID' );
</ins><span class="cx">           }
</span><ins>+
</ins><span class="cx">           $id_base = $matches[2];
</span><span class="cx">          $number  = isset( $matches[3] ) ? intval( $matches[3] ) : null;
</span><span class="cx">          return compact( 'id_base', 'number' );
</span><span class="lines">@@ -500,6 +497,7 @@
</span><span class="cx">                          'save_btn_tooltip' => ( 'Save and preview changes before publishing them.' ),
</span><span class="cx">                          'remove_btn_label' => __( 'Remove' ),
</span><span class="cx">                          'remove_btn_tooltip' => ( 'Trash widget by moving it to the inactive widgets sidebar.' ),
</span><ins>+                               'error' => __('An error has occurred. Please reload the page and try again.'),
</ins><span class="cx">                   ),
</span><span class="cx">                  'tpl' => array(
</span><span class="cx">                          'widget_reorder_nav' => $widget_reorder_nav_tpl,
</span><span class="lines">@@ -912,108 +910,106 @@
</span><span class="cx">   * Find and invoke the widget update and control callbacks. Requires that
</span><span class="cx">   * $_POST be populated with the instance data.
</span><span class="cx">   *
</span><del>-        * @throws Widget_Customizer_Exception
-        * @throws Exception
-        *
-        * @param string $widget_id
-        * @return array
</del><ins>+         * @param  string $widget_id
+        * @return WP_Error|array
</ins><span class="cx">    */
</span><span class="cx">  static function call_widget_update( $widget_id ) {
</span><span class="cx">          global $wp_registered_widget_updates, $wp_registered_widget_controls;
</span><span class="cx"> 
</span><span class="cx">          $options_transaction = new Options_Transaction();
</span><span class="cx"> 
</span><del>-               try {
-                       $options_transaction->start();
-                       $parsed_id   = self::parse_widget_id( $widget_id );
-                       $option_name = 'widget_' . $parsed_id['id_base'];
</del><ins>+                $options_transaction->start();
+               $parsed_id   = self::parse_widget_id( $widget_id );
+               $option_name = 'widget_' . $parsed_id['id_base'];
</ins><span class="cx"> 
</span><del>-                       /**
-                        * If a previously-sanitized instance is provided, populate the input vars
-                        * with its values so that the widget update callback will read this instance
-                        */
-                       $added_input_vars = array();
-                       if ( ! empty( $_POST['sanitized_widget_setting'] ) ) {
-                               $sanitized_widget_setting = json_decode( self::get_post_value( 'sanitized_widget_setting' ), true );
-                               if ( empty( $sanitized_widget_setting ) ) {
-                                       throw new Widget_Customizer_Exception( 'Malformed sanitized_widget_setting' );
-                               }
-                               $instance = self::sanitize_widget_instance( $sanitized_widget_setting );
-                               if ( is_null( $instance ) ) {
-                                       throw new Widget_Customizer_Exception( 'Unsanitary sanitized_widget_setting' );
-                               }
-                               if ( ! is_null( $parsed_id['number'] ) ) {
-                                       $value = array();
-                                       $value[$parsed_id['number']] = $instance;
-                                       $key = 'widget-' . $parsed_id['id_base'];
</del><ins>+                /**
+                * If a previously-sanitized instance is provided, populate the input vars
+                * with its values so that the widget update callback will read this instance
+                */
+               $added_input_vars = array();
+               if ( ! empty( $_POST['sanitized_widget_setting'] ) ) {
+                       $sanitized_widget_setting = json_decode( self::get_post_value( 'sanitized_widget_setting' ), true );
+                       if ( empty( $sanitized_widget_setting ) ) {
+                               $options_transaction->rollback();
+                               return new WP_Error( 'malformed_data', 'Malformed sanitized_widget_setting' );
+                       }
+
+                       $instance = self::sanitize_widget_instance( $sanitized_widget_setting );
+                       if ( is_null( $instance ) ) {
+                               $options_transaction->rollback();
+                               return new WP_Error( 'unsanitary_data', 'Unsanitary sanitized_widget_setting' );
+                       }
+
+                       if ( ! is_null( $parsed_id['number'] ) ) {
+                               $value = array();
+                               $value[$parsed_id['number']] = $instance;
+                               $key = 'widget-' . $parsed_id['id_base'];
+                               $_REQUEST[$key] = $_POST[$key] = wp_slash( $value );
+                               $added_input_vars[] = $key;
+                       } else {
+                               foreach ( $instance as $key => $value ) {
</ins><span class="cx">                                   $_REQUEST[$key] = $_POST[$key] = wp_slash( $value );
</span><span class="cx">                                  $added_input_vars[] = $key;
</span><del>-                               } else {
-                                       foreach ( $instance as $key => $value ) {
-                                               $_REQUEST[$key] = $_POST[$key] = wp_slash( $value );
-                                               $added_input_vars[] = $key;
-                                       }
</del><span class="cx">                           }
</span><span class="cx">                  }
</span><ins>+               }
</ins><span class="cx"> 
</span><del>-                       /**
-                        * Invoke the widget update callback
-                        */
-                       foreach ( (array) $wp_registered_widget_updates as $name => $control ) {
-                               if ( $name === $parsed_id['id_base'] && is_callable( $control['callback'] ) ) {
-                                       ob_start();
-                                       call_user_func_array( $control['callback'], $control['params'] );
-                                       ob_end_clean();
-                                       break;
-                               }
</del><ins>+                /**
+                * Invoke the widget update callback
+                */
+               foreach ( (array) $wp_registered_widget_updates as $name => $control ) {
+                       if ( $name === $parsed_id['id_base'] && is_callable( $control['callback'] ) ) {
+                               ob_start();
+                               call_user_func_array( $control['callback'], $control['params'] );
+                               ob_end_clean();
+                               break;
</ins><span class="cx">                   }
</span><ins>+               }
</ins><span class="cx"> 
</span><del>-                       // Clean up any input vars that were manually added
-                       foreach ( $added_input_vars as $key ) {
-                               unset( $_POST[$key] );
-                               unset( $_REQUEST[$key] );
-                       }
</del><ins>+                // Clean up any input vars that were manually added
+               foreach ( $added_input_vars as $key ) {
+                       unset( $_POST[$key] );
+                       unset( $_REQUEST[$key] );
+               }
</ins><span class="cx"> 
</span><del>-                       /**
-                        * Make sure the expected option was updated
-                        */
-                       if ( 0 !== $options_transaction->count() ) {
-                               if ( count( $options_transaction->options ) > 1 ) {
-                                       throw new Widget_Customizer_Exception( sprintf( 'Widget %1$s unexpectedly updated more than one option.', $widget_id ) );
-                               }
-                               $updated_option_name = key( $options_transaction->options );
-                               if ( $updated_option_name !== $option_name ) {
-                                       throw new Widget_Customizer_Exception( sprintf( 'Widget %1$s updated option "%2$s", but expected "%3$s".', $widget_id, $updated_option_name, $option_name ) );
-                               }
</del><ins>+                /**
+                * Make sure the expected option was updated
+                */
+               if ( 0 !== $options_transaction->count() ) {
+                       if ( count( $options_transaction->options ) > 1 ) {
+                               $options_transaction->rollback();
+                               return new WP_Error( 'unexpected_update', 'Widget unexpectedly updated more than one option.' );
</ins><span class="cx">                   }
</span><span class="cx"> 
</span><del>-                       /**
-                        * Obtain the widget control with the updated instance in place
-                        */
-                       ob_start();
-                       $form = $wp_registered_widget_controls[$widget_id];
-                       if ( $form ) {
-                               call_user_func_array( $form['callback'], $form['params'] );
</del><ins>+                        $updated_option_name = key( $options_transaction->options );
+                       if ( $updated_option_name !== $option_name ) {
+                               $options_transaction->rollback();
+                               return new WP_Error( 'wrong_option', sprintf( 'Widget updated option "%1$s", but expected "%2$s".', $updated_option_name, $option_name ) );
</ins><span class="cx">                   }
</span><del>-                       $form = ob_get_clean();
</del><ins>+                }
</ins><span class="cx"> 
</span><del>-                       /**
-                        * Obtain the widget instance
-                        */
-                       $option = get_option( $option_name );
-                       if ( null !== $parsed_id['number'] ) {
-                               $instance = $option[$parsed_id['number']];
-                       } else {
-                               $instance = $option;
-                       }
</del><ins>+                /**
+                * Obtain the widget control with the updated instance in place
+                */
+               ob_start();
+               $form = $wp_registered_widget_controls[$widget_id];
+               if ( $form ) {
+                       call_user_func_array( $form['callback'], $form['params'] );
+               }
+               $form = ob_get_clean();
</ins><span class="cx"> 
</span><del>-                       $options_transaction->rollback();
-                       return compact( 'instance', 'form' );
</del><ins>+                /**
+                * Obtain the widget instance
+                */
+               $option = get_option( $option_name );
+               if ( null !== $parsed_id['number'] ) {
+                       $instance = $option[$parsed_id['number']];
+               } else {
+                       $instance = $option;
</ins><span class="cx">           }
</span><del>-               catch ( Exception $e ) {
-                       $options_transaction->rollback();
-                       throw $e;
-               }
</del><ins>+
+               $options_transaction->rollback();
+               return compact( 'instance', 'form' );
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  /**
</span><span class="lines">@@ -1026,53 +1022,47 @@
</span><span class="cx">   * @action wp_ajax_update_widget
</span><span class="cx">   */
</span><span class="cx">  static function wp_ajax_update_widget() {
</span><del>-               $generic_error = __( 'An error has occurred. Please reload the page and try again.' );
</del><span class="cx"> 
</span><del>-               try {
-                       if ( ! check_ajax_referer( self::UPDATE_WIDGET_AJAX_ACTION, self::UPDATE_WIDGET_NONCE_POST_KEY, false ) ) {
-                               throw new Widget_Customizer_Exception( ( 'Nonce check failed. Reload and try again?' ) );
-                       }
-                       if ( ! current_user_can( 'edit_theme_options' ) ) {
-                               throw new Widget_Customizer_Exception( ( 'Current user cannot!' ) ); // @todo translate
-                       }
-                       if ( ! isset( $_POST['widget-id'] ) ) {
-                               throw new Widget_Customizer_Exception( ( 'Incomplete request' ) ); // @todo translate
-                       }
</del><ins>+                if ( ! is_user_logged_in() ) {
+                       wp_die( 0 );
+               }
</ins><span class="cx"> 
</span><del>-                       unset( $_POST[self::UPDATE_WIDGET_NONCE_POST_KEY], $_POST['action'] );
</del><ins>+                check_ajax_referer( self::UPDATE_WIDGET_AJAX_ACTION, self::UPDATE_WIDGET_NONCE_POST_KEY );
</ins><span class="cx"> 
</span><del>-                       do_action( 'load-widgets.php' );
-                       do_action( 'widgets.php' );
-                       do_action( 'sidebar_admin_setup' );
</del><ins>+                if ( ! current_user_can( 'edit_theme_options' ) ) {
+                       wp_die( -1 );
+               }
</ins><span class="cx"> 
</span><del>-                       $widget_id = self::get_post_value( 'widget-id' );
-                       $parsed_id = self::parse_widget_id( $widget_id );
-                       $id_base   = $parsed_id['id_base'];
</del><ins>+                if ( ! isset( $_POST['widget-id'] ) ) {
+                       wp_send_json_error();
+               }
</ins><span class="cx"> 
</span><del>-                       if ( isset( $_POST['widget-' . $id_base] ) && is_array( $_POST['widget-' . $id_base] ) && preg_match( '/__i__|%i%/', key( $_POST['widget-' . $id_base] ) ) ) {
-                               throw new Widget_Customizer_Exception( 'Cannot pass widget templates to create new instances; apply template vars in JS' );
-                       }
</del><ins>+                unset( $_POST[self::UPDATE_WIDGET_NONCE_POST_KEY], $_POST['action'] );
</ins><span class="cx"> 
</span><del>-                       $updated_widget = self::call_widget_update( $widget_id ); // => {instance,form}
-                       $form = $updated_widget['form'];
-                       $instance = self::sanitize_widget_js_instance( $updated_widget['instance'] );
</del><ins>+                do_action( 'load-widgets.php' );
+               do_action( 'widgets.php' );
+               do_action( 'sidebar_admin_setup' );
</ins><span class="cx"> 
</span><del>-                       wp_send_json_success( compact( 'form', 'instance' ) );
</del><ins>+                $widget_id = self::get_post_value( 'widget-id' );
+               $parsed_id = self::parse_widget_id( $widget_id );
+               $id_base   = $parsed_id['id_base'];
+
+               if ( isset( $_POST['widget-' . $id_base] ) && is_array( $_POST['widget-' . $id_base] ) && preg_match( '/__i__|%i%/', key( $_POST['widget-' . $id_base] ) ) ) {
+                       wp_send_json_error();
</ins><span class="cx">           }
</span><del>-               catch( Exception $e ) {
-                       if ( $e instanceof Widget_Customizer_Exception ) {
-                               $message = $e->getMessage();
-                       } else {
-                               error_log( sprintf( '%s in %s: %s', get_class( $e ), __FUNCTION__, $e->getMessage() ) );
-                               $message = $generic_error;
-                       }
-                       wp_send_json_error( compact( 'message' ) );
</del><ins>+
+               $updated_widget = self::call_widget_update( $widget_id ); // => {instance,form}
+               if ( is_wp_error( $updated_widget ) ) {
+                       wp_send_json_error();
</ins><span class="cx">           }
</span><ins>+
+               $form = $updated_widget['form'];
+               $instance = self::sanitize_widget_js_instance( $updated_widget['instance'] );
+
+               wp_send_json_success( compact( 'form', 'instance' ) );
</ins><span class="cx">   }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-class Widget_Customizer_Exception extends Exception {}
-
</del><span class="cx"> class Options_Transaction {
</span><span class="cx"> 
</span><span class="cx">  /**
</span><span class="lines">@@ -1204,9 +1194,6 @@
</span><span class="cx">                  else if ( 'update' === $option_operation['operation'] ) {
</span><span class="cx">                          update_option( $option_operation['option_name'], $option_operation['old_value'] );
</span><span class="cx">                  }
</span><del>-                       else {
-                               throw new Exception( 'Unexpected operation' );
-                       }
</del><span class="cx">           }
</span><span class="cx">          $this->_is_current = false;
</span><span class="cx">  }
</span></span></pre>
</div>
</div>

</body>
</html>