| 1 | Index: wp-content/themes/twentytwelve/functions.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-content/themes/twentytwelve/functions.php (revision 23403) |
|---|
| 4 | +++ wp-content/themes/twentytwelve/functions.php (working copy) |
|---|
| 5 | @@ -102,19 +102,39 @@ |
|---|
| 6 | */ |
|---|
| 7 | wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '1.0', true ); |
|---|
| 8 | |
|---|
| 9 | + $font_url = twentytwelve_get_font_url(); |
|---|
| 10 | + if ( ! empty( $font_url ) ) |
|---|
| 11 | + wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), null ); |
|---|
| 12 | + |
|---|
| 13 | /* |
|---|
| 14 | - * Loads our special font CSS file. |
|---|
| 15 | - * |
|---|
| 16 | - * The use of Open Sans by default is localized. For languages that use |
|---|
| 17 | - * characters not supported by the font, the font can be disabled. |
|---|
| 18 | - * |
|---|
| 19 | - * To disable in a child theme, use wp_dequeue_style() |
|---|
| 20 | - * function mytheme_dequeue_fonts() { |
|---|
| 21 | - * wp_dequeue_style( 'twentytwelve-fonts' ); |
|---|
| 22 | - * } |
|---|
| 23 | - * add_action( 'wp_enqueue_scripts', 'mytheme_dequeue_fonts', 11 ); |
|---|
| 24 | + * Loads our main stylesheet. |
|---|
| 25 | */ |
|---|
| 26 | + wp_enqueue_style( 'twentytwelve-style', get_stylesheet_uri() ); |
|---|
| 27 | |
|---|
| 28 | + /* |
|---|
| 29 | + * Loads the Internet Explorer specific stylesheet. |
|---|
| 30 | + */ |
|---|
| 31 | + wp_enqueue_style( 'twentytwelve-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentytwelve-style' ), '20121010' ); |
|---|
| 32 | + $wp_styles->add_data( 'twentytwelve-ie', 'conditional', 'lt IE 9' ); |
|---|
| 33 | +} |
|---|
| 34 | +add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' ); |
|---|
| 35 | + |
|---|
| 36 | +/** |
|---|
| 37 | + * Returns the Google font stylesheet URL if available |
|---|
| 38 | + * |
|---|
| 39 | + * The use of Open Sans by default is localized. For languages that use |
|---|
| 40 | + * characters not supported by the font, the font can be disabled. |
|---|
| 41 | + * |
|---|
| 42 | + * To disable in a child theme or plugin, use: |
|---|
| 43 | + * add_filter( 'twentytwelve_get_font_url', '__return_null' ); |
|---|
| 44 | + * |
|---|
| 45 | + * @since Twenty Twelve 1.2 |
|---|
| 46 | + * |
|---|
| 47 | + * @return string Font stylesheet or empty string if disabled |
|---|
| 48 | + */ |
|---|
| 49 | +function twentytwelve_get_font_url() { |
|---|
| 50 | + $font_url = ''; |
|---|
| 51 | + |
|---|
| 52 | /* translators: If there are characters in your language that are not supported |
|---|
| 53 | by Open Sans, translate this to 'off'. Do not translate into your own language. */ |
|---|
| 54 | if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'twentytwelve' ) ) { |
|---|
| 55 | @@ -136,21 +156,11 @@ |
|---|
| 56 | 'family' => 'Open+Sans:400italic,700italic,400,700', |
|---|
| 57 | 'subset' => $subsets, |
|---|
| 58 | ); |
|---|
| 59 | - wp_enqueue_style( 'twentytwelve-fonts', add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" ), array(), null ); |
|---|
| 60 | + $font_url = add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" ); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | - /* |
|---|
| 64 | - * Loads our main stylesheet. |
|---|
| 65 | - */ |
|---|
| 66 | - wp_enqueue_style( 'twentytwelve-style', get_stylesheet_uri() ); |
|---|
| 67 | - |
|---|
| 68 | - /* |
|---|
| 69 | - * Loads the Internet Explorer specific stylesheet. |
|---|
| 70 | - */ |
|---|
| 71 | - wp_enqueue_style( 'twentytwelve-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentytwelve-style' ), '20121010' ); |
|---|
| 72 | - $wp_styles->add_data( 'twentytwelve-ie', 'conditional', 'lt IE 9' ); |
|---|
| 73 | + return apply_filters( 'twentytwelve_get_font_url', $font_url ); |
|---|
| 74 | } |
|---|
| 75 | -add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' ); |
|---|
| 76 | |
|---|
| 77 | /** |
|---|
| 78 | * Creates a nicely formatted and more specific title element text |
|---|
| 79 | @@ -448,3 +458,23 @@ |
|---|
| 80 | wp_enqueue_script( 'twentytwelve-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20120827', true ); |
|---|
| 81 | } |
|---|
| 82 | add_action( 'customize_preview_init', 'twentytwelve_customize_preview_js' ); |
|---|
| 83 | + |
|---|
| 84 | +/** |
|---|
| 85 | + * Adds additional stylesheets to the TinyMCE editor if needed. |
|---|
| 86 | + * |
|---|
| 87 | + * @uses twentytwelve_get_font_url() To get the Google Font stylesheet URL |
|---|
| 88 | + * |
|---|
| 89 | + * @since Twenty Twelve 1.2 |
|---|
| 90 | + */ |
|---|
| 91 | +function twentytwelve_mce_css( $mce_css ) { |
|---|
| 92 | + $font_url = twentytwelve_get_font_url(); |
|---|
| 93 | + if ( empty( $font_url ) ) |
|---|
| 94 | + return $mce_css; |
|---|
| 95 | + |
|---|
| 96 | + if ( ! empty( $mce_css ) ) |
|---|
| 97 | + $mce_css .= ','; |
|---|
| 98 | + |
|---|
| 99 | + $mce_css .= esc_url_raw( str_replace( ',', '%2C', $font_url ) ); |
|---|
| 100 | + return $mce_css; |
|---|
| 101 | +} |
|---|
| 102 | +add_filter( 'mce_css', 'twentytwelve_mce_css' ); |
|---|
| 103 | \ No newline at end of file |
|---|