Make WordPress Core

Changeset 23713


Ignore:
Timestamp:
03/15/2013 05:09:12 PM (12 years ago)
Author:
lancewillett
Message:

Twenty Twelve: load our special Google Font in the visual editor to improve user experience. Props to the Konstanthemes: kovshenin and obenland.

Closes #22499. See also r23672.

File:
1 edited

Legend:

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

    r23572 r23713  
    8484
    8585/**
    86  * Enqueues scripts and styles for front-end.
    87  *
    88  * @since Twenty Twelve 1.0
    89  */
    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      */
     86 * Returns the Google font stylesheet URL if available.
     87 *
     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.
     94 */
     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
     
    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    }
     121
     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 );
    141148
    142149    /*
     
    152159}
    153160add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' );
     161
     162/**
     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' );
    154186
    155187/**
Note: See TracChangeset for help on using the changeset viewer.