Options Framework - Version 1.0

Version Description

  • Added filters for entire options array (props @inxilpro)
  • Added a filter for options.php location (props @mattwiebe)
  • Option header (h4) will not display in panel if name !isset (props @alepee)
Download this release

Release Info

Developer downstairsdev
Plugin Icon wp plugin Options Framework
Version 1.0
Comparing to
See all releases

Code changes from version 0.9 to 1.0

options-check/functions.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * Helper function to return the theme option value. If no value has been saved, it returns $default.
5
+ * Needed because options are saved as serialized strings.
6
+ *
7
+ * This code allows the theme to work without errors if the Options Framework plugin has been disabled.
8
+ */
9
+
10
+ if ( !function_exists( 'of_get_option' ) ) {
11
+ function of_get_option($name, $default = false) {
12
+
13
+ $optionsframework_settings = get_option('optionsframework');
14
+
15
+ // Gets the unique option id
16
+ $option_name = $optionsframework_settings['id'];
17
+
18
+ if ( get_option($option_name) ) {
19
+ $options = get_option($option_name);
20
+ }
21
+
22
+ if ( isset($options[$name]) ) {
23
+ return $options[$name];
24
+ } else {
25
+ return $default;
26
+ }
27
+ }
28
+ }
29
+
30
+ /*
31
+ * This is an example of how to add custom scripts to the options panel.
32
+ * This one shows/hides the an option when a checkbox is clicked.
33
+ */
34
+
35
+ add_action('optionsframework_custom_scripts', 'optionsframework_custom_scripts');
36
+
37
+ function optionsframework_custom_scripts() { ?>
38
+
39
+ <script type="text/javascript">
40
+ jQuery(document).ready(function() {
41
+
42
+ jQuery('#example_showhidden').click(function() {
43
+ jQuery('#section-example_text_hidden').fadeToggle(400);
44
+ });
45
+
46
+ if (jQuery('#example_showhidden:checked').val() !== undefined) {
47
+ jQuery('#section-example_text_hidden').show();
48
+ }
49
+
50
+ });
51
+ </script>
52
+
53
+ <?php
54
+ }
55
+
56
+ /*
57
+ * This is an example of how to override a default filter
58
+ * for 'text' sanitization and use a different one.
59
+ */
60
+
61
+ /*
62
+
63
+ add_action('admin_init','optionscheck_change_santiziation', 100);
64
+
65
+ function optionscheck_change_santiziation() {
66
+ remove_filter( 'of_sanitize_text', 'sanitize_text_field' );
67
+ add_filter( 'of_sanitize_text', 'of_sanitize_text_field' );
68
+ }
69
+
70
+ function of_sanitize_text_field($input) {
71
+ global $allowedtags;
72
+ $output = wp_kses( $input, $allowedtags);
73
+ return $output;
74
+ }
75
+
76
+ */
77
+
78
+ /*
79
+ * This is an example of how to override the default location and name of options.php
80
+ * In this example it has been renamed options-renamed.php and moved into the folder extensions
81
+ */
82
+
83
+ /*
84
+
85
+ add_filter('options_framework_location','options_framework_location_override');
86
+
87
+ function options_framework_location_override() {
88
+ return array('/extensions/options-renamed.php');
89
+ }
90
+
91
+ */
92
+
93
+ /*
94
+ * Turns off the default options panel from Twenty Eleven
95
+ */
96
+
97
+ add_action('after_setup_theme','remove_twentyeleven_options', 100);
98
+
99
+ function remove_twentyeleven_options() {
100
+ remove_action( 'admin_menu', 'twentyeleven_theme_options_add_page' );
101
+ }
options-check/images/1col.png ADDED
Binary file
options-check/images/2cl.png ADDED
Binary file
options-check/images/2cr.png ADDED
Binary file
options-check/index.php ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * The main template file.
4
+ *
5
+ * This theme is purely for the purpose of testing theme options in Options Framework plugin.
6
+ *
7
+ * @package WordPress
8
+ * @subpackage Options Check
9
+ */
10
+
11
+ get_header(); ?>
12
+
13
+ <div id="primary">
14
+ <div id="content" role="main">
15
+
16
+ <article id="post-0" class="post no-results not-found">
17
+ <header class="entry-header">
18
+ <h1 class="entry-title">Options Check</h1>
19
+ </header><!-- .entry-header -->
20
+
21
+ <div class="entry-content">
22
+ <p>Use of_of_get_option($id,$default) to return option values.</p>
23
+
24
+ <h2>Basic Options</h2>
25
+
26
+ <dl>
27
+ <dt>type: text (mini)</dt>
28
+ <dd>of_get_option('example_text_mini'): <?php echo of_get_option('example_text_mini', 'no entry'); ?></dd>
29
+ </dl>
30
+
31
+ <dl>
32
+ <dt>type: text</dt>
33
+ <dd>of_get_option('example_text'): <?php echo of_get_option('example_text', 'no entry'); ?></dd>
34
+ </dl>
35
+
36
+ <dl>
37
+ <dt>type: textarea</dt>
38
+ <dd>of_get_option('example_textarea'): <?php echo of_get_option('example_textarea', 'no entry' ); ?></dd>
39
+ </dl>
40
+
41
+ <dl>
42
+ <dt>type: select (mini)</dt>
43
+ <dd>of_get_option('example_select'): <?php echo of_get_option('example_select', 'no entry' ); ?></dd>
44
+ </dl>
45
+
46
+ <dl>
47
+ <dt>type: select2 (wide)</dt>
48
+ <dd>of_get_option('example_select_wide'): <?php echo of_get_option('example_select_wide', 'no entry' ); ?></dd>
49
+ </dl>
50
+
51
+ <dl>
52
+ <dt>type: select</dt>
53
+ <dd>of_get_option('example_select_categories'): category id = <?php echo of_get_option('example_select_categories', 'no entry' ); ?></dd>
54
+ </dl>
55
+
56
+ <dl>
57
+ <dt>type: select</dt>
58
+ <dd>of_get_option('example_select_pages'): page id = <?php echo of_get_option('example_select_pages', 'no entry' ); ?></dd>
59
+ </dl>
60
+
61
+ <dl>
62
+ <dt>type: radio</dt>
63
+ <dd>of_get_option('example_radio'): <?php echo of_get_option('example_radio', 'no entry' ); ?></dd>
64
+ </dl>
65
+
66
+ <dl>
67
+ <dt>type: checkbox</dt>
68
+ <dd>of_get_option('example_checkbox'): <?php echo of_get_option('example_checkbox', 'no entry' ); ?></dd>
69
+ </dl>
70
+
71
+ <hr/>
72
+
73
+ <h2>Advanced Options</h2>
74
+
75
+ <dl>
76
+ <dt>type: uploader</dt>
77
+ <dd>of_get_option('example_uploader'): <?php echo of_get_option('example_uploader', 'no entry'); ?></dd>
78
+ <?php if ( of_get_option('example_uploader') ) { ?>
79
+ <img src="<?php echo of_get_option('example_uploader'); ?>" />
80
+ <?php } ?>
81
+ </dl>
82
+
83
+ <dl>
84
+ <dt>type: image</dt>
85
+ <dd>of_get_option('images'): <?php echo of_get_option('example_images', 'no entry' ); ?></dd>
86
+ </dl>
87
+
88
+ <dl>
89
+ <dt>type: multicheck</dt>
90
+ <dd>of_get_option('multicheck'):
91
+ <?php $multicheck = of_get_option('example_multicheck', 'none' ); ?>
92
+ <?php print_r($multicheck); ?>
93
+ </dd>
94
+ </dl>
95
+
96
+ <p>The array sent in the options panel was defined as:<br>
97
+ <?php
98
+ $test_array_jr = array("one" => "French Toast","two" => "Pancake","three" => "Omelette","four" => "Crepe","five" => "Waffle");
99
+ print_r($test_array_jr);
100
+ ?>
101
+ </p>
102
+
103
+ <p>You can get the value of all items in the checkbox array:</p>
104
+ <ul>
105
+ <?php
106
+ if ( is_array($multicheck) ) {
107
+ foreach ($multicheck as $key => $value) {
108
+ // If you need the option's name rather than the key you can get that
109
+ $name = $test_array_jr[$key];
110
+ // Prints out each of the values
111
+ echo '<li>' . $key . ' (' . $name . ') = ' . $value . '</li>';
112
+ }
113
+ }
114
+ else {
115
+ echo '<li>There are no saved values yet.</li>';
116
+ }
117
+ ?>
118
+ </ul>
119
+
120
+ <p>You can also get an individual checkbox value if you know what you are looking for. In this example, I'll check for the key "one", which is an item I sent in the array for checkboxes:</p>
121
+
122
+ <p>The value of the multicheck box "one" of example_multicheck is:
123
+ <b>
124
+ <?php
125
+ if (isset($multicheck['one']) ) {
126
+ echo $multicheck['one'];
127
+ } else {
128
+ echo 'no entry';
129
+ }
130
+ ?>
131
+ </b>
132
+ </p>
133
+
134
+
135
+ <dl>
136
+ <dt>type: background</dt>
137
+ <dd>of_get_option('background'):
138
+ <?php $background = of_get_option('example_background');
139
+ if ($background) {
140
+ if ($background['image']) {
141
+ echo '<span style="display: block; height: 200px; width: 200px; background:url('.$background['image']. ') "></span>';
142
+ echo '<ul>';
143
+ foreach ($background as $i=>$param){
144
+ echo '<li>'.$i . ' = ' . $param.'</li>';
145
+ }
146
+ echo '</ul>';
147
+ } else {
148
+ echo '<span style="display: inline-block; height: 20px; width: 20px; background:'.$background['color']. ' "></span>';
149
+ echo '<ul>';
150
+ echo '<li>'.$background['color'].'</li>';
151
+ echo '</ul>';
152
+ }
153
+ } else {
154
+ echo "no entry";
155
+ }; ?>
156
+ </span>
157
+ </dd>
158
+ </dl>
159
+
160
+ <dl>
161
+ <dt>type: colorpicker</dt>
162
+ <dd>of_get_option('colorpicker'):
163
+ <span style="color:<?php echo of_get_option('example_colorpicker', '#000' ); ?>">
164
+ <?php echo of_get_option('example_colorpicker', 'no entry' ); ?>
165
+ </span>
166
+ </dd>
167
+ </dl>
168
+
169
+ <dl>
170
+ <dt>type: typography</dt>
171
+ <dd>of_get_option('typography'):
172
+ <?php $typography = of_get_option('example_typography');
173
+ if ($typography) {
174
+ echo '<span style="font-family: ' . $typography['face']. '; font:'.$typography['size'] . $typography['style'] . '; color:'.$typography['color'].';">Some sample text in your style</span>';
175
+
176
+ echo '<ul>';
177
+ foreach ($typography as $i=>$param) {
178
+ echo '<li>'.$i . ' = ' . $param.'</li>';
179
+ }
180
+ echo '</ul>';
181
+ } else {
182
+ echo "no entry";
183
+ } ?>
184
+ </dd>
185
+ </dl>
186
+
187
+ </div><!-- .entry-content -->
188
+ </article><!-- #post-0 -->
189
+
190
+
191
+ </div><!-- #content -->
192
+ </div><!-- #primary -->
193
+
194
+ <?php get_footer(); ?>
options-check/options.php ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * A unique identifier is defined to store the options in the database and reference them from the theme.
4
+ * By default it uses the theme name, in lowercase and without spaces, but this can be changed if needed.
5
+ * If the identifier changes, it'll appear as if the options have been reset.
6
+ *
7
+ */
8
+
9
+ function optionsframework_option_name() {
10
+
11
+ // This gets the theme name from the stylesheet (lowercase and without spaces)
12
+ $themename = get_option( 'stylesheet' );
13
+ $themename = preg_replace("/\W/", "_", strtolower($themename) );
14
+
15
+ $optionsframework_settings = get_option('optionsframework');
16
+ $optionsframework_settings['id'] = $themename;
17
+ update_option('optionsframework', $optionsframework_settings);
18
+
19
+ // echo $themename;
20
+ }
21
+
22
+ /**
23
+ * Defines an array of options that will be used to generate the settings page and be saved in the database.
24
+ * When creating the "id" fields, make sure to use all lowercase and no spaces.
25
+ *
26
+ */
27
+
28
+ function optionsframework_options() {
29
+
30
+ // Test data
31
+ $test_array = array("one" => "One","two" => "Two","three" => "Three","four" => "Four","five" => "Five");
32
+
33
+ // Multicheck Array
34
+ $multicheck_array = array("one" => "French Toast", "two" => "Pancake", "three" => "Omelette", "four" => "Crepe", "five" => "Waffle");
35
+
36
+ // Multicheck Defaults
37
+ $multicheck_defaults = array("one" => "1","five" => "1");
38
+
39
+ // Background Defaults
40
+
41
+ $background_defaults = array('color' => '', 'image' => '', 'repeat' => 'repeat','position' => 'top center','attachment'=>'scroll');
42
+
43
+
44
+ // Pull all the categories into an array
45
+ $options_categories = array();
46
+ $options_categories_obj = get_categories();
47
+ foreach ($options_categories_obj as $category) {
48
+ $options_categories[$category->cat_ID] = $category->cat_name;
49
+ }
50
+
51
+ // Pull all the pages into an array
52
+ $options_pages = array();
53
+ $options_pages_obj = get_pages('sort_column=post_parent,menu_order');
54
+ $options_pages[''] = 'Select a page:';
55
+ foreach ($options_pages_obj as $page) {
56
+ $options_pages[$page->ID] = $page->post_title;
57
+ }
58
+
59
+ // If using image radio buttons, define a directory path
60
+ $imagepath = get_bloginfo('stylesheet_directory') . '/images/';
61
+
62
+ $options = array();
63
+
64
+ $options[] = array( "name" => "Basic Settings",
65
+ "type" => "heading");
66
+
67
+ $options[] = array( "name" => "Input Text Mini",
68
+ "desc" => "A mini text input field.",
69
+ "id" => "example_text_mini",
70
+ "std" => "Default",
71
+ "class" => "mini",
72
+ "type" => "text");
73
+
74
+ $options[] = array( "name" => "Input Text",
75
+ "desc" => "A text input field.",
76
+ "id" => "example_text",
77
+ "std" => "Default Value",
78
+ "type" => "text");
79
+
80
+ $options[] = array( "name" => "Textarea",
81
+ "desc" => "Textarea description.",
82
+ "id" => "example_textarea",
83
+ "std" => "Default Text",
84
+ "type" => "textarea");
85
+
86
+ $options[] = array( "name" => "Input Select Small",
87
+ "desc" => "Small Select Box.",
88
+ "id" => "example_select",
89
+ "std" => "three",
90
+ "type" => "select",
91
+ "class" => "mini", //mini, tiny, small
92
+ "options" => $test_array);
93
+
94
+ $options[] = array( "name" => "Input Select Wide",
95
+ "desc" => "A wider select box.",
96
+ "id" => "example_select_wide",
97
+ "std" => "two",
98
+ "type" => "select",
99
+ "options" => $test_array);
100
+
101
+ $options[] = array( "name" => "Select a Category",
102
+ "desc" => "Passed an array of categories with cat_ID and cat_name",
103
+ "id" => "example_select_categories",
104
+ "type" => "select",
105
+ "options" => $options_categories);
106
+
107
+ $options[] = array( "name" => "Select a Page",
108
+ "desc" => "Passed an pages with ID and post_title",
109
+ "id" => "example_select_pages",
110
+ "type" => "select",
111
+ "options" => $options_pages);
112
+
113
+ $options[] = array( "name" => "Input Radio (one)",
114
+ "desc" => "Radio select with default options 'one'.",
115
+ "id" => "example_radio",
116
+ "std" => "one",
117
+ "type" => "radio",
118
+ "options" => $test_array);
119
+
120
+ $options[] = array( "name" => "Example Info",
121
+ "desc" => "This is just some example information you can put in the panel.",
122
+ "type" => "info");
123
+
124
+ $options[] = array( "name" => "Input Checkbox",
125
+ "desc" => "Example checkbox, defaults to true.",
126
+ "id" => "example_checkbox",
127
+ "std" => "1",
128
+ "type" => "checkbox");
129
+
130
+ $options[] = array( "name" => "Advanced Settings",
131
+ "type" => "heading");
132
+
133
+ $options[] = array( "name" => "Check to Show a Hidden Text Input",
134
+ "desc" => "Click here and see what happens.",
135
+ "id" => "example_showhidden",
136
+ "type" => "checkbox");
137
+
138
+ $options[] = array( "name" => "Hidden Text Input",
139
+ "desc" => "This option is hidden unless activated by a checkbox click.",
140
+ "id" => "example_text_hidden",
141
+ "std" => "Hello",
142
+ "class" => "hidden",
143
+ "type" => "text");
144
+
145
+ $options[] = array( "name" => "Uploader Test",
146
+ "desc" => "This creates a full size uploader that previews the image.",
147
+ "id" => "example_uploader",
148
+ "type" => "upload");
149
+
150
+ $options[] = array( "name" => "Example Image Selector",
151
+ "desc" => "Images for layout.",
152
+ "id" => "example_images",
153
+ "std" => "2c-l-fixed",
154
+ "type" => "images",
155
+ "options" => array(
156
+ '1col-fixed' => $imagepath . '1col.png',
157
+ '2c-l-fixed' => $imagepath . '2cl.png',
158
+ '2c-r-fixed' => $imagepath . '2cr.png')
159
+ );
160
+
161
+ $options[] = array( "name" => "Example Background",
162
+ "desc" => "Change the background CSS.",
163
+ "id" => "example_background",
164
+ "std" => $background_defaults,
165
+ "type" => "background");
166
+
167
+ $options[] = array( "name" => "Multicheck",
168
+ "desc" => "Multicheck description.",
169
+ "id" => "example_multicheck",
170
+ "std" => $multicheck_defaults, // These items get checked by default
171
+ "type" => "multicheck",
172
+ "options" => $multicheck_array);
173
+
174
+ $options[] = array( "name" => "Colorpicker",
175
+ "desc" => "No color selected by default.",
176
+ "id" => "example_colorpicker",
177
+ "std" => "",
178
+ "type" => "color");
179
+
180
+ $options[] = array( "name" => "Typography",
181
+ "desc" => "Example typography.",
182
+ "id" => "example_typography",
183
+ "std" => array('size' => '12px','face' => 'verdana','style' => 'bold italic','color' => '#123456'),
184
+ "type" => "typography");
185
+ return $options;
186
+ }
options-check/screenshot.png ADDED
Binary file
options-check/style.css ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Theme Name: Options Check
3
+ Theme URI: http://wptheming.com
4
+ Description: A example/test theme to make sure all the options work in the Options Framework plugin.
5
+ Author: Devin Price
6
+ Author URI: http://wptheming.com
7
+ Version: 1.0
8
+ Template: twentyeleven
9
+ */
10
+
11
+ @import url('../twentyeleven/style.css');
12
+
13
+ #branding hgroup, #searchform, #branding img, #access {display:none;}
options-framework.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Options Framework
4
  Plugin URI: http://www.wptheming.com
5
  Description: A framework for building theme options.
6
- Version: 0.9
7
  Author: Devin Price
8
  Author URI: http://www.wptheming.com
9
  License: GPLv2
@@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27
 
28
  /* Basic plugin definitions */
29
 
30
- define('OPTIONS_FRAMEWORK_VERSION', '0.9');
31
  define('OPTIONS_FRAMEWORK_URL', plugin_dir_url( __FILE__ ));
32
 
33
  /* Make sure we don't expose any info if called directly */
@@ -43,15 +43,16 @@ add_action('init', 'optionsframework_rolescheck' );
43
 
44
  function optionsframework_rolescheck () {
45
  if ( current_user_can( 'edit_theme_options' ) ) {
46
- $optionsfile = locate_template( array('options.php') );
47
- if ($optionsfile) {
48
  // If the user can edit theme options, let the fun begin!
49
  add_action( 'admin_menu', 'optionsframework_add_page');
50
  add_action( 'admin_init', 'optionsframework_init' );
51
  add_action( 'admin_init', 'optionsframework_mlu_init' );
 
52
  }
53
  else {
54
- // Display a notice if options.php isn't present in the theme
55
  add_action('admin_notices', 'optionsframework_admin_notice');
56
  add_action('admin_init', 'optionsframework_nag_ignore');
57
  }
@@ -115,13 +116,18 @@ function optionsframework_load_sanitization() {
115
  }
116
 
117
  /*
118
- * Creates the settings in the database by looping through the array
119
- * we supplied in options.php. This is a neat way to do it since
120
- * we won't have to save settings for headers, descriptions, or arguments.
121
  *
122
  * Read more about the Settings API in the WordPress codex:
123
  * http://codex.wordpress.org/Settings_API
124
  *
 
 
 
 
 
 
 
125
  */
126
 
127
  function optionsframework_init() {
@@ -130,32 +136,65 @@ function optionsframework_init() {
130
  require_once dirname( __FILE__ ) . '/options-interface.php';
131
  require_once dirname( __FILE__ ) . '/options-medialibrary-uploader.php';
132
 
133
- // Loads the options array from the theme
134
- $optionsfile = locate_template( array('options.php') );
135
- require_once($optionsfile);
136
 
137
- $optionsframework_settings = get_option('optionsframework' );
 
138
 
139
  // Updates the unique option id in the database if it has changed
140
- optionsframework_option_name();
141
-
142
- // Gets the unique id, returning a default if it isn't defined
143
- if ( isset($optionsframework_settings['id']) ) {
144
- $option_name = $optionsframework_settings['id'];
145
  }
 
146
  else {
147
- $option_name = 'optionsframework';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  }
149
 
150
  // If the option has no saved data, load the defaults
151
- if ( ! get_option($option_name) ) {
152
  optionsframework_setdefaults();
153
  }
154
 
155
  // Registers the settings fields and callback
156
- register_setting( 'optionsframework', $option_name, 'optionsframework_validate' );
 
 
 
 
157
  }
158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  /*
160
  * Adds default options to the database if they aren't already present.
161
  * May update this later to load only on plugin activation, or theme
@@ -195,7 +234,7 @@ function optionsframework_setdefaults() {
195
  }
196
 
197
  // Gets the default options data from the array in options.php
198
- $options = optionsframework_options();
199
 
200
  // If the options haven't been added to the database yet, they are added now
201
  $values = of_get_default_values();
@@ -320,7 +359,7 @@ function optionsframework_validate( $input ) {
320
 
321
  if ( isset( $_POST['update'] ) ) {
322
  $clean = array();
323
- $options = optionsframework_options();
324
  foreach ( $options as $option ) {
325
 
326
  if ( ! isset( $option['id'] ) ) {
@@ -378,7 +417,7 @@ function optionsframework_validate( $input ) {
378
 
379
  function of_get_default_values() {
380
  $output = array();
381
- $config = optionsframework_options();
382
  foreach ( (array) $config as $option ) {
383
  if ( ! isset( $option['id'] ) ) {
384
  continue;
@@ -400,8 +439,6 @@ function of_get_default_values() {
400
  * Add Theme Options menu item to Admin Bar.
401
  */
402
 
403
- add_action( 'wp_before_admin_bar_render', 'optionsframework_adminbar' );
404
-
405
  function optionsframework_adminbar() {
406
 
407
  global $wp_admin_bar;
@@ -439,4 +476,56 @@ if ( ! function_exists( 'of_get_option' ) ) {
439
 
440
  return $default;
441
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
442
  }
3
  Plugin Name: Options Framework
4
  Plugin URI: http://www.wptheming.com
5
  Description: A framework for building theme options.
6
+ Version: 1.0
7
  Author: Devin Price
8
  Author URI: http://www.wptheming.com
9
  License: GPLv2
27
 
28
  /* Basic plugin definitions */
29
 
30
+ define('OPTIONS_FRAMEWORK_VERSION', '1.0');
31
  define('OPTIONS_FRAMEWORK_URL', plugin_dir_url( __FILE__ ));
32
 
33
  /* Make sure we don't expose any info if called directly */
43
 
44
  function optionsframework_rolescheck () {
45
  if ( current_user_can( 'edit_theme_options' ) ) {
46
+ $options =& _optionsframework_options();
47
+ if ( $options ) {
48
  // If the user can edit theme options, let the fun begin!
49
  add_action( 'admin_menu', 'optionsframework_add_page');
50
  add_action( 'admin_init', 'optionsframework_init' );
51
  add_action( 'admin_init', 'optionsframework_mlu_init' );
52
+ add_action( 'wp_before_admin_bar_render', 'optionsframework_adminbar' );
53
  }
54
  else {
55
+ // Display a notice if options aren't present in the theme
56
  add_action('admin_notices', 'optionsframework_admin_notice');
57
  add_action('admin_init', 'optionsframework_nag_ignore');
58
  }
116
  }
117
 
118
  /*
119
+ * The optionsframework_init loads all the required files and registers the settings.
 
 
120
  *
121
  * Read more about the Settings API in the WordPress codex:
122
  * http://codex.wordpress.org/Settings_API
123
  *
124
+ * The theme options are saved using a unique option id in the database. Developers
125
+ * traditionally set the option id via in theme using the function
126
+ * optionsframework_option_name, but it can also be set using a hook of the same name.
127
+ *
128
+ * If a theme developer doesn't explictly set the unique option id using one of those
129
+ * functions it will be set by default to: optionsframework_[the theme name]
130
+ *
131
  */
132
 
133
  function optionsframework_init() {
136
  require_once dirname( __FILE__ ) . '/options-interface.php';
137
  require_once dirname( __FILE__ ) . '/options-medialibrary-uploader.php';
138
 
139
+ // Optionally Loads the options file from the theme
140
+ $location = apply_filters( 'options_framework_location', array('options.php') );
141
+ $optionsfile = locate_template( $location );
142
 
143
+ // Load settings
144
+ $optionsframework_settings = get_option( 'optionsframework' );
145
 
146
  // Updates the unique option id in the database if it has changed
147
+ if ( function_exists( 'optionsframework_option_name' ) ) {
148
+ optionsframework_option_name();
149
+ }
150
+ elseif ( has_action( 'optionsframework_option_name' ) ) {
151
+ do_action( 'optionsframework_option_name' );
152
  }
153
+ // If the developer hasn't explicitly set an option id, we'll use a default
154
  else {
155
+ $default_themename = get_option( 'stylesheet' );
156
+ $default_themename = preg_replace("/\W/", "_", strtolower($default_themename) );
157
+ $default_themename = 'optionsframework_' . $default_themename;
158
+ if ( isset( $optionsframework_settings['id'] ) ) {
159
+ if ( $optionsframework_settings['id'] == $default_themename ) {
160
+ // All good, using default theme id
161
+ } else {
162
+ $optionsframework_settings['id'] = $default_themename;
163
+ update_option( 'optionsframework', $optionsframework_settings );
164
+ }
165
+ }
166
+ else {
167
+ $optionsframework_settings['id'] = $default_themename;
168
+ update_option( 'optionsframework', $optionsframework_settings );
169
+ }
170
  }
171
 
172
  // If the option has no saved data, load the defaults
173
+ if ( ! get_option( $optionsframework_settings['id'] ) ) {
174
  optionsframework_setdefaults();
175
  }
176
 
177
  // Registers the settings fields and callback
178
+ register_setting( 'optionsframework', $optionsframework_settings['id'], 'optionsframework_validate' );
179
+ // Change the capability required to save the 'optionsframework' options group.
180
+ add_filter( 'option_page_capability_optionsframework', 'optionsframework_page_capability' );
181
+
182
+
183
  }
184
 
185
+ /**
186
+ * Ensures that a user with the 'edit_theme_options' capability can actually set the options
187
+ * See: http://core.trac.wordpress.org/ticket/14365
188
+ *
189
+ * @param string $capability The capability used for the page, which is manage_options by default.
190
+ * @return string The capability to actually use.
191
+ */
192
+
193
+ function optionsframework_page_capability( $capability ) {
194
+ return 'edit_theme_options';
195
+ }
196
+
197
+
198
  /*
199
  * Adds default options to the database if they aren't already present.
200
  * May update this later to load only on plugin activation, or theme
234
  }
235
 
236
  // Gets the default options data from the array in options.php
237
+ $options =& _optionsframework_options();
238
 
239
  // If the options haven't been added to the database yet, they are added now
240
  $values = of_get_default_values();
359
 
360
  if ( isset( $_POST['update'] ) ) {
361
  $clean = array();
362
+ $options =& _optionsframework_options();
363
  foreach ( $options as $option ) {
364
 
365
  if ( ! isset( $option['id'] ) ) {
417
 
418
  function of_get_default_values() {
419
  $output = array();
420
+ $config =& _optionsframework_options();
421
  foreach ( (array) $config as $option ) {
422
  if ( ! isset( $option['id'] ) ) {
423
  continue;
439
  * Add Theme Options menu item to Admin Bar.
440
  */
441
 
 
 
442
  function optionsframework_adminbar() {
443
 
444
  global $wp_admin_bar;
476
 
477
  return $default;
478
  }
479
+ }
480
+
481
+ /**
482
+ * Wrapper for optionsframework_options()
483
+ *
484
+ * Allows for manipulating or setting options via 'of_options' filter
485
+ * For example:
486
+ *
487
+ * <code>
488
+ * add_filter('of_options', function($options) {
489
+ * $options[] = array(
490
+ * 'name' => 'Input Text Mini',
491
+ * 'desc' => 'A mini text input field.',
492
+ * 'id' => 'example_text_mini',
493
+ * 'std' => 'Default',
494
+ * 'class' => 'mini',
495
+ * 'type' => 'text'
496
+ * );
497
+ *
498
+ * return $options;
499
+ * });
500
+ * </code>
501
+ *
502
+ * Also allows for setting options via a return statement in the
503
+ * options.php file. For example (in options.php):
504
+ *
505
+ * <code>
506
+ * return array(...);
507
+ * </code>
508
+ *
509
+ * @return array (by reference)
510
+ */
511
+ function &_optionsframework_options() {
512
+ static $options = null;
513
+
514
+ if (!$options) {
515
+ // Load options from options.php file (if it exists)
516
+ $location = apply_filters( 'options_framework_location', array('options.php') );
517
+ if ( $optionsfile = locate_template( $location ) ) {
518
+ $maybe_options = require_once $optionsfile;
519
+ if (is_array($maybe_options)) {
520
+ $options = $maybe_options;
521
+ } else if (function_exists('optionsframework_options')) {
522
+ $options = optionsframework_options();
523
+ }
524
+ }
525
+
526
+ // Allow setting/manipulating options via filters
527
+ $options = apply_filters('of_options', $options);
528
+ }
529
+
530
+ return $options;
531
  }
options-interface.php CHANGED
@@ -22,7 +22,7 @@ function optionsframework_fields() {
22
  };
23
 
24
  $settings = get_option($option_name);
25
- $options = optionsframework_options();
26
 
27
  $counter = 0;
28
  $menu = '';
@@ -52,7 +52,9 @@ function optionsframework_fields() {
52
  }
53
 
54
  $output .= '<div id="' . esc_attr( $id ) .'" class="' . esc_attr( $class ) . '">'."\n";
55
- $output .= '<h4 class="heading">' . esc_html( $value['name'] ) . '</h4>' . "\n";
 
 
56
  $output .= '<div class="option">' . "\n" . '<div class="controls">' . "\n";
57
  }
58
 
22
  };
23
 
24
  $settings = get_option($option_name);
25
+ $options =& _optionsframework_options();
26
 
27
  $counter = 0;
28
  $menu = '';
52
  }
53
 
54
  $output .= '<div id="' . esc_attr( $id ) .'" class="' . esc_attr( $class ) . '">'."\n";
55
+ if ( isset( $value['name'] ) ) {
56
+ $output .= '<h4 class="heading">' . esc_html( $value['name'] ) . '</h4>' . "\n";
57
+ }
58
  $output .= '<div class="option">' . "\n" . '<div class="controls">' . "\n";
59
  }
60
 
options-sanitize.php CHANGED
@@ -16,7 +16,7 @@ add_filter( 'of_sanitize_textarea', 'of_sanitize_textarea' );
16
 
17
  /* Info */
18
 
19
- add_filter( 'of_sanitize_info', 'of_sanitize_allowedposttags' );
20
 
21
  /* Select */
22
 
@@ -34,9 +34,9 @@ add_filter( 'of_sanitize_images', 'of_sanitize_enum', 10, 2);
34
 
35
  function of_sanitize_checkbox( $input ) {
36
  if ( $input ) {
37
- $output = "1";
38
  } else {
39
- $output = "0";
40
  }
41
  return $output;
42
  }
@@ -84,8 +84,6 @@ function of_sanitize_allowedtags($input) {
84
  return $output;
85
  }
86
 
87
- add_filter( 'of_sanitize_info', 'of_sanitize_allowedtags' );
88
-
89
  /* Allowed Post Tags */
90
 
91
  function of_sanitize_allowedposttags($input) {
16
 
17
  /* Info */
18
 
19
+
20
 
21
  /* Select */
22
 
34
 
35
  function of_sanitize_checkbox( $input ) {
36
  if ( $input ) {
37
+ $output = '1';
38
  } else {
39
+ $output = '0';
40
  }
41
  return $output;
42
  }
84
  return $output;
85
  }
