Skip to content
This repository has been archived by the owner on Dec 17, 2018. It is now read-only.

Commit

Permalink
Fix multicheck not saving properly. Using add_metadata is not very he…
Browse files Browse the repository at this point in the history
…lpful in our situation
  • Loading branch information
jtsternberg committed Mar 24, 2014
1 parent bac4b0f commit 8202eb5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
3 changes: 2 additions & 1 deletion helpers/cmb_Meta_Box_field.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ public function _set_field_defaults( $args ) {
$args['default'] = apply_filters( 'cmb_std_filter', $args['default'], $args, $this->object_type, $this->object_type );
$args['allow'] = 'file' == $args['type'] && ! isset( $args['allow'] ) ? array( 'url', 'attachment' ) : array();
$args['save_id'] = 'file' == $args['type'] && ! ( isset( $args['save_id'] ) && ! $args['save_id'] );
$args['multiple'] = isset( $args['multiple'] ) ? $args['multiple'] : ( 'multicheck' == $args['type'] ? true : false );
// $args['multiple'] = isset( $args['multiple'] ) ? $args['multiple'] : ( 'multicheck' == $args['type'] ? true : false );
$args['multiple'] = isset( $args['multiple'] ) ? $args['multiple'] : false;
$args['repeatable'] = isset( $args['repeatable'] ) && $args['repeatable'] && ! $this->repeatable_exception( $args['type'] );
$args['inline'] = isset( $args['inline'] ) && $args['inline'] || false !== stripos( $args['type'], '_inline' );
$args['on_front'] = ! ( isset( $args['on_front'] ) && ! $args['on_front'] );
Expand Down
23 changes: 12 additions & 11 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,21 +631,22 @@ public static function save_field( $new_value, $field ) {
$name = $field->id();
$old = $field->get_data();

if ( $field->args( 'multiple' ) && ! $field->args( 'repeatable' ) && ! $field->group ) {
$field->remove_data();
if ( ! empty( $new_value ) ) {
foreach ( $new_value as $add_new ) {
self::$updated[] = $name;
$field->update_data( $add_new, $name, false );
}
}
} elseif ( ! empty( $new_value ) && $new_value != $old ) {
// if ( $field->args( 'multiple' ) && ! $field->args( 'repeatable' ) && ! $field->group ) {
// $field->remove_data();
// if ( ! empty( $new_value ) ) {
// foreach ( $new_value as $add_new ) {
// self::$updated[] = $name;
// $field->update_data( $add_new, $name, false );
// }
// }
// } else
if ( ! empty( $new_value ) && $new_value != $old ) {
self::$updated[] = $name;
$field->update_data( $new_value );
return $field->update_data( $new_value );
} elseif ( empty( $new_value ) ) {
if ( ! empty( $old ) )
self::$updated[] = $name;
$field->remove_data();
return $field->remove_data();
}
}

Expand Down

0 comments on commit 8202eb5

Please sign in to comment.