devinsays/options-framework-plugin — pull request #78 by inxilpro (2011-11-02 13:40:51+00:00)
Title: Removed dependency on options.php

I've modified the framework to not depend on options.php, and more importantly, to not depend on global functions. I take an OOP approach to theme code, and those two mandatory global functions (`optionsframework_option_name()` and `optionsframework_options()`) were constantly bugging me. I also found that they made it difficult to manipulate the options of a parent theme in a child theme.

So I made two changes:

### More flexibility in setting options

I've added two new ways to set options:

1. Returning an array() in options.php
2. Adding a filter on 'of_options'

The main advantage of using a filter is that this provides more granular control over options. For example, a child theme could add its own options in addition to the parent theme's options using this method. It also means that options can be set anywhere in your project. For example:

_In parent theme:_

```php
add_filter('of_options', function($options) {
$options[] = array(
'name' => 'Input Text Mini',
'desc' => 'A mini text input field.',
'id' => 'example_text_mini',
'std' => 'Default',
'class' => 'mini',
'type' => 'text'
);

return $options;
});
```

_In child theme:_

```php
add_filter('of_options', function($options) {
$options[] = array(
'name' => 'Another Text Field',
'desc' => 'This is a second text field, added in the child theme.',
'id' => 'example_text2',
'type' => 'text'
);

return $options;
});
```

And in the end your options will contain both fields.

### Made optionsframework_option_name() optional

The option name can now be set using the Wordpress action `optionsframework_option_name` rather than requiring the `optionsframework_option_name()` function. If no name is set, the plugin defaults to __optionsframework_global_options__. Obviously most themes are going to want to override this behavior using the action, but it's there if not. `optionsframework_option_name()` still works, but it's now optional.