Make WordPress Core

Ticket #22499: 22499.3.diff

File 22499.3.diff, 4.4 KB (added by obenland, 12 years ago)
  • wp-content/themes/twentytwelve/functions.php

     
    8383require( get_template_directory() . '/inc/custom-header.php' );
    8484
    8585/**
    86  * Enqueues scripts and styles for front-end.
     86 * Returns the Google font stylesheet URL if available.
    8787 *
    88  * @since Twenty Twelve 1.0
     88 * The use of Open Sans by default is localized. For languages that use
     89 * characters not supported by the font, the font can be disabled.
     90 *
     91 * @since Twenty Twelve 1.2
     92 *
     93 * @return string Font stylesheet or empty string if disabled.
    8994 */
    90 function twentytwelve_scripts_styles() {
    91         global $wp_styles;
    92 
    93         /*
    94          * Adds JavaScript to pages with the comment form to support
    95          * sites with threaded comments (when in use).
    96          */
    97         if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
    98                 wp_enqueue_script( 'comment-reply' );
    99 
    100         /*
    101          * Adds JavaScript for handling the navigation menu hide-and-show behavior.
    102          */
    103         wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '1.0', true );
    104 
    105         /*
    106          * Loads our special font CSS file.
    107          *
    108          * The use of Open Sans by default is localized. For languages that use
    109          * characters not supported by the font, the font can be disabled.
    110          *
    111          * To disable in a child theme, use wp_dequeue_style()
    112          * function mytheme_dequeue_fonts() {
    113          *     wp_dequeue_style( 'twentytwelve-fonts' );
    114          * }
    115          * add_action( 'wp_enqueue_scripts', 'mytheme_dequeue_fonts', 11 );
    116          */
     95function twentytwelve_get_font_url() {
     96        $font_url = '';
    11797
    11898        /* translators: If there are characters in your language that are not supported
    119            by Open Sans, translate this to 'off'. Do not translate into your own language. */
     99         by Open Sans, translate this to 'off'. Do not translate into your own language. */
    120100        if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'twentytwelve' ) ) {
    121101                $subsets = 'latin,latin-ext';
    122102
    123103                /* translators: To add an additional Open Sans character subset specific to your language, translate
    124                    this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language. */
     104                 this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language. */
    125105                $subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)', 'twentytwelve' );
    126106
    127107                if ( 'cyrillic' == $subset )
     
    136116                        'family' => 'Open+Sans:400italic,700italic,400,700',
    137117                        'subset' => $subsets,
    138118                );
    139                 wp_enqueue_style( 'twentytwelve-fonts', add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" ), array(), null );
     119                $font_url = add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" );
    140120        }
    141121
     122        return $font_url;
     123}
     124
     125/**
     126 * Enqueues scripts and styles for front-end.
     127 *
     128 * @since Twenty Twelve 1.0
     129 */
     130function twentytwelve_scripts_styles() {
     131        global $wp_styles;
     132
     133        /*
     134         * Adds JavaScript to pages with the comment form to support
     135         * sites with threaded comments (when in use).
     136         */
     137        if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
     138                wp_enqueue_script( 'comment-reply' );
     139
     140        /*
     141         * Adds JavaScript for handling the navigation menu hide-and-show behavior.
     142         */
     143        wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '1.0', true );
     144
     145        $font_url = twentytwelve_get_font_url();
     146        if ( ! empty( $font_url ) )
     147                wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), null );
     148
    142149        /*
    143150         * Loads our main stylesheet.
    144151         */
     
    153160add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' );
    154161
    155162/**
     163 * Adds additional stylesheets to the TinyMCE editor if needed.
     164 *
     165 * @uses twentytwelve_get_font_url() To get the Google Font stylesheet URL.
     166 *
     167 * @since Twenty Twelve 1.2
     168 *
     169 * @param string $mce_css CSS path to load in TinyMCE.
     170 * @return string
     171 */
     172function twentytwelve_mce_css( $mce_css ) {
     173        $font_url = twentytwelve_get_font_url();
     174
     175        if ( empty( $font_url ) )
     176                return $mce_css;
     177
     178        if ( ! empty( $mce_css ) )
     179                $mce_css .= ',';
     180
     181        $mce_css .= esc_url_raw( str_replace( ',', '%2C', $font_url ) );
     182
     183        return $mce_css;
     184}
     185add_filter( 'mce_css', 'twentytwelve_mce_css' );
     186
     187/**
    156188 * Creates a nicely formatted and more specific title element text
    157189 * for output in head of document, based on current view.
    158190 *