From d5a3b0966971cfeb5e028b37cd35f35fad122fe2 Mon Sep 17 00:00:00 2001 From: mAAdhaTTah Date: Sun, 7 Dec 2014 14:44:16 -0500 Subject: [PATCH] Add helper function to update an option --- includes/helper-functions.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/includes/helper-functions.php b/includes/helper-functions.php index c0ac7c8ec..8bfdd5cad 100644 --- a/includes/helper-functions.php +++ b/includes/helper-functions.php @@ -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