PageRenderTime 39ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 0ms

/blog/wp-content/themes/bueno/includes/options-page.php

https://bitbucket.org/sergiohzlz/reportaprod
PHP | 127 lines | 80 code | 19 blank | 28 comment | 10 complexity | 85bd51e0ea5da76e7a13d148bea5d7eb MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. add_action( 'admin_init', 'theme_options_init' );
  3. add_action( 'admin_menu', 'theme_options_add_page' );
  4. /**
  5. * Init plugin options to white list our options
  6. */
  7. function theme_options_init(){
  8. register_setting( 'bueno_options', 'bueno_theme_options', 'theme_options_validate' );
  9. }
  10. /**
  11. * Load up the menu page
  12. */
  13. function theme_options_add_page() {
  14. add_theme_page( __( 'Theme Options' ), __( 'Theme Options' ), 'edit_theme_options', 'theme_options', 'theme_options_do_page' );
  15. }
  16. /**
  17. * Set the default options for the select option
  18. */
  19. $select_options = array( 'Blue', 'Brown', 'Default', 'Green', 'Grey', 'Purple', 'Red' );
  20. /**
  21. * Create the options page
  22. */
  23. function theme_options_do_page() {
  24. global $select_options;
  25. ?>
  26. <div class="wrap">
  27. <?php screen_icon(); echo "<h2>" . get_current_theme() . __( ' Theme Options' ) . "</h2>"; ?>
  28. <?php if( $_REQUEST['updated'] == 'true' ) : ?>
  29. <div class="updated fade"><p><strong><?php _e( 'Options saved' ); ?></strong></p></div>
  30. <?php endif; ?>
  31. <form method="post" action="options.php">
  32. <?php settings_fields('bueno_options'); ?>
  33. <?php $options = get_option('bueno_theme_options'); ?>
  34. <table class="form-table">
  35. <?php
  36. /**
  37. * Home link in nav menu?
  38. */
  39. ?>
  40. <tr valign="top"><th scope="row"><?php _e( 'Home Link' ); ?></th>
  41. <td>
  42. <input id="bueno_theme_options[homelink]" name="bueno_theme_options[homelink]" type="checkbox" value="1" <?php checked('1', $options['homelink']); ?> />
  43. <label class="description" for="bueno_theme_options[homelink]"><?php _e( 'Show a link to your home page in the nav menu' ); ?></label>
  44. </td>
  45. </tr>
  46. <?php
  47. /**
  48. * Feed link in nav menu?
  49. */
  50. ?>
  51. <tr valign="top"><th scope="row"><?php _e( 'Feed Link' ); ?></th>
  52. <td>
  53. <input id="bueno_theme_options[feedlink]" name="bueno_theme_options[feedlink]" type="checkbox" value="1" <?php checked('1', $options['feedlink']); ?> />
  54. <label class="description" for="bueno_theme_options[feedlink]"><?php _e( 'Show a link to your RSS feed in the nav menu' ); ?></label>
  55. </td>
  56. </tr>
  57. <?php
  58. /**
  59. * Alternate color scheme option
  60. */
  61. ?>
  62. <tr valign="top"><th scope="row"><?php _e( 'Color scheme' ); ?></th>
  63. <td>
  64. <select name="bueno_theme_options[colorscheme]">
  65. <?php
  66. $selected = $options['colorscheme'];
  67. $p = '';
  68. $r = '';
  69. foreach ( $select_options as $option ) {
  70. if ( ! isset( $options['colorscheme'] ) || ! in_array($options['colorscheme'], $select_options) ) {
  71. $selected = 'Default';
  72. }
  73. if ( $selected == $option ) // Make default first in list
  74. $p = "\n\t<option style=\"padding-right: 10px;\" selected='selected' value='" . esc_attr($option) . "'>$option</option>";
  75. else
  76. $r .= "\n\t<option style=\"padding-right: 10px;\" value='" . esc_attr($option) . "'>$option</option>";
  77. }
  78. echo $p . $r; ?>
  79. </select>
  80. <label class="description" for="bueno_theme_options[colorscheme]"><?php _e( 'Select an alternate color scheme' ); ?></label>
  81. </td>
  82. </tr>
  83. </table>
  84. <p class="submit">
  85. <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
  86. </p>
  87. </form>
  88. </div>
  89. <?php
  90. }
  91. /**
  92. * Sanitize and validate input. Accepts an array, return a sanitized array.
  93. */
  94. function theme_options_validate($input) {
  95. global $select_options;
  96. // Our homelink value is either 0 or 1
  97. $input['homelink'] = ( $input['homelink'] == 1 ? 1 : 0 );
  98. // Our feedlink value is either 0 or 1
  99. $input['feedlink'] = ( $input['feedlink'] == 1 ? 1 : 0 );
  100. // Say our color scheme option must be safe text with no HTML tags and in our array of select options
  101. if ( in_array( $input['colorscheme'], $select_options) ) {
  102. $input['colorscheme'] = $input['colorscheme'];
  103. } else {
  104. $input['colorscheme'] = 'Default';
  105. }
  106. return $input;
  107. }
  108. // adapted from http://planetozh.com/blog/2009/05/handling-plugins-options-in-wordpress-28-with-register_setting/