Skip to content
This repository
Newer
Older
100644 676 lines (605 sloc) 24.661 kb
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
1 <?php
2 /**
3 * Initializr functions and definitions
4 *
5 * Sets up the theme and provides some helper functions. Some helper functions
6 * are used in the theme as custom template tags. Others are attached to action and
7 * filter hooks in WordPress to change core functionality.
8 *
9 * The first function, initializr_setup(), sets up the theme by registering support
10 * for various features in WordPress, such as post thumbnails, navigation menus, and the like.
11 *
12 * When using a child theme (see http://codex.wordpress.org/Theme_Development and
13 * http://codex.wordpress.org/Child_Themes), you can override certain functions
14 * (those wrapped in a function_exists() call) by defining them first in your child theme's
15 * functions.php file. The child theme's functions.php file is included before the parent
16 * theme's file, so the child theme functions would be used.
17 *
18 * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
19 * to a filter or action hook. The hook can be removed by using remove_action() or
20 * remove_filter() and you can attach your own function to the hook.
21 *
22 * We can remove the parent theme's hook only after it is attached, which means we need to
23 * wait until setting up the child theme:
24 *
25 * <code>
26 * add_action( 'after_setup_theme', 'my_child_theme_setup' );
27 * function my_child_theme_setup() {
28 * // We are providing our own filter for excerpt_length (or using the unfiltered value)
29 * remove_filter( 'excerpt_length', 'initializr_excerpt_length' );
30 * ...
31 * }
32 * </code>
33 *
34 * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
35 *
36 * @package WordPress
58c22f5e »
2011-04-02 Misc changes. Styling fixes. s/twentyten/initializr/
37 * @subpackage Initializr
38 * @since Initializr 1.0
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
39 */
40
41 /**
ee6528f1 »
2011-04-18 Add the remaining formats. More styling. Support for setting post-for…
42 * In wp-includes/vars.php we set some user-agent variables.
43 * Let's be more specific about iPad vs iPhone:
44 */
45 if ( $is_iphone && stripos($_SERVER['HTTP_USER_AGENT'], 'ipad') !== false ) {
46 $is_ipad = true;
47 $is_iphone = false;
48 }
49
50 if ( $is_iphone || $is_ipad )
51 $is_ios = true;
52
53
54
55 /**
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
56 * Set the content width based on the theme's design and stylesheet.
57 *
58 * Used to set the width of images and content. Should be equal to the width the theme
59 * is designed for, generally via the style.css stylesheet.
60 */
ee6528f1 »
2011-04-18 Add the remaining formats. More styling. Support for setting post-for…
61 if ( ! isset( $content_width ) ) {
62 $content_width = 480;
63 if ( $is_ipad ) {
64 $content_width = 380; // for ipad portrait orientation
65 }
66 }
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
67
68 /** Tell WordPress to run initializr_setup() when the 'after_setup_theme' hook is run. */
b146631a »
2011-04-21 backporting fixes
69 add_action( 'after_setup_theme', 'initializr_setup', 9 );
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
70
71 add_action( 'template_redirect', 'initializr_redirect' );
72
73 if ( ! function_exists( 'initializr_setup' ) ):
74 /**
75 * Sets up theme defaults and registers support for various WordPress features.
76 *
77 * Note that this function is hooked into the after_setup_theme hook, which runs
78 * before the init hook. The init hook is too late for some features, such as indicating
79 * support post thumbnails.
80 *
81 * To override initializr_setup() in a child theme, add your own initializr_setup to your child theme's
82 * functions.php file.
83 *
84 * @uses add_theme_support() To add support for post thumbnails and automatic feed links.
85 * @uses register_nav_menus() To add support for navigation menus.
86 * @uses add_custom_background() To add support for a custom background.
87 * @uses add_editor_style() To style the visual editor.
88 * @uses load_theme_textdomain() For translation/localization support.
89 * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
90 *
58c22f5e »
2011-04-02 Misc changes. Styling fixes. s/twentyten/initializr/
91 * @since Initializr 1.0
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
92 */
93 function initializr_setup() {
b146631a »
2011-04-21 backporting fixes
94 // Load main stylesheet
a8f0ee5e »
2011-04-23 ver bump
95 if (! is_admin() ) {
96 wp_enqueue_style('initializr', get_template_directory_uri() . '/style.css', array(), '0.0.9');
3a278c9d »
2011-04-23 ver bump
97 }
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
98 // This theme styles the visual editor with editor-style.css to match the theme style.
99 add_editor_style();
100
101 // Post Format support. You can also use the legacy "gallery" or "asides" (note the plural) categories.
ee6528f1 »
2011-04-18 Add the remaining formats. More styling. Support for setting post-for…
102 add_theme_support( 'post-formats', array( 'aside', 'link', 'image', 'video', 'quote', 'gallery', 'status', 'chat', 'audio' ) );
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
103
104 // This theme uses post thumbnails
105 add_theme_support( 'post-thumbnails' );
106
107 // Add default posts and comments RSS feed links to head
108 add_theme_support( 'automatic-feed-links' );
109
2c831257 »
2011-04-03 Making progress
110 // Auto-add a float-right thumbnail featured image, when set
111 if (function_exists('set_post_thumbnail_size')) {
ee6528f1 »
2011-04-18 Add the remaining formats. More styling. Support for setting post-for…
112 set_post_thumbnail_size( 240, 240, true );
113 }
114
115 if (function_exists('add_image_size')) {
116 add_image_size('thumbnail', 125, 125, true);
117 add_image_size('featured', 240, 240, true);
118 add_image_size('small', 125, 170);
119 add_image_size('medium', 240, 320);
120 add_image_size('large', 380, 512);
121 add_image_size('xlarge', 480, 640);
122 add_image_size('full', 9999, 9999);
2c831257 »
2011-04-03 Making progress
123 }
124
125 add_filter('the_content', 'gr_post_thumbnail');
126
127 // Make theme available for translation
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
128 // Translations can be filed in the /languages/ directory
129 load_theme_textdomain( 'initializr', TEMPLATEPATH . '/languages' );
130
131 $locale = get_locale();
132 $locale_file = TEMPLATEPATH . "/languages/$locale.php";
133 if ( is_readable( $locale_file ) )
134 require_once( $locale_file );
135
136 // This theme uses wp_nav_menu() in one location.
137 register_nav_menus( array(
138 'primary' => __( 'Primary Navigation', 'initializr' ),
139 ) );
140
ee6528f1 »
2011-04-18 Add the remaining formats. More styling. Support for setting post-for…
141 // Add official.fm as an oembed provider:
142 wp_oembed_add_provider('http://official.fm/*', 'http://official.fm/services/oembed/');
e12966aa »
2011-04-19 proto dropdown menus. needs work.
143
144 // Dropdown menus
145 wp_enqueue_script('dropdown', trailingslashit( get_stylesheet_directory_uri() ) . 'js/jquery.dropdownPlain.js', array('jquery'), '1.0');
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
146 }
147 endif;
148
2c831257 »
2011-04-03 Making progress
149 // Add X-UA-Compatible header in HTTP, not in HTML
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
150 if ( ! function_exists( 'initializr_redirect' ) ) :
151 function initializr_redirect() {
152 // Send as an HTTP header instead using meta http-equiv.
153 // See: http://lists.w3.org/Archives/Public/www-validator/2010Nov/0050.html
154 @header( 'X-UA-Compatible: IE=edge,chrome=1' );
155 }
156 endif;
157
158 /**
159 * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
160 *
161 * To override this in a child theme, remove the filter and optionally add
162 * your own function tied to the wp_page_menu_args filter hook.
163 *
58c22f5e »
2011-04-02 Misc changes. Styling fixes. s/twentyten/initializr/
164 * @since Initializr 1.0
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
165 */
c6b46a73 »
2011-04-20 wrap
166 if (! function_exists('initializr_page_menu_args') ) {
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
167 function initializr_page_menu_args( $args ) {
168 $args['show_home'] = true;
169 return $args;
170 }
c6b46a73 »
2011-04-20 wrap
171 }
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
172 add_filter( 'wp_page_menu_args', 'initializr_page_menu_args' );
173
174 /**
2c831257 »
2011-04-03 Making progress
175 * Sets the post excerpt length to 75 words.
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
176 *
2c831257 »
2011-04-03 Making progress
177 * To override this length in a child theme, remove the filter and add your
178 * own function tied to the excerpt_length filter hook.
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
179 *
58c22f5e »
2011-04-02 Misc changes. Styling fixes. s/twentyten/initializr/
180 * @since Initializr 1.0
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
181 * @return int
182 */
183 function initializr_excerpt_length( $length ) {
2c831257 »
2011-04-03 Making progress
184 return 75;
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
185 }
186 add_filter( 'excerpt_length', 'initializr_excerpt_length' );
187
188 /**
189 * Returns a "Continue Reading" link for excerpts
190 *
58c22f5e »
2011-04-02 Misc changes. Styling fixes. s/twentyten/initializr/
191 * @since Initializr 1.0
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
192 * @return string "Continue Reading" link
193 */
c6b46a73 »
2011-04-20 wrap
194 if (! function_exists('initializr_continue_reading_link') ) {
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
195 function initializr_continue_reading_link() {
196 return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'initializr' ) . '</a>';
197 }
c6b46a73 »
2011-04-20 wrap
198 }
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
199
200 /**
201 * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and initializr_continue_reading_link().
202 *
203 * To override this in a child theme, remove the filter and add your own
204 * function tied to the excerpt_more filter hook.
205 *
58c22f5e »
2011-04-02 Misc changes. Styling fixes. s/twentyten/initializr/
206 * @since Initializr 1.0
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
207 * @return string An ellipsis
208 */
209 function initializr_auto_excerpt_more( $more ) {
210 return ' &hellip;' . initializr_continue_reading_link();
211 }
212 add_filter( 'excerpt_more', 'initializr_auto_excerpt_more' );
213
214 /**
215 * Adds a pretty "Continue Reading" link to custom post excerpts.
216 *
217 * To override this link in a child theme, remove the filter and add your own
218 * function tied to the get_the_excerpt filter hook.
219 *
58c22f5e »
2011-04-02 Misc changes. Styling fixes. s/twentyten/initializr/
220 * @since Initializr 1.0
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
221 * @return string Excerpt with a pretty "Continue Reading" link
222 */
223 function initializr_custom_excerpt_more( $output ) {
224 if ( has_excerpt() && ! is_attachment() ) {
225 $output .= initializr_continue_reading_link();
226 }
227 return $output;
228 }
229 add_filter( 'get_the_excerpt', 'initializr_custom_excerpt_more' );
230
231 /**
232 * Remove inline styles printed when the gallery shortcode is used.
233 *
58c22f5e »
2011-04-02 Misc changes. Styling fixes. s/twentyten/initializr/
234 * Galleries are styled by the theme in Initializr's style.css. This is just
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
235 * a simple filter call that tells WordPress to not use the default styles.
236 *
58c22f5e »
2011-04-02 Misc changes. Styling fixes. s/twentyten/initializr/
237 * @since Initializr 1.2
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
238 */
239 add_filter( 'use_default_gallery_style', '__return_false' );
240
241 if ( ! function_exists( 'initializr_comment' ) ) :
242 /**
243 * Template for comments and pingbacks.
244 *
245 * To override this walker in a child theme without modifying the comments template
246 * simply create your own initializr_comment(), and that function will be used instead.
247 *
248 * Used as a callback by wp_list_comments() for displaying the comments.
249 *
58c22f5e »
2011-04-02 Misc changes. Styling fixes. s/twentyten/initializr/
250 * @since Initializr 1.0
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
251 */
252 function initializr_comment( $comment, $args, $depth ) {
253 $GLOBALS['comment'] = $comment;
58c22f5e »
2011-04-02 Misc changes. Styling fixes. s/twentyten/initializr/
254 $GLOBALS['depth'] = $depth;
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
255 switch ( $comment->comment_type ) :
256 case '' :
ee6528f1 »
2011-04-18 Add the remaining formats. More styling. Support for setting post-for…
257 ?><!-- comment callback -->
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
258 <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
259 <div id="comment-<?php comment_ID(); ?>">
260 <div class="comment-author vcard">
261 <?php echo get_avatar( $comment, 40 ); ?>
262 <?php printf( __( '%s <span class="says">says:</span>', 'initializr' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
263 </div><!-- .comment-author .vcard -->
264 <?php if ( $comment->comment_approved == '0' ) : ?>
265 <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'initializr' ); ?></em>
266 <br />
267 <?php endif; ?>
268
269 <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
270 <?php
271 /* translators: 1: date, 2: time */
272 printf( __( '%1$s at %2$s', 'initializr' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'initializr' ), ' ' );
273 ?>
274 </div><!-- .comment-meta .commentmetadata -->
275
276 <div class="comment-body"><?php comment_text(); ?></div>
277
278 <div class="reply">
279 <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
280 </div><!-- .reply -->
281 </div><!-- #comment-## -->
282
283 <?php
284 break;
285 case 'pingback' :
286 case 'trackback' :
287 ?>
288 <li class="post pingback">
289 <p><?php _e( 'Pingback:', 'initializr' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'initializr' ), ' ' ); ?></p>
290 <?php
291 break;
292 endswitch;
293 }
294 endif;
295
296 /**
297 * Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
298 *
299 * To override initializr_widgets_init() in a child theme, remove the action hook and add your own
300 * function tied to the init hook.
301 *
58c22f5e »
2011-04-02 Misc changes. Styling fixes. s/twentyten/initializr/
302 * @since Initializr 1.0
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
303 * @uses register_sidebar
304 */
305 function initializr_widgets_init() {
cfacb211 »
2011-04-22 widget area madness!
306 // Header widget area
307 register_sidebar( array(
308 'name' => __( 'Above Header Widget Area', 'initializr' ),
309 'id' => 'above-header',
310 'description' => __( 'In the header, before site name', 'initializr' ),
311 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
312 'after_widget' => '</li>',
313 'before_title' => '<h3 class="widget-title">',
314 'after_title' => '</h3>',
315 ) );
316
317 // Primary sidebar, located at the top of the sidebar.
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
318 register_sidebar( array(
319 'name' => __( 'Primary Widget Area', 'initializr' ),
d627aa23 »
2011-04-22 rename primary widget area
320 'id' => 'primary-aside',
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
321 'description' => __( 'The primary widget area', 'initializr' ),
322 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
323 'after_widget' => '</li>',
324 'before_title' => '<h3 class="widget-title">',
325 'after_title' => '</h3>',
326 ) );
327
cfacb211 »
2011-04-22 widget area madness!
328 // Secondary sidebar, located below the Primary Widget Area in the sidebar. Empty by default.
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
329 register_sidebar( array(
330 'name' => __( 'Secondary Widget Area', 'initializr' ),
2f6ce980 »
2011-04-22 add index-top widget area
331 'id' => 'secondary-aside',
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
332 'description' => __( 'The secondary widget area', 'initializr' ),
333 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
334 'after_widget' => '</li>',
335 'before_title' => '<h3 class="widget-title">',
336 'after_title' => '</h3>',
337 ) );
338
2f6ce980 »
2011-04-22 add index-top widget area
339 // Top of the content area. Empty by default.
340 register_sidebar( array(
341 'name' => __( 'Index Top Widget Area', 'initializr' ),
342 'id' => 'index-top',
343 'description' => __( 'Appears between header and content on index and single post pages.', 'initializr' ),
344 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
345 'after_widget' => '</li>',
346 'before_title' => '<h3 class="widget-title">',
347 'after_title' => '</h3>',
348 ) );
349
cfacb211 »
2011-04-22 widget area madness!
350 // Top of the content area. Empty by default.
351 register_sidebar( array(
352 'name' => __( 'Index Insert Widget Area', 'initializr' ),
353 'id' => 'index-insert',
354 'description' => __( 'Appears between 1st and 2nd post on index page.', 'initializr' ),
355 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
356 'after_widget' => '</li>',
357 'before_title' => '<h3 class="widget-title">',
358 'after_title' => '</h3>',
359 ) );
360
361 // Top of the content area. Empty by default.
362 register_sidebar( array(
363 'name' => __( 'Index Bottom Widget Area', 'initializr' ),
364 'id' => 'index-bottom',
365 'description' => __( 'Appears below posts on index page.', 'initializr' ),
366 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
367 'after_widget' => '</li>',
368 'before_title' => '<h3 class="widget-title">',
369 'after_title' => '</h3>',
370 ) );
371
372 // Top of the content area. Empty by default.
373 register_sidebar( array(
374 'name' => __( 'Single Top Widget Area', 'initializr' ),
375 'id' => 'single-top',
376 'description' => __( 'Appears between header and content on single post pages.', 'initializr' ),
377 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
378 'after_widget' => '</li>',
379 'before_title' => '<h3 class="widget-title">',
380 'after_title' => '</h3>',
381 ) );
382
383 // Top of the content area. Empty by default.
384 register_sidebar( array(
385 'name' => __( 'Single Bottom Widget Area', 'initializr' ),
386 'id' => 'single-bottom',
387 'description' => __( 'Appears below posts on single pages.', 'initializr' ),
388 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
389 'after_widget' => '</li>',
390 'before_title' => '<h3 class="widget-title">',
391 'after_title' => '</h3>',
392 ) );
393
394 // Top of the content area. Empty by default.
395 register_sidebar( array(
396 'name' => __( 'Page Top Widget Area', 'initializr' ),
397 'id' => 'page-top',
398 'description' => __( 'Appears between header and content on pages.', 'initializr' ),
399 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
400 'after_widget' => '</li>',
401 'before_title' => '<h3 class="widget-title">',
402 'after_title' => '</h3>',
403 ) );
404
405 // Top of the content area. Empty by default.
406 register_sidebar( array(
407 'name' => __( 'Page Bottom Widget Area', 'initializr' ),
408 'id' => 'Page-bottom',
409 'description' => __( 'Appears below posts on pages.', 'initializr' ),
410 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
411 'after_widget' => '</li>',
412 'before_title' => '<h3 class="widget-title">',
413 'after_title' => '</h3>',
414 ) );
415
416 // Footer 1, located in the footer. Empty by default.
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
417 register_sidebar( array(
418 'name' => __( 'First Footer Widget Area', 'initializr' ),
419 'id' => 'first-footer-widget-area',
420 'description' => __( 'The first footer widget area', 'initializr' ),
421 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
422 'after_widget' => '</li>',
423 'before_title' => '<h3 class="widget-title">',
424 'after_title' => '</h3>',
425 ) );
426
cfacb211 »
2011-04-22 widget area madness!
427 // Footer 2, located in the footer. Empty by default.
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
428 register_sidebar( array(
429 'name' => __( 'Second Footer Widget Area', 'initializr' ),
430 'id' => 'second-footer-widget-area',
431 'description' => __( 'The second footer widget area', 'initializr' ),
432 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
433 'after_widget' => '</li>',
434 'before_title' => '<h3 class="widget-title">',
435 'after_title' => '</h3>',
436 ) );
437
cfacb211 »
2011-04-22 widget area madness!
438 // Footer 3, located in the footer. Empty by default.
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
439 register_sidebar( array(
440 'name' => __( 'Third Footer Widget Area', 'initializr' ),
441 'id' => 'third-footer-widget-area',
442 'description' => __( 'The third footer widget area', 'initializr' ),
443 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
444 'after_widget' => '</li>',
445 'before_title' => '<h3 class="widget-title">',
446 'after_title' => '</h3>',
447 ) );
448
cfacb211 »
2011-04-22 widget area madness!
449 // Footer 4, located in the footer. Empty by default.
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
450 register_sidebar( array(
451 'name' => __( 'Fourth Footer Widget Area', 'initializr' ),
452 'id' => 'fourth-footer-widget-area',
453 'description' => __( 'The fourth footer widget area', 'initializr' ),
454 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
455 'after_widget' => '</li>',
456 'before_title' => '<h3 class="widget-title">',
457 'after_title' => '</h3>',
458 ) );
459 }
460 /** Register sidebars by running initializr_widgets_init() on the widgets_init hook. */
461 add_action( 'widgets_init', 'initializr_widgets_init' );
462
463 /**
464 * Removes the default styles that are packaged with the Recent Comments widget.
465 *
2c831257 »
2011-04-03 Making progress
466 * To override this in a child theme, remove the filter and optionally add
467 * your own function tied to the widgets_init action hook.
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
468 *
2c831257 »
2011-04-03 Making progress
469 * This function uses a filter (show_recent_comments_widget_style) new in
470 * WordPress 3.1 to remove the default style. Using Initializr 1.2 in
471 * WordPress 3.0 will show the styles, but they won't have any effect on the
472 * widget in default Initializr styling.
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
473 *
58c22f5e »
2011-04-02 Misc changes. Styling fixes. s/twentyten/initializr/
474 * @since Initializr 1.0
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
475 */
476 function initializr_remove_recent_comments_style() {
477 add_filter( 'show_recent_comments_widget_style', '__return_false' );
478 }
479 add_action( 'widgets_init', 'initializr_remove_recent_comments_style' );
480
481 if ( ! function_exists( 'initializr_posted_on' ) ) :
482 /**
483 * Prints HTML with meta information for the current post-date/time and author.
484 *
58c22f5e »
2011-04-02 Misc changes. Styling fixes. s/twentyten/initializr/
485 * @since Initializr 1.0
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
486 */
487 function initializr_posted_on() {
488 printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'initializr' ),
489 'meta-prep meta-prep-author',
490 sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
491 get_permalink(),
492 esc_attr( get_the_time() ),
493 get_the_date()
494 ),
495 sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
496 get_author_posts_url( get_the_author_meta( 'ID' ) ),
497 sprintf( esc_attr__( 'View all posts by %s', 'initializr' ), get_the_author() ),
498 get_the_author()
499 )
500 );
501 }
502 endif;
503
504 if ( ! function_exists( 'initializr_posted_in' ) ) :
505 /**
506 * Prints HTML with meta information for the current post (category, tags and permalink).
507 *
58c22f5e »
2011-04-02 Misc changes. Styling fixes. s/twentyten/initializr/
508 * @since Initializr 1.0
2e4fc22d »
2011-04-01 Initial commit. Bare bones.
509 */
510 function initializr_posted_in() {
511 // Retrieves tag list of current post, separated by commas.
512 $tag_list = get_the_tag_list( '', ', ' );
513 if ( $tag_list ) {
514 $posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'initializr' );
515 } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
516 $posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'initializr' );
517 } else {
518 $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'initializr' );
519 }
520 // Prints the string, replacing the placeholders.
521 printf(
522 $posted_in,
523 get_the_category_list( ', ' ),
524 $tag_list,
525 get_permalink(),
526 the_title_attribute( 'echo=0' )
527 );
528 }
529 endif;
58c22f5e »
2011-04-02 Misc changes. Styling fixes. s/twentyten/initializr/
530
531 if ( ! function_exists( 'initializr_post_date' ) ) :
532 function initializr_post_date() {
533 $mon = get_the_time('M');
534 $day = get_the_time('d');
535 $year = get_the_time('Y');
536
537 printf('<div class="post-date"><span class="month">%s</span><span class="day">%s</span><span class="year">%s</span></div>', $mon, $day, $year);
538 }
539 endif;
540
2c831257 »
2011-04-03 Making progress
541 function gr_post_thumbnail($text) {
542 if (function_exists('has_post_thumbnail') && has_post_thumbnail() /* && (is_home() || is_singular()) */) {
c203ae90 »
2011-04-03 More tweakage.
543 $text = '<div class="featured-image align-right" style="float: right;">' . get_the_post_thumbnail() . '</div>' . $text;
2c831257 »
2011-04-03 Making progress
544 }
545
546 return $text;
547 }
548
549 /*
550 * Extract the title and url for a post object for a 'link' post format.
551 */
552 function extract_first_link($post) {
553 $str = $post->post_content;
554 if ( preg_match('%^(https?://[^\s]*)$%', trim($str), $matches) ) {
555 $url = $matches[1];
556 if ($post->post_title) {
557 $title = $post->post_title;
558 } else {
559 $title = $url;
560 }
561 return array('url' => $url, 'title' => $title );
562 }
563
564 preg_match('%<a\s*+(.*?)href=(["\']?)(.*?)\2(.*?)>(.*?)</a>%', trim($str), $matches);
565 $url = $matches[3];
566 $title = $post->post_title ? $post->post_title : $matches[5];
567
568 return array( 'url' => $url, 'title' => $title );
569 }
570
571 function timeAgo($timestamp=0, $granularity=2, $format='Y-m-d H:i:s'){
572 if ( 0 === $timestamp ) {
573 $timestamp = get_the_time("U");
574 }
575 $difference = time() - $timestamp;
576 if($difference < 0) return 'just now';
577 elseif($difference < 31536000){
578 $periods = array('mon' => 2592000, 'wk' => 604800,'day' => 86400,'hr' => 3600,'min' => 60,'sec' => 1);
579 $output = '';
580 foreach($periods as $key => $value){
581 if($difference >= $value){
582 $time = round($difference / $value);
583 $difference %= $value;
584 $output .= ($output ? ' ' : '').$time.' ';
585 $output .= (($time > 1 /* && $key == 'day' */) ? $key.'s' : $key);
586 $granularity--;
587 }
588 if($granularity == 0) break;
589 }
590 return ($output ? $output : 'Just now').' ago';
591 }
592 else return date($format, $timestamp);
593 }
594
ee6528f1 »
2011-04-18 Add the remaining formats. More styling. Support for setting post-for…
595
596 function process_chat( $content ) {
597 if (has_post_format('chat')) {
598 $content = preg_replace('%<p>\s*([^:]+):(\s.*)</p>%e', '\'<p class="chat"><span class="person person-\'.sanitize_title(\'\\1\').\'">\\1:</span>\\2</p>\'', $content);
599 }
600 return $content;
601 }
602
603 /**
604 * If a post comes from XML-RPC or APP, try to detect and set the post
605 * format
606 */
607 function auto_post_format_detect( $data, $postarr ) {
608 global $dc_auto_post_format;
609 if ( defined('XMLRPC_REQUEST') || defined('APP_REQUEST') ) {
610 /* Look for an image at the beginning of a post. Optionally preceded
611 * by <br> or <p> tags. Optionally linked with an <a> tag.
612 */
613 if ( preg_match('%^(((<p[^>]*?>)?)((<br ?/?>)*?))*?(<a\s+[^>]+>)?<img\s+[^>]+>%', $post->post_content) ) {
614 $dc_auto_post_format = 'image';
615 }
616
617 /* This is insufficient. And transcoding video is a real pain. I think
618 * the best way to handle this is to upload videos to a dedicated
619 * service (YouTube, Vimeo, Flickr, etc), and use plugins to import them
620 * as posts from there. Maybe one day there will be a universal codec
621 * and container format shared by all browsers and mobile devices. Yeah,
622 * right.
623 */
624 /*
625 if ( preg_match('%^(<br ?/?>)*<video\s+[^>]+>%', $post->post_content) ) {
626 $dc_auto_post_format = 'video';
627 }
628 */
629
630 /*
631 * Look for :FORMAT: in the first 30 chars. If we see it, use that
632 * as the post format. E.g., '<p>:STATUS:Hanging with my buds</p>'
633 * would become a 'format-status' post.
634 */
635 $count = preg_match('%:([A-Za-z]+):%', substr($data['post_content'], 0, 30), $matches);
636 if ( $count ) {
637 // Strip our :FORMAT: sentinel string from the content
638 $data['post_content'] = preg_replace('%:'.$matches[1].':\s*%i', '', $data['post_content'], 1);
639 $dc_auto_post_format = $matches[1];
640 }
641
642 /*
643 * Look for [gallery] in the post. If we see it, set the gallery post
644 * format.
645 */
646 if ( false !== strpos('[gallery]', $data['post_content']) ) {
647 $dc_auto_post_format = 'gallery';
648 }
649
650 if ( $dc_auto_post_format ) {
651 add_action( 'wp_insert_post', 'auto_post_format_set', 10, 2 );
652 }
653 }
654
655 return $data;
656 }
657
658 function auto_post_format_set( $postid, $post ) {
659 global $dc_auto_post_format;
660 // Validate format
661 $dc_auto_post_format = sanitize_key($dc_auto_post_format);
662
663 if ( !array_key_exists( $dc_auto_post_format, get_post_format_strings() ) ) {
664 // not a valid post format. do nothing.
665 return;
666 }
667 set_post_format( $postid, $dc_auto_post_format );
668 }
669
670
671 // Run after WP html formatting
672 add_filter('the_content', 'process_chat', 15);
673
674 add_filter('wp_insert_post_data', 'auto_post_format_detect', 10, 2);
675
Something went wrong with that request. Please try again.