Forums

OptionTree
[resolved] Default form values? (6 posts)

  1. johnb41
    Member
    Posted 1 year ago #

    I love this plugin from what I've seen so far. But I don't know if it's usable for "me" until I get this resolved:

    My current (old) Theme Options has some default values set (default text for textareas, default dropdown lists selected, etc.) It would be great if after the user uploads the XML for their site, that certain things would be pre-populated. Am I missing something, or is such a thing not supported?

    http://wordpress.org/extend/plugins/option-tree/

  2. Derek Herman
    Member
    Posted 1 year ago #

    Default values are created when you save the data and export it to an XML file. They become the defaults when the user imports the XMl file. Basically, you create the defaults yourself when you have saved all the basic settings and export them.

  3. thelumberjack
    Member
    Posted 1 year ago #

    I know I'm a little bit late to the party, but I thought I'd drop in some code that may prove handy for anybody looking for a way to set actual default values on their options.

    So here is how to display an option in your template (I'm using a Twitter account as the option for this example):

    if ( function_exists( 'get_option_tree' ) ) {
        get_option_tree( 'twitter', '', true );
    }

    To display a default value, simple drop this line of code underneath and edit accordingly:

    [EDIT] Hold that thought. I found an error in my code.

    Now, if a value is not set, it will default to "th3lumberjack". Hopefully somebody out there finds this useful.

    : )

  4. thelumberjack
    Member
    Posted 1 year ago #

    Try this instead:

    $otest = get_option_tree( 'twitter' );
    
    if ($otest == "") {
        echo("th3lumberjack");
    }

    $otest is simply a variable for testing the result.

  5. Flaunt Books
    Member
    Posted 1 year ago #

    Another way to achieve greater speed and simplicity is this code below:
    Add this to the functions.php file in your theme:

    if ( function_exists( 'get_option_tree' ) ) {
      $theme_options = $theme_options;
    }
    
    function option_tree_default($val,$default){
    	global theme_options;
    	if($theme_options[$val]){
    		return $theme_options[$val];
    	}else{
    		return $default;
    	}
    }

    Then within you theme you can use it as such:
    echo 'option_tree_default('my_var_value','Default Value');

  6. Flaunt Books
    Member
    Posted 1 year ago #

    I think the important issue behind default values is that the end-user is potentially hazardous to the site operations when they remove important values, insert wrong values, insert improperly formatted values (colors, measurements), etc.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic