X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/6c8f14c09105d0afa4c1574215c59b5021040e76..0461a5f2e55c8d5f1fde96ca2e83117152573c7d:/wp-content/themes/twentytwelve/functions.php diff --git a/wp-content/themes/twentytwelve/functions.php b/wp-content/themes/twentytwelve/functions.php index 760c1132..c4055ba0 100644 --- a/wp-content/themes/twentytwelve/functions.php +++ b/wp-content/themes/twentytwelve/functions.php @@ -1,6 +1,6 @@ 'e6e6e6', @@ -78,50 +78,32 @@ function twentytwelve_setup() { add_action( 'after_setup_theme', 'twentytwelve_setup' ); /** - * Adds support for a custom header image. + * Add support for a custom header image. */ require( get_template_directory() . '/inc/custom-header.php' ); /** - * Enqueues scripts and styles for front-end. + * Return the Google font stylesheet URL if available. * - * @since Twenty Twelve 1.0 + * The use of Open Sans by default is localized. For languages that use + * characters not supported by the font, the font can be disabled. + * + * @since Twenty Twelve 1.2 + * + * @return string Font stylesheet or empty string if disabled. */ -function twentytwelve_scripts_styles() { - global $wp_styles; - - /* - * Adds JavaScript to pages with the comment form to support - * sites with threaded comments (when in use). - */ - if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) - wp_enqueue_script( 'comment-reply' ); - - /* - * Adds JavaScript for handling the navigation menu hide-and-show behavior. - */ - wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '1.0', true ); - - /* - * Loads our special font CSS file. - * - * The use of Open Sans by default is localized. For languages that use - * characters not supported by the font, the font can be disabled. - * - * To disable in a child theme, use wp_dequeue_style() - * function mytheme_dequeue_fonts() { - * wp_dequeue_style( 'twentytwelve-fonts' ); - * } - * add_action( 'wp_enqueue_scripts', 'mytheme_dequeue_fonts', 11 ); - */ +function twentytwelve_get_font_url() { + $font_url = ''; /* translators: If there are characters in your language that are not supported - by Open Sans, translate this to 'off'. Do not translate into your own language. */ + * by Open Sans, translate this to 'off'. Do not translate into your own language. + */ if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'twentytwelve' ) ) { $subsets = 'latin,latin-ext'; - /* translators: To add an additional Open Sans character subset specific to your language, translate - this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language. */ + /* translators: To add an additional Open Sans character subset specific to your language, + * translate this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language. + */ $subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)', 'twentytwelve' ); if ( 'cyrillic' == $subset ) @@ -136,23 +118,73 @@ function twentytwelve_scripts_styles() { 'family' => 'Open+Sans:400italic,700italic,400,700', 'subset' => $subsets, ); - wp_enqueue_style( 'twentytwelve-fonts', add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" ), array(), null ); + $font_url = add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" ); } + return $font_url; +} + +/** + * Enqueue scripts and styles for front-end. + * + * @since Twenty Twelve 1.0 + */ +function twentytwelve_scripts_styles() { + global $wp_styles; + /* - * Loads our main stylesheet. + * Adds JavaScript to pages with the comment form to support + * sites with threaded comments (when in use). */ + if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) + wp_enqueue_script( 'comment-reply' ); + + // Adds JavaScript for handling the navigation menu hide-and-show behavior. + wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20140318', true ); + + $font_url = twentytwelve_get_font_url(); + if ( ! empty( $font_url ) ) + wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), null ); + + // Loads our main stylesheet. wp_enqueue_style( 'twentytwelve-style', get_stylesheet_uri() ); - /* - * Loads the Internet Explorer specific stylesheet. - */ + // Loads the Internet Explorer specific stylesheet. wp_enqueue_style( 'twentytwelve-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentytwelve-style' ), '20121010' ); $wp_styles->add_data( 'twentytwelve-ie', 'conditional', 'lt IE 9' ); } add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' ); /** + * Filter TinyMCE CSS path to include Google Fonts. + * + * Adds additional stylesheets to the TinyMCE editor if needed. + * + * @uses twentytwelve_get_font_url() To get the Google Font stylesheet URL. + * + * @since Twenty Twelve 1.2 + * + * @param string $mce_css CSS path to load in TinyMCE. + * @return string Filtered CSS path. + */ +function twentytwelve_mce_css( $mce_css ) { + $font_url = twentytwelve_get_font_url(); + + if ( empty( $font_url ) ) + return $mce_css; + + if ( ! empty( $mce_css ) ) + $mce_css .= ','; + + $mce_css .= esc_url_raw( str_replace( ',', '%2C', $font_url ) ); + + return $mce_css; +} +add_filter( 'mce_css', 'twentytwelve_mce_css' ); + +/** + * Filter the page title. + * * Creates a nicely formatted and more specific title element text * for output in head of document, based on current view. * @@ -169,7 +201,7 @@ function twentytwelve_wp_title( $title, $sep ) { return $title; // Add the site name. - $title .= get_bloginfo( 'name' ); + $title .= get_bloginfo( 'name', 'display' ); // Add the site description for the home/front page. $site_description = get_bloginfo( 'description', 'display' ); @@ -185,6 +217,8 @@ function twentytwelve_wp_title( $title, $sep ) { add_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 ); /** + * Filter the page menu arguments. + * * Makes our wp_nav_menu() fallback -- wp_page_menu() -- show a home link. * * @since Twenty Twelve 1.0 @@ -197,6 +231,8 @@ function twentytwelve_page_menu_args( $args ) { add_filter( 'wp_page_menu_args', 'twentytwelve_page_menu_args' ); /** + * Register sidebars. + * * Registers our main widget area and the front page widget areas. * * @since Twenty Twelve 1.0 @@ -248,8 +284,8 @@ function twentytwelve_content_nav( $html_id ) { if ( $wp_query->max_num_pages > 1 ) : ?> %1$s %2$s', + printf( '%1$s %2$s', get_comment_author_link(), // If current post author is also comment author, make it known visually. - ( $comment->user_id === $post->post_author ) ? ' ' . __( 'Post author', 'twentytwelve' ) . '' : '' + ( $comment->user_id === $post->post_author ) ? '' . __( 'Post author', 'twentytwelve' ) . '' : '' ); printf( '', esc_url( get_comment_link( $comment->comment_ID ) ), @@ -321,6 +357,8 @@ endif; if ( ! function_exists( 'twentytwelve_entry_meta' ) ) : /** + * Set up post entry meta. + * * Prints HTML with meta information for current post: categories, tags, permalink, author, and date. * * Create your own twentytwelve_entry_meta() to override in a child theme. @@ -367,6 +405,8 @@ function twentytwelve_entry_meta() { endif; /** + * Extend the default WordPress body classes. + * * Extends the default WordPress body class to denote: * 1. Using a full-width layout, when no active widgets in the sidebar * or full-width template. @@ -378,11 +418,12 @@ endif; * * @since Twenty Twelve 1.0 * - * @param array Existing class values. + * @param array $classes Existing class values. * @return array Filtered class values. */ function twentytwelve_body_class( $classes ) { $background_color = get_background_color(); + $background_image = get_background_image(); if ( ! is_active_sidebar( 'sidebar-1' ) || is_page_template( 'page-templates/full-width.php' ) ) $classes[] = 'full-width'; @@ -395,10 +436,12 @@ function twentytwelve_body_class( $classes ) { $classes[] = 'two-sidebars'; } - if ( empty( $background_color ) ) - $classes[] = 'custom-background-empty'; - elseif ( in_array( $background_color, array( 'fff', 'ffffff' ) ) ) - $classes[] = 'custom-background-white'; + if ( empty( $background_image ) ) { + if ( empty( $background_color ) ) + $classes[] = 'custom-background-empty'; + elseif ( in_array( $background_color, array( 'fff', 'ffffff' ) ) ) + $classes[] = 'custom-background-white'; + } // Enable custom font class only if the font CSS is queued to load. if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) ) @@ -412,6 +455,8 @@ function twentytwelve_body_class( $classes ) { add_filter( 'body_class', 'twentytwelve_body_class' ); /** + * Adjust content width in certain contexts. + * * Adjusts content_width value for full-width and single image attachment * templates, and when there are no active widgets in the sidebar. * @@ -426,25 +471,29 @@ function twentytwelve_content_width() { add_action( 'template_redirect', 'twentytwelve_content_width' ); /** - * Add postMessage support for site title and description for the Theme Customizer. + * Register postMessage support. + * + * Add postMessage support for site title and description for the Customizer. * * @since Twenty Twelve 1.0 * - * @param WP_Customize_Manager $wp_customize Theme Customizer object. - * @return void + * @param WP_Customize_Manager $wp_customize Customizer object. */ function twentytwelve_customize_register( $wp_customize ) { - $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; - $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; + $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; + $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; + $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; } add_action( 'customize_register', 'twentytwelve_customize_register' ); /** - * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. + * Enqueue Javascript postMessage handlers for the Customizer. + * + * Binds JS handlers to make the Customizer preview reload changes asynchronously. * * @since Twenty Twelve 1.0 */ function twentytwelve_customize_preview_js() { - wp_enqueue_script( 'twentytwelve-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20120827', true ); + wp_enqueue_script( 'twentytwelve-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20130301', true ); } add_action( 'customize_preview_init', 'twentytwelve_customize_preview_js' );