Changeset 28143
- Timestamp:
- 04/16/2014 12:10:09 AM (11 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/customize-widgets.js
r28124 r28143 723 723 724 724 // Trigger widget form update when hitting Enter within an input 725 this.container.find( '.widget-content' ).on( 'keydown', 'input', function( e ) {725 $widgetContent.on( 'keydown', 'input', function( e ) { 726 726 if ( 13 === e.which ) { // Enter 727 727 e.preventDefault(); -
trunk/src/wp-includes/class-wp-customize-widgets.php
r28140 r28143 149 149 // Input from customizer preview. 150 150 if ( isset( $_POST['customized'] ) ) { 151 $ customized = json_decode( $this->get_post_value( 'customized' ), true );151 $this->_customized = json_decode( $this->get_post_value( 'customized' ), true ); 152 152 } else { // Input from ajax widget update request. 153 $ customized= array();154 $id_base 155 $widget_number = (int) $this->get_post_value( 'widget_number');156 $option_name 157 $ customized[$option_name] = array();158 if ( false !== $widget_number) {153 $this->_customized = array(); 154 $id_base = $this->get_post_value( 'id_base' ); 155 $widget_number = $this->get_post_value( 'widget_number', false ); 156 $option_name = 'widget_' . $id_base; 157 $this->_customized[ $option_name ] = array(); 158 if ( preg_match( '/^[0-9]+$/', $widget_number ) ) { 159 159 $option_name .= '[' . $widget_number . ']'; 160 $ customized[$option_name][$widget_number] = array();160 $this->_customized[ $option_name ][ $widget_number ] = array(); 161 161 } 162 162 } … … 172 172 $this->_prepreview_added_filters[] = compact( 'hook', 'function' ); 173 173 174 foreach ( $customized as $setting_id => $value ) { 175 if ( preg_match( '/^(widget_.+?)(\[(\d+)\])?$/', $setting_id, $matches ) ) { 176 177 /* 178 * @todo Replace the next two lines with the following once WordPress supports PHP 5.3. 179 * 180 * $self = $this; // not needed in PHP 5.4 181 * 182 * $function = function ( $value ) use ( $self, $setting_id ) { 183 * return $self->manager->widgets->prepreview_added_widget_instance( $value, $setting_id ); 184 * }; 185 */ 186 $body = sprintf( 'global $wp_customize; return $wp_customize->widgets->prepreview_added_widget_instance( $value, %s );', var_export( $setting_id, true ) ); 187 $function = create_function( '$value', $body ); 188 174 $function = array( $this, 'prepreview_added_widget_instance' ); 175 foreach ( $this->_customized as $setting_id => $value ) { 176 if ( preg_match( '/^(widget_.+?)(?:\[(\d+)\])?$/', $setting_id, $matches ) ) { 189 177 $option = $matches[1]; 190 178 191 179 $hook = sprintf( 'option_%s', $option ); 192 add_filter( $hook, $function ); 193 $this->_prepreview_added_filters[] = compact( 'hook', 'function' ); 180 if ( ! has_filter( $hook, $function ) ) { 181 add_filter( $hook, $function ); 182 $this->_prepreview_added_filters[] = compact( 'hook', 'function' ); 183 } 194 184 195 185 $hook = sprintf( 'default_option_%s', $option ); 196 add_filter( $hook, $function ); 197 $this->_prepreview_added_filters[] = compact( 'hook', 'function' ); 186 if ( ! has_filter( $hook, $function ) ) { 187 add_filter( $hook, $function ); 188 $this->_prepreview_added_filters[] = compact( 'hook', 'function' ); 189 } 198 190 199 191 /* … … 205 197 } 206 198 } 207 208 $this->_customized = $customized;209 199 } 210 200 … … 226 216 if ( preg_match( '/^sidebars_widgets\[(.+?)\]$/', $setting_id, $matches ) ) { 227 217 $sidebar_id = $matches[1]; 228 $sidebars_widgets[ $sidebar_id] = $value;218 $sidebars_widgets[ $sidebar_id ] = $value; 229 219 } 230 220 } … … 243 233 * @access public 244 234 * 245 * @param array $instance Widget instance. 246 * @param string $setting_id Widget setting ID. 247 * @return array Parsed widget instance. 248 */ 249 public function prepreview_added_widget_instance( $instance, $setting_id ) { 250 if ( isset( $this->_customized[$setting_id] ) ) { 235 * @param array|bool|mixed $value Widget instance(s), false if open was empty. 236 * @return array|mixed Widget instance(s) with additions. 237 */ 238 public function prepreview_added_widget_instance( $value = false ) { 239 if ( ! preg_match( '/^(?:default_)?option_(widget_(.+))/', current_filter(), $matches ) ) { 240 return $value; 241 } 242 $id_base = $matches[2]; 243 244 foreach ( $this->_customized as $setting_id => $setting ) { 251 245 $parsed_setting_id = $this->parse_widget_setting_id( $setting_id ); 252 $widget_number = $parsed_setting_id['number']; 253 254 // Single widget. 246 if ( is_wp_error( $parsed_setting_id ) || $id_base !== $parsed_setting_id['id_base'] ) { 247 continue; 248 } 249 $widget_number = $parsed_setting_id['number']; 250 255 251 if ( is_null( $widget_number ) ) { 256 if ( false === $instance && empty( $value ) ) { 257 $instance = array(); 252 // Single widget. 253 if ( false === $value ) { 254 $value = array(); 258 255 } 259 } else if ( false === $instance || ! isset( $instance[$widget_number] ) ) { // Multi widget 260 if ( empty( $instance ) ) { 261 $instance = array( '_multiwidget' => 1 ); 256 } else { 257 // Multi widget. 258 if ( empty( $value ) ) { 259 $value = array( '_multiwidget' => 1 ); 262 260 } 263 if ( ! isset( $ instance[$widget_number] ) ) {264 $ instance[$widget_number] = array();261 if ( ! isset( $value[ $widget_number ] ) ) { 262 $value[ $widget_number ] = array(); 265 263 } 266 264 } 267 265 } 268 return $instance; 266 267 return $value; 269 268 } 270 269
Note: See TracChangeset
for help on using the changeset viewer.