Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 5th, 2010  |  syntax: PHP  |  size: 6.28 KB  |  views: 328  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. $themename = "Jeans WP";
  3. $shortname = "jwp";
  4. $options = array (
  5.  
  6.         array(  "name" => "About",
  7.                         "type" => "title"),
  8.                        
  9.         array(  "type" => "open"),
  10.        
  11.         array(  "name" => "Title",
  12.                         "desc" => "Enter a title to display for your about info.",
  13.                         "id" => $shortname."_about_title",
  14.                         "std" => "",
  15.                         "type" => "text"),
  16.                        
  17.         array(  "name" => "Message",
  18.                         "desc" => "Text to display as about info.",
  19.             "id" => $shortname."_about_message",
  20.             "type" => "textarea"),
  21.        
  22.         array(  "name" => "Disable About Message?",
  23.                         "desc" => "Check this box if you would like to DISABLE the about info.",
  24.             "id" => $shortname."_about_disable",
  25.             "type" => "checkbox",
  26.             "std" => "false"),
  27.        
  28.         array(  "type" => "close")
  29.        
  30.        
  31.        
  32.        
  33.        
  34. );
  35.  
  36.  
  37. function mytheme_add_admin() {
  38.  
  39.     global $themename, $shortname, $options;
  40.  
  41.     if ( $_GET['page'] == basename(__FILE__) ) {
  42.    
  43.         if ( 'save' == $_REQUEST['action'] ) {
  44.  
  45.                 foreach ($options as $value) {
  46.                     update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
  47.  
  48.                 foreach ($options as $value) {
  49.                     if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
  50.  
  51.                 header("Location: themes.php?page=functions.php&saved=true");
  52.                 die;
  53.  
  54.         } else if( 'reset' == $_REQUEST['action'] ) {
  55.  
  56.             foreach ($options as $value) {
  57.                 delete_option( $value['id'] ); }
  58.  
  59.             header("Location: themes.php?page=functions.php&reset=true");
  60.             die;
  61.  
  62.         }
  63.     }
  64.  
  65.     add_theme_page($themename." Options", "".$themename." Options", 'edit_themes', basename(__FILE__), 'mytheme_admin');
  66.  
  67. }
  68.  
  69. function mytheme_admin() {
  70.  
  71.     global $themename, $shortname, $options;
  72.  
  73.     if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
  74.     if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
  75.    
  76. ?>
  77. <div class="wrap">
  78. <h2><?php echo $themename; ?> settings</h2>
  79.  
  80. <form method="post">
  81.  
  82.  
  83.  
  84. <?php foreach ($options as $value) {
  85.    
  86.         switch ( $value['type'] ) {
  87.        
  88.                 case "open":
  89.                 ?>
  90.         <table width="100%" border="0" style="background-color:#eef5fb; padding:10px;">
  91.                
  92.        
  93.        
  94.                 <?php break;
  95.                
  96.                 case "close":
  97.                 ?>
  98.                
  99.         </table><br />
  100.        
  101.        
  102.                 <?php break;
  103.                
  104.                 case "title":
  105.                 ?>
  106.                 <table width="100%" border="0" style="background-color:#dceefc; padding:5px 10px;"><tr>
  107.                 <td colspan="2"><h3 style="font-family:Georgia,'Times New Roman',Times,serif;"><?php echo $value['name']; ?></h3></td>
  108.         </tr>
  109.                
  110.        
  111.                 <?php break;
  112.  
  113.                 case 'text':
  114.                 ?>
  115.        
  116.         <tr>
  117.             <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  118.             <td width="80%"><input style="width:400px;" 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']; } ?>" /></td>
  119.         </tr>
  120.  
  121.         <tr>
  122.             <td><small><?php echo $value['desc']; ?></small></td>
  123.         </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
  124.  
  125.                 <?php
  126.                 break;
  127.                
  128.                 case 'textarea':
  129.                 ?>
  130.        
  131.         <tr>
  132.             <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  133.             <td width="80%"><textarea name="<?php echo $value['id']; ?>" style="width:400px; height:200px;" type="<?php echo $value['type']; ?>" cols="" rows=""><?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?></textarea></td>
  134.            
  135.         </tr>
  136.  
  137.         <tr>
  138.             <td><small><?php echo $value['desc']; ?></small></td>
  139.         </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
  140.  
  141.                 <?php
  142.                 break;
  143.                
  144.                 case 'select':
  145.                 ?>
  146.         <tr>
  147.             <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  148.             <td width="80%"><select style="width:240px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>"><?php foreach ($value['options'] as $option) { ?><option<?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?></select></td>
  149.        </tr>
  150.                
  151.        <tr>
  152.             <td><small><?php echo $value['desc']; ?></small></td>
  153.        </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
  154.  
  155.                 <?php
  156.         break;
  157.            
  158.                 case "checkbox":
  159.                 ?>
  160.             <tr>
  161.             <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  162.                 <td width="80%"><? if(get_settings($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = ""; } ?>
  163.                         <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
  164.                         </td>
  165.             </tr>
  166.                        
  167.             <tr>
  168.                 <td><small><?php echo $value['desc']; ?></small></td>
  169.            </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
  170.            
  171.         <?php           break;
  172.        
  173.  
  174. }
  175. }
  176. ?>
  177.  
  178. <!--</table>-->
  179.  
  180. <p class="submit">
  181. <input name="save" type="submit" value="Save changes" />    
  182. <input type="hidden" name="action" value="save" />
  183. </p>
  184. </form>
  185. <form method="post">
  186. <p class="submit">
  187. <input name="reset" type="submit" value="Reset" />
  188. <input type="hidden" name="action" value="reset" />
  189. </p>
  190. </form>
  191.  
  192. <?php
  193. }
  194.  
  195. add_action('admin_menu', 'mytheme_add_admin'); ?>
clone this paste RAW Paste Data