Changeset 42343 for trunk/src/wp-includes/class-wp-customize-setting.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-customize-setting.php
r41162 r42343 170 170 171 171 $this->manager = $manager; 172 $this->id = $id;172 $this->id = $id; 173 173 174 174 // Parse the ID for array keys. … … 177 177 178 178 // Rebuild the ID. 179 $this->id = $this->id_data[ 'base'];180 if ( ! empty( $this->id_data[ 'keys'] ) ) {179 $this->id = $this->id_data['base']; 180 if ( ! empty( $this->id_data['keys'] ) ) { 181 181 $this->id .= '[' . implode( '][', $this->id_data['keys'] ) . ']'; 182 182 } … … 312 312 } 313 313 314 $id_base = $this->id_data['base'];315 $is_multidimensional = ! empty( $this->id_data['keys'] );314 $id_base = $this->id_data['base']; 315 $is_multidimensional = ! empty( $this->id_data['keys'] ); 316 316 $multidimensional_filter = array( $this, '_multidimensional_preview_filter' ); 317 317 … … 322 322 * to be previewed. 323 323 */ 324 $undefined = new stdClass();324 $undefined = new stdClass(); 325 325 $needs_preview = ( $undefined !== $this->post_value( $undefined ) ); 326 $value = null;326 $value = null; 327 327 328 328 // Since no post value was defined, check if we have an initial value set. 329 329 if ( ! $needs_preview ) { 330 330 if ( $this->is_multidimensional_aggregated ) { 331 $root = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value'];331 $root = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value']; 332 332 $value = $this->multidimensional_get( $root, $this->id_data['keys'], $undefined ); 333 333 } else { 334 $default = $this->default;334 $default = $this->default; 335 335 $this->default = $undefined; // Temporarily set default to undefined so we can detect if existing value is set. 336 $value = $this->value();336 $value = $this->value(); 337 337 $this->default = $default; 338 338 } … … 349 349 350 350 switch ( $this->type ) { 351 case 'theme_mod' :351 case 'theme_mod': 352 352 if ( ! $is_multidimensional ) { 353 353 add_filter( "theme_mod_{$id_base}", array( $this, '_preview_filter' ) ); … … 360 360 } 361 361 break; 362 case 'option' :362 case 'option': 363 363 if ( ! $is_multidimensional ) { 364 364 add_filter( "pre_option_{$id_base}", array( $this, '_preview_filter' ) ); … … 372 372 } 373 373 break; 374 default : 375 374 default: 376 375 /** 377 376 * Fires when the WP_Customize_Setting::preview() method is called for settings … … 437 436 } 438 437 439 $undefined = new stdClass(); // Symbol hack.438 $undefined = new stdClass(); // Symbol hack. 440 439 $post_value = $this->post_value( $undefined ); 441 440 if ( $undefined !== $post_value ) { … … 484 483 // Do the replacements of the posted/default sub value into the root value. 485 484 $value = $previewed_setting->post_value( $previewed_setting->default ); 486 $root = self::$aggregated_multidimensionals[ $previewed_setting->type ][ $id_base ]['root_value'];487 $root = $previewed_setting->multidimensional_replace( $root, $previewed_setting->id_data['keys'], $value );485 $root = self::$aggregated_multidimensionals[ $previewed_setting->type ][ $id_base ]['root_value']; 486 $root = $previewed_setting->multidimensional_replace( $root, $previewed_setting->id_data['keys'], $value ); 488 487 self::$aggregated_multidimensionals[ $previewed_setting->type ][ $id_base ]['root_value'] = $root; 489 488 … … 721 720 */ 722 721 public function value() { 723 $id_base = $this->id_data['base'];722 $id_base = $this->id_data['base']; 724 723 $is_core_type = ( 'option' === $this->type || 'theme_mod' === $this->type ); 725 724 … … 754 753 } elseif ( $this->is_multidimensional_aggregated ) { 755 754 $root_value = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value']; 756 $value = $this->multidimensional_get( $root_value, $this->id_data['keys'], $this->default );755 $value = $this->multidimensional_get( $root_value, $this->id_data['keys'], $this->default ); 757 756 758 757 // Ensure that the post value is used if the setting is previewed, since preview filters aren't applying on cached $root_value. … … 787 786 $value = apply_filters( "customize_sanitize_js_{$this->id}", $this->value(), $this ); 788 787 789 if ( is_string( $value ) ) 790 return html_entity_decode( $value, ENT_QUOTES, 'UTF-8'); 788 if ( is_string( $value ) ) { 789 return html_entity_decode( $value, ENT_QUOTES, 'UTF-8' ); 790 } 791 791 792 792 return $value; … … 817 817 */ 818 818 final public function check_capabilities() { 819 if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) 819 if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) { 820 820 return false; 821 822 if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) 821 } 822 823 if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) { 823 824 return false; 825 } 824 826 825 827 return true; … … 837 839 */ 838 840 final protected function multidimensional( &$root, $keys, $create = false ) { 839 if ( $create && empty( $root ) ) 841 if ( $create && empty( $root ) ) { 840 842 $root = array(); 841 842 if ( ! isset( $root ) || empty( $keys ) ) 843 } 844 845 if ( ! isset( $root ) || empty( $keys ) ) { 843 846 return; 847 } 844 848 845 849 $last = array_pop( $keys ); … … 847 851 848 852 foreach ( $keys as $key ) { 849 if ( $create && ! isset( $node[ $key ] ) ) 853 if ( $create && ! isset( $node[ $key ] ) ) { 850 854 $node[ $key ] = array(); 851 852 if ( ! is_array( $node ) || ! isset( $node[ $key ] ) ) 855 } 856 857 if ( ! is_array( $node ) || ! isset( $node[ $key ] ) ) { 853 858 return; 859 } 854 860 855 861 $node = &$node[ $key ]; … … 866 872 } 867 873 868 if ( ! isset( $node[ $last ] ) ) 874 if ( ! isset( $node[ $last ] ) ) { 869 875 return; 876 } 870 877 871 878 return array( … … 887 894 */ 888 895 final protected function multidimensional_replace( $root, $keys, $value ) { 889 if ( ! isset( $value ) ) 896 if ( ! isset( $value ) ) { 890 897 return $root; 891 elseif ( empty( $keys ) )// If there are no keys, we're replacing the root.898 } elseif ( empty( $keys ) ) { // If there are no keys, we're replacing the root. 892 899 return $value; 900 } 893 901 894 902 $result = $this->multidimensional( $root, $keys, true ); 895 903 896 if ( isset( $result ) ) 904 if ( isset( $result ) ) { 897 905 $result['node'][ $result['key'] ] = $value; 906 } 898 907 899 908 return $root; … … 911 920 */ 912 921 final protected function multidimensional_get( $root, $keys, $default = null ) { 913 if ( empty( $keys ) ) // If there are no keys, test the root.922 if ( empty( $keys ) ) { // If there are no keys, test the root. 914 923 return isset( $root ) ? $root : $default; 924 } 915 925 916 926 $result = $this->multidimensional( $root, $keys );
Note: See TracChangeset
for help on using the changeset viewer.