whyisjake

Untitled

Jun 24th, 2010
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.32 KB | None | 0 0
  1. /*Start of Theme Options*/
  2.  
  3. $themename = "eShop Momma Store";
  4. $shortname = "mama";
  5. $options = array (
  6.  
  7. array( "name" => "$themename PayPal Settings",
  8.     "type" => "title"),
  9.  
  10. array( "type" => "open"),
  11.  
  12. array( "name" => "PayPal Email",
  13.     "desc" => "Enter your PayPal email here.",
  14.     "id" => $shortname."_paypal",
  15.     "type" => "text",
  16.     "std" => "email@domain.com"),
  17.  
  18. array( "name" => "Default Handling",
  19.     "desc" => "Any fee that you want automatically added to every purchase.",
  20.     "id" => $shortname."_handling",
  21.     "type" => "text",
  22.     "std" => "0.00"),  
  23.  
  24. array( "type" => "close")
  25.  
  26. );
  27.  
  28.  
  29. function mytheme_add_admin() {
  30.  
  31. global $themename, $shortname, $options;
  32.  
  33. if ( $_GET['page'] == basename(__FILE__) ) {
  34.  
  35. if ( 'save' == $_REQUEST['action'] ) {
  36.  
  37. foreach ($options as $value) {
  38. update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
  39.  
  40. foreach ($options as $value) {
  41. if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
  42.  
  43. header("Location: edit.php?post_type=the_store&saved=true");
  44. die;
  45.  
  46. } else if( 'reset' == $_REQUEST['action'] ) {
  47.  
  48. foreach ($options as $value) {
  49. delete_option( $value['id'] ); }
  50.  
  51. header("Location: edit.php?post_type=the_store&reset=true");
  52. die;
  53.  
  54. }
  55. }
  56.  
  57. add_submenu_page( 'edit.php?post_type=the_store', 'Store Options', 'Store Options', 'manage_options', 'js_store_options', 'js_store_options_page');
  58.  
  59. }
  60.  
  61. function js_store_options_page() {
  62.  
  63. global $themename, $shortname, $options;
  64.  
  65. if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
  66. if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
  67.  
  68. ?>
  69. <div class="wrap">
  70. <h2><?php echo $themename; ?> Settings</h2>
  71.  
  72. <form method="post">
  73.  
  74. <?php foreach ($options as $value) {
  75. switch ( $value['type'] ) {
  76.  
  77. case "open":
  78. ?>
  79. <table width="100%" border="0" style="background-color:#eef5fb; padding:10px;">
  80.  
  81. <?php break;
  82.  
  83. case "close":
  84. ?>
  85.  
  86. </table><br />
  87.  
  88. <?php break;
  89.  
  90. case "title":
  91. ?>
  92. <table width="100%" border="0" style="background-color:#dceefc; padding:5px 10px;"><tr>
  93. <td colspan="2"><h3 style="font-family:Georgia,'Times New Roman',Times,serif;"><?php echo $value['name']; ?></h3></td>
  94. </tr>
  95.  
  96. <?php break;
  97.  
  98. case 'text':
  99. ?>
  100.  
  101. <tr>
  102. <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  103. <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>
  104. </tr>
  105.  
  106. <tr>
  107. <td><small><?php echo $value['desc']; ?></small></td>
  108. </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
  109.  
  110. <?php
  111. break;
  112.  
  113. case 'textarea':
  114. ?>
  115.  
  116. <tr>
  117. <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  118. <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>
  119.  
  120. </tr>
  121.  
  122. <tr>
  123. <td><small><?php echo $value['desc']; ?></small></td>
  124. </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
  125.  
  126. <?php
  127. break;
  128.  
  129. case 'select':
  130. ?>
  131. <tr>
  132. <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  133. <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>
  134. </tr>
  135.  
  136. <tr>
  137. <td><small><?php echo $value['desc']; ?></small></td>
  138. </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
  139.  
  140. <?php
  141. break;
  142.  
  143. case "checkbox":
  144. ?>
  145. <tr>
  146. <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  147. <td width="80%"><?php if(get_option($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = "";} ?>
  148. <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
  149. </td>
  150. </tr>
  151.  
  152. <tr>
  153. <td><small><?php echo $value['desc']; ?></small></td>
  154. </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
  155.  
  156. <?php break;
  157.  
  158. }
  159. }
  160. ?>
  161.  
  162. <p class="submit">
  163. <input name="save" type="submit" value="Save changes" />
  164. <input type="hidden" name="action" value="save" />
  165. </p>
  166. </form>
  167. <form method="post">
  168. <p class="submit">
  169. <input name="reset" type="submit" value="Reset" />
  170. <input type="hidden" name="action" value="reset" />
  171. </p>
  172. </form>
  173.  
  174. <?php
  175. }
  176.  
  177. add_action('admin_menu', 'mytheme_add_admin');
Add Comment
Please, Sign In to add comment