kirki icon indicating copy to clipboard operation
kirki copied to clipboard

Configurations not saving to DB

Open boquiabierto opened this issue 11 years ago • 6 comments

Fields are saving only as separate option (example here 'logo_default'), not into the configurated array option (example 'site_branding'). Don’t know if the configured option it is intended to get saved instead of or additionally to the option_name specified in the settings option.

    Kirki::add_config( 'site_branding', array(
        'option_type'      => 'option',
        'option_name'   => 'site_branding',
    ) );
    Kirki::add_field( 'site_branding', array(
        'settings'  => 'logo_default',
        'label' => __('Default logo', 'my-theme'),
        'section'   => 'logo',
        'type'  => 'image',
        'priority'  => 10,
        'default'   => '',
    ) );

The $args passed in self::$fields[Kirki_Field::sanitize_settings( $args )] = $args; are: Array ( [settings] => logo_default [label] => Default logo' [section] => logo [type] => image [priority] => 10 [default] => [option] => [capability] => edit_theme_options [option_type] => option ) I went through all the process I think and couldn’t find the place where the $config['option_name'] is taken into account for saving it into a separate option. The probably best spot to do it is in the sanitize_settings method:

public static function sanitize_settings( $field ) {

        // If the value of 'option_name' is not empty, then we're also using options instead of theme_mods.
        if ( ( isset( $field['option_name'] ) ) && ! empty( $field['option_name'] ) ) {
            $field['settings'] = esc_attr( $field['option_name'] ).'['.esc_attr( $field['settings'] ).']';
        }

        return $field['settings'];

    }

Thanks for looking into it.

boquiabierto avatar Jul 01 '15 16:07 boquiabierto

Hey there!

Can you please try pulling the latest changes from the master branch and test again?

aristath avatar Jul 01 '15 18:07 aristath

This is a WIP, related to https://github.com/reduxframework/kirki/issues/263 as well

aristath avatar Jul 01 '15 19:07 aristath

No news in this matter after me pulling latest changes. Problem must be elsewhere.

boquiabierto avatar Jul 02 '15 10:07 boquiabierto

@boquiabierto can you please try pulling again and test if the latest commits fixed this one?

aristath avatar Jul 03 '15 02:07 aristath

Looks like this has been fixed. I tried adding your code

Kirki::add_config( 'site_branding', array(
    'option_type'      => 'option',
    'option_name'   => 'site_branding',
) );
Kirki::add_field( 'site_branding', array(
    'settings'  => 'logo_default',
    'label' => __('Default logo', 'my-theme'),
    'section'   => 'logo',
    'type'  => 'image',
    'priority'  => 10,
    'default'   => '',
) );

and the option was saved in the db properly (see screenshot below) db-entry

Can you please verify it now works for you as well?

aristath avatar Jul 03 '15 12:07 aristath

Works! Thanks!

boquiabierto avatar Jul 03 '15 15:07 boquiabierto