diff --git a/src/wp-admin/css/common.css b/src/wp-admin/css/common.css index 579bdaf0fa..45f10635f3 100644 --- a/src/wp-admin/css/common.css +++ b/src/wp-admin/css/common.css @@ -123,6 +123,7 @@ .ui-helper-hidden-accessible { border: 0; clip: rect(1px, 1px, 1px, 1px); + -webkit-clip-path: inset(50%); clip-path: inset(50%); height: 1px; margin: -1px; diff --git a/src/wp-admin/css/customize-controls.css b/src/wp-admin/css/customize-controls.css index 45c49b5fa5..fe5cb71048 100644 --- a/src/wp-admin/css/customize-controls.css +++ b/src/wp-admin/css/customize-controls.css @@ -589,20 +589,16 @@ body.outer-section-open .wp-full-overlay.expanded .wp-full-overlay-main { } #customize-theme-controls .customize-pane-child.open, -#customize-theme-controls .customize-pane-child.current-panel, -#customize-theme-controls .customize-themes-panel.customize-pane-child.current-panel { +#customize-theme-controls .customize-pane-child.current-panel { -webkit-transform: none; transform: none; } -#customize-theme-controls .customize-themes-panel.customize-pane-child, .section-open #customize-theme-controls .customize-pane-parent, .in-sub-panel #customize-theme-controls .customize-pane-parent, .section-open #customize-info, .in-sub-panel #customize-info, -.in-sub-panel.section-open #customize-theme-controls .customize-pane-child.current-panel, -.in-themes-panel #customize-theme-controls .customize-pane-parent, -.in-themes-panel #customize-info { +.in-sub-panel.section-open #customize-theme-controls .customize-pane-child.current-panel { visibility: hidden; height: 0; overflow: hidden; @@ -612,10 +608,8 @@ body.outer-section-open .wp-full-overlay.expanded .wp-full-overlay-main { .section-open #customize-theme-controls .customize-pane-parent.busy, .in-sub-panel #customize-theme-controls .customize-pane-parent.busy, -.in-themes-panel #customize-theme-controls .customize-pane-parent.busy, .section-open #customize-info.busy, .in-sub-panel #customize-info.busy, -.in-themes-panel #customize-info.busy, .busy.section-open.in-sub-panel #customize-theme-controls .customize-pane-child.current-panel, #customize-theme-controls .customize-pane-child.open, #customize-theme-controls .customize-pane-child.current-panel, @@ -625,12 +619,6 @@ body.outer-section-open .wp-full-overlay.expanded .wp-full-overlay-main { overflow: auto; } -.in-themes-panel #customize-theme-controls .customize-pane-parent, -.in-themes-panel #customize-info { - -webkit-transform: translateX(100%); - transform: translateX(100%); -} - #customize-theme-controls .customize-pane-child.accordion-section-content, #customize-theme-controls .customize-pane-child.accordion-sub-container { display: block; @@ -1572,37 +1560,45 @@ p.customize-section-description { 100% { opacity: 1; } } -/* #customize-container is reused from customize-loader.js, hence the naming. */ -.wp-customizer .customize-loading #customize-container { +.wp-customizer .customize-loading #customize-themes-loading-container { display: block; - -webkit-animation: customize-reload .75s; /* Can't use `transition` because `display` changes here. */ - animation: customize-reload .75s; + -webkit-animation: customize-reload .5s; /* Can't use `transition` because `display` changes here. */ + animation: customize-reload .5s; } -#customize-theme-controls .control-section-themes .accordion-section-title:hover, /* Not a focusable element. */ -#customize-theme-controls .control-section-themes .accordion-section-title { +.customize-loading #customize-themes-loading-container span { + clear: both; + color: #191e23; + font-size: 18px; + font-style: normal; + margin: 0; + padding: 2em 0; + text-align: center; + width: 100%; + display: block; + top: 50%; + position: relative; +} + +.customize-loading #customize-themes-loading-container .customize-loading-text { + display: none; +} + +#customize-theme-controls .control-panel-themes { + border-bottom: none; +} + +#customize-theme-controls .control-panel-themes > .accordion-section-title:hover, /* Not a focusable element. */ +#customize-theme-controls .control-panel-themes > .accordion-section-title { cursor: default; background: #fff; color: #555d66; border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; border-left: none; - margin-top: 0; -} -#customize-theme-controls .control-section-themes .customize-section-back { - position: absolute; - right: 0; - top: 0; - height: 80px; - border-left: 1px solid #ddd; - border-right: 4px solid #fff; -} -#customize-theme-controls .control-section-themes .customize-section-back:before { - content: "\f345"; -} -#customize-theme-controls .control-section-themes .customize-section-back:hover, -#customize-theme-controls .control-section-themes .customize-section-back:focus { - border-right-color: #0073aa; + border-right: none; + margin: 0 0 15px 0; + padding-right: 100px; /* Space for the button */ } #customize-theme-controls .control-section-themes .customize-themes-panel .accordion-section-title:first-child:hover, /* Not a focusable element. */ @@ -1625,6 +1621,8 @@ p.customize-section-description { padding-right: 100px; /* Space for the button */ } +.control-panel-themes .accordion-section-title span.customize-action, +#customize-controls .customize-section-title span.customize-action, #customize-controls .control-section-themes .accordion-section-title span.customize-action, #customize-controls .customize-section-title span.customize-action, #customize-outer-theme-controls .customize-section-title span.customize-action { @@ -1633,8 +1631,7 @@ p.customize-section-description { font-weight: 400; } -#customize-controls .control-section-themes .accordion-section-title .change-theme, -#customize-controls .customize-themes-panel .accordion-section-title .customize-theme { +#customize-theme-controls .control-panel-themes .accordion-section-title .change-theme { position: absolute; right: 10px; top: 50%; @@ -1642,36 +1639,253 @@ p.customize-section-description { font-weight: 400; } -#customize-controls .control-section-themes .accordion-section-title:before { +#customize-theme-controls .control-panel-themes > .accordion-section-title:after { display: none; } -#customize-controls .customize-themes-panel { - padding: 0 8px; - background: #f1f1f1; +.control-panel-themes .customize-themes-full-container { + position: fixed; + top: 0; + left: 0; + transition: .18s left ease-in-out; + margin: 46px 0 0 300px; + padding: 25px 0; + overflow-y: scroll; + width: calc(100% - 300px); + height: calc(100% - 96px); + background: #eee; + z-index: 20; +} + +/* Animations for opening the themes panel */ +#customize-header-actions .save, +#customize-header-actions .spinner, +#customize-header-actions .customize-controls-preview-toggle { + position: relative; + top: 0; + transition: .18s top ease-in-out; +} + +#customize-footer-actions, +#customize-footer-actions .collapse-sidebar { + bottom: 0; + transition: .18s bottom ease-in-out; +} + +.in-themes-panel:not(.animating) #customize-header-actions .save, +.in-themes-panel:not(.animating) #customize-header-actions #publish-settings, +.in-themes-panel:not(.animating) #customize-header-actions .spinner, +.in-themes-panel:not(.animating) #customize-header-actions .customize-controls-preview-toggle, +.in-themes-panel:not(.animating) #customize-preview, +.in-themes-panel:not(.animating) #customize-footer-actions { + visibility: hidden; +} + +.wp-full-overlay.in-themes-panel { + background: #eee; /* Prevents a black flash when fading in the panel */ +} + +.in-themes-panel #customize-header-actions .save, +.in-themes-panel #customize-header-actions .spinner, +.in-themes-panel #customize-header-actions .customize-controls-preview-toggle { + top: -45px; +} + +.in-themes-panel #customize-footer-actions, +.in-themes-panel #customize-footer-actions .collapse-sidebar { + bottom: -45px; +} + +/* Don't show the theme count while the panel opens, as it's in the wrong place during the animation */ +.in-themes-panel.animating .control-panel-themes .filter-themes-count { + display: none; +} + +.in-themes-panel.wp-full-overlay .wp-full-overlay-sidebar-content { + bottom: 0; +} + +.themes-filter-bar .feature-filter-toggle { + float: right; + margin: 3px 0 3px 25px; +} + +.themes-filter-bar .feature-filter-toggle:before { + content: "\f111"; + margin: 0 5px 0 0; + font: normal 16px/1 dashicons; + vertical-align: text-bottom; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +.themes-filter-bar .feature-filter-toggle.open { + background: #eee; + border-color: #999; + box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 ); + -webkit-transform: translateY(1px); + transform: translateY(1px); +} + +.themes-filter-bar .feature-filter-toggle .filter-count-filters { + display: none; +} + +.themes-filter-bar .filter-drawer { box-sizing: border-box; + width: 100%; + position: absolute; + top: 46px; + left: 0; + padding: 25px 0 25px 25px; + border-top: 0; + margin: 0; + background: #eee; + border-bottom: 1px solid #ddd; } -#customize-controls .customize-themes-panel .accordion-section-title:first-child { - margin-top: 0; +.themes-filter-bar .filter-group { + margin: 0 25px 0 0; + width: calc( (100% - 75px) / 3); + min-width: 200px; + max-width: 320px; } -#customize-controls .customize-themes-panel .accordion-section-title:nth-child(2) { +/* Adds a delay before fading in to avoid it "jumping" */ +@-webkit-keyframes themes-fade-in { + 0% { + opacity: 0; + } + 50% { + opacity: 0; + } + 100% { + opacity: 1; + } +} +@keyframes themes-fade-in { + 0% { + opacity: 0; + } + 50% { + opacity: 0; + } + 100% { + opacity: 1; + } +} + +.control-panel-themes .customize-themes-full-container.animate { + -webkit-animation: .6s themes-fade-in 1; + animation: .6s themes-fade-in 1; +} + +.in-themes-panel:not(.animating) .control-panel-themes .filter-themes-count { + -webkit-animation: .6s themes-fade-in 1; + animation: .6s themes-fade-in 1; +} + +.control-panel-themes .filter-themes-count { + position: relative; + float: right; + line-height: 34px; +} + +.control-panel-themes .filter-themes-count .themes-displayed { + font-weight: 600; + color: #555d66; +} + +.customize-themes-notifications { + margin: 0; +} + +.control-panel-themes .customize-themes-notifications .notice { + margin: 0 0 25px 0; +} + +.customize-themes-full-container .customize-themes-section { + display: none !important; /* There is unknown JS that perpetually tries to show all theme sections when more items are added. */ + overflow: hidden; +} + +.customize-themes-full-container .customize-themes-section.current-section { + display: list-item !important; /* There is unknown JS that perpetually tries to show all theme sections when more items are added. */ +} + +.control-section .customize-section-text-before { + padding: 0 0 8px 15px; + margin: 15px 0 0 0; + line-height: 16px; + border-bottom: 1px solid #ddd; + color: #555d66; +} + +.control-panel-themes .customize-themes-section-title { + width: 100%; + background: #fff; + box-shadow: none; + outline: none; + border-top: none; + border-bottom: 1px solid #ddd; + border-left: 4px solid #fff; + border-right: none; + cursor: pointer; + padding: 10px 15px; + position: relative; + text-align: left; font-size: 14px; font-weight: 600; + color: #555d66; + text-shadow: none; } -#customize-controls .customize-themes-panel > h2 { - padding: 15px 8px 0 8px; +.control-panel-themes #accordion-section-installed_themes { + border-top: 1px solid #ddd; } -#customize-theme-controls .customize-themes-panel .accordion-section-content { - background: transparent; +.control-panel-themes .theme-section { + margin: 0; + position: relative; +} + +.control-panel-themes .customize-themes-section-title:focus, +.control-panel-themes .customize-themes-section-title:hover { + border-left-color: #0073aa; + color: #0073aa; + background: #f5f5f5; +} + +.customize-themes-section-title:not(.selected):after { + content: ""; display: block; + position: absolute; + top: 9px; + right: 15px; + width: 18px; + height: 18px; + border-radius: 100%; + border: 1px solid #ccc; + background: #fff; } -.customize-control.customize-control-theme { - margin-bottom: 8px; +.control-panel-themes .theme-section .customize-themes-section-title.selected:after { + content: "\f147"; + font: 16px/1 dashicons; + box-sizing: border-box; + width: 20px; + height: 20px; + padding: 3px 3px 1px 1px; /* Re-align the icon to the smaller grid */ + border-radius: 100%; + position: absolute; + top: 9px; + right: 15px; + background: #0073aa; + color: #fff; +} + +.control-panel-themes .customize-themes-section-title.selected { + color: #0073aa; } #customize-theme-controls .themes.accordion-section-content { @@ -1681,17 +1895,94 @@ p.customize-section-description { width: 100%; } -.wp-customizer .theme-browser .themes { - padding-bottom: 8px; +.loading .customize-themes-section .spinner { + display: block; + visibility: visible; + position: relative; + clear: both; + width: 20px; + height: 20px; + left: calc(50% - 10px); + float: none; + margin-top: 50px; } -.wp-customizer .theme-browser .theme { - margin: 0; +.customize-themes-section .no-themes, +.customize-themes-section .no-themes-local { + display: none; +} + +.themes-section-installed_themes .theme .notice-success { + display: none; /* Hide "installed" notice on installed themes tab. */ +} + +.control-panel-themes .theme-browser .theme .theme-actions .button-primary { + margin: 0 0 0 8px; +} + +.customize-control-theme .theme { width: 100%; + margin: 0; + border: 1px solid #ddd; + background: #fff; +} + +.customize-control-theme .theme .theme-name, .customize-control-theme .theme .theme-actions { + background: #fff; + border: none; +} + +.customize-control.customize-control-theme { /* override most properties on .customize-control */ + box-sizing: border-box; + width: 25%; + max-width: 600px; /* Max. screenshot size / 2 */ + margin: 0 25px 25px 0; + padding: 0; + clear: none; +} + +/* 5 columns above 2100px */ +@media screen and (min-width: 2101px) { + .customize-control.customize-control-theme { + width: calc( ( 100% - 125px ) / 5 - 1px ); /* 1px offset accounts for browser rounding, typical all grids */ + } +} + +/* 4 columns up to 2100px */ +@media screen and (min-width: 1601px) and (max-width: 2100px) { + .customize-control.customize-control-theme { + width: calc( ( 100% - 100px ) / 4 - 1px ); + } +} + +/* 3 columns up to 1600px */ +@media screen and (min-width: 1201px) and (max-width: 1600px) { + .customize-control.customize-control-theme { + width: calc( ( 100% - 75px ) / 3 - 1px ); + } +} + +/* 2 columns up to 1200px */ +@media screen and (min-width: 851px) and (max-width: 1200px) { + .customize-control.customize-control-theme { + width: calc( ( 100% - 50px ) / 2 - 1px ); + + } +} + +/* 1 column up to 850 px */ +@media screen and (max-width: 850px) { + .customize-control.customize-control-theme { + width: 100%; + } +} + +.wp-customizer .theme-browser .themes { + padding: 0 0 25px 25px; + transition: .18s margin-top linear; } .wp-customizer .theme-browser .theme .theme-actions { - -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; opacity: 1; } @@ -1703,20 +1994,161 @@ p.customize-section-description { font-size: 32px; } -.wp-customizer #themes-filter { - font-size: 16px; - font-weight: 300; - line-height: 1.5; - width: 100%; +.customize-preview-header.themes-filter-bar { + position: fixed; + top: 0; + left: 300px; + width: calc(100% - 300px); + height: 46px; + background: #eee; + z-index: 10; + padding: 6px 25px; + box-sizing: border-box; + border-bottom: 1px solid #ddd; } -.control-section-themes .accordion-section-title:after, -.customize-themes-panel .accordion-section-title:after { +.themes-filter-bar .themes-filter-container { + margin: 0; + padding: 0; +} + +.themes-filter-bar .wp-filter-search { + line-height: 25px; + padding: 3px 5px; + max-width: 100%; + width: 40%; + min-width: 300px; + position: absolute; + top: 6px; + left: 25px; +} + +/* Unstick the filter bar on short windows/screens. This breakpoint is based on the + current length of .org feature filters assuming translations do not wrap lines. */ +@media screen and (max-height:540px), screen and (max-width:1018px) { + .customize-preview-header.themes-filter-bar { + position: relative; + left: 0; + width: 100%; + margin: 0 0 25px 0; + } + .wp-customizer .theme-browser .themes { + padding: 0 0 25px 25px; + overflow: hidden; + } + + .control-panel-themes .customize-themes-full-container { + margin-top: 0; + padding: 0; + height: 100%; + width: calc(100% - 300px); + } +} + +@media screen and (max-width:1018px) { + .themes-filter-bar .filter-group { + width: calc( (100% - 50px) / 2); + } +} + +@media screen and (max-width:900px) { + .customize-preview-header.themes-filter-bar { + height: 86px; + padding-top: 46px; + } + + .themes-filter-bar .wp-filter-search { + width: calc(100% - 50px); + margin: 0; + min-width: 200px; + } + + .themes-filter-bar .filter-drawer { + top: 86px; + } + + .control-panel-themes .filter-themes-count { + float: left; + } +} + +@media screen and (max-width:792px) { + .themes-filter-bar .filter-group { + width: calc( 100% - 25px); + } +} + +.control-panel-themes .customize-themes-mobile-back { display: none; } -.customize-themes-panel.control-panel-content { - border-top: 1px solid #ddd; +/* Mobile - toggle between themes and filters */ +@media screen and (max-width:600px) { + + .wp-full-overlay.showing-themes .control-panel-themes .filter-themes-count .filter-themes { + display: block; + float: right; + } + + .control-panel-themes .customize-themes-full-container { + width: 100%; + margin: 0; + top: 46px; + height: calc(100% - 46px); + z-index: 1; + display: none; + } + + .showing-themes .control-panel-themes .customize-themes-full-container { + display: block; + } + + .wp-customizer .showing-themes .control-panel-themes .customize-themes-mobile-back { + display: block; + position: fixed; + top: 0; + left: 0; + background: #eee; + color: #444; + border-radius: 0; + box-shadow: none; + border: none; + height: 46px; + width: 100%; + z-index: 10; + text-align: left; + text-shadow: none; + border-bottom: 1px solid #ddd; + border-left: 4px solid transparent; + margin: 0; + padding: 0; + font-size: 0; + overflow: hidden; + } + + .wp-customizer .showing-themes .control-panel-themes .customize-themes-mobile-back:before { + left: 0; + top: 0; + height: 42px; + width: 26px; + display: block; + line-height: 46px; + padding: 0 8px 0 8px; + border-right: 1px solid #ddd; + } + + .wp-customizer .showing-themes .control-panel-themes .customize-themes-mobile-back:hover, + .wp-customizer .showing-themes .control-panel-themes .customize-themes-mobile-back:focus { + color: #0073aa; + background: #f3f3f5; + border-left-color: #0073aa; + outline: none; + box-shadow: none; + } + + .showing-themes #customize-header-actions { + display: none; + } } /* Details View */ @@ -1733,29 +2165,90 @@ p.customize-section-description { z-index: 109; } +/* Avoid a z-index war by resetting elements that should be under the overlay. + This is likely required because of the way that sections and panels are positioned. */ +.wp-customizer.modal-open #customize-header-actions, +.wp-customizer.modal-open .control-panel-themes .filter-themes-count, +.wp-customizer.modal-open .control-panel-themes .customize-themes-section-title.selected:after { + z-index: -1; +} + .wp-customizer .theme-overlay .theme-backdrop { background: rgba( 238, 238, 238, 0.75 ); position: fixed; z-index: 110; } +.wp-customizer .theme-overlay .star-rating { + float: left; + margin-right: 8px; +} + +.wp-customizer .theme-rating .num-ratings { + line-height: 20px; +} + .wp-customizer .theme-overlay .theme-wrap { left: 90px; right: 90px; top: 45px; bottom: 45px; z-index: 120; - max-width: 1740px; /* To ensure that theme screenshots are not displayed larger than 880px wide. */ } .wp-customizer .theme-overlay .theme-actions { - text-align: right; /* Because there's only one action, match the pattern of media modals and right-align the action. */ + text-align: right; /* Because there're only one or two actions, match the UI pattern of media modals and right-align the action. */ + padding: 10px 25px; + background: #eee; + border-top: 1px solid #ddd; } -.ie8 .wp-customizer .theme-overlay .theme-header, -.ie8 .wp-customizer .theme-overlay .theme-about, -.ie8 .wp-customizer .theme-overlay .theme-actions { - position: static; +.wp-customizer .theme-overlay .theme-actions .theme-install.preview { + margin-left: 8px; +} + +.control-panel-themes .theme-actions .delete-theme { + left: 15px; /* these override themes.css on mobile */ + right: auto; + bottom: auto; + position: absolute; +} + +.modal-open .in-themes-panel #customize-controls .wp-full-overlay-sidebar-content { + overflow: visible; /* Prevent the top-level Customizer controls from becoming visible when elements on the right of the details modal are focused. */ +} + +.wp-customizer .theme-header { + background: #eee; +} + +.wp-customizer .theme-overlay .theme-header button, +.wp-customizer .theme-overlay .theme-header .close:before { + color: #444; +} + +.wp-customizer .theme-overlay .theme-header .close:focus, +.wp-customizer .theme-overlay .theme-header .close:hover, +.wp-customizer .theme-overlay .theme-header .right:focus, +.wp-customizer .theme-overlay .theme-header .right:hover, +.wp-customizer .theme-overlay .theme-header .left:focus, +.wp-customizer .theme-overlay .theme-header .left:hover { + background: #fff; + border-bottom: 4px solid #0073aa; + color: #0073aa; +} + +.wp-customizer .theme-overlay .theme-header .close:focus:before, +.wp-customizer .theme-overlay .theme-header .close:hover:before { + color: #0073aa; +} + +.wp-customizer .theme-overlay .theme-header button.disabled, +.wp-customizer .theme-overlay .theme-header button.disabled:hover, +.wp-customizer .theme-overlay .theme-header button.disabled:focus { + border-bottom: none; + background: transparent; + color: #ccc; } /* Small Screens */ @@ -1783,7 +2276,7 @@ body.cheatin { body.cheatin h1 { border-bottom: 1px solid #ddd; clear: both; - color: #666; + color: #555d66; font-size: 24px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; margin: 30px 0 0 0; diff --git a/src/wp-admin/css/install.css b/src/wp-admin/css/install.css index 4253b08061..84c2f5e1d3 100644 --- a/src/wp-admin/css/install.css +++ b/src/wp-admin/css/install.css @@ -404,6 +404,7 @@ body.language-chooser { .screen-reader-text { border: 0; clip: rect(1px, 1px, 1px, 1px); + -webkit-clip-path: inset(50%); clip-path: inset(50%); height: 1px; margin: -1px; diff --git a/src/wp-admin/css/list-tables.css b/src/wp-admin/css/list-tables.css index 6e7269206c..ca40082609 100644 --- a/src/wp-admin/css/list-tables.css +++ b/src/wp-admin/css/list-tables.css @@ -1821,6 +1821,7 @@ div.action-links, /* Show comment bubble as text instead */ .post-com-count .screen-reader-text { position: static; + -webkit-clip-path: none; clip-path: none; width: auto; height: auto; diff --git a/src/wp-admin/css/nav-menus.css b/src/wp-admin/css/nav-menus.css index 2edb269bc9..ddc55dbde9 100644 --- a/src/wp-admin/css/nav-menus.css +++ b/src/wp-admin/css/nav-menus.css @@ -599,6 +599,7 @@ body.menu-max-depth-11 { min-width: 1280px !important; } .no-js.nav-menus-php .item-edit .screen-reader-text { position: static; + -webkit-clip-path: none; clip-path: none; width: auto; height: auto; diff --git a/src/wp-admin/css/themes.css b/src/wp-admin/css/themes.css index 6c4ce8716a..b6522952e6 100644 --- a/src/wp-admin/css/themes.css +++ b/src/wp-admin/css/themes.css @@ -549,7 +549,7 @@ body.folded .theme-browser ~ .theme-overlay .theme-wrap { float: left; margin: 0 30px 0 0; width: 55%; - max-width: 880px; + max-width: 1200px; /* Recommended theme screenshot width, set here to avoid stretching */ text-align: center; } @@ -1049,7 +1049,8 @@ body.folded .theme-browser ~ .theme-overlay .theme-wrap { text-align: center; } -p.no-themes { +p.no-themes, +p.no-themes-local { clear: both; color: #666; font-size: 18px; @@ -1705,9 +1706,10 @@ body.full-overlay-active { display: none; } -#customize-container { +#customize-container, +#customize-themes-loading-container { display: none; - background: #fff; + background: #eee; z-index: 500000; position: fixed; overflow: visible; @@ -1720,6 +1722,7 @@ body.full-overlay-active { /* Make the Customizer and Theme installer overlays the only available content. */ #customize-container, +#customize-themes-loading-container, .theme-install-overlay { visibility: visible; } @@ -1824,6 +1827,7 @@ body.full-overlay-active { #customize-preview.wp-full-overlay-main:before, .customize-loading #customize-container:before, +.customize-loading #customize-themes-loading-container:before, .theme-install-overlay .wp-full-overlay-main:before { content: ""; display: block; @@ -1861,6 +1865,7 @@ body.full-overlay-active { #customize-preview.wp-full-overlay-main:before, .customize-loading #customize-container:before, + .customize-loading #customize-themes-loading-container:before, .theme-install-overlay .wp-full-overlay-main:before { background-image: url(../images/spinner-2x.gif); } diff --git a/src/wp-admin/customize.php b/src/wp-admin/customize.php index 3fc2b5b6bd..897771b3d7 100644 --- a/src/wp-admin/customize.php +++ b/src/wp-admin/customize.php @@ -125,7 +125,8 @@ $admin_title = sprintf( $wp_customize->get_document_title_template(), __( 'Loadi ?><?php echo $admin_title; ?> array( - 'grid-layout' => __( 'Grid Layout' ), - 'one-column' => __( 'One Column' ), - 'two-columns' => __( 'Two Columns' ), - 'three-columns' => __( 'Three Columns' ), - 'four-columns' => __( 'Four Columns' ), - 'left-sidebar' => __( 'Left Sidebar' ), - 'right-sidebar' => __( 'Right Sidebar' ), - ), - - __( 'Features' ) => array( - 'accessibility-ready' => __( 'Accessibility Ready' ), - 'buddypress' => __( 'BuddyPress' ), - 'custom-background' => __( 'Custom Background' ), - 'custom-colors' => __( 'Custom Colors' ), - 'custom-header' => __( 'Custom Header' ), - 'custom-logo' => __( 'Custom Logo' ), - 'custom-menu' => __( 'Custom Menu' ), - 'editor-style' => __( 'Editor Style' ), - 'featured-image-header' => __( 'Featured Image Header' ), - 'featured-images' => __( 'Featured Images' ), - 'flexible-header' => __( 'Flexible Header' ), - 'footer-widgets' => __( 'Footer Widgets' ), - 'front-page-post-form' => __( 'Front Page Posting' ), - 'full-width-template' => __( 'Full Width Template' ), - 'microformats' => __( 'Microformats' ), - 'post-formats' => __( 'Post Formats' ), - 'rtl-language-support' => __( 'RTL Language Support' ), - 'sticky-post' => __( 'Sticky Post' ), - 'theme-options' => __( 'Theme Options' ), - 'threaded-comments' => __( 'Threaded Comments' ), - 'translation-ready' => __( 'Translation Ready' ), - ), - __( 'Subject' ) => array( 'blog' => __( 'Blog' ), 'e-commerce' => __( 'E-Commerce' ), @@ -278,7 +244,34 @@ function get_theme_feature_list( $api = true ) { 'news' => __( 'News' ), 'photography' => __( 'Photography' ), 'portfolio' => __( 'Portfolio' ), + ), + + __( 'Features' ) => array( + 'accessibility-ready' => __( 'Accessibility Ready' ), + 'custom-background' => __( 'Custom Background' ), + 'custom-colors' => __( 'Custom Colors' ), + 'custom-header' => __( 'Custom Header' ), + 'custom-logo' => __( 'Custom Logo' ), + 'editor-style' => __( 'Editor Style' ), + 'featured-image-header' => __( 'Featured Image Header' ), + 'featured-images' => __( 'Featured Images' ), + 'footer-widgets' => __( 'Footer Widgets' ), + 'full-width-template' => __( 'Full Width Template' ), + 'post-formats' => __( 'Post Formats' ), + 'sticky-post' => __( 'Sticky Post' ), + 'theme-options' => __( 'Theme Options' ), + ), + + __( 'Layout' ) => array( + 'grid-layout' => __( 'Grid Layout' ), + 'one-column' => __( 'One Column' ), + 'two-columns' => __( 'Two Columns' ), + 'three-columns' => __( 'Three Columns' ), + 'four-columns' => __( 'Four Columns' ), + 'left-sidebar' => __( 'Left Sidebar' ), + 'right-sidebar' => __( 'Right Sidebar' ), ) + ); if ( ! $api || ! current_user_can( 'install_themes' ) ) @@ -574,8 +567,9 @@ function wp_prepare_themes_for_js( $themes = null ) { $parent = false; if ( $theme->parent() ) { - $parent = $theme->parent()->display( 'Name' ); - $parents[ $slug ] = $theme->parent()->get_stylesheet(); + $parent = $theme->parent(); + $parents[ $slug ] = $parent->get_stylesheet(); + $parent = $parent->display( 'Name' ); } $customize_action = null; @@ -635,8 +629,6 @@ function wp_prepare_themes_for_js( $themes = null ) { * @since 4.2.0 */ function customize_themes_print_templates() { - $preview_url = esc_url( add_query_arg( 'theme', '__THEME__' ) ); // Token because esc_url() strips curly braces. - $preview_url = str_replace( '__THEME__', '{{ data.id }}', $preview_url ); ?> ', + section: section.params.id, + active: true, + theme: theme, + priority: section.loaded + 1 + }, + previewer: api.previewer + } ); + + api.control.add( customizeId, themeControl ); + newThemeControls.push( themeControl ); + section.loaded = section.loaded + 1; + }); + + if ( 1 === page ) { + + // Pre-load the first 3 theme screenshots. + _.each( section.controls().slice( 0, 3 ), function( control ) { + var img, src = control.params.theme.screenshot[0]; + if ( src ) { + img = new Image(); + img.src = src; + } + }); + if ( 'installed' !== section.params.action ) { + wp.a11y.speak( api.settings.l10n.themeSearchResults.replace( '%d', data.info.results ) ); + } + } else { + Array.prototype.push.apply( section.screenshotQueue, newThemeControls ); // Add new themes to the screenshot queue. + } + _.delay( section.renderScreenshots, 100 ); // Wait for the controls to become visible. + + if ( 'installed' === section.params.action || 100 > themes.length ) { // If we have less than the requested 100 themes, it's the end of the list. + section.fullyLoaded = true; + } + } else { + if ( 0 === section.loaded ) { + section.container.find( '.no-themes' ).show(); + wp.a11y.speak( section.container.find( '.no-themes' ).text() ); + } else { + section.fullyLoaded = true; + } + } + if ( 'installed' === section.params.action ) { + section.updateCount(); // Count of visible theme controls. + } else { + section.updateCount( data.info.results ); // Total number of results including pages not yet loaded. + } + section.container.find( '.unexpected-error' ).hide(); // Hide error notice in case it was previously shown. + + // This cannot run on request.always, as section.loading may turn false before the new controls load in the success case. + section.headContainer.closest( '.wp-full-overlay' ).removeClass( 'loading' ); + section.loading = false; + }); + request.fail(function( data ) { + if ( 'undefined' === typeof data ) { + section.container.find( '.unexpected-error' ).show(); + wp.a11y.speak( section.container.find( '.unexpected-error' ).text() ); + } else if ( 'undefined' !== typeof console && console.error ) { + console.error( data ); + } + + // This cannot run on request.always, as section.loading may turn false before the new controls load in the success case. + section.headContainer.closest( '.wp-full-overlay' ).removeClass( 'loading' ); + section.loading = false; + }); + }, + + /** + * Determines whether more themes should be loaded, and loads them. + * + * @since 4.9.0 + * @returns {void} + */ + loadMore: function() { + var section = this, container, bottom, threshold; + if ( ! section.fullyLoaded && ! section.loading ) { + container = section.container.closest( '.customize-themes-full-container' ); + + bottom = container.scrollTop() + container.height(); + threshold = container.prop( 'scrollHeight' ) - 3000; // Use a fixed distance to the bottom of loaded results to avoid unnecessarily loading results sooner when using a percentage of scroll distance. + + if ( bottom > threshold ) { + section.loadControls(); + } + } + }, + + /** + * Event handler for search input that filters visible controls. + * + * @since 4.9.0 + * + * @param {Element} el - The search input element as a raw JS object. + * @returns {void} + */ + filterSearch: function( el ) { + var count = 0, + visible = false, + section = this, + noFilter = ( undefined !== api.section( 'wporg_themes' ) && 'wporg' !== section.params.action ) ? '.no-themes-local' : '.no-themes', + term = el.value.toLowerCase().trim().replace( '-', ' ' ), + controls = section.controls(), + renderScreenshots; + + if ( section.loading ) { + return; + } + + _.each( controls, function( control ) { + visible = control.filter( term ); + if ( visible ) { + count = count + 1; + } + }); + + if ( 0 === count ) { + section.container.find( noFilter ).show(); + wp.a11y.speak( section.container.find( noFilter ).text() ); + } else { + section.container.find( noFilter ).hide(); + } + + renderScreenshots = _.throttle( _.bind( section.renderScreenshots, this ), 100 ); + + renderScreenshots(); + + // Update theme count. + section.updateCount( count ); + }, + + /** + * Event handler for search input that determines if the terms have changed and loads new controls as needed. + * + * @since 4.9.0 + * + * @param {wp.customize.ThemesSection} section - The current theme section, passed through the debouncer. + * @returns {void} + */ + checkTerm: function( section ) { + var newTerm; + if ( 'wporg' === section.params.action ) { + newTerm = $( '#wp-filter-search-input' ).val(); + if ( section.term !== newTerm ) { + section.initializeNewQuery( newTerm, section.tags ); + } + } + }, + + /** + * Check for filters checked in the feature filter list and initialize a new query. + * + * @since 4.9.0 + * + * @returns {void} + */ + filtersChecked: function() { + var section = this, + items = section.container.find( '.filter-group' ).find( ':checkbox' ), + tags = []; + + _.each( items.filter( ':checked' ), function( item ) { + tags.push( $( item ).prop( 'value' ) ); + }); + + // When no filters are checked, restore initial state. Update filter count. + if ( 0 === tags.length ) { + tags = ''; + section.contentContainer.find( '.feature-filter-toggle .filter-count-0' ).show(); + section.contentContainer.find( '.feature-filter-toggle .filter-count-filters' ).hide(); + } else { + section.contentContainer.find( '.feature-filter-toggle .theme-filter-count' ).text( tags.length ); + section.contentContainer.find( '.feature-filter-toggle .filter-count-0' ).hide(); + section.contentContainer.find( '.feature-filter-toggle .filter-count-filters' ).show(); + } + + // Check whether tags have changed, and either load or queue them. + if ( ! _.isEqual( section.tags, tags ) ) { + if ( section.loading ) { + section.nextTags = tags; + } else { + section.initializeNewQuery( section.term, tags ); + } + } + }, + + /** + * Reset the current query and load new results. + * + * @since 4.9.0 + * + * @param {string} newTerm - New term. + * @param {Array} newTags - New tags. + * @returns {void} + */ + initializeNewQuery: function( newTerm, newTags ) { + var section = this; + + // Clear the controls in the section. + _.each( section.controls(), function( control ) { + control.container.remove(); + api.control.remove( control.id ); + }); + section.loaded = 0; + section.fullyLoaded = false; + section.screenshotQueue = null; + + // Run a new query, with loadControls handling paging, etc. + if ( ! section.loading ) { + section.term = newTerm; + section.tags = newTags; + section.loadControls(); + } else { + section.nextTerm = newTerm; // This will reload from loadControls() with the newest term once the current batch is loaded. + section.nextTags = newTags; // This will reload from loadControls() with the newest tags once the current batch is loaded. + } + if ( ! section.expanded() ) { + section.expand(); // Expand the section if it isn't expanded. } }, @@ -1633,16 +2031,22 @@ * Render control's screenshot if the control comes into view. * * @since 4.2.0 + * + * @returns {void} */ - renderScreenshots: function( ) { + renderScreenshots: function() { var section = this; - // Fill queue initially. - if ( section.screenshotQueue === null ) { - section.screenshotQueue = section.controls(); + // Fill queue initially, or check for more if empty. + if ( null === section.screenshotQueue || 0 === section.screenshotQueue.length ) { + + // Add controls that haven't had their screenshots rendered. + section.screenshotQueue = _.filter( section.controls(), function( control ) { + return ! control.screenshotRendered; + }); } - // Are all screenshots rendered? + // Are all screenshots rendered (for now)? if ( ! section.screenshotQueue.length ) { return; } @@ -1677,10 +2081,53 @@ } ); }, + /** + * Get visible count. + * + * @since 4.9.0 + * + * @returns {int} Visible count. + */ + getVisibleCount: function() { + return this.contentContainer.find( 'li.customize-control:visible' ).length; + }, + + /** + * Update the number of themes in the section. + * + * @since 4.9.0 + * + * @returns {void} + */ + updateCount: function( count ) { + var section = this, countEl, displayed; + + if ( ! count && 0 !== count ) { + count = section.getVisibleCount(); + } + + displayed = section.contentContainer.find( '.themes-displayed' ); + countEl = section.contentContainer.find( '.theme-count' ); + + if ( 0 === count ) { + countEl.text( '0' ); + } else { + + // Animate the count change for emphasis. + displayed.fadeOut( 180, function() { + countEl.text( count ); + displayed.fadeIn( 180 ); + } ); + wp.a11y.speak( api.settings.l10n.announceThemeCount.replace( '%d', count ) ); + } + }, + /** * Advance the modal to the next theme. * * @since 4.2.0 + * + * @returns {void} */ nextTheme: function () { var section = this; @@ -1695,15 +2142,17 @@ * Get the next theme model. * * @since 4.2.0 + * + * @returns {object|boolean} Next theme. */ getNextTheme: function () { - var control, next; - control = api.control( 'theme_' + this.currentTheme ); + var section = this, control, next; + control = api.control( section.params.action + '_theme_' + this.currentTheme ); next = control.container.next( 'li.customize-control-theme' ); if ( ! next.length ) { return false; } - next = next[0].id.replace( 'customize-control-', '' ); + next = next[0].id.replace( 'customize-control-theme-' + section.params.action, section.params.action + '_theme' ); control = api.control( next ); return control.params.theme; @@ -1713,6 +2162,7 @@ * Advance the modal to the previous theme. * * @since 4.2.0 + * @returns {void} */ previousTheme: function () { var section = this; @@ -1727,15 +2177,16 @@ * Get the previous theme model. * * @since 4.2.0 + * @returns {object|boolean} Previous theme. */ getPreviousTheme: function () { - var control, previous; - control = api.control( 'theme_' + this.currentTheme ); + var section = this, control, previous; + control = api.control( section.params.action + '_theme_' + this.currentTheme ); previous = control.container.prev( 'li.customize-control-theme' ); if ( ! previous.length ) { return false; } - previous = previous[0].id.replace( 'customize-control-', '' ); + previous = previous[0].id.replace( 'customize-control-theme-' + section.params.action, section.params.action + '_theme' ); control = api.control( previous ); return control.params.theme; @@ -1745,6 +2196,8 @@ * Disable buttons when we're viewing the first or last theme. * * @since 4.2.0 + * + * @returns {void} */ updateLimits: function () { if ( ! this.getNextTheme() ) { @@ -1820,52 +2273,46 @@ * * @since 4.2.0 * - * @param {Object} theme + * @param {object} theme - Theme. + * @param {Function} [callback] - Callback once the details have been shown. + * @returns {void} */ showDetails: function ( theme, callback ) { - var section = this, link; - callback = callback || function(){}; + var section = this; section.currentTheme = theme.id; section.overlay.html( section.template( theme ) ) .fadeIn( 'fast' ) .focus(); - $( 'body' ).addClass( 'modal-open' ); + section.$body.addClass( 'modal-open' ); section.containFocus( section.overlay ); section.updateLimits(); - - link = section.overlay.find( '.inactive-theme > a' ); - - link.on( 'click', function( event ) { - event.preventDefault(); - - // Short-circuit if request is currently being made. - if ( link.hasClass( 'disabled' ) ) { - return; - } - link.addClass( 'disabled' ); - - section.loadThemePreview( theme.id ).fail( function() { - link.removeClass( 'disabled' ); - } ); - } ); - callback(); + wp.a11y.speak( api.settings.l10n.announceThemeDetails.replace( '%s', theme.name ) ); + if ( callback ) { + callback(); + } }, /** * Close the theme details modal. * * @since 4.2.0 + * + * @returns {void} */ closeDetails: function () { - $( 'body' ).removeClass( 'modal-open' ); - this.overlay.fadeOut( 'fast' ); - api.control( 'theme_' + this.currentTheme ).focus(); + var section = this; + section.$body.removeClass( 'modal-open' ); + section.overlay.fadeOut( 'fast' ); + api.control( section.params.action + '_theme_' + section.currentTheme ).container.find( '.theme' ).focus(); }, /** * Keep tab focus within the theme details modal. * * @since 4.2.0 + * + * @param {jQuery} el - Element to contain focus. + * @returns {void} */ containFocus: function( el ) { var tabbables; @@ -1918,7 +2365,7 @@ var section = this; section.containerParent = '#customize-outer-theme-controls'; section.containerPaneParent = '.customize-outer-pane-parent'; - return api.Section.prototype.initialize.apply( section, arguments ); + api.Section.prototype.initialize.apply( section, arguments ); }, /** @@ -1939,7 +2386,7 @@ content = section.contentContainer, backBtn = content.find( '.customize-section-back' ), sectionTitle = section.headContainer.find( '.accordion-section-title' ).first(), - body = $( 'body' ), + body = $( document.body ), expand, panel; body.toggleClass( 'outer-section-open', expanded ); @@ -2058,8 +2505,8 @@ } if ( ! panel.contentContainer.parent().is( panel.headContainer ) ) { container.append( panel.contentContainer ); - panel.renderContent(); } + panel.renderContent(); panel.deferred.embedded.resolve(); }, @@ -2131,7 +2578,7 @@ * * @since 4.1.0 * - * @returns {boolean} + * @returns {boolean} Whether contextually active. */ isContextuallyActive: function () { var panel = this, @@ -2146,7 +2593,7 @@ }, /** - * Update UI to reflect expanded state + * Update UI to reflect expanded state. * * @since 4.1.0 * @@ -2154,6 +2601,7 @@ * @param {Object} args * @param {Boolean} args.unchanged * @param {Function} args.completeCallback + * @returns {void} */ onChangeExpanded: function ( expanded, args ) { @@ -2264,6 +2712,334 @@ } }); + /** + * Class wp.customize.ThemesPanel. + * + * Custom section for themes that displays without the customize preview. + * + * @constructor + * @augments wp.customize.Panel + * @augments wp.customize.Container + */ + api.ThemesPanel = api.Panel.extend({ + + /** + * Initialize. + * + * @since 4.9.0 + * + * @param {string} id - The ID for the panel. + * @param {object} options - Options. + * @returns {void} + */ + initialize: function( id, options ) { + var panel = this; + panel.installingThemes = []; + api.Panel.prototype.initialize.call( panel, id, options ); + }, + + /** + * Attach events. + * + * @since 4.9.0 + * @returns {void} + */ + attachEvents: function() { + var panel = this; + + // Attach regular panel events. + api.Panel.prototype.attachEvents.apply( panel ); + + // Collapse panel to customize the current theme. + panel.contentContainer.on( 'click', '.customize-theme', function() { + panel.collapse(); + }); + + // Toggle between filtering and browsing themes on mobile. + panel.contentContainer.on( 'click', '.customize-themes-section-title, .customize-themes-mobile-back', function() { + $( '.wp-full-overlay' ).toggleClass( 'showing-themes' ); + }); + + // Install (and maybe preview) a theme. + panel.contentContainer.on( 'click', '.theme-install', function( event ) { + panel.installTheme( event ); + }); + + // Update a theme. Theme cards have the class, the details modal has the id. + panel.contentContainer.on( 'click', '.update-theme, #update-theme', function( event ) { + + // #update-theme is a link. + event.preventDefault(); + event.stopPropagation(); + + panel.updateTheme( event ); + }); + + // Delete a theme. + panel.contentContainer.on( 'click', '.delete-theme', function( event ) { + panel.deleteTheme( event ); + }); + + _.bindAll( panel, 'installTheme', 'updateTheme' ); + }, + + /** + * Update UI to reflect expanded state + * + * @since 4.9.0 + * + * @param {Boolean} expanded - Expanded state. + * @param {Object} args - Args. + * @param {Boolean} args.unchanged - Whether or not the state changed. + * @param {Function} args.completeCallback - Callback to execute when the animation completes. + * @returns {void} + */ + onChangeExpanded: function( expanded, args ) { + var panel = this, overlay; + + // Expand/collapse the panel normally. + api.Panel.prototype.onChangeExpanded.apply( this, [ expanded, args ] ); + + // Immediately call the complete callback if there were no changes + if ( args.unchanged ) { + if ( args.completeCallback ) { + args.completeCallback(); + } + return; + } + + overlay = panel.headContainer.closest( '.wp-full-overlay' ); + + if ( expanded ) { + overlay + .addClass( 'in-themes-panel' ) + .delay( 200 ).find( '.customize-themes-full-container' ).addClass( 'animate' ); + + // Automatically open the installed themes section (except on small screens). + if ( 600 < window.innerWidth ) { + api.section( 'installed_themes' ).expand(); + } + } else { + overlay + .removeClass( 'in-themes-panel' ) + .find( '.customize-themes-full-container' ).removeClass( 'animate' ); + } + }, + + /** + * Install a theme via wp.updates. + * + * @since 4.9.0 + * + * @returns {void} + */ + installTheme: function( event ) { + var panel = this, preview = false, slug = $( event.target ).data( 'slug' ); + + if ( _.contains( panel.installingThemes, slug ) ) { + return; // Theme is already being installed. + } + + wp.updates.maybeRequestFilesystemCredentials( event ); + + $( document ).one( 'wp-theme-install-success', function( event, response ) { + var theme = false, customizeId, themeControl; + if ( preview ) { + + panel.loadThemePreview( slug ).fail( function() { + $( '.wp-full-overlay' ).removeClass( 'customize-loading' ); + } ); + + } else { + api.control.each( function( control ) { + if ( 'theme' === control.params.type && control.params.theme.id === response.slug ) { + theme = control.params.theme; // Used below to add theme control. + control.rerenderAsInstalled( true ); + } + }); + + // Don't add the same theme more than once. + if ( ! theme || api.control.has( 'installed_theme_' + theme.id ) ) { + return; + } + + // Add theme control to installed section. + theme.type = 'installed'; + customizeId = 'installed_theme_' + theme.id; + themeControl = new api.controlConstructor.theme( customizeId, { + params: { + type: 'theme', + content: $( '
  • ' ).attr( 'id', 'customize-control-theme-installed_' + theme.id ).prop( 'outerHTML' ), + section: 'installed_themes', + active: true, + theme: theme, + priority: 0 // Add all newly-installed themes to the top. + }, + previewer: api.previewer + } ); + + api.control.add( customizeId, themeControl ); + api.control( customizeId ).container.trigger( 'render-screenshot' ); + + // Close the details modal if it's open to the installed theme. + api.section.each( function( section ) { + if ( 'themes' === section.params.type ) { + if ( theme.id === section.currentTheme ) { // Don't close the modal if the user has navigated elsewhere. + section.closeDetails(); + } + } + }); + } + } ); + + panel.installingThemes.push( $( event.target ).data( 'slug' ) ); // Note: we don't remove elements from installingThemes, since they shouldn't be installed again. + wp.updates.installTheme( { + slug: slug + } ); + + // Also preview the theme as the event is triggered on Install & Preview. + if ( $( event.target ).hasClass( 'preview' ) ) { + preview = true; + $( '.wp-full-overlay' ).addClass( 'customize-loading' ); + wp.a11y.speak( $( '#customize-themes-loading-container .customize-loading-text-installing-theme' ).text() ); + } + }, + + /** + * Load theme preview. + * + * @since 4.9.0 + * + * @param {string} themeId Theme ID. + * @returns {jQuery.promise} Promise. + */ + loadThemePreview: function( themeId ) { + var deferred = $.Deferred(), onceProcessingComplete, overlay, urlParser; + + urlParser = document.createElement( 'a' ); + urlParser.href = location.href; + urlParser.search = $.param( _.extend( + api.utils.parseQueryString( urlParser.search.substr( 1 ) ), + { + theme: themeId, + changeset_uuid: api.settings.changeset.uuid + } + ) ); + + // Update loading message. Everything else is handled by reloading the page. + $( '#customize-themes-loading-container span' ).hide(); + $( '#customize-themes-loading-container .customize-loading-text' ).css( 'display', 'block' ); + wp.a11y.speak( $( '#customize-themes-loading-container .customize-loading-text' ).text() ); + overlay = $( '.wp-full-overlay' ); + overlay.addClass( 'customize-loading' ); + + onceProcessingComplete = function() { + var request; + if ( api.state( 'processing' ).get() > 0 ) { + return; + } + + api.state( 'processing' ).unbind( onceProcessingComplete ); + + request = api.requestChangesetUpdate(); + request.done( function() { + deferred.resolve(); + $( window ).off( 'beforeunload.customize-confirm' ); + window.location.href = urlParser.href; + } ); + request.fail( function() { + overlay.removeClass( 'customize-loading' ); + deferred.reject(); + } ); + }; + + if ( 0 === api.state( 'processing' ).get() ) { + onceProcessingComplete(); + } else { + api.state( 'processing' ).bind( onceProcessingComplete ); + } + + return deferred.promise(); + }, + + /** + * Update a theme via wp.updates. + * + * @since 4.9.0 + * + * @param {jQuery.Event} event - Event. + * @returns {void} + */ + updateTheme: function( event ) { + wp.updates.maybeRequestFilesystemCredentials( event ); + + $( document ).one( 'wp-theme-update-success', function( e, response ) { + + // Rerender the control to reflect the update. + api.control.each( function( control ) { + if ( 'theme' === control.params.type && control.params.theme.id === response.slug ) { + control.params.theme.hasUpdate = false; + control.rerenderAsInstalled( true ); + } + }); + } ); + + wp.updates.updateTheme( { + slug: $( event.target ).closest( '.notice' ).data( 'slug' ) + } ); + }, + + /** + * Delete a theme via wp.updates. + * + * @since 4.9.0 + * + * @param {jQuery.Event} event - Event. + * @returns {void} + */ + deleteTheme: function( event ) { + var theme, section; + theme = $( event.target ).data( 'slug' ); + section = api.section( 'installed_themes' ); + + event.preventDefault(); + + // Confirmation dialog for deleting a theme. + if ( ! window.confirm( api.settings.l10n.confirmDeleteTheme ) ) { + return; + } + + wp.updates.maybeRequestFilesystemCredentials( event ); + + $( document ).one( 'wp-theme-delete-success', function() { + var control = api.control( 'installed_theme_' + theme ); + + // Remove theme control. + control.container.remove(); + api.control.remove( control.id ); + + // Update installed count. + section.loaded = section.loaded - 1; + section.updateCount(); + + // Rerender any other theme controls as uninstalled. + api.control.each( function( control ) { + if ( 'theme' === control.params.type && control.params.theme.id === theme ) { + control.rerenderAsInstalled( false ); + } + }); + } ); + + wp.updates.deleteTheme( { + slug: theme + } ); + + // Close modal and focus the section. + section.closeDetails(); + section.focus(); + } + }); + /** * A Customizer Control. * @@ -2613,7 +3389,7 @@ * @param {Boolean} active * @param {Object} args * @param {Number} args.duration - * @param {Callback} args.completeCallback + * @param {Function} args.completeCallback */ onChangeActive: function ( active, args ) { if ( args.unchanged ) { @@ -3785,31 +4561,7 @@ api.ThemeControl = api.Control.extend({ touchDrag: false, - isRendered: false, - - /** - * Defer rendering the theme control until the section is displayed. - * - * @since 4.2.0 - */ - renderContent: function () { - var control = this, - renderContentArgs = arguments; - - api.section( control.section(), function( section ) { - if ( section.expanded() ) { - api.Control.prototype.renderContent.apply( control, renderContentArgs ); - control.isRendered = true; - } else { - section.expanded.bind( function( expanded ) { - if ( expanded && ! control.isRendered ) { - api.Control.prototype.renderContent.apply( control, renderContentArgs ); - control.isRendered = true; - } - } ); - } - } ); - }, + screenshotRendered: false, /** * @since 4.2.0 @@ -3833,20 +4585,11 @@ } // Prevent the modal from showing when the user clicks the action button. - if ( $( event.target ).is( '.theme-actions .button' ) ) { - return; - } - - api.section( control.section() ).loadThemePreview( control.params.theme.id ); - }); - - control.container.on( 'click keydown', '.theme-actions .theme-details', function( event ) { - if ( api.utils.isKeydownButNotEnterEvent( event ) ) { + if ( $( event.target ).is( '.theme-actions .button, .update-theme' ) ) { return; } event.preventDefault(); // Keep this AFTER the key filter above - api.section( control.section() ).showDetails( control.params.theme ); }); @@ -3857,13 +4600,15 @@ if ( source ) { $screenshot.attr( 'src', source ); } + control.screenshotRendered = true; }); }, /** - * Show or hide the theme based on the presence of the term in the title, description, and author. + * Show or hide the theme based on the presence of the term in the title, description, tags, and author. * * @since 4.2.0 + * @returns {boolean} Whether a theme control was activated or not. */ filter: function( term ) { var control = this, @@ -3874,9 +4619,30 @@ haystack = haystack.toLowerCase().replace( '-', ' ' ); if ( -1 !== haystack.search( term ) ) { control.activate(); + return true; } else { control.deactivate(); + return false; } + }, + + /** + * Rerender the theme from its JS template with the installed type. + * + * @since 4.9.0 + * + * @returns {void} + */ + rerenderAsInstalled: function( installed ) { + var control = this, section; + if ( installed ) { + control.params.theme.type = 'installed'; + } else { + section = api.section( control.params.section ); + control.params.theme.type = section.params.action; + } + control.renderContent(); // Replaces existing content. + control.container.trigger( 'render-screenshot' ); } }); @@ -5280,7 +6046,9 @@ date_time: api.DateTimeControl, code_editor: api.CodeEditorControl }; - api.panelConstructor = {}; + api.panelConstructor = { + themes: api.ThemesPanel + }; api.sectionConstructor = { themes: api.ThemesSection, outer: api.OuterSection @@ -5399,6 +6167,10 @@ // Sort the sections within each panel api.panel.each( function ( panel ) { + if ( 'themes' === panel.id ) { + return; // Don't reflow theme sections, as doing so moves them after the themes container. + } + var sections = panel.sections(), sectionHeadContainers = _.pluck( sections, 'headContainer' ); rootNodes.push( panel ); @@ -6223,20 +6995,18 @@ history.replaceState( {}, document.title, urlParser.href ); }; - /** - * Deactivate themes section if changeset status is not auto-draft - */ - api.section( 'themes', function( section ) { + // Deactivate themes panel if changeset status is not auto-draft. + api.panel( 'themes', function( panel ) { var canActivate; canActivate = function() { return ! changesetStatus() || 'auto-draft' === changesetStatus(); }; - section.active.validate = canActivate; - section.active.set( canActivate() ); + panel.active.validate = canActivate; + panel.active.set( canActivate() ); changesetStatus.bind( function() { - section.active.set( canActivate() ); + panel.active.set( canActivate() ); } ); } ); @@ -6400,7 +7170,7 @@ }); // Keyboard shortcuts - esc to exit section/panel. - $( 'body' ).on( 'keydown', function( event ) { + body.on( 'keydown', function( event ) { var collapsedObject, expandedControls = [], expandedSections = [], expandedPanels = []; if ( 27 !== event.which ) { // Esc. @@ -6440,6 +7210,18 @@ // Collapse the most granular expanded object. collapsedObject = expandedControls[0] || expandedSections[0] || expandedPanels[0]; if ( collapsedObject ) { + if ( 'themes' === collapsedObject.params.type ) { + + // Themes panel or section. + if ( body.hasClass( 'modal-open' ) ) { + collapsedObject.closeDetails(); + } else { + + // If we're collapsing a section, collapse the panel also. + wp.customize.panel( 'themes' ).collapse(); + } + return; + } collapsedObject.collapse(); event.preventDefault(); } diff --git a/src/wp-admin/js/updates.js b/src/wp-admin/js/updates.js index fc457a6236..cf63c17e2b 100644 --- a/src/wp-admin/js/updates.js +++ b/src/wp-admin/js/updates.js @@ -183,7 +183,11 @@ if ( $notice.length ) { $notice.replaceWith( $adminNotice ); } else { - $( '.wrap' ).find( '> h1' ).after( $adminNotice ); + if ( 'customize' === pagenow ) { + $( '.customize-themes-notifications' ).append( $adminNotice ); + } else { + $( '.wrap' ).find( '> h1' ).after( $adminNotice ); + } } $document.trigger( 'wp-updates-notice-added' ); @@ -930,6 +934,17 @@ if ( 'themes-network' === pagenow ) { $notice = $( '[data-slug="' + args.slug + '"]' ).find( '.update-message' ).removeClass( 'notice-error' ).addClass( 'updating-message notice-warning' ).find( 'p' ); + } else if ( 'customize' === pagenow ) { + + // Update the theme details UI. + $notice = $( '#update-theme' ).closest( '.notice' ).removeClass( 'notice-large' ); + + $notice.find( 'h3' ).remove(); + + // Add the top-level UI, and update both. + $notice = $notice.add( $( '#customize-control-theme-installed_' + args.slug ).find( '.update-message' ) ); + $notice = $notice.addClass( 'updating-message' ).find( 'p' ); + } else { $notice = $( '#update-theme' ).closest( '.notice' ).removeClass( 'notice-large' ); @@ -972,6 +987,10 @@ }, $notice, newText; + if ( 'customize' === pagenow ) { + $theme = wp.customize.control( 'installed_theme_' + response.slug ).container; + } + if ( 'themes-network' === pagenow ) { $notice = $theme.find( '.update-message' ); @@ -1026,6 +1045,10 @@ return; } + if ( 'customize' === pagenow ) { + $theme = wp.customize.control( 'installed_theme_' + response.slug ).container; + } + if ( 'themes-network' === pagenow ) { $notice = $theme.find( '.update-message ' ); } else { @@ -1162,12 +1185,23 @@ return; } - if ( $document.find( 'body' ).hasClass( 'full-overlay-active' ) ) { - $button = $( '.theme-install[data-slug="' + response.slug + '"]' ); - $card = $( '.install-theme-info' ).prepend( $message ); + if ( 'customize' === pagenow ) { + if ( $document.find( 'body' ).hasClass( 'modal-open' ) ) { + $button = $( '.theme-install[data-slug="' + response.slug + '"]' ); + $card = $( '.theme-overlay .theme-info' ).prepend( $message ); + } else { + $button = $( '.theme-install[data-slug="' + response.slug + '"]' ); + $card = $button.closest( '.theme' ).addClass( 'theme-install-failed' ).append( $message ); + } + $( '.wp-full-overlay' ).removeClass( 'customize-loading' ); } else { - $card = $( '[data-slug="' + response.slug + '"]' ).removeClass( 'focus' ).addClass( 'theme-install-failed' ).append( $message ); - $button = $card.find( '.theme-install' ); + if ( $document.find( 'body' ).hasClass( 'full-overlay-active' ) ) { + $button = $( '.theme-install[data-slug="' + response.slug + '"]' ); + $card = $( '.install-theme-info' ).prepend( $message ); + } else { + $card = $( '[data-slug="' + response.slug + '"]' ).removeClass( 'focus' ).addClass( 'theme-install-failed' ).append( $message ); + $button = $card.find( '.theme-install' ); + } } $button diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php index a9f07e1f1b..95dfa794af 100644 --- a/src/wp-includes/class-wp-customize-manager.php +++ b/src/wp-includes/class-wp-customize-manager.php @@ -320,6 +320,7 @@ final class WP_Customize_Manager { require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menus-panel.php' ); + require_once( ABSPATH . WPINC . '/customize/class-wp-customize-themes-panel.php' ); require_once( ABSPATH . WPINC . '/customize/class-wp-customize-themes-section.php' ); require_once( ABSPATH . WPINC . '/customize/class-wp-customize-sidebar-section.php' ); require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-section.php' ); @@ -375,6 +376,7 @@ final class WP_Customize_Manager { add_action( 'wp_ajax_customize_save', array( $this, 'save' ) ); add_action( 'wp_ajax_customize_refresh_nonces', array( $this, 'refresh_nonces' ) ); + add_action( 'wp_ajax_customize-load-themes', array( $this, 'load_themes_ajax' ) ); add_action( 'wp_ajax_dismiss_customize_changeset_autosave', array( $this, 'handle_dismiss_changeset_autosave_request' ) ); add_action( 'customize_register', array( $this, 'register_controls' ) ); @@ -392,6 +394,12 @@ final class WP_Customize_Manager { // Export the settings to JS via the _wpCustomizeSettings variable. add_action( 'customize_controls_print_footer_scripts', array( $this, 'customize_pane_settings' ), 1000 ); + + // Add theme update notices. + if ( current_user_can( 'install_themes' ) || current_user_can( 'update_themes' ) ) { + require_once ABSPATH . '/wp-admin/includes/update.php'; + add_action( 'customize_controls_print_footer_scripts', 'wp_print_admin_notice_templates' ); + } } /** @@ -3685,6 +3693,10 @@ final class WP_Customize_Manager { foreach ( $this->controls as $control ) { $control->enqueue(); } + + if ( ! is_multisite() && ( current_user_can( 'install_themes' ) || current_user_can( 'update_themes' ) || current_user_can( 'delete_themes' ) ) ) { + wp_enqueue_script( 'updates' ); + } } /** @@ -3889,6 +3901,7 @@ final class WP_Customize_Manager { $nonces = array( 'save' => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ), 'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() ), + 'switch-themes' => wp_create_nonce( 'switch-themes' ), 'dismiss_autosave' => wp_create_nonce( 'dismiss_customize_changeset_autosave' ), ); @@ -3995,6 +4008,15 @@ final class WP_Customize_Manager { 'autofocus' => $this->get_autofocus(), 'documentTitleTmpl' => $this->get_document_title_template(), 'previewableDevices' => $this->get_previewable_devices(), + 'l10n' => array( + 'confirmDeleteTheme' => __( 'Are you sure you want to delete this theme?' ), + /* translators: %d is the number of theme search results, which cannot currently consider singular vs. plural forms */ + 'themeSearchResults' => __( '%d themes found' ), + /* translators: %d is the number of themes being displayed, which cannot currently consider singular vs. plural forms */ + 'announceThemeCount' => __( 'Displaying %d themes' ), + /* translators: %s is the theme name */ + 'announceThemeDetails' => __( 'Showing details for theme: %s' ), + ), ); // Prepare Customize Section objects to pass to JavaScript. @@ -4098,8 +4120,10 @@ final class WP_Customize_Manager { /* Panel, Section, and Control Types */ $this->register_panel_type( 'WP_Customize_Panel' ); + $this->register_panel_type( 'WP_Customize_Themes_Panel' ); $this->register_section_type( 'WP_Customize_Section' ); $this->register_section_type( 'WP_Customize_Sidebar_Section' ); + $this->register_section_type( 'WP_Customize_Themes_Section' ); $this->register_control_type( 'WP_Customize_Color_Control' ); $this->register_control_type( 'WP_Customize_Media_Control' ); $this->register_control_type( 'WP_Customize_Upload_Control' ); @@ -4159,50 +4183,38 @@ final class WP_Customize_Manager { 'default_value' => $initial_date, ) ) ); - /* Themes */ + /* Themes (controls are loaded via ajax) */ - $this->add_section( new WP_Customize_Themes_Section( $this, 'themes', array( - 'title' => $this->theme()->display( 'Name' ), - 'capability' => 'switch_themes', - 'priority' => 0, + $this->add_panel( new WP_Customize_Themes_Panel( $this, 'themes', array( + 'title' => $this->theme()->display( 'Name' ), + 'description' => __( 'Once themes are installed, you can live-preview them on your site, customize them, and publish your new design. Browse available themes via the filters in this menu.' ), + 'capability' => 'switch_themes', + 'priority' => 0, ) ) ); + $this->add_section( new WP_Customize_Themes_Section( $this, 'installed_themes', array( + 'title' => __( 'Installed themes' ), + 'action' => 'installed', + 'capability' => 'switch_themes', + 'panel' => 'themes', + 'priority' => 0, + ) ) ); + + if ( ! is_multisite() ) { + $this->add_section( new WP_Customize_Themes_Section( $this, 'wporg_themes', array( + 'title' => __( 'WordPress.org themes' ), + 'action' => 'wporg', + 'capability' => 'install_themes', + 'panel' => 'themes', + 'priority' => 5, + ) ) ); + } + // Themes Setting (unused - the theme is considerably more fundamental to the Customizer experience). $this->add_setting( new WP_Customize_Filter_Setting( $this, 'active_theme', array( 'capability' => 'switch_themes', ) ) ); - require_once( ABSPATH . 'wp-admin/includes/theme.php' ); - - // Theme Controls. - - // Add a control for the active/original theme. - if ( ! $this->is_theme_active() ) { - $themes = wp_prepare_themes_for_js( array( wp_get_theme( $this->original_stylesheet ) ) ); - $active_theme = current( $themes ); - $active_theme['isActiveTheme'] = true; - $this->add_control( new WP_Customize_Theme_Control( $this, $active_theme['id'], array( - 'theme' => $active_theme, - 'section' => 'themes', - 'settings' => 'active_theme', - ) ) ); - } - - $themes = wp_prepare_themes_for_js(); - foreach ( $themes as $theme ) { - if ( $theme['active'] || $theme['id'] === $this->original_stylesheet ) { - continue; - } - - $theme_id = 'theme_' . $theme['id']; - $theme['isActiveTheme'] = false; - $this->add_control( new WP_Customize_Theme_Control( $this, $theme_id, array( - 'theme' => $theme, - 'section' => 'themes', - 'settings' => 'active_theme', - ) ) ); - } - /* Site Identity */ $this->add_section( 'title_tagline', array( @@ -4706,6 +4718,141 @@ final class WP_Customize_Manager { $this->add_dynamic_settings( $setting_ids ); } + /** + * Load themes into the theme browsing/installation UI. + * + * @since 4.9.0 + */ + public function load_themes_ajax() { + check_ajax_referer( 'switch-themes', 'switch-themes-nonce' ); + + if ( ! current_user_can( 'switch_themes' ) ) { + wp_die( -1 ); + } + + if ( empty( $_POST['theme_action'] ) ) { + wp_send_json_error( 'missing_theme_action' ); + } + $theme_action = sanitize_key( $_POST['theme_action'] ); + $themes = array(); + + require_once ABSPATH . 'wp-admin/includes/theme.php'; + if ( 'installed' === $theme_action ) { + $themes = array( 'themes' => wp_prepare_themes_for_js() ); + foreach ( $themes['themes'] as &$theme ) { + $theme['type'] = 'installed'; + $theme['active'] = ( isset( $_POST['customized_theme'] ) && $_POST['customized_theme'] === $theme['id'] ); + } + } elseif ( 'wporg' === $theme_action ) { + if ( ! current_user_can( 'install_themes' ) ) { + wp_die( -1 ); + } + + // Arguments for all queries. + $args = array( + 'per_page' => 100, + 'page' => isset( $_POST['page'] ) ? absint( $_POST['page'] ) : 1, + 'fields' => array( + 'screenshot_url' => true, + 'description' => true, + 'rating' => true, + 'downloaded' => true, + 'downloadlink' => true, + 'last_updated' => true, + 'homepage' => true, + 'num_ratings' => true, + 'tags' => true, + 'parent' => true, + // 'extended_author' => true, @todo: WordPress.org throws a 500 server error when this is here. + ), + ); + + // Define query filters based on user input. + if ( ! array_key_exists( 'search', $_POST ) ) { + $args['search'] = ''; + } else { + $args['search'] = sanitize_text_field( wp_unslash( $_POST['search'] ) ); + } + + if ( ! array_key_exists( 'tags', $_POST ) ) { + $args['tag'] = ''; + } else { + $args['tag'] = array_map( 'sanitize_text_field', wp_unslash( (array) $_POST['tags'] ) ); + } + + if ( '' === $args['search'] && '' === $args['tag'] ) { + $args['browse'] = 'new'; // Sort by latest themes by default. + } + + // Load themes from the .org API. + $themes = themes_api( 'query_themes', $args ); + if ( is_wp_error( $themes ) ) { + wp_send_json_error(); + } + + // This list matches the allowed tags in wp-admin/includes/theme-install.php. + $themes_allowedtags = array_fill_keys( + array( 'a', 'abbr', 'acronym', 'code', 'pre', 'em', 'strong', 'div', 'p', 'ul', 'ol', 'li', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'img' ), + array() + ); + $themes_allowedtags['a'] = array_fill_keys( array( 'href', 'title', 'target' ), true ); + $themes_allowedtags['acronym']['title'] = true; + $themes_allowedtags['abbr']['title'] = true; + $themes_allowedtags['img'] = array_fill_keys( array( 'src', 'class', 'alt' ), true ); + + // Prepare a list of installed themes to check against before the loop. + $installed_themes = array(); + $wp_themes = wp_get_themes(); + foreach ( $wp_themes as $theme ) { + $installed_themes[] = $theme->get_stylesheet(); + } + $update_php = network_admin_url( 'update.php?action=install-theme' ); + + // Set up properties for themes available on WordPress.org. + foreach ( $themes->themes as &$theme ) { + $theme->install_url = add_query_arg( array( + 'theme' => $theme->slug, + '_wpnonce' => wp_create_nonce( 'install-theme_' . $theme->slug ), + ), $update_php ); + + $theme->name = wp_kses( $theme->name, $themes_allowedtags ); + $theme->author = wp_kses( $theme->author, $themes_allowedtags ); + $theme->version = wp_kses( $theme->version, $themes_allowedtags ); + $theme->description = wp_kses( $theme->description, $themes_allowedtags ); + $theme->tags = implode( ', ', $theme->tags ); + $theme->stars = wp_star_rating( array( + 'rating' => $theme->rating, + 'type' => 'percent', + 'number' => $theme->num_ratings, + 'echo' => false, + ) ); + $theme->num_ratings = number_format_i18n( $theme->num_ratings ); + $theme->preview_url = set_url_scheme( $theme->preview_url ); + + // Handle themes that are already installed as installed themes. + if ( in_array( $theme->slug, $installed_themes, true ) ) { + $theme->type = 'installed'; + } else { + $theme->type = $theme_action; + } + + // Set active based on customized theme. + $theme->active = ( isset( $_POST['customized_theme'] ) && $_POST['customized_theme'] === $theme->slug ); + + // Map available theme properties to installed theme properties. + $theme->id = $theme->slug; + $theme->screenshot = array( $theme->screenshot_url ); + $theme->authorAndUri = $theme->author; + $theme->parent = ( $theme->slug === $theme->template ) ? false : $theme->template; // The .org API does not seem to return the parent in a documented way; however, this check should yield a similar result in most cases. + unset( $theme->slug ); + unset( $theme->screenshot_url ); + unset( $theme->author ); + } // End foreach(). + } // End if(). + wp_send_json_success( $themes ); + } + + /** * Callback for validating the header_textcolor value. * diff --git a/src/wp-includes/css/admin-bar.css b/src/wp-includes/css/admin-bar.css index 7d031f489e..31241de502 100644 --- a/src/wp-includes/css/admin-bar.css +++ b/src/wp-includes/css/admin-bar.css @@ -693,6 +693,7 @@ html:lang(he-il) .rtl #wpadminbar * { #wpadminbar .screen-reader-text span { border: 0; clip: rect(1px, 1px, 1px, 1px); + -webkit-clip-path: inset(50%); clip-path: inset(50%); height: 1px; margin: -1px; diff --git a/src/wp-includes/css/wp-embed-template.css b/src/wp-includes/css/wp-embed-template.css index bd3edb2021..b1fd593e74 100644 --- a/src/wp-includes/css/wp-embed-template.css +++ b/src/wp-includes/css/wp-embed-template.css @@ -11,6 +11,7 @@ body { .screen-reader-text { border: 0; clip: rect(1px, 1px, 1px, 1px); + -webkit-clip-path: inset(50%); clip-path: inset(50%); height: 1px; margin: -1px; diff --git a/src/wp-includes/customize/class-wp-customize-theme-control.php b/src/wp-includes/customize/class-wp-customize-theme-control.php index ffc9c878ae..2d1cbdbcf2 100644 --- a/src/wp-includes/customize/class-wp-customize-theme-control.php +++ b/src/wp-includes/customize/class-wp-customize-theme-control.php @@ -57,18 +57,22 @@ class WP_Customize_Theme_Control extends WP_Customize_Control { * @since 4.2.0 */ public function content_template() { - $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); - $active_url = esc_url( remove_query_arg( 'customize_theme', $current_url ) ); - $preview_url = esc_url( add_query_arg( 'customize_theme', '__THEME__', $current_url ) ); // Token because esc_url() strips curly braces. - $preview_url = str_replace( '__THEME__', '{{ data.theme.id }}', $preview_url ); + /* translators: %s: theme name */ + $details_label = sprintf( __( 'Details for theme: %s' ), '{{ data.theme.name }}' ); + /* translators: %s: theme name */ + $customize_label = sprintf( __( 'Customize theme: %s' ), '{{ data.theme.name }}' ); + /* translators: %s: theme name */ + $preview_label = sprintf( __( 'Live preview theme: %s' ), '{{ data.theme.name }}' ); + /* translators: %s: theme name */ + $install_label = sprintf( __( 'Install and preview theme: %s' ), '{{ data.theme.name }}' ); ?> - <# if ( data.theme.isActiveTheme ) { #> -
    + <# if ( data.theme.active ) { #> +
    <# } else { #> -
    +
    <# } #> - <# if ( data.theme.screenshot[0] ) { #> + <# if ( data.theme.screenshot && data.theme.screenshot[0] ) { #>
    @@ -76,28 +80,45 @@ class WP_Customize_Theme_Control extends WP_Customize_Control {
    <# } #> - <# if ( data.theme.isActiveTheme ) { #> - - <# } else { #> - - <# } #> +
    - <# if ( data.theme.isActiveTheme ) { #> -

    + <# if ( 'installed' === data.theme.type && data.theme.hasUpdate ) { #> +
    +

    + ' . __( 'Update now' ) . '' ); + ?> +

    +
    + <# } #> + + <# if ( data.theme.active ) { #> +

    Active: %s' ), '{{{ data.theme.name }}}' ); + printf( __( 'Previewing: %s' ), '{{ data.theme.name }}' ); ?>

    - <# } else { #> -

    {{{ data.theme.name }}}

    - + +
    +

    + <# } else if ( 'installed' === data.theme.type ) { #> +

    {{ data.theme.name }}

    +
    +
    +

    + <# } else { #> +

    {{ data.theme.name }}

    +
    +
    <# } #>
    diff --git a/src/wp-includes/customize/class-wp-customize-themes-panel.php b/src/wp-includes/customize/class-wp-customize-themes-panel.php new file mode 100644 index 0000000000..8cd8e8dd88 --- /dev/null +++ b/src/wp-includes/customize/class-wp-customize-themes-panel.php @@ -0,0 +1,103 @@ + +
  • +

    + manager->is_theme_active() ) { + echo '' . __( 'Active theme' ) . ' {{ data.title }}'; + } else { + echo '' . __( 'Previewing theme' ) . ' {{ data.title }}'; + } + ?> + + + + +

    +
      +
    • + +
    • + +
      + + ' . __( 'Themes' ) . '' ); // Separate strings for consistency with other panels. + ?> + + + <# if ( data.description ) { #> + + <# } #> + +
      + + <# if ( data.description ) { #> +
      + {{{ data.description }}} +
      + <# } #> + +
    • +
    • + + +
    • +
    • +
        +
      • +
      +
    • + type; + public $action = ''; + + /** + * Get section parameters for JS. + * + * @since 4.9.0 + * @return array Exported parameters. + */ + public function json() { + $exported = parent::json(); + $exported['action'] = $this->action; + + return $exported; + } + + /** + * Render a themes section as a JS template. + * + * The template is only rendered by PHP once, so all actions are prepared at once on the server side. + * + * @since 4.9.0 + */ + protected function render_template() { ?> -
    • -

      - manager->is_theme_active() ) { - echo '' . __( 'Active theme' ) . ' ' . $this->title; - } else { - echo '' . __( 'Previewing theme' ) . ' ' . $this->title; - } - ?> - - controls ) > 0 ) : ?> - - -

      -
      -

      - - - - controls ) + 1 /* Active theme */; ?> -

      -

      - manager->is_theme_active() ) { - echo '' . __( 'Active theme' ) . ' ' . $this->title; - } else { - echo '' . __( 'Previewing theme' ) . ' ' . $this->title; - } - ?> - -

      - +
    • + + + +
      - -
      - controls ) > 4 ) : ?> -

      -
      -
        +
        + filter_bar_content_template(); ?> +
        + +
        +

        +

        + %s', __( 'Search WordPress.org themes' ) ) + ); + ?> +

        +

    • - + + <# if ( 'wporg' === data.action ) { #> +
      + + + +
      + +
      + $features ) { + echo '
      '; + echo '' . esc_html( $feature_name ) . ''; + echo '
      '; + foreach ( $features as $feature => $feature_name ) { + echo ' '; + echo '
      '; + } + echo '
      '; + echo '
      '; + } + ?> +
      + <# } else { #> +

      + +

      + <# } #> +
      + + 0' ); + ?> + +
      + assertNotEmpty( $data ); - $this->assertEqualSets( array( 'theme', 'url', 'browser', 'panels', 'sections', 'nonce', 'autofocus', 'documentTitleTmpl', 'previewableDevices', 'changeset', 'timeouts', 'initialClientTimestamp', 'initialServerDate', 'initialServerTimestamp' ), array_keys( $data ) ); + $this->assertEqualSets( array( 'theme', 'url', 'browser', 'panels', 'sections', 'nonce', 'autofocus', 'documentTitleTmpl', 'previewableDevices', 'changeset', 'timeouts', 'initialClientTimestamp', 'initialServerDate', 'initialServerTimestamp', 'l10n' ), array_keys( $data ) ); $this->assertEquals( $autofocus, $data['autofocus'] ); $this->assertArrayHasKey( 'save', $data['nonce'] ); $this->assertArrayHasKey( 'preview', $data['nonce'] );