Options Framework - Version 0.4

Version Description

  • Updated multicheck option to save keys rather than values
  • Unset default array options after each output in optionsframework_setdefaults
Download this release

Release Info

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

Code changes from version 0.3 to 0.4

Files changed (3) hide show
  1. options-framework.php +5 -5
  2. options-interface.php +29 -32
  3. readme.txt +16 -11
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.3
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.3');
31
  define('OPTIONS_FRAMEWORK_URL', plugin_dir_url( __FILE__ ));
32
 
33
  /* Make sure we don't expose any info if called directly */
@@ -173,6 +173,7 @@ function optionsframework_setdefaults() {
173
  $optionarray[$key] = wp_filter_post_kses($value);
174
  }
175
  $values[$option_id] = $optionarray;
 
176
  }
177
  } else {
178
  $value = '';
@@ -375,10 +376,9 @@ function optionsframework_validate($input) {
375
 
376
  // If it's a multicheck
377
  case ($option['type'] == 'multicheck'):
378
- $i = 0;
379
- foreach ($option['options'] as $key ) {
380
  // Make sure the key is lowercase and without spaces
381
- $key = ereg_replace("[^A-Za-z0-9]", "", strtolower($key));
382
  // Check that the option isn't null
383
  if (!empty($input[($option['id']. '_' . $key)])) {
384
  // If it's not null, make sure it's true, add it to an array
3
  Plugin Name: Options Framework
4
  Plugin URI: http://www.wptheming.com
5
  Description: A framework for building theme options.
6
+ Version: 0.4
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', '0.4');
31
  define('OPTIONS_FRAMEWORK_URL', plugin_dir_url( __FILE__ ));
32
 
33
  /* Make sure we don't expose any info if called directly */
173
  $optionarray[$key] = wp_filter_post_kses($value);
174
  }
175
  $values[$option_id] = $optionarray;
176
+ unset($optionarray);
177
  }
178
  } else {
179
  $value = '';
376
 
377
  // If it's a multicheck
378
  case ($option['type'] == 'multicheck'):
379
+ foreach ($option['options'] as $key => $option_name ) {
 
380
  // Make sure the key is lowercase and without spaces
381
+ $key = preg_replace("[^A-Za-z0-9_]", "", strtolower($key));
382
  // Check that the option isn't null
383
  if (!empty($input[($option['id']. '_' . $key)])) {
384
  // If it's not null, make sure it's true, add it to an array
options-interface.php CHANGED
@@ -22,6 +22,7 @@ function optionsframework_fields() {
22
  $counter = 0;
23
  $menu = '';
24
  $output = '';
 
25
  foreach ($options as $value) {
26
 
27
  $counter++;
@@ -120,25 +121,18 @@ function optionsframework_fields() {
120
  // Multicheck
121
  case "multicheck":
122
  $output .= '<input id="'. $value['id'] .'" type="hidden" name="'.$option_name.'['.$value['id'].']" />';
123
- foreach ($value['options'] as $option) {
124
  $checkbox_name = $option;
125
- $option = ereg_replace("[^A-Za-z0-9]", "", strtolower($option));
126
  $checkbox_id = $option_name.'['.$value['id'].'_'. $option .']';
127
  $checked = '';
128
 
129
- if ( isset($settings[$option]) ) {
130
- $saved_std = $settings[$option];
131
- if ($saved_std == 'true') {
132
- $checked = 'checked="checked"';
133
- }
134
- }
135
- else {
136
- if ( isset($val[$option]) ) {
137
- if ( $val[$option] == 'true') {
138
  $checked = 'checked="checked"';
139
- }
140
  }
141
- }
 
142
  $output .= '<input id="'. $checkbox_id .'" class="checkbox of-input" type="checkbox" name="'. $checkbox_id .'" value="true" '. $checked .' /><label for="'. $option .'">'. $checkbox_name .'</label><br />';
143
  }
144
  break;
@@ -181,20 +175,21 @@ function optionsframework_fields() {
181
  'palatino'=>'Palatino',
182
  'helvetica'=>'Helvetica*' );
183
 
184
- foreach ($faces as $i=>$face) {
185
- $output .= '<option value="'. $i .'" ' . selected($typography_stored['face'], $i, false) . '>'. $face .'</option>';
186
  }
187
  $output .= '</select>';
188
 
189
  // Font Weight
190
  $output .= '<select class="of-typography of-typography-style" name="'.$option_name.'['.$value['id'].'_style]" id="'. $value['id'].'_style">';
 
191
  $styles = array('normal'=>'Normal',
192
  'italic'=>'Italic',
193
  'bold'=>'Bold',
194
  'bold italic'=>'Bold Italic');
195
 
196
- foreach ($styles as $i=>$style) {
197
- $output .= '<option value="'. $i .'" ' . selected($typography_stored['style'], $i, false) . '>'. $style .'</option>';
198
  }
199
  $output .= '</select>';
200
 
@@ -210,32 +205,33 @@ function optionsframework_fields() {
210
  //Set main option
211
  $output .= '<input id="'. $value['id'] .'" type="hidden" name="'.$option_name.'['.$value['id'].']" />';
212
 
213
- $background_stored = $val;
214
 
215
  // Background Color
216
- if (!isset($background_stored['color'])) {
217
- $background_stored['color'] = '';
218
  }
219
 
220
- $output .= '<div id="' . $value['id'] . '_color_picker" class="colorSelector"><div style="background-color:'.$background_stored['color'].'"></div></div>';
221
- $output .= '<input class="of-color of-background of-background-color" name="'.$option_name.'['.$value['id'].'_color]" id="'. $value['id'] .'_color" type="text" value="'. $background_stored['color'] .'" />';
 
222
 
223
 
224
  // Background Image - New AJAX Uploader using Media Library
225
- if (!isset($background_stored['image'])) {
226
- $background_stored['image'] = '';
227
  }
228
 
229
- $output .= optionsframework_medialibrary_uploader( $value['id'] . '_image', $background_stored['image'], null );
230
- if ($background_stored['image']=='') {$hide = ' hide ';} else { $hide=''; }
231
  $output .= '<div class="of-background-properties' . $hide . '">';
232
 
233
  // Background Repeat
234
  $output .= '<select class="of-background of-background-repeat" name="'.$option_name.'['.$value['id'].'_repeat]" id="'. $value['id'].'_repeat">';
235
  $repeats = array("no-repeat"=>"No Repeat","repeat-x"=>"Repeat Horizontally","repeat-y"=>"Repeat Vertically","repeat"=>"Repeat All");
236
 
237
- foreach ($repeats as $i=>$repeat) {
238
- $output .= '<option value="'. $i .'" ' . selected($background_stored['repeat'], $i, false) . '>'. $repeat .'</option>';
239
  }
240
  $output .= '</select>';
241
 
@@ -243,16 +239,17 @@ function optionsframework_fields() {
243
  $output .= '<select class="of-background of-background-position" name="'.$option_name.'['.$value['id'].'_position]" id="'. $value['id'].'_position">';
244
  $positions = array("top left"=>"Top Left","top center"=>"Top Center","top right"=>"Top Right","center left"=>"Middle Left","center center"=>"Middle Center","center right"=>"Middle Right","bottom left"=>"Bottom Left","bottom center"=>"Bottom Center","bottom right"=>"Bottom Right");
245
 
246
- foreach ($positions as $i=>$position) {
247
- $output .= '<option value="'. $i .'" ' . selected($background_stored['position'], $i, false) . '>'. $position .'</option>';
248
  }
249
  $output .= '</select>';
250
 
251
  // Background Attachment
252
  $output .= '<select class="of-background of-background-attachment" name="'.$option_name.'['.$value['id'].'_attachment]" id="'. $value['id'].'_attachment">';
253
  $attachments = array("scroll"=>"Scroll Normally","fixed"=>"Fixed in Place");
254
- foreach ($attachments as $i=>$attachment) {
255
- $output .= '<option value="'. $i .'" ' . selected($background_stored['attachment'], $i, false) . '>'. $attachment .'</option>';
 
256
  }
257
  $output .= '</select>';
258
  $output .= '</div>';
22
  $counter = 0;
23
  $menu = '';
24
  $output = '';
25
+
26
  foreach ($options as $value) {
27
 
28
  $counter++;
121
  // Multicheck
122
  case "multicheck":
123
  $output .= '<input id="'. $value['id'] .'" type="hidden" name="'.$option_name.'['.$value['id'].']" />';
124
+ foreach ($value['options'] as $key => $option) {
125
  $checkbox_name = $option;
126
+ $option = preg_replace("[^A-Za-z0-9_]", "", strtolower($key));
127
  $checkbox_id = $option_name.'['.$value['id'].'_'. $option .']';
128
  $checked = '';
129
 
130
+ if ( isset($val[$option]) ) {
131
+ if ( $val[$option] == 'true') {
 
 
 
 
 
 
 
132
  $checked = 'checked="checked"';
 
133
  }
134
+ }
135
+
136
  $output .= '<input id="'. $checkbox_id .'" class="checkbox of-input" type="checkbox" name="'. $checkbox_id .'" value="true" '. $checked .' /><label for="'. $option .'">'. $checkbox_name .'</label><br />';
137
  }
138
  break;
175
  'palatino'=>'Palatino',
176
  'helvetica'=>'Helvetica*' );
177
 
178
+ foreach ($faces as $key => $face) {
179
+ $output .= '<option value="'. $key .'" ' . selected($typography_stored['face'], $key, false) . '>'. $face .'</option>';
180
  }
181
  $output .= '</select>';
182
 
183
  // Font Weight
184
  $output .= '<select class="of-typography of-typography-style" name="'.$option_name.'['.$value['id'].'_style]" id="'. $value['id'].'_style">';
185
+
186
  $styles = array('normal'=>'Normal',
187
  'italic'=>'Italic',
188
  'bold'=>'Bold',
189
  'bold italic'=>'Bold Italic');
190
 
191
+ foreach ($styles as $key => $style) {
192
+ $output .= '<option value="'. $key .'" ' . selected($typography_stored['style'], $key, false) . '>'. $style .'</option>';
193
  }
194
  $output .= '</select>';
195
 
205
  //Set main option
206
  $output .= '<input id="'. $value['id'] .'" type="hidden" name="'.$option_name.'['.$value['id'].']" />';
207
 
208
+ $background = $val;
209
 
210
  // Background Color
211
+ if (!isset($background['color'])) {
212
+ $background['color'] = '';
213
  }
214
 
215
+ $output .= '<div id="' . $value['id'] . '_color_picker" class="colorSelector"><div style="background-color:'.$background['color'].'"></div></div>';
216
+
217
+ $output .= '<input class="of-color of-background of-background-color" name="'.$option_name.'['.$value['id'].'_color]" id="'. $value['id'] .'_color" type="text" value="'. $background['color'] .'" />';
218
 
219
 
220
  // Background Image - New AJAX Uploader using Media Library
221
+ if (!isset($background['image'])) {
222
+ $background['image'] = '';
223
  }
224
 
225
+ $output .= optionsframework_medialibrary_uploader( $value['id'] . '_image', $background['image'], null );
226
+ if ($background['image'] == '') {$hide = ' hide ';} else { $hide=''; }
227
  $output .= '<div class="of-background-properties' . $hide . '">';
228
 
229
  // Background Repeat
230
  $output .= '<select class="of-background of-background-repeat" name="'.$option_name.'['.$value['id'].'_repeat]" id="'. $value['id'].'_repeat">';
231
  $repeats = array("no-repeat"=>"No Repeat","repeat-x"=>"Repeat Horizontally","repeat-y"=>"Repeat Vertically","repeat"=>"Repeat All");
232
 
233
+ foreach ($repeats as $key => $repeat) {
234
+ $output .= '<option value="'. $key .'" ' . selected($background['repeat'], $key, false) . '>'. $repeat .'</option>';
235
  }
236
  $output .= '</select>';
237
 
239
  $output .= '<select class="of-background of-background-position" name="'.$option_name.'['.$value['id'].'_position]" id="'. $value['id'].'_position">';
240
  $positions = array("top left"=>"Top Left","top center"=>"Top Center","top right"=>"Top Right","center left"=>"Middle Left","center center"=>"Middle Center","center right"=>"Middle Right","bottom left"=>"Bottom Left","bottom center"=>"Bottom Center","bottom right"=>"Bottom Right");
241
 
242
+ foreach ($positions as $key=>$position) {
243
+ $output .= '<option value="'. $key .'" ' . selected($background['position'], $key, false) . '>'. $position .'</option>';
244
  }
245
  $output .= '</select>';
246
 
247
  // Background Attachment
248
  $output .= '<select class="of-background of-background-attachment" name="'.$option_name.'['.$value['id'].'_attachment]" id="'. $value['id'].'_attachment">';
249
  $attachments = array("scroll"=>"Scroll Normally","fixed"=>"Fixed in Place");
250
+
251
+ foreach ($attachments as $key => $attachment) {
252
+ $output .= '<option value="'. $key .'" ' . selected($background['attachment'], $key, false) . '>'. $attachment .'</option>';
253
  }
254
  $output .= '</select>';
255
  $output .= '</div>';
readme.txt CHANGED
@@ -34,17 +34,17 @@ You can also watch the video screencast I have at [http://wptheming.com/options-
34
 
35
  = What options are available to use? =
36
 
37
- text
38
- textarea
39
- checkbox
40
- select
41
- radio
42
- upload (an image uploader)
43
- images (use images instead of radio buttons)
44
- background (a set of options to define a background)
45
- multicheck
46
- color (a jquery color picker)
47
- typography (a set of options to define typography)
48
 
49
  == Screenshots ==
50
 
@@ -52,6 +52,11 @@ typography (a set of options to define typography)
52
 
53
  == Changelog ==
54
 
 
 
 
 
 
55
  = 0.3 =
56
 
57
  * White listed options for increased security
34
 
35
  = What options are available to use? =
36
 
37
+ * text
38
+ * textarea
39
+ * checkbox
40
+ * select
41
+ * radio
42
+ * upload (an image uploader)
43
+ * images (use images instead of radio buttons)
44
+ * background (a set of options to define a background)
45
+ * multicheck
46
+ * color (a jquery color picker)
47
+ * typography (a set of options to define typography)
48
 
49
  == Screenshots ==
50
 
52
 
53
  == Changelog ==
54
 
55
+ = 0.4 =
56
+
57
+ * Updated multicheck option to save keys rather than values
58
+ * Unset default array options after each output in optionsframework_setdefaults
59
+
60
  = 0.3 =
61
 
62
  * White listed options for increased security