Ticket #22346: functions.php

File functions.php, 20.3 KB (added by Videojug, 7 months ago)

The modified default theme.

Line 
1<?php
2wp_oembed_add_provider( '#http://(www\.)?videojug.com/(film|interview)/.*#i', 'http://www.videojug.com/oembed.{format}', true );
3
4/**
5 * Twenty Eleven functions and definitions
6 *
7 * Sets up the theme and provides some helper functions. Some helper functions
8 * are used in the theme as custom template tags. Others are attached to action and
9 * filter hooks in WordPress to change core functionality.
10 *
11 * The first function, twentyeleven_setup(), sets up the theme by registering support
12 * for various features in WordPress, such as post thumbnails, navigation menus, and the like.
13 *
14 * When using a child theme (see http://codex.wordpress.org/Theme_Development and
15 * http://codex.wordpress.org/Child_Themes), you can override certain functions
16 * (those wrapped in a function_exists() call) by defining them first in your child theme's
17 * functions.php file. The child theme's functions.php file is included before the parent
18 * theme's file, so the child theme functions would be used.
19 *
20 * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
21 * to a filter or action hook. The hook can be removed by using remove_action() or
22 * remove_filter() and you can attach your own function to the hook.
23 *
24 * We can remove the parent theme's hook only after it is attached, which means we need to
25 * wait until setting up the child theme:
26 *
27 * <code>
28 * add_action( 'after_setup_theme', 'my_child_theme_setup' );
29 * function my_child_theme_setup() {
30 *     // We are providing our own filter for excerpt_length (or using the unfiltered value)
31 *     remove_filter( 'excerpt_length', 'twentyeleven_excerpt_length' );
32 *     ...
33 * }
34 * </code>
35 *
36 * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
37 *
38 * @package WordPress
39 * @subpackage Twenty_Eleven
40 * @since Twenty Eleven 1.0
41 */
42
43/**
44 * Set the content width based on the theme's design and stylesheet.
45 */
46if ( ! isset( $content_width ) )
47        $content_width = 584;
48
49/**
50 * Tell WordPress to run twentyeleven_setup() when the 'after_setup_theme' hook is run.
51 */
52add_action( 'after_setup_theme', 'twentyeleven_setup' );
53
54if ( ! function_exists( 'twentyeleven_setup' ) ):
55/**
56 * Sets up theme defaults and registers support for various WordPress features.
57 *
58 * Note that this function is hooked into the after_setup_theme hook, which runs
59 * before the init hook. The init hook is too late for some features, such as indicating
60 * support post thumbnails.
61 *
62 * To override twentyeleven_setup() in a child theme, add your own twentyeleven_setup to your child theme's
63 * functions.php file.
64 *
65 * @uses load_theme_textdomain() For translation/localization support.
66 * @uses add_editor_style() To style the visual editor.
67 * @uses add_theme_support() To add support for post thumbnails, automatic feed links, and Post Formats.
68 * @uses register_nav_menus() To add support for navigation menus.
69 * @uses add_custom_background() To add support for a custom background.
70 * @uses add_custom_image_header() To add support for a custom header.
71 * @uses register_default_headers() To register the default custom header images provided with the theme.
72 * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
73 *
74 * @since Twenty Eleven 1.0
75 */
76function twentyeleven_setup() {
77
78        /* Make Twenty Eleven available for translation.
79         * Translations can be added to the /languages/ directory.
80         * If you're building a theme based on Twenty Eleven, use a find and replace
81         * to change 'twentyeleven' to the name of your theme in all the template files.
82         */
83        load_theme_textdomain( 'twentyeleven', TEMPLATEPATH . '/languages' );
84
85        $locale = get_locale();
86        $locale_file = TEMPLATEPATH . "/languages/$locale.php";
87        if ( is_readable( $locale_file ) )
88                require_once( $locale_file );
89
90        // This theme styles the visual editor with editor-style.css to match the theme style.
91        add_editor_style();
92
93        // Load up our theme options page and related code.
94        require( dirname( __FILE__ ) . '/inc/theme-options.php' );
95
96        // Grab Twenty Eleven's Ephemera widget.
97        require( dirname( __FILE__ ) . '/inc/widgets.php' );
98
99        // Add default posts and comments RSS feed links to <head>.
100        add_theme_support( 'automatic-feed-links' );
101
102        // This theme uses wp_nav_menu() in one location.
103        register_nav_menu( 'primary', __( 'Primary Menu', 'twentyeleven' ) );
104
105        // Add support for a variety of post formats
106        add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) );
107
108        // Add support for custom backgrounds
109        add_custom_background();
110
111        // This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images
112        add_theme_support( 'post-thumbnails' );
113
114        // The next four constants set how Twenty Eleven supports custom headers.
115
116        // The default header text color
117        define( 'HEADER_TEXTCOLOR', '000' );
118
119        // By leaving empty, we allow for random image rotation.
120        define( 'HEADER_IMAGE', '' );
121
122        // The height and width of your custom header.
123        // Add a filter to twentyeleven_header_image_width and twentyeleven_header_image_height to change these values.
124        define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyeleven_header_image_width', 1000 ) );
125        define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyeleven_header_image_height', 288 ) );
126
127        // We'll be using post thumbnails for custom header images on posts and pages.
128        // We want them to be the size of the header image that we just defined
129        // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
130        set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
131
132        // Add Twenty Eleven's custom image sizes
133        add_image_size( 'large-feature', HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); // Used for large feature (header) images
134        add_image_size( 'small-feature', 500, 300 ); // Used for featured posts if a large-feature doesn't exist
135
136        // Turn on random header image rotation by default.
137        add_theme_support( 'custom-header', array( 'random-default' => true ) );
138
139        // Add a way for the custom header to be styled in the admin panel that controls
140        // custom headers. See twentyeleven_admin_header_style(), below.
141        add_custom_image_header( 'twentyeleven_header_style', 'twentyeleven_admin_header_style', 'twentyeleven_admin_header_image' );
142
143        // ... and thus ends the changeable header business.
144
145        // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
146        register_default_headers( array(
147                'wheel' => array(
148                        'url' => '%s/images/headers/wheel.jpg',
149                        'thumbnail_url' => '%s/images/headers/wheel-thumbnail.jpg',
150                        /* translators: header image description */
151                        'description' => __( 'Wheel', 'twentyeleven' )
152                ),
153                'shore' => array(
154                        'url' => '%s/images/headers/shore.jpg',
155                        'thumbnail_url' => '%s/images/headers/shore-thumbnail.jpg',
156                        /* translators: header image description */
157                        'description' => __( 'Shore', 'twentyeleven' )
158                ),
159                'trolley' => array(
160                        'url' => '%s/images/headers/trolley.jpg',
161                        'thumbnail_url' => '%s/images/headers/trolley-thumbnail.jpg',
162                        /* translators: header image description */
163                        'description' => __( 'Trolley', 'twentyeleven' )
164                ),
165                'pine-cone' => array(
166                        'url' => '%s/images/headers/pine-cone.jpg',
167                        'thumbnail_url' => '%s/images/headers/pine-cone-thumbnail.jpg',
168                        /* translators: header image description */
169                        'description' => __( 'Pine Cone', 'twentyeleven' )
170                ),
171                'chessboard' => array(
172                        'url' => '%s/images/headers/chessboard.jpg',
173                        'thumbnail_url' => '%s/images/headers/chessboard-thumbnail.jpg',
174                        /* translators: header image description */
175                        'description' => __( 'Chessboard', 'twentyeleven' )
176                ),
177                'lanterns' => array(
178                        'url' => '%s/images/headers/lanterns.jpg',
179                        'thumbnail_url' => '%s/images/headers/lanterns-thumbnail.jpg',
180                        /* translators: header image description */
181                        'description' => __( 'Lanterns', 'twentyeleven' )
182                ),
183                'willow' => array(
184                        'url' => '%s/images/headers/willow.jpg',
185                        'thumbnail_url' => '%s/images/headers/willow-thumbnail.jpg',
186                        /* translators: header image description */
187                        'description' => __( 'Willow', 'twentyeleven' )
188                ),
189                'hanoi' => array(
190                        'url' => '%s/images/headers/hanoi.jpg',
191                        'thumbnail_url' => '%s/images/headers/hanoi-thumbnail.jpg',
192                        /* translators: header image description */
193                        'description' => __( 'Hanoi Plant', 'twentyeleven' )
194                )
195        ) );
196}
197endif; // twentyeleven_setup
198
199if ( ! function_exists( 'twentyeleven_header_style' ) ) :
200/**
201 * Styles the header image and text displayed on the blog
202 *
203 * @since Twenty Eleven 1.0
204 */
205function twentyeleven_header_style() {
206
207        // If no custom options for text are set, let's bail
208        // get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value
209        if ( HEADER_TEXTCOLOR == get_header_textcolor() )
210                return;
211        // If we get this far, we have custom styles. Let's do this.
212        ?>
213        <style type="text/css">
214        <?php
215                // Has the text been hidden?
216                if ( 'blank' == get_header_textcolor() ) :
217        ?>
218                #site-title,
219                #site-description {
220                        position: absolute !important;
221                        clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
222                        clip: rect(1px, 1px, 1px, 1px);
223                }
224        <?php
225                // If the user has set a custom color for the text use that
226                else :
227        ?>
228                #site-title a,
229                #site-description {
230                        color: #<?php echo get_header_textcolor(); ?> !important;
231                }
232        <?php endif; ?>
233        </style>
234        <?php
235}
236endif; // twentyeleven_header_style
237
238if ( ! function_exists( 'twentyeleven_admin_header_style' ) ) :
239/**
240 * Styles the header image displayed on the Appearance > Header admin panel.
241 *
242 * Referenced via add_custom_image_header() in twentyeleven_setup().
243 *
244 * @since Twenty Eleven 1.0
245 */
246function twentyeleven_admin_header_style() {
247?>
248        <style type="text/css">
249        .appearance_page_custom-header #headimg {
250                border: none;
251        }
252        #headimg h1,
253        #desc {
254                font-family: "Helvetica Neue", Arial, Helvetica, "Nimbus Sans L", sans-serif;
255        }
256        #headimg h1 {
257                margin: 0;
258        }
259        #headimg h1 a {
260                font-size: 32px;
261                line-height: 36px;
262                text-decoration: none;
263        }
264        #desc {
265                font-size: 14px;
266                line-height: 23px;
267                padding: 0 0 3em;
268        }
269        <?php
270                // If the user has set a custom color for the text use that
271                if ( get_header_textcolor() != HEADER_TEXTCOLOR ) :
272        ?>
273                #site-title a,
274                #site-description {
275                        color: #<?php echo get_header_textcolor(); ?>;
276                }
277        <?php endif; ?>
278        #headimg img {
279                max-width: 1000px;
280                height: auto;
281                width: 100%;
282        }
283        </style>
284<?php
285}
286endif; // twentyeleven_admin_header_style
287
288if ( ! function_exists( 'twentyeleven_admin_header_image' ) ) :
289/**
290 * Custom header image markup displayed on the Appearance > Header admin panel.
291 *
292 * Referenced via add_custom_image_header() in twentyeleven_setup().
293 *
294 * @since Twenty Eleven 1.0
295 */
296function twentyeleven_admin_header_image() { ?>
297        <div id="headimg">
298                <?php
299                if ( 'blank' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) || '' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) )
300                        $style = ' style="display:none;"';
301                else
302                        $style = ' style="color:#' . get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) . ';"';
303                ?>
304                <h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
305                <div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>
306                <?php $header_image = get_header_image();
307                if ( ! empty( $header_image ) ) : ?>
308                        <img src="<?php echo esc_url( $header_image ); ?>" alt="" />
309                <?php endif; ?>
310        </div>
311<?php }
312endif; // twentyeleven_admin_header_image
313
314/**
315 * Sets the post excerpt length to 40 words.
316 *
317 * To override this length in a child theme, remove the filter and add your own
318 * function tied to the excerpt_length filter hook.
319 */
320function twentyeleven_excerpt_length( $length ) {
321        return 40;
322}
323add_filter( 'excerpt_length', 'twentyeleven_excerpt_length' );
324
325/**
326 * Returns a "Continue Reading" link for excerpts
327 */
328function twentyeleven_continue_reading_link() {
329        return ' <a href="'. esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) . '</a>';
330}
331
332/**
333 * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyeleven_continue_reading_link().
334 *
335 * To override this in a child theme, remove the filter and add your own
336 * function tied to the excerpt_more filter hook.
337 */
338function twentyeleven_auto_excerpt_more( $more ) {
339        return ' &hellip;' . twentyeleven_continue_reading_link();
340}
341add_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' );
342
343/**
344 * Adds a pretty "Continue Reading" link to custom post excerpts.
345 *
346 * To override this link in a child theme, remove the filter and add your own
347 * function tied to the get_the_excerpt filter hook.
348 */
349function twentyeleven_custom_excerpt_more( $output ) {
350        if ( has_excerpt() && ! is_attachment() ) {
351                $output .= twentyeleven_continue_reading_link();
352        }
353        return $output;
354}
355add_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' );
356
357/**
358 * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
359 */
360function twentyeleven_page_menu_args( $args ) {
361        $args['show_home'] = true;
362        return $args;
363}
364add_filter( 'wp_page_menu_args', 'twentyeleven_page_menu_args' );
365
366/**
367 * Register our sidebars and widgetized areas. Also register the default Epherma widget.
368 *
369 * @since Twenty Eleven 1.0
370 */
371function twentyeleven_widgets_init() {
372
373        register_widget( 'Twenty_Eleven_Ephemera_Widget' );
374
375        register_sidebar( array(
376                'name' => __( 'Main Sidebar', 'twentyeleven' ),
377                'id' => 'sidebar-1',
378                'before_widget' => '<aside id="%1$s" class="widget %2$s">',
379                'after_widget' => "</aside>",
380                'before_title' => '<h3 class="widget-title">',
381                'after_title' => '</h3>',
382        ) );
383
384        register_sidebar( array(
385                'name' => __( 'Showcase Sidebar', 'twentyeleven' ),
386                'id' => 'sidebar-2',
387                'description' => __( 'The sidebar for the optional Showcase Template', 'twentyeleven' ),
388                'before_widget' => '<aside id="%1$s" class="widget %2$s">',
389                'after_widget' => "</aside>",
390                'before_title' => '<h3 class="widget-title">',
391                'after_title' => '</h3>',
392        ) );
393
394        register_sidebar( array(
395                'name' => __( 'Footer Area One', 'twentyeleven' ),
396                'id' => 'sidebar-3',
397                'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ),
398                'before_widget' => '<aside id="%1$s" class="widget %2$s">',
399                'after_widget' => "</aside>",
400                'before_title' => '<h3 class="widget-title">',
401                'after_title' => '</h3>',
402        ) );
403
404        register_sidebar( array(
405                'name' => __( 'Footer Area Two', 'twentyeleven' ),
406                'id' => 'sidebar-4',
407                'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ),
408                'before_widget' => '<aside id="%1$s" class="widget %2$s">',
409                'after_widget' => "</aside>",
410                'before_title' => '<h3 class="widget-title">',
411                'after_title' => '</h3>',
412        ) );
413
414        register_sidebar( array(
415                'name' => __( 'Footer Area Three', 'twentyeleven' ),
416                'id' => 'sidebar-5',
417                'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ),
418                'before_widget' => '<aside id="%1$s" class="widget %2$s">',
419                'after_widget' => "</aside>",
420                'before_title' => '<h3 class="widget-title">',
421                'after_title' => '</h3>',
422        ) );
423}
424add_action( 'widgets_init', 'twentyeleven_widgets_init' );
425
426/**
427 * Display navigation to next/previous pages when applicable
428 */
429function twentyeleven_content_nav( $nav_id ) {
430        global $wp_query;
431
432        if ( $wp_query->max_num_pages > 1 ) : ?>
433                <nav id="<?php echo $nav_id; ?>">
434                        <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3>
435                        <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyeleven' ) ); ?></div>
436                        <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?></div>
437                </nav><!-- #nav-above -->
438        <?php endif;
439}
440
441/**
442 * Return the URL for the first link found in the post content.
443 *
444 * @since Twenty Eleven 1.0
445 * @return string|bool URL or false when no link is present.
446 */
447function twentyeleven_url_grabber() {
448        if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) )
449                return false;
450
451        return esc_url_raw( $matches[1] );
452}
453
454/**
455 * Count the number of footer sidebars to enable dynamic classes for the footer
456 */
457function twentyeleven_footer_sidebar_class() {
458        $count = 0;
459
460        if ( is_active_sidebar( 'sidebar-3' ) )
461                $count++;
462
463        if ( is_active_sidebar( 'sidebar-4' ) )
464                $count++;
465
466        if ( is_active_sidebar( 'sidebar-5' ) )
467                $count++;
468
469        $class = '';
470
471        switch ( $count ) {
472                case '1':
473                        $class = 'one';
474                        break;
475                case '2':
476                        $class = 'two';
477                        break;
478                case '3':
479                        $class = 'three';
480                        break;
481        }
482
483        if ( $class )
484                echo 'class="' . $class . '"';
485}
486
487if ( ! function_exists( 'twentyeleven_comment' ) ) :
488/**
489 * Template for comments and pingbacks.
490 *
491 * To override this walker in a child theme without modifying the comments template
492 * simply create your own twentyeleven_comment(), and that function will be used instead.
493 *
494 * Used as a callback by wp_list_comments() for displaying the comments.
495 *
496 * @since Twenty Eleven 1.0
497 */
498function twentyeleven_comment( $comment, $args, $depth ) {
499        $GLOBALS['comment'] = $comment;
500        switch ( $comment->comment_type ) :
501                case 'pingback' :
502                case 'trackback' :
503        ?>
504        <li class="post pingback">
505                <p><?php _e( 'Pingback:', 'twentyeleven' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?></p>
506        <?php
507                        break;
508                default :
509        ?>
510        <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
511                <article id="comment-<?php comment_ID(); ?>" class="comment">
512                        <footer class="comment-meta">
513                                <div class="comment-author vcard">
514                                        <?php
515                                                $avatar_size = 68;
516                                                if ( '0' != $comment->comment_parent )
517                                                        $avatar_size = 39;
518
519                                                echo get_avatar( $comment, $avatar_size );
520
521                                                /* translators: 1: comment author, 2: date and time */
522                                                printf( __( '%1$s on %2$s <span class="says">said:</span>', 'twentyeleven' ),
523                                                        sprintf( '<span class="fn">%s</span>', get_comment_author_link() ),
524                                                        sprintf( '<a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a>',
525                                                                esc_url( get_comment_link( $comment->comment_ID ) ),
526                                                                get_comment_time( 'c' ),
527                                                                /* translators: 1: date, 2: time */
528                                                                sprintf( __( '%1$s at %2$s', 'twentyeleven' ), get_comment_date(), get_comment_time() )
529                                                        )
530                                                );
531                                        ?>
532
533                                        <?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?>
534                                </div><!-- .comment-author .vcard -->
535
536                                <?php if ( $comment->comment_approved == '0' ) : ?>
537                                        <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyeleven' ); ?></em>
538                                        <br />
539                                <?php endif; ?>
540
541                        </footer>
542
543                        <div class="comment-content"><?php comment_text(); ?></div>
544
545                        <div class="reply">
546                                <?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply <span>&darr;</span>', 'twentyeleven' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
547                        </div><!-- .reply -->
548                </article><!-- #comment-## -->
549
550        <?php
551                        break;
552        endswitch;
553}
554endif; // ends check for twentyeleven_comment()
555
556if ( ! function_exists( 'twentyeleven_posted_on' ) ) :
557/**
558 * Prints HTML with meta information for the current post-date/time and author.
559 * Create your own twentyeleven_posted_on to override in a child theme
560 *
561 * @since Twenty Eleven 1.0
562 */
563function twentyeleven_posted_on() {
564        printf( __( '<span class="sep">Posted on </span><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s" pubdate>%4$s</time></a><span class="by-author"> <span class="sep"> by </span> <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'twentyeleven' ),
565                esc_url( get_permalink() ),
566                esc_attr( get_the_time() ),
567                esc_attr( get_the_date( 'c' ) ),
568                esc_html( get_the_date() ),
569                esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
570                sprintf( esc_attr__( 'View all posts by %s', 'twentyeleven' ), get_the_author() ),
571                esc_html( get_the_author() )
572        );
573}
574endif;
575
576/**
577 * Adds two classes to the array of body classes.
578 * The first is if the site has only had one author with published posts.
579 * The second is if a singular post being displayed
580 *
581 * @since Twenty Eleven 1.0
582 */
583function twentyeleven_body_classes( $classes ) {
584
585        if ( ! is_multi_author() ) {
586                $classes[] = 'single-author';
587        }
588
589        if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) )
590                $classes[] = 'singular';
591
592        return $classes;
593}
594add_filter( 'body_class', 'twentyeleven_body_classes' );
595