type ) {
case 'sortlist' :
if ( ! empty( $this->label ) ) : ?>
label ); ?>
description ) ) : ?>
description ; ?>
sublabel ) ) : ?>
sublabel ; ?>
id ) );
$choices = $this->choices;
$rawvalue = $this->value();
$valuearray = array();
// We do not use JSON.stringify( $optionsform.serializeArray() ) and PHP json_decode().
// This is because when using a dafult value, it is passed through get_theme_mod which creates a sprintf error ( since default string has a lot of % signs from http_build_query(): php equivalent of jquery.serialize() ). We dont face this issue if the value is stored, as sprintf is only applied on default in get_theme_mod. Also note, this error is only visible in customizer view.
// Hence we use a mix. For normal stored values and js computation, we use jquery.serialize() and PHP parse_str().
// However, for defaults, we still use json_encode instead of http_build_query due to above reason
// If revert to stringify + json_decode():
// Known bug: error in saving (") in textareas when using stringify + json_decode()
// Make sure hidden input has value marked with single inverted (') to work with stringify which uses " in the string.
if ( !empty( $rawvalue ) ) { // We either have a default, or value stored
$value_json = json_decode( $rawvalue, true ); // We cant use parse_str because parse_str on json_encoded string still gives an array. However json_decode on jquery.serialize string returns null
if ( !empty( $value_json ) && is_array( $value_json ) ) { // json_encoded default value
$valuearray = $value_json;
} else {
parse_str($rawvalue, $valuearray);
}
}
// Check if stored value / default value parsed properly to an array
if ( !empty( $valuearray ) && is_array( $valuearray ) ) {
$valuearray = $valuearray[ esc_attr( $id ) ];
// Check choices if any missing (useful if a child theme adds choices after this setting has been saved atleast once in database)
foreach ( $choices as $choiceid => $choicelabel )
if ( !array_key_exists( $choiceid, $valuearray ) )
$valuearray[ $choiceid ]['sortitem_hide'] = '';
// Also check if a choice has been removed (by child theme) but its value still exists in stored value
foreach ( $valuearray as $choiceid => $choicevalues )
if ( empty( $choices[ $choiceid ] ) )
unset( $valuearray[ $choiceid ] );
} else {
// no value stored, no default=> create empty array
foreach ( $choices as $choiceid => $choicelabel )
$valuearray[ $choiceid ] = $valuearray[ $choiceid ]['sortitem_hide'] = '';
}
$display = ( isset( $this->attributes['display-label'] ) && $this->attributes['display-label'] === false ) ? false : true; // default: true
$display = ( !empty( $this->options ) && is_array( $this->options ) ) ? $display : true; // always true if no options
$hideable = ( !empty( $this->attributes['hideable'] ) ); // default: false
$hideable = ( !$display ) ? false : $hideable; // always false if display-label false
$open = ( !empty( $this->attributes['open-state'] ) ); // default: false
$open = ( !$display ) ? true : $open; // always true if display-label false
$sortable = ( !empty( $this->attributes['sortable'] ) ); // default: false
$sortable = ( !$display ) ? false : $sortable; // always false if display-label false
?>