/swatch/functions/admin-setup.php

https://github.com/fauverism/swatch-remix · PHP · 308 lines · 180 code · 52 blank · 76 comment · 56 complexity · ad7ba6462f5488ef5c69a964fc4c1cf8 MD5 · raw file

  1. <?php
  2. /*-------------------------------------------------------------------------------------
  3. TABLE OF CONTENTS
  4. - Redirect to "Theme Options" screen (hooked onto woo_theme_activate at 10).
  5. - Flush rewrite rules to refresh permalinks for custom post types, etc.
  6. - Show Options Panel after activate
  7. - Admin Backend
  8. - Setup Custom Navigation
  9. - Output HEAD - woothemes_wp_head()
  10. - Output alternative stylesheet
  11. - Output custom favicon
  12. - Load textdomains
  13. - Output CSS from standarized styling options
  14. - Output shortcodes stylesheet
  15. - Output custom.css
  16. - Post Images from WP2.9+ integration
  17. - Enqueue comment reply script
  18. -------------------------------------------------------------------------------------*/
  19. define( 'THEME_FRAMEWORK', 'woothemes' );
  20. /*-----------------------------------------------------------------------------------*/
  21. /* Redirect to "Theme Options" screen (hooked onto woo_theme_activate at 10). */
  22. /*-----------------------------------------------------------------------------------*/
  23. add_action( 'woo_theme_activate', 'woo_themeoptions_redirect', 10 );
  24. function woo_themeoptions_redirect () {
  25. // Do redirect
  26. header( 'Location: ' . admin_url() . 'admin.php?page=woothemes' );
  27. } // End woo_themeoptions_redirect()
  28. /*-----------------------------------------------------------------------------------*/
  29. /* Flush rewrite rules to refresh permalinks for custom post types, etc. */
  30. /*-----------------------------------------------------------------------------------*/
  31. add_action( 'admin_head', 'woo_flush_rewriterules', 9 );
  32. function woo_flush_rewriterules () {
  33. flush_rewrite_rules();
  34. } // End woo_flush_rewriterules()
  35. /*-----------------------------------------------------------------------------------*/
  36. /* Add default options and show Options Panel after activate */
  37. /*-----------------------------------------------------------------------------------*/
  38. global $pagenow;
  39. if ( is_admin() && isset( $_GET['activated'] ) && $pagenow == 'themes.php' ) {
  40. // Call action that sets.
  41. add_action( 'admin_head','woo_option_setup' );
  42. // Flush rewrite rules.
  43. add_action( 'admin_head', 'woo_flush_rewriterules', 9 );
  44. // Custom action for theme-setup (redirect is at priority 10).
  45. do_action( 'woo_theme_activate' );
  46. }
  47. if ( ! function_exists( 'woo_option_setup' ) ) {
  48. function woo_option_setup(){
  49. //Update EMPTY options
  50. $woo_array = array();
  51. add_option( 'woo_options', $woo_array );
  52. $template = get_option( 'woo_template' );
  53. $saved_options = get_option( 'woo_options' );
  54. foreach ( (array) $template as $option ) {
  55. if ($option['type'] != 'heading'){
  56. $id = $option['id'];
  57. $std = isset( $option['std'] ) ? $option['std'] : NULL;
  58. $db_option = get_option($id);
  59. if (empty($db_option)){
  60. if (is_array($option['type'])) {
  61. foreach ($option['type'] as $child){
  62. $c_id = $child['id'];
  63. $c_std = $child['std'];
  64. $db_option = get_option($c_id);
  65. if (!empty($db_option)){
  66. update_option($c_id,$db_option);
  67. $woo_array[$id] = $db_option;
  68. } else {
  69. $woo_array[$c_id] = $c_std;
  70. }
  71. }
  72. } else {
  73. update_option($id,$std);
  74. $woo_array[$id] = $std;
  75. }
  76. } else { //So just store the old values over again.
  77. $woo_array[$id] = $db_option;
  78. }
  79. }
  80. }
  81. // Allow child themes/plugins to filter here.
  82. $woo_array = apply_filters( 'woo_options_array', $woo_array );
  83. update_option( 'woo_options', $woo_array );
  84. }
  85. }
  86. /*-----------------------------------------------------------------------------------*/
  87. /* Admin Backend */
  88. /*-----------------------------------------------------------------------------------*/
  89. if ( ! function_exists( 'woothemes_admin_head' ) ) {
  90. function woothemes_admin_head() {
  91. //Setup Custom Navigation Menu
  92. if ( function_exists( 'woo_custom_navigation_setup' ) ) {
  93. woo_custom_navigation_setup();
  94. }
  95. }
  96. }
  97. add_action( 'admin_head', 'woothemes_admin_head', 10 );
  98. /*-----------------------------------------------------------------------------------*/
  99. /* Output HEAD - woothemes_wp_head */
  100. /*-----------------------------------------------------------------------------------*/
  101. if ( ! function_exists( 'woothemes_wp_head' ) ) {
  102. function woothemes_wp_head() {
  103. do_action( 'woothemes_wp_head_before' );
  104. // Output alternative stylesheet
  105. if ( function_exists( 'woo_output_alt_stylesheet' ) )
  106. woo_output_alt_stylesheet();
  107. // Output custom favicon
  108. if ( function_exists( 'woo_output_custom_favicon' ) )
  109. woo_output_custom_favicon();
  110. // Output CSS from standarized styling options
  111. if ( function_exists( 'woo_head_css' ) )
  112. woo_head_css();
  113. // Output shortcodes stylesheet
  114. if ( function_exists( 'woo_shortcode_stylesheet' ) )
  115. woo_shortcode_stylesheet();
  116. // Output custom.css
  117. if ( function_exists( 'woo_output_custom_css' ) )
  118. woo_output_custom_css();
  119. do_action( 'woothemes_wp_head_after' );
  120. } // End woothemes_wp_head()
  121. }
  122. add_action( 'wp_head', 'woothemes_wp_head', 10 );
  123. /*-----------------------------------------------------------------------------------*/
  124. /* Output alternative stylesheet - woo_output_alt_stylesheet */
  125. /*-----------------------------------------------------------------------------------*/
  126. if ( ! function_exists( 'woo_output_alt_stylesheet' ) ) {
  127. function woo_output_alt_stylesheet() {
  128. $style = '';
  129. if ( isset( $_REQUEST['style'] ) ) {
  130. // Sanitize requested value.
  131. $requested_style = strtolower( strip_tags( trim( $_REQUEST['style'] ) ) );
  132. $style = $requested_style;
  133. }
  134. echo "<!-- Alt Stylesheet -->\n";
  135. if ($style != '') {
  136. echo '<link href="'. get_template_directory_uri() . '/styles/'. $style . '.css" rel="stylesheet" type="text/css" />' . "\n\n";
  137. } else {
  138. $style = get_option( 'woo_alt_stylesheet' );
  139. if( $style != '' ) {
  140. // Sanitize value.
  141. $style = strtolower( strip_tags( trim( $style ) ) );
  142. echo '<link href="'. get_template_directory_uri() . '/styles/'. $style .'" rel="stylesheet" type="text/css" />' . "\n\n";
  143. } else {
  144. echo '<link href="'. get_template_directory_uri() . '/styles/default.css" rel="stylesheet" type="text/css" />' . "\n\n";
  145. }
  146. }
  147. } // End woo_output_alt_stylesheet()
  148. }
  149. /*-----------------------------------------------------------------------------------*/
  150. /* Output favicon link - woo_custom_favicon() */
  151. /*-----------------------------------------------------------------------------------*/
  152. if ( ! function_exists( 'woo_output_custom_favicon' ) ) {
  153. function woo_output_custom_favicon() {
  154. // Favicon
  155. $favicon = '';
  156. $favicon = get_option( 'woo_custom_favicon' );
  157. // Allow child themes/plugins to filter here.
  158. $favicon = apply_filters( 'woo_custom_favicon', $favicon );
  159. if( $favicon != '' ) {
  160. echo "<!-- Custom Favicon -->\n";
  161. echo '<link rel="shortcut icon" href="' . esc_url( $favicon ) . '"/>' . "\n\n";
  162. }
  163. } // End woo_output_custom_favicon()
  164. }
  165. /*-----------------------------------------------------------------------------------*/
  166. /* Load textdomain - woo_load_textdomain() */
  167. /*-----------------------------------------------------------------------------------*/
  168. if ( ! function_exists( 'woo_load_textdomain' ) ) {
  169. function woo_load_textdomain() {
  170. load_theme_textdomain( 'woothemes' );
  171. load_theme_textdomain( 'woothemes', get_template_directory() . '/lang' );
  172. if ( function_exists( 'load_child_theme_textdomain' ) )
  173. load_child_theme_textdomain( 'woothemes' );
  174. }
  175. }
  176. add_action( 'init', 'woo_load_textdomain', 10 );
  177. /*-----------------------------------------------------------------------------------*/
  178. /* Output CSS from standarized options */
  179. /*-----------------------------------------------------------------------------------*/
  180. if ( ! function_exists( 'woo_head_css' ) ) {
  181. function woo_head_css() {
  182. $output = '';
  183. $text_title = get_option( 'woo_texttitle' );
  184. $tagline = get_option( 'woo_tagline' );
  185. $custom_css = get_option( 'woo_custom_css' );
  186. $template = get_option( 'woo_template' );
  187. if (is_array($template)) {
  188. foreach($template as $option){
  189. if(isset($option['id'])){
  190. if($option['id'] == 'woo_texttitle') {
  191. // Add CSS to output
  192. if ( $text_title == "true" ) {
  193. $output .= '#logo img { display:none; } #logo .site-title { display:block; }' . "\n";
  194. if ( $tagline == "false" )
  195. $output .= '#logo .site-description { display:none; }' . "\n";
  196. else
  197. $output .= '#logo .site-description { display:block; }' . "\n";
  198. }
  199. }
  200. }
  201. }
  202. }
  203. if ( $custom_css <> '' ) {
  204. $output .= $custom_css . "\n";
  205. }
  206. // Output styles
  207. if ( $output <> '' ) {
  208. $output = strip_tags($output);
  209. echo "<!-- Options Panel Custom CSS -->\n";
  210. $output = "<style type=\"text/css\">\n" . $output . "</style>\n\n";
  211. echo stripslashes( $output );
  212. }
  213. } // End woo_head_css()
  214. }
  215. /*-----------------------------------------------------------------------------------*/
  216. /* Output custom.css - woo_custom_css() */
  217. /*-----------------------------------------------------------------------------------*/
  218. if ( ! function_exists( 'woo_output_custom_css' ) ) {
  219. function woo_output_custom_css() {
  220. // Custom.css insert
  221. echo "<!-- Custom Stylesheet -->\n";
  222. echo '<link href="'. get_template_directory_uri() . '/custom.css" rel="stylesheet" type="text/css" />' . "\n";
  223. } // End woo_output_custom_css()
  224. }
  225. /*-----------------------------------------------------------------------------------*/
  226. /* Post Images from WP2.9+ integration /*
  227. /*-----------------------------------------------------------------------------------*/
  228. if( function_exists( 'add_theme_support' ) ) {
  229. if( get_option( 'woo_post_image_support' ) == 'true' ) {
  230. add_theme_support( 'post-thumbnails' );
  231. // set height, width and crop if dynamic resize functionality isn't enabled
  232. if ( get_option( 'woo_pis_resize' ) != 'true' ) {
  233. $thumb_width = get_option( 'woo_thumb_w' );
  234. $thumb_height = get_option( 'woo_thumb_h' );
  235. $single_width = get_option( 'woo_single_w' );
  236. $single_height = get_option( 'woo_single_h' );
  237. $hard_crop = get_option( 'woo_pis_hard_crop' );
  238. if($hard_crop == 'true') { $hard_crop = true; } else { $hard_crop = false; }
  239. set_post_thumbnail_size( $thumb_width, $thumb_height, $hard_crop ); // Normal post thumbnails
  240. add_image_size( 'single-post-thumbnail', $single_width, $single_height, $hard_crop );
  241. }
  242. }
  243. }
  244. /*-----------------------------------------------------------------------------------*/
  245. /* Enqueue comment reply script */
  246. /*-----------------------------------------------------------------------------------*/
  247. if ( ! function_exists( 'woo_comment_reply' ) ) {
  248. function woo_comment_reply() {
  249. if ( is_singular() ) wp_enqueue_script( 'comment-reply' );
  250. } // End woo_comment_reply()
  251. }
  252. add_action( 'get_header', 'woo_comment_reply', 10 );
  253. ?>