Share this diff
168 lines added. 178 lines deleted.
1<?php 1<?php
2/** 2/**
3 * Spun functions and definitions 3 * Spun functions and definitions
4 * 4 *
5 * @package Spun 5 * @package Spun
6 * @since Spun 1.0  
7 */ 6 */
8 7
9/** 8/**
10 * Set the content width based on the theme's design and stylesheet. 9 * Set the content width based on the theme's design and stylesheet.
11 * 10 *
12 * @since Spun 1.0  
13 */ 11 */
14if ( ! isset( $content_width ) ) 12if ( ! isset( $content_width ) )
15 $content_width = 640; /* pixels */13 $content_width = 700; /* pixels */
16 14
17if ( ! function_exists( 'spun_setup' ) ): 15if ( ! function_exists( 'spun_setup' ) ):
18/** 16/**
19 * Sets up theme defaults and registers support for various WordPress features. 17 * Sets up theme defaults and registers support for various WordPress features.
20 * 18 *
21 * Note that this function is hooked into the after_setup_theme hook, which runs 19 * Note that this function is hooked into the after_setup_theme hook, which runs
22 * before the init hook. The init hook is too late for some features, such as indicating 20 * before the init hook. The init hook is too late for some features, such as indicating
23 * support post thumbnails. 21 * support post thumbnails.
24 * 22 *
25 * @since Spun 1.0  
26 */ 23 */
27function spun_setup() { 24function spun_setup() {
28 25
29 /** 26 /**
30 * Custom template tags for this theme.  
31 */  
32 require( get_template_directory() . '/inc/template-tags.php' );  
33  
34 /**  
35 * Custom functions that act independently of the theme templates  
36 */  
37 require( get_template_directory() . '/inc/tweaks.php' );  
38  
39 /* Jetpack Infinite Scroll */  
40 add_theme_support( 'infinite-scroll', array(  
41 'container' => 'content',  
42 'footer' => 'page',  
43 'render' => 'spun_infinite_scroll',  
44 'posts_per_page' => 15,  
45 'footer_widgets' => array( 'sidebar-1', 'sidebar-2', 'sidebar-3' ),  
46 ) );  
47  
48 /* Load the proper content template */  
49 function spun_infinite_scroll() {  
50 while( have_posts() ) {  
51 the_post();  
52  
53 get_template_part( 'content', 'home' );  
54 }  
55 }  
56  
57 /**  
58 * Make theme available for translation 27 * Make theme available for translation
59 * Translations can be filed in the /languages/ directory 28 * Translations can be filed in the /languages/ directory
60 * If you're building a theme based on Spun, use a find and replace 29 * If you're building a theme based on Spun, use a find and replace
61 * to change 'spun' to the name of your theme in all the template files 30 * to change 'spun' to the name of your theme in all the template files
62 */ 31 */
63 load_theme_textdomain( 'spun', get_template_directory() . '/languages' ); 32 load_theme_textdomain( 'spun', get_template_directory() . '/languages' );
64 33
65 /** 34 /**
66 * Add default posts and comments RSS feed links to head 35 * Add default posts and comments RSS feed links to head
67 */ 36 */
68 add_theme_support( 'automatic-feed-links' ); 37 add_theme_support( 'automatic-feed-links' );
69 38
70 /** 39 /**
71 * Enable support for Post Thumbnails 40 * Enable support for Post Thumbnails
72 */ 41 */
73 add_theme_support( 'post-thumbnails' ); 42 add_theme_support( 'post-thumbnails' );
74 set_post_thumbnail_size( 360, 360, true );43 add_image_size( 'home-post', 360, 360, true );
75 add_image_size( 'single-post', 700, 467, true );44 add_image_size( 'single-post', 700, 999 );
76 45
77 /** 46 /**
78 * This theme uses wp_nav_menu() in one location. 47 * This theme uses wp_nav_menu() in one location.
79 */ 48 */
80 register_nav_menus( array( 49 register_nav_menus( array(
81 'primary' => __( 'Primary Menu', 'spun' ), 50 'primary' => __( 'Primary Menu', 'spun' ),
82 ) ); 51 ) );
83 52
84 /** 53 /**
85 * Add support for custom backgrounds 54 * Add support for custom backgrounds
86 */ 55 */
87  
88 add_theme_support( 'custom-background' ); 56 add_theme_support( 'custom-background' );
 57
 58 /**
 59 * Add support for editor styles
 60 */
 61 add_editor_style();
89 62
90 /** 63 /**
91 * Add support for Post Formats 64 * Add support for Post Formats
92 */ 65 */
93 add_theme_support( 'post-formats', array( 'aside', 'gallery', 'image', 'quote', 'status' ) );66 add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link', 'status', 'gallery' ) );
94 67
95} 68}
96endif; // spun_setup 69endif; // spun_setup
97add_action( 'after_setup_theme', 'spun_setup' ); 70add_action( 'after_setup_theme', 'spun_setup' );
98 71
99/* Filter to add author credit to Infinite Scroll footer */  
100function spun_footer_credits( $credit ) {  
101 $credit = sprintf( __( '%3$s | Theme: %1$s by %2$s.', 'spun' ), 'Spun', '<a href="http://carolinemoore.net/" rel="designer">Caroline Moore</a>', '<a href="http://wordpress.org/" title="' . esc_attr( __( 'A Semantic Personal Publishing Platform', 'spun' ) ) . '" rel="generator">Proudly powered by WordPress</a>' );  
102 return $credit;  
103}  
104add_filter( 'infinite_scroll_credit', 'spun_footer_credits' );  
105  
106/**  
107 * Filter archives to display one less post per page to account for the .page-title circle  
108 */  
109function limit_posts_per_archive_page() {  
110  
111 if ( ! is_home() && is_archive() || is_search() ) {  
112  
113 $posts_per_page = intval( get_option( 'posts_per_page' ) ) - 1;  
114 set_query_var( 'posts_per_page', $posts_per_page );  
115 }  
116}  
117add_filter( 'pre_get_posts', 'limit_posts_per_archive_page' );  
118  
119  
120/** 72/**
121 * Register widgetized area and update sidebar with default widgets 73 * Register widgetized area and update sidebar with default widgets
122 * 74 *
123 * @since Spun 1.0  
124 */ 75 */
125function spun_widgets_init() { 76function spun_widgets_init() {
126 register_sidebar( array( 77 register_sidebar( array(
127 'name' => __( 'Sidebar 1', 'spun' ), 78 'name' => __( 'Sidebar 1', 'spun' ),
128 'id' => 'sidebar-1', 79 'id' => 'sidebar-1',
129 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 80 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
130 'after_widget' => '</aside>', 81 'after_widget' => '</aside>',
131 'before_title' => '<h1 class="widget-title">', 82 'before_title' => '<h1 class="widget-title">',
132 'after_title' => '</h1>', 83 'after_title' => '</h1>',
133 ) ); 84 ) );
134 register_sidebar( array( 85 register_sidebar( array(
135 'name' => __( 'Sidebar 2', 'spun' ), 86 'name' => __( 'Sidebar 2', 'spun' ),
136 'id' => 'sidebar-2', 87 'id' => 'sidebar-2',
137 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 88 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
138 'after_widget' => '</aside>', 89 'after_widget' => '</aside>',
139 'before_title' => '<h1 class="widget-title">', 90 'before_title' => '<h1 class="widget-title">',
140 'after_title' => '</h1>', 91 'after_title' => '</h1>',
141 ) ); 92 ) );
142 register_sidebar( array( 93 register_sidebar( array(
143 'name' => __( 'Sidebar 3', 'spun' ), 94 'name' => __( 'Sidebar 3', 'spun' ),
144 'id' => 'sidebar-3', 95 'id' => 'sidebar-3',
145 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 96 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
146 'after_widget' => '</aside>', 97 'after_widget' => '</aside>',
147 'before_title' => '<h1 class="widget-title">', 98 'before_title' => '<h1 class="widget-title">',
148 'after_title' => '</h1>', 99 'after_title' => '</h1>',
149 ) ); 100 ) );
150} 101}
151add_action( 'widgets_init', 'spun_widgets_init' ); 102add_action( 'widgets_init', 'spun_widgets_init' );
152 103
153 104
154/** 105/**
155 * Enqueue scripts and styles 106 * Enqueue scripts and styles
156 */ 107 */
157function spun_scripts() { 108function spun_scripts() {
158 109
159 wp_enqueue_style( 'style', get_stylesheet_uri() ); 110 wp_enqueue_style( 'style', get_stylesheet_uri() );
160 111
161 wp_enqueue_script( 'spun-toggle', get_template_directory_uri() . '/js/toggle.js', array( 'jquery' ), '20121005', true ); 112 wp_enqueue_script( 'spun-toggle', get_template_directory_uri() . '/js/toggle.js', array( 'jquery' ), '20121005', true );
162 113
163 if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { 114 if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
164 wp_enqueue_script( 'comment-reply' ); 115 wp_enqueue_script( 'comment-reply' );
165 } 116 }
166 117
167 if ( is_singular() && wp_attachment_is_image() ) { 118 if ( is_singular() && wp_attachment_is_image() ) {
168 wp_enqueue_script( 'keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20120202' ); 119 wp_enqueue_script( 'keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20120202' );
169 } 120 }
170 121
171 wp_enqueue_style( 'spun-quicksand' ); 122 wp_enqueue_style( 'spun-quicksand' );
172 wp_enqueue_style( 'spun-playfair' ); 123 wp_enqueue_style( 'spun-playfair' );
173 wp_enqueue_style( 'spun-nunito' ); 124 wp_enqueue_style( 'spun-nunito' );
174 125
175} 126}
176add_action( 'wp_enqueue_scripts', 'spun_scripts', 1 ); 127add_action( 'wp_enqueue_scripts', 'spun_scripts', 1 );
177 128
178 129function spun_options_styles() {
179/*130 if ( false == get_theme_mod( 'spun_grayscale', false ) ) : ?>
180 * Change the theme's accent color131 <style type="text/css">
181 * Not yet working with the Customizer132 .blog .hentry a .attachment-home-post,
182 * @todo find a way to reset to default values133 .archive .hentry a .attachment-home-post,
183 * /134 .search .hentry a .attachment-home-post {
184 function spun_custom_color() {135 filter: grayscale(100%);
185 //If a custom accent color is set, use it!136 -webkit-filter: grayscale(100%);
186 if ( '' != get_theme_mod( 'spun_color' ) ) {137 -webkit-filter: grayscale(1); /* Older versions of webkit */
187 138 -moz-filter: grayscale(100%);
188 $color = esc_html( get_theme_mod( 'spun_color' ) ); ?>139 -o-filter: grayscale(100%);
189 140 -ms-filter: grayscale(100%); /* IE 10 */
 141 filter: gray; /* IE 9 */
 142 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 */
 143 }
 144 @media screen and ( max-width: 800px ) {
 145 /* Remove hover effects for touchscreens */
 146 .blog .hentry a .attachment-home-post,
 147 .archive .hentry a .attachment-home-post,
 148 .search .hentry a .attachment-home-post {
 149 filter:none;
 150 -webkit-filter:none;
 151 -moz-filter:none;
 152 -o-filter:none;
 153 }
 154 }
 155 </style>
 156 <?php
 157 endif;
 158
 159 if ( false == get_theme_mod( 'spun_opacity', false ) ) : ?>
