Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using Options Framework to build a list of theme options (using code from the theme, not the plugin).

I have a colour picker as an option, and I can set and call this colour okay.

I'd like to convert the RGB value to HSV, and I found the code to do that here.

I entered this code into my functions.php, in a function called convert_RGA_HSV (on pastebin). It accepts a RGB colour, and returns an array($H, $S, $V).

Also in functions.php I have:

function set_HSV () {
    $varcolour = of_get_option('custom_colour');
    $varhsv = convert_RGA_HSV($varcolour);
    add_option( 'hsv', $varhsv, '', 'yes' );
}

add_action( 'after_setup_theme', 'set_HSV' );   

of_get_option is the function built into the Options Framework to return a value of an option.

I don't know if this set_HSV function is being run, or if it is not working properly, as no option called hsv is being inserted into theme options.

share|improve this question
    
have you enabled debugging to see if any errors are produced? how are you accessing the value of the hsv option in your code? –  Milo Jan 6 '13 at 7:36
    
Is $varcolour = of_get_option('custom_colour'); actually set before you are trying to retrieve it? –  userabuser Jan 6 '13 at 8:33
    
@userabuser Yes, of_get_option('custom_colour') will already return a value. –  Steve Jan 6 '13 at 12:34
    
Is your function convert_RGA_HSV accessible to your set_HSV function? Check by dumping the $varhsv variable. If you don't need add_option's extra parameters then its also OK to use update_option which will create the option if it does not exist and or update the option if it already exists. Syntax: update_option( $option, $new_value ); –  userabuser Jan 6 '13 at 12:56
1  
@Steve - you didn't say how you were attempting to access the hsv option, of_get_option('hsv') will not work, as it's not part of your array of theme options, you've saved it under its own key so you have to use WordPress' get_option –  Milo Jan 6 '13 at 17:13
show 3 more comments

1 Answer

When you save an array of data in an option, WordPress serializes it to save, then when you use get_option, it gets unserialized back into the original array, so it can be accessed as you'd access any indexed array without keys in php:

original option added:

$hsv = array('hval','sval','vval');
add_option('hsv', $hsv);

then, to access this data:

$hsv = get_option('hsv');
echo 'h value is ' . $hsv[0];
echo 's value is ' . $hsv[1];
echo 'v value is ' . $hsv[2];
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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