Advertisement
Guest User

DemtriusPop

a guest
Apr 19th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.62 KB | None | 0 0
  1. <?php
  2.  
  3. // Set some theme specific variables for the options panel
  4. $childthemename = "my-path Theme";
  5. $childshortname = "mt08";
  6. $childoptions = array();
  7.  
  8. function childtheme_options() {
  9. global $childthemename, $childshortname, $childoptions;
  10.  
  11. // Create array to store the Categories to be used in the drop-down select box
  12. $categories_obj = get_categories('hide_empty=0');
  13. $categories = array();
  14. foreach ($categories_obj as $cat) {
  15. $categories[$cat->cat_ID] = $cat->cat_name;
  16. }
  17.  
  18. // the color variants array
  19. $color_variants = array(
  20. "blue" => "blue",
  21. "red" => "red",
  22. "steel" => "steel"
  23. );
  24.  
  25. $childoptions = array (
  26.  
  27. array( "name" => __('Color Variant','path'),
  28. "desc" => __('Select which color scheme or variant you would like to use.','path'),
  29. "id" => "my_path_color_variant",
  30. "std" => 'skin',
  31. "type" => "radio",
  32. "options" => $color_variants
  33. ),
  34.  
  35. array( "name" => __('Link Color','path'),
  36. "desc" => __('Change the color of links by entering a HEX color number. (e.g.: 003333)','path'),
  37. "id" => "my_path_link_color",
  38. "std" => "999999",
  39. "type" => "text"
  40. ),
  41. array( "name" => __('Show Header Image','path'),
  42. "desc" => __('Show an image in the header. Replace the header.png file found in the /my-path/images/ folder with your own image, up to 120x100px.','path'),
  43. "id" => "my_path_show_logo",
  44. "std" => "false",
  45. "type" => "checkbox"
  46. ),
  47. array( "name" => __('Featured Category','path'),
  48. "desc" => __('A category of posts to be featured on the front page.','path'),
  49. "id" => "my_path_feature_cat",
  50. "std" => $default_cat,
  51. "type" => "select",
  52. "options" => $categories
  53. )
  54. );
  55. }
  56. add_action('init', 'childtheme_options');
  57.  
  58. // Make a Theme Options Page
  59. function childtheme_add_admin() {
  60. global $childthemename, $childshortname, $childoptions;
  61.  
  62. if ( $_GET['page'] == basename(__FILE__) ) {
  63.  
  64. if ( 'save' == $_REQUEST['action'] ) {
  65. // protect against request forgery
  66. check_admin_referer('childtheme-save');
  67. // save the options
  68. foreach ($childoptions as $value) {
  69. if( isset( $_REQUEST[ $value['id'] ] ) ) {
  70. update_option( $value['id'], $_REQUEST[ $value['id'] ] );
  71. } else {
  72. delete_option( $value['id'] );
  73. }
  74. }
  75.  
  76. // return to the options page
  77. header("Location: themes.php?page=options.php&saved=true");
  78. die;
  79.  
  80. } else if ( 'reset' == $_REQUEST['action'] ) {
  81. // protect against request forgery
  82. check_admin_referer('childtheme-reset');
  83. // delete the options
  84. foreach ($childoptions as $value) {
  85. delete_option( $value['id'] );
  86. }
  87.  
  88. // return to the options page
  89. header("Location: themes.php?page=options.php&reset=true");
  90. die;
  91. }
  92. }
  93. add_theme_page($childthemename." Options", "$childthemename Options", 'edit_themes', basename(__FILE__), 'childtheme_admin');
  94. }
  95. add_action('admin_menu' , 'childtheme_add_admin');
  96.  
  97. function childtheme_admin() {
  98.  
  99. global $childthemename, $childshortname, $childoptions;
  100.  
  101. // Saved or Updated message
  102. if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$childthemename.' settings saved.</strong></p></div>';
  103. if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$childthemename.' settings reset.</strong></p></div>';
  104.  
  105. // The form
  106. ?>
  107.  
  108. <div class="wrap">
  109. <h2><?php echo $childthemename; ?> Options</h2>
  110.  
  111. <form method="post">
  112.  
  113. <?php wp_nonce_field('childtheme-save'); ?>
  114. <table class="form-table">
  115.  
  116. <?php foreach ($childoptions as $value) {
  117.  
  118. // Output the appropriate form element
  119. switch ( $value['type'] ) {
  120.  
  121. case 'text':
  122. ?>
  123. <tr valign="top">
  124. <th scope="row"><?php echo $value['name']; ?>:</th>
  125. <td>
  126. <input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="text" value="<?php echo stripslashes(get_option( $value['id'], $value['std'] )); ?>" />
  127. <?php echo $value['desc']; ?>
  128. </td>
  129. </tr>
  130. <?php
  131. break;
  132.  
  133. case 'select':
  134. ?>
  135. <tr valign="top">
  136. <th scope="row"><?php echo $value['name']; ?></th>
  137. <td>
  138. <select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
  139. <option value="">--</option>
  140. <?php foreach ($value['options'] as $key=>$option) {
  141. if ($key == get_option($value['id'], $value['std']) ) {
  142. $selected = "selected=\"selected\"";
  143. } else {
  144. $selected = "";
  145. }
  146. ?>
  147. <option value="<?php echo $key ?>" <?php echo $selected ?>><?php echo $option; ?></option>
  148. <?php } ?>
  149. </select>
  150. <?php echo $value['desc']; ?>
  151. </td>
  152. </tr>
  153. <?php
  154. break;
  155.  
  156. case 'textarea':
  157. $ta_options = $value['options'];
  158. ?>
  159. <tr valign="top">
  160. <th scope="row"><?php echo $value['name']; ?>:</th>
  161. <td>
  162. <?php echo $value['desc']; ?>
  163. <textarea name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" cols="<?php echo $ta_options['cols']; ?>" rows="<?php echo $ta_options['rows']; ?>"><?php
  164. echo stripslashes(get_option($value['id'], $value['std']));
  165. ?></textarea>
  166. </td>
  167. </tr>
  168. <?php
  169. break;
  170.  
  171. case "radio":
  172. ?>
  173. <tr valign="top">
  174. <th scope="row"><?php echo $value['name']; ?>:</th>
  175. <td>
  176. <?php foreach ($value['options'] as $key=>$option) {
  177. if ($key == get_option($value['id'], $value['std']) ) {
  178. $checked = "checked=\"checked\"";
  179. } else {
  180. $checked = "";
  181. }
  182. ?>
  183. <input type="radio" name="<?php echo $value['id']; ?>" value="<?php echo $key; ?>" <?php echo $checked; ?> /><?php echo $option; ?><br />
  184. <?php } ?>
  185. <?php echo $value['desc']; ?>
  186. </td>
  187. </tr>
  188. <?php
  189. break;
  190.  
  191. case "checkbox":
  192. ?>
  193. <tr valign="top">
  194. <th scope="row"><?php echo $value['name']; ?></th>
  195. <td>
  196. <?php
  197. if(get_option($value['id'])){
  198. $checked = "checked=\"checked\"";
  199. } else {
  200. $checked = "";
  201. }
  202. ?>
  203. <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
  204. <?php echo $value['desc']; ?>
  205. </td>
  206. </tr>
  207. <?php
  208. break;
  209.  
  210. default:
  211. break;
  212. }
  213. }
  214. ?>
  215.  
  216. </table>
  217.  
  218. <p class="submit">
  219. <input name="save" type="submit" value="Save changes" class="button-primary" />
  220. <input type="hidden" name="action" value="save" />
  221. </p>
  222.  
  223. </form>
  224.  
  225. <form method="post">
  226. <?php wp_nonce_field('childtheme-reset'); ?>
  227. <p class="submit">
  228. <input name="reset" type="submit" value="Reset" />
  229. <input type="hidden" name="action" value="reset" />
  230. </p>
  231. </form>
  232.  
  233. <p><?php _e('For more information about this theme, check out <a href="http://sitepoint.com/books/wordpress1">Build Your Own my-path WordPress Themes</a>. If you have any questions, visit the <a href="http://sitepoint.com/forums/">SitePoint Forums</a>.', 'path'); ?></p>
  234.  
  235. <?php
  236. } // end function
  237.  
  238. ?>
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245. Style sheet:
  246. <?php
  247.  
  248. function my_path_load_custom_styles() {
  249. // load the custom options
  250. global $childoptions;
  251. foreach ($childoptions as $value) {
  252. $$value['id'] = get_option($value['id'], $value['std']);
  253. }
  254.  
  255. wp_enqueue_style(
  256. 'my-path-skin',
  257. get_bloginfo('stylesheet_directory').'/skins/'.$my_path_color_variant.'/skin.css',
  258. '', '', 'all'
  259. );
  260.  
  261. // output a style sheet with the options
  262. ?>
  263.  
  264. <style type="text/css">
  265. /* <![CDATA[ */
  266. /* Color Options */
  267. a, a:link, a:visited,
  268. #content a,
  269. #content a:link,
  270. #content a:visited {color:#<?php echo $my_path_link_color; ?>;}
  271.  
  272. <?php if ($my_path_show_logo == 'true') { ?>
  273.  
  274. #blog-title {
  275. background:transparent url('<?php echo get_bloginfo('stylesheet_directory') ?>/images/Logo.png') left top no-repeat;
  276. padding-left: 120px;
  277. height: 120px;
  278. }
  279.  
  280. <?php } ?>
  281.  
  282. /* ]]> */
  283. </style>
  284.  
  285. <?php
  286. } // end function
  287.  
  288. add_action('wp_print_styles', 'my_path_load_custom_styles');
  289.  
  290. add_action('wp_head', 'my_path_load_custom_styles');
  291.  
  292. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement