Skip to content

Commit

Permalink
More work on #75, removing dependency on options.php. Untested, not p…
Browse files Browse the repository at this point in the history
…roduction ready.
  • Loading branch information
devinsays committed Jan 4, 2012
1 parent 182c11b commit df79a40
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
5 changes: 2 additions & 3 deletions options-check/options.php
Expand Up @@ -9,9 +9,8 @@
function optionsframework_option_name() { function optionsframework_option_name() {


// This gets the theme name from the stylesheet (lowercase and without spaces) // This gets the theme name from the stylesheet (lowercase and without spaces)
$themename = get_theme_data(STYLESHEETPATH . '/style.css'); $themename = get_option( 'stylesheet' );
$themename = $themename['Name']; $themename = preg_replace("/\W/", "_", strtolower($themename) );
$themename = preg_replace("/\W/", "", strtolower($themename) );


$optionsframework_settings = get_option('optionsframework'); $optionsframework_settings = get_option('optionsframework');
$optionsframework_settings['id'] = $themename; $optionsframework_settings['id'] = $themename;
Expand Down
50 changes: 34 additions & 16 deletions options-framework.php
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Options Framework Plugin Name: Options Framework
Plugin URI: http://www.wptheming.com Plugin URI: http://www.wptheming.com
Description: A framework for building theme options. Description: A framework for building theme options.
Version: 0.9 Version: 1.0 Beta
Author: Devin Price Author: Devin Price
Author URI: http://www.wptheming.com Author URI: http://www.wptheming.com
License: GPLv2 License: GPLv2
Expand All @@ -27,7 +27,7 @@


/* Basic plugin definitions */ /* Basic plugin definitions */


define('OPTIONS_FRAMEWORK_VERSION', '0.9'); define('OPTIONS_FRAMEWORK_VERSION', '1.0');
define('OPTIONS_FRAMEWORK_URL', plugin_dir_url( __FILE__ )); define('OPTIONS_FRAMEWORK_URL', plugin_dir_url( __FILE__ ));


/* Make sure we don't expose any info if called directly */ /* Make sure we don't expose any info if called directly */
Expand Down Expand Up @@ -116,13 +116,18 @@ function optionsframework_load_sanitization() {
} }


/* /*
* Creates the settings in the database by looping through the array * The optionsframework_init loads all the required files and registers the settings.
* we supplied in options.php. This is a neat way to do it since
* we won't have to save settings for headers, descriptions, or arguments.
* *
* Read more about the Settings API in the WordPress codex: * Read more about the Settings API in the WordPress codex:
* http://codex.wordpress.org/Settings_API * http://codex.wordpress.org/Settings_API
* *
* The theme options are saved using a unique option id in the database. Developers
* traditionally set the option id via in theme using the function
* optionsframework_option_name, but it can also be set using a hook of the same name.
*
* If a theme developer doesn't explictly set the unique option id using one of those
* functions it will be set by default to: optionsframework_[the theme name]
*
*/ */


function optionsframework_init() { function optionsframework_init() {
Expand All @@ -135,19 +140,33 @@ function optionsframework_init() {
$location = apply_filters( 'options_framework_location', array('options.php') ); $location = apply_filters( 'options_framework_location', array('options.php') );
$optionsfile = locate_template( $location ); $optionsfile = locate_template( $location );


// Load settings
$optionsframework_settings = get_option( 'optionsframework' );

// Updates the unique option id in the database if it has changed // Updates the unique option id in the database if it has changed
if ( function_exists( 'optionsframework_option_name' ) ) { if ( function_exists( 'optionsframework_option_name' ) ) {
optionsframework_option_name(); optionsframework_option_name();
} }
do_action( 'optionsframework_option_name' ); elseif ( has_action( 'optionsframework_option_name' ) ) {

do_action( 'optionsframework_option_name' );
// Load settings }
$optionsframework_settings = get_option( 'optionsframework' ); // If the developer hasn't explicitly set an option id, we'll use a default

else {
// Set default name if none is set $default_themename = get_option( 'stylesheet' );
if ( !isset( $optionsframework_settings['id'] ) ) { $default_themename = preg_replace("/\W/", "_", strtolower($default_themename) );
$optionsframework_settings['id'] = 'optionsframework_global_options'; $default_themename = 'optionsframework_' . $default_themename;
update_option( 'optionsframework', $optionsframework_settings ); if ( isset( $optionsframework_settings['id'] ) ) {
if ( $optionsframework_settings['id'] == $default_themename ) {
// All good, using default theme id
} else {
$optionsframework_settings['id'] = $default_themename;
update_option( 'optionsframework', $optionsframework_settings );
}
}
else {
$optionsframework_settings['id'] = $default_themename;
update_option( 'optionsframework', $optionsframework_settings );
}
} }


// If the option has no saved data, load the defaults // If the option has no saved data, load the defaults
Expand Down Expand Up @@ -472,8 +491,7 @@ function of_get_option( $name, $default = false ) {
* *
* @return array (by reference) * @return array (by reference)
*/ */
function &_optionsframework_options() function &_optionsframework_options() {
{
static $options = null; static $options = null;


if (!$options) { if (!$options) {
Expand Down

0 comments on commit df79a40

Please sign in to comment.