Options Framework - Version 0.6

Version Description

  • Introduces validation filters
  • Better data sanitization and escaping
  • Updates labels in options-interface.php
  • Changes how checkboxes saved in database ("0" or "1")
  • Stores typography, backgrounds and multichecks directly as arrays
  • For full description, see: http://wptheming.com/2011/05/options-framework-0-6/
Download this release

Release Info

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

Code changes from version 0.5 to 0.6

js/of-medialibrary-uploader.js CHANGED
@@ -64,29 +64,36 @@
64
 
65
  $( 'input.upload_button' ).removeAttr('style');
66
 
67
- var formfield,
68
- formID,
69
- btnContent = true;
70
- // On Click
71
- $('input.upload_button').live("click", function () {
 
72
  formfield = $(this).prev('input').attr('id');
73
  formID = $(this).attr('rel');
 
 
 
74
 
75
  // Display a custom title for each Thickbox popup.
76
  var woo_title = '';
77
 
78
- if ( $(this).parents('.section').find('.heading') ) { woo_title = $(this).parents('.section').find('.heading').text(); } // End IF Statement
79
 
80
- tb_show( woo_title, 'media-upload.php?post_id='+formID+'&TB_iframe=1' );
81
- return false;
82
- });
83
 
84
- window.original_send_to_editor = window.send_to_editor;
85
- window.send_to_editor = function(html) {
86
 
87
- if (formfield) {
 
 
 
88
 
89
- // itemurl = $(html).attr('href'); // Use the URL to the main image.
90
 
91
  if ( $(html).html(html).find('img').length > 0 ) {
92
 
@@ -96,9 +103,8 @@
96
 
97
  // It's not an image. Get the URL to the file instead.
98
 
99
- var htmlBits = html.split("'"); // jQuery seems to strip out XHTML when assigning the string to an object. Use alternate method.
100
-
101
- itemurl = htmlBits[1]; // Use the URL to the file.
102
 
103
  var itemtitle = htmlBits[2];
104
 
64
 
65
  $( 'input.upload_button' ).removeAttr('style');
66
 
67
+ var formfield,
68
+ formID,
69
+ btnContent = true,
70
+ tbframe_interval;
71
+ // On Click
72
+ $('input.upload_button').live("click", function () {
73
  formfield = $(this).prev('input').attr('id');
74
  formID = $(this).attr('rel');
75
+
76
+ //Change "insert into post" to "Use this Button"
77
+ tbframe_interval = setInterval(function() {jQuery('#TB_iframeContent').contents().find('.savesend .button').val('Use This Image');}, 2000);
78
 
79
  // Display a custom title for each Thickbox popup.
80
  var woo_title = '';
81
 
82
+ if ( $(this).parents('.section').find('.heading') ) { woo_title = $(this).parents('.section').find('.heading').text(); } // End IF Statement
83
 
84
+ tb_show( woo_title, 'media-upload.php?post_id='+formID+'&TB_iframe=1' );
85
+ return false;
86
+ });
87
 
88
+ window.original_send_to_editor = window.send_to_editor;
89
+ window.send_to_editor = function(html) {
90
 
91
+ if (formfield) {
92
+
93
+ //clear interval for "Use this Button" so button text resets
94
+ clearInterval(tbframe_interval);
95
 
96
+ // itemurl = $(html).attr('href'); // Use the URL to the main image.
97
 
98
  if ( $(html).html(html).find('img').length > 0 ) {
99
 
103
 
104
  // It's not an image. Get the URL to the file instead.
105
 
106
+ var htmlBits = html.split("'"); // jQuery seems to strip out XHTML when assigning the string to an object. Use alternate method.
107
+ itemurl = htmlBits[1]; // Use the URL to the file.
 
108
 
109
  var itemtitle = htmlBits[2];
110
 
js/options-custom.js CHANGED
@@ -6,7 +6,7 @@
6
  jQuery(document).ready(function($) {
7
 
8
  // Fade out the save message
9
- $('#message').delay(1000).fadeOut(1000);
10
 
11
  // Color Picker
12
  $('.colorSelector').each(function(){
@@ -71,13 +71,14 @@ jQuery(document).ready(function($) {
71
  $('.of-radio-img-label').hide();
72
  $('.of-radio-img-img').show();
73
  $('.of-radio-img-radio').hide();
 
74
  $('#of-nav li:first').addClass('current');
75
  $('#of-nav li a').click(function(evt) {
76
- $('#of-nav li').removeClass('current');
77
- $(this).parent().addClass('current');
78
- var clicked_group = $(this).attr('href');
79
- $('.group').hide();
80
- $(clicked_group).fadeIn();
81
- evt.preventDefault();
82
  });
83
  });
6
  jQuery(document).ready(function($) {
7
 
8
  // Fade out the save message
9
+ $('.fade').delay(1000).fadeOut(1000);
10
 
11
  // Color Picker
12
  $('.colorSelector').each(function(){
71
  $('.of-radio-img-label').hide();
72
  $('.of-radio-img-img').show();
73
  $('.of-radio-img-radio').hide();
74
+
75
  $('#of-nav li:first').addClass('current');
76
  $('#of-nav li a').click(function(evt) {
77
+ $('#of-nav li').removeClass('current');
78
+ $(this).parent().addClass('current');
79
+ var clicked_group = $(this).attr('href');
80
+ $('.group').hide();
81
+ $(clicked_group).fadeIn();
82
+ evt.preventDefault();
83
  });
84
  });
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.5
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.4');
31
  define('OPTIONS_FRAMEWORK_URL', plugin_dir_url( __FILE__ ));
32
 
33
  /* Make sure we don't expose any info if called directly */
@@ -90,6 +90,7 @@ function optionsframework_delete_options() {
90
  function optionsframework_init() {
91
 
92
  // Include the required files
 
93
  require_once dirname( __FILE__ ) . '/options-interface.php';
94
  require_once dirname( __FILE__ ) . '/options-medialibrary-uploader.php';
95
 
@@ -244,34 +245,12 @@ function optionsframework_page() {
244
  $themename = get_theme_data(STYLESHEETPATH . '/style.css');
245
  $themename = $themename['Name'];
246
 
247
- $optionsframework_settings = get_option('optionsframework');
248
-
249
- // Display message when options are reset/updated
250
- $message = '';
251
-
252
- if ( isset($optionsframework_settings['message']) ) {
253
- $message = $optionsframework_settings['message'];
254
- }
255
-
256
- if ( $message == 'reset' ) {
257
- $message = __( 'Options reset.' );
258
- }
259
- if ( $message == 'update' ) {
260
- $message = __( 'Options updated.' );
261
- }
262
-
263
- // Sets the option back to null, so the message doesn't display on refresh
264
- $optionsframework_settings['message'] = '';
265
- update_option('optionsframework',$optionsframework_settings)
266
  ?>
267
 
268
  <div class="wrap">
269
  <?php screen_icon( 'themes' ); ?>
270
- <h2><?php _e('Theme Options'); ?></h2>
271
-
272
- <?php if ($message) { ?>
273
- <div id="message" class="updated fade"><p><strong><?php echo $message; ?></strong></p></div>
274
- <?php } ?>
275
 
276
  <div id="of_container">
277
  <form action="options.php" method="post">
@@ -279,7 +258,7 @@ function optionsframework_page() {
279
 
280
  <div id="header">
281
  <div class="logo">
282
- <h2><?php echo $themename; ?></h2>
283
  </div>
284
  <div class="clear"></div>
285
  </div>
@@ -296,12 +275,11 @@ function optionsframework_page() {
296
  <div class="clear"></div>
297
  </div>
298
  <div class="of_admin_bar">
299
- <input type="submit" class="button-primary" name="update" value="<?php _e( 'Save Options' ); ?>" />
300
- </form>
301
-
302
- <input type="submit" class="reset-button button-secondary" name="reset" value="<?php _e('Restore Defaults')?>" onclick="return confirm('Click OK to reset. Any theme settings will be lost!');"/>
303
  </div>
304
  <div class="clear"></div>
 
305
  </div> <!-- / #container -->
306
  </div> <!-- / .wrap -->
307
 
@@ -317,7 +295,6 @@ function optionsframework_page() {
317
  *
318
  */
319
 
320
- if ( !function_exists( 'optionsframework_validate' ) ) {
321
  function optionsframework_validate($input) {
322
 
323
  $optionsframework_settings = get_option('optionsframework');
@@ -326,25 +303,20 @@ function optionsframework_validate($input) {
326
  $option_name = $optionsframework_settings['id'];
327
 
328
  // If the reset button was clicked
329
- if (!empty($_REQUEST['reset'])) {
330
- delete_option($option_name);
331
- $optionsframework_settings['message'] = 'reset';
332
- update_option('optionsframework', $optionsframework_settings);
333
- header('Location: themes.php?page=options-framework');
334
- exit;
335
  }
336
 
337
  else
338
 
339
  {
340
 
341
- if (!empty($_REQUEST['update'])) {
342
 
343
  $clean = array();
344
-
345
- $optionsframework_settings['message'] = 'update';
346
-
347
- update_option('optionsframework', $optionsframework_settings);
348
 
349
  // Get the options array we have defined in options.php
350
  $options = optionsframework_options();
@@ -355,91 +327,24 @@ function optionsframework_validate($input) {
355
  if ( isset ($option['id']) ) {
356
 
357
  // Keep all ids lowercase with no spaces
358
- $option['id'] = preg_replace('/\W/', '', strtolower($option['id']) );
359
 
360
- // Checkbox data isn't sent if it's unchecked, so we'll default it to false
361
- if ( ($option['type'] == 'checkbox') && !isset($input[($option['id'])]) ) {
362
- $input[($option['id'])] = 'false';
363
  }
364
 
365
- // Verify that there's a value in the $input
366
- if (isset ($input[($option['id'])]) ) {
367
-
368
- switch ( $option['type'] ) {
369
-
370
- // If it's a checkbox, make sure it's either true or false
371
- case ($option['type'] == 'checkbox'):
372
- if ( ($input[($option['id'])]) == 'true' )
373
- $clean[($option['id'])] = 'true';
374
- else {
375
- $clean[($option['id'])] = 'false';
376
- }
377
- break;
378
-
379
- // If it's a multicheck
380
- case ($option['type'] == 'multicheck'):
381
- unset($checkboxarray);
382
- foreach ($option['options'] as $key => $option_name ) {
383
- // Make sure the key is lowercase and without spaces
384
- $key = preg_replace('/\W/', '', strtolower($key));
385
- // Check that the option isn't null
386
- if (!empty($input[($option['id']. '_' . $key)])) {
387
- // If it's not null, make sure it's true, add it to an array
388
- $checkboxarray[$key] = 'true';
389
- }
390
- else {
391
- $checkboxarray[$key] = 'false';
392
- }
393
- }
394
- // Take all the items that were checked, and set them as the main option
395
- if (!empty($checkboxarray)) {
396
- $clean[($option['id'])] = $checkboxarray;
397
- }
398
- break;
399
-
400
- // If it's a typography option
401
- case ($option['type'] == 'typography') :
402
- $typography_id = $option['id'];
403
- $clean[$typography_id] = array(
404
- 'size' => $input[$typography_id .'_size'],
405
- 'face' => $input[$typography_id .'_face'],
406
- 'style' => $input[$typography_id .'_style'],
407
- 'color' => $input[$typography_id .'_color']);
408
- break;
409
-
410
- // If it's a background option
411
- case ($option['type'] == 'background') :
412
- $background_id = $option['id'];
413
- if ( empty($input[$background_id .'_color']) ) {
414
- $clean[$background_id .'_color'] = '';
415
- }
416
- if ( empty($input[$background_id .'_image']) ) {
417
- $clean[$background_id .'_image'] = '';
418
- }
419
- $clean[$background_id] = array(
420
- 'color' => $input[$background_id .'_color'],
421
- 'image' => $input[$background_id .'_image'],
422
- 'repeat' => $input[$background_id .'_repeat'],
423
- 'position' => $input[$background_id .'_position'],
424
- 'attachment' => $input[$background_id .'_attachment']);
425
- break;
426
-
427
- // If it's a select make sure it's in the array we supplied
428
- case ($option['type'] == 'select') :
429
- if ( array_key_exists( $input[($option['id'])], $option['options'] ) ) {
430
- $clean[($option['id'])] = $input[($option['id'])];
431
- }
432
- break;
433
-
434
- // For the remaining options, strip any tags that aren't allowed in posts
435
- default:
436
- // Cleans html characters
437
- $input[($option['id'])] = sanitize_text_field($input[($option['id'])]);
438
- // http://codex.wordpress.org/Function_Reference/wp_filter_post_kses
439
- $clean[($option['id'])] = wp_filter_post_kses( $input[($option['id'])] );
440
- }
441
-
442
- } // end switch
443
 
444
  } // end isset $input
445
 
@@ -448,13 +353,13 @@ function optionsframework_validate($input) {
448
  } // end foreach
449
 
450
  if ( isset($clean) ) {
 
451
  return $clean; // Return validated input
452
  }
453
 
454
- } // end $_REQUEST['update']
455
 
456
  }
457
- }
458
 
459
 
460
  /*
@@ -464,7 +369,7 @@ function optionsframework_validate($input) {
464
  */
465
 
466
  if ( !function_exists( 'of_get_option' ) ) {
467
- function of_get_option($name, $default = 'false') {
468
 
469
  $optionsframework_settings = get_option('optionsframework');
470
 
3
  Plugin Name: Options Framework
4
  Plugin URI: http://www.wptheming.com
5
  Description: A framework for building theme options.
6
+ Version: 0.6
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.6');
31
  define('OPTIONS_FRAMEWORK_URL', plugin_dir_url( __FILE__ ));
32
 
33
  /* Make sure we don't expose any info if called directly */
90
  function optionsframework_init() {
91
 
92
  // Include the required files
93
+ require_once dirname( __FILE__ ) . '/options-sanitize.php';
94
  require_once dirname( __FILE__ ) . '/options-interface.php';
95
  require_once dirname( __FILE__ ) . '/options-medialibrary-uploader.php';
96
 
245
  $themename = get_theme_data(STYLESHEETPATH . '/style.css');
246
  $themename = $themename['Name'];
247
 
248
+ settings_errors();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  ?>
250
 
251
  <div class="wrap">
252
  <?php screen_icon( 'themes' ); ?>
253
+ <h2><?php esc_html_e( 'Theme Options' ); ?></h2>
 
 
 
 
254
 
255
  <div id="of_container">
256
  <form action="options.php" method="post">
258
 
259
  <div id="header">
260
  <div class="logo">
261
+ <h2><?php esc_html_e( $themename ); ?></h2>
262
  </div>
263
  <div class="clear"></div>
264
  </div>
275
  <div class="clear"></div>
276
  </div>
277
  <div class="of_admin_bar">
278
+ <input type="submit" class="button-primary" name="update" value="<?php esc_attr_e( 'Save Options' ); ?>" />
279
+ <input type="submit" class="reset-button button-secondary" name="reset" value="<?php esc_attr_e( 'Restore Defaults' ); ?>" onclick="return confirm( '<?php print esc_js( __( 'Click OK to reset. Any theme settings will be lost!' ) ); ?>' );" />
 
 
280
  </div>
281
  <div class="clear"></div>
282
+ </form>
283
  </div> <!-- / #container -->
284
  </div> <!-- / .wrap -->
285
 
295
  *
296
  */
297
 
 
298
  function optionsframework_validate($input) {
299
 
300
  $optionsframework_settings = get_option('optionsframework');
303
  $option_name = $optionsframework_settings['id'];
304
 
305
  // If the reset button was clicked
306
+ if (!empty($_POST['reset'])) {
307
+ // If options are deleted sucessfully update the error message
308
+ if (delete_option($option_name) ) {
309
+ add_settings_error('options-framework', 'restore_defaults', __('Default options restored.'), 'updated fade');
310
+ }
 
311
  }
312
 
313
  else
314
 
315
  {
316
 
317
+ if (!empty($_POST['update'])) {
318
 
319
  $clean = array();
 
 
 
 
320
 
321
  // Get the options array we have defined in options.php
322
  $options = optionsframework_options();
327
  if ( isset ($option['id']) ) {
328
 
329
  // Keep all ids lowercase with no spaces
330
+ $id = preg_replace( '/\W/', '', strtolower( $option['id'] ) );
331
 
332
+ // Set checkbox to false if it wasn't sent in the $_POST
333
+ if ( 'checkbox' == $option['type'] && ! isset( $input[$id] ) ) {
334
+ $input[$id] = "0";
335
  }
336
 
337
+ // Set each item in the multicheck to false if it wasn't sent in the $_POST
338
+ if ( 'multicheck' == $option['type'] && ! isset( $input[$id] ) ) {
339
+ foreach ( $option['options'] as $key => $value ) {
340
+ $input[$id][$key] = "0";
341
+ }
342
+ }
343
+
344
+ // For a value to be submitted to database it must pass through a sanitization filter
345
+ if ( isset ( $input[$id] ) && has_filter('of_sanitize_' . $option['type']) ) {
346
+ $clean[$id] = apply_filters( 'of_sanitize_' . $option['type'], $input[$id], $option );
347
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
348
 
349
  } // end isset $input
350
 
353
  } // end foreach
354
 
355
  if ( isset($clean) ) {
356
+ add_settings_error('options-framework', 'save_options', __('Options saved.'), 'updated fade');
357
  return $clean; // Return validated input
358
  }
359
 
360
+ } // end $_POST['update']
361
 
362
  }
 
363
 
364
 
365
  /*
369
  */
370
 
371
  if ( !function_exists( 'of_get_option' ) ) {
372
+ function of_get_option($name, $default = false) {
373
 
374
  $optionsframework_settings = get_option('optionsframework');
375
 
options-interface.php CHANGED
@@ -6,6 +6,7 @@
6
 
7
  function optionsframework_fields() {
8
 
 
9
  $optionsframework_settings = get_option('optionsframework');
10
 
11
  // Gets the unique option id
@@ -28,21 +29,31 @@ function optionsframework_fields() {
28
  $counter++;
29
  $val = '';
30
  $select_value = '';
 
31
 
32
  // Wrap all options
33
  if ( ($value['type'] != "heading") && ($value['type'] != "info") ) {
34
-
35
  // Keep all ids lowercase with no spaces
36
  $value['id'] = preg_replace('/\W/', '', strtolower($value['id']) );
37
-
38
- $class = ''; if(isset( $value['class'] )) { $class = $value['class']; }
39
- $output .= '<div id="section-' . $value['id'] .'" class="section section-'.$value['type'].' '. $class .'">'."\n";
40
- $output .= '<h3 class="heading">'. $value['name'] .'</h3>'."\n";
41
- $output .= '<div class="option">'."\n" . '<div class="controls">'."\n";
 
 
 
 
 
 
 
 
 
42
  }
43
 
44
  // Set default value to $val
45
- if ( isset($value['std']) ) {
46
  $val = $value['std'];
47
  }
48
 
@@ -61,7 +72,7 @@ function optionsframework_fields() {
61
 
62
  // Basic text input
63
  case 'text':
64
- $output .= '<input id="'. $value['id'] .'" class="of-input" name="'.$option_name.'['.$value['id'].']" type="'. $value['type'] .'" value="'. $val .'" />';
65
  break;
66
 
67
  // Textarea
@@ -78,21 +89,19 @@ function optionsframework_fields() {
78
 
79
  $val = stripslashes( $val );
80
 
81
- $output .= '<textarea id="'. $value['id'] .'" class="of-input" name="'.$option_name.'['.$value['id'].']" cols="'. $cols .'" rows="8">'.$val.'</textarea>';
82
  break;
83
 
84
  // Select Box
85
  case ($value['type'] == 'select'):
86
- $output .= '<select class="of-input" name="'.$option_name.'['.$value['id'].']" id="'. $value['id'] .'">';
87
 
88
  foreach ($value['options'] as $key => $option ) {
89
  $selected = '';
90
  if( $val != '' ) {
91
  if ( $val == $key) { $selected = ' selected="selected"';}
92
  }
93
- $output .= '<option'. $selected .' value="' . $key . '">';
94
- $output .= $option;
95
- $output .= '</option>';
96
  }
97
  $output .= '</select>';
98
  break;
@@ -100,50 +109,58 @@ function optionsframework_fields() {
100
 
101
  // Radio Box
102
  case "radio":
 
103
  foreach ($value['options'] as $key => $option) {
 
 
 
 
 
 
 
 
 
 
104
  $checked = '';
105
- if($val != '') {
106
- if ( $val == $key) { $checked = ' checked'; }
107
- }
108
- $output .= '<input class="of-input of-radio" type="radio" name="'.$option_name.'['.$value['id'].']" value="'. $key .'" '. $checked .' />' . $option .'<br />';
 
 
 
 
 
109
  }
110
  break;
111
 
112
  // Checkbox
113
- case "checkbox":
114
-
115
- $checked = '';
116
-
117
- if ( $val == 'true') {
118
- $checked = 'checked="checked"';
119
- }
120
-
121
- $output .= '<input id="'. $value['id'] .'" class="checkbox of-input" type="checkbox" name="'.$option_name.'['.$value['id'].']" value="true" '. $checked .' />';
122
  break;
123
 
124
  // Multicheck
125
  case "multicheck":
126
- $output .= '<input id="'. $value['id'] .'" type="hidden" name="'.$option_name.'['.$value['id'].']" />';
127
  foreach ($value['options'] as $key => $option) {
128
- $checkbox_name = $option;
129
- $option = preg_replace('/\W/', '', strtolower($key));
130
- $checkbox_id = $option_name.'['.$value['id'].'_'. $option .']';
131
  $checked = '';
132
-
 
 
 
 
 
133
  if ( isset($val[$option]) ) {
134
- if ( $val[$option] == 'true') {
135
- $checked = 'checked="checked"';
136
- }
137
  }
138
-
139
- $output .= '<input id="'. $checkbox_id .'" class="checkbox of-input" type="checkbox" name="'. $checkbox_id .'" value="true" '. $checked .' /><label for="'. $option .'">'. $checkbox_name .'</label><br />';
140
  }
141
  break;
142
 
143
  // Color picker
144
  case "color":
145
- $output .= '<div id="' . $value['id'] . '_picker" class="colorSelector"><div style="background-color:'.$val.'"></div></div>';
146
- $output .= '<input class="of-color" name="'.$option_name.'['.$value['id'].']" id="'. $value['id'] .'" type="text" value="'. $val .'" />';
147
  break;
148
 
149
  // Uploader
@@ -154,138 +171,114 @@ function optionsframework_fields() {
154
  // Typography
155
  case 'typography':
156
 
157
- // Set main option
158
- $output .= '<input id="'. $value['id'] .'" type="hidden" name="'.$option_name.'['.$value['id'].']" />';
159
  $typography_stored = $val;
160
 
161
  // Font Size
162
- $output .= '<select class="of-typography of-typography-size" name="'.$option_name.'['.$value['id'].'_size]" id="'. $value['id'].'_size">';
163
  for ($i = 9; $i < 71; $i++) {
164
- $size = $i.'px';
165
- if ($typography_stored['size'] == $size) { $selected = ' selected="selected"'; }
166
- $output .= '<option value="'. $i .'px" ' . selected($typography_stored['size'], $size, false) . '>'. $i .'px</option>';
167
  }
168
  $output .= '</select>';
169
 
170
  // Font Face
171
- $output .= '<select class="of-typography of-typography-face" name="'.$option_name.'['.$value['id'].'_face]" id="'. $value['id'].'_face">';
172
- $faces = array('arial'=>'Arial',
173
- 'verdana'=>'Verdana, Geneva',
174
- 'trebuchet'=>'Trebuchet',
175
- 'georgia' =>'Georgia',
176
- 'times'=>'Times New Roman',
177
- 'tahoma'=>'Tahoma, Geneva',
178
- 'palatino'=>'Palatino',
179
- 'helvetica'=>'Helvetica*' );
180
 
181
- foreach ($faces as $key => $face) {
182
- $output .= '<option value="'. $key .'" ' . selected($typography_stored['face'], $key, false) . '>'. $face .'</option>';
 
183
  }
184
- $output .= '</select>';
185
 
 
 
186
  // Font Weight
187
- $output .= '<select class="of-typography of-typography-style" name="'.$option_name.'['.$value['id'].'_style]" id="'. $value['id'].'_style">';
188
-
189
  $styles = array('normal'=>'Normal',
190
  'italic'=>'Italic',
191
  'bold'=>'Bold',
192
  'bold italic'=>'Bold Italic');
193
-
194
  foreach ($styles as $key => $style) {
195
- $output .= '<option value="'. $key .'" ' . selected($typography_stored['style'], $key, false) . '>'. $style .'</option>';
196
  }
197
  $output .= '</select>';
198
-
199
  // Font Color
200
- $output .= '<div id="' . $value['id'] . '_color_picker" class="colorSelector"><div style="background-color:'.$typography_stored['color'].'"></div></div>';
201
- $output .= '<input class="of-color of-typography of-typography-color" name="'.$option_name.'['.$value['id'].'_color]" id="'. $value['id'] .'_color" type="text" value="'. $typography_stored['color'] .'" />';
202
-
203
  break;
204
 
205
  // Background
206
  case 'background':
207
-
208
- //Set main option
209
- $output .= '<input id="'. $value['id'] .'" type="hidden" name="'.$option_name.'['.$value['id'].']" />';
210
 
211
  $background = $val;
212
 
213
- // Background Color
214
- if (!isset($background['color'])) {
215
- $background['color'] = '';
216
- }
217
-
218
- $output .= '<div id="' . $value['id'] . '_color_picker" class="colorSelector"><div style="background-color:'.$background['color'].'"></div></div>';
219
-
220
- $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'] .'" />';
221
-
222
 
223
  // Background Image - New AJAX Uploader using Media Library
224
  if (!isset($background['image'])) {
225
  $background['image'] = '';
226
  }
227
 
228
- $output .= optionsframework_medialibrary_uploader( $value['id'] . '_image', $background['image'], null );
229
- if ($background['image'] == '') {$hide = ' hide ';} else { $hide=''; }
230
- $output .= '<div class="of-background-properties' . $hide . '">';
 
 
 
231
 
232
  // Background Repeat
233
- $output .= '<select class="of-background of-background-repeat" name="'.$option_name.'['.$value['id'].'_repeat]" id="'. $value['id'].'_repeat">';
234
- $repeats = array("no-repeat"=>"No Repeat","repeat-x"=>"Repeat Horizontally","repeat-y"=>"Repeat Vertically","repeat"=>"Repeat All");
235
 
236
  foreach ($repeats as $key => $repeat) {
237
- $output .= '<option value="'. $key .'" ' . selected($background['repeat'], $key, false) . '>'. $repeat .'</option>';
238
  }
239
  $output .= '</select>';
240
 
241
  // Background Position
242
- $output .= '<select class="of-background of-background-position" name="'.$option_name.'['.$value['id'].'_position]" id="'. $value['id'].'_position">';
243
- $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");
244
 
245
  foreach ($positions as $key=>$position) {
246
- $output .= '<option value="'. $key .'" ' . selected($background['position'], $key, false) . '>'. $position .'</option>';
247
  }
248
  $output .= '</select>';
249
 
250
  // Background Attachment
251
- $output .= '<select class="of-background of-background-attachment" name="'.$option_name.'['.$value['id'].'_attachment]" id="'. $value['id'].'_attachment">';
252
- $attachments = array("scroll"=>"Scroll Normally","fixed"=>"Fixed in Place");
253
 
254
  foreach ($attachments as $key => $attachment) {
255
- $output .= '<option value="'. $key .'" ' . selected($background['attachment'], $key, false) . '>'. $attachment .'</option>';
256
  }
257
  $output .= '</select>';
258
  $output .= '</div>';
259
 
260
- break;
261
-
262
- // Image Selectors
263
- case "images":
264
- $i = 0;
265
-
266
- foreach ($value['options'] as $key => $option) {
267
- $i++;
268
- $checked = '';
269
- $selected = '';
270
- if ($val != '') {
271
- if ( $val == $key) { $checked = ' checked'; $selected = 'of-radio-img-selected'; }
272
- }
273
-
274
- $output .= '<span>';
275
- $output .= '<input type="radio" id="of-radio-img-' . $value['id'] . $i . '" class="checkbox of-radio-img-radio" value="'.$key.'" name="'.$option_name.'['.$value['id'].']" '.$checked.' />';
276
- $output .= '<div class="of-radio-img-label">'. $key .'</div>';
277
- $output .= '<img src="'.$option.'" alt="" class="of-radio-img-img '. $selected .'" onClick="document.getElementById(\'of-radio-img-'. $value['id'] . $i.'\').checked = true;" />';
278
- $output .= '</span>';
279
- }
280
- break;
281
 
282
  // Info
283
  case "info":
284
- $class = ''; if(isset( $value['class'] )) { $class = $value['class']; }
285
- $output .= '<div class="section section-'.$value['type'].' '. $class .'">'."\n";
286
- if ( isset($value['name']) ) { $output .= '<h3 class="heading">'. $value['name'] .'</h3>'."\n"; }
287
- if ( $value['desc'] ) { $output .= '<p>'. $value['desc'] .'</p>'."\n"; }
288
- $output .= '<div class="clear"></div></div>'."\n";
 
 
 
 
 
 
 
 
 
 
 
289
  break;
290
 
291
  // Heading for Navigation
@@ -295,19 +288,21 @@ function optionsframework_fields() {
295
  }
296
  $jquery_click_hook = preg_replace('/\W/', '', strtolower($value['name']) );
297
  $jquery_click_hook = "of-option-" . $jquery_click_hook;
298
- $menu .= '<li><a title="'. $value['name'] .'" href="#'. $jquery_click_hook .'">'. $value['name'] .'</a></li>';
299
- $output .= '<div class="group" id="'. $jquery_click_hook .'"><h2>'.$value['name'].'</h2>'."\n";
300
- break;
301
  }
302
-
303
- if ( ($value['type'] != "heading") && ($value['type'] != "info") ) {
304
- if ( $value['type'] != "checkbox" )
305
- {
306
  $output .= '<br/>';
307
- }
308
- if(!isset($value['desc'])){ $explain_value = ''; } else{ $explain_value = $value['desc']; }
309
- $output .= '</div><div class="explain">'. $explain_value .'</div>'."\n";
310
- $output .= '<div class="clear"> </div></div></div>'."\n";
 
 
 
311
  }
312
  }
313
  $output .= '</div>';
6
 
7
  function optionsframework_fields() {
8
 
9
+ global $allowedtags;
10
  $optionsframework_settings = get_option('optionsframework');
11
 
12
  // Gets the unique option id
29
  $counter++;
30
  $val = '';
31
  $select_value = '';
32
+ $checked = '';
33
 
34
  // Wrap all options
35
  if ( ($value['type'] != "heading") && ($value['type'] != "info") ) {
36
+
37
  // Keep all ids lowercase with no spaces
38
  $value['id'] = preg_replace('/\W/', '', strtolower($value['id']) );
39
+
40
+ $id = 'section-' . $value['id'];
41
+
42
+ $class = 'section ';
43
+ if ( isset( $value['type'] ) ) {
44
+ $class .= ' section-' . $value['type'];
45
+ }
46
+ if ( isset( $value['class'] ) ) {
47
+ $class .= ' ' . $value['class'];
48
+ }
49
+
50
+ $output .= '<div id="' . esc_attr( $id ) .'" class="' . esc_attr( $class ) . '">'."\n";
51
+ $output .= '<h3 class="heading">' . esc_html( $value['name'] ) . '</h3>' . "\n";
52
+ $output .= '<div class="option">' . "\n" . '<div class="controls">' . "\n";
53
  }
54
 
55
  // Set default value to $val
56
+ if ( isset( $value['std']) ) {
57
  $val = $value['std'];
58
  }
59
 
72
 
73
  // Basic text input
74
  case 'text':
75
+ $output .= '<input id="' . esc_attr( $value['id'] ) . '" class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" type="text" value="' . esc_attr( $val ) . '" />';
76
  break;
77
 
78
  // Textarea
89
 
90
  $val = stripslashes( $val );
91
 
92
+ $output .= '<textarea id="' . esc_attr( $value['id'] ) . '" class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" cols="'. esc_attr( $cols ) . '" rows="8">' . esc_textarea( $val ) . '</textarea>';
93
  break;
94
 
95
  // Select Box
96
  case ($value['type'] == 'select'):
97
+ $output .= '<select class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" id="' . esc_attr( $value['id'] ) . '">';
98
 
99
  foreach ($value['options'] as $key => $option ) {
100
  $selected = '';
101
  if( $val != '' ) {
102
  if ( $val == $key) { $selected = ' selected="selected"';}
103
  }
104
+ $output .= '<option'. $selected .' value="' . esc_attr( $key ) . '">' . esc_html( $option ) . '</option>';
 
 
105
  }
106
  $output .= '</select>';
107
  break;
109
 
110
  // Radio Box
111
  case "radio":
112
+ $name = $option_name .'['. $value['id'] .']';
113
  foreach ($value['options'] as $key => $option) {
114
+ $id = $option_name . '-' . $value['id'] .'-'. $key;
115
+ $output .= '<input class="of-input of-radio" type="radio" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" value="'. esc_attr( $key ) . '" '. checked( $val, $key, false) .' /><label for="' . esc_attr( $id ) . '">' . esc_html( $option ) . '</label><br />';
116
+ }
117
+ break;
118
+
119
+ // Image Selectors
120
+ case "images":
121
+ $name = $option_name .'['. $value['id'] .']';
122
+ foreach ( $value['options'] as $key => $option ) {
123
+ $selected = '';
124
  $checked = '';
125
+ if ( $val != '' ) {
126
+ if ( $val == $key ) {
127
+ $selected = ' of-radio-img-selected';
128
+ $checked = ' checked="checked"';
129
+ }
130
+ }
131
+ $output .= '<input type="radio" id="' . esc_attr( $value['id'] .'_'. $key) . '" class="of-radio-img-radio" value="' . esc_attr( $key ) . '" name="' . esc_attr( $name ) . '" '. $checked .' />';
132
+ $output .= '<div class="of-radio-img-label">' . esc_html( $key ) . '</div>';
133
+ $output .= '<img src="' . esc_url( $option ) . '" alt="' . $option .'" class="of-radio-img-img' . $selected .'" onclick="document.getElementById(\''. esc_attr($value['id'] .'_'. $key) .'\').checked=true;" />';
134
  }
135
  break;
136
 
137
  // Checkbox
138
+ case "checkbox":
139
+ $output .= '<input id="' . esc_attr( $value['id'] ) . '" class="checkbox of-input" type="checkbox" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" '. checked( $val, 1, false) .' />';
 
 
 
 
 
 
 
140
  break;
141
 
142
  // Multicheck
143
  case "multicheck":
 
144
  foreach ($value['options'] as $key => $option) {
 
 
 
145
  $checked = '';
146
+ $label = $option;
147
+ $option = preg_replace('/\W/', '', strtolower($key));
148
+
149
+ $id = $option_name . '-' . $value['id'] . '-'. $option;
150
+ $name = $option_name . '[' . $value['id'] . '][' . $option .']';
151
+
152
  if ( isset($val[$option]) ) {
153
+ $checked = checked($val[$option], 1, false);
 
 
154
  }
155
+
156
+ $output .= '<input id="' . esc_attr( $id ) . '" class="checkbox of-input" type="checkbox" name="' . esc_attr( $name ) . '" ' . $checked . ' /><label for="' . esc_attr( $id ) . '">' . esc_html( $label ) . '</label><br />';
157
  }
158
  break;
159
 
160
  // Color picker
161
  case "color":
162
+ $output .= '<div id="' . esc_attr( $value['id'] . '_picker' ) . '" class="colorSelector"><div style="' . esc_attr( 'background-color:' . $val ) . '"></div></div>';
163
+ $output .= '<input class="of-color" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" id="' . esc_attr( $value['id'] ) . '" type="text" value="' . esc_attr( $val ) . '" />';
164
  break;
165
 
166
  // Uploader
171
  // Typography
172
  case 'typography':
173
 
 
 
174
  $typography_stored = $val;
175
 
176
  // Font Size
177
+ $output .= '<select class="of-typography of-typography-size" name="' . esc_attr( $option_name . '[' . $value['id'] . '][size]' ) . '" id="' . esc_attr( $value['id'] . '_size' ) . '">';
178
  for ($i = 9; $i < 71; $i++) {
179
+ $size = $i . 'px';
180
+ $output .= '<option value="' . esc_attr( $size ) . '" ' . selected( $typography_stored['size'], $size, false ) . '>' . esc_html( $size ) . '</option>';
 
181
  }
182
  $output .= '</select>';
183
 
184
  // Font Face
185
+ $output .= '<select class="of-typography of-typography-face" name="' . esc_attr( $option_name . '[' . $value['id'] . '][face]' ) . '" id="' . esc_attr( $value['id'] . '_face' ) . '">';
 
 
 
 
 
 
 
 
186
 
187
+ $faces = of_recognized_font_faces();
188
+ foreach ( $faces as $key => $face ) {
189
+ $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $typography_stored['face'], $key, false ) . '>' . esc_html( $face ) . '</option>';
190
  }
 
191
 
192
+ $output .= '</select>';
193
+
194
  // Font Weight
195
+ $output .= '<select class="of-typography of-typography-style" name="'.$option_name.'['.$value['id'].'][style]" id="'. $value['id'].'_style">';
196
+
197
  $styles = array('normal'=>'Normal',
198
  'italic'=>'Italic',
199
  'bold'=>'Bold',
200
  'bold italic'=>'Bold Italic');
201
+
202
  foreach ($styles as $key => $style) {
203
+ $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $typography_stored['style'], $key, false ) . '>'. $style .'</option>';
204
  }
205
  $output .= '</select>';
206
+
207
  // Font Color
208
+ $output .= '<div id="' . esc_attr( $value['id'] ) . '_color_picker" class="colorSelector"><div style="' . esc_attr( 'background-color:' . $typography_stored['color'] ) . '"></div></div>';
209
+ $output .= '<input class="of-color of-typography of-typography-color" name="' . esc_attr( $option_name . '[' . $value['id'] . '][color]' ) . '" id="' . esc_attr( $value['id'] . '_color' ) . '" type="text" value="' . esc_attr( $typography_stored['color'] ) . '" />';
210
+
211
  break;
212
 
213
  // Background
214
  case 'background':
 
 
 
215
 
216
  $background = $val;
217
 
218
+ // Background Color
219
+ $output .= '<div id="' . esc_attr( $value['id'] ) . '_color_picker" class="colorSelector"><div style="' . esc_attr( 'background-color:' . $background['color'] ) . '"></div></div>';
220
+ $output .= '<input class="of-color of-background of-background-color" name="' . esc_attr( $option_name . '[' . $value['id'] . '][color]' ) . '" id="' . esc_attr( $value['id'] . '_color' ) . '" type="text" value="' . esc_attr( $background['color'] ) . '" />';
 
 
 
 
 
 
221
 
222
  // Background Image - New AJAX Uploader using Media Library
223
  if (!isset($background['image'])) {
224
  $background['image'] = '';
225
  }
226
 
227
+ $output .= optionsframework_medialibrary_uploader( $value['id'], $background['image'], null, '',0,'image');
228
+ $class = 'of-background-properties';
229
+ if ( '' == $background['image'] ) {
230
+ $class .= ' hide';
231
+ }
232
+ $output .= '<div class="' . esc_attr( $class ) . '">';
233
 
234
  // Background Repeat
235
+ $output .= '<select class="of-background of-background-repeat" name="' . esc_attr( $option_name . '[' . $value['id'] . '][repeat]' ) . '" id="' . esc_attr( $value['id'] . '_repeat' ) . '">';
236
+ $repeats = of_recognized_background_repeat();
237
 
238
  foreach ($repeats as $key => $repeat) {
239
+ $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['repeat'], $key, false ) . '>'. esc_html( $repeat ) . '</option>';
240
  }
241
  $output .= '</select>';
242
 
243
  // Background Position
244
+ $output .= '<select class="of-background of-background-position" name="' . esc_attr( $option_name . '[' . $value['id'] . '][position]' ) . '" id="' . esc_attr( $value['id'] . '_position' ) . '">';
245
+ $positions = of_recognized_background_position();
246
 
247
  foreach ($positions as $key=>$position) {
248
+ $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['position'], $key, false ) . '>'. esc_html( $position ) . '</option>';
249
  }
250
  $output .= '</select>';
251
 
252
  // Background Attachment
253
+ $output .= '<select class="of-background of-background-attachment" name="' . esc_attr( $option_name . '[' . $value['id'] . '][attachment]' ) . '" id="' . esc_attr( $value['id'] . '_attachment' ) . '">';
254
+ $attachments = of_recognized_background_attachment();
255
 
256
  foreach ($attachments as $key => $attachment) {
257
+ $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['attachment'], $key, false ) . '>' . esc_html( $attachment ) . '</option>';
258
  }
259
  $output .= '</select>';
260
  $output .= '</div>';
261
 
262
+ break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
 
264
  // Info
265
  case "info":
266
+ $class = 'section';
267
+ if ( isset( $value['type'] ) ) {
268
+ $class .= ' section-' . $value['type'];
269
+ }
270
+ if ( isset( $value['class'] ) ) {
271
+ $class .= ' ' . $value['class'];
272
+ }
273
+
274
+ $output .= '<div class="' . esc_attr( $class ) . '">' . "\n";
275
+ if ( isset($value['name']) ) {
276
+ $output .= '<h3 class="heading">' . esc_html( $value['name'] ) . '</h3>' . "\n";
277
+ }
278
+ if ( $value['desc'] ) {
279
+ $output .= '<p>'. wp_kses( $value['desc'], $allowedtags) . '</p>' . "\n";
280
+ }
281
+ $output .= '<div class="clear"></div></div>' . "\n";
282
  break;
283
 
284
  // Heading for Navigation
288
  }
289
  $jquery_click_hook = preg_replace('/\W/', '', strtolower($value['name']) );
290
  $jquery_click_hook = "of-option-" . $jquery_click_hook;
291
+ $menu .= '<li><a title="' . esc_attr( $value['name'] ) . '" href="' . esc_attr( '#'. $jquery_click_hook ) . '">' . esc_html( $value['name'] ) . '</a></li>';
292
+ $output .= '<div class="group" id="' . esc_attr( $jquery_click_hook ) . '"><h2>' . esc_html( $value['name'] ) . '</h2>' . "\n";
293
+ break;
294
  }
295
+
296
+ if ( ( $value['type'] != "heading" ) && ( $value['type'] != "info" ) ) {
297
+ if ( $value['type'] != "checkbox" ) {
 
298
  $output .= '<br/>';
299
+ }
300
+ $explain_value = '';
301
+ if ( isset( $value['desc'] ) ) {
302
+ $explain_value = $value['desc'];
303
+ }
304
+ $output .= '</div><div class="explain">' . wp_kses( $explain_value, $allowedtags) . '</div>'."\n";
305
+ $output .= '<div class="clear"></div></div></div>'."\n";
306
  }
307
  }
308
  $output .= '</div>';
options-medialibrary-uploader.php CHANGED
@@ -93,7 +93,7 @@ if ( ! function_exists( 'optionsframework_mlu_js' ) ) {
93
 
94
  if ( ! function_exists( 'optionsframework_medialibrary_uploader' ) ) {
95
 
96
- function optionsframework_medialibrary_uploader( $_id, $_value, $_mode = 'full', $_desc = '', $_postid = 0 ) {
97
 
98
  $optionsframework_settings = get_option('optionsframework');
99
 
@@ -105,6 +105,7 @@ if ( ! function_exists( 'optionsframework_medialibrary_uploader' ) ) {
105
  $class = '';
106
  $int = '';
107
  $value = '';
 
108
 
109
  $id = strip_tags( strtolower( $_id ) );
110
  // Change for each field, using a "silent" post. If no post is present, one will be created.
@@ -115,8 +116,15 @@ if ( ! function_exists( 'optionsframework_medialibrary_uploader' ) ) {
115
  $value = $_value;
116
  }
117
 
 
 
 
 
 
 
 
118
  if ( $value ) { $class = ' has-file'; }
119
- $output .= '<input id="' . $id . '" class="upload' . $class . '" type="text" name="'.$option_name.'['.$id.']" value="' . $value . '" />' . "\n";
120
  $output .= '<input id="upload_' . $id . '" class="upload_button button" type="button" value="' . __( 'Upload' ) . '" rel="' . $int . '" />' . "\n";
121
 
122
  if ( $_desc != '' ) {
93
 
94
  if ( ! function_exists( 'optionsframework_medialibrary_uploader' ) ) {
95
 
96
+ function optionsframework_medialibrary_uploader( $_id, $_value, $_mode = 'full', $_desc = '', $_postid = 0, $_name = '') {
97
 
98
  $optionsframework_settings = get_option('optionsframework');
99
 
105
  $class = '';
106
  $int = '';
107
  $value = '';
108
+ $name = '';
109
 
110
  $id = strip_tags( strtolower( $_id ) );
111
  // Change for each field, using a "silent" post. If no post is present, one will be created.
116
  $value = $_value;
117
  }
118
 
119
+ if ($_name != '') {
120
+ $name = $option_name.'['.$id.']['.$_name.']';
121
+ }
122
+ else {
123
+ $name = $option_name.'['.$id.']';
124
+ }
125
+
126
  if ( $value ) { $class = ' has-file'; }
127
+ $output .= '<input id="' . $id . '" class="upload' . $class . '" type="text" name="'.$name.'" value="' . $value . '" />' . "\n";
128
  $output .= '<input id="upload_' . $id . '" class="upload_button button" type="button" value="' . __( 'Upload' ) . '" rel="' . $int . '" />' . "\n";
129
 
130
  if ( $_desc != '' ) {
options-sanitize.php ADDED
@@ -0,0 +1,330 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /* Text */
4
+
5
+ add_filter( 'of_sanitize_text', 'sanitize_text_field' );
6
+
7
+ /* Textarea */
8
+
9
+ function of_sanitize_textarea($input) {
10
+ global $allowedtags;
11
+ $output = wp_kses( $input, $allowedtags);
12
+ return $output;
13
+ }
14
+
15
+ add_filter( 'of_sanitize_textarea', 'of_sanitize_textarea' );
16
+
17
+ /* Select */
18
+
19
+ add_filter( 'of_sanitize_select', 'of_sanitize_enum', 10, 2);
20
+
21
+ /* Radio */
22
+
23
+ add_filter( 'of_sanitize_radio', 'of_sanitize_enum', 10, 2);
24
+
25
+ /* Images */
26
+
27
+ add_filter( 'of_sanitize_images', 'of_sanitize_enum', 10, 2);
28
+
29
+ /* Checkbox */
30
+
31
+ function of_sanitize_checkbox( $input ) {
32
+ if ( $input ) {
33
+ $output = "1";
34
+ } else {
35
+ $output = "0";
36
+ }
37
+ return $output;
38
+ }
39
+ add_filter( 'of_sanitize_checkbox', 'of_sanitize_checkbox' );
40
+
41
+ /* Multicheck */
42
+
43
+ function of_sanitize_multicheck( $input, $option ) {
44
+ $output = '';
45
+ if ( is_array( $input ) ) {
46
+ foreach( $option['options'] as $key => $value ) {
47
+ $output[$key] = "0";
48
+ }
49
+ foreach( $input as $key => $value ) {
50
+ if ( array_key_exists( $key, $option['options'] ) && $value ) {
51
+ $output[$key] = "1";
52
+ }
53
+ }
54
+ }
55
+ return $output;
56
+ }
57
+ add_filter( 'of_sanitize_multicheck', 'of_sanitize_multicheck', 10, 2 );
58
+
59
+ /* Color Picker */
60
+
61
+ add_filter( 'of_sanitize_color', 'of_sanitize_hex' );
62
+
63
+ /* Uploader */
64
+
65
+ function of_sanitize_upload( $input ) {
66
+ $output = '';
67
+ $filetype = wp_check_filetype($input);
68
+ if ( $filetype["ext"] ) {
69
+ $output = $input;
70
+ }
71
+ return $output;
72
+ }
73
+ add_filter( 'of_sanitize_upload', 'of_sanitize_upload' );
74
+
75
+ /* Check that the key value sent is valid */
76
+
77
+ function of_sanitize_enum( $input, $option ) {
78
+ $output = '';
79
+ if ( array_key_exists( $input, $option['options'] ) ) {
80
+ $output = $input;
81
+ }
82
+ return $output;
83
+ }
84
+
85
+ /* Background */
86
+
87
+ function of_sanitize_background( $input ) {
88
+ $output = wp_parse_args( $input, array(
89
+ 'color' => '',
90
+ 'image' => '',
91
+ 'repeat' => 'repeat',
92
+ 'position' => 'top center',
93
+ 'attachment' => 'scroll'
94
+ ) );
95
+
96
+ $output['color'] = apply_filters( 'of_sanitize_hex', $input['color'] );
97
+ $output['image'] = apply_filters( 'of_sanitize_upload', $input['image'] );
98
+ $output['repeat'] = apply_filters( 'of_background_repeat', $input['repeat'] );
99
+ $output['position'] = apply_filters( 'of_background_position', $input['position'] );
100
+ $output['attachment'] = apply_filters( 'of_background_attachment', $input['attachment'] );
101
+
102
+ return $output;
103
+ }
104
+ add_filter( 'of_sanitize_background', 'of_sanitize_background' );
105
+
106
+ function of_sanitize_background_repeat( $value ) {
107
+ $recognized = of_recognized_background_repeat();
108
+ if ( array_key_exists( $value, $recognized ) ) {
109
+ return $value;
110
+ }
111
+ return apply_filters( 'of_default_background_repeat', current( $recognized ) );
112
+ }
113
+ add_filter( 'of_background_repeat', 'of_sanitize_background_repeat' );
114
+
115
+ function of_sanitize_background_position( $value ) {
116
+ $recognized = of_recognized_background_position();
117
+ if ( array_key_exists( $value, $recognized ) ) {
118
+ return $value;
119
+ }
120
+ return apply_filters( 'of_default_background_position', current( $recognized ) );
121
+ }
122
+ add_filter( 'of_background_position', 'of_sanitize_background_position' );
123
+
124
+ function of_sanitize_background_attachment( $value ) {
125
+ $recognized = of_recognized_background_attachment();
126
+ if ( array_key_exists( $value, $recognized ) ) {
127
+ return $value;
128
+ }
129
+ return apply_filters( 'of_default_background_attachment', current( $recognized ) );
130
+ }
131
+ add_filter( 'of_background_attachment', 'of_sanitize_background_attachment' );
132
+
133
+
134
+ /* Typography */
135
+
136
+ function of_sanitize_typography( $input ) {
137
+ $output = wp_parse_args( $input, array(
138
+ 'size' => '',
139
+ 'face' => '',
140
+ 'style' => '',
141
+ 'color' => ''
142
+ ) );
143
+
144
+ $output['size'] = apply_filters( 'of_font_size', $output['size'] );
145
+ $output['face'] = apply_filters( 'of_font_face', $output['face'] );
146
+ $output['style'] = apply_filters( 'of_font_style', $output['style'] );
147
+ $output['color'] = apply_filters( 'of_color', $output['color'] );
148
+
149
+ return $output;
150
+ }
151
+ add_filter( 'of_sanitize_typography', 'of_sanitize_typography' );
152
+
153
+
154
+ function of_sanitize_font_size( $value ) {
155
+ $recognized = of_recognized_font_sizes();
156
+ if ( in_array( (int) $value, $recognized ) ) {
157
+ return (int) $value;
158
+ }
159
+ return (int) apply_filters( 'of_default_font_size', $recognized );
160
+ }
161
+ add_filter( 'of_font_face', 'of_sanitize_font_face' );
162
+
163
+
164
+ function of_sanitize_font_style( $value ) {
165
+ $recognized = of_recognized_font_styles();
166
+ if ( array_key_exists( $value, $recognized ) ) {
167
+ return $value;
168
+ }
169
+ return apply_filters( 'of_default_font_style', current( $recognized ) );
170
+ }
171
+ add_filter( 'of_font_style', 'of_sanitize_font_style' );
172
+
173
+
174
+ function of_sanitize_font_face( $value ) {
175
+ $recognized = of_recognized_font_faces();
176
+ if ( array_key_exists( $value, $recognized ) ) {
177
+ return $value;
178
+ }
179
+ return apply_filters( 'of_default_font_face', current( $recognized ) );
180
+ }
181
+ add_filter( 'of_font_face', 'of_sanitize_font_face' );
182
+
183
+ /**
184
+ * Get recognized background repeat settings
185
+ *
186
+ * @return array
187
+ *
188
+ */
189
+ function of_recognized_background_repeat() {
190
+ return array(
191
+ 'none' => 'No Repeat',
192
+ 'repeat-x' => 'Repeat Horizontally',
193
+ 'repeat-y' => 'Repeat Vertically',
194
+ 'repeat' => 'Repeat All',
195
+ );
196
+ }
197
+
198
+ /**
199
+ * Get recognized background positions
200
+ *
201
+ * @return array
202
+ *
203
+ */
204
+ function of_recognized_background_position() {
205
+ return array(
206
+ 'top left' => 'Top Left',
207
+ 'top center' => 'Top Center',
208
+ 'top right' => 'Top Right',
209
+ 'center left' => 'Middle Left',
210
+ 'center center' => 'Middle Center',
211
+ 'center right' => 'Middle Right',
212
+ 'bottom left' => 'Bottom Left',
213
+ 'bottom center' => 'Bottom Center',
214
+ 'bottom right' => 'Bottom Right'
215
+ );
216
+ }
217
+
218
+ /**
219
+ * Get recognized background attachment
220
+ *
221
+ * @return array
222
+ *
223
+ */
224
+ function of_recognized_background_attachment() {
225
+ return array(
226
+ 'scroll' => 'Scroll Normally',
227
+ 'fixed' => 'Fixed in Place'
228
+ );
229
+ }
230
+
231
+ /**
232
+ * Sanitize a color represented in hexidecimal notation.
233
+ *
234
+ * @param string Color in hexidecimal notation. "#" may or may not be prepended to the string.
235
+ * @param string The value that this function should return if it cannot be recognized as a color.
236
+ * @return string
237
+ *
238
+ */
239
+
240
+ function of_sanitize_hex( $hex, $default = '' ) {
241
+ if ( of_validate_hex( $hex ) ) {
242
+ return $hex;
243
+ }
244
+ return $default;
245
+ }
246
+
247
+ /**
248
+ * Get recognized font sizes.
249
+ *
250
+ * Returns an indexed array of all recognized font sizes.
251
+ * Values are integers and represent a range of sizes from
252
+ * smallest to largest.
253
+ *
254
+ * @return array
255
+ */
256
+
257
+ function of_recognized_font_sizes() {
258
+ $sizes = range( 9, 71 );
259
+ $sizes = apply_filters( 'of_recognized_font_sizes', $sizes );
260
+ $sizes = array_map( 'absint', $sizes );
261
+ return $sizes;
262
+ }
263
+
264
+ /**
265
+ * Get recognized font faces.
266
+ *
267
+ * Returns an array of all recognized font faces.
268
+ * Keys are intended to be stored in the database
269
+ * while values are ready for display in in html.
270
+ *
271
+ * @return array
272
+ *
273
+ */
274
+ function of_recognized_font_faces() {
275
+ return array(
276
+ 'arial' => 'Arial',
277
+ 'verdana' => 'Verdana, Geneva',
278
+ 'trebuchet' => 'Trebuchet',
279
+ 'georgia' => 'Georgia',
280
+ 'times' => 'Times New Roman',
281
+ 'tahoma' => 'Tahoma, Geneva',
282
+ 'palatino' => 'Palatino',
283
+ 'helvetica' => 'Helvetica*'
284
+ );
285
+ }
286
+
287
+ /**
288
+ * Get recognized font styles.
289
+ *
290
+ * Returns an array of all recognized font styles.
291
+ * Keys are intended to be stored in the database
292
+ * while values are ready for display in in html.
293
+ *
294
+ * @return array
295
+ *
296
+ */
297
+ function of_recognized_font_styles() {
298
+ return array(
299
+ 'normal' => 'Normal',
300
+ 'italic' => 'Italic',
301
+ 'bold' => 'Bold',
302
+ 'bold italic' => 'Bold Italic'
303
+ );
304
+ }
305
+
306
+ /**
307
+ * Is a given string a color formatted in hexidecimal notation?
308
+ *
309
+ * @param string Color in hexidecimal notation. "#" may or may not be prepended to the string.
310
+ * @return bool
311
+ *
312
+ */
313
+
314
+ function of_validate_hex( $hex ) {
315
+ $hex = trim( $hex );
316
+ /* Strip recognized prefixes. */
317
+ if ( 0 === strpos( $hex, '#' ) ) {
318
+ $hex = substr( $hex, 1 );
319
+ }
320
+ elseif ( 0 === strpos( $hex, '%23' ) ) {
321
+ $hex = substr( $hex, 3 );
322
+ }
323
+ /* Regex match. */
324
+ if ( 0 === preg_match( '/^[0-9a-fA-F]{6}$/', $hex ) ) {
325
+ return false;
326
+ }
327
+ else {
328
+ return true;
329
+ }
330
+ }
readme.txt CHANGED
@@ -1,11 +1,10 @@
1
  === Options Framework ===
2
  Contributors: Devin Price
3
  Tags: options, theme options
4
- Donate link:
5
- https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=X238BDP4QGTV2
6
  Requires at least: 3.0
7
  Tested up to: 3.1
8
- Stable tag: 0.5
9
  License: GPLv2
10
 
11
  == Description ==
@@ -52,6 +51,15 @@ You can also watch the video screencast I have at [http://wptheming.com/options-
52
 
53
  == Changelog ==
54
 
 
 
 
 
 
 
 
 
 
55
  = 0.5 =
56
 
57
  * Fixed errors when more than one multicheck options is used
1
  === Options Framework ===
2
  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.1
7
+ Stable tag: 0.6
8
  License: GPLv2
9
 
10
  == Description ==
51
 
52
  == Changelog ==
53
 
54
+ = 0.6 =
55
+
56
+ * Introduces validation filters
57
+ * Better data sanitization and escaping
58
+ * Updates labels in options-interface.php
59
+ * Changes how checkboxes saved in database ("0" or "1")
60
+ * Stores typography, backgrounds and multichecks directly as arrays
61
+ * For full description, see: http://wptheming.com/2011/05/options-framework-0-6/
62
+
63
  = 0.5 =
64
 
65
  * Fixed errors when more than one multicheck options is used