functions.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <?php
  2. /**
  3. * Spun functions and definitions
  4. *
  5. * @package Spun
  6. */
  7. # Automatically clear autoptimizeCache if it goes beyond 256MB
  8. if (class_exists('autoptimizeCache')) {
  9. $myMaxSize = 256000; # You may change this value to lower like 100000 for 100MB if you have limited server space
  10. $statArr=autoptimizeCache::stats();
  11. $cacheSize=round($statArr[1]/1024);
  12. if ($cacheSize>$myMaxSize){
  13. autoptimizeCache::clearall();
  14. header("Refresh:0"); # Refresh the page so that autoptimize can create new cache files and it does breaks the page after clearall.
  15. }
  16. }
  17. /**
  18. * Set the content width based on the theme's design and stylesheet.
  19. *
  20. */
  21. if ( ! isset( $content_width ) )
  22. $content_width = 700; /* pixels */
  23. if ( ! function_exists( 'spun_setup' ) ):
  24. /**
  25. * Sets up theme defaults and registers support for various WordPress features.
  26. *
  27. * Note that this function is hooked into the after_setup_theme hook, which runs
  28. * before the init hook. The init hook is too late for some features, such as indicating
  29. * support post thumbnails.
  30. *
  31. */
  32. function spun_setup() {
  33. /**
  34. * Make theme available for translation
  35. * Translations can be filed in the /languages/ directory
  36. * If you're building a theme based on Spun, use a find and replace
  37. * to change 'spun' to the name of your theme in all the template files
  38. */
  39. load_theme_textdomain( 'spun', get_template_directory() . '/languages' );
  40. /**
  41. * Add default posts and comments RSS feed links to head
  42. */
  43. add_theme_support( 'automatic-feed-links' );
  44. /**
  45. * Enable support for Post Thumbnails
  46. */
  47. add_theme_support( 'post-thumbnails' );
  48. add_image_size( 'home-post', 360, 360, true );
  49. add_image_size( 'single-post', 700, 999 );
  50. /**
  51. * This theme uses wp_nav_menu() in one location.
  52. */
  53. register_nav_menus( array(
  54. 'primary' => __( 'Primary Menu', 'spun' ),
  55. ) );
  56. /**
  57. * Add support for custom backgrounds
  58. */
  59. add_theme_support( 'custom-background' );
  60. /**
  61. * Add support for editor styles
  62. */
  63. add_editor_style();
  64. /**
  65. * Add support for Post Formats
  66. */
  67. add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link', 'status', 'gallery' ) );
  68. }
  69. endif; // spun_setup
  70. add_action( 'after_setup_theme', 'spun_setup' );
  71. /**
  72. * Register widgetized area and update sidebar with default widgets
  73. *
  74. */
  75. function spun_widgets_init() {
  76. register_sidebar( array(
  77. 'name' => __( 'Sidebar 1', 'spun' ),
  78. 'id' => 'sidebar-1',
  79. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  80. 'after_widget' => '</aside>',
  81. 'before_title' => '<h1 class="widget-title">',
  82. 'after_title' => '</h1>',
  83. ) );
  84. register_sidebar( array(
  85. 'name' => __( 'Sidebar 2', 'spun' ),
  86. 'id' => 'sidebar-2',
  87. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  88. 'after_widget' => '</aside>',
  89. 'before_title' => '<h1 class="widget-title">',
  90. 'after_title' => '</h1>',
  91. ) );
  92. register_sidebar( array(
  93. 'name' => __( 'Sidebar 3', 'spun' ),
  94. 'id' => 'sidebar-3',
  95. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  96. 'after_widget' => '</aside>',
  97. 'before_title' => '<h1 class="widget-title">',
  98. 'after_title' => '</h1>',
  99. ) );
  100. }
  101. add_action( 'widgets_init', 'spun_widgets_init' );
  102. /**
  103. * Enqueue scripts and styles
  104. */
  105. function spun_scripts() {
  106. wp_enqueue_style( 'style', get_stylesheet_uri() );
  107. wp_enqueue_script( 'spun-toggle', get_template_directory_uri() . '/js/toggle.js', array( 'jquery' ), '20121005', true );
  108. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  109. wp_enqueue_script( 'comment-reply' );
  110. }
  111. if ( is_singular() && wp_attachment_is_image() ) {
  112. wp_enqueue_script( 'keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20120202' );
  113. }
  114. wp_enqueue_style( 'spun-quicksand' );
  115. wp_enqueue_style( 'spun-playfair' );
  116. wp_enqueue_style( 'spun-nunito' );
  117. }
  118. add_action( 'wp_enqueue_scripts', 'spun_scripts', 1 );
  119. function spun_options_styles() {
  120. if ( false == get_theme_mod( 'spun_grayscale', false ) ) : ?>
  121. <style type="text/css">
  122. .blog .hentry a .attachment-home-post,
  123. .archive .hentry a .attachment-home-post,
  124. .search .hentry a .attachment-home-post {
  125. filter: grayscale(100%);
  126. -webkit-filter: grayscale(100%);
  127. -webkit-filter: grayscale(1); /* Older versions of webkit */
  128. -moz-filter: grayscale(100%);
  129. -o-filter: grayscale(100%);
  130. -ms-filter: grayscale(100%); /* IE 10 */
  131. filter: gray; /* IE 9 */
  132. filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale"); /* Firefox */
  133. }
  134. @media screen and ( max-width: 800px ) {
  135. /* Remove hover effects for touchscreens */
  136. .blog .hentry a .attachment-home-post,
  137. .archive .hentry a .attachment-home-post,
  138. .search .hentry a .attachment-home-post {
  139. filter:none;
  140. -webkit-filter:none;
  141. -moz-filter:none;
  142. -o-filter:none;
  143. }
  144. }
  145. </style>
  146. <?php
  147. endif;
  148. if ( false == get_theme_mod( 'spun_opacity', false ) ) : ?>
  149. <style type="text/css">
  150. .site-content #nav-below .nav-previous a,
  151. .site-content #nav-below .nav-next a,
  152. .site-content #image-navigation .nav-previous a,
  153. .site-content #image-navigation .nav-next a,
  154. .comment-navigation .nav-next,
  155. .comment-navigation .nav-previous,
  156. #infinite-handle span,
  157. .sidebar-link,
  158. a.comment-reply-link,
  159. a#cancel-comment-reply-link,
  160. .comments-link a,
  161. .hentry.no-thumbnail,
  162. button,
  163. html input[type="button"],
  164. input[type="reset"],
  165. input[type="submit"],
  166. .site-footer {
  167. opacity: .2;
  168. }
  169. .site-header,
  170. .entry-meta-wrapper,
  171. .comment-meta,
  172. .page-links span.active-link,
  173. .page-links a span.active-link {
  174. opacity: .3;
  175. }
  176. @media screen and ( max-width: 800px ) {
  177. /* Increase opacity for small screen sizes and touch screens */
  178. .site-header,
  179. .site-content #nav-below .nav-previous a,
  180. .site-content #nav-below .nav-next a,
  181. .site-content #image-navigation .nav-previous a,
  182. .site-content #image-navigation .nav-next a,
  183. .comment-navigation .nav-next a,
  184. .comment-navigation .nav-previous a,
  185. #infinite-handle span,
  186. .sidebar-link,
  187. a.comment-reply-link,
  188. a#cancel-comment-reply-link,
  189. .site-footer,
  190. .comments-link a,
  191. .comment-meta,
  192. .entry-meta-wrapper,
  193. .hentry.no-thumbnail,
  194. .page-links span.active-link,
  195. .page-links a span.active-link {
  196. opacity: 1;
  197. }
  198. }
  199. </style>
  200. <?php
  201. endif;
  202. if ( false == get_theme_mod( 'spun_titles', false ) ) : ?>
  203. <style type="text/css">
  204. .hentry .thumbnail-title {
  205. display: none;
  206. }
  207. </style>
  208. <?php
  209. endif;
  210. }
  211. add_action( 'wp_head', 'spun_options_styles', 1 );
  212. /**
  213. * Register Google Fonts
  214. */
  215. function spun_google_fonts() {
  216. $protocol = is_ssl() ? 'https' : 'http';
  217. /* translators: If there are characters in your language that are not supported
  218. by Playfair, translate this to 'off'. Do not translate into your own language. */
  219. if ( 'off' !== _x( 'on', 'Playfair font: on or off', 'spun' ) ) {
  220. wp_register_style( 'spun-playfair', "$protocol://fonts.googleapis.com/css?family=Playfair+Display:400,700,400italic,700italic" );
  221. }
  222. /* translators: If there are characters in your language that are not supported
  223. by Quicksand, translate this to 'off'. Do not translate into your own language. */
  224. if ( 'off' !== _x( 'on', 'Quicksand font: on or off', 'spun' ) ) {
  225. wp_register_style( 'spun-quicksand', "$protocol://fonts.googleapis.com/css?family=Quicksand:300" );
  226. }
  227. /* translators: If there are characters in your language that are not supported
  228. by Nunito, translate this to 'off'. Do not translate into your own language. */
  229. if ( 'off' !== _x( 'on', 'Nunito font: on or off', 'spun' ) ) {
  230. wp_register_style( 'spun-nunito', "$protocol://fonts.googleapis.com/css?family=Nunito:300" );
  231. }
  232. }
  233. add_action( 'init', 'spun_google_fonts' );
  234. /**
  235. * Filter TinyMCE CSS path to include Google Fonts.
  236. *
  237. * Adds additional stylesheets to the TinyMCE editor if needed.
  238. *
  239. * @param string $mce_css CSS path to load in TinyMCE.
  240. * @return string Filtered CSS path.
  241. */
  242. function typo_mce_css( $mce_css ) {
  243. $protocol = is_ssl() ? 'https' : 'http';
  244. $font_url = $protocol . '://fonts.googleapis.com/css?family=Quicksand:300|Playfair+Display:400,700,400italic,700italic';
  245. if ( empty( $font_url ) )
  246. return $mce_css;
  247. if ( ! empty( $mce_css ) )
  248. $mce_css .= ',';
  249. $mce_css .= esc_url_raw( str_replace( ',', '%2C', $font_url ) );
  250. return $mce_css;
  251. }
  252. add_filter( 'mce_css', 'typo_mce_css' );
  253. /**
  254. * Enqueue Google Fonts for custom headers
  255. */
  256. function spun_admin_scripts( $hook_suffix ) {
  257. if ( 'appearance_page_custom-header' != $hook_suffix )
  258. return;
  259. wp_enqueue_style( 'spun-playfair' );
  260. wp_enqueue_style( 'spun-quicksand' );
  261. }
  262. add_action( 'admin_enqueue_scripts', 'spun_admin_scripts' );
  263. /**
  264. * Implement the Custom Header feature
  265. */
  266. require( get_template_directory() . '/inc/custom-header.php' );
  267. /**
  268. * Load Jetpack compatibility file.
  269. */
  270. if ( file_exists( get_template_directory() . '/inc/jetpack.php' ) )
  271. require get_template_directory() . '/inc/jetpack.php';
  272. /**
  273. * Custom template tags for this theme.
  274. */
  275. require( get_template_directory() . '/inc/template-tags.php' );
  276. /**
  277. * Custom functions that act independently of the theme templates
  278. */
  279. require( get_template_directory() . '/inc/extras.php' );
  280. /**
  281. * Customizer support for theme options
  282. */
  283. require( get_template_directory() . '/inc/customizer.php' );
  284. // updater for WordPress.com themes
  285. if ( is_admin() )
  286. include dirname( __FILE__ ) . '/inc/updater.php';