0

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.

7
  • 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, 2013 at 7:36
  • Is $varcolour = of_get_option('custom_colour'); actually set before you are trying to retrieve it?
    – Adam
    Jan 6, 2013 at 8:33
  • @userabuser Yes, of_get_option('custom_colour') will already return a value.
    – Steve
    Jan 6, 2013 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 );
    – Adam
    Jan 6, 2013 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, 2013 at 17:13

1 Answer 1

1

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];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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