-1

Still trying to figure my way around Wordpress plugin development, how can I resolve this undefined error? This appears when I add a new post, it can't find the post so I'm trying to figure out how to resolve it with an isset.

Notice: Undefined index: kk_youtube in /var/www/html/wordpress/wp-content/plugins/video_widget/video_widget.php on line 33

The error is on this line 33:

$youtube_link = esc_attr($value['kk_youtube'][0]);

I've been trying to wrap it in isset($post) but it's still not working.

This is the entire function call.

function kk_youtube_handler($post) {
    $value = get_post_custom($post->ID);

    $youtube_link = esc_attr($value['kk_youtube'][0]);

    echo '<label for="kk_youtube">YouTube Video Link</label>
          <input type="text" id="kk_youtube" name="kk_youtube" value="' . 
          $youtube_link . '" />';
}

Can I get some help on this?

esteemed.squire
  • 524
  • 1
  • 7
  • 20

1 Answers1

0

In your form is no name="kk_youtube[]" or name="kk_youtube[0]" attribute.

Use

$value['kk_youtube']

instead of

$value['kk_youtube'][0]

EDIT:

$youtube_link = isset($value['kk_youtube']) ? esc_attr($value['kk_youtube']) : '';
pavel
  • 26,538
  • 10
  • 45
  • 61