Skip to content

Commit

Permalink
Merge branch 'feature/issue-64' of https://github.com/sc0ttkclark/CMB2
Browse files Browse the repository at this point in the history
…into sc0ttkclark-feature/issue-64
  • Loading branch information
jtsternberg committed Nov 9, 2014
2 parents c804bde + 79b643a commit ee1bb33
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions includes/CMB2_Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,26 @@ public function get_data( $field_id = '', $args = array() ) {
public function update_data( $new_value, $single = true ) {
$a = $this->data_args( array( 'single' => $single ) );

$new_value = $a['repeat'] ? array_values( $new_value ) : $new_value;
$a[ 'value' ] = $a['repeat'] ? array_values( $new_value ) : $new_value;

if ( 'options-page' === $a['type'] ) {
return cmb2_options( $a['id'] )->update( $a['field_id'], $new_value, false, $a['single'] );
}
// Allow an override for the field's saving
$override = apply_filters( 'cmb2_override_meta_save', null, $a, $this->args(), $this );

if ( ! $a['single'] ) {
return add_metadata( $a['type'], $a['id'], $a['field_id'], $new_value, false );
// If no override, update as usual
if ( null !== $override ) {
return $override;
}
// Options page handling
elseif ( 'options-page' === $a['type'] ) {
return cmb2_options( $a['id'] )->update( $a['field_id'], $a[ 'value' ], false, $a['single'] );
}
// Add metadata if not single
elseif ( ! $a['single'] ) {
return add_metadata( $a['type'], $a['id'], $a['field_id'], $a[ 'value' ], false );
}

return update_metadata( $a['type'], $a['id'], $a['field_id'], $new_value );
// Update metadata
return update_metadata( $a['type'], $a['id'], $a['field_id'], $a[ 'value' ] );
}

/**
Expand All @@ -188,11 +197,22 @@ public function update_data( $new_value, $single = true ) {
* @param string $old Old value
*/
public function remove_data( $old = '' ) {
$a = $this->data_args();
$a = $this->data_args( array( 'old' => $old ) );

// Allow an override for the field's saving
$override = apply_filters( 'cmb2_override_meta_remove', null, $a, $this->args(), $this );

// If no override, remove as usual
if ( null !== $override ) {
return $override;
}
// Option page handling
elseif ( 'options-page' === $a['type'] ) {
return cmb2_options( $a['id'] )->remove( $a['field_id'] );
}

return 'options-page' === $a['type']
? cmb2_options( $a['id'] )->remove( $a['field_id'] )
: delete_metadata( $a['type'], $a['id'], $a['field_id'], $old );
// Remove metadata
return delete_metadata( $a['type'], $a['id'], $a['field_id'], $old );
}

/**
Expand Down

0 comments on commit ee1bb33

Please sign in to comment.