Use editable_option() on a key within an options array #56

helgatheviking opened this Issue Feb 15, 2012 · 9 comments


None yet
2 participants

right now (as far as i can tell), you can only use editable_option on options that have their own entry in the wp_options table. a lot of themes wrap their options up into 1 array and so it'd be cool if we could use editable_option() on options that are stored as an array


scribu commented Feb 15, 2012

That's a good idea. editable_option() could accept a 'subkey' parameter:

<?php editable_option( array( 'key' => 'my_options', 'subkey' => 'foo' ) ); ?>

seems like a good idea. it could check that if the get_options returns an array it uses the subkey to find the appropriate value.

question: does the front-end editor actually update the theme option in wp_options? looking at the code and at my db, it looks like it is creating a new key called

$key = "editable_option_$key";

which then makes me understand the default better, b/c initially i thought the value ought to be the theme option... but it is more like front-end-editor creates new options.


scribu commented Feb 16, 2012

It prefixes the option name with editable_option_ for safety. You can disable the prefixing by passing theme_option => false:

editable_option( array( 'key' => 'my_option', 'theme_option' => false ) );

i can tweak the editable_option() function to display the theme option if it is a subkey. but i can't backtrack the $data variable well enough to be able to ensure the $subkey is passed into wrap() function of class FEE_Field_Option. it looks like only some of the $args from editable_option are passed along and i can't figure out how to ensure that the subkey param is included.

function editable_option( $args ) {
    if ( !is_array( $args ) ) {
        _deprecated_argument( __FUNCTION__, '1.9.5', 'Passing individual arguments is deprecated. Use an associative array of arguments instead.' );
        $argv = func_get_args();
        $args = scbUtil::numeric_to_assoc( $argv, array( 'key', 'theme_option', 'ui', 'echo' ) );

    extract( wp_parse_args( $args, array(
        'key' => '',
        'subkey' => false,
        'theme_option' => true,
        'default' => false,
        'ui' => 'input',
        'echo' => true
    ) ) );

    if ( empty( $key ) )
        return false;

    if ( $theme_option ) {
        $key = ($subkey) ? "editable_option_$key_$subkey" : "editable_option_$key";
        $result = get_option( $key, $default );
    } elseif ( $subkey ) { 
        $result = get_option( $key, $default );
        $result = $result[$subkey];
    } else { 
        $result = get_option( $key, $default );

    $output = apply_filters( 'editable_option', $result , $key, $ui );

    if ( $echo )
        echo $output;

    return $output;

additionally, no matter what i pass as the type parameter, i am getting a text input.

editable_option( array(
                  'key' => 'chicago_inter_options',
                  'subkey' => 'message_box',
                  'type' => 'rich',
                  'theme_option' => false,
                  'default' => '',
                ) );

scribu commented Feb 19, 2012

This is a bigger problem that needs to be fixed: #57

ok, so then editable_options aren't quite ready yet?


scribu commented Feb 19, 2012

I guess you can put it like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment