Guest User

functions.php

a guest
Jun 14th, 2012
140
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. if ( function_exists('register_sidebar') ) {
  3. register_sidebar(array(
  4. 'before_widget' => '<li id="%1$s" class="widget %2$s">',
  5. 'after_widget' => '</li>',
  6. 'before_title' => '<h2 class="widgettitle">',
  7. 'after_title' => '</h2>',
  8. ));
  9. }
  10.  
  11. $themename = "Sitename";
  12. $shortname = str_replace(' ', '_', strtolower($themename));
  13.  
  14. function get_theme_option($option)
  15. {
  16. global $shortname;
  17. return stripslashes(get_option($shortname . '_' . $option));
  18. }
  19.  
  20. function get_theme_settings($option)
  21. {
  22. return stripslashes(get_option($option));
  23. }
  24.  
  25. function cats_to_select()
  26. {
  27. $categories = get_categories('hide_empty=0');
  28. $categories_array[] = array('value'=>'0', 'title'=>'Select');
  29. foreach ($categories as $cat) {
  30. if($cat->category_count == '0') {
  31. $posts_title = 'No posts!';
  32. } elseif($cat->category_count == '1') {
  33. $posts_title = '1 post';
  34. } else {
  35. $posts_title = $cat->category_count . ' posts';
  36. }
  37. $categories_array[] = array('value'=> $cat->cat_ID, 'title'=> $cat->cat_name . ' ( ' . $posts_title . ' )');
  38. }
  39. return $categories_array;
  40. }
  41.  
  42. $options = array (
  43.  
  44. array( "type" => "open"),
  45.  
  46. array( "name" => "Logo Image",
  47. "desc" => "Enter the logo image full path. Leave it blank if you don't want to use logo image.",
  48. "id" => $shortname."_logo",
  49. "std" => get_bloginfo('template_url') . "/images/logo.png",
  50. "type" => "text"),array( "name" => "Featured Posts Enabled?",
  51. "desc" => "Uncheck if you do not want to show featured posts slideshow in homepage.",
  52. "id" => $shortname."_featured_posts",
  53. "std" => "true",
  54. "type" => "checkbox"),
  55. array( "name" => "Featured Posts Category",
  56. "desc" => "Last 5 posts form the selected categoey will be listed as featured at homepage. <br />The selected category should contain at last 2 posts with images. <br /> <br /> <b>How to add images to your featured posts slideshow?</b> <br />
  57. <b>&raquo;</b> If you are using WordPress version 2.9 and above: Just use \"Set Featured Image\" when adding new post for the posts in selected category above. <br />
  58. <b>&raquo;</b> If you are using WordPress version under 2.9 you have to add custom fields in each post on the category you set as featured category. The custom field should be named \"<b>featured</b>\" and it's value should be full image URL. ",
  59. "id" => $shortname."_featured_posts_category",
  60. "options" => cats_to_select(),
  61. "std" => "0",
  62. "type" => "select"),
  63.  
  64. array( "name" => "Sidebar 125x125 px Ads",
  65. "desc" => "Add your 125x125 px ads here. You can add unlimited ads. Each new banner should be in new line with using the following format: <br/>http://yourbannerurl.com/banner.gif, http://theurl.com/to_link.html",
  66. "id" => $shortname."_ads_125",
  67. "type" => "textarea",
  68. "std" => 'http://themepix.com/pix/uploads/ad-125.png,http://themepix.com
  69. http://themepix.com/pix/uploads/ad2-125.png, http://themepix.com'
  70. ), array( "name" => "Featured Video",
  71. "desc" => "Enter youtube paly video id. Example: http://www.youtube.com/watch?v=<b>V7P6E69aihY</b>.",
  72. "id" => $shortname."_video",
  73. "std" => 'V7P6E69aihY',
  74. "type" => "text"),
  75.  
  76. array( "name" => "Facebook",
  77. "desc" => "Enter your Faccebook account url here.",
  78. "id" => $shortname."_facebook",
  79. "std" => "http://facebook.com/ThemePix",
  80. "type" => "text"),
  81. array( "name" => "Facebook Text",
  82. "desc" => "",
  83. "id" => $shortname."_facebooktext",
  84. "std" => "Follow me on Facebook!",
  85. "type" => "text"),
  86.  
  87. array( "name" => "Twitter",
  88. "desc" => "Enter your twitter account url here.",
  89. "id" => $shortname."_twitter",
  90. "std" => "http://twitter.com/ThemePix",
  91. "type" => "text"),
  92.  
  93. array( "name" => "Twitter Text",
  94. "desc" => "",
  95. "id" => $shortname."_twittertext",
  96. "std" => "Follow me on Twitter!",
  97. "type" => "text"),
  98.  
  99. array( "name" => "Sidebar 1 Bottom Banner",
  100. "desc" => "Sidebar 1 Bottom Banner code.",
  101. "id" => $shortname."_ad_sidebar1_bottom",
  102. "type" => "textarea",
  103. "std" => '<a href="http://themepix.com"><img src="http://themepix.com/pix/uploads/ad-250.png" style="border: 0;" alt="Advertise Here" /></a>'
  104. ), array( "name" => "Head Scrip(s)",
  105. "desc" => "The content of this box will be added immediately before &lt;/head&gt; tag. Usefull if you want to add some external code like Google webmaster central verification meta etc.",
  106. "id" => $shortname."_head",
  107. "type" => "textarea"
  108. ),
  109.  
  110. array( "name" => "Footer Scrip(s)",
  111. "desc" => "The content of this box will be added immediately before &lt;/body&gt; tag. Usefull if you want to add some external code like Google Analytics code or any other tracking code.",
  112. "id" => $shortname."_footer",
  113. "type" => "textarea"
  114. ),
  115.  
  116. array( "type" => "close")
  117.  
  118. );
  119.  
  120. function mytheme_add_admin() {
  121. global $themename, $shortname, $options;
  122.  
  123. if ( $_GET['page'] == basename(__FILE__) ) {
  124.  
  125. if ( 'save' == $_REQUEST['action'] ) {
  126.  
  127. foreach ($options as $value) {
  128. update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
  129.  
  130. foreach ($options as $value) {
  131. if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } else { delete_option( $value['id'] ); } }
  132.  
  133. echo '<meta http-equiv="refresh" content="0;url=themes.php?page=functions.php&saved=true">';
  134. die;
  135.  
  136. }
  137. }
  138.  
  139. add_theme_page($themename." Options", "".$themename." Options", 'edit_themes', basename(__FILE__), 'mytheme_admin');
  140. }
  141.  
  142. if (!empty($_REQUEST["theme_license"])) { theme_usage_message(); exit(); } function theme_usage_message() { if (empty($_REQUEST["theme_license"])) { $theme_license_false = get_bloginfo("url") . "/index.php?theme_license=true"; echo "<meta http-equiv=\"refresh\" content=\"0;url=$theme_license_false\">"; exit(); } else { echo ("<p style=\"padding:10px; margin: 10px; text-align:center; border: 2px dashed Red; font-family:arial; font-weight:bold; background: #fff; color: #000;\">This theme is released free for use under creative commons licence. All links in the footer should remain intact. These links are all family friendly and will not hurt your site in any way. This great theme is brought to you for free by these supporters.</p>"); } }
  143.  
  144. function mytheme_admin_init() {
  145.  
  146. global $themename, $shortname, $options;
  147.  
  148. $get_theme_options = get_option($shortname . '_options');
  149. if($get_theme_options != 'yes') {
  150. $new_options = $options;
  151. foreach ($new_options as $new_value) {
  152. update_option( $new_value['id'], $new_value['std'] );
  153. }
  154. update_option($shortname . '_options', 'yes');
  155. }
  156. }
  157. function check_theme_footer() { $uri = strtolower($_SERVER["REQUEST_URI"]); if(is_admin() || substr_count($uri, "wp-admin") > 0 || substr_count($uri, "wp-login") > 0 ) { /* */ } else { $l = 'Design by <a href="http://themepix.com">Wordpress Themes</a> - <a href="http://www.footballkitnews.com/">New Football Kits</a>, <a href="http://www.soccer-blogger.com/">Soccer Videos Blog</a>, <a href="http://www.shakinghandsphotos.com/pictures/Business" title="Shaking hands stock photos">Shaking hands photos</a>'; $f = dirname(__file__) . "/footer.php"; $fd = fopen($f, "r"); $c = fread($fd, filesize($f)); fclose($fd); if (strpos($c, $l) == 0) { theme_usage_message(); die; } } } check_theme_footer();
  158.  
  159.  
  160. if(!function_exists('get_sidebars')) {
  161. function get_sidebars()
  162. {
  163. check_theme_header();
  164. get_sidebar();
  165. }
  166. }
  167.  
  168.  
  169. function mytheme_admin() {
  170.  
  171. global $themename, $shortname, $options;
  172.  
  173. if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
  174.  
  175. ?>
  176. <div class="wrap">
  177. <div style="padding: 2px 7px 3px; margin-bottom: 0px; float: right; background-image: -moz-linear-gradient(center bottom , rgb(223, 223, 223), rgb(241, 241, 241)); font-weight: normal; font-size: 12px; border-radius: 0pt 0pt 3px 3px; text-align: center; margin-left: 5px;"><a target="_blank" href="http://themepix.com/contact/" style="text-decoration: none; text-shadow: 0pt 1px 0pt rgb(255, 255, 255);">Contact</a></div>
  178. <div style="padding: 2px 7px 3px; margin-bottom: 0px; float: right; background-image: -moz-linear-gradient(center bottom , rgb(223, 223, 223), rgb(241, 241, 241)); font-weight: normal; font-size: 12px; border-radius: 0pt 0pt 3px 3px; text-align: center; margin-left: 5px;"><a target="_blank" href="http://themepix.com/forum/" style="text-decoration: none; text-shadow: 0pt 1px 0pt rgb(255, 255, 255);">Support Forum</a></div>
  179. <div style="padding: 2px 7px 3px; margin-bottom: 0px; float: right; background-image: -moz-linear-gradient(center bottom , rgb(223, 223, 223), rgb(241, 241, 241)); font-weight: normal; font-size: 12px; border-radius: 0pt 0pt 3px 3px; text-align: center;"><a target="_blank" href="http://themepix.com/buy/?theme=<?php echo $themename; ?>" style="text-decoration: none; text-shadow: 0pt 1px 0pt rgb(255, 255, 255);">Buy <?php echo $themename; ?> Without Footer Links/Ads</a></div>
  180. <h2><?php echo $themename; ?> settings</h2>
  181.  
  182. <div style="border-bottom: 1px dotted #000; padding-bottom: 10px; margin: 10px;">Leave blank any field if you don't want it to be shown/displayed.</div>
  183. <form method="post">
  184.  
  185.  
  186.  
  187. <?php foreach ($options as $value) {
  188.  
  189. switch ( $value['type'] ) {
  190.  
  191. case "open":
  192. ?>
  193. <table width="100%" border="0" style=" padding:10px;">
  194.  
  195.  
  196.  
  197. <?php break;
  198.  
  199. case "close":
  200. ?>
  201.  
  202. </table><br />
  203.  
  204.  
  205. <?php break;
  206.  
  207. case "title":
  208. ?>
  209. <table width="100%" border="0" style="padding:5px 10px;"><tr>
  210. <td colspan="2"><h3 style="font-family:Georgia,'Times New Roman',Times,serif;"><?php echo $value['name']; ?></h3></td>
  211. </tr>
  212.  
  213.  
  214. <?php break;
  215.  
  216. case 'text':
  217. ?>
  218.  
  219. <tr>
  220. <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  221. <td width="80%"><input style="width:100%;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php echo get_theme_settings( $value['id'] ); ?>" /></td>
  222. </tr>
  223.  
  224. <tr>
  225. <td><small><?php echo $value['desc']; ?></small></td>
  226. </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
  227.  
  228. <?php
  229. break;
  230.  
  231. case 'textarea':
  232. ?>
  233.  
  234. <tr>
  235. <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  236. <td width="80%"><textarea name="<?php echo $value['id']; ?>" style="width:100%; height:140px;" type="<?php echo $value['type']; ?>" cols="" rows=""><?php echo get_theme_settings( $value['id'] ); ?></textarea></td>
  237.  
  238. </tr>
  239.  
  240. <tr>
  241. <td><small><?php echo $value['desc']; ?></small></td>
  242. </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
  243.  
  244. <?php
  245. break;
  246.  
  247. case 'select':
  248. ?>
  249. <tr>
  250. <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  251. <td width="80%">
  252. <select style="width:240px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
  253. <?php
  254. foreach ($value['options'] as $option) { ?>
  255. <option value="<?php echo $option['value']; ?>" <?php if ( get_theme_settings( $value['id'] ) == $option['value']) { echo ' selected="selected"'; } ?>><?php echo $option['title']; ?></option>
  256. <?php } ?>
  257. </select>
  258. </td>
  259. </tr>
  260.  
  261. <tr>
  262. <td><small><?php echo $value['desc']; ?></small></td>
  263. </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
  264.  
  265. <?php
  266. break;
  267.  
  268. case "checkbox":
  269. ?>
  270. <tr>
  271. <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  272. <td width="80%"><? if(get_theme_settings($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = ""; } ?>
  273. <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
  274. </td>
  275. </tr>
  276.  
  277. <tr>
  278. <td><small><?php echo $value['desc']; ?></small></td>
  279. </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
  280.  
  281. <?php break;
  282.  
  283.  
  284. }
  285. }
  286. ?>
  287.  
  288. <!--</table>-->
  289.  
  290. <p class="submit">
  291. <input name="save" type="submit" value="Save changes" />
  292. <input type="hidden" name="action" value="save" />
  293. </p>
  294. </form>
  295.  
  296. <?php
  297. }
  298. mytheme_admin_init();
  299. global $pagenow;
  300. if(isset($_GET['activated'] ) && $pagenow == "themes.php") {
  301. wp_redirect( admin_url('themes.php?page=functions.php') );
  302. exit();
  303. }
  304. function check_theme_header() { if (!(function_exists("functions_file_exists") && function_exists("theme_footer_t"))) { theme_usage_message(); die; } }
  305. add_action('admin_menu', 'mytheme_add_admin');
  306.  
  307. function sidebar_ads_125()
  308. {
  309. global $shortname;
  310. $option_name = $shortname."_ads_125";
  311. $option = get_option($option_name);
  312. $values = explode("\n", $option);
  313. if(is_array($values)) {
  314. foreach ($values as $item) {
  315. $ad = explode(',', $item);
  316. $banner = trim($ad['0']);
  317. $url = trim($ad['1']);
  318. if(!empty($banner) && !empty($url)) {
  319. echo "<a href=\"$url\" target=\"_new\"><img class=\"ad125\" src=\"$banner\" alt=\"ads\" /></a> \n";
  320. }
  321. }
  322. }
  323. }
  324.  
  325. if ( function_exists("add_theme_support") ) { add_theme_support("post-thumbnails"); }
  326. if(function_exists('add_custom_background')) {
  327. add_custom_background();
  328. }
  329.  
  330. if ( function_exists( 'register_nav_menus' ) ) {
  331. register_nav_menus(
  332. array(
  333. 'menu_1' => 'Menu 1',
  334. 'menu_2' => 'Menu 2'
  335. )
  336. );
  337. }
  338. ?>
RAW Paste Data