-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Add an option to configure the site icon in general settings #6064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3ab40ab
6ad7148
e722ab6
65d9c5e
6b4a7eb
d17d133
1f291c5
882fe18
4b29b19
a96e56f
d37778e
63b1348
b9f5019
e861b06
965a307
d66d623
f0c4bb5
eefc817
fa5b46b
c8103bb
f9ad50f
6bcd656
81b0d88
c8110eb
83a1cd3
4b3757b
19ee9ae
2015624
a14a6fd
a9f3578
c3e4d53
e13e3ff
52c4d81
dbfac29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| (function($) { | ||
| var frame; | ||
|
|
||
| function calculateImageSelectOptions ( attachment ) { | ||
| var realWidth = attachment.get( 'width' ), | ||
| realHeight = attachment.get( 'height' ), | ||
| xInit = 512, | ||
| yInit = 512, | ||
| ratio = xInit / yInit, | ||
| xImg = xInit, | ||
| yImg = yInit, | ||
| x1, y1, imgSelectOptions; | ||
|
|
||
| if ( realWidth / realHeight > ratio ) { | ||
| yInit = realHeight; | ||
| xInit = yInit * ratio; | ||
| } else { | ||
| xInit = realWidth; | ||
| yInit = xInit / ratio; | ||
| } | ||
|
|
||
| x1 = ( realWidth - xInit ) / 2; | ||
| y1 = ( realHeight - yInit ) / 2; | ||
|
|
||
| imgSelectOptions = { | ||
| aspectRatio: xInit + ':' + yInit, | ||
| handles: true, | ||
| keys: true, | ||
| instance: true, | ||
| persistent: true, | ||
| imageWidth: realWidth, | ||
| imageHeight: realHeight, | ||
| minWidth: xImg > xInit ? xInit : xImg, | ||
| minHeight: yImg > yInit ? yInit : yImg, | ||
| x1: x1, | ||
| y1: y1, | ||
| x2: xInit + x1, | ||
| y2: yInit + y1 | ||
| }; | ||
|
|
||
| return imgSelectOptions; | ||
| } | ||
|
|
||
| $( function() { | ||
| // Build the choose from library frame. | ||
| $( '#choose-from-library-link' ).on( 'click', function() { | ||
| var $el = $(this); | ||
|
|
||
| // Create the media frame. | ||
| frame = wp.media({ | ||
| button: { | ||
| // Set the text of the button. | ||
| text: $el.data('update'), | ||
| // Don't close, we might need to crop. | ||
| close: false | ||
| }, | ||
| states: [ | ||
| new wp.media.controller.Library({ | ||
| title: $el.data( 'choose' ), | ||
| library: wp.media.query({ type: 'image' }), | ||
| date: false, | ||
| suggestedWidth: $el.data( 'size' ), | ||
| suggestedHeight: $el.data( 'size' ) | ||
| }), | ||
| new wp.media.controller.SiteIconCropper({ | ||
| control: { | ||
| params: { | ||
| width: $el.data( 'size' ), | ||
| height: $el.data( 'size' ) | ||
| } | ||
| }, | ||
| imgSelectOptions: calculateImageSelectOptions | ||
| }) | ||
| ] | ||
| }); | ||
|
|
||
| frame.on( 'cropped', function( attachment) { | ||
| $( '#site_icon_hidden_field' ).val(attachment.id); | ||
| switchToUpdate(attachment.url); | ||
| frame.close(); | ||
| // Start over with a frame that is so fresh and so clean clean. | ||
| frame = null; | ||
| }); | ||
|
|
||
| // When an image is selected, run a callback. | ||
| frame.on( 'select', function() { | ||
| // Grab the selected attachment. | ||
| var attachment = frame.state().get('selection').first(); | ||
|
|
||
| if ( attachment.attributes.height === $el.data('size') && $el.data('size') === attachment.attributes.width ) { | ||
| // Set the value of the hidden input to the attachment id. | ||
| $( '#site_icon_hidden_field').val(attachment.id); | ||
| switchToUpdate(attachment.attributes.url); | ||
| frame.close(); | ||
| } else { | ||
| frame.setState( 'cropper' ); | ||
| } | ||
| }); | ||
|
|
||
| frame.open(); | ||
| }); | ||
| }); | ||
|
|
||
| function switchToUpdate( url ){ | ||
| // Set site-icon-img src to the url and remove the hidden class. | ||
| $( '#site-icon-preview').find('img').not('.browser-preview').each( function(i, img ){ | ||
| $(img).attr('src', url ); | ||
| }); | ||
| $( '#site-icon-preview' ).removeClass( 'hidden' ); | ||
| // Remove hidden class from remove. | ||
| $( '#js-remove-site-icon' ).removeClass( 'hidden' ); | ||
| // If the button is not in the update state, swap the classes. | ||
| if( $( '#choose-from-library-link' ).attr( 'data-state' ) !== '1' ){ | ||
| var classes = $( '#choose-from-library-link' ).attr( 'class' ); | ||
| $( '#choose-from-library-link' ).attr( 'class', $( '#choose-from-library-link' ).attr('data-alt-classes') ); | ||
| $( '#choose-from-library-link' ).attr( 'data-alt-classes', classes ); | ||
| $( '#choose-from-library-link' ).attr( 'data-state', '1' ); | ||
| } | ||
|
|
||
| // swap the text of the button | ||
| $( '#choose-from-library-link' ).text( $( '#choose-from-library-link' ).attr( 'data-update-text' ) ); | ||
| } | ||
|
|
||
| $( '#js-remove-site-icon' ).on( 'click', function() { | ||
| $( '#site_icon_hidden_field' ).val( 'false' ); | ||
| $( '#site-icon-preview' ).toggleClass( 'hidden' ); | ||
| $( this ).toggleClass( 'hidden' ); | ||
|
|
||
| var classes = $( '#choose-from-library-link' ).attr( 'class' ); | ||
| $( '#choose-from-library-link' ).attr( 'class', $( '#choose-from-library-link' ).attr( 'data-alt-classes' ) ); | ||
| $( '#choose-from-library-link' ).attr( 'data-alt-classes', classes ); | ||
|
|
||
| // Swap the text of the button. | ||
| $( '#choose-from-library-link' ).text( $( '#choose-from-library-link' ).attr( 'data-choose-text' ) ); | ||
| // Set the state of the button so it can be changed on new icon. | ||
| $( '#choose-from-library-link' ).attr( 'data-state', ''); | ||
| }); | ||
| }(jQuery)); | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |||||||
| overflow: hidden; | ||||||||
| position: relative; | ||||||||
| max-width: 180px; | ||||||||
| float: left; | ||||||||
| } | ||||||||
|
|
||||||||
| .site-icon-preview .favicon, | ||||||||
|
|
@@ -52,3 +53,20 @@ | |||||||
| .customize-control-site_icon .app-icon-preview { | ||||||||
| margin-top: 9px; | ||||||||
| } | ||||||||
|
|
||||||||
| .site-icon-section button.reset { | ||||||||
| color: #b32d2e; | ||||||||
| text-decoration: none; | ||||||||
| border-color: transparent; | ||||||||
| box-shadow: none; | ||||||||
| background: transparent; | ||||||||
| margin: 0 10px; | ||||||||
| } | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| .site-icon-section button.reset:focus, | ||||||||
| .site-icon-section button.reset:hover { | ||||||||
| background: #b32d2e; | ||||||||
| color: #fff; | ||||||||
| border-color: #b32d2e; | ||||||||
| box-shadow: 0 0 0 1px #b32d2e; | ||||||||
| } | ||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,7 +97,86 @@ | |
| <p class="description" id="tagline-description"><?php echo $tagline_description; ?></p></td> | ||
| </tr> | ||
|
|
||
| <?php | ||
| <?php if ( current_user_can( 'upload_files' ) ) : ?> | ||
| <tr class="hide-if-no-js site-icon-section"> | ||
| <th scope="row"><?php _e( 'Site Icon' ); ?></th> | ||
| <td> | ||
| <?php | ||
| wp_enqueue_media(); | ||
| wp_enqueue_script( 'site-icon' ); | ||
|
|
||
| $classes_for_upload_button = 'upload-button button-add-media button-add-site-icon'; | ||
| $classes_for_update_button = 'button'; | ||
|
|
||
| $classes_for_avatar = 'avatar avatar-150'; | ||
| if ( has_site_icon() ) { | ||
| $classes_for_avatar .= ' has-site-icon'; | ||
| $classes_for_button = $classes_for_update_button; | ||
| $classes_for_button_on_change = $classes_for_upload_button; | ||
| } else { | ||
| $classes_for_avatar .= ' hidden'; | ||
| $classes_for_button = $classes_for_upload_button; | ||
| $classes_for_button_on_change = $classes_for_update_button; | ||
| } | ||
aaronjorbin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| ?> | ||
| <div id="site-icon-preview" class="site-icon-preview wp-clearfix <?php echo esc_attr( $classes_for_avatar ); ?>"> | ||
| <div class="favicon-preview"> | ||
| <img src="<?php echo esc_url( admin_url( 'images/' . ( is_rtl() ? 'browser-rtl.png' : 'browser.png' ) ) ); ?>" class="browser-preview" width="182" alt=""> | ||
| <div class="favicon"> | ||
| <img src="<?php site_icon_url(); ?>" alt="Preview as a browser icon"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the alt text is not translatable |
||
| </div> | ||
| <span class="browser-title" aria-hidden="true"><?php echo get_bloginfo( 'name' ); ?></span> | ||
| </div> | ||
| <img class="app-icon-preview" src="<?php site_icon_url(); ?>" alt="Preview as an app icon"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the alt text is not translatable |
||
| </div> | ||
| <input type="hidden" name="site_icon" id="site_icon_hidden_field" value="<?php form_option( 'site_icon' ); ?>" /> | ||
| <p> | ||
| <button type="button" | ||
| id="choose-from-library-link" | ||
| type="button" | ||
| class="<?php echo esc_attr( $classes_for_button ); ?>" | ||
| data-alt-classes="<?php echo esc_attr( $classes_for_button_on_change ); ?>" | ||
| data-size="512" | ||
| data-choose-text="<?php esc_attr_e( 'Choose a Site Icon' ); ?>" | ||
aaronjorbin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| data-update-text="<?php esc_attr_e( 'Change Site Icon' ); ?>" | ||
| data-update="<?php esc_attr_e( 'Set as Site Icon' ); ?>" | ||
| data-state="<?php echo esc_attr( has_site_icon() ); ?>" | ||
|
|
||
| > | ||
| <?php if ( has_site_icon() ) : ?> | ||
| <?php _e( 'Change Site Icon' ); ?> | ||
| <?php else : ?> | ||
| <?php _e( 'Choose a Site Icon' ); ?> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make casing consistent |
||
| <?php endif; ?> | ||
| </button> | ||
| <button | ||
aaronjorbin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| id="js-remove-site-icon" | ||
| type="button" | ||
| <?php echo has_site_icon() ? 'class="button button-secondary reset"' : 'class="button button-secondary reset hidden"'; ?> | ||
| > | ||
| <?php _e( 'Remove Site Icon' ); ?> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make casing consistent. I think 'site icon' should probably be lowercased in all instances, matching the 'Change site icon' text.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sentence cased, technically. |
||
| </button> | ||
| </p> | ||
|
|
||
| <p class="description" id="site-icon-description"> | ||
aaronjorbin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <?php _e( 'Site Icons are what you see in browser tabs, bookmark bars, and within the WordPress mobile apps. Upload one here!' ); ?> | ||
| </p> | ||
| <p class="description" id="site-icon-further-description"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure the id is actually used anywhere
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IDs are used for descriptions throughout this page, so this keeps consistency.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Late to the party but I'm not sure this is correct. IDs are used on this page but only when they're referenced by an |
||
| <?php | ||
| /* translators: %s: Site Icon size in pixels. */ | ||
| printf( __( 'Site Icons should be square and at least %s pixels.' ), '<strong>512 × 512</strong>' ); | ||
| ?> | ||
| </p> | ||
|
|
||
| </td> | ||
| </tr> | ||
|
|
||
| <?php | ||
| endif; | ||
| /* End Site Icon */ | ||
|
|
||
| if ( ! is_multisite() ) { | ||
| $wp_site_url_class = ''; | ||
| $wp_home_class = ''; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.