Ticket #33755: 33755.14.diff
File 33755.14.diff, 19.9 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/admin.php
72 72 /** WordPress Site Icon API */ 73 73 require_once(ABSPATH . 'wp-admin/includes/class-wp-site-icon.php'); 74 74 75 /** WordPress Site Logo API */ 76 require_once(ABSPATH . 'wp-admin/includes/class-wp-site-logo.php'); 77 75 78 /** WordPress Update Administration API */ 76 79 require_once(ABSPATH . 'wp-admin/includes/update.php'); 77 80 -
src/wp-admin/includes/class-wp-site-logo.php
1 <?php 2 /** 3 * Administration API: WP_Site_Logo class 4 * 5 * @package WordPress 6 * @subpackage Administration 7 * @since 4.5.0 8 */ 9 10 /** 11 * Core class used to implement site logo functionality. 12 * 13 * @since 4.5.0 14 */ 15 class WP_Site_Logo { 16 17 /** 18 * Get current logo settings stored in theme mod. 19 * 20 * @since 4.5.0 21 * @access public 22 */ 23 public function __construct() { 24 add_action( 'wp_head', array( $this, 'head_text_styles' ) ); 25 add_action( 'delete_attachment', array( $this, 'delete_attachment_data' ) ); 26 add_filter( 'image_size_names_choose', array( $this, 'media_manager_image_sizes' ) ); 27 } 28 29 /** 30 * Enqueue scripts for the Customizer live preview. 31 * 32 * @since 4.5.0 33 * @access public 34 */ 35 public function preview_enqueue() { 36 37 // Don't bother passing in header text classes if the theme supports custom headers. 38 if ( ! current_theme_supports( 'custom-header' ) ) { 39 wp_enqueue_script( 'site-logo-header-text', plugins_url( '../js/site-logo-header-text.js', __FILE__ ), array( 'media-views' ), '', true ); 40 wp_localize_script( 'site-logo-header-text', 'site_logo_header_classes', $this->header_text_classes() ); 41 } 42 } 43 44 /** 45 * Get header text classes. If not defined in add_theme_support(), defaults from Underscores will be used. 46 * 47 * @since 4.5.0 48 * @access public 49 * 50 * @return string String of classes to hide 51 */ 52 public function header_text_classes() { 53 $args = get_theme_support( 'site-logo' ); 54 55 if ( isset( $args[0]['header-text'] ) ) { 56 // Use any classes defined in add_theme_support(). 57 $classes = $args[0]['header-text']; 58 } else { 59 // Otherwise, use these defaults, which will work with any Underscores-based theme. 60 $classes = array( 61 'site-title', 62 'site-description', 63 ); 64 } 65 66 // If we've got an array, reduce them to a string for output. 67 if ( is_array( $classes ) ) { 68 $classes = array_map( 'sanitize_html_class', $classes ); 69 $classes = (string) '.' . implode( ', .', $classes ); 70 } else { 71 $classes = (string) '.' . $classes; 72 } 73 74 return $classes; 75 } 76 77 /** 78 * Hide header text on front-end if necessary. 79 * 80 * @since 4.5.0 81 * @access public 82 */ 83 public function head_text_styles() { 84 // Bail if our theme supports custom headers. 85 if ( current_theme_supports( 'custom-header' ) || get_theme_mod( 'site_logo_header_text', true ) ) { 86 return; 87 } 88 89 // Is Display Header Text unchecked? If so, we need to hide our header text. 90 ?> 91 <!-- Site Logo: hide header text --> 92 <style type="text/css"> 93 <?php echo sanitize_html_class( $this->header_text_classes() ); ?> { 94 position: absolute; 95 clip: rect(1px, 1px, 1px, 1px); 96 } 97 </style> 98 <?php 99 } 100 101 /** 102 * Make custom image sizes available to the media manager. 103 * 104 * @since 4.5.0 105 * @access public 106 * 107 * @param array $sizes Image sizes. 108 * @return array All default and registered custom image sizes. 109 */ 110 public function media_manager_image_sizes( $sizes ) { 111 // Get an array of all registered image sizes. 112 $intermediate = get_intermediate_image_sizes(); 113 114 // Have we got anything fun to work with? 115 if ( is_array( $intermediate ) && ! empty( $intermediate ) ) { 116 foreach ( $intermediate as $key => $size ) { 117 // If the size isn't already in the $sizes array, add it. 118 if ( ! array_key_exists( $size, $sizes ) ) { 119 $sizes[ $size ] = $size; 120 } 121 } 122 } 123 124 return $sizes; 125 } 126 127 /** 128 * Reset the site logo if the current logo is deleted in the media manager. 129 * 130 * @since 4.5.0 131 * @access public 132 * 133 * @param int $post_id 134 */ 135 public function delete_attachment_data( $post_id ) { 136 $site_logo_id = get_theme_mod( 'site_logo' ); 137 138 if ( $site_logo_id && $site_logo_id == $post_id ) { 139 remove_theme_mod( 'site_logo' ); 140 } 141 } 142 143 /** 144 * Sanitize our header text Customizer setting. 145 * 146 * @since 4.5.0 147 * @access public 148 * 149 * @param int|string $input Input value. 150 * @return int|string 1 if checked, empty string if not checked. 151 */ 152 public function sanitize_checkbox( $input ) { 153 return ( 1 == $input ) ? 1 : ''; 154 } 155 } 156 157 /** 158 * WP_Site_Logo instance. 159 * 160 * @global WP_Site_Logo $wp_site_logo 161 */ 162 $GLOBALS['wp_site_logo'] = new WP_Site_Logo; -
src/wp-admin/includes/template.php
1750 1750 $media_states[] = __( 'Site Icon' ); 1751 1751 } 1752 1752 1753 if ( $post->ID == get_theme_mod( 'site_logo' ) ) { 1754 $media_states[] = __( 'Logo' ); 1755 } 1756 1753 1757 /** 1754 1758 * Filter the default media display states for items in the Media list table. 1755 1759 * … … 1756 1760 * @since 3.2.0 1757 1761 * 1758 1762 * @param array $media_states An array of media states. Default 'Header Image', 1759 * 'Background Image', 'Site Icon' .1763 * 'Background Image', 'Site Icon', 'Logo'. 1760 1764 */ 1761 1765 $media_states = apply_filters( 'display_media_states', $media_states ); 1762 1766 -
src/wp-admin/js/customize-controls.js
1784 1784 }); 1785 1785 1786 1786 // Re-render whenever the control's setting changes. 1787 control.setting.bind( function () { control.renderContent(); } ); 1787 control.setting.bind( function ( value ) { 1788 // Send attachment information to the preview for possible use in `postMessage` transport. 1789 wp.media.attachment( value ).fetch().done( function() { 1790 wp.customize.previewer.send( control.id + '-attachment-data', this.attributes ); 1791 } ); 1792 alert( control.id + '-attachment-data' ); 1793 1794 control.renderContent(); 1795 } ); 1788 1796 }, 1789 1797 1790 1798 pausePlayer: function () { -
src/wp-includes/class-wp-customize-manager.php
828 828 'activeSections' => array(), 829 829 'activeControls' => array(), 830 830 'nonce' => $this->get_nonces(), 831 'l10n' => array( 832 'shiftClickToEdit' => __( 'Shift-click to edit this element.' ), 833 ), 831 834 '_dirty' => array_keys( $this->unsanitized_post_values() ), 832 835 ); 833 836 … … 1932 1935 'section' => 'title_tagline', 1933 1936 ) ); 1934 1937 1938 // Add a setting to hide header text if the theme isn't supporting the feature itself. 1939 // @todo 1940 if ( ! current_theme_supports( 'custom-header' ) ) { 1941 $this->add_setting( 'header_text', array( 1942 'default' => 1, 1943 'sanitize_callback' => 'absint', 1944 'transport' => 'postMessage', 1945 ) ); 1946 1947 $this->add_control( 'header_text', array( 1948 'label' => __( 'Display Site Title and Tagline' ), 1949 'section' => 'title_tagline', 1950 'settings' => 'header_text', 1951 'type' => 'checkbox', 1952 ) ); 1953 } 1954 1935 1955 $this->add_setting( 'site_icon', array( 1936 1956 'type' => 'option', 1937 1957 'capability' => 'manage_options', … … (this hunk was shorter than expected) 1951 1971 'width' => 512, 1952 1972 ) ) ); 1953 1973 1974 $this->add_setting( 'site_logo', array( 1975 'theme_supports' => array( 'site-logo' ), 1976 'transport' => 'postMessage', 1977 ) ); 1978 1979 $this->add_control( new WP_Customize_Media_Control( $this, 'site_logo', array( 1980 'label' => __( 'Logo' ), 1981 'section' => 'title_tagline', 1982 'mime_type' => 'image', 1983 'priority' => 80, 1984 'button_labels' => array( 1985 'select' => __( 'Select logo' ), 1986 'change' => __( 'Change logo' ), 1987 'placeholder' => __( 'No logo selected' ), 1988 'frame_title' => __( 'Select logo' ), 1989 'frame_button' => __( 'Choose logo' ), 1990 ), 1991 ) ) ); 1992 1993 if ( isset( $this->selective_refresh ) ) { 1994 $this->selective_refresh->add_partial( 'site_logo', array( 1995 'settings' => array( 'site_logo' ), 1996 'selector' => '.site-logo-link', 1997 'render_callback' => array( $this, '_render_site_logo_partial' ), 1998 'container_inclusive' => true, 1999 ) ); 2000 } 2001 1954 2002 /* Colors */ 1955 2003 1956 2004 $this->add_section( 'colors', array( … … 2180 2230 2181 2231 return $color; 2182 2232 } 2233 2234 /** 2235 * Callback for rendering the site logo, used in the site_logo partial. 2236 * 2237 * This method exists because the partial object and context data are passed 2238 * into a partial's render_callback so we cannot use get_the_site_logo() as 2239 * the render_callback directly since it expects a blog ID as the first 2240 * argument. When WP no longer supports PHP 5.3, this method can be removed 2241 * in favor of an anonymous function. 2242 * 2243 * @see WP_Customize_Manager::register_controls() 2244 * 2245 * @since 4.5.0 2246 * @access private 2247 * 2248 * @return string Site logo. 2249 */ 2250 public function _render_site_logo_partial() { 2251 return get_the_site_logo(); 2252 } 2183 2253 } 2184 2254 2185 2255 /** -
src/wp-includes/customize/class-wp-customize-image-control.php
31 31 public function __construct( $manager, $id, $args = array() ) { 32 32 parent::__construct( $manager, $id, $args ); 33 33 34 $this->button_labels = array(34 $this->button_labels = wp_parse_args( $this->button_labels, array( 35 35 'select' => __( 'Select Image' ), 36 36 'change' => __( 'Change Image' ), 37 37 'remove' => __( 'Remove' ), … … 39 39 'placeholder' => __( 'No image selected' ), 40 40 'frame_title' => __( 'Select Image' ), 41 41 'frame_button' => __( 'Choose Image' ), 42 ) ;42 ) ); 43 43 } 44 44 45 45 /** -
src/wp-includes/customize/class-wp-customize-media-control.php
55 55 public function __construct( $manager, $id, $args = array() ) { 56 56 parent::__construct( $manager, $id, $args ); 57 57 58 $this->button_labels = array( 59 'select' => __( 'Select File' ), 60 'change' => __( 'Change File' ), 61 'default' => __( 'Default' ), 62 'remove' => __( 'Remove' ), 63 'placeholder' => __( 'No file selected' ), 64 'frame_title' => __( 'Select File' ), 65 'frame_button' => __( 'Choose File' ), 66 ); 58 if ( ! is_a( $this, 'WP_Customize_Image_Control' ) ) { 59 $this->button_labels = wp_parse_args( $this->button_labels, array( 60 'select' => __( 'Select File' ), 61 'change' => __( 'Change File' ), 62 'default' => __( 'Default' ), 63 'remove' => __( 'Remove' ), 64 'placeholder' => __( 'No file selected' ), 65 'frame_title' => __( 'Select File' ), 66 'frame_button' => __( 'Choose File' ), 67 ) ); 68 } 67 69 } 68 70 69 71 /** -
src/wp-includes/customize/class-wp-customize-site-icon-control.php
41 41 parent::__construct( $manager, $id, $args ); 42 42 add_action( 'customize_controls_print_styles', 'wp_site_icon', 99 ); 43 43 } 44 45 /** 46 * Render a JS template for the content of the site icon control. 47 * 48 * @since 4.5.0 49 */ 50 public function content_template() { 51 ?> 52 <label for="{{ data.settings['default'] }}-button"> 53 <# if ( data.label ) { #> 54 <span class="customize-control-title">{{ data.label }}</span> 55 <# } #> 56 <# if ( data.description ) { #> 57 <span class="description customize-control-description">{{{ data.description }}}</span> 58 <# } #> 59 </label> 60 61 <# if ( data.attachment && data.attachment.id ) { #> 62 <div class="current"> 63 <div class="container"> 64 <div class="attachment-media-view attachment-media-view-{{ data.attachment.type }} {{ data.attachment.orientation }} site-icon-preview"> 65 <strong><?php _e( 'As a browser icon' ); ?></strong> 66 <div class="favicon-preview"> 67 <img src="images/browser.png" class="browser-preview" width="182" height="" alt="" /> 68 69 <div class="favicon"> 70 <img id="preview-favicon" src="{{ data.attachment.sizes.full.url }}" alt="<?php esc_attr_e( 'Preview as a browser icon' ); ?>"/> 71 </div> 72 <span class="browser-title"><?php bloginfo( 'name' ); ?></span> 73 </div> 74 75 <strong><?php _e( 'As an app icon' ); ?></strong> 76 <p class="app-icon-preview"> 77 <img id="preview-app-icon" src="{{ data.attachment.sizes.full.url }}" alt="<?php esc_attr_e( 'Preview as an app icon' ); ?>"/> 78 </p> 79 </div> 80 </div> 81 </div> 82 <div class="actions"> 83 <# if ( data.canUpload ) { #> 84 <button type="button" class="button remove-button"><?php echo $this->button_labels['remove']; ?></button> 85 <button type="button" class="button upload-button" id="{{ data.settings['default'] }}-button"><?php echo $this->button_labels['change']; ?></button> 86 <div style="clear:both"></div> 87 <# } #> 88 </div> 89 <# } else { #> 90 <div class="current"> 91 <div class="container"> 92 <div class="placeholder"> 93 <div class="inner"> 94 <span><?php echo $this->button_labels['placeholder']; ?></span> 95 </div> 96 </div> 97 </div> 98 </div> 99 <div class="actions"> 100 <# if ( data.defaultAttachment ) { #> 101 <button type="button" class="button default-button"><?php echo $this->button_labels['default']; ?></button> 102 <# } #> 103 <# if ( data.canUpload ) { #> 104 <button type="button" class="button upload-button" id="{{ data.settings['default'] }}-button"><?php echo $this->button_labels['select']; ?></button> 105 <# } #> 106 <div style="clear:both"></div> 107 </div> 108 <# } #> 109 <?php 110 } 44 111 } -
src/wp-includes/general-template.php
836 836 } 837 837 838 838 /** 839 * Whether the site has a Site Logo. 840 * 841 * @since 4.5.0 842 * 843 * @param int $blog_id Optional. ID of the blog in question. Default current blog. 844 * @return bool Whether the site has a site logo or not. 845 */ 846 function has_site_logo( $blog_id = 0 ) { 847 if ( is_multisite() && (int) $blog_id !== get_current_blog_id() ) { 848 switch_to_blog( $blog_id ); 849 } 850 851 $site_logo_id = get_theme_mod( 'site_logo' ); 852 853 if ( is_multisite() && ms_is_switched() ) { 854 restore_current_blog(); 855 } 856 857 return (bool) $site_logo_id; 858 } 859 860 /** 861 * Returns a Site Logo, linked to home. 862 * 863 * @since 4.5.0 864 * 865 * @param int $blog_id Optional. ID of the blog in question. Default current blog. 866 * @return string Site logo markup. 867 */ 868 function get_the_site_logo( $blog_id = 0 ) { 869 $html = ''; 870 871 if ( is_multisite() && (int) $blog_id !== get_current_blog_id() ) { 872 switch_to_blog( $blog_id ); 873 } 874 875 $site_logo_id = get_theme_mod( 'site_logo' ); 876 877 if ( is_multisite() && ms_is_switched() ) { 878 restore_current_blog(); 879 } 880 $size = get_theme_support( 'site-logo' ); 881 $size = $size[0]['size']; 882 883 // We have a logo. Logo is go. 884 if ( $site_logo_id ) { 885 $html = sprintf( '<a href="%1$s" class="site-logo-link" rel="home" itemprop="url">%2$s</a>', 886 esc_url( home_url( '/' ) ), 887 wp_get_attachment_image( $site_logo_id, $size, false, array( 888 'class' => "site-logo attachment-$size", 889 'data-size' => $size, 890 'itemprop' => 'logo', 891 ) ) 892 ); 893 } 894 895 // If no logo is set but we're in the Customizer, leave a placeholder (needed for the live preview). 896 elseif ( is_customize_preview() ) { 897 $html = sprintf( '<a href="%1$s" class="site-logo-link" style="display:none;"><img class="site-logo" data-size="%2$s" /></a>', 898 esc_url( home_url( '/' ) ), 899 esc_attr( $size ) 900 ); 901 } 902 903 /** 904 * Filter the Site Logo output. 905 * 906 * @since 4.5.0 907 * 908 * @param string $html Site Logo HTML output. 909 * @param string $size Size specified in add_theme_support declaration, or 'thumbnail' default. 910 */ 911 return apply_filters( 'get_the_site_logo', $html, $size ); 912 } 913 914 /** 915 * Displays a Site Logo, linked to home. 916 * 917 * @since 4.5.0 918 * 919 * @param int $blog_id Optional. ID of the blog in question. Default current blog. 920 */ 921 function the_site_logo( $blog_id = 0 ) { 922 echo get_the_site_logo( $blog_id ); 923 } 924 925 /** 839 926 * Returns document title for the current page. 840 927 * 841 928 * @since 4.4.0 -
src/wp-includes/js/customize-preview.js
223 223 }); 224 224 }); 225 225 226 /** 227 * Site Logo 228 * 229 * The site logo setting only contains the attachment ID. To avoid having to send an AJAX request to get more 230 * data, we send a separate message with the attachment data we get from the Customizer's media modal. 231 * Therefore first callback handles only the event of a new logo being selected. 232 * 233 * We don't need any information about a removed logo, so the second callback only handles that. 234 * 235 * @since 4.5.0 236 */ 237 api.preview.bind( 'site_logo-attachment-data', function( attachment ) { 238 var $logo = $( '.site-logo' ), 239 size = $logo.data( 'size' ), 240 srcset = []; 241 242 // If the source was smaller than the size required by the theme, give the biggest we've got. 243 if ( ! attachment.sizes[ size ] ) { 244 size = 'full'; 245 } 246 247 _.each( attachment.sizes, function( size ) { 248 srcset.push( size.url + ' ' + size.width + 'w' ); 249 } ); 250 251 $logo.attr( { 252 height: attachment.sizes[ size ].height, 253 width: attachment.sizes[ size ].width, 254 src: attachment.sizes[ size ].url, 255 srcset: srcset 256 } ); 257 258 $( '.site-logo-link' ).show(); 259 $( 'body' ).addClass( 'wp-site-logo' ); 260 } ); 261 262 api( 'site_logo', function( setting ) { 263 setting.bind( function( newValue ) { 264 if ( ! newValue ) { 265 $( '.site-logo-link' ).hide(); 266 $( 'body' ).removeClass( 'wp-site-logo' ); 267 } 268 } ); 269 270 // Focus on the control when the logo is clicked, if there is no site_logo partial. 271 if ( ! api.selectiveRefresh || ! api.selectiveRefresh.partial.has( 'site_logo' ) ) { 272 $( document.body ).on( 'click', '.site-logo-link', function( e ) { 273 if ( ! e.shiftKey ) { 274 return; 275 } 276 api.preview.send( 'focus-control-for-setting', 'site_logo' ); 277 } ); 278 $( '.site-logo-link' ).attr( 'title', api.settings.l10n.shiftClickToEdit ); 279 } 280 } ); 281 226 282 api.trigger( 'preview-ready' ); 227 283 }); 228 284 -
src/wp-includes/post-template.php
706 706 if ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() ) 707 707 $classes[] = 'custom-background'; 708 708 709 if ( has_site_logo() ) { 710 $classes[] = 'wp-site-logo'; 711 } 712 709 713 $page = $wp_query->get( 'page' ); 710 714 711 715 if ( ! $page || $page < 2 )