diff --git src/wp-admin/customize.php src/wp-admin/customize.php
index 1f85ec6..63fd528 100644
|
|
|
if ( ! $return ) { |
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | |
| | 36 | /** |
| | 37 | * @var WP_Customize_Manager $wp_customize |
| | 38 | */ |
| 36 | 39 | global $wp_scripts, $wp_customize; |
| 37 | 40 | |
| 38 | 41 | $registered = $wp_scripts->registered; |
| … |
… |
do_action( 'customize_controls_print_scripts' ); |
| 257 | 260 | |
| 258 | 261 | // Prepare Customize Setting objects to pass to Javascript. |
| 259 | 262 | foreach ( $wp_customize->settings() as $id => $setting ) { |
| 260 | | $settings['settings'][ $id ] = array( |
| 261 | | 'value' => $setting->js_value(), |
| 262 | | 'transport' => $setting->transport, |
| 263 | | ); |
| | 263 | $settings['settings'][ $id ] = $setting->json(); |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | // Prepare Customize Control objects to pass to JavaScript. |
diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
index 0ea60ce..022c952 100644
|
|
|
|
| 1641 | 1641 | self.send( 'active' ); |
| 1642 | 1642 | }); |
| 1643 | 1643 | |
| | 1644 | var settings = {}; |
| | 1645 | api.each( function ( setting, id) { |
| | 1646 | settings[ id ] = { |
| | 1647 | value: setting.get(), |
| | 1648 | selector: setting.selector |
| | 1649 | }; |
| | 1650 | } ); |
| | 1651 | |
| 1644 | 1652 | this.send( 'sync', { |
| 1645 | 1653 | scroll: self.scroll, |
| 1646 | | settings: api.get() |
| | 1654 | settings: settings |
| 1647 | 1655 | }); |
| 1648 | 1656 | }); |
| 1649 | 1657 | |
| … |
… |
|
| 1855 | 1863 | |
| 1856 | 1864 | // Create Settings |
| 1857 | 1865 | $.each( api.settings.settings, function( id, data ) { |
| 1858 | | api.create( id, id, data.value, { |
| 1859 | | transport: data.transport, |
| | 1866 | var options = $.extend( {}, data, { |
| 1860 | 1867 | previewer: api.previewer |
| 1861 | 1868 | } ); |
| | 1869 | delete options.value; // remove duplicate |
| | 1870 | api.create( id, id, data.value, options ); |
| 1862 | 1871 | }); |
| 1863 | 1872 | |
| 1864 | 1873 | // Create Panels |
diff --git src/wp-content/themes/twentyfifteen/js/customizer.js src/wp-content/themes/twentyfifteen/js/customizer.js
index 0aa9728..5fd4d7c 100644
|
|
|
|
| 16 | 16 | $( '.site-description' ).text( to ); |
| 17 | 17 | } ); |
| 18 | 18 | } ); |
| 19 | | } )( jQuery ); |
| 20 | | No newline at end of file |
| | 19 | } )( jQuery ); |
diff --git src/wp-content/themes/twentyfourteen/inc/customizer.php src/wp-content/themes/twentyfourteen/inc/customizer.php
index 78a667f..9041cc2 100644
|
|
|
|
| 16 | 16 | */ |
| 17 | 17 | function twentyfourteen_customize_register( $wp_customize ) { |
| 18 | 18 | // Add postMessage support for site title and description. |
| 19 | | $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; |
| 20 | | $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; |
| | 19 | $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; |
| | 20 | $wp_customize->get_setting( 'blogname' )->selector = '.site-title a'; |
| | 21 | $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; |
| | 22 | $wp_customize->get_setting( 'blogdescription' )->selector = '.site-description'; |
| 21 | 23 | $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; |
| 22 | 24 | |
| | 25 | /* |
| | 26 | @todo Allow this more convenient syntax |
| | 27 | $wp_customize->update_settings( array( |
| | 28 | 'blog_name' => array( |
| | 29 | 'transport' => 'postMessage', |
| | 30 | 'selector' => '.site-title a', |
| | 31 | ), |
| | 32 | 'blogdescription' => array( |
| | 33 | 'transport' => 'postMessage', |
| | 34 | 'selector' => '.site-description', |
| | 35 | ), |
| | 36 | 'background_color' => array( |
| | 37 | 'transport' => 'postMessage', |
| | 38 | 'selector' => '.site-title a', |
| | 39 | ), |
| | 40 | 'header_textcolor' => array( |
| | 41 | 'transport' => 'postMessage', |
| | 42 | ) |
| | 43 | ) ); |
| | 44 | */ |
| | 45 | |
| | 46 | |
| 23 | 47 | // Rename the label to "Site Title Color" because this only affects the site title in this theme. |
| 24 | 48 | $wp_customize->get_control( 'header_textcolor' )->label = __( 'Site Title Color', 'twentyfourteen' ); |
| 25 | 49 | |
diff --git src/wp-content/themes/twentyfourteen/js/customizer.js src/wp-content/themes/twentyfourteen/js/customizer.js
index 10f3340..b92db79 100644
|
|
|
|
| 3 | 3 | * |
| 4 | 4 | * Contains handlers to make Customizer preview reload changes asynchronously. |
| 5 | 5 | */ |
| 6 | | ( function( $ ) { |
| | 6 | ( function( $, api ) { |
| 7 | 7 | // Site title and description. |
| 8 | | wp.customize( 'blogname', function( value ) { |
| | 8 | api( 'blogname', function( value ) { |
| 9 | 9 | value.bind( function( to ) { |
| 10 | | $( '.site-title a' ).text( to ); |
| | 10 | $( value.selector ).text( to ); |
| 11 | 11 | } ); |
| 12 | 12 | } ); |
| 13 | | wp.customize( 'blogdescription', function( value ) { |
| | 13 | api( 'blogdescription', function( value ) { |
| 14 | 14 | value.bind( function( to ) { |
| 15 | | $( '.site-description' ).text( to ); |
| | 15 | $( value.selector ).text( to ); |
| 16 | 16 | } ); |
| 17 | 17 | } ); |
| 18 | 18 | // Header text color. |
| 19 | | wp.customize( 'header_textcolor', function( value ) { |
| | 19 | api( 'header_textcolor', 'blogname', 'blogdescription', function( value ) { |
| | 20 | |
| 20 | 21 | value.bind( function( to ) { |
| | 22 | var titleDescriptionSelector = api( 'blogname' ).selector + ', ' + api( 'blogdescription' ).selector; |
| | 23 | |
| 21 | 24 | if ( 'blank' === to ) { |
| 22 | | $( '.site-title, .site-description' ).css( { |
| | 25 | $( titleDescriptionSelector ).css( { |
| 23 | 26 | 'clip': 'rect(1px, 1px, 1px, 1px)', |
| 24 | 27 | 'position': 'absolute' |
| 25 | 28 | } ); |
| 26 | 29 | } else { |
| 27 | | $( '.site-title, .site-description' ).css( { |
| | 30 | $( titleDescriptionSelector ).css( { |
| 28 | 31 | 'clip': 'auto', |
| 29 | 32 | 'position': 'static' |
| 30 | 33 | } ); |
| 31 | 34 | |
| 32 | | $( '.site-title a' ).css( { |
| | 35 | $( api( 'blogname' ).selector ).css( { |
| 33 | 36 | 'color': to |
| 34 | 37 | } ); |
| 35 | 38 | } |
| 36 | 39 | } ); |
| 37 | 40 | } ); |
| 38 | | } )( jQuery ); |
| 39 | | No newline at end of file |
| | 41 | } )( jQuery, wp.customize ); |
diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php
index 371ea90..75befba 100644
|
|
|
final class WP_Customize_Manager { |
| 296 | 296 | * |
| 297 | 297 | * @since 3.4.0 |
| 298 | 298 | * |
| 299 | | * @return array |
| | 299 | * @return WP_Customize_Setting[] |
| 300 | 300 | */ |
| 301 | 301 | public function settings() { |
| 302 | 302 | return $this->settings; |
| … |
… |
final class WP_Customize_Manager { |
| 307 | 307 | * |
| 308 | 308 | * @since 3.4.0 |
| 309 | 309 | * |
| 310 | | * @return array |
| | 310 | * @return WP_Customize_Control[] |
| 311 | 311 | */ |
| 312 | 312 | public function controls() { |
| 313 | 313 | return $this->controls; |
| … |
… |
final class WP_Customize_Manager { |
| 329 | 329 | * |
| 330 | 330 | * @since 3.4.0 |
| 331 | 331 | * |
| 332 | | * @return array |
| | 332 | * @return WP_Customize_Section[] |
| 333 | 333 | */ |
| 334 | 334 | public function sections() { |
| 335 | 335 | return $this->sections; |
| … |
… |
final class WP_Customize_Manager { |
| 341 | 341 | * @since 4.0.0 |
| 342 | 342 | * @access public |
| 343 | 343 | * |
| 344 | | * @return array Panels. |
| | 344 | * @return WP_Customize_Panel[] |
| 345 | 345 | */ |
| 346 | 346 | public function panels() { |
| 347 | 347 | return $this->panels; |
| … |
… |
final class WP_Customize_Manager { |
| 496 | 496 | */ |
| 497 | 497 | public function customize_preview_settings() { |
| 498 | 498 | $settings = array( |
| 499 | | 'values' => array(), |
| 500 | 499 | 'channel' => wp_unslash( $_POST['customize_messenger_channel'] ), |
| 501 | 500 | 'activePanels' => array(), |
| 502 | 501 | 'activeSections' => array(), |
| … |
… |
final class WP_Customize_Manager { |
| 510 | 509 | ); |
| 511 | 510 | } |
| 512 | 511 | |
| 513 | | foreach ( $this->settings as $id => $setting ) { |
| 514 | | $settings['values'][ $id ] = $setting->js_value(); |
| 515 | | } |
| 516 | 512 | foreach ( $this->panels as $id => $panel ) { |
| 517 | 513 | $settings['activePanels'][ $id ] = $panel->active(); |
| 518 | 514 | } |
diff --git src/wp-includes/class-wp-customize-setting.php src/wp-includes/class-wp-customize-setting.php
index 7d3511c..8d62d52 100644
|
|
|
|
| 10 | 10 | */ |
| 11 | 11 | class WP_Customize_Setting { |
| 12 | 12 | /** |
| | 13 | * Manager class instance. |
| | 14 | * |
| 13 | 15 | * @access public |
| 14 | 16 | * @var WP_Customize_Manager |
| 15 | 17 | */ |
| 16 | 18 | public $manager; |
| 17 | 19 | |
| 18 | 20 | /** |
| | 21 | * ID for control. |
| | 22 | * |
| 19 | 23 | * @access public |
| 20 | 24 | * @var string |
| 21 | 25 | */ |
| 22 | 26 | public $id; |
| 23 | 27 | |
| 24 | 28 | /** |
| | 29 | * Type of data that this setting represents. |
| | 30 | * |
| 25 | 31 | * @access public |
| 26 | 32 | * @var string |
| 27 | 33 | */ |
| … |
… |
class WP_Customize_Setting { |
| 30 | 36 | /** |
| 31 | 37 | * Capability required to edit this setting. |
| 32 | 38 | * |
| | 39 | * @access public |
| 33 | 40 | * @var string |
| 34 | 41 | */ |
| 35 | 42 | public $capability = 'edit_theme_options'; |
| … |
… |
class WP_Customize_Setting { |
| 41 | 48 | * @var string |
| 42 | 49 | */ |
| 43 | 50 | public $theme_supports = ''; |
| 44 | | public $default = ''; |
| 45 | | public $transport = 'refresh'; |
| 46 | 51 | |
| 47 | 52 | /** |
| 48 | | * Server-side sanitization callback for the setting's value. |
| | 53 | * Default value for setting when associated theme_mod/option/etc is absent. |
| | 54 | * |
| | 55 | * @access public |
| | 56 | * @var string |
| | 57 | */ |
| | 58 | public $default = ''; |
| | 59 | |
| | 60 | /** |
| | 61 | * Transport mechanism for updating the theme preview when a setting changes. |
| | 62 | * |
| | 63 | * The values 'refresh' and 'postMessage' have associated behaviors. |
| | 64 | * |
| | 65 | * @access public |
| | 66 | * @var string |
| | 67 | */ |
| | 68 | public $transport = 'refresh'; |
| | 69 | |
| | 70 | /** |
| | 71 | * Server-side sanitization callback for the setting's value when saved to the DB. |
| | 72 | * |
| | 73 | * This callback is automatically added as a filter for customize_sanitize_{$this->id}. |
| | 74 | * |
| | 75 | * @access public |
| | 76 | * @var callback |
| | 77 | */ |
| | 78 | public $sanitize_callback = ''; |
| | 79 | |
| | 80 | /** |
| | 81 | * Server-side sanitization callback for the setting's value exported to JS. |
| 49 | 82 | * |
| | 83 | * This callback is automatically added as a filter for customize_sanitize_js_{$this->id} |
| | 84 | * |
| | 85 | * @access public |
| 50 | 86 | * @var callback |
| 51 | 87 | */ |
| 52 | | public $sanitize_callback = ''; |
| 53 | 88 | public $sanitize_js_callback = ''; |
| 54 | 89 | |
| | 90 | /** |
| | 91 | * jQuery selector for the element(s) on the frontend which render data. |
| | 92 | * |
| | 93 | * Multiple selectors may be separated by commas. |
| | 94 | * |
| | 95 | * @access public |
| | 96 | * @var string |
| | 97 | */ |
| | 98 | public $selector = ''; |
| | 99 | |
| | 100 | /** |
| | 101 | * The ID parsed into its multidimensional parts. |
| | 102 | * |
| | 103 | * @access protected |
| | 104 | * @var array |
| | 105 | */ |
| 55 | 106 | protected $id_data = array(); |
| 56 | 107 | |
| 57 | 108 | /** |
| … |
… |
class WP_Customize_Setting { |
| 78 | 129 | public function __construct( $manager, $id, $args = array() ) { |
| 79 | 130 | $keys = array_keys( get_object_vars( $this ) ); |
| 80 | 131 | foreach ( $keys as $key ) { |
| 81 | | if ( isset( $args[ $key ] ) ) |
| | 132 | if ( isset( $args[ $key ] ) ) { |
| 82 | 133 | $this->$key = $args[ $key ]; |
| | 134 | } |
| 83 | 135 | } |
| 84 | 136 | |
| 85 | 137 | $this->manager = $manager; |
| 86 | 138 | $this->id = $id; |
| 87 | 139 | |
| 88 | 140 | // Parse the ID for array keys. |
| 89 | | $this->id_data[ 'keys' ] = preg_split( '/\[/', str_replace( ']', '', $this->id ) ); |
| 90 | | $this->id_data[ 'base' ] = array_shift( $this->id_data[ 'keys' ] ); |
| | 141 | $this->id_data['keys'] = preg_split( '/\[/', str_replace( ']', '', $this->id ) ); |
| | 142 | $this->id_data['base'] = array_shift( $this->id_data['keys'] ); |
| 91 | 143 | |
| 92 | 144 | // Rebuild the ID. |
| 93 | | $this->id = $this->id_data[ 'base' ]; |
| 94 | | if ( ! empty( $this->id_data[ 'keys' ] ) ) |
| 95 | | $this->id .= '[' . implode( '][', $this->id_data[ 'keys' ] ) . ']'; |
| | 145 | $this->id = $this->id_data['base']; |
| | 146 | if ( ! empty( $this->id_data['keys'] ) ) { |
| | 147 | $this->id .= '[' . implode( '][', $this->id_data['keys'] ) . ']'; |
| | 148 | } |
| 96 | 149 | |
| 97 | | if ( $this->sanitize_callback ) |
| | 150 | if ( $this->sanitize_callback ) { |
| 98 | 151 | add_filter( "customize_sanitize_{$this->id}", $this->sanitize_callback, 10, 2 ); |
| | 152 | } |
| 99 | 153 | |
| 100 | | if ( $this->sanitize_js_callback ) |
| | 154 | if ( $this->sanitize_js_callback ) { |
| 101 | 155 | add_filter( "customize_sanitize_js_{$this->id}", $this->sanitize_js_callback, 10, 2 ); |
| | 156 | } |
| 102 | 157 | |
| 103 | 158 | return $this; |
| 104 | 159 | } |
| … |
… |
class WP_Customize_Setting { |
| 109 | 164 | * @since 3.4.0 |
| 110 | 165 | */ |
| 111 | 166 | public function preview() { |
| 112 | | switch( $this->type ) { |
| | 167 | switch ( $this->type ) { |
| 113 | 168 | case 'theme_mod' : |
| 114 | | add_filter( 'theme_mod_' . $this->id_data[ 'base' ], array( $this, '_preview_filter' ) ); |
| | 169 | add_filter( 'theme_mod_' . $this->id_data['base'], array( $this, '_preview_filter' ) ); |
| 115 | 170 | break; |
| 116 | 171 | case 'option' : |
| 117 | | if ( empty( $this->id_data[ 'keys' ] ) ) |
| 118 | | add_filter( 'pre_option_' . $this->id_data[ 'base' ], array( $this, '_preview_filter' ) ); |
| 119 | | else { |
| 120 | | add_filter( 'option_' . $this->id_data[ 'base' ], array( $this, '_preview_filter' ) ); |
| 121 | | add_filter( 'default_option_' . $this->id_data[ 'base' ], array( $this, '_preview_filter' ) ); |
| | 172 | if ( empty( $this->id_data['keys'] ) ) { |
| | 173 | add_filter( 'pre_option_' . $this->id_data['base'], array( $this, '_preview_filter' ) ); |
| | 174 | } else { |
| | 175 | add_filter( 'option_' . $this->id_data['base'], array( $this, '_preview_filter' ) ); |
| | 176 | add_filter( 'default_option_' . $this->id_data['base'], array( $this, '_preview_filter' ) ); |
| 122 | 177 | } |
| 123 | 178 | break; |
| 124 | 179 | default : |
| … |
… |
class WP_Customize_Setting { |
| 159 | 214 | * @return mixed New or old value. |
| 160 | 215 | */ |
| 161 | 216 | public function _preview_filter( $original ) { |
| 162 | | return $this->multidimensional_replace( $original, $this->id_data[ 'keys' ], $this->post_value() ); |
| | 217 | return $this->multidimensional_replace( $original, $this->id_data['keys'], $this->post_value() ); |
| 163 | 218 | } |
| 164 | 219 | |
| 165 | 220 | /** |
| … |
… |
class WP_Customize_Setting { |
| 173 | 228 | public final function save() { |
| 174 | 229 | $value = $this->post_value(); |
| 175 | 230 | |
| 176 | | if ( ! $this->check_capabilities() || ! isset( $value ) ) |
| | 231 | if ( ! $this->check_capabilities() || ! isset( $value ) ) { |
| 177 | 232 | return false; |
| | 233 | } |
| 178 | 234 | |
| 179 | 235 | /** |
| 180 | 236 | * Fires when the WP_Customize_Setting::save() method is called. |
| … |
… |
class WP_Customize_Setting { |
| 186 | 242 | * |
| 187 | 243 | * @param WP_Customize_Setting $this WP_Customize_Setting instance. |
| 188 | 244 | */ |
| 189 | | do_action( 'customize_save_' . $this->id_data[ 'base' ], $this ); |
| | 245 | do_action( 'customize_save_' . $this->id_data['base'], $this ); |
| 190 | 246 | |
| 191 | 247 | $this->update( $value ); |
| | 248 | return true; |
| 192 | 249 | } |
| 193 | 250 | |
| 194 | 251 | /** |
| … |
… |
class WP_Customize_Setting { |
| 201 | 258 | */ |
| 202 | 259 | public final function post_value( $default = null ) { |
| 203 | 260 | // Check for a cached value |
| 204 | | if ( isset( $this->_post_value ) ) |
| | 261 | if ( isset( $this->_post_value ) ) { |
| 205 | 262 | return $this->_post_value; |
| | 263 | } |
| 206 | 264 | |
| 207 | 265 | // Call the manager for the post value |
| 208 | 266 | $result = $this->manager->post_value( $this ); |
| 209 | 267 | |
| 210 | | if ( isset( $result ) ) |
| | 268 | if ( isset( $result ) ) { |
| 211 | 269 | return $this->_post_value = $result; |
| 212 | | else |
| | 270 | } else { |
| 213 | 271 | return $default; |
| | 272 | } |
| 214 | 273 | } |
| 215 | 274 | |
| 216 | 275 | /** |
| … |
… |
class WP_Customize_Setting { |
| 244 | 303 | * @return mixed The result of saving the value. |
| 245 | 304 | */ |
| 246 | 305 | protected function update( $value ) { |
| 247 | | switch( $this->type ) { |
| | 306 | switch ( $this->type ) { |
| 248 | 307 | case 'theme_mod' : |
| 249 | 308 | return $this->_update_theme_mod( $value ); |
| 250 | 309 | |
| … |
… |
class WP_Customize_Setting { |
| 274 | 333 | * @since 3.4.0 |
| 275 | 334 | * |
| 276 | 335 | * @param mixed $value The value to update. |
| 277 | | * @return mixed The result of saving the value. |
| | 336 | * @return bool The result of saving the value. |
| 278 | 337 | */ |
| 279 | 338 | protected function _update_theme_mod( $value ) { |
| 280 | 339 | // Handle non-array theme mod. |
| 281 | | if ( empty( $this->id_data[ 'keys' ] ) ) |
| 282 | | return set_theme_mod( $this->id_data[ 'base' ], $value ); |
| | 340 | if ( empty( $this->id_data['keys'] ) ) { |
| | 341 | set_theme_mod( $this->id_data['base'], $value ); |
| | 342 | return true; |
| | 343 | } |
| 283 | 344 | |
| 284 | 345 | // Handle array-based theme mod. |
| 285 | | $mods = get_theme_mod( $this->id_data[ 'base' ] ); |
| 286 | | $mods = $this->multidimensional_replace( $mods, $this->id_data[ 'keys' ], $value ); |
| 287 | | if ( isset( $mods ) ) |
| 288 | | return set_theme_mod( $this->id_data[ 'base' ], $mods ); |
| | 346 | $mods = get_theme_mod( $this->id_data['base'] ); |
| | 347 | $mods = $this->multidimensional_replace( $mods, $this->id_data['keys'], $value ); |
| | 348 | if ( isset( $mods ) ) { |
| | 349 | set_theme_mod( $this->id_data['base'], $mods ); |
| | 350 | return true; |
| | 351 | } |
| | 352 | return false; |
| 289 | 353 | } |
| 290 | 354 | |
| 291 | 355 | /** |
| … |
… |
class WP_Customize_Setting { |
| 294 | 358 | * @since 3.4.0 |
| 295 | 359 | * |
| 296 | 360 | * @param mixed $value The value to update. |
| 297 | | * @return mixed The result of saving the value. |
| | 361 | * @return bool The result of saving the value. |
| 298 | 362 | */ |
| 299 | 363 | protected function _update_option( $value ) { |
| 300 | 364 | // Handle non-array option. |
| 301 | | if ( empty( $this->id_data[ 'keys' ] ) ) |
| 302 | | return update_option( $this->id_data[ 'base' ], $value ); |
| | 365 | if ( empty( $this->id_data['keys'] ) ) { |
| | 366 | return update_option( $this->id_data['base'], $value ); |
| | 367 | } |
| 303 | 368 | |
| 304 | 369 | // Handle array-based options. |
| 305 | | $options = get_option( $this->id_data[ 'base' ] ); |
| 306 | | $options = $this->multidimensional_replace( $options, $this->id_data[ 'keys' ], $value ); |
| 307 | | if ( isset( $options ) ) |
| 308 | | return update_option( $this->id_data[ 'base' ], $options ); |
| | 370 | $options = get_option( $this->id_data['base'] ); |
| | 371 | $options = $this->multidimensional_replace( $options, $this->id_data['keys'], $value ); |
| | 372 | if ( isset( $options ) ) { |
| | 373 | return update_option( $this->id_data['base'], $options ); |
| | 374 | } |
| | 375 | return false; |
| 309 | 376 | } |
| 310 | 377 | |
| 311 | 378 | /** |
| … |
… |
class WP_Customize_Setting { |
| 317 | 384 | */ |
| 318 | 385 | public function value() { |
| 319 | 386 | // Get the callback that corresponds to the setting type. |
| 320 | | switch( $this->type ) { |
| | 387 | switch ( $this->type ) { |
| 321 | 388 | case 'theme_mod' : |
| 322 | 389 | $function = 'get_theme_mod'; |
| 323 | 390 | break; |
| … |
… |
class WP_Customize_Setting { |
| 339 | 406 | * |
| 340 | 407 | * @param mixed $default The setting default value. Default empty. |
| 341 | 408 | */ |
| 342 | | return apply_filters( 'customize_value_' . $this->id_data[ 'base' ], $this->default ); |
| | 409 | return apply_filters( 'customize_value_' . $this->id_data['base'], $this->default ); |
| 343 | 410 | } |
| 344 | 411 | |
| 345 | 412 | // Handle non-array value |
| 346 | | if ( empty( $this->id_data[ 'keys' ] ) ) |
| 347 | | return $function( $this->id_data[ 'base' ], $this->default ); |
| | 413 | if ( empty( $this->id_data['keys'] ) ) { |
| | 414 | return $function( $this->id_data['base'], $this->default ); |
| | 415 | } |
| 348 | 416 | |
| 349 | 417 | // Handle array-based value |
| 350 | | $values = $function( $this->id_data[ 'base' ] ); |
| 351 | | return $this->multidimensional_get( $values, $this->id_data[ 'keys' ], $this->default ); |
| | 418 | $values = $function( $this->id_data['base'] ); |
| | 419 | return $this->multidimensional_get( $values, $this->id_data['keys'], $this->default ); |
| 352 | 420 | } |
| 353 | 421 | |
| 354 | 422 | /** |
| … |
… |
class WP_Customize_Setting { |
| 372 | 440 | */ |
| 373 | 441 | $value = apply_filters( "customize_sanitize_js_{$this->id}", $this->value(), $this ); |
| 374 | 442 | |
| 375 | | if ( is_string( $value ) ) |
| 376 | | return html_entity_decode( $value, ENT_QUOTES, 'UTF-8'); |
| | 443 | if ( is_string( $value ) ) { |
| | 444 | return html_entity_decode( $value, ENT_QUOTES, 'UTF-8' ); |
| | 445 | } |
| 377 | 446 | |
| 378 | 447 | return $value; |
| 379 | 448 | } |
| 380 | 449 | |
| 381 | 450 | /** |
| | 451 | * Gather the parameters passed to client JavaScript via JSON. |
| | 452 | * |
| | 453 | * @since 4.1.0 |
| | 454 | * |
| | 455 | * @return array The array to be exported to the client as JSON |
| | 456 | */ |
| | 457 | public function json() { |
| | 458 | $array = wp_array_slice_assoc( (array) $this, array( 'transport', 'selector' ) ); |
| | 459 | $array['value'] = $this->js_value(); |
| | 460 | return $array; |
| | 461 | } |
| | 462 | |
| | 463 | /** |
| 382 | 464 | * Validate user capabilities whether the theme supports the setting. |
| 383 | 465 | * |
| 384 | 466 | * @since 3.4.0 |
| … |
… |
class WP_Customize_Setting { |
| 386 | 468 | * @return bool False if theme doesn't support the setting or user can't change setting, otherwise true. |
| 387 | 469 | */ |
| 388 | 470 | public final function check_capabilities() { |
| 389 | | if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) |
| | 471 | if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) { |
| 390 | 472 | return false; |
| | 473 | } |
| 391 | 474 | |
| 392 | | if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) |
| | 475 | if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) { |
| 393 | 476 | return false; |
| | 477 | } |
| 394 | 478 | |
| 395 | 479 | return true; |
| 396 | 480 | } |
| … |
… |
class WP_Customize_Setting { |
| 400 | 484 | * |
| 401 | 485 | * @since 3.4.0 |
| 402 | 486 | * |
| 403 | | * @param $root |
| 404 | | * @param $keys |
| | 487 | * @param array $root |
| | 488 | * @param null|array $keys |
| 405 | 489 | * @param bool $create Default is false. |
| 406 | 490 | * @return null|array Keys are 'root', 'node', and 'key'. |
| 407 | 491 | */ |
| 408 | 492 | final protected function multidimensional( &$root, $keys, $create = false ) { |
| 409 | | if ( $create && empty( $root ) ) |
| | 493 | if ( $create && empty( $root ) ) { |
| 410 | 494 | $root = array(); |
| | 495 | } |
| 411 | 496 | |
| 412 | | if ( ! isset( $root ) || empty( $keys ) ) |
| 413 | | return; |
| | 497 | if ( ! isset( $root ) || empty( $keys ) ) { |
| | 498 | return null; |
| | 499 | } |
| 414 | 500 | |
| 415 | 501 | $last = array_pop( $keys ); |
| 416 | 502 | $node = &$root; |
| 417 | 503 | |
| 418 | 504 | foreach ( $keys as $key ) { |
| 419 | | if ( $create && ! isset( $node[ $key ] ) ) |
| | 505 | if ( $create && ! isset( $node[ $key ] ) ) { |
| 420 | 506 | $node[ $key ] = array(); |
| | 507 | } |
| 421 | 508 | |
| 422 | | if ( ! is_array( $node ) || ! isset( $node[ $key ] ) ) |
| 423 | | return; |
| | 509 | if ( ! is_array( $node ) || ! isset( $node[ $key ] ) ) { |
| | 510 | return null; |
| | 511 | } |
| 424 | 512 | |
| 425 | 513 | $node = &$node[ $key ]; |
| 426 | 514 | } |
| 427 | 515 | |
| 428 | | if ( $create && ! isset( $node[ $last ] ) ) |
| | 516 | if ( $create && ! isset( $node[ $last ] ) ) { |
| 429 | 517 | $node[ $last ] = array(); |
| | 518 | } |
| 430 | 519 | |
| 431 | | if ( ! isset( $node[ $last ] ) ) |
| 432 | | return; |
| | 520 | if ( ! isset( $node[ $last ] ) ) { |
| | 521 | return null; |
| | 522 | } |
| 433 | 523 | |
| 434 | 524 | return array( |
| 435 | 525 | 'root' => &$root, |
| … |
… |
class WP_Customize_Setting { |
| 445 | 535 | * |
| 446 | 536 | * @param $root |
| 447 | 537 | * @param $keys |
| | 538 | * @param $value |
| 448 | 539 | * @param mixed $value The value to update. |
| 449 | | * @return |
| | 540 | * @return mixed |
| 450 | 541 | */ |
| 451 | 542 | final protected function multidimensional_replace( $root, $keys, $value ) { |
| 452 | | if ( ! isset( $value ) ) |
| | 543 | if ( ! isset( $value ) ) { |
| 453 | 544 | return $root; |
| 454 | | elseif ( empty( $keys ) ) // If there are no keys, we're replacing the root. |
| | 545 | } elseif ( empty( $keys ) ) { // If there are no keys, we're replacing the root. |
| 455 | 546 | return $value; |
| | 547 | } |
| 456 | 548 | |
| 457 | 549 | $result = $this->multidimensional( $root, $keys, true ); |
| 458 | 550 | |
| 459 | | if ( isset( $result ) ) |
| | 551 | if ( isset( $result ) ) { |
| 460 | 552 | $result['node'][ $result['key'] ] = $value; |
| | 553 | } |
| 461 | 554 | |
| 462 | 555 | return $root; |
| 463 | 556 | } |
| … |
… |
class WP_Customize_Setting { |
| 468 | 561 | * @since 3.4.0 |
| 469 | 562 | * |
| 470 | 563 | * @param $root |
| 471 | | * @param $keys |
| 472 | | * @param $default A default value which is used as a fallback. Default is null. |
| | 564 | * @param null|array $keys |
| | 565 | * @param mixed $default A default value which is used as a fallback. Default is null. |
| 473 | 566 | * @return mixed The requested value or the default value. |
| 474 | 567 | */ |
| 475 | 568 | final protected function multidimensional_get( $root, $keys, $default = null ) { |
| 476 | | if ( empty( $keys ) ) // If there are no keys, test the root. |
| | 569 | if ( empty( $keys ) ) { // If there are no keys, test the root. |
| 477 | 570 | return isset( $root ) ? $root : $default; |
| | 571 | } |
| 478 | 572 | |
| 479 | 573 | $result = $this->multidimensional( $root, $keys ); |
| 480 | 574 | return isset( $result ) ? $result['node'][ $result['key'] ] : $default; |
| … |
… |
class WP_Customize_Setting { |
| 507 | 601 | class WP_Customize_Filter_Setting extends WP_Customize_Setting { |
| 508 | 602 | |
| 509 | 603 | /** |
| | 604 | * Override WP_Customize_Setting::update() to no-op. |
| | 605 | * |
| 510 | 606 | * @since 3.4.0 |
| | 607 | * |
| | 608 | * @param mixed $value |
| | 609 | * @return bool |
| 511 | 610 | */ |
| 512 | | public function update( $value ) {} |
| | 611 | public function update( $value ) { |
| | 612 | return true; |
| | 613 | } |
| 513 | 614 | } |
| 514 | 615 | |
| 515 | 616 | /** |
| … |
… |
final class WP_Customize_Header_Image_Setting extends WP_Customize_Setting { |
| 528 | 629 | * @since 3.4.0 |
| 529 | 630 | * |
| 530 | 631 | * @param $value |
| | 632 | * @return bool |
| 531 | 633 | */ |
| 532 | 634 | public function update( $value ) { |
| | 635 | /** |
| | 636 | * @var Custom_Image_Header $custom_image_header |
| | 637 | */ |
| 533 | 638 | global $custom_image_header; |
| 534 | 639 | |
| 535 | | // If the value doesn't exist (removed or random), |
| 536 | | // use the header_image value. |
| 537 | | if ( ! $value ) |
| 538 | | $value = $this->manager->get_setting('header_image')->post_value(); |
| | 640 | /* |
| | 641 | * If the value doesn't exist (removed or random), |
| | 642 | * use the header_image value. |
| | 643 | */ |
| | 644 | if ( ! $value ) { |
| | 645 | $value = $this->manager->get_setting( 'header_image' )->post_value(); |
| | 646 | } |
| 539 | 647 | |
| 540 | | if ( is_array( $value ) && isset( $value['choice'] ) ) |
| | 648 | if ( is_array( $value ) && isset( $value['choice'] ) ) { |
| 541 | 649 | $custom_image_header->set_header_image( $value['choice'] ); |
| 542 | | else |
| | 650 | } else { |
| 543 | 651 | $custom_image_header->set_header_image( $value ); |
| | 652 | } |
| | 653 | return true; |
| 544 | 654 | } |
| 545 | 655 | } |
| 546 | 656 | |
| … |
… |
final class WP_Customize_Background_Image_Setting extends WP_Customize_Setting { |
| 558 | 668 | * @since 3.4.0 |
| 559 | 669 | * |
| 560 | 670 | * @param $value |
| | 671 | * @return bool |
| 561 | 672 | */ |
| 562 | 673 | public function update( $value ) { |
| 563 | 674 | remove_theme_mod( 'background_image_thumb' ); |
| | 675 | return true; |
| 564 | 676 | } |
| 565 | 677 | } |
diff --git src/wp-includes/js/customize-preview.js src/wp-includes/js/customize-preview.js
index 1a82565..5c279d4 100644
|
|
|
|
| 74 | 74 | channel: api.settings.channel |
| 75 | 75 | }); |
| 76 | 76 | |
| 77 | | preview.bind( 'settings', function( values ) { |
| 78 | | $.each( values, function( id, value ) { |
| 79 | | if ( api.has( id ) ) |
| | 77 | preview.bind( 'settings', function( settings ) { |
| | 78 | |
| | 79 | $.each( settings, function( id, setting ) { |
| | 80 | var value = setting.value; |
| | 81 | delete setting.value; |
| | 82 | if ( api.has( id ) ) { |
| 80 | 83 | api( id ).set( value ); |
| 81 | | else |
| 82 | | api.create( id, value ); |
| | 84 | } else { |
| | 85 | setting.id = id; |
| | 86 | api.create( id, value, setting ); // Note this is an api.Value, not an api.Setting |
| | 87 | } |
| 83 | 88 | }); |
| 84 | 89 | }); |
| 85 | 90 | |
| 86 | | preview.trigger( 'settings', api.settings.values ); |
| 87 | | |
| | 91 | /** |
| | 92 | * @todo Send an setting object instead of a key/value pair? |
| | 93 | */ |
| 88 | 94 | preview.bind( 'setting', function( args ) { |
| 89 | 95 | var value; |
| 90 | 96 | |
| | 97 | // @todo Allow other args? |
| 91 | 98 | args = args.slice(); |
| 92 | 99 | |
| 93 | | if ( value = api( args.shift() ) ) |
| | 100 | if ( value = api( args.shift() ) ) { |
| 94 | 101 | value.set.apply( value, args ); |
| | 102 | } |
| 95 | 103 | }); |
| 96 | 104 | |
| 97 | 105 | preview.bind( 'sync', function( events ) { |
| … |
… |
|
| 101 | 109 | preview.send( 'synced' ); |
| 102 | 110 | }); |
| 103 | 111 | |
| 104 | | preview.bind( 'active', function() { |
| 105 | | if ( api.settings.nonce ) |
| 106 | | preview.send( 'nonce', api.settings.nonce ); |
| 107 | | }); |
| | 112 | preview.bind( 'active', function() { |
| | 113 | if ( api.settings.nonce ) { |
| | 114 | preview.send( 'nonce', api.settings.nonce ); |
| | 115 | } |
| | 116 | }); |
| 108 | 117 | |
| 109 | 118 | preview.send( 'ready', { |
| 110 | 119 | activePanels: api.settings.activePanels, |