themeum / kirki

Extending the customizer
https://kirki.org
MIT License
1.26k stars 328 forks source link

Notice: Undefined index, repeater field #1291

Closed fakrulislam closed 7 years ago

fakrulislam commented 7 years ago

Issue description:

Hi Ari, I'm using repeater field. When WP_DEBUG is true, kirki display's an Undefined index notice in the customizer panel for one of the repeater field (textarea). I tried to figure it out & spent lot of time but can't find the solution. Could you please see the code below where I'm doing wrong?

The ol_service_desc field producing the Undefined index notice. I embedded kirki into theme.

Here is the entire notice: Notice: Undefined index: ol_service_desc in /Applications/MAMP/htdocs/mytheme/mytheme-pro/wp-content/themes/mytheme-pro/inc/kirki/includes/field/class-kirki-field-repeater.php on line 79

Version used:

(Did you try using the develop branch from github? There's a chance your issue has already been adressed there) Version: 2.3.7 (from wp.org)

Using theme_mods or options?

theme_mods

Code to reproduce the issue (config + field(s))

mytheme_Kirki::add_config( 'mytheme_config', array(
    'capability'    => 'edit_theme_options',
    'option_type'   => 'theme_mod',
) );

    mytheme_Kirki::add_field( 'mytheme_config', array(
        'type'              => 'repeater',
        'settings'          => 'mytheme_services_option',        
        'label'             => __( 'Add Service', 'mytheme-pro' ),
        'section'           => 'mytheme_services_section',                      
        'priority'          => 10,
        'default'           => array(),
        'row_label'         => array(               
            'type'                          => 'text',
            'value'                         => esc_attr__( 'service', 'mytheme-pro' ),
        ),
        'active_callback'   => array(
            array(
                'setting'                   => 'mytheme_services_enable_disable',
                'operator'                  => '==',
                'value'                     => 1,
            ),
        ),              
        'fields'            => array(
                'ol_service_icon'           => array(
                'type'                      => 'select',
                'label'                     => esc_attr__( 'Icon', 'mytheme-pro' ),
                'choices'                   => mytheme_font_awesome(),                
                'default'                   => '',               
            ),
                'ol_service_title'          => array(
                'type'                      => 'text',
                'label'                     => esc_attr__( 'Title', 'mytheme-pro' ),
                'default'                   => '',                
            ),
                'ol_service_desc'           => array(
                'type'                      => 'textarea',
                'label'                     => esc_attr__( 'Description', 'mytheme-pro' ),
                'default'                   => '',
            ),                                                          
        )
    ) );
aristath commented 7 years ago

Hey there!

I just tested this with the develop branch and can't replicate the issue. Can you please test using the version from the develop branch on github and not the one from wordpress.org? If you're still having issues using the develop branch, can you post the mytheme_services_enable_disable function that you're using? Perhaps the error is coming from there.

tjuris commented 7 years ago

Hello I'm experiencing the same notice cluttering my logfile. PHP Notice: Undefined index: link_url in .../wp-content/plugins/kirki/includes/field/class-kirki-field-repeater.php on line 79 The field link_url was used for testing and still has a value stored in database (I checked). It's no longer present in config - I'm using other field names. The offending line 79 is $subfield_type = $this->fields[ $subfield_id ]['type'];, same as https://github.com/aristath/kirki/blob/develop/field/class-kirki-field-repeater.php#L100 I'm guessing the problem lies with unsetting the value a few lines before. Unsetting it is correct, since it's no longer a valid field, but the notice should be avoided and invalid data removed from the setting value stored in database.

aristath commented 7 years ago

Is this using the develop branch or 2.3.7? Try using the latest develop branch and let me know if this still happens for you. I just pushed another commit that should take care of this in your case as well.

tjuris commented 7 years ago

I was using 2.3.7.

Tried the develop version, it's fixed now. Thanks.