Skip to content

Commit

Permalink
Add helper function to update an option
Browse files Browse the repository at this point in the history
  • Loading branch information
mAAdhaTTah committed Dec 9, 2014
1 parent ea64bad commit d5a3b09
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions includes/helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ function cmb2_get_option( $option_key, $field_id = '' ) {
return cmb2_options( $option_key )->get( $field_id );
}

/**
* A helper function to update an option in a CMB options array
* @since 2.0.0
* @param string $option_key Option key
* @param string $field_id Option array field key
* @param mixed $value Value to update data with
* @param bool $resave Whether to re-save the data
* @param bool $single Whether data should be an array
* @return array Modified options
*/
function cmb2_update_option( $option_key, $field_id, $value, $resave = false, $single = true ) {
if ( cmb2_options( $option_key )->update( $field_id, $value, $resave, $single ) ) {
return cmb2_options( $option_key )->set();
}

return false;
}

/**
* Get a CMB field object.
* @since 1.1.0
Expand Down

0 comments on commit d5a3b09

Please sign in to comment.