Make WordPress Core

Ticket #16434: 16434-06.patch

File 16434-06.patch, 8.9 KB (added by brandondove, 10 years ago)

Refreshed patch based on 4.3-alpha-32500

  • wp-admin/css/common.css

     
    18801880        font-weight: 600;
    18811881}
    18821882
     1883.options-general-php img.favicon {
     1884        vertical-align:middle;
     1885
     1886        -moz-box-shadow:    1px 1px 3px 0px #aaa;
     1887        -webkit-box-shadow: 1px 1px 3px 0px #aaa;
     1888        box-shadow:         1px 1px 3px 0px #aaa;
     1889}
     1890
     1891#remove-favicon-button {
     1892        margin-left:5px;
     1893}
     1894
     1895/* Favicon upload error messages */
     1896#favicon-invalid-filetype-error {
     1897        display:none;
     1898        color:red;
     1899        font-style: italic;
     1900}
     1901
    18831902/*------------------------------------------------------------------------------
    18841903  21.0 - Admin Footer
    18851904------------------------------------------------------------------------------*/
  • wp-admin/options-general.php

     
    105105        '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
    106106);
    107107
     108wp_enqueue_script('wp-favicon');
     109
    108110include( ABSPATH . 'wp-admin/admin-header.php' );
    109111?>
    110112
     
    111113<div class="wrap">
    112114<h2><?php echo esc_html( $title ); ?></h2>
    113115
     116<form action="<?php echo admin_url('favicon-upload.php')?>" method="post" enctype="multipart/form-data" id="faviconupload">
     117    <?php settings_fields('favicon_upload') ?>
     118        <table class="form-table">
     119                <tr valign="top">
     120                        <th scope="row"><label for="sitefavicon"><?php _e('Favicon') ?></label></th>
     121                        <td>
     122                                <?php
     123                                        // display the icon and the remove link if appropriate
     124                                        if ( has_custom_favicon() ){
     125                                                if ( $thumbnail = get_favicon_img() ) echo $thumbnail;
     126                                                echo "\t" . '<input type="submit" name="REMOVE_FAVICON" value="Remove Favicon" id="remove-favicon-button" />';
     127                                                echo ' <span class="description no-js">' . __( 'The image at right is used as your site\'s favicon. To change it, first remove this one.' ) . '</span>';
     128                                        } else {
     129                                ?>
     130                                        <input class="button" name="avatarfile" type="file" id="faviconfile" size="35" />
     131                                        <p class="submit no-js hide-if-js"><input type="submit" name="Submit" value="Upload Image &raquo;" id="faviconsubmit" /></p>
     132                                        <span class="description no-js"><?php _e('Click to upload your own custom icon ("favicon") for your blog. You\'ll be able to crop and scale it once it\'s uploaded.') ?></span>
     133                                        <span id="favicon-invalid-filetype-error"><?php _e( 'Please only upload files in the following formats: .ico, .png, .bmp, .jpg' ) ?></span>
     134                                <?php } ?>
     135                        </td>
     136                </tr>
     137        </table>
     138</form>
     139
    114140<form method="post" action="options.php" novalidate="novalidate">
    115141<?php settings_fields('general'); ?>
    116142
  • wp-includes/functions.php

     
    21812181        'png' => 'image/png',
    21822182        'bmp' => 'image/bmp',
    21832183        'tiff|tif' => 'image/tiff',
    2184         'ico' => 'image/x-icon',
     2184        'ico' => 'image/vnd.microsoft.icon',
    21852185        // Video formats.
    21862186        'asf|asx' => 'video/x-ms-asf',
    21872187        'wmv' => 'video/x-ms-wmv',
  • wp-includes/general-template.php

     
    22212221}
    22222222
    22232223/**
     2224 * Convenience function that echoes the HTML for the site's favicon icon.
     2225 * By default, automatically included in the header via the 'wp_head' action, which can be removed by themes if a custom favicon is desired.
     2226 *
     2227 * @uses generate_site_favicon_html() to do the actual heavy lifting
     2228 */
     2229function site_favicon(){
     2230        echo generate_site_favicon_html();
     2231}
     2232add_action( 'wp_head', 'site_favicon' );
     2233add_action( 'admin_head', 'site_favicon' );
     2234
     2235/**
     2236 * Return the HTML for the site's favicon icon, if such has been defined.
     2237 *
     2238 * @uses get_site_favicon_uri();
     2239 *
     2240 * Includes the conditional tag wrapper for an IE (.ico) version.
     2241 */
     2242function generate_site_favicon_html() {
     2243        $favicon_uri = get_site_favicon_uri();
     2244        $ie_favicon_uri = get_site_favicon_uri( 'ico' );
     2245
     2246        $content = "";
     2247        if (! empty( $favicon_uri ) ){
     2248                $content .= "\n\n<!--favicon (via 'wp_head' action) -->\n";
     2249
     2250                if (! empty( $ie_favicon_uri )) $content .= <<<IE_FAVICON_1
     2251<!--[if IE]>
     2252        <link rel="shortcut icon" href="{$ie_favicon_uri}" />
     2253<![endif]-->
     2254<!--[if !IE]>-->\n
     2255IE_FAVICON_1;
     2256
     2257                $content .= "\t<link href=\"{$favicon_uri}\" rel=\"icon\" type=\"image/png\" />\n";
     2258
     2259                if (! empty( $ie_favicon_uri )) $content .= "<!--<![endif]-->";
     2260                $content .= "\n<!-- /favicon -->\n\n";
     2261    }
     2262        return $content;
     2263}
     2264
     2265/**
     2266 * Get the attachment post object associated with the current site favicon, based on the 'sitefavicon' option
     2267 *
     2268 * @param string $format Default 'png'. Format of the file we're looking for
     2269 * @return object If found, returns the post object; if not, a WP_Error object
     2270 */
     2271function get_site_favicon_attachment( $format = 'png' ){
     2272        $favicon_basename = get_option ( 'sitefavicon' );
     2273
     2274        if ( ! empty( $favicon_basename ) ) {
     2275                $favicon_fullname = $favicon_basename . '-' . $format;
     2276
     2277                $posts = get_posts( array( 'name' => $favicon_fullname, 'post_type' => 'attachment' ) );
     2278                if ( count( $posts ) > 0 ){
     2279                        return $posts[0];
     2280                } else {
     2281                        return new WP_Error( 'attachment_missing', __( "No attachment for '$favicon_fullname' was found." ) );
     2282                }
     2283        } else {
     2284                return new WP_Error( 'not_defined', __( "No favicon file provided." ) );
     2285        }
     2286}
     2287
     2288/**
     2289 * Returns the URI for the site's favicon based on the option set in  Admin > Settings > General.
     2290 *
     2291 * @param string $format png|ico default 'png'. Use 'ico' for serving up an IE-compatible ICO file
     2292 * @return string fully qualified URI
     2293 */
     2294function get_site_favicon_uri( $format = 'png' ){
     2295        /** @TODO provide error checking for validity of $format and $size */
     2296        $favicon_attachment = get_site_favicon_attachment( $format );
     2297
     2298        /** @TODO provide the ability to define a 'default' favicon that would be distributed with fresh WP installations */
     2299        if ( ! is_wp_error( $favicon_attachment ) ) {
     2300                return wp_get_attachment_url( $favicon_attachment->ID );
     2301        }
     2302
     2303        // We get here because of an error condition
     2304        /** @TODO default to the theme's favicon **/
     2305        // ATM do nothing (so URI is blank, rather than a WP_Error)
     2306}
     2307
     2308/**
     2309 * Gets the path to the favicon file, or returns a WP_Error
     2310 * @param string $format Default 'png'
     2311 * @return mixed File string or WP_Error object
     2312 */
     2313function get_site_favicon_file( $format = 'png' ){
     2314        $favicon_attachment = get_site_favicon_attachment( $format );
     2315
     2316        /** @TODO provide the ability to define a 'default' favicon that would be distributed with fresh WP installations */
     2317        if ( ! is_wp_error( $favicon_attachment ) ) {
     2318                $file = get_attached_file( $favicon_attachment->ID );
     2319                if ( file_exists( $file ) ) return $file;
     2320                else return new WP_Error( 'file_missing', __( 'Favicon image file missing.' ) );
     2321        } else {
     2322                return $favicon_attachment; // returns the WP_Error object
     2323        }
     2324}
     2325
     2326/**
     2327 * Returns true or false depending on whether a custom favicon has been defined in Admin
     2328 * @return boolean
     2329 */
     2330function has_custom_favicon(){
     2331        return ( get_option ( 'sitefavicon' ) && ! is_wp_error( get_site_favicon_file() ) );
     2332}
     2333
     2334/**
     2335 * Returns an HTML <img> tag populated with the site favicon, in the format specified (usually PNG)
     2336 * @param string $format Default 'png'. Valid values are 'png', 'bmp' (note 'ico' is NOT valid)
     2337 * @return mixed Returns HTML <img> tag or WP_Error if invalid format given. Returns nothing if the file is missing.
     2338 */
     2339function get_favicon_img( $format = 'png' ){
     2340        if (in_array( strtolower( $format ), array( 'png', 'bmp' ) ) ){
     2341                // Does the file actually exist?
     2342                $file = get_site_favicon_file( $format );
     2343                if (! is_wp_error( $file ) && file_exists( $file ) ){
     2344                        $src = get_site_favicon_uri( $format );
     2345                        if (!is_wp_error( $src ) ){
     2346                                return '<img src="' . $src . '" class="favicon" alt="' . _x( 'Site favicon thumbnail', 'Thumbnail image accessibility text' ) .'" />';
     2347                        }
     2348                }
     2349        } else {
     2350                return new WP_Error( 'invalid_file_format', __( 'Invalid file format. Valid formats are "png", "bmp".' ) );
     2351        }
     2352}
     2353
     2354/**
    22242355 * Display the links to the general feeds.
    22252356 *
    22262357 * @since 2.8.0
  • wp-includes/script-loader.php

     
    107107
    108108        $scripts->add( 'wp-fullscreen', "/wp-admin/js/wp-fullscreen$suffix.js", array('jquery'), false, 1 );
    109109
     110        $scripts->add( 'wp-favicon', "/wp-admin/js/wp-favicon$suffix.js", array('jquery'), false, 1 );
     111
    110112        $scripts->add( 'wp-ajax-response', "/wp-includes/js/wp-ajax-response$suffix.js", array('jquery'), false, 1 );
    111113        did_action( 'init' ) && $scripts->localize( 'wp-ajax-response', 'wpAjax', array(
    112114                'noPerm' => __('You do not have permission to do that.'),