Skip to content

Commit

Permalink
Add option to store values in individual rows instead of serialized a…
Browse files Browse the repository at this point in the history
…rray
  • Loading branch information
Johny Goerend committed Mar 24, 2015
1 parent d41535c commit 24bb1b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions example-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ function yourprefix_register_demo_metabox() {
'desc' => __( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'multicheckbox',
'type' => 'multicheck',
//'multiple' => true, // Store values in individual rows
'options' => array(
'check1' => __( 'Check One', 'cmb2' ),
'check2' => __( 'Check Two', 'cmb2' ),
Expand Down
21 changes: 10 additions & 11 deletions includes/CMB2_Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,17 +448,16 @@ public function save_field( $meta_value ) {

$new_value = $this->sanitization_cb( $meta_value );
$old = $this->get_data();
// $name = $this->id();
// if ( $this->args( 'multiple' ) && ! $this->args( 'repeatable' ) && ! $this->group ) {
// $this->remove_data();
// if ( ! empty( $new_value ) ) {
// foreach ( $new_value as $add_new ) {
// $this->updated[] = $name;
// $this->update_data( $add_new, $name, false );
// }
// }
// } else
if ( ! cmb2_utils()->isempty( $new_value ) && $new_value !== $old ) {
$name = $this->id();
if ( $this->args( 'multiple' ) && ! $this->args( 'repeatable' ) && ! $this->group ) {
$this->remove_data();
if ( ! empty( $new_value ) ) {
foreach ( $new_value as $add_new ) {
$this->updated[] = $name;
$this->update_data( $add_new, false );
}
}
} elseif ( ! cmb2_utils()->isempty( $new_value ) && $new_value !== $old ) {
return $this->update_data( $new_value );
} elseif ( cmb2_utils()->isempty( $new_value ) ) {
return $this->remove_data();
Expand Down

0 comments on commit 24bb1b2

Please sign in to comment.