Make WordPress Core


Ignore:
Timestamp:
08/14/2013 04:38:01 PM (13 years ago)
Author:
lancewillett
Message:

Twenty Fourteen: first pass at matching code standards achieved with Twenty Thirteen development. See #24858, props obenland.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyfourteen/functions.php

    r24990 r25021  
    2828 * before the init hook. The init hook is too late for some features, such as indicating
    2929 * support post thumbnails.
    30  *
    3130 */
    3231function twentyfourteen_setup() {
    33         /**
    34          * Custom template tags for this theme.
    35          */
    36         require( get_template_directory() . '/inc/template-tags.php' );
    37 
    38         /**
    39          * Customizer additions
    40          */
    41         require( get_template_directory() . '/inc/customizer.php' );
    4232
    4333        /**
     
    8272         * This theme allows users to set a custom background.
    8373         */
    84         $args = apply_filters( 'twentyfourteen_custom_background_args', array( 'default-color' => 'f5f5f5' ) );
    85 
    86         if ( function_exists( 'wp_get_theme' ) ) {
    87                 add_theme_support( 'custom-background', $args );
    88         } else {
    89                 // Compat: Versions of WordPress prior to 3.4.
    90                 define( 'BACKGROUND_COLOR', $args['default-color'] );
    91                 add_custom_background();
    92         }
     74        add_theme_support( 'custom-background', apply_filters( 'twentyfourteen_custom_background_args', array(
     75                'default-color' => 'f5f5f5',
     76        ) ) );
    9377}
    9478endif; // twentyfourteen_setup
     
    11397                return false;
    11498
    115         $minimum = absint( $minimum );
    11699        $featured_posts = apply_filters( 'twentyfourteen_get_featured_posts', array() );
    117100
    118         if ( ! is_array( $featured_posts ) )
    119                 return false;
    120 
    121         if ( $minimum > count( $featured_posts ) )
    122                 return false;
    123 
    124         return true;
     101        return is_array( $featured_posts ) && count( $featured_posts ) > absint( $minimum );
    125102}
    126103
     
    192169
    193170/**
    194  * Register Google fonts for Twenty Fourteen
     171 * Register Google fonts for Twenty Fourteen.
    195172 *
    196173 */
     
    198175        /* translators: If there are characters in your language that are not supported
    199176           by Lato, translate this to 'off'. Do not translate into your own language. */
    200         if ( 'off' !== _x( 'on', 'Lato font: on or off', 'twentyfourteen' ) ) {
    201 
    202                 $protocol = is_ssl() ? 'https' : 'http';
    203 
    204                 wp_register_style( 'twentyfourteen-lato', "$protocol://fonts.googleapis.com/css?family=Lato:100,300,400,700,900,100italic,300italic,400italic,700italic,900italic", array(), null );
    205         }
     177        if ( 'off' !== _x( 'on', 'Lato font: on or off', 'twentyfourteen' ) )
     178                wp_register_style( 'twentyfourteen-lato', '//fonts.googleapis.com/css?family=Lato:100,300,400,700,900,100italic,300italic,400italic,700italic,900italic', array(), null );
    206179}
    207180add_action( 'init', 'twentyfourteen_fonts' );
     
    216189        wp_enqueue_style( 'twentyfourteen-lato' );
    217190
    218         if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
     191        if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
    219192                wp_enqueue_script( 'comment-reply' );
    220         }
    221 
    222         if ( is_singular() && wp_attachment_is_image() ) {
     193
     194        if ( is_singular() && wp_attachment_is_image() )
    223195                wp_enqueue_script( 'twentyfourteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20130402' );
    224         }
    225196
    226197        wp_enqueue_script( 'twentyfourteen-theme', get_template_directory_uri() . '/js/theme.js', array( 'jquery' ), '20130402', true );
     
    232203 *
    233204 */
    234 function twentyfourteen_admin_fonts( $hook_suffix ) {
    235         if ( 'appearance_page_custom-header' != $hook_suffix )
    236                 return;
    237 
     205function twentyfourteen_admin_fonts() {
    238206        wp_enqueue_style( 'twentyfourteen-lato' );
    239207}
    240 add_action( 'admin_enqueue_scripts', 'twentyfourteen_admin_fonts' );
     208add_action( 'admin_print_scripts-appearance_page_custom-header', 'twentyfourteen_admin_fonts' );
    241209
    242210/**
     
    285253}
    286254add_filter( 'get_the_excerpt', 'twentyfourteen_custom_excerpt_more' );
     255
     256if ( ! function_exists( 'twentyfourteen_the_attached_image' ) ) :
     257/**
     258 * Prints the attached image with a link to the next attached image.
     259 *
     260 * @since Twenty Thirteen 1.0
     261 *
     262 * @return void
     263 */
     264function twentyfourteen_the_attached_image() {
     265        $post                = get_post();
     266        $attachment_size     = apply_filters( 'twentyfourteen_attachment_size', array( 1200, 1200 ) );
     267        $next_attachment_url = wp_get_attachment_url();
     268
     269        /**
     270         * Grab the IDs of all the image attachments in a gallery so we can get the URL
     271         * of the next adjacent image in a gallery, or the first image (if we're
     272         * looking at the last image in a gallery), or, in a gallery of one, just the
     273         * link to that image file.
     274         */
     275        $attachment_ids = get_posts( array(
     276                'post_parent'    => $post->post_parent,
     277                'fields'         => 'ids',
     278                'numberposts'    => -1,
     279                'post_status'    => 'inherit',
     280                'post_type'      => 'attachment',
     281                'post_mime_type' => 'image',
     282                'order'          => 'ASC',
     283                'orderby'        => 'menu_order ID'
     284        ) );
     285
     286        // If there is more than 1 attachment in a gallery...
     287        if ( count( $attachment_ids ) > 1 ) {
     288                foreach ( $attachment_ids as $attachment_id ) {
     289                        if ( $attachment_id == $post->ID ) {
     290                                $next_id = current( $attachment_ids );
     291                                break;
     292                        }
     293                }
     294
     295                // get the URL of the next image attachment...
     296                if ( $next_id )
     297                        $next_attachment_url = get_attachment_link( $next_id );
     298
     299                // or get the URL of the first image attachment.
     300                else
     301                        $next_attachment_url = get_attachment_link( array_shift( $attachment_ids ) );
     302        }
     303
     304        printf( '<a href="%1$s" title="%2$s" rel="attachment">%3$s</a>',
     305                esc_url( $next_attachment_url ),
     306                the_title_attribute( array( 'echo' => false ) ),
     307                wp_get_attachment_image( $post->ID, $attachment_size )
     308        );
     309}
     310endif;
    287311
    288312/**
     
    329353
    330354        if ( $class )
    331                 echo 'class="clearfix ' . $class . '"';
     355                printf( 'class="%s"', $class );
    332356}
    333357
     
    445469}
    446470add_filter( 'wp_title', 'twentyfourteen_wp_title', 10, 2 );
     471
     472/**
     473 * Custom template tags for this theme.
     474 */
     475require get_template_directory() . '/inc/template-tags.php';
     476
     477/**
     478 * Customizer additions
     479 */
     480require get_template_directory() . '/inc/customizer.php';
Note: See TracChangeset for help on using the changeset viewer.