86
 
 
 
87
  /* Allowed Post Tags */
88
 
89
  function of_sanitize_allowedposttags($input) {
readme.txt CHANGED
@@ -3,17 +3,31 @@ Contributors: Devin Price
3
  Tags: options, theme options
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=X238BDP4QGTV2
5
  Requires at least: 3.0
6
- Tested up to: 3.2
7
- Stable tag: 0.9
8
  License: GPLv2
9
 
10
  == Description ==
11
 
12
- The Options Framework Plugin makes it easy to include an options panel in any WordPress theme. It was built so that theme developers can concentrate on making the actual theme rather than spending a ton of time on creating an options panel from scratch. It's free to use in both commercial and personal projects, just like WordPress itself.
13
 
14
- Please visit [http://wptheming.com/options-framework-plugin](http://wptheming.com/options-framework-plugin) for a full description of how to define and use the theme options.
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- The code was originally based on the [WooFramework](http://www.woothemes.com/) and their option styles.
 
 
17
 
18
  == Installation ==
19
 
@@ -33,12 +47,12 @@ You can also watch the video screencast I have at [http://wptheming.com/options-
33
 
34
  = What options are available to use? =
35
 
36
- * text
37
  * textarea
38
  * checkbox
39
  * select
40
- * radio
41
- * upload (an image uploader)
42
  * images (use images instead of radio buttons)
43
  * background (a set of options to define a background)
44
  * multicheck
@@ -51,6 +65,12 @@ You can also watch the video screencast I have at [http://wptheming.com/options-
51
 
52
  == Changelog ==
53
 
 
 
 
 
 
 
54
  = 0.9 =
55
 
56
  * Load thickbox using site_url() to allow for https (props @samargulies)
3
  Tags: options, theme options
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=X238BDP4QGTV2
5
  Requires at least: 3.0
6
+ Tested up to: 3.3
7
+ Stable tag: 1.0
8
  License: GPLv2
9
 
10
  == Description ==
11
 
12
+ The Options Framework Plugin makes it easy to include an options panel in any WordPress theme. It was built so developers can concentrate on making the actual theme rather than spending time creating an options panel from scratch. It's free to use in both commercial and personal projects, just like WordPress itself.
13
 
14
+ = Options Include =
15
+
16
+ * text input
17
+ * textarea
18
+ * checkbox
19
+ * select
20
+ * radio button
21
+ * upload (image uploader)
22
+ * images (use images instead of radio buttons)
23
+ * background (a set of options to define a background)
24
+ * multicheck
25
+ * color (a jquery color picker)
26
+ * typography (a set of options to define typography)
27
 
28
+ = Learn More =
29
+
30
+ Please visit [http://wptheming.com/options-framework-plugin](http://wptheming.com/options-framework-plugin) for a full description of how to define and use the theme options.
31
 
32
  == Installation ==
33
 
47
 
48
  = What options are available to use? =
49
 
50
+ * text input
51
  * textarea
52
  * checkbox
53
  * select
54
+ * radio button
55
+ * upload (image uploader)
56
  * images (use images instead of radio buttons)
57
  * background (a set of options to define a background)
58
  * multicheck
65
 
66
  == Changelog ==
67
 
68
+ = 1.0 =
69
+
70
+ * Added filters for entire options array (props @inxilpro)
71
+ * Added a filter for options.php location (props @mattwiebe)
72
+ * Option header (h4) will not display in panel if name !isset (props @alepee)
73
+
74
  = 0.9 =
75
 
76
  * Load thickbox using site_url() to allow for https (props @samargulies)