I’m still having trouble sorting out how to deal with the result from the save callback.
The return value from the save callback is an array. Then that value is saved as the setting defined in the addon settings array. This is the same array in which the two subfields are stored.
$fields = array(
array(
'name' => 'authorization',
'type' => 'authorization',
'save_callback' => array($this, 'save_authorization'),
'args' => array(
'appName' => array(
'name' => self::SDK_APP_NAME,
'type' => 'text',
),
'apiKey' => array(
'name' => self::SDK_API_KEY,
'type' => 'text',
)
),
),
array(
'type' => 'save',
),
array(
'name' => 'clear_cache',
'type' => 'clear_cache',
),
);
The save function re-writes the apiKey
entry
public function save_authorization($value)
{
// If settings have not changed, do not update infusionsoft_sdk values
if (!$this->have_plugin_settings_changed()) {
return $value;
}
$settings = $this->get_posted_settings();
// If the app name or api key are empty, set result to null.
if (!rgar($settings, self::SDK_APP_NAME) || !rgar($settings, self::SDK_API_KEY)) {
return null;
}
$settings[self::SDK_API_KEY] = encrypt(rgar($settings, self::SDK_API_KEY));
return $settings;
}
After this return, the wp_option entry contains three entries: appName, apiKey and an array of these two values called ‘authorization’
Any advice would be appreciated.