Ticket #33755: 33755.2.diff
File 33755.2.diff, 19.7 KB (added by , 9 years ago) |
---|
-
src/wp-admin/css/customize-controls.css
724 724 .customize-control-background .current, 725 725 .customize-control-cropped_image .current, 726 726 .customize-control-site_icon .current, 727 .customize-control-site_logo .current, 727 728 .customize-control-header .current { 728 729 margin-bottom: 8px; 729 730 } … … 765 766 .customize-control-site_icon .remove-button, 766 767 .customize-control-site_icon .default-button, 767 768 .customize-control-site_icon .upload-button, 769 .customize-control-site_logo .remove-button, 770 .customize-control-site_logo .default-button, 771 .customize-control-site_logo .upload-button, 768 772 .customize-control-header button.new, 769 773 .customize-control-header button.remove { 770 774 white-space: normal; … … 778 782 .customize-control-background .current .container, 779 783 .customize-control-cropped_image .current .container, 780 784 .customize-control-site_icon .current .container, 785 .customize-control-site_logo .current .container, 781 786 .customize-control-header .current .container { 782 787 overflow: hidden; 783 788 -webkit-border-radius: 2px; … … 791 796 .customize-control-background .current .container, 792 797 .customize-control-cropped_image .current .container, 793 798 .customize-control-site_icon .current .container, 799 .customize-control-site_logo .current .container, 794 800 .customize-control-image .current .container { 795 801 min-height: 40px; 796 802 } … … 801 807 .customize-control-background .placeholder, 802 808 .customize-control-cropped_image .placeholder, 803 809 .customize-control-site_icon .placeholder, 810 .customize-control-site_logo .placeholder, 804 811 .customize-control-header .placeholder { 805 812 width: 100%; 806 813 position: relative; … … 814 821 .customize-control-background .inner, 815 822 .customize-control-cropped_image .inner, 816 823 .customize-control-site_icon .inner, 824 .customize-control-site_logo .inner, 817 825 .customize-control-header .inner { 818 826 display: none; 819 827 position: absolute; … … 829 837 .customize-control-background .inner, 830 838 .customize-control-cropped_image .inner, 831 839 .customize-control-site_icon .inner, 840 .customize-control-site_logo .inner, 832 841 .customize-control-image .inner { 833 842 display: block; 834 843 min-height: 40px; … … 840 849 .customize-control-background .inner, 841 850 .customize-control-cropped_image .inner, 842 851 .customize-control-site_icon .inner, 852 .customize-control-site_logo.inner, 843 853 .customize-control-header .inner, 844 854 .customize-control-header .inner .dashicons { 845 855 line-height: 20px; … … 945 955 .customize-control-background .actions, 946 956 .customize-control-cropped_image .actions, 947 957 .customize-control-site_icon .actions, 958 .customize-control-site_logo .actions, 948 959 .customize-control-header .actions { 949 960 margin-bottom: 32px; 950 961 } … … 965 976 .customize-control-background img, 966 977 .customize-control-cropped_image img, 967 978 .customize-control-site_icon img, 979 .customize-control-site_logo img, 968 980 .customize-control-header img { 969 981 width: 100%; 970 982 -webkit-border-radius: 2px; … … 983 995 .customize-control-cropped_image .default-button, 984 996 .customize-control-site_icon .remove-button, 985 997 .customize-control-site_icon .default-button, 998 .customize-control-site_logo .remove-button, 999 .customize-control-site_logo .default-button, 986 1000 .customize-control-header .remove { 987 1001 float: left; 988 1002 margin-right: 3px; … … 994 1008 .customize-control-background .upload-button, 995 1009 .customize-control-cropped_image .upload-button, 996 1010 .customize-control-site_icon .upload-button, 1011 .customize-control-site_logo .upload-button, 997 1012 .customize-control-header .new { 998 1013 float: right; 999 1014 } -
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 options. 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 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_option( 'site_logo' ); 137 138 if ( $site_logo_id && $site_logo_id == $post_id ) { 139 delete_option( '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 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 * @global WP_Site_Logo $wp_site_logo 159 */ 160 $GLOBALS['wp_site_logo'] = new WP_Site_Logo; -
src/wp-admin/includes/template.php
1748 1748 $media_states[] = __( 'Site Icon' ); 1749 1749 } 1750 1750 1751 if ( $post->ID == get_option( 'site_logo' ) ) { 1752 $media_states[] = __( 'Logo' ); 1753 } 1754 1751 1755 /** 1752 1756 * Filter the default media display states for items in the Media list table. 1753 1757 * 1754 1758 * @since 3.2.0 1755 1759 * 1756 1760 * @param array $media_states An array of media states. Default 'Header Image', 1757 * 'Background Image', 'Site Icon' .1761 * 'Background Image', 'Site Icon', 'Logo'. 1758 1762 */ 1759 1763 $media_states = apply_filters( 'display_media_states', $media_states ); 1760 1764 -
src/wp-admin/js/customize-controls.js
2296 2296 }); 2297 2297 2298 2298 /** 2299 * A control for selecting Site Logos. 2300 * 2301 * @class 2302 * @augments wp.customize.MediaControl 2303 * @augments wp.customize.Control 2304 * @augments wp.customize.Class 2305 */ 2306 api.SiteLogoControl = api.MediaControl.extend({ 2307 2308 /** 2309 * When the control's DOM structure is ready, 2310 * set up internal event bindings. 2311 */ 2312 ready: function() { 2313 var control = this; 2314 2315 // Shortcut so that we don't have to use _.bind every time we add a callback. 2316 _.bindAll( control, 'restoreDefault', 'removeFile', 'openFrame', 'select' ); 2317 2318 // Bind events, with delegation to facilitate re-rendering. 2319 control.container.on( 'click keydown', '.upload-button', control.openFrame ); 2320 control.container.on( 'click keydown', '.thumbnail-image img', control.openFrame ); 2321 control.container.on( 'click keydown', '.default-button', control.restoreDefault ); 2322 control.container.on( 'click keydown', '.remove-button', control.removeFile ); 2323 2324 control.setting.bind( function( attachmentId ) { 2325 wp.media.attachment( attachmentId ).fetch().done( function() { 2326 wp.customize.previewer.send( 'site-logo-attachment-data', this.attributes ); 2327 } ); 2328 2329 // Re-render whenever the control's setting changes. 2330 control.renderContent(); 2331 } ); 2332 } 2333 }); 2334 2335 /** 2299 2336 * @class 2300 2337 * @augments wp.customize.Control 2301 2338 * @augments wp.customize.Class … … 3201 3238 image: api.ImageControl, 3202 3239 cropped_image: api.CroppedImageControl, 3203 3240 site_icon: api.SiteIconControl, 3241 site_logo: api.SiteLogoControl, 3204 3242 header: api.HeaderControl, 3205 3243 background: api.BackgroundControl, 3206 3244 theme: api.ThemeControl -
src/wp-includes/class-wp-customize-manager.php
208 208 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-background-image-control.php' ); 209 209 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-cropped-image-control.php' ); 210 210 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-site-icon-control.php' ); 211 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-site-logo-control.php' ); 211 212 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-header-image-control.php' ); 212 213 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-theme-control.php' ); 213 214 require_once( ABSPATH . WPINC . '/customize/class-wp-widget-area-customize-control.php' ); … … 1804 1805 $this->register_control_type( 'WP_Customize_Background_Image_Control' ); 1805 1806 $this->register_control_type( 'WP_Customize_Cropped_Image_Control' ); 1806 1807 $this->register_control_type( 'WP_Customize_Site_Icon_Control' ); 1808 $this->register_control_type( 'WP_Customize_Site_Logo_Control' ); 1807 1809 $this->register_control_type( 'WP_Customize_Theme_Control' ); 1808 1810 1809 1811 /* Themes */ … … 1879 1881 'section' => 'title_tagline', 1880 1882 ) ); 1881 1883 1884 // Add a setting to hide header text if the theme isn't supporting the feature itself. 1885 // @todo 1886 if ( ! current_theme_supports( 'custom-header' ) ) { 1887 $this->add_setting( 'header_text', array( 1888 'default' => 1, 1889 'sanitize_callback' => 'absint', 1890 'transport' => 'postMessage', 1891 ) ); 1892 1893 $this->add_control( 'header_text', array( 1894 'label' => __( 'Display Site Title and Tagline' ), 1895 'section' => 'title_tagline', 1896 'settings' => 'header_text', 1897 'type' => 'checkbox', 1898 ) ); 1899 } 1900 1882 1901 $this->add_setting( 'site_icon', array( 1883 1902 'type' => 'option', 1884 1903 'capability' => 'manage_options', … … 1898 1917 'width' => 512, 1899 1918 ) ) ); 1900 1919 1920 $this->add_setting( 'site_logo', array( 1921 'theme_supports' => array( 'site-logo' ), 1922 'type' => 'option', 1923 'capability' => 'manage_options', 1924 'transport' => 'postMessage', 1925 ) ); 1926 1927 $this->add_control( new WP_Customize_Site_Logo_Control( $this, 'site_logo', array( 1928 'label' => __( 'Logo' ), 1929 'section' => 'title_tagline', 1930 'priority' => 50, 1931 ) ) ); 1932 1901 1933 /* Colors */ 1902 1934 1903 1935 $this->add_section( 'colors', array( -
src/wp-includes/customize/class-wp-customize-site-logo-control.php
1 <?php 2 /** 3 * Customize API: WP_Customize_Site_Logo_Control class 4 * 5 * @package WordPress 6 * @subpackage Customize 7 * @since 4.5.0 8 */ 9 10 /** 11 * Customize Site Logo control class. 12 * 13 * Used only for custom functionality in JavaScript. 14 * 15 * @since 4.5.0 16 * 17 * @see WP_Customize_Image_Control 18 */ 19 class WP_Customize_Site_Logo_Control extends WP_Customize_Image_Control { 20 21 /** 22 * Control type. 23 * 24 * @since 4.5.0 25 * @access public 26 * @var string 27 */ 28 public $type = 'site_logo'; 29 30 /** 31 * Constructor. 32 * 33 * @since 4.5.0 34 * @access public 35 * 36 * @param WP_Customize_Manager $manager Customizer bootstrap instance. 37 * @param string $id Control ID. 38 * @param array $args Optional. Arguments to override class property defaults. 39 */ 40 public function __construct( $manager, $id, $args = array() ) { 41 parent::__construct( $manager, $id, $args ); 42 43 $this->button_labels = array( 44 'select' => __( 'Select logo' ), 45 'change' => __( 'Change logo' ), 46 'remove' => __( 'Remove' ), 47 'default' => __( 'Default' ), 48 'placeholder' => __( 'No logo selected' ), 49 'frame_title' => __( 'Select logo' ), 50 'frame_button' => __( 'Choose logo' ), 51 ); 52 } 53 } -
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_option( '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 function get_the_site_logo( $blog_id = 0 ) { 861 $html = ''; 862 863 if ( is_multisite() && (int) $blog_id !== get_current_blog_id() ) { 864 switch_to_blog( $blog_id ); 865 } 866 867 $site_logo_id = get_option( 'site_logo' ); 868 869 if ( is_multisite() && ms_is_switched() ) { 870 restore_current_blog(); 871 } 872 $size = get_theme_support( 'site-logo' ); 873 $size = $size[0]['size']; 874 875 // We have a logo. Logo is go. 876 if ( $site_logo_id ) { 877 $html = sprintf( '<a href="%1$s" class="site-logo-link" rel="home" itemprop="url">%2$s</a>', 878 esc_url( home_url( '/' ) ), 879 wp_get_attachment_image( $site_logo_id, $size, false, array( 880 'class' => "site-logo attachment-$size", 881 'data-size' => $size, 882 'itemprop' => 'logo', 883 ) ) 884 ); 885 } 886 887 // If no logo is set but we're in the Customizer, leave a placeholder (needed for the live preview). 888 elseif ( is_customize_preview() ) { 889 $html = sprintf( '<a href="%1$s" class="site-logo-link" style="display:none;"><img class="site-logo" data-size="%2$s" /></a>', 890 esc_url( home_url( '/' ) ), 891 esc_attr( $size ) 892 ); 893 } 894 895 /** 896 * Filter the Site Logo output. 897 * 898 * @since 4.5.0 899 * 900 * @param string $html Site Logo HTML output. 901 * @param string $size Size specified in add_theme_support declaration, or 'thumbnail' default. 902 */ 903 return apply_filters( 'get_the_site_logo', $html, $size ); 904 } 905 906 function the_site_logo( $blog_id = 0 ) { 907 echo get_the_site_logo( $blog_id ); 908 } 909 /** 839 910 * Returns document title for the current page. 840 911 * 841 912 * @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 226 271 api.trigger( 'preview-ready' ); 227 272 }); 228 273 -
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 )