monsterinsights_update_option

Helper method for updating a setting's value.

Description

(boolean) monsterinsights_update_option( (string) $key = '', (bool) $value = false ); 

Returns (boolean)

True if updated, false if not.

Parameters (2)

0. $key — Optional. (string) => ''
The setting key.
1. $value — Optional. (bool) => false
The value to set for the key.

Usage

  1. if ( !function_exists( 'monsterinsights_update_option' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-analytics-for-wordpress-by-monsterinsights/includes/options.php'; 
  3.  
  4. // The setting key. 
  5. $key = ''; 
  6.  
  7. // The value to set for the key. 
  8. $value = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = monsterinsights_update_option($key, $value); 
  12.  

Defined (1)

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

/includes/options.php  
  1. function monsterinsights_update_option( $key = '', $value = false ) { 
  2.  
  3. // If no key, exit 
  4. if ( empty( $key ) ) { 
  5. return false; 
  6.  
  7. if ( empty( $value ) ) { 
  8. $remove_option = monsterinsights_delete_option( $key ); 
  9. return $remove_option; 
  10.  
  11. $option_name = monsterinsights_get_option_name(); 
  12.  
  13. // First let's grab the current settings 
  14.  
  15. // if on network panel or if on single site using network settings 
  16. //$settings = get_site_option( $option_name ); 
  17. //$use_network_settings = ! empty( $use_network_settings['use_network_settings'] ) ? true : false; 
  18. //$is_network = is_multisite(); 
  19. //$update_network_option = true; 
  20. //if ( ! is_network_admin() && ! ( $is_network && $use_network_settings ) ) { 
  21. $settings = get_option( $option_name ); 
  22. // $update_network_option = false; 
  23. //} 
  24.  
  25. // Let's let devs alter that value coming in 
  26. $value = apply_filters( 'monsterinsights_update_option', $value, $key ); 
  27.  
  28. // Next let's try to update the value 
  29. $settings[ $key ] = $value; 
  30. $did_update = false; 
  31. //if ( $update_network_option ) { 
  32. // $did_update = update_site_option( $option_name, $settings ); 
  33. //} else { 
  34. $did_update = update_option( $option_name, $settings ); 
  35. //} 
  36.  
  37. // If it updated, let's update the global variable 
  38. if ( $did_update ) { 
  39. global $monsterinsights_settings; 
  40. $monsterinsights_settings[ $key ] = $value; 
  41.  
  42. return $did_update;