devinsays/options-framework-theme

Using sane defaults

devinsays opened this issue · 7 comments

This issue was opened by @justintadlock for the plugin, but applies more to the theme version:
devinsays/options-framework-plugin#200

When a theme is activated that has the options-framework bundled, an option is set for "optionsframework", which is not permitted by the theme review guidelines (.org theme review team). This is more of a legacy from the plugin version so that data could be removed for each of the themes when the plugin was deleted- but shouldn't really be necessary here.

Let's remove it and see if we can maintain backcompat.

See this commit:
b86684e

Instead of setting an value in "optionsframework_option_name", the option name is simply returned. This is a much better way of defining the option name- but also has potential to be a breaking change for users if developers used a different option name than the theme slug and don't update options.php when they pull in a new version of the framework. Will need to send out an e-mail to developers on the mail list and write a post.

The plugin version has not changed yet as that update would be much more problematic for backwards compat.

Sorry about posting in the wrong repo. I didn't realize you had two separate repos.

Based on my reading of the code, it looks good. I'll post this on the TRT mailing list to let everyone know you're working on it.

Example of how to set option name in options.php using this new method:

function optionsframework_option_name() {

    // Change this to use your theme slug
    return 'example-theme-slug';
}

A few people have reported issues with how "of_get_option" works. I just made an update that should fix this in: fdf2e5f

Ideally, moving forward, I people will want to include their own "of_get_option function". Something like:

function of_get_option( $name, $default = false ) {

    // Get theme options
    $options = get_option( 'example-option-name' );

    // Return specific option
    if ( isset( $options[$name] ) ) {
        return $options[$name];
    }
    return $default;
}

I've never liked having to use a custom function for something like this though. Would prefer a core function like "get_serialized_option".

This question was just e-mailed to me. Thought it was worth noting in this ticket and also wanted to remind myself to note it in the announcement post:

I hope you are well. I just wanted to put a short question about the options framework theme and wanted to get your views on it.

Previously I have this code in the theme

function optionsframework_option_name() {
     // This gets the theme name from the stylesheet (lowercase and without spaces)
     $themename = get_option( 'stylesheet' );
     $themename = preg_replace("/\W/", "_", strtolower($themename) );

     $optionsframework_settings = get_option('optionsframework');
     $optionsframework_settings['id'] = $themename;
     update_option('optionsframework', $optionsframework_settings);
}

Now, in version 1.9 you have asked to do as following

function optionsframework_option_name() {
       // Change this to use your theme slug
       return 'options-framework-theme';
}

Now, if I do this in next version update of my themes and update the framework to latest version.
What would happen to the settings of users who have used the child theme (previously), as the options id(slug) previously in their database would be child-theme-name and it would be parent theme name now after updating to the new version.

Does this mean their settings would be lost?

Thank you for any views that you share on this.

If that original method was used, settings would indeed be altered for a child theme. This can be used instead to maintain continuity:

function optionsframework_option_name() {
       $themename = get_option( 'stylesheet' );
       $themename = preg_replace( "/\W/", "_", strtolower( $themename ) );
       return $themename;
}

Wrote a post about this update: http://wptheming.com/2014/11/options-framework-theme-v1-9-0/

Latest version of has been tagged 1.9.0.