Skip to content

Commit

Permalink
Revert "fix(admin-form): 2.2 ensure name title prefixes can be remove…
Browse files Browse the repository at this point in the history
…d once saved #3466"
  • Loading branch information
mehul0810 authored Jul 16, 2018
1 parent 0783185 commit b541c93
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 46 deletions.
51 changes: 25 additions & 26 deletions includes/admin/class-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -796,51 +796,50 @@ class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_att

// Get option value.
$option_value = self::get_option( $option_name, $value['id'], $value['default'] );
$option_value = array_fill_keys( $option_value, 'selected' );
$wrapper_class = ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '';
$type = '';
$allow_new_values = '';
$name = give_get_field_name( $value );

// Set attributes based on multiselect datatype.
if ( 'multiselect' === $value['data_type'] ) {
$type = 'multiple';
$type = 'multiple';
$allow_new_values = 'data-allows-new-values="true"';
$name = $name . '[]';
$option_value = empty( $option_value ) ? array() : $option_value;
}

$title_prefixes_value = ( is_array( $option_value ) && count( $option_value ) > 0 ) ?
array_merge( $value['options'], $option_value ) :
$value['options'];
$option_value = empty( $option_value ) ? array() : $option_value;
}

$value['options'] = array_merge( $value['options'], array_combine( array_values( $option_value ), array_values( $option_value ) ) );
?>
<tr valign="top" <?php echo $wrapper_class; ?>>
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_attr( self::get_field_title( $value ) ); ?></label>
</th>
<td class="give-forminp give-forminp-<?php echo esc_attr( $value['type'] ); ?>">
<select
class="give-select-chosen give-chosen-settings"
style="<?php echo esc_attr( $value['style'] ); ?>"
name="<?php echo esc_attr( $name ); ?>"
id="<?php echo esc_attr( $value['id'] ); ?>"
<?php
echo "{$type} {$allow_new_values}";
echo implode( ' ', $custom_attributes );
?>
class="give-select-chosen give-chosen-settings"
style="<?php echo esc_attr( $value['style'] ); ?>"
name="<?php echo esc_attr( $name ); ?>"
id="<?php echo esc_attr( $value['id'] ); ?>"
<?php echo esc_attr( $type ) . ' ' . esc_attr( $allow_new_values ); ?>
<?php echo implode( ' ', $custom_attributes ); ?>
>
<?php
if ( is_array( $title_prefixes_value ) && count( $title_prefixes_value ) > 0 ) {
foreach ( $title_prefixes_value as $key => $item_value ) {
echo sprintf(
'<option %1$s value="%2$s">%2$s</option>',
( 'selected' === $item_value ) ? 'selected="selected"' : '',
esc_attr( $key )
);
}
}
?>
<?php foreach ( $value['options'] as $key => $item_value ) : ?>
<option
value="<?php echo esc_attr( $key ); ?>"
<?php
if ( is_array( $option_value ) ) {
selected( in_array( $key, $option_value, true ) );
} else {
selected( $option_value, $key );
}
?>
>
<?php echo esc_html( $item_value ); ?>
</option>
<?php endforeach; ?>

</select>
<?php echo wp_kses_post( $description ); ?>
</td>
Expand Down
4 changes: 2 additions & 2 deletions includes/admin/forms/class-metabox-form-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -926,8 +926,8 @@ public function save( $post_id, $post ) {

// Set default value for checkbox fields.
if (
! isset( $_POST[ $form_meta_key ] ) &&
in_array( $this->get_field_type( $form_meta_key ), array( 'checkbox', 'chosen' ) )
! isset( $_POST[ $form_meta_key ] )
&& ( 'checkbox' === $this->get_field_type( $form_meta_key ) )
) {
$_POST[ $form_meta_key ] = '';
}
Expand Down
33 changes: 15 additions & 18 deletions includes/admin/give-metabox-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,24 +320,19 @@ function give_chosen_input( $field ) {
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
$field['style'] = isset( $field['style'] ) ? $field['style'] : '';
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
$field['value'] = array_filter( give_get_field_value( $field, $thepostid ) );
$field['value'] = array_fill_keys( $field['value'], 'selected' );
$field['value'] = give_get_field_value( $field, $thepostid );
$field['before_field'] = '';
$field['after_field'] = '';
$placeholder = isset( $field['placeholder'] ) ? 'data-placeholder="' . $field['placeholder'] . '"' : '';
$data_type = ! empty( $field['data_type'] ) ? $field['data_type'] : '';
$type = '';
$allow_new_values = '';
$title_prefixes_value = ( is_array( $field['value'] ) && count( $field['value'] ) > 0 ) ?
array_merge( $field['options'], $field['value'] ) :
$field['options'];

// Set attributes based on multiselect datatype.
if ( 'multiselect' === $data_type ) {
$type = 'multiple';
$allow_new_values = 'data-allows-new-values="true"';
}

?>
<p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
<label for="<?php echo esc_attr( give_get_field_name( $field ) ); ?>">
Expand All @@ -349,19 +344,21 @@ class="give-select-chosen give-chosen-settings"
style="<?php echo esc_attr( $field['style'] ); ?>"
name="<?php echo esc_attr( give_get_field_name( $field ) ); ?>[]"
id="<?php echo esc_attr( $field['id'] ); ?>"
<?php echo "{$type} {$allow_new_values} {$placeholder}"; ?>
<?php echo esc_attr( $type ) . ' ' . esc_attr( $allow_new_values ) . ' ' . esc_attr( $placeholder ); ?>
>
<?php
if ( is_array( $title_prefixes_value ) && count( $title_prefixes_value ) > 0 ) {
foreach ( $title_prefixes_value as $key => $value ) {
echo sprintf(
'<option %1$s value="%2$s">%2$s</option>',
( 'selected' === $value ) ? 'selected="selected"' : '',
esc_attr( $key )
);
}
}
?>
<?php foreach ( $field['options'] as $key => $value ) { ?>
<option value="<?php echo esc_attr( $key ); ?>"
<?php
if ( is_array( $field['value'] ) ) {
selected( in_array( $key, $field['value'], true ) );
} else {
selected( $field['value'], $key, true );
}
?>
>
<?php echo esc_html( $value ); ?>
</option>
<?php } ?>
</select>
<?php echo esc_attr( $field['after_field'] ); ?>
<?php echo give_get_field_description( $field ); ?>
Expand Down

0 comments on commit b541c93

Please sign in to comment.