Changeset 20645
- Timestamp:
- 04/30/2012 03:46:17 PM (13 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-wp-customize-setting.php
r20585 r20645 22 22 private $_post_value; // Cached, sanitized $_POST value. 23 23 24 // Prefix for $_POST values to prevent naming conflicts.25 const name_prefix = 'customize_';26 27 24 /** 28 25 * Constructor. … … 122 119 return $this->_post_value; 123 120 124 $base = self::name_prefix . $this->id_data[ 'base' ]; 125 126 if ( ! isset( $_POST[ $base ] ) ) 127 return $default; 128 129 $result = $this->multidimensional_get( $_POST[ $base ], $this->id_data[ 'keys' ] ); 130 if ( ! isset( $result ) ) 131 return $default; 132 133 $result = $this->sanitize( $result ); 121 $result = $this->manager->post_value( $this ); 122 134 123 if ( isset( $result ) ) 135 124 return $this->_post_value = $result; -
trunk/wp-includes/class-wp-customize.php
r20598 r20645 18 18 protected $controls = array(); 19 19 20 protected $customized; 21 22 private $_post_values; 23 20 24 /** 21 25 * Constructor. … … 31 35 add_action( 'admin_init', array( $this, 'admin_init' ) ); 32 36 add_action( 'wp_loaded', array( $this, 'wp_loaded' ) ); 37 38 add_action( 'wp_ajax_customize_save', array( $this, 'save' ) ); 33 39 34 40 add_action( 'customize_register', array( $this, 'register_controls' ) ); … … 150 156 151 157 /** 158 * Decode the $_POST attribute used to override the WP_Customize_Setting values. 159 * 160 * @since 3.4.0 161 */ 162 public function post_value( $setting ) { 163 if ( ! isset( $this->_post_values ) ) { 164 if ( isset( $_POST['customized'] ) ) 165 $this->_post_values = json_decode( stripslashes( $_POST['customized'] ), true ); 166 else 167 $this->_post_values = false; 168 } 169 170 if ( isset( $this->_post_values[ $setting->id ] ) ) 171 return $setting->sanitize( $this->_post_values[ $setting->id ] ); 172 } 173 174 175 /** 152 176 * Print javascript settings. 153 177 * … … 268 292 */ 269 293 public function admin_init() { 270 if ( isset( $_REQUEST['save_customize_controls'] ) )271 $this->save();272 273 294 if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) 274 295 return; … … 298 319 public function save() { 299 320 if ( ! $this->is_preview() ) 300 return;301 302 check_a dmin_referer( 'customize_controls' );321 die; 322 323 check_ajax_referer( 'customize_controls', 'nonce' ); 303 324 304 325 // Do we have to switch themes? 305 326 if ( $this->get_stylesheet() != $this->original_stylesheet ) { 306 327 if ( ! current_user_can( 'switch_themes' ) ) 307 return;328 die; 308 329 309 330 // Temporarily stop previewing the theme to allow switch_themes() … … 321 342 322 343 add_action( 'admin_notices', array( $this, '_save_feedback' ) ); 344 345 die; 323 346 } 324 347 -
trunk/wp-includes/css/customize-controls.dev.css
r20598 r20645 127 127 #customize-theme-controls .customize-section-content { 128 128 margin: 0; 129 } 130 131 #customize-footer-actions img { 132 display: none; 133 position: absolute; 134 top: 18px; 135 margin-left: 4px; 136 } 137 .saving #customize-footer-actions img { 138 display: inline; 129 139 } 130 140 -
trunk/wp-includes/customize-controls.php
r20585 r20645 42 42 </head> 43 43 <body class="wp-full-overlay"> 44 <form id="customize-controls" method="post" class="wrap wp-full-overlay-sidebar" target="_parent" action="<?php echo esc_url( add_query_arg( 'save_customize_controls', '1', admin_url( 'themes.php' ) ) ); ?>">44 <form id="customize-controls" class="wrap wp-full-overlay-sidebar"> 45 45 <?php wp_nonce_field( 'customize_controls' ); ?> 46 <input type="hidden" name="customize" value="on" />47 <input type="hidden" name="theme" value="<?php echo esc_attr( $this->get_stylesheet() ); ?>" />48 46 <div id="customize-header-actions" class="customize-section wp-full-overlay-header"> 49 47 <a class="back" href="<?php echo esc_url( admin_url( 'themes.php' ) ); ?>"> … … 80 78 submit_button( $save_text, 'primary', 'save', false ); 81 79 ?> 80 <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" /> 81 82 82 <a href="#" class="collapse-sidebar button-secondary" title="<?php esc_attr_e('Collapse Sidebar'); ?>"> 83 83 <span class="collapse-sidebar-label"><?php _e('Collapse'); ?></span> … … 86 86 </div> 87 87 </form> 88 <div id="customize-preview" class="wp-full-overlay-main"> 89 <iframe name="customize-target"></iframe> 90 </div> 88 <div id="customize-preview" class="wp-full-overlay-main"></div> 91 89 <?php 92 90 … … 96 94 $scheme = is_ssl() ? 'https' : 'http'; 97 95 $settings = array( 96 'theme' => $this->get_stylesheet(), 98 97 'preview' => esc_url( home_url( '/', $scheme ) ), 99 98 'settings' => array(), 100 99 'controls' => array(), 101 'prefix' => WP_Customize_Setting::name_prefix,102 100 'parent' => esc_url( admin_url() ), 101 'ajax' => esc_url( admin_url( 'admin-ajax.php', 'relative' ) ), 103 102 ); 104 103 -
trunk/wp-includes/js/customize-base.dev.js
r20517 r20645 266 266 }, 267 267 268 get: function() { 269 var result = {}; 270 271 if ( arguments.length ) 272 return this.pass( 'get', arguments ); 273 274 $.each( this._value, function( key, obj ) { 275 result[ key ] = obj.get(); 276 } ); 277 return result; 278 }, 279 268 280 set: function( id ) { 269 281 if ( this.has( id ) ) … … 327 339 }); 328 340 329 $.each( [ ' get', 'bind', 'unbind', 'link', 'unlink', 'sync', 'unsync', 'setter', 'resetSetter' ], function( i, method ) {341 $.each( [ 'bind', 'unbind', 'link', 'unlink', 'sync', 'unsync', 'setter', 'resetSetter' ], function( i, method ) { 330 342 api.Values.prototype[ method ] = function() { 331 343 return this.pass( method, arguments ); -
trunk/wp-includes/js/customize-controls.dev.js
r20598 r20645 16 16 this.transport = this.transport || 'refresh'; 17 17 18 element = $( '<input />', {19 type: 'hidden',20 value: this.get(),21 name: api.settings.prefix + id22 });23 24 element.appendTo( this.previewer.form );25 this.element = new api.Element( element );26 27 this.sync( this.element );28 18 this.bind( this.preview ); 29 19 }, … … 272 262 /** 273 263 * Requires params: 274 * - iframe - a selector or jQuery element 275 * - form - a selector or jQuery element 276 * - url - the URL of preview frame 264 * - container - a selector or jQuery element 265 * - url - the URL of preview frame 277 266 */ 278 267 initialize: function( params, options ) { … … 282 271 283 272 this.loaded = $.proxy( this.loaded, this ); 284 285 this.loaderUuid = 0;286 273 287 274 /* … … 321 308 })( this ); 322 309 323 this.iframe = api.ensure( params.iframe ); 324 this.form = api.ensure( params.form ); 325 this.name = this.iframe.prop('name'); 326 327 this.container = this.iframe.parent(); 328 329 api.Messenger.prototype.initialize.call( this, params.url, this.iframe[0].contentWindow ); 330 331 this._formOriginalProps = { 332 target: this.form.prop('target'), 333 action: this.form.prop('action') 334 }; 310 this.container = api.ensure( params.container ); 311 312 api.Messenger.prototype.initialize.call( this, params.url ); 335 313 336 314 this.bind( 'url', function( url ) { 337 315 // Bail if we're navigating to the current url, to a different origin, or wp-admin. 338 if ( this.url() == url || 0 !== url.indexOf( this.origin() + '/' ) || -1 !== url.indexOf( 'wp-admin' ) 316 if ( this.url() == url || 0 !== url.indexOf( this.origin() + '/' ) || -1 !== url.indexOf( 'wp-admin' ) ) 339 317 return; 340 318 … … 342 320 this.refresh(); 343 321 }); 344 345 this.refresh();346 347 // Prevent the form from saving when enter is pressed.348 this.form.on( 'keydown', function( e ) {349 if ( 13 === e.which ) // Enter350 e.preventDefault();351 });352 353 // Create a potential postMessage connection with the parent frame.354 this.parent = new api.Messenger( api.settings.parent );355 356 // If we receive a 'back' event, we're inside an iframe.357 // Send any clicks to the 'Return' link to the parent page.358 this.parent.bind( 'back', function( text ) {359 self.form.find('.back').text( text ).click( function( event ) {360 event.preventDefault();361 self.parent.send( 'close' );362 });363 });364 365 // Initialize the connection with the parent frame.366 this.parent.send( 'ready' );367 322 }, 368 323 loader: function() { … … 370 325 return this.loading; 371 326 372 this.loading = $('<iframe />', { 373 name: this.name + '-loading-' + this.loaderUuid++ 374 }).appendTo( this.container ); 327 this.loading = $('<iframe />').appendTo( this.container ); 375 328 376 329 return this.loading; 377 330 }, 378 331 loaded: function() { 379 this.iframe.remove(); 332 if ( this.iframe ) 333 this.iframe.remove(); 380 334 this.iframe = this.loading; 381 335 delete this.loading; 382 this.iframe.prop( 'name', this.name ); 336 383 337 this.targetWindow( this.iframe[0].contentWindow ); 384 338 }, 339 query: function() {}, 385 340 refresh: function() { 386 this.loader().one( 'load', this.loaded ); 387 388 this.submit({ 389 target: this.loader().prop('name'), 390 action: this.url() 391 }); 392 }, 393 submit: function( props ) { 394 if ( props ) 395 this.form.prop( props ); 396 this.form.submit(); 397 if ( props ) 398 this.form.prop( this._formOriginalProps ); 341 var self = this; 342 343 if ( this.request ) 344 this.request.abort(); 345 346 this.request = $.post( this.url(), this.query() || {}, function( response ) { 347 var iframe = self.loader()[0].contentWindow; 348 349 self.loader().one( 'load', self.loaded ); 350 351 iframe.document.open(); 352 iframe.document.write( response ); 353 iframe.document.close(); 354 }); 399 355 } 400 356 }); … … 416 372 // Initialize Previewer 417 373 var body = $( document.body ), 418 previewer = new api.Previewer({ 419 iframe: '#customize-preview iframe', 420 form: '#customize-controls', 421 url: api.settings.preview 422 }); 374 query, previewer, parent; 375 376 // Prevent the form from saving when enter is pressed. 377 $('#customize-controls').on( 'keydown', function( e ) { 378 if ( 13 === e.which ) // Enter 379 e.preventDefault(); 380 }); 381 382 previewer = new api.Previewer({ 383 container: '#customize-preview', 384 form: '#customize-controls', 385 url: api.settings.preview 386 }, { 387 query: function() { 388 return { 389 customize: 'on', 390 theme: api.settings.theme, 391 customized: JSON.stringify( api.get() ) 392 }; 393 }, 394 395 nonce: $('#_wpnonce').val(), 396 397 save: function() { 398 var query = $.extend( this.query(), { 399 action: 'customize_save', 400 nonce: this.nonce 401 }), 402 request = $.post( api.settings.ajax, query ); 403 404 body.addClass('saving'); 405 request.always( function() { 406 body.removeClass('saving'); 407 }); 408 } 409 }); 423 410 424 411 $.each( api.settings.settings, function( id, data ) { … … 439 426 }); 440 427 428 // Load the preview frame. 429 previewer.refresh(); 430 441 431 // Temporary accordion code. 442 432 $('.customize-section-title').click( function() { … … 447 437 // Button bindings. 448 438 $('#save').click( function( event ) { 449 previewer.s ubmit();439 previewer.save(); 450 440 event.preventDefault(); 451 441 }); … … 455 445 event.preventDefault(); 456 446 }); 447 448 // Create a potential postMessage connection with the parent frame. 449 parent = new api.Messenger( api.settings.parent ); 450 451 // If we receive a 'back' event, we're inside an iframe. 452 // Send any clicks to the 'Return' link to the parent page. 453 parent.bind( 'back', function( text ) { 454 $('.back').text( text ).click( function( event ) { 455 event.preventDefault(); 456 parent.send( 'close' ); 457 }); 458 }); 459 460 // Initialize the connection with the parent frame. 461 parent.send( 'ready' ); 457 462 458 463 // Control visibility for default controls
Note: See TracChangeset
for help on using the changeset viewer.