190 <style type="text/css"> 160 <style type="text/css">
191 ::selection,161 .site-content #nav-below .nav-previous a,
192 button:hover,162 .site-content #nav-below .nav-next a,
193 html input[type="button"]:hover,163 .site-content #image-navigation .nav-previous a,
194 input[type="reset"]:hover,164 .site-content #image-navigation .nav-next a,
195 input[type="submit"]:hover,165 .comment-navigation .nav-next,
196 .site-description,166 .comment-navigation .nav-previous,
197 .hentry.no-thumbnail:hover,167 #infinite-handle span,
198 .page-links a:hover span.active-link,168 .sidebar-link,
 169 a.comment-reply-link,
 170 a#cancel-comment-reply-link,
 171 .comments-link a,
 172 .hentry.no-thumbnail,
 173 button,
 174 html input[type="button"],
 175 input[type="reset"],
 176 input[type="submit"],
 177 .site-footer {
 178 opacity: .2;
 179 }
 180 .site-header,
 181 .entry-meta-wrapper,
 182 .comment-meta,
199 .page-links span.active-link, 183 .page-links span.active-link,
200 .page-header h1,184 .page-links a span.active-link {
201 a.comment-reply-link:hover,185 opacity: .3;
202 a#cancel-comment-reply-link:hover,  
203 .comments-link a:hover,  
204 .sidebar-link:hover {  
205 background-color: <?php echo $color; ?>;  
206 } 186 }
207 .comments-link a:hover .tail {187 @media screen and ( max-width: 800px ) {
208 border-top-color: <?php echo $color; ?>;188 /* Increase opacity for small screen sizes and touch screens */
 189 .site-header,
 190 .site-content #nav-below .nav-previous a,
 191 .site-content #nav-below .nav-next a,
 192 .site-content #image-navigation .nav-previous a,
 193 .site-content #image-navigation .nav-next a,
 194 .comment-navigation .nav-next a,
 195 .comment-navigation .nav-previous a,
 196 #infinite-handle span,
 197 .sidebar-link,
 198 a.comment-reply-link,
 199 a#cancel-comment-reply-link,
 200 .site-footer,
 201 .comments-link a,
 202 .comment-meta,
 203 .entry-meta-wrapper,
 204 .hentry.no-thumbnail,
 205 .page-links span.active-link,
 206 .page-links a span.active-link {
 207 opacity: 1;
 208 }
209 } 209 }
210 .entry-title,210 </style>
211 .entry-title a,211 <?php
212 .entry-content a,212 endif;
213 .entry-content a:visited,213
214 .widget a,214 if ( false == get_theme_mod( 'spun_titles', false ) ) : ?>
215 .widget a:visited,215 <style type="text/css">
216 .main-navigation a,216 .hentry .thumbnail-title {
217 .main-navigation a:visited,217 display: none;
218 .main-navigation ul ul .parent > a::after,  
219 .main-small-navigation a,  
220 .main-small-navigation a:visited,  
221 .menu-toggle {  
222 color: <?php echo $color; ?>;  
223 } 218 }
224 </style> 219 </style>
225 <?php220 <?php
226 }221 endif;
227} 222}
228 223add_action( 'wp_head', 'spun_options_styles', 1 );
229if ( '' != get_theme_mod( 'spun_color' ) )  
230 add_action( 'wp_head', 'spun_custom_color', 99 );*/  
231 224
232/** 225/**
233 * Enqueue scripts and styles in custom header admin226 * Register Google Fonts
234 */ 227 */
235function spun_admin_scripts( $hook_suffix ) {228function spun_google_fonts() {
236 229
237 if ( 'appearance_page_custom-header' != $hook_suffix )230 $protocol = is_ssl() ? 'https' : 'http';
238 return;  
239 231
240 wp_enqueue_style( 'spun-playfair' );232 /* translators: If there are characters in your language that are not supported
 233 by Playfair, translate this to 'off'. Do not translate into your own language. */
241 234
242}235 if ( 'off' !== _x( 'on', 'Playfair font: on or off', 'spun' ) ) {
243add_action( 'admin_enqueue_scripts', 'spun_admin_scripts' );  
244 236
245/**237 wp_register_style( 'spun-playfair', "$protocol://fonts.googleapis.com/css?family=Playfair+Display:400,700,400italic,700i
talic" );
246 * Register Google Fonts  
247 */  
248function spun_register_fonts() {  
249 238
250 $protocol = is_ssl() ? 'https' : 'http';239 }
 240
 241 /* translators: If there are characters in your language that are not supported
 242 by Quicksand, translate this to 'off'. Do not translate into your own language. */
251 243
252 wp_register_style(244 if ( 'off' !== _x( 'on', 'Quicksand font: on or off', 'spun' ) ) {
253 'spun-quicksand',  
254 "$protocol://fonts.googleapis.com/css?family=Quicksand:300",  
255 array(),  
256 '20121005'  
257 );  
258 wp_register_style(  
259 'spun-playfair',  
260 "$protocol://fonts.googleapis.com/css?family=Playfair+Display:400,700,400italic,7
00italic",
 
261 array(),  
262 '20121005'  
263 );  
264 wp_register_style(  
265 'spun-nunito',  
266 "$protocol://fonts.googleapis.com/css?family=Nunito:300",  
267 array(),  
268 '20121005'  
269 );  
270}  
271add_action( 'init', 'spun_register_fonts' );  
272 245
 246 wp_register_style( 'spun-quicksand', "$protocol://fonts.googleapis.com/css?family=Quicksand:300" );
273 247
274/**248 }
275 * Implement the Custom Header feature249
276 */250 /* translators: If there are characters in your language that are not supported
277require( get_template_directory() . '/inc/custom-header.php' );251 by Nunito, translate this to 'off'. Do not translate into your own language. */
278 252
279/**253 if ( 'off' !== _x( 'on', 'Nunito font: on or off', 'spun' ) ) {
280 * Remove widget title header if no title is entered.  
281 * @todo Remove this function when this is fixed in core.  
282 */  
283 254
284function spun_calendar_widget_title( $title = '', $instance = '', $id_base = '' ) {255 wp_register_style( 'spun-nunito', "$protocol://fonts.googleapis.com/css?family=Nunito:300" );
285 256
286 if ( 'calendar' == $id_base && '&nbsp;' == $title )257 }
287 $title = '';  
288 return $title;  
289}  
290add_filter( 'widget_title', 'spun_calendar_widget_title', 10, 3 );  
291 258
 259}
 260add_action( 'init', 'spun_google_fonts' );
