Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 413 lines (342 sloc) 12.375 kb
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
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
877f5cfb »
2012-08-24 Update copyright and theme info.
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.
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
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
7d67bf4c »
2013-04-10 Bring copyright version up to date and version bump to 0.3.0.
23 * @version 0.3.0
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
24 * @since 0.1.0
25 * @author Justin Tadlock <justin@justintadlock.com>
7d67bf4c »
2013-04-10 Bring copyright version up to date and version bump to 0.3.0.
26 * @copyright Copyright (c) 2011 - 2013, Justin Tadlock
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
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. */
e2f6121f »
2012-08-24 Update call to the framework.
32 require_once( trailingslashit( get_template_directory() ) . 'library/hybrid.php' );
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
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' ) );
1e0242ab »
2013-04-10 Bring code up to date with latest version of Hybrid Core.
55 add_theme_support( 'hybrid-core-scripts', array( 'comment-reply', 'drop-downs' ) );
56 add_theme_support( 'hybrid-core-styles', array( 'style' ) );
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
57 add_theme_support( 'hybrid-core-template-hierarchy' );
58
59 /* Add theme support for framework extensions. */
1e0242ab »
2013-04-10 Bring code up to date with latest version of Hybrid Core.
60 add_theme_support(
61 'theme-layouts',
62 array( '1c', '2c-l', '2c-r', '3c-l', '3c-r', '3c-c' ),
63 array( 'default' => '2c-l', 'customize' => true )
64 );
65
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
66 add_theme_support( 'post-stylesheets' );
67 add_theme_support( 'dev-stylesheet' );
68 add_theme_support( 'loop-pagination' );
69 add_theme_support( 'get-the-image' );
70 add_theme_support( 'breadcrumb-trail' );
71 add_theme_support( 'cleaner-gallery' );
72 add_theme_support( 'cleaner-caption' );
73
74 /* Add theme support for WordPress features. */
75 add_theme_support( 'automatic-feed-links' );
76 add_theme_support( 'post-formats', array( 'aside', 'audio', 'image', 'gallery', 'link', 'quote', 'status', 'video' ) );
be30b02d »
2012-08-24 Switch to newer 'custom-background' theme feature.
77
78 /* Add support for a custom background. */
79 add_theme_support(
80 'custom-background',
81 array(
82 'default-image' => trailingslashit( get_template_directory_uri() ) . 'images/bg.png',
83 )
84 );
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
85
189b7226 »
2012-08-24 Switch to the new 'custom-header' theme feature.
86 /* Add support for a custom header image. */
87 add_theme_support(
88 'custom-header',
89 array(
90 'default-image' => 'remove-header',
91 'width' => 1000,
92 'height' => 200,
93 'header-text' => false,
94 'wp-head-callback' => '__return_false',
95 'admin-head-callback' => '__return_false',
96 )
97 );
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
98
99 /* Embed width/height defaults. */
100 add_filter( 'embed_defaults', 'my_life_embed_defaults' );
101
102 /* Set content width. */
103 hybrid_set_content_width( 600 );
104
105 /* Filter the sidebar widgets. */
106 add_filter( 'sidebars_widgets', 'my_life_disable_sidebars' );
107 add_action( 'template_redirect', 'my_life_one_column' );
108
109 /* Add classes to the comments pagination. */
110 add_filter( 'previous_comments_link_attributes', 'my_life_previous_comments_link_attributes' );
111 add_filter( 'next_comments_link_attributes', 'my_life_next_comments_link_attributes' );
112
113 /* Add custom image sizes. */
114 add_action( 'init', 'my_life_add_image_sizes' );
115
116 /* Filter the header image on singular views. */
117 add_filter( 'theme_mod_header_image', 'my_life_header_image' );
118
119 /* Filters the image/gallery post format archive galleries. */
120 add_filter( "{$prefix}_post_format_archive_gallery_columns", 'my_life_archive_gallery_columns' );
121 }
122
123 /**
124 * Sets the number of columns to show on image and gallery post format archives pages based on the
125 * layout that is currently being used.
126 *
127 * @since 0.1.0
128 * @param int $columns Number of gallery columns to display.
129 * @return int $columns
130 */
131 function my_life_archive_gallery_columns( $columns ) {
132
133 /* Only run the code if the theme supports the 'theme-layouts' feature. */
134 if ( current_theme_supports( 'theme-layouts' ) ) {
135
136 /* Get the current theme layout. */
137 $layout = theme_layouts_get_layout();
138
139 if ( 'layout-1c' == $layout )
140 $columns = 4;
141
142 elseif ( in_array( $layout, array( 'layout-3c-l', 'layout-3c-r', 'layout-3c-c' ) ) )
143 $columns = 2;
144 }
145
146 return $columns;
147 }
148
149 /**
150 * Filter for the "theme_mod_header_image" hook, which returns the header image URL. This allows the user
151 * to change the header image on a per-post basis by uploading a feature image large enough to display as a
152 * header image.
153 *
154 * @since 0.1.0
155 * @param string $url The URL of the current header image.
156 * @return string $url
157 */
158 function my_life_header_image( $url ) {
159
160 if ( is_singular() && 'remove-header' !== $url ) {
161
162 $post_id = get_queried_object_id();
163
164 if ( is_attachment() && wp_attachment_is_image( $post_id ) )
165 $thumbnail_id = $post_id;
166
167 elseif ( has_post_thumbnail( $post_id ) )
168 $thumbnail_id = get_post_thumbnail_id( $post_id );
169
170 if ( !empty( $thumbnail_id ) ) {
171
646d6fee » greenshady
2011-12-05 Finalizing version 0.1 changes.
172 $image = wp_get_attachment_image_src( $thumbnail_id, 'header' );
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
173
174 if ( $image[1] >= HEADER_IMAGE_WIDTH && $image[2] >= HEADER_IMAGE_HEIGHT )
175 $url = $image[0];
176 }
177 }
178
179 return $url;
180 }
181
182 /**
183 * Adds custom image sizes for featured images. The 'feature' image size is used for sticky posts.
184 *
185 * @since 0.1.0
186 */
187 function my_life_add_image_sizes() {
646d6fee » greenshady
2011-12-05 Finalizing version 0.1 changes.
188 add_image_size( 'header', 1000, 200, true );
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
189 }
190
191 /**
192 * Function for deciding which pages should have a one-column layout.
193 *
194 * @since 0.1.0
195 */
196 function my_life_one_column() {
197
198 if ( !is_active_sidebar( 'primary' ) && !is_active_sidebar( 'secondary' ) )
1e0242ab »
2013-04-10 Bring code up to date with latest version of Hybrid Core.
199 add_filter( 'theme_mod_theme_layout', 'my_life_theme_layout_one_column' );
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
200
1e0242ab »
2013-04-10 Bring code up to date with latest version of Hybrid Core.
201 elseif ( is_attachment() && wp_attachment_is_image() && 'default' == get_post_layout( get_queried_object_id() ) )
202 add_filter( 'theme_mod_theme_layout', 'my_life_theme_layout_one_column' );
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
203 }
204
205 /**
206 * Filters 'get_theme_layout' by returning 'layout-1c'.
207 *
208 * @since 0.1.0
209 * @param string $layout The layout of the current page.
210 * @return string
211 */
212 function my_life_theme_layout_one_column( $layout ) {
1e0242ab »
2013-04-10 Bring code up to date with latest version of Hybrid Core.
213 return '1c';
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
214 }
215
216 /**
217 * Disables sidebars if viewing a one-column page.
218 *
219 * @since 0.1.0
220 * @param array $sidebars_widgets A multidimensional array of sidebars and widgets.
221 * @return array $sidebars_widgets
222 */
223 function my_life_disable_sidebars( $sidebars_widgets ) {
224
225 if ( current_theme_supports( 'theme-layouts' ) && !is_admin() ) {
226
227 if ( 'layout-1c' == theme_layouts_get_layout() ) {
228 $sidebars_widgets['primary'] = false;
229 $sidebars_widgets['secondary'] = false;
230 }
231 }
232
233 return $sidebars_widgets;
234 }
235
236 /**
237 * Overwrites the default widths for embeds. This is especially useful for making sure videos properly
238 * expand the full width on video pages. This function overwrites what the $content_width variable handles
239 * with context-based widths.
240 *
241 * @since 0.1.0
242 */
243 function my_life_embed_defaults( $args ) {
244
245 $args['width'] = 600;
246
247 if ( current_theme_supports( 'theme-layouts' ) ) {
248
249 $layout = theme_layouts_get_layout();
250
251 if ( 'layout-3c-l' == $layout || 'layout-3c-r' == $layout || 'layout-3c-c' == $layout )
252 $args['width'] = 470;
253 elseif ( 'layout-1c' == $layout )
254 $args['width'] = 808;
255 }
256
257 return $args;
258 }
259
260 /**
261 * Adds 'class="prev" to the previous comments link.
262 *
263 * @since 0.1.0
264 * @param string $attributes The previous comments link attributes.
265 * @return string
266 */
267 function my_life_previous_comments_link_attributes( $attributes ) {
268 return $attributes . ' class="prev"';
269 }
270
271 /**
272 * Adds 'class="next" to the next comments link.
273 *
274 * @since 0.1.0
275 * @param string $attributes The next comments link attributes.
276 * @return string
277 */
278 function my_life_next_comments_link_attributes( $attributes ) {
279 return $attributes . ' class="next"';
280 }
281
282
283 /**
284 * Returns a set of image attachment links based on size.
285 *
286 * @since 0.1.0
287 * @return string Links to various image sizes for the image attachment.
288 */
289 function my_life_get_image_size_links() {
290
291 /* If not viewing an image attachment page, return. */
292 if ( !wp_attachment_is_image( get_the_ID() ) )
293 return;
294
295 /* Set up an empty array for the links. */
296 $links = array();
297
298 /* Get the intermediate image sizes and add the full size to the array. */
299 $sizes = get_intermediate_image_sizes();
300 $sizes[] = 'full';
301
302 /* Loop through each of the image sizes. */
303 foreach ( $sizes as $size ) {
304
305 /* Get the image source, width, height, and whether it's intermediate. */
306 $image = wp_get_attachment_image_src( get_the_ID(), $size );
307
308 /* Add the link to the array if there's an image and if $is_intermediate (4th array value) is true or full size. */
309 if ( !empty( $image ) && ( true === $image[3] || 'full' == $size ) )
310 $links[] = "<a class='image-size-link' href='" . esc_url( $image[0] ) . "'>{$image[1]} &times; {$image[2]}</a>";
311 }
312
313 /* Join the links in a string and return. */
314 return join( ' <span class="sep">/</span> ', $links );
315 }
316
be30b02d »
2012-08-24 Switch to newer 'custom-background' theme feature.
317
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
318 /**
319 * @since 0.1.0
be30b02d »
2012-08-24 Switch to newer 'custom-background' theme feature.
320 * @deprecated 0.2.0
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
321 */
322 function my_life_custom_background_callback() {
be30b02d »
2012-08-24 Switch to newer 'custom-background' theme feature.
323 _deprecated_function( __FUNCTION__, '0.2.0' );
324 _custom_background_cb();
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
325 }
326
327 /**
328 * @since 0.1.0
d29f7c5c »
2012-08-24 Deprecated functions that have been added to the Hybrid Core framework.
329 * @deprecated 0.2.0
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
330 */
d29f7c5c »
2012-08-24 Deprecated functions that have been added to the Hybrid Core framework.
331 function my_life_body_class() {
332 _deprecated_function( __FUNCTION__, '0.2.0' );
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
333 }
334
335 /**
336 * Removes 'post-format-' from the taxonomy template name for post formats.
337 *
338 * @since 0.1.0
d29f7c5c »
2012-08-24 Deprecated functions that have been added to the Hybrid Core framework.
339 * @deprecated 0.2.0
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
340 */
341 function my_life_taxonomy_template( $template ) {
d29f7c5c »
2012-08-24 Deprecated functions that have been added to the Hybrid Core framework.
342 _deprecated_function( __FUNCTION__, '0.2.0' );
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
343 }
344
345 /**
346 * @since 0.1.0
d29f7c5c »
2012-08-24 Deprecated functions that have been added to the Hybrid Core framework.
347 * @deprecated 0.2.0
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
348 */
d29f7c5c »
2012-08-24 Deprecated functions that have been added to the Hybrid Core framework.
349 function my_life_clean_post_format_slug() {
350 _deprecated_function( __FUNCTION__, '0.2.0' );
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
351 }
352
353 /**
354 * @since 0.1.0
d29f7c5c »
2012-08-24 Deprecated functions that have been added to the Hybrid Core framework.
355 * @deprecated 0.2.0
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
356 */
357 function my_life_register_shortcodes() {
d29f7c5c »
2012-08-24 Deprecated functions that have been added to the Hybrid Core framework.
358 _deprecated_function( __FUNCTION__, '0.2.0' );
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
359 }
360
361 /**
362 * @since 0.1.0
d29f7c5c »
2012-08-24 Deprecated functions that have been added to the Hybrid Core framework.
363 * @deprecated 0.2.0
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
364 */
d29f7c5c »
2012-08-24 Deprecated functions that have been added to the Hybrid Core framework.
365 function my_life_post_format_link_shortcode() {
366 _deprecated_function( __FUNCTION__, '0.2.0' );
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
367 }
368
369 /**
370 * Returns the output of the [entry-permalink] shortcode.
371 *
372 * @since 0.1.0
d29f7c5c »
2012-08-24 Deprecated functions that have been added to the Hybrid Core framework.
373 * @deprecated 0.2.0
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
374 */
d29f7c5c »
2012-08-24 Deprecated functions that have been added to the Hybrid Core framework.
375 function my_life_entry_permalink_shortcode() {
376 _deprecated_function( __FUNCTION__, '0.2.0' );
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
377 }
378
1e0242ab »
2013-04-10 Bring code up to date with latest version of Hybrid Core.
379 /**
380 * @since 0.1.0
381 * @deprecated 0.3.0
382 */
383 function my_life_quote_content() {
384 _deprecated_function( __FUNCTION__, '0.3.0' );
385 }
386
387 /**
388 * @since 0.1.0
389 * @deprecated 0.3.0
390 */
391 function my_life_image_content() {
392 _deprecated_function( __FUNCTION__, '0.3.0' );
393 }
394
395 /**
396 * @since 0.1.0
397 * @deprecated 0.3.0
398 */
399 function my_life_get_image_attachment_count() {
400 _deprecated_function( __FUNCTION__, '0.3.0', 'post_format_tools_get_image_attachment_count' );
401 post_format_tools_get_image_attachment_count();
402 }
403
404 /**
405 * @since 0.1.0
406 * @deprecated 0.3.0
407 */
408 function my_life_url_grabber() {
409 _deprecated_function( __FUNCTION__, '0.3.0', 'post_format_tools_url_grabber' );
410 post_format_tools_url_grabber();
411 }
412
2aa88900 » greenshady
2011-12-05 Importing the initial My Life theme files and folders.
413 ?>
Something went wrong with that request. Please try again.