osompress / simple-social-icons

Plugin: Simple Social Icons
62 stars 33 forks source link

Notice of Undefined index in widget after adding custom icon #49

Closed jdelia closed 7 years ago

jdelia commented 7 years ago

After adding a custom icon per instructions, I receive this notice (with debug and trace on) when I first add a widget to a widget area. Once the widget area is saved, the notice is gone and does not return.

Notice: Undefined index: youtube-alt in /Users/site/Documents/Websites/sample.dev/wp-content/plugins/simple-social-icons/simple-social-icons.php on line 319

Code added to functions.php

add_filter( 'simple_social_default_profiles', 'jd_custom_add_new_simple_icon' );
/**
 * Add custom icon to simple social icons
 *
 * @param array $icons return social icons.
 */
function jd_custom_add_new_simple_icon( $icons ) {
    $icons['youtube-alt'] = [
        'label'   => __( 'Youtube alt', 'simple-social-icons' ),
        'pattern' => '<li class="social-youtube-alt"><a href="%s" %s><svg role="img" class="social-youtube-alt-svg" aria-labelledby="social-youtube-alt"><title id="social-youtube-alt">' . __( 'Youtube', 'simple-social-icons' ) . '</title><use xlink:href="' . CHILD_THEME_URI . '/images/custom-icons.svg#youtube-alt"></use></svg></a></li>',
    ];

    return $icons;
}
nickcernis commented 7 years ago

Thanks, @jdelia. If you add a default value for the new icon too, that notice will disappear:

add_filter( 'simple_social_default_styles', 'custom_add_new_icon_default' );

function custom_add_new_icon_default( $defaults ) {
    $defaults['youtube-alt'] = '';

    return $defaults;
}

I have updated the wiki entry to mention this. Thanks for your report!

jdelia commented 7 years ago

Thank you Nick.