Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 419 lines (341 sloc) 14.928 kb
0c01223 @justintadlock Bring in the initial files and folders.
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
d8e7a87 @justintadlock Many, many changes getting this theme ready.
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.
0c01223 @justintadlock Bring in the initial files and folders.
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 *
8ab6ce2 @justintadlock Copy/Paste fail. Update all instances of @package MyLife to @package…
authored
21 * @package Picturesque
0c01223 @justintadlock Bring in the initial files and folders.
authored
22 * @subpackage Functions
746cb4d @justintadlock Version bump to 0.1.1 beta.
authored
23 * @version 0.1.1
0c01223 @justintadlock Bring in the initial files and folders.
authored
24 * @since 0.1.0
25 * @author Justin Tadlock <justin@justintadlock.com>
d8e7a87 @justintadlock Many, many changes getting this theme ready.
authored
26 * @copyright Copyright (c) 2012, Justin Tadlock
27 * @link http://themehybrid.com/themes/picturesque
0c01223 @justintadlock Bring in the initial files and folders.
authored
28 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
29 */
30
31 /* Load the core theme framework. */
d8e7a87 @justintadlock Many, many changes getting this theme ready.
authored
32 require_once( trailingslashit( get_template_directory() ) . 'library/hybrid.php' );
0c01223 @justintadlock Bring in the initial files and folders.
authored
33 new Hybrid();
34
35 /* Do theme setup on the 'after_setup_theme' hook. */
36 add_action( 'after_setup_theme', 'picturesque_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 picturesque_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', 'subsidiary' ) );
d8e7a87 @justintadlock Many, many changes getting this theme ready.
authored
51 add_theme_support( 'hybrid-core-sidebars', array( 'primary' ) );
0c01223 @justintadlock Bring in the initial files and folders.
authored
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' ) );
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
68 /* Add theme support for WordPress features. */
69 add_theme_support( 'automatic-feed-links' );
70 add_theme_support( 'post-formats', array( 'image', 'gallery' ) );
d8e7a87 @justintadlock Many, many changes getting this theme ready.
authored
71
72 /* Add support for WordPress custom background. */
73 add_theme_support(
74 'custom-background',
75 array(
76 'default-image' => trailingslashit( get_template_directory_uri() ) . 'images/bg.png',
77 'wp-head-callback' => 'picturesque_custom_background_callback'
78 )
79 );
80
81 /* Add support for WordPress custom header image. */
82 add_theme_support(
83 'custom-header',
84 array(
85 'wp-head-callback' => '__return_false',
86 'admin-head-callback' => '__return_false',
87 'header-text' => false,
88 'default-image' => 'remove-header',
89 'width' => 1050,
90 'height' => 200
91 )
92 );
0c01223 @justintadlock Bring in the initial files and folders.
authored
93
94 /* Embed width/height defaults. */
95 add_filter( 'embed_defaults', 'picturesque_embed_defaults' );
96
97 /* Set content width. */
98 hybrid_set_content_width( 600 );
99
100 /* Filter the sidebar widgets. */
101 add_filter( 'sidebars_widgets', 'picturesque_disable_sidebars' );
102 add_action( 'template_redirect', 'picturesque_one_column' );
103
104 /* Add classes to the comments pagination. */
105 add_filter( 'previous_comments_link_attributes', 'picturesque_previous_comments_link_attributes' );
106 add_filter( 'next_comments_link_attributes', 'picturesque_next_comments_link_attributes' );
107
108 /* Wraps <blockquote> around quote posts. */
109 add_filter( 'the_content', 'picturesque_quote_content' );
110
111 /* Adds the featured image to image posts if no content is found. */
112 add_filter( 'the_content', 'picturesque_image_content' );
113
114 /* Filters the image/gallery post format archive galleries. */
115 add_filter( "{$prefix}_post_format_archive_gallery_columns", 'picturesque_archive_gallery_columns' );
116 }
117
118 /**
119 * Sets the number of columns to show on image and gallery post format archives pages based on the
120 * layout that is currently being used.
121 *
122 * @since 0.1.0
123 * @param int $columns Number of gallery columns to display.
124 * @return int $columns
125 */
126 function picturesque_archive_gallery_columns( $columns ) {
127
128 /* Only run the code if the theme supports the 'theme-layouts' feature. */
129 if ( current_theme_supports( 'theme-layouts' ) ) {
130
131 /* Get the current theme layout. */
132 $layout = theme_layouts_get_layout();
133
134 if ( 'layout-1c' == $layout )
d8e7a87 @justintadlock Many, many changes getting this theme ready.
authored
135 $columns = 5;
0c01223 @justintadlock Bring in the initial files and folders.
authored
136 }
137
138 return $columns;
139 }
140
141 /**
142 * Wraps the output of the quote post format content in a <blockquote> element if the user hasn't added a
143 * <blockquote> in the post editor.
144 *
145 * @since 0.1.0
146 * @param string $content The post content.
147 * @return string $content
148 */
149 function picturesque_quote_content( $content ) {
150
151 if ( has_post_format( 'quote' ) ) {
152 preg_match( '/<blockquote.*?>/', $content, $matches );
153
154 if ( empty( $matches ) )
155 $content = "<blockquote>{$content}</blockquote>";
156 }
157
158 return $content;
159 }
160
161 /**
162 * Returns the featured image for the image post format if the user didn't add any content to the post.
163 *
164 * @since 0.1.0
165 * @param string $content The post content.
166 * @return string $content
167 */
168 function picturesque_image_content( $content ) {
169
170 if ( has_post_format( 'image' ) && '' == $content ) {
171 if ( is_singular() )
172 $content = get_the_image( array( 'size' => 'full', 'meta_key' => false, 'link_to_post' => false ) );
173 else
174 $content = get_the_image( array( 'size' => 'full', 'meta_key' => false ) );
175 }
176
177 return $content;
178 }
179
180 /**
181 * Function for deciding which pages should have a one-column layout.
182 *
183 * @since 0.1.0
184 */
185 function picturesque_one_column() {
186
187 if ( !is_active_sidebar( 'primary' ) && !is_active_sidebar( 'secondary' ) )
188 add_filter( 'get_theme_layout', 'picturesque_theme_layout_one_column' );
189
190 elseif ( is_attachment() && 'layout-default' == theme_layouts_get_layout() )
191 add_filter( 'get_theme_layout', 'picturesque_theme_layout_one_column' );
192 }
193
194 /**
195 * Filters 'get_theme_layout' by returning 'layout-1c'.
196 *
197 * @since 0.1.0
198 * @param string $layout The layout of the current page.
199 * @return string
200 */
201 function picturesque_theme_layout_one_column( $layout ) {
202 return 'layout-1c';
203 }
204
205 /**
206 * Disables sidebars if viewing a one-column page.
207 *
208 * @since 0.1.0
209 * @param array $sidebars_widgets A multidimensional array of sidebars and widgets.
210 * @return array $sidebars_widgets
211 */
212 function picturesque_disable_sidebars( $sidebars_widgets ) {
213
214 if ( current_theme_supports( 'theme-layouts' ) && !is_admin() ) {
215
216 if ( 'layout-1c' == theme_layouts_get_layout() ) {
217 $sidebars_widgets['primary'] = false;
218 $sidebars_widgets['secondary'] = false;
219 }
220 }
221
222 return $sidebars_widgets;
223 }
224
225 /**
226 * Overwrites the default widths for embeds. This is especially useful for making sure videos properly
227 * expand the full width on video pages. This function overwrites what the $content_width variable handles
228 * with context-based widths.
229 *
230 * @since 0.1.0
231 */
232 function picturesque_embed_defaults( $args ) {
233
d8e7a87 @justintadlock Many, many changes getting this theme ready.
authored
234 $args['width'] = hybrid_get_content_width();
0c01223 @justintadlock Bring in the initial files and folders.
authored
235
236 if ( current_theme_supports( 'theme-layouts' ) ) {
237
238 $layout = theme_layouts_get_layout();
239
d8e7a87 @justintadlock Many, many changes getting this theme ready.
authored
240 if ( 'layout-1c' == $layout )
241 $args['width'] = 950;
0c01223 @justintadlock Bring in the initial files and folders.
authored
242 }
243
244 return $args;
245 }
246
247 /**
248 * Adds 'class="prev" to the previous comments link.
249 *
250 * @since 0.1.0
251 * @param string $attributes The previous comments link attributes.
252 * @return string
253 */
254 function picturesque_previous_comments_link_attributes( $attributes ) {
255 return $attributes . ' class="prev"';
256 }
257
258 /**
259 * Adds 'class="next" to the next comments link.
260 *
261 * @since 0.1.0
262 * @param string $attributes The next comments link attributes.
263 * @return string
264 */
265 function picturesque_next_comments_link_attributes( $attributes ) {
266 return $attributes . ' class="next"';
267 }
268
269 /**
270 * Returns the number of images attached to the current post in the loop.
271 *
272 * @since 0.1.0
273 * @return int
274 */
275 function picturesque_get_image_attachment_count() {
276 $images = get_children( array( 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => -1 ) );
277 return count( $images );
278 }
279
280 /**
281 * Returns a set of image attachment links based on size.
282 *
283 * @since 0.1.0
284 * @return string Links to various image sizes for the image attachment.
285 */
286 function picturesque_get_image_size_links() {
287
288 /* If not viewing an image attachment page, return. */
289 if ( !wp_attachment_is_image( get_the_ID() ) )
290 return;
291
292 /* Set up an empty array for the links. */
293 $links = array();
294
295 /* Get the intermediate image sizes and add the full size to the array. */
296 $sizes = get_intermediate_image_sizes();
297 $sizes[] = 'full';
298
299 /* Loop through each of the image sizes. */
300 foreach ( $sizes as $size ) {
301
302 /* Get the image source, width, height, and whether it's intermediate. */
303 $image = wp_get_attachment_image_src( get_the_ID(), $size );
304
305 /* Add the link to the array if there's an image and if $is_intermediate (4th array value) is true or full size. */
306 if ( !empty( $image ) && ( true === $image[3] || 'full' == $size ) )
307 $links[] = "<a class='image-size-link' href='" . esc_url( $image[0] ) . "'>{$image[1]} &times; {$image[2]}</a>";
308 }
309
310 /* Join the links in a string and return. */
311 return join( ' <span class="sep">/</span> ', $links );
312 }
313
314 /**
315 * This is a fix for when a user sets a custom background color with no custom background image. What
316 * happens is the theme's background image hides the user-selected background color. If a user selects a
317 * background image, we'll just use the WordPress custom background callback.
318 *
319 * @since 0.1.0
320 * @link http://core.trac.wordpress.org/ticket/16919
321 */
322 function picturesque_custom_background_callback() {
323
324 /* Get the background image. */
325 $image = get_background_image();
326
327 /* If there's an image, just call the normal WordPress callback. We won't do anything here. */
328 if ( !empty( $image ) ) {
329 _custom_background_cb();
330 return;
331 }
332
333 /* Get the background color. */
334 $color = get_background_color();
335
336 /* If no background color, return. */
337 if ( empty( $color ) )
338 return;
339
340 /* Use 'background' instead of 'background-color'. */
341 $style = "background: #{$color};";
342
343 ?>
344 <style type="text/css">body.custom-background { <?php echo trim( $style ); ?> }</style>
345 <?php
346
347 }
348
349 /**
350 * Displays an attachment image's metadata and exif data while viewing a singular attachment page.
351 *
352 * Note: This function will most likely be restructured completely in the future. The eventual plan is to
353 * separate each of the elements into an attachment API that can be used across multiple themes. Keep
354 * this in mind if you plan on using the current filter hooks in this function.
355 *
356 * @since 0.1.0
357 */
d8e7a87 @justintadlock Many, many changes getting this theme ready.
authored
358 function picturesque_image_info() {
0c01223 @justintadlock Bring in the initial files and folders.
authored
359
360 /* Set up some default variables and get the image metadata. */
361 $meta = wp_get_attachment_metadata( get_the_ID() );
362 $items = array();
363 $list = '';
364
365 /* Add the width/height to the $items array. */
d8e7a87 @justintadlock Many, many changes getting this theme ready.
authored
366 $items['dimensions'] = sprintf( __( '<span class="prep">Dimensions:</span> %s', 'picturesque' ), '<span class="image-data"><a href="' . esc_url( wp_get_attachment_url() ) . '">' . sprintf( __( '%1$s &#215; %2$s pixels', 'picturesque' ), $meta['width'], $meta['height'] ) . '</a></span>' );
0c01223 @justintadlock Bring in the initial files and folders.
authored
367
368 /* If a timestamp exists, add it to the $items array. */
369 if ( !empty( $meta['image_meta']['created_timestamp'] ) )
d8e7a87 @justintadlock Many, many changes getting this theme ready.
authored
370 $items['created_timestamp'] = sprintf( __( '<span class="prep">Date:</span> %s', 'picturesque' ), '<span class="image-data">' . date( get_option( 'date_format' ), $meta['image_meta']['created_timestamp'] ) . '</span>' );
0c01223 @justintadlock Bring in the initial files and folders.
authored
371
372 /* If a camera exists, add it to the $items array. */
373 if ( !empty( $meta['image_meta']['camera'] ) )
d8e7a87 @justintadlock Many, many changes getting this theme ready.
authored
374 $items['camera'] = sprintf( __( '<span class="prep">Camera:</span> %s', 'picturesque' ), '<span class="image-data">' . $meta['image_meta']['camera'] . '</span>' );
0c01223 @justintadlock Bring in the initial files and folders.
authored
375
376 /* If an aperture exists, add it to the $items array. */
377 if ( !empty( $meta['image_meta']['aperture'] ) )
d8e7a87 @justintadlock Many, many changes getting this theme ready.
authored
378 $items['aperture'] = sprintf( __( '<span class="prep">Aperture:</span> %s', 'picturesque' ), '<span class="image-data">' . sprintf( __( 'f/%s', 'picturesque' ), $meta['image_meta']['aperture'] ) . '</span>' );
0c01223 @justintadlock Bring in the initial files and folders.
authored
379
380 /* If a focal length is set, add it to the $items array. */
381 if ( !empty( $meta['image_meta']['focal_length'] ) )
d8e7a87 @justintadlock Many, many changes getting this theme ready.
authored
382 $items['focal_length'] = sprintf( __( '<span class="prep">Focal Length:</span> %s', 'picturesque' ), '<span class="image-data">' . sprintf( __( '%s mm', 'picturesque' ), $meta['image_meta']['focal_length'] ) . '</span>' );
0c01223 @justintadlock Bring in the initial files and folders.
authored
383
384 /* If an ISO is set, add it to the $items array. */
385 if ( !empty( $meta['image_meta']['iso'] ) )
d8e7a87 @justintadlock Many, many changes getting this theme ready.
authored
386 $items['iso'] = sprintf( __( '<span class="prep">ISO:</span> %s', 'picturesque' ), '<span class="image-data">' . $meta['image_meta']['iso'] . '</span>' );
0c01223 @justintadlock Bring in the initial files and folders.
authored
387
388 /* If a shutter speed is given, format the float into a fraction and add it to the $items array. */
389 if ( !empty( $meta['image_meta']['shutter_speed'] ) ) {
390
391 if ( ( 1 / $meta['image_meta']['shutter_speed'] ) > 1 ) {
392 $shutter_speed = '1/';
393
394 if ( number_format( ( 1 / $meta['image_meta']['shutter_speed'] ), 1 ) == number_format( ( 1 / $meta['image_meta']['shutter_speed'] ), 0 ) )
395 $shutter_speed .= number_format( ( 1 / $meta['image_meta']['shutter_speed'] ), 0, '.', '' );
396 else
397 $shutter_speed .= number_format( ( 1 / $meta['image_meta']['shutter_speed'] ), 1, '.', '' );
398 } else {
399 $shutter_speed = $meta['image_meta']['shutter_speed'];
400 }
401
d8e7a87 @justintadlock Many, many changes getting this theme ready.
authored
402 $items['shutter_speed'] = sprintf( __( '<span class="prep">Shutter Speed:</span> %s', 'picturesque' ), '<span class="image-data">' . sprintf( __( '%s sec', 'picturesque' ), $shutter_speed ) . '</span>' );
0c01223 @justintadlock Bring in the initial files and folders.
authored
403 }
404
405 /* Allow devs to overwrite the array of items. */
406 $items = apply_atomic( 'image_info_items', $items );
407
408 /* Loop through the items, wrapping each in an <li> element. */
409 foreach ( $items as $item )
410 $list .= "<li>{$item}</li>";
411
412 /* Format the HTML output of the function. */
d8e7a87 @justintadlock Many, many changes getting this theme ready.
authored
413 $output = '<div class="image-info"><h3>' . __( 'Image Info', 'picturesque' ) . '</h3><ul>' . $list . '</ul></div>';
0c01223 @justintadlock Bring in the initial files and folders.
authored
414
415 /* Display the image info and allow devs to overwrite the final output. */
416 echo apply_atomic( 'image_info', $output );
417 }
418
419 ?>
Something went wrong with that request. Please try again.