Skip to content

Commit

Permalink
fixes #1521, #1560
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Oct 5, 2017
1 parent 01f14d3 commit 7f10ff0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
18 changes: 15 additions & 3 deletions controls/typography/class-kirki-control-typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ public function to_json() {
$this->json['default'] = $this->default;
}
$this->json['output'] = $this->output;
$this->json['value'] = Kirki_Field_Typography::sanitize( $this->value() );
$this->json['value'] = wp_parse_args(
Kirki_Field_Typography::sanitize( $this->value() ),
$this->json['default']
);
$this->json['choices'] = $this->choices;
$this->json['link'] = $this->get_link();
$this->json['id'] = $this->id;
Expand Down Expand Up @@ -183,7 +186,7 @@ protected function content_template() {
<div class="wrapper">

<# if ( data.default['font-family'] ) { #>
<# if ( '' == data.value['font-family'] ) { data.value['font-family'] = data.default['font-family']; } #>
<# data.value['font-family'] = data.value['font-family'] || data['default']['font-family']; #>
<# if ( data.choices['fonts'] ) { data.fonts = data.choices['fonts']; } #>
<div class="font-family">
<h5><?php esc_attr_e( 'Font Family', 'kirki' ); ?></h5>
Expand Down Expand Up @@ -214,34 +217,39 @@ protected function content_template() {
<# } #>

<# if ( data.default['font-size'] ) { #>
<# data.value['font-size'] = data.value['font-size'] || data['default']['font-size']; #>
<div class="font-size">
<h5><?php esc_attr_e( 'Font Size', 'kirki' ); ?></h5>
<input {{{ data.inputAttrs }}} type="text" value="{{ data.value['font-size'] }}"/>
</div>
<# } #>

<# if ( data.default['line-height'] ) { #>
<# data.value['line-height'] = data.value['line-height'] || data['default']['line-height']; #>
<div class="line-height">
<h5><?php esc_attr_e( 'Line Height', 'kirki' ); ?></h5>
<input {{{ data.inputAttrs }}} type="text" value="{{ data.value['line-height'] }}"/>
</div>
<# } #>

<# if ( data.default['letter-spacing'] ) { #>
<# data.value['letter-spacing'] = data.value['letter-spacing'] || data['default']['letter-spacing']; #>
<div class="letter-spacing">
<h5><?php esc_attr_e( 'Letter Spacing', 'kirki' ); ?></h5>
<input {{{ data.inputAttrs }}} type="text" value="{{ data.value['letter-spacing'] }}"/>
</div>
<# } #>

<# if ( data.default['word-spacing'] ) { #>
<# data.value['word-spacing'] = data.value['word-spacing'] || data['default']['word-spacing']; #>
<div class="word-spacing">
<h5><?php esc_attr_e( 'Word Spacing', 'kirki' ); ?></h5>
<input {{{ data.inputAttrs }}} type="text" value="{{ data.value['word-spacing'] }}"/>
</div>
<# } #>

<# if ( data.default['text-align'] ) { #>
<# data.value['text-align'] = data.value['text-align'] || data['default']['text-align']; #>
<div class="text-align">
<h5><?php esc_attr_e( 'Text Align', 'kirki' ); ?></h5>
<input {{{ data.inputAttrs }}} type="radio" value="inherit" name="_customize-typography-text-align-radio-{{ data.id }}" id="{{ data.id }}-text-align-inherit" <# if ( data.value['text-align'] === 'inherit' ) { #> checked="checked"<# } #>>
Expand Down Expand Up @@ -278,6 +286,7 @@ protected function content_template() {
<# } #>

<# if ( data.default['text-transform'] ) { #>
<# data.value['text-transform'] = data.value['text-transform'] || data['default']['text-transform']; #>
<div class="text-transform">
<h5><?php esc_attr_e( 'Text Transform', 'kirki' ); ?></h5>
<select {{{ data.inputAttrs }}} id="kirki-typography-text-transform-{{{ data.id }}}">
Expand All @@ -292,20 +301,23 @@ protected function content_template() {
<# } #>

<# if ( false !== data.default['color'] && data.default['color'] ) { #>
<# data.value['color'] = data.value['color'] || data['default']['color']; #>
<div class="color">
<h5><?php esc_attr_e( 'Color', 'kirki' ); ?></h5>
<input {{{ data.inputAttrs }}} type="text" data-palette="{{ data.palette }}" data-default-color="{{ data.default['color'] }}" value="{{ data.value['color'] }}" class="kirki-color-control" {{{ data.link }}} />
<input {{{ data.inputAttrs }}} type="text" data-palette="{{ data.palette }}" data-default-color="{{ data.default['color'] }}" value="{{ data.value['color'] }}" class="kirki-color-control"/>
</div>
<# } #>

<# if ( data.default['margin-top'] ) { #>
<# data.value['margin-top'] = data.value['margin-top'] || data['default']['margin-top']; #>
<div class="margin-top">
<h5><?php esc_attr_e( 'Margin Top', 'kirki' ); ?></h5>
<input {{{ data.inputAttrs }}} type="text" value="{{ data.value['margin-top'] }}"/>
</div>
<# } #>

<# if ( data.default['margin-bottom'] ) { #>
<# data.value['margin-bottom'] = data.value['margin-bottom'] || data['default']['margin-bottom']; #>
<div class="margin-bottom">
<h5><?php esc_attr_e( 'Margin Bottom', 'kirki' ); ?></h5>
<input {{{ data.inputAttrs }}} type="text" value="{{ data.value['margin-bottom'] }}"/>
Expand Down
2 changes: 1 addition & 1 deletion controls/typography/typography.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ wp.customize.controlConstructor['kirki-typography'] = wp.customize.Control.exten
valueObj = JSON.parse( valueJSON );

valueObj[ property ] = value;
wp.customize.control( control.id ).setting.set( valueObj );
jQuery( input ).attr( 'value', JSON.stringify( valueObj ) ).trigger( 'change' );
control.setting.set( valueObj );
}
});
15 changes: 0 additions & 15 deletions field/class-kirki-field-typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ protected function set_type() {

}

/**
* Helper for the static sanitization.
*
* @static
* @since 3.0.10
* @var array
*/
private static $static_default = array();

/**
* The class constructor.
* Parses and sanitizes all field arguments.
Expand All @@ -48,7 +39,6 @@ protected function set_type() {
public function __construct( $config_id = 'global', $args = array() ) {
parent::__construct( $config_id, $args );
$this->set_default();
self::$static_default = $this->default;
}

/**
Expand Down Expand Up @@ -223,11 +213,6 @@ public static function sanitize( $value ) {
} // End switch().
} // End foreach().

foreach ( array( 'font-size', 'letter-spacing', 'word-spacing', 'line-height', 'text-align', 'color' ) as $property ) {
if ( is_array( self::$static_default ) && ! isset( self::$static_default[ $property ] ) ) {
unset( $value[ $property ] );
}
}
return $value;
}

Expand Down

0 comments on commit 7f10ff0

Please sign in to comment.