Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 449 lines (372 sloc) 13.911 kb
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
1 <?php
2 /**
3 * The functions file is used to initialize everything in the theme. It controls how the theme is loaded and
4 * sets up the supported features, default actions, and default filters. If making customizations, users
5 * should create a child theme and make changes to its functions.php file (not this one). Friends don't let
6 * friends modify parent theme files. ;)
7 *
8 * Child themes should do their setup on the 'after_setup_theme' hook with a priority of 11 if they want to
9 * override parent theme features. Use a priority of 9 if wanting to run before the parent theme.
10 *
11 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
877f5cf Justin Tadlock Update copyright and theme info.
authored
12 * General Public License as published by the Free Software Foundation; either version 2 of the License,
13 * or (at your option) any later version.
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
14 *
15 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
16 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 *
18 * You should have received a copy of the GNU General Public License along with this program; if not, write
19 * to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 * @package MyLife
22 * @subpackage Functions
1696aa7 Justin Tadlock Version bump to 0.2 beta.
authored
23 * @version 0.2.0
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
24 * @since 0.1.0
25 * @author Justin Tadlock <justin@justintadlock.com>
877f5cf Justin Tadlock Update copyright and theme info.
authored
26 * @copyright Copyright (c) 2011 - 2012, Justin Tadlock
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
27 * @link http://themehybrid.com/themes/my-life
28 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
29 */
30
31 /* Load the core theme framework. */
e2f6121 Justin Tadlock Update call to the framework.
authored
32 require_once( trailingslashit( get_template_directory() ) . 'library/hybrid.php' );
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
33 new Hybrid();
34
35 /* Do theme setup on the 'after_setup_theme' hook. */
36 add_action( 'after_setup_theme', 'my_life_theme_setup' );
37
38 /**
39 * Theme setup function. This function adds support for theme features and defines the default theme
40 * actions and filters.
41 *
42 * @since 0.1.0
43 */
44 function my_life_theme_setup() {
45
46 /* Get action/filter hook prefix. */
47 $prefix = hybrid_get_prefix();
48
49 /* Add theme support for core framework features. */
50 add_theme_support( 'hybrid-core-menus', array( 'primary', 'secondary', 'subsidiary' ) );
51 add_theme_support( 'hybrid-core-sidebars', array( 'primary', 'secondary' ) );
52 add_theme_support( 'hybrid-core-widgets' );
53 add_theme_support( 'hybrid-core-shortcodes' );
54 add_theme_support( 'hybrid-core-theme-settings', array( 'about', 'footer' ) );
55 add_theme_support( 'hybrid-core-drop-downs' );
56 add_theme_support( 'hybrid-core-template-hierarchy' );
57 //add_theme_support( 'hybrid-core-seo' );
58
59 /* Add theme support for framework extensions. */
60 add_theme_support( 'theme-layouts', array( '1c', '2c-l', '2c-r', '3c-l', '3c-r', '3c-c' ) );
61 add_theme_support( 'post-stylesheets' );
62 add_theme_support( 'dev-stylesheet' );
63 add_theme_support( 'loop-pagination' );
64 add_theme_support( 'get-the-image' );
65 add_theme_support( 'breadcrumb-trail' );
66 add_theme_support( 'cleaner-gallery' );
67 add_theme_support( 'cleaner-caption' );
68
69 /* Add theme support for WordPress features. */
70 add_theme_support( 'automatic-feed-links' );
71 add_theme_support( 'post-formats', array( 'aside', 'audio', 'image', 'gallery', 'link', 'quote', 'status', 'video' ) );
be30b02 Justin Tadlock Switch to newer 'custom-background' theme feature.
authored
72
73 /* Add support for a custom background. */
74 add_theme_support(
75 'custom-background',
76 array(
77 'default-image' => trailingslashit( get_template_directory_uri() ) . 'images/bg.png',
78 )
79 );
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
80
189b722 Justin Tadlock Switch to the new 'custom-header' theme feature.
authored
81 /* Add support for a custom header image. */
82 add_theme_support(
83 'custom-header',
84 array(
85 'default-image' => 'remove-header',
86 'width' => 1000,
87 'height' => 200,
88 'header-text' => false,
89 'wp-head-callback' => '__return_false',
90 'admin-head-callback' => '__return_false',
91 )
92 );
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
93
94 /* Embed width/height defaults. */
95 add_filter( 'embed_defaults', 'my_life_embed_defaults' );
96
97 /* Set content width. */
98 hybrid_set_content_width( 600 );
99
100 /* Filter the sidebar widgets. */
101 add_filter( 'sidebars_widgets', 'my_life_disable_sidebars' );
102 add_action( 'template_redirect', 'my_life_one_column' );
103
104 /* Add classes to the comments pagination. */
105 add_filter( 'previous_comments_link_attributes', 'my_life_previous_comments_link_attributes' );
106 add_filter( 'next_comments_link_attributes', 'my_life_next_comments_link_attributes' );
107
108 /* Add custom image sizes. */
109 add_action( 'init', 'my_life_add_image_sizes' );
110
111 /* Wraps <blockquote> around quote posts. */
112 add_filter( 'the_content', 'my_life_quote_content' );
113
114 /* Adds the featured image to image posts if no content is found. */
115 add_filter( 'the_content', 'my_life_image_content' );
116
117 /* Filter the header image on singular views. */
118 add_filter( 'theme_mod_header_image', 'my_life_header_image' );
119
120 /* Filters the image/gallery post format archive galleries. */
121 add_filter( "{$prefix}_post_format_archive_gallery_columns", 'my_life_archive_gallery_columns' );
122 }
123
124 /**
125 * Sets the number of columns to show on image and gallery post format archives pages based on the
126 * layout that is currently being used.
127 *
128 * @since 0.1.0
129 * @param int $columns Number of gallery columns to display.
130 * @return int $columns
131 */
132 function my_life_archive_gallery_columns( $columns ) {
133
134 /* Only run the code if the theme supports the 'theme-layouts' feature. */
135 if ( current_theme_supports( 'theme-layouts' ) ) {
136
137 /* Get the current theme layout. */
138 $layout = theme_layouts_get_layout();
139
140 if ( 'layout-1c' == $layout )
141 $columns = 4;
142
143 elseif ( in_array( $layout, array( 'layout-3c-l', 'layout-3c-r', 'layout-3c-c' ) ) )
144 $columns = 2;
145 }
146
147 return $columns;
148 }
149
150 /**
151 * Filter for the "theme_mod_header_image" hook, which returns the header image URL. This allows the user
152 * to change the header image on a per-post basis by uploading a feature image large enough to display as a
153 * header image.
154 *
155 * @since 0.1.0
156 * @param string $url The URL of the current header image.
157 * @return string $url
158 */
159 function my_life_header_image( $url ) {
160
161 if ( is_singular() && 'remove-header' !== $url ) {
162
163 $post_id = get_queried_object_id();
164
165 if ( is_attachment() && wp_attachment_is_image( $post_id ) )
166 $thumbnail_id = $post_id;
167
168 elseif ( has_post_thumbnail( $post_id ) )
169 $thumbnail_id = get_post_thumbnail_id( $post_id );
170
171 if ( !empty( $thumbnail_id ) ) {
172
646d6fe Finalizing version 0.1 changes.
greenshady authored
173 $image = wp_get_attachment_image_src( $thumbnail_id, 'header' );
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
174
175 if ( $image[1] >= HEADER_IMAGE_WIDTH && $image[2] >= HEADER_IMAGE_HEIGHT )
176 $url = $image[0];
177 }
178 }
179
180 return $url;
181 }
182
183 /**
184 * Wraps the output of the quote post format content in a <blockquote> element if the user hasn't added a
185 * <blockquote> in the post editor.
186 *
187 * @since 0.1.0
188 * @param string $content The post content.
189 * @return string $content
190 */
191 function my_life_quote_content( $content ) {
192
193 if ( has_post_format( 'quote' ) ) {
194 preg_match( '/<blockquote.*?>/', $content, $matches );
195
196 if ( empty( $matches ) )
197 $content = "<blockquote>{$content}</blockquote>";
198 }
199
200 return $content;
201 }
202
203 /**
204 * Returns the featured image for the image post format if the user didn't add any content to the post.
205 *
206 * @since 0.1.0
207 * @param string $content The post content.
208 * @return string $content
209 */
210 function my_life_image_content( $content ) {
211
212 if ( has_post_format( 'image' ) && '' == $content ) {
213 if ( is_singular() )
214 $content = get_the_image( array( 'size' => 'full', 'meta_key' => false, 'link_to_post' => false ) );
215 else
216 $content = get_the_image( array( 'size' => 'full', 'meta_key' => false ) );
217 }
218
219 return $content;
220 }
221
222 /**
223 * Grabs the first URL from the post content of the current post. This is meant to be used with the link post
224 * format to easily find the link for the post.
225 *
226 * @since 0.1.0
227 * @return string The link if found. Otherwise, the permalink to the post.
228 *
229 * @note This is a modified version of the twentyeleven_url_grabber() function in the TwentyEleven theme.
230 * @author wordpressdotorg
877f5cf Justin Tadlock Update copyright and theme info.
authored
231 * @copyright Copyright (c) 2011 - 2012, wordpressdotorg
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
232 * @link http://wordpress.org/extend/themes/twentyeleven
233 * @license http://wordpress.org/about/license
234 */
235 function my_life_url_grabber() {
236 if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) )
237 return get_permalink( get_the_ID() );
238
239 return esc_url_raw( $matches[1] );
240 }
241
242 /**
243 * Adds custom image sizes for featured images. The 'feature' image size is used for sticky posts.
244 *
245 * @since 0.1.0
246 */
247 function my_life_add_image_sizes() {
646d6fe Finalizing version 0.1 changes.
greenshady authored
248 add_image_size( 'header', 1000, 200, true );
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
249 }
250
251 /**
252 * Function for deciding which pages should have a one-column layout.
253 *
254 * @since 0.1.0
255 */
256 function my_life_one_column() {
257
258 if ( !is_active_sidebar( 'primary' ) && !is_active_sidebar( 'secondary' ) )
259 add_filter( 'get_theme_layout', 'my_life_theme_layout_one_column' );
260
261 elseif ( is_attachment() && 'layout-default' == theme_layouts_get_layout() )
262 add_filter( 'get_theme_layout', 'my_life_theme_layout_one_column' );
263 }
264
265 /**
266 * Filters 'get_theme_layout' by returning 'layout-1c'.
267 *
268 * @since 0.1.0
269 * @param string $layout The layout of the current page.
270 * @return string
271 */
272 function my_life_theme_layout_one_column( $layout ) {
273 return 'layout-1c';
274 }
275
276 /**
277 * Disables sidebars if viewing a one-column page.
278 *
279 * @since 0.1.0
280 * @param array $sidebars_widgets A multidimensional array of sidebars and widgets.
281 * @return array $sidebars_widgets
282 */
283 function my_life_disable_sidebars( $sidebars_widgets ) {
284
285 if ( current_theme_supports( 'theme-layouts' ) && !is_admin() ) {
286
287 if ( 'layout-1c' == theme_layouts_get_layout() ) {
288 $sidebars_widgets['primary'] = false;
289 $sidebars_widgets['secondary'] = false;
290 }
291 }
292
293 return $sidebars_widgets;
294 }
295
296 /**
297 * Overwrites the default widths for embeds. This is especially useful for making sure videos properly
298 * expand the full width on video pages. This function overwrites what the $content_width variable handles
299 * with context-based widths.
300 *
301 * @since 0.1.0
302 */
303 function my_life_embed_defaults( $args ) {
304
305 $args['width'] = 600;
306
307 if ( current_theme_supports( 'theme-layouts' ) ) {
308
309 $layout = theme_layouts_get_layout();
310
311 if ( 'layout-3c-l' == $layout || 'layout-3c-r' == $layout || 'layout-3c-c' == $layout )
312 $args['width'] = 470;
313 elseif ( 'layout-1c' == $layout )
314 $args['width'] = 808;
315 }
316
317 return $args;
318 }
319
320 /**
321 * Adds 'class="prev" to the previous comments link.
322 *
323 * @since 0.1.0
324 * @param string $attributes The previous comments link attributes.
325 * @return string
326 */
327 function my_life_previous_comments_link_attributes( $attributes ) {
328 return $attributes . ' class="prev"';
329 }
330
331 /**
332 * Adds 'class="next" to the next comments link.
333 *
334 * @since 0.1.0
335 * @param string $attributes The next comments link attributes.
336 * @return string
337 */
338 function my_life_next_comments_link_attributes( $attributes ) {
339 return $attributes . ' class="next"';
340 }
341
342 /**
343 * Returns the number of images attached to the current post in the loop.
344 *
345 * @since 0.1.0
346 * @return int
347 */
348 function my_life_get_image_attachment_count() {
349 $images = get_children( array( 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => -1 ) );
350 return count( $images );
351 }
352
353 /**
354 * Returns a set of image attachment links based on size.
355 *
356 * @since 0.1.0
357 * @return string Links to various image sizes for the image attachment.
358 */
359 function my_life_get_image_size_links() {
360
361 /* If not viewing an image attachment page, return. */
362 if ( !wp_attachment_is_image( get_the_ID() ) )
363 return;
364
365 /* Set up an empty array for the links. */
366 $links = array();
367
368 /* Get the intermediate image sizes and add the full size to the array. */
369 $sizes = get_intermediate_image_sizes();
370 $sizes[] = 'full';
371
372 /* Loop through each of the image sizes. */
373 foreach ( $sizes as $size ) {
374
375 /* Get the image source, width, height, and whether it's intermediate. */
376 $image = wp_get_attachment_image_src( get_the_ID(), $size );
377
378 /* Add the link to the array if there's an image and if $is_intermediate (4th array value) is true or full size. */
379 if ( !empty( $image ) && ( true === $image[3] || 'full' == $size ) )
380 $links[] = "<a class='image-size-link' href='" . esc_url( $image[0] ) . "'>{$image[1]} &times; {$image[2]}</a>";
381 }
382
383 /* Join the links in a string and return. */
384 return join( ' <span class="sep">/</span> ', $links );
385 }
386
be30b02 Justin Tadlock Switch to newer 'custom-background' theme feature.
authored
387
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
388 /**
389 * @since 0.1.0
be30b02 Justin Tadlock Switch to newer 'custom-background' theme feature.
authored
390 * @deprecated 0.2.0
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
391 */
392 function my_life_custom_background_callback() {
be30b02 Justin Tadlock Switch to newer 'custom-background' theme feature.
authored
393 _deprecated_function( __FUNCTION__, '0.2.0' );
394 _custom_background_cb();
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
395 }
396
397 /**
398 * @since 0.1.0
d29f7c5 Justin Tadlock Deprecated functions that have been added to the Hybrid Core framework.
authored
399 * @deprecated 0.2.0
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
400 */
d29f7c5 Justin Tadlock Deprecated functions that have been added to the Hybrid Core framework.
authored
401 function my_life_body_class() {
402 _deprecated_function( __FUNCTION__, '0.2.0' );
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
403 }
404
405 /**
406 * Removes 'post-format-' from the taxonomy template name for post formats.
407 *
408 * @since 0.1.0
d29f7c5 Justin Tadlock Deprecated functions that have been added to the Hybrid Core framework.
authored
409 * @deprecated 0.2.0
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
410 */
411 function my_life_taxonomy_template( $template ) {
d29f7c5 Justin Tadlock Deprecated functions that have been added to the Hybrid Core framework.
authored
412 _deprecated_function( __FUNCTION__, '0.2.0' );
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
413 }
414
415 /**
416 * @since 0.1.0
d29f7c5 Justin Tadlock Deprecated functions that have been added to the Hybrid Core framework.
authored
417 * @deprecated 0.2.0
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
418 */
d29f7c5 Justin Tadlock Deprecated functions that have been added to the Hybrid Core framework.
authored
419 function my_life_clean_post_format_slug() {
420 _deprecated_function( __FUNCTION__, '0.2.0' );
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
421 }
422
423 /**
424 * @since 0.1.0
d29f7c5 Justin Tadlock Deprecated functions that have been added to the Hybrid Core framework.
authored
425 * @deprecated 0.2.0
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
426 */
427 function my_life_register_shortcodes() {
d29f7c5 Justin Tadlock Deprecated functions that have been added to the Hybrid Core framework.
authored
428 _deprecated_function( __FUNCTION__, '0.2.0' );
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
429 }
430
431 /**
432 * @since 0.1.0
d29f7c5 Justin Tadlock Deprecated functions that have been added to the Hybrid Core framework.
authored
433 * @deprecated 0.2.0
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
434 */
d29f7c5 Justin Tadlock Deprecated functions that have been added to the Hybrid Core framework.
authored
435 function my_life_post_format_link_shortcode() {
436 _deprecated_function( __FUNCTION__, '0.2.0' );
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
437 }
438
439 /**
440 * Returns the output of the [entry-permalink] shortcode.
441 *
442 * @since 0.1.0
d29f7c5 Justin Tadlock Deprecated functions that have been added to the Hybrid Core framework.
authored
443 * @deprecated 0.2.0
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
444 */
d29f7c5 Justin Tadlock Deprecated functions that have been added to the Hybrid Core framework.
authored
445 function my_life_entry_permalink_shortcode() {
446 _deprecated_function( __FUNCTION__, '0.2.0' );
2aa8890 Importing the initial My Life theme files and folders.
greenshady authored
447 }
448
449 ?>
Something went wrong with that request. Please try again.