cmb2_update_option

A helper function to update an option in a CMB2 options array.

Description

(boolean) cmb2_update_option( (string) $option_key, (string) $field_id, (mixed) $value, (bool) $single = true ); 

Returns (boolean)

Success/Failure

Parameters (4)

0. $option_key (string)
The option key.
1. $field_id (string)
Option array field key
2. $value (mixed)
Value to update data with
3. $single — Optional. (bool) => true
Whether data should not be an array

Usage

  1. if ( !function_exists( 'cmb2_update_option' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'cmb2/includes/helper-functions.php'; 
  3.  
  4. // The option key. 
  5. $option_key = ''; 
  6.  
  7. // Option array field key 
  8. $field_id = ''; 
  9.  
  10. // Value to update data with 
  11. $value = null; 
  12.  
  13. // Whether data should not be an array 
  14. $single = true; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = cmb2_update_option($option_key, $field_id, $value, $single); 
  18.  

Defined (1)

The function is defined in the following location(s).

/includes/helper-functions.php  
  1. function cmb2_update_option( $option_key, $field_id, $value, $single = true ) { 
  2. if (cmb2_options $option_key )->update( $field_id, $value, false, $single ) ) { 
  3. returncmb2_options $option_key )->set(); 
  4.  
  5. return false;