WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/29/2015 12:57:35 PM (4 years ago)
Author:
obenland
Message:

Introducing Site Icon, favicon management for WordPress.

This v1 marries Jetpack's Site Icon module with the Media Modal, reusing code
from the Custom Header admin. For now, the core-provided icons will be limited
to a favicon, an iOS app icon, and a Windows tile icon, leaving .ico support
and additional icons to plugins to add.

Props obenland, tyxla, flixos90, jancbeck, markjaquith, scruffian.
See #16434.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/general-template.php

    r32935 r32994  
    720720
    721721    return $output;
     722}
     723
     724/**
     725 * Returns the Site Icon URL.
     726 *
     727 * @param  null|int $blog_id Id of the blog to get the site icon for.
     728 * @param  int      $size    Size of the site icon.
     729 * @param  string   $url     Fallback url if no site icon is found.
     730 * @return string            Site Icon URL.
     731 */
     732function get_site_icon_url( $blog_id = null, $size = 512, $url = '' ) {
     733    if ( function_exists( 'get_blog_option' ) ) {
     734        if ( ! is_int( $blog_id ) ) {
     735            $blog_id = get_current_blog_id();
     736        }
     737        $site_icon_id = get_blog_option( $blog_id, 'site_icon' );
     738    } else {
     739        $site_icon_id = get_option( 'site_icon' );
     740    }
     741
     742    if ( $site_icon_id  ) {
     743        if ( $size >= 512 ) {
     744            $size_data = 'full';
     745        } else {
     746            $size_data = array( $size, $size );
     747        }
     748        $url_data = wp_get_attachment_image_src( $site_icon_id, $size_data );
     749        $url = $url_data[0];
     750    }
     751
     752    return $url;
     753}
     754
     755/**
     756 * Displays the Site Icon URL.
     757 *
     758 * @param null|int $blog_id Id of the blog to get the site icon for.
     759 * @param int      $size    Size of the site icon.
     760 * @param string   $url     Fallback url if no site icon is found.
     761 */
     762function site_icon_url( $blog_id = null, $size = 512, $url = '' ) {
     763    echo esc_url( get_site_icon_url( $blog_id, $size, $url ) );
     764}
     765
     766/**
     767 * Whether the site has a Site Icon.
     768 *
     769 * @param int|null $blog_id Optional. Blog ID. Default: Current blog.
     770 * @return bool
     771 */
     772function has_site_icon( $blog_id = null ) {
     773    return !! get_site_icon_url( $blog_id, 512 );
    722774}
    723775
     
    23872439
    23882440/**
     2441 * Display site icon meta tags.
     2442 *
     2443 * @since 4.3.0
     2444 *
     2445 * @link http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#rel-icon HTML5 specification link icon.
     2446 */
     2447function wp_site_icon() {
     2448    if ( ! has_site_icon() ) {
     2449        return;
     2450    }
     2451
     2452    $meta_tags = array(
     2453        sprintf( '<link rel="icon" href="%s" sizes="32x32" />', esc_url( get_site_icon_url( null, 32 ) ) ),
     2454        sprintf( '<link rel="apple-touch-icon-precomposed" href="%s">', esc_url( get_site_icon_url( null, 180 ) ) ),
     2455        sprintf( '<meta name="msapplication-TileImage" content="%s">', esc_url( get_site_icon_url( null, 270 ) ) ),
     2456    );
     2457
     2458    /**
     2459     * Filters the site icon meta tags, so Plugins can add their own.
     2460     *
     2461     * @since 4.3.0
     2462     *
     2463     * @param array $meta_tags Site Icon meta elements.
     2464     */
     2465    $meta_tags = apply_filters( 'site_icon_meta_tags', $meta_tags );
     2466    $meta_tags = array_filter( $meta_tags );
     2467
     2468    foreach ( $meta_tags as $meta_tag ) {
     2469        echo "$meta_tag\n";
     2470    }
     2471}
     2472
     2473/**
    23892474 * Whether the user should have a WYSIWIG editor.
    23902475 *
Note: See TracChangeset for help on using the changeset viewer.