0

I have built a theme.. Now i have updated the theme and my theme consist of two new fields in the theme option panel

<input id="welcome_post_char" type="text" name="abc_options[welcome_post_char]" value="<?php echo esc_attr($settings['welcome_post_char'],'abc'); ?>">

But when i install this theme with old abc_options in my database table, gives an error

Undefined index: welcome_post_char in D:\wamp\www\wptest2\wp-content\themes\accesspress-lite\inc\admin-panel\theme-options.php on line 394

If i do

<input id="welcome_post_char" type="text" name="abc_options[welcome_post_char]" value="<?php if (isset($settings['welcome_post_char'])){echo esc_attr($settings['welcome_post_char'],'abc')}; ?>">

it doesn't give errors.. But i didn't see this approach in other Themes.. So can anyone please suggest me what is the best approach

closed as off-topic by Pieter Goosen, fuxia Jun 12 '14 at 9:30

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • This is not really related to wordpress, but php, which is off topic here. – Pieter Goosen Jun 12 '14 at 6:45
  • If you could answer then please... and It is related to wordpress Theme development – pzstar Jun 12 '14 at 7:14
  • I don't understand what is wrong with this pieter.. Instead of answer what is he doing.. He can use his time instead answering the question – pzstar Jun 12 '14 at 10:03
  • I understand and appreciate your concern, but there are community rules that we all need to abide by to keep this site constructive. Unfortunately your question doesn't fall into scope as this is purely a php error. Stackoverflow is more suited for this type of questions as it is dedicated to php – Pieter Goosen Jun 12 '14 at 10:18
1

@pzstar it is a good approach to check if your variables are assigned a value or not. If a variable or an index in an array is not declared/assigned then you'd probably get such error. I would suggest you to use isset().

<input id="welcome_post_char" type="text" name="abc_options[welcome_post_char]" value="<?php echo (isset($settings['welcome_post_char']))? esc_attr($settings['welcome_post_char'],'abc'): ''}; ?>">

Not the answer you're looking for? Browse other questions tagged or ask your own question.