292 261
293/** 262/**
294 * Count the number of active sidebars and generate an ID to style them.263 * Filter TinyMCE CSS path to include Google Fonts.
 264 *
 265 * Adds additional stylesheets to the TinyMCE editor if needed.
 266 *
 267 * @param string $mce_css CSS path to load in TinyMCE.
 268 * @return string Filtered CSS path.
295 */ 269 */
 270function typo_mce_css( $mce_css ) {
 271 $protocol = is_ssl() ? 'https' : 'http';
 272 $font_url = $protocol . '://fonts.googleapis.com/css?family=Quicksand:300|Playfair+Display:400,700,400italic
,700italic';
296 273
297function spun_count_sidebars() {274 if ( empty( $font_url ) )
298 $count = 0;275 return $mce_css;
299  
300 if ( is_active_sidebar( 'sidebar-1' ) || is_active_sidebar( 'sidebar-2' ) || is_active_sidebar( 'sidebar-3' ) )  
301 $count = 'one';  
302 276
303 if ( is_active_sidebar( 'sidebar-1' ) && is_active_sidebar( 'sidebar-2' ) ||277 if ( ! empty( $mce_css ) )
304 is_active_sidebar( 'sidebar-1' ) && is_active_sidebar( 'sidebar-3' ) ||278 $mce_css .= ',';
305 is_active_sidebar( 'sidebar-2' ) && is_active_sidebar( 'sidebar-3' ) )  
306 $count = 'two';  
307 279
308 if ( is_active_sidebar( 'sidebar-1' ) && is_active_sidebar( 'sidebar-2' ) && is_active_sidebar( 'sidebar-3' ) )280 $mce_css .= esc_url_raw( str_replace( ',', '%2C', $font_url ) );
309 $count = 'three';  
310 281
311 print $count;282 return $mce_css;
312} 283}
313 284add_filter( 'mce_css', 'typo_mce_css' );
314 285
315/** 286/**
316 * Add color change theme options in the Customizer287 * Enqueue Google Fonts for custom headers
317 * @todo find a way to reset to default values288 */
318 289function spun_admin_scripts( $hook_suffix ) {
319function spun_customize( $wp_customize ) {  
320 290
321 $wp_customize->add_setting( 'spun_color', array(291 if ( 'appearance_page_custom-header' != $hook_suffix )
322 'default' => '',292 return;
323 ) );  
324 293
325 $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'spun_color', array(294 wp_enqueue_style( 'spun-playfair' );
326 'label' => 'Accent Color',295 wp_enqueue_style( 'spun-quicksand' );
327 'section' => 'colors',  
328 'default' => '',  
329 )  
330 ) );  
331 296
332} 297}
 298add_action( 'admin_enqueue_scripts', 'spun_admin_scripts' );
 299
 300/**
 301 * Implement the Custom Header feature
 302 */
 303require( get_template_directory() . '/inc/custom-header.php' );
 304
 305/**
 306 * Load Jetpack compatibility file.
 307 */
 308if ( file_exists( get_template_directory() . '/inc/jetpack.php' ) )
 309 require get_template_directory() . '/inc/jetpack.php';
 310
 311/**
 312 * Custom template tags for this theme.
 313 */
 314require( get_template_directory() . '/inc/template-tags.php' );
333 315
334add_action( 'customize_register', 'spun_customize' );*/316/**
 317 * Custom functions that act independently of the theme templates
 318 */
 319require( get_template_directory() . '/inc/extras.php' );
 320
 321/**
 322 * Customizer support for theme options
 323 */
 324require( get_template_directory() . '/inc/customizer.php' );
ORIGINAL TEXT
CHANGED TEXT