Duplicate entry in custom field addon

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.

Here’s the database after the SQL INSERT

 select * from wp_options where option_name like '%systasis%';
+-----------+---------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
| option_id | option_name                                 | option_value                                                                                                                                                                                               | autoload |
|     14099 | gravityformsaddon_systasisgfifscrm_version  | 3.0.0                                                                                                                                                                                                      | yes      |
|     14100 | gravityformsaddon_systasisgfifscrm_settings | a:4:{s:25:"sdk_app_name";s:5:"sd108";s:24:"sdk_api_key";s:57:"AK-41e0556ea0ba1d03ce736e739c33cccb78683320eb011e563c";s:13:"authorization";s:0:"";s:11:"clear_cache";s:0:"";} | yes

Notice the empty authorization field

I’m wondering if this is an undocumented artifact of the settings field implementation.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.