Advertisement
sgodar

Notepad FUNCTIONS

Apr 24th, 2012
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.73 KB | None | 0 0
  1. <?php
  2. if ( function_exists('register_sidebar') )
  3. register_sidebar(array('name'=>'Left Sidebar'));
  4. register_sidebar(array('name'=>'Right Sidebar'));
  5. ?>
  6. <?php //Begin Theme Options Code (many thanks to the undersigned for the great tutorial)
  7. $themename = "BlankBiz";
  8. $shortname = "bb";
  9. $options = array (
  10.     array(  "name" => "Address Line 1",
  11.             "id" => $shortname."_address_1",
  12.             "std" => "",
  13.             "type" => "text"),
  14.     array(  "name" => "Address Line 2",
  15.             "id" => $shortname."address_2",
  16.             "std" => "",
  17.             "type" => "text"),
  18.     array(  "name" => "City",
  19.             "id" => $shortname."_city",
  20.             "std" => "",
  21.             "type" => "text"),
  22.     array(  "name" => "State",
  23.             "id" => $shortname."_state",
  24.             "std" => "",
  25.             "type" => "text"),
  26.     array(  "name" => "Zip",
  27.             "id" => $shortname."_zip",
  28.             "std" => "",
  29.             "type" => "text"),
  30.     array(  "name" => "Phone including dashes",
  31.             "id" => $shortname."_phone",
  32.             "std" => "",
  33.             "type" => "text"),
  34.     array(  "name" => "Email",
  35.             "id" => $shortname."_email",
  36.             "std" => "",
  37.             "type" => "text")
  38. );
  39. function mytheme_add_admin() {
  40.     global $themename, $shortname, $options;
  41.     if ( $_GET['page'] == basename(__FILE__) ) {
  42.         if ( 'save' == $_REQUEST['action'] ) {
  43.                 foreach ($options as $value) {
  44.                     update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
  45.                 foreach ($options as $value) {
  46.                     if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
  47.                 header("Location: themes.php?page=functions.php&saved=true");
  48.                 die;
  49.         } else if( 'reset' == $_REQUEST['action'] ) {
  50.             foreach ($options as $value) {
  51.                 delete_option( $value['id'] ); }
  52.             header("Location: themes.php?page=functions.php&reset=true");
  53.             die;
  54.         }
  55.     }
  56.     add_theme_page($themename." Options", "Current Theme Options", 'edit_themes', basename(__FILE__), 'mytheme_admin');
  57. }
  58. function mytheme_admin() {
  59.     global $themename, $shortname, $options;
  60.     if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
  61.     if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
  62. ?>
  63. <div class="wrap">
  64. <h2><?php echo $themename; ?> settings</h2>
  65. <form method="post">
  66. <table class="optiontable">
  67. <?php foreach ($options as $value) {
  68. if ($value['type'] == "text") { //If we have configured this for text options ... ?>
  69. <tr valign="top">
  70.     <th scope="row"><?php echo $value['name']; ?>:</th>
  71.     <td>
  72.         <input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?>" />
  73.     </td>
  74. </tr>
  75. <?php } elseif ($value['type'] == "select") { //If we have configured this for select box options ... ?>
  76.     <tr valign="top">
  77.         <th scope="row"><?php echo $value['name']; ?>:</th>
  78.         <td>
  79.             <select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
  80.                 <?php foreach ($value['options'] as $option) { ?>
  81.                 <option<?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option>
  82.                 <?php } ?>
  83.             </select>
  84.         </td>
  85.     </tr>
  86. <?php
  87. }
  88. }
  89. ?>
  90. </table>
  91. <p class="submit">
  92. <input name="save" type="submit" value="Save changes" />   
  93. <input type="hidden" name="action" value="save" />
  94. </p>
  95. </form>
  96. <form method="post">
  97. <p class="submit">
  98. <input name="reset" type="submit" value="Reset" />
  99. <input type="hidden" name="action" value="reset" />
  100. </p>
  101. </form>
  102. <?php
  103. }
  104. add_action('admin_menu', 'mytheme_add_admin');
  105. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement