ThemeForest

help me to solve prevent_notice function problem

2498 posts Nice Guy
  • Most Wanted Bounty Winner
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 5-6 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Won a Competition
  • Bought between 100 and 499 items
  • Exclusive Author
  • Referred between 200 and 499 users
+5 more
RubenBristian says

thanks for your code. if the option alway have real init so I never care for notice problem :) . because I’m alway set init for it , so the notice’s never come. I just don’t happy with init value for empty var

I don’t understand.. You came here and said that your item got rejected because you tried to echo empty variables and asked for a solution. We gave you a solution but now you’re saying that you didn’t needed our solution since you already had empty values in those variables. So if you had empty values why did your theme got rejected over issets issues?

I’m sorry but nothing makes sense here :D

373 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 1 and 9 users
  • Sold between 5 000 and 10 000 dollars
  • Vietnam
rongcon says


why not? I just call them in theme options. which only use once. it’s simple the code.
done few times the overhead is negligible so it really doesn’t matter but, if it’s all around in your code, including nested loops, you may want to avoid unnecessary functions call and use directly
if (isset($var)) echo $var;
absolute true!
But you may don’t know where I got the problem. If I need to check the var in some case for example like “full screen” or “boxed” layout IN FRONT END then I’ll use what you’re mention.
The problem’s come in almost task : keep form status. example
$radio_site_layout[$main_option['site-layout']] = 'checked="checked"';
...

<input type="radio" name="site-layout" id="layout-fullscreen" value="1" <?php echo $radio_site_layout[1];?>><label for="layout-fullscreen">Full Screen</label>
                            <input type="radio" name="site-layout" id="layout-boxed" value="2" <?php echo $radio_site_layout[2];?> ><label for="layout-boxed">Boxed</label>
or even hell like this :D
<option value="easeInExpo" <?php echo $easing_select['easeInExpo'];?>>easeInExpo</option>
                                                <option value="easeOutExpo" <?php echo $easing_select['easeOutExpo'];?>>easeOutExpo</option>
                                                <option value="easeInOutExpo" <?php echo $easing_select['easeInOutExpo'];?>>easeInOutExpo</option>
                                                <option value="easeInElastic" <?php echo $easing_select['easeInElastic'];?>>easeInElastic</option>
                                                <option value="easeOutElastic" <?php echo $easing_select['easeOutElastic'];?>>easeOutElastic</option>
                                                <option value="easeInOutElastic" <?php echo $easing_select['easeInOutElastic'];?>>easeInOutElastic</option>
                                                <option value="easeInBack" <?php echo $easing_select['easeInBack'];?>>easeInBack</option>
                                                <option value="easeOutBack" <?php echo $easing_select['easeOutBack'];?>>easeOutBack</option>
...
but this case can use array and foreach to solve problem. :D. actually almost notices I got is from the example #1 :)
373 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 1 and 9 users
  • Sold between 5 000 and 10 000 dollars
  • Vietnam
rongcon says


thanks for your code. if the option alway have real init so I never care for notice problem :) . because I’m alway set init for it , so the notice’s never come. I just don’t happy with init value for empty var

I don’t understand.. You came here and said that your item got rejected because you tried to echo empty variables and asked for a solution. We gave you a solution but now you’re saying that you didn’t needed our solution since you already had empty values in those variables. So if you had empty values why did your theme got rejected over issets issues?

I’m sorry but nothing makes sense here :D
haha , it’s my fault. Sorry I don’t provide my problem case. ok let me describe
my normal code is
$radio_site_layout[$main_option['site-layout']] = 'checked="checked"';
...
<input type="radio" name="site-layout" id="layout-fullscreen" value="1" <?php echo $radio_site_layout[1];?>><label for="layout-fullscreen">Full Screen</label>
                            <input type="radio" name="site-layout" id="layout-boxed" value="2" <?php echo $radio_site_layout[2];?> ><label for="layout-boxed">Boxed</label>
it got notice because the $radio_site_layout array could not have exists key “1” or “2”
so I need to fix it by place this code above :
$radio_site_layout[1] = '';
$radio_site_layout[2] = '';
:D
373 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 1 and 9 users
  • Sold between 5 000 and 10 000 dollars
  • Vietnam
rongcon says

Honestly, for theme options, we just set default values once. A very simple way to do it by using http://codex.wordpress.org/Function_Reference/shortcode_atts
$options = shortcode_adds($defaults,$options)
thanks for suggestion but I did not use any shortcodes :(
373 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 1 and 9 users
  • Sold between 5 000 and 10 000 dollars
  • Vietnam
rongcon says
better code
//prevent notice when the var is not set
function prevent_notice($var){
    if($var){
        echo $var;
    }
}
//for array
function prevent_notice_array($var,$key = ""){
    if(isset($var[$key]) and array_key_exists($key,$var)){
        echo $var[$key];
    }
}
681 posts
  • Sold between 5 000 and 10 000 dollars
  • Exclusive Author
  • Croatia
  • Bought between 10 and 49 items
  • Has been a member for 1-2 years
OriginalEXE says
Not totally related to your issue, but are you aware of these two functions ( I see you manually echo “selected state so I though I could point it out ) http://codex.wordpress.org/Function_Reference/selected http://codex.wordpress.org/Function_Reference/checked
373 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 1 and 9 users
  • Sold between 5 000 and 10 000 dollars
  • Vietnam
rongcon says

Not totally related to your issue, but are you aware of these two functions ( I see you manually echo “selected state so I though I could point it out ) http://codex.wordpress.org/Function_Reference/selected http://codex.wordpress.org/Function_Reference/checked

hmm you saved my life. never seen this function. thank a million times :(

384 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Won a Competition
  • Referred between 500 and 999 users
  • Author had a Free File of the Month
  • Author had a File in an Envato Bundle
  • Bought between 10 and 49 items
+3 more
pixelentity says

thanks for suggestion but I did not use any shortcodes :(
forget about the name (actually there’s a typo in my previous post as function name is shortcode_atts)

what that function does is setting a default value for keys not set in the 2nd array.

373 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 1 and 9 users
  • Sold between 5 000 and 10 000 dollars
  • Vietnam
rongcon says

hmmm, I never know selected and checked function which can pass the php notice. so I can go to simple way and forgot the prevent_notice functions.
Thanks OriginalEXE for your recommend :)
Thanks pixelentity & RubenBristian was too patience to let me see my fault. :D I’m alway kid like that when I don’t understand something. LOL

681 posts
  • Sold between 5 000 and 10 000 dollars
  • Exclusive Author
  • Croatia
  • Bought between 10 and 49 items
  • Has been a member for 1-2 years
OriginalEXE says

No problem ;)

by
by
by
by
by