1141 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
KarmaThemes says

Hi you guys and girls!

Thanks for wanting to help!
I got this option: http://pastie.org/3206675
to select premade backgrounds and call it with this function: http://pastie.org/3206683

Now I want to check if e.g. the first radiobutton/background of the array is selected so I can enhance the function.
Does anyone know how I can do that? I’m thinking something like if(of_get_option(‘patterns’)[1]==checked){ …

Appreciate every help,
thank you!

1152 posts
  • Interviewed on the Envato Notes blog
  • Won a Competition
  • Halloween Competition Winner
  • Exclusive Author
  • Has been a member for 3-4 years
  • Sold between 50 000 and 100 000 dollars
  • Referred between 100 and 199 users
  • Bought between 1 and 9 items
  • United Kingdom
iKreativ says
$backgrounds = array( of_get_option(‘patterns’) );
if ( $backgrounds[1] == 'true' ) :
    // do something 
endif;

Or, if you’re just trying to set a user selected background on the body:

<style type="text/css">
/* Background */
html, body { background: url(<?php bloginfo('template_directory'); ?>/img/<?php echo of_get_option('pattern'); ?>) top center!important;; }
</style>
1141 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
KarmaThemes says

Hi Scott and thanks!

Now I got this: http://pastie.org/3206893 Because it only should call the background function if the first background pattern is not selected. But like that, it seems to return false all the time because the pattern option http://pastie.org/3206896 does not work anymore.

Also, if I output this:
$background = array(of_get_option(‘patterns’,’‘)); print_r($background); I get this (no matter which background of the radiobutton array I selected):
Array ( [0] => http://karmathem.es/dev/this/wp-content/themes/this/patterns/ )

So it seems I will never be able to choose 1, which does not explain why the function will not run, since 0 != 1…

Maybe I am being blind now.

1152 posts
  • Interviewed on the Envato Notes blog
  • Won a Competition
  • Halloween Competition Winner
  • Exclusive Author
  • Has been a member for 3-4 years
  • Sold between 50 000 and 100 000 dollars
  • Referred between 100 and 199 users
  • Bought between 1 and 9 items
  • United Kingdom
iKreativ says

So basically what you require is that if no option is set then it defaults to a background that you specify, else it sets the users chosen background?

<?php

// Check if a user has set a background via the options
if ( of_get_option(‘patterns’) ) : 

// they have, so set it
    <style type="text/css">
        html, body { background: url(<?php echo of_get_option('patterns'); ?>); }
    </style>

// Nope, lets set a default one thene
else :

    <style type="text/css">
        html, body { background: url(../your/default/image.jpg); }
    </style>

endif;
?>
1141 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
KarmaThemes says

Hi Scotty, thanks for your help again!

It’s not quite like that.
The problem with the radiobutton option is that you cannot unselect it without resetting all the options which will cause a loss of all option settings. Which means I cannot check the if of get option because as soon as a background is chosen for the first time you cannot unselect it, but only select another background or reset the options, therefor the if of get option will always be true.
So the first radio button will be a “none” selection the person chooses in order to remove his custom background choice.
I need to check if the first one has been selected in order to deactivate the custom background function.

All the best

436 posts Don't be a HATER!
  • Exclusive Author
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Bought between 10 and 49 items
  • Referred between 10 and 49 users
  • Won a Competition
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Has been a member for 4-5 years
webinpixels says

I dont know ‘of_get_option’ function details, :D – are you use option framework or something?


//which mean user has made some changes
if( get_option('patterns') !== '' ){

     //first option value selected
     if( get_option('patterns') == $patternpath . '01.jpg' ){

     } else { //another option value

     }

} 
else { //do something default, if option is not set

}

I dont know if this will help you :D

good luck

1141 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
KarmaThemes says

Thank you webinpixels!
Yes, it’s the framework, so instead of get_option it’s just of_get_option (I just now realized “of” actually means “option framework”).

I tried this: http://pastie.org/3212224 But no matter which radiobutton I select it’s always “hi”.

:/

436 posts Don't be a HATER!
  • Exclusive Author
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Bought between 10 and 49 items
  • Referred between 10 and 49 users
  • Won a Competition
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Has been a member for 4-5 years
webinpixels says

do you have test the value of your option ( with print_r ), if the value is right (same with the value of radiobutton that selected) – please post it here – but if the value is not right as expected , you should check the framework function or your function which process the data into wp option table

1141 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
KarmaThemes says

I just found out if I do this: http://pastie.org/3212281 and link directly to the static URL of the image it says ‘hey’, so there probably is no way of making that dynamic since the output of the option is static.

Thanks for all your help, if anybody wants to share a brainstorm I’m thankful!

Edit: webinpixels we just had the same thought :)

1141 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
KarmaThemes says
Finally!
http://pastie.org/3212382
Thank you for bringing me on the right track you guys! Have a fantastic day :)

All the best,
Mel for KarmaThemes
by
by
by
by
by
by