X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/f9001779751f83dc8a10e478bfecb4d8dd5f964c..38ca813a0e312e2768e5b9519f0415cd0aa84781:/wp-includes/theme.php diff --git a/wp-includes/theme.php b/wp-includes/theme.php index c2960557..78d97395 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -79,7 +79,7 @@ function get_stylesheet_directory_uri() { */ function get_stylesheet_uri() { $stylesheet_dir_uri = get_stylesheet_directory_uri(); - $stylesheet_uri = $stylesheet_dir_uri . "/style.css"; + $stylesheet_uri = $stylesheet_dir_uri . '/style.css'; return apply_filters('stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri); } @@ -396,12 +396,14 @@ function get_themes() { // Check for theme name collision. This occurs if a theme is copied to // a new theme directory and the theme header is not updated. Whichever // theme is first keeps the name. Subsequent themes get a suffix applied. - // The Twenty Ten, Default and Classic themes always trump their pretenders. + // The Twenty Eleven, Twenty Ten, Default and Classic themes always trump + // their pretenders. if ( isset($wp_themes[$name]) ) { $trump_cards = array( - 'classic' => 'WordPress Classic', - 'default' => 'WordPress Default', - 'twentyten' => 'Twenty Ten', + 'classic' => 'WordPress Classic', + 'default' => 'WordPress Default', + 'twentyten' => 'Twenty Ten', + 'twentyeleven' => 'Twenty Eleven', ); if ( isset( $trump_cards[ $stylesheet ] ) && $name == $trump_cards[ $stylesheet ] ) { // If another theme has claimed to be one of our default themes, move @@ -827,7 +829,7 @@ function get_category_template() { $templates[] = "category-{$category->slug}.php"; $templates[] = "category-{$category->term_id}.php"; - $templates[] = "category.php"; + $templates[] = 'category.php'; return get_query_template( 'category', $templates ); } @@ -851,7 +853,7 @@ function get_tag_template() { $templates[] = "tag-{$tag->slug}.php"; $templates[] = "tag-{$tag->term_id}.php"; - $templates[] = "tag.php"; + $templates[] = 'tag.php'; return get_query_template( 'tag', $templates ); } @@ -881,7 +883,7 @@ function get_taxonomy_template() { $templates[] = "taxonomy-$taxonomy-{$term->slug}.php"; $templates[] = "taxonomy-$taxonomy.php"; - $templates[] = "taxonomy.php"; + $templates[] = 'taxonomy.php'; return get_query_template( 'taxonomy', $templates ); } @@ -963,7 +965,7 @@ function get_page_template() { $templates[] = "page-$pagename.php"; if ( $id ) $templates[] = "page-$id.php"; - $templates[] = "page.php"; + $templates[] = 'page.php'; return get_query_template( 'page', $templates ); } @@ -1427,15 +1429,84 @@ function header_textcolor() { */ function get_header_image() { $default = defined( 'HEADER_IMAGE' ) ? HEADER_IMAGE : ''; - $url = get_theme_mod( 'header_image', $default ); + if ( 'remove-header' == $url ) + return false; + + if ( is_random_header_image() ) + $url = get_random_header_image(); + if ( is_ssl() ) $url = str_replace( 'http://', 'https://', $url ); else $url = str_replace( 'https://', 'http://', $url ); - return $url; + return esc_url_raw( $url ); +} + +/** + * Get random header image from registered images in theme. + * + * @since 3.2.0 + * + * @return string Path to header image + */ +function get_random_header_image() { + global $_wp_default_headers; + + $header_image_mod = get_theme_mod( 'header_image', '' ); + $headers = array(); + + if ( 'random-uploaded-image' == $header_image_mod ) + $headers = get_uploaded_header_images(); + elseif ( ! empty( $_wp_default_headers ) ) { + if ( 'random-default-image' == $header_image_mod ) { + $headers = $_wp_default_headers; + } else { + $is_random = get_theme_support( 'custom-header' ); + if ( isset( $is_random[ 0 ] ) && !empty( $is_random[ 0 ][ 'random-default' ] ) ) + $headers = $_wp_default_headers; + } + } + + if ( empty( $headers ) ) + return ''; + + $random_image = array_rand( $headers ); + $header_url = sprintf( $headers[$random_image]['url'], get_template_directory_uri(), get_stylesheet_directory_uri() ); + + return $header_url; +} + +/** + * Check if random header image is in use. + * + * Always true if user expressly chooses the option in Appearance > Header. + * Also true if theme has multiple header images registered, no specific header image + * is chosen, and theme turns on random headers with add_theme_support(). + * + * @since 3.2.0 + * @uses HEADER_IMAGE + * + * @param string $type The random pool to use. any|default|uploaded + * @return boolean + */ +function is_random_header_image( $type = 'any' ) { + $default = defined( 'HEADER_IMAGE' ) ? HEADER_IMAGE : ''; + $header_image_mod = get_theme_mod( 'header_image', $default ); + + if ( 'any' == $type ) { + if ( 'random-default-image' == $header_image_mod || 'random-uploaded-image' == $header_image_mod || ( '' != get_random_header_image() && empty( $header_image_mod ) ) ) + return true; + } else { + if ( "random-$type-image" == $header_image_mod ) + return true; + elseif ( 'default' == $type && empty( $header_image_mod ) && '' != get_random_header_image() ) + return true; + } + + return false; } /** @@ -1447,6 +1518,34 @@ function header_image() { echo get_header_image(); } +/** + * Get the header images uploaded for the current theme. + * + * @since 3.2.0 + * + * @return array + */ +function get_uploaded_header_images() { + $header_images = array(); + + // @todo caching + $headers = get_posts( array( 'post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true ) ); + + if ( empty( $headers ) ) + return array(); + + foreach ( (array) $headers as $header ) { + $url = esc_url_raw( $header->guid ); + $header = basename($url); + $header_images[$header] = array(); + $header_images[$header]['url'] = $url; + $header_images[$header]['thumbnail_url'] = $url; + $header_images[$header]['uploaded'] = true; + } + + return $header_images; +} + /** * Add callbacks for image header display. * @@ -1466,7 +1565,11 @@ function add_custom_image_header( $header_callback, $admin_header_callback, $adm if ( ! empty( $header_callback ) ) add_action('wp_head', $header_callback); - add_theme_support( 'custom-header', array( 'callback' => $header_callback ) ); + $support = array( 'callback' => $header_callback ); + $theme_support = get_theme_support( 'custom-header' ); + if ( ! empty( $theme_support ) && is_array( $theme_support[ 0 ] ) ) + $support = array_merge( $theme_support[ 0 ], $support ); + add_theme_support( 'custom-header', $support ); add_theme_support( 'custom-header-uploads' ); if ( ! is_admin() )