Make WordPress Core

Ticket #22499: 22499.2.diff

File 22499.2.diff, 3.8 KB (added by kovshenin, 12 years ago)
  • wp-content/themes/twentytwelve/functions.php

     
    102102         */
    103103        wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '1.0', true );
    104104
     105        $font_url = twentytwelve_get_font_url();
     106        if ( ! empty( $font_url ) )
     107                wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), null );
     108
    105109        /*
    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 );
     110         * Loads our main stylesheet.
    116111         */
     112        wp_enqueue_style( 'twentytwelve-style', get_stylesheet_uri() );
    117113
     114        /*
     115         * Loads the Internet Explorer specific stylesheet.
     116         */
     117        wp_enqueue_style( 'twentytwelve-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentytwelve-style' ), '20121010' );
     118        $wp_styles->add_data( 'twentytwelve-ie', 'conditional', 'lt IE 9' );
     119}
     120add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' );
     121
     122/**
     123 * Returns the Google font stylesheet URL if available
     124 *
     125 * The use of Open Sans by default is localized. For languages that use
     126 * characters not supported by the font, the font can be disabled.
     127 *
     128 * To disable in a child theme or plugin, use:
     129 * add_filter( 'twentytwelve_get_font_url', '__return_null' );
     130 *
     131 * @since Twenty Twelve 1.2
     132 *
     133 * @return string Font stylesheet or empty string if disabled
     134 */
     135function twentytwelve_get_font_url() {
     136        $font_url = '';
     137
    118138        /* translators: If there are characters in your language that are not supported
    119139           by Open Sans, translate this to 'off'. Do not translate into your own language. */
    120140        if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'twentytwelve' ) ) {
     
    136156                        'family' => 'Open+Sans:400italic,700italic,400,700',
    137157                        'subset' => $subsets,
    138158                );
    139                 wp_enqueue_style( 'twentytwelve-fonts', add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" ), array(), null );
     159                $font_url = add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" );
    140160        }
    141161
    142         /*
    143          * Loads our main stylesheet.
    144          */
    145         wp_enqueue_style( 'twentytwelve-style', get_stylesheet_uri() );
    146 
    147         /*
    148          * Loads the Internet Explorer specific stylesheet.
    149          */
    150         wp_enqueue_style( 'twentytwelve-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentytwelve-style' ), '20121010' );
    151         $wp_styles->add_data( 'twentytwelve-ie', 'conditional', 'lt IE 9' );
     162        return $font_url;
    152163}
    153 add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' );
    154164
    155165/**
    156166 * Creates a nicely formatted and more specific title element text
     
    452462        wp_enqueue_script( 'twentytwelve-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20130301', true );
    453463}
    454464add_action( 'customize_preview_init', 'twentytwelve_customize_preview_js' );
     465
     466/**
     467 * Adds additional stylesheets to the TinyMCE editor if needed.
     468 *
     469 * @uses twentytwelve_get_font_url() To get the Google Font stylesheet URL
     470 *
     471 * @since Twenty Twelve 1.2
     472 */
     473function twentytwelve_mce_css( $mce_css ) {
     474        $font_url = twentytwelve_get_font_url();
     475        if ( empty( $font_url ) )
     476                return $mce_css;
     477
     478        if ( ! empty( $mce_css ) )
     479                $mce_css .= ',';
     480
     481        $mce_css .= esc_url_raw( str_replace( ',', '%2C', $font_url ) );
     482        return $mce_css;
     483}
     484add_filter( 'mce_css', 'twentytwelve_mce_css' );
     485 No newline at end of file