WordPress.org

Make WordPress Core

Ticket #23467: 23467.diff

File 23467.diff, 3.8 KB (added by kovshenin, 5 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 apply_filters( 'twentytwelve_get_font_url', $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
     
    448458        wp_enqueue_script( 'twentytwelve-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20120827', true );
    449459}
    450460add_action( 'customize_preview_init', 'twentytwelve_customize_preview_js' );
     461
     462/**
     463 * Adds additional stylesheets to the TinyMCE editor if needed.
     464 *
     465 * @uses twentytwelve_get_font_url() To get the Google Font stylesheet URL
     466 *
     467 * @since Twenty Twelve 1.2
     468 */
     469function twentytwelve_mce_css( $mce_css ) {
     470        $font_url = twentytwelve_get_font_url();
     471        if ( empty( $font_url ) )
     472                return $mce_css;
     473
     474        if ( ! empty( $mce_css ) )
     475                $mce_css .= ',';
     476
     477        $mce_css .= esc_url_raw( str_replace( ',', '%2C', $font_url ) );
     478        return $mce_css;
     479}
     480add_filter( 'mce_css', 'twentytwelve_mce_css' );
     481 No newline at end of file