gmb_v21_api_key_upgrades

Upgrade API Keys.

Description

gmb_v21_api_key_upgrades(); 

API keys were stored under several option values over plugin versions, requiring reconciliation.


Usage

  1. if ( !function_exists( 'gmb_v21_api_key_upgrades' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'maps-builder/vendor/wordimpress/maps-builder-core/includes/admin/upgrades/upgrades.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = gmb_v21_api_key_upgrades(); 
  7.  

Defined (1)

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

/vendor/wordimpress/maps-builder-core/includes/admin/upgrades/upgrades.php  
  1. function gmb_v21_api_key_upgrades() { 
  2.  
  3. // Establish an array with all possible key values 
  4. $api_key_values = array( 
  5. 'gmb_maps_api_key' => gmb_get_option( 'gmb_maps_api_key' ),  
  6. 'gmb_api_key' => gmb_get_option( 'gmb_api_key' ),  
  7. 'maps_api_key' => gmb_get_option( 'maps_api_key' ),  
  8. ); 
  9.  
  10. // Remove all false/empty values, then get rid of duplicates, then reset the array indices (array_unique preserves indices) 
  11. $unique_api_key_values = array_values( array_unique( array_filter( $api_key_values ) ) ); 
  12.  
  13. // Start with an empty API key 
  14. $reconciled_api_key = ''; 
  15.  
  16. // If there was only one API key value in the list, we'll use that one 
  17. if ( count( $unique_api_key_values ) === 1 ) { 
  18.  
  19. $reconciled_api_key = $unique_api_key_values[0]; 
  20.  
  21. // There was more than one API key value in the list 
  22. } else { 
  23.  
  24. /** 
  25. * Given that there are many API key values, we need to pick just one. So, we prioritize 
  26. * `gmb_maps_api_key` over `gmb_api_key` over `maps_api_key`. 
  27. */ 
  28. $reconciled_api_key = ( ! empty( $api_key_values['maps_api_key'] ) ) ? $api_key_values['maps_api_key'] : $reconciled_api_key; 
  29. $reconciled_api_key = ( ! empty( $api_key_values['gmb_api_key'] ) ) ? $api_key_values['gmb_api_key'] : $reconciled_api_key; 
  30. $reconciled_api_key = ( ! empty( $api_key_values['gmb_maps_api_key'] ) ) ? $api_key_values['gmb_maps_api_key'] : $reconciled_api_key; 
  31.  
  32.  
  33. // Set our API key under the `gmb_maps_api_key` key 
  34. $gmb_settings = get_option( 'gmb_settings' ); 
  35.  
  36. $gmb_settings[ 'gmb_maps_api_key' ] = $reconciled_api_key; 
  37.  
  38. update_option( 'gmb_settings', $gmb_settings ); 
  39.  
  40. // Woo, we made it! 
  41. gmb_set_upgrade_complete( 'gmb_api_keys_upgraded' ); 
  42.