wp-front-end-editor icon indicating copy to clipboard operation
wp-front-end-editor copied to clipboard

Use editable_option() on a key within an options array

Open helgatheviking opened this issue 13 years ago • 9 comments

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

helgatheviking avatar Feb 15 '12 20:02 helgatheviking

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

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

scribu avatar Feb 15 '12 21:02 scribu

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.

helgatheviking avatar Feb 15 '12 21:02 helgatheviking

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.

helgatheviking avatar Feb 16 '12 16:02 helgatheviking

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

scribu avatar Feb 16 '12 19:02 scribu

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

helgatheviking avatar Feb 19 '12 05:02 helgatheviking

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' => '',
                ) );

helgatheviking avatar Feb 19 '12 05:02 helgatheviking

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

scribu avatar Feb 19 '12 10:02 scribu

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

helgatheviking avatar Feb 19 '12 17:02 helgatheviking

I guess you can put it like that.

scribu avatar Feb 19 '12 17:02 scribu