Make WordPress Core

Ticket #37661: 37661.4.diff

File 37661.4.diff, 82.1 KB (added by celloexpressions, 8 years ago)

Refresh for [38648]. Please report any bugs with the panel and sections properly opening/closing if they come up.

  • src/wp-admin/css/customize-controls.css

     
    271271}
    272272
    273273#customize-theme-controls .customize-pane-child.open,
    274 #customize-theme-controls .customize-pane-child.current-panel,
    275 #customize-theme-controls .customize-themes-panel.customize-pane-child.current-panel {
     274#customize-theme-controls .customize-pane-child.current-panel {
    276275        -webkit-transform: none;
    277276        -ms-transform: none;
    278277        transform: none;
    279278}
    280279
    281 #customize-theme-controls .customize-themes-panel.customize-pane-child,
    282280.section-open #customize-theme-controls .customize-pane-parent,
    283281.in-sub-panel #customize-theme-controls .customize-pane-parent,
    284282.section-open #customize-info,
    285283.in-sub-panel #customize-info,
    286 .in-sub-panel.section-open #customize-theme-controls .customize-pane-child.current-panel,
    287 .in-themes-panel #customize-theme-controls .customize-pane-parent,
    288 .in-themes-panel #customize-info {
     284.in-sub-panel.section-open #customize-theme-controls .customize-pane-child.current-panel {
    289285        visibility: hidden;
    290286        height: 0;
    291287        overflow: hidden;
     
    296292
    297293.section-open #customize-theme-controls .customize-pane-parent.busy,
    298294.in-sub-panel #customize-theme-controls .customize-pane-parent.busy,
    299 .in-themes-panel #customize-theme-controls .customize-pane-parent.busy,
    300295.section-open #customize-info.busy,
    301296.in-sub-panel #customize-info.busy,
    302 .in-themes-panel #customize-info.busy,
    303297.busy.section-open.in-sub-panel #customize-theme-controls .customize-pane-child.current-panel,
    304298#customize-theme-controls .customize-pane-child.open,
    305299#customize-theme-controls .customize-pane-child.current-panel,
     
    309303        overflow: auto;
    310304}
    311305
    312 .in-themes-panel #customize-theme-controls .customize-pane-parent,
    313 .in-themes-panel #customize-info {
    314         -webkit-transform: translateX(100%);
    315         -ms-transform: translateX(100%);
    316         transform: translateX(100%);
    317 }
    318 
    319306#customize-theme-controls .customize-pane-child.accordion-section-content,
    320307#customize-theme-controls .customize-pane-child.accordion-sub-container {
    321308        display: block;
     
    996983        animation: customize-reload .75s;
    997984}
    998985
    999 #customize-theme-controls .control-section-themes .accordion-section-title:hover, /* Not a focusable element. */
    1000 #customize-theme-controls .control-section-themes .accordion-section-title {
     986#customize-theme-controls .control-panel-themes {
     987        border-bottom: none;
     988}
     989
     990#customize-theme-controls .control-panel-themes > .accordion-section-title:hover, /* Not a focusable element. */
     991#customize-theme-controls .control-panel-themes > .accordion-section-title {
    1001992        cursor: default;
    1002993        background: #fff;
    1003994        color: #555;
     
    1004995        border-top: 1px solid #ddd;
    1005996        border-bottom: 1px solid #ddd;
    1006997        border-left: none;
    1007         margin-top: 0;
     998        border-right: none;
     999        margin: 0 0 15px 0;
     1000        padding-right: 100px; /* Space for the button */
    10081001}
    10091002
    10101003#customize-theme-controls .control-section-themes .customize-themes-panel .accordion-section-title:first-child:hover, /* Not a focusable element. */
     
    10121005        border-top: 0;
    10131006}
    10141007
    1015 #customize-theme-controls .control-section-themes > .accordion-section-title:hover, /* Not a focusable element. */
    1016 #customize-theme-controls .control-section-themes > .accordion-section-title {
    1017         margin: 0 0 15px;
    1018 }
    1019 
    1020 #customize-controls .customize-themes-panel .accordion-section-title {
    1021         margin: 15px -8px;
    1022 }
    1023 
    1024 #customize-controls .control-section-themes .accordion-section-title,
    1025 #customize-controls .customize-themes-panel .accordion-section-title {
    1026         padding-right: 100px; /* Space for the button */
    1027 }
    1028 
    1029 #customize-controls .control-section-themes .accordion-section-title span.customize-action,
     1008.control-panel-themes .accordion-section-title span.customize-action,
    10301009#customize-controls .customize-section-title span.customize-action {
    10311010        font-size: 13px;
    10321011        display: block;
     
    10331012        font-weight: 400;
    10341013}
    10351014
    1036 #customize-controls .control-section-themes .accordion-section-title .change-theme,
    1037 #customize-controls .customize-themes-panel .accordion-section-title .customize-theme {
     1015.control-panel-themes .accordion-section-title .change-theme {
    10381016        position: absolute;
    10391017        right: 10px;
    10401018        top: 50%;
     
    10421020        font-weight: 400;
    10431021}
    10441022
    1045 #customize-controls .control-section-themes .accordion-section-title:before {
     1023#customize-theme-controls .control-panel-themes > .accordion-section-title:after {
    10461024        display: none;
    10471025}
    10481026
    1049 #customize-controls .customize-themes-panel {
    1050         padding: 0 8px;
    1051         background: #f1f1f1;
    1052         -webkit-box-sizing: border-box;
    1053         -moz-box-sizing: border-box;
    1054         box-sizing: border-box;
     1027.control-panel-themes .control-panel-content {
     1028        display: none;
     1029        position: fixed;
     1030        width: 100%;
     1031        height: 100%;
     1032        top: 0;
     1033        left: -100%;
     1034        background: #eee;
     1035        z-index: 10;
     1036        transition: .2s left ease-in-out;
     1037        margin: 0;
     1038        padding: 0;
     1039        overflow-y: auto;
    10551040}
    10561041
    1057 #customize-controls .customize-themes-panel .accordion-section-title:first-child {
    1058         margin-top: 0;
     1042.in-themes-panel .control-panel-themes .control-panel-content {
     1043        left: 0;
    10591044}
    10601045
    1061 #customize-controls .customize-themes-panel .accordion-section-title:nth-child(2) {
    1062         font-size: 14px;
    1063         font-weight: 600;
     1046#customize-controls,
     1047#customize-footer-actions,
     1048#customize-footer-actions .collapse-sidebar {
     1049        left: 0;
     1050        transition: .2s left ease-in-out;
    10641051}
    10651052
    1066 #customize-controls .customize-themes-panel > h2 {
     1053.in-themes-panel #customize-controls,
     1054.in-themes-panel #customize-preview,
     1055.in-themes-panel #customize-footer-actions,
     1056.in-themes-panel #customize-footer-actions .collapse-sidebar {
     1057        left: 100%;
     1058}
     1059
     1060.customize-themes-panel > h2 {
    10671061        padding: 15px 8px 0 8px;
    10681062}
    10691063
    1070 #customize-theme-controls .customize-themes-panel .accordion-section-content {
     1064.control-panel-themes .panel-meta .current-theme {
     1065        position: absolute;
     1066        right: 0;
     1067        top: 0;
     1068        background: #fff;
     1069        border-left: 1px solid #ddd;
     1070        padding: 15px 125px 15px 25px;
     1071}
     1072
     1073.control-panel-themes .panel-meta .customize-theme {
     1074        position: absolute;
     1075        bottom: 15px;
     1076        right: 25px;
     1077}
     1078
     1079.control-panel-themes .panel-meta h2 {
     1080        font-size: 32px;
     1081        font-weight: 200;
     1082        margin: 0 25px;
     1083        padding: 15px 0;
     1084        line-height: 50px;
     1085        float: left;
     1086}
     1087
     1088.control-panel-themes .panel-meta {
     1089        min-height: 80px;
     1090        overflow: hidden;
     1091}
     1092
     1093.control-panel-themes .panel-meta .page-title-action {
     1094        margin-top: 28px;
     1095}
     1096
     1097/* Mobile header */
     1098@media screen and (max-width:700px) {
     1099        .control-panel-themes .panel-meta .current-theme {
     1100                width: calc(100% - 150px);
     1101                position: relative;
     1102                border-bottom: 1px solid #ddd;
     1103        }
     1104}
     1105
     1106.control-panel-themes .customize-themes-notifications .notice {
     1107        margin: 0 25px 15px 25px;
     1108}
     1109
     1110#customize-theme-section-navigation {
     1111        margin: 0 25px 15px 25px;
     1112        width: calc(100% - 50px);
     1113}
     1114
     1115#customize-theme-section-navigation .filter-links .customize-themes-section-title:only-child {
     1116        display: none; /* Don't show the heading if there is only one section (presumably installed themes). */
     1117}
     1118
     1119.control-panel-themes .filter-count {
     1120        padding: 12px 0;
     1121}
     1122
     1123#customize-theme-section-navigation .themes-filter-container {
     1124        display: inline-block;
     1125}
     1126
     1127.control-panel-themes .wp-filter .customize-help-toggle {
     1128        float: right;
     1129        padding: 10px;
     1130        height: 40px;
     1131        width: 40px;
     1132        margin: 5px;
    10711133        background: transparent;
    1072         display: block;
     1134        border: none;
     1135        box-shadow: none;
     1136        cursor: pointer;
     1137        color: #555;
    10731138}
    10741139
    1075 .customize-control.customize-control-theme {
    1076         margin-bottom: 8px;
     1140.control-panel-themes .wp-filter .customize-help-toggle:hover {
     1141        color: #0073aa;
    10771142}
    10781143
     1144.control-panel-themes .wp-filter .customize-help-toggle:focus,
     1145.control-panel-themes .wp-filter .customize-help-toggle.toggled {
     1146        color: #0073aa;
     1147        border-radius: 100%;
     1148        box-shadow: 0 0 0 1px #5b9dd9,
     1149                    0 0 2px 1px rgba(30, 140, 190, .8);
     1150        outline: 0;
     1151}
     1152
     1153.control-panel-themes .customize-panel-description {
     1154        position: absolute;
     1155        right: -1px;
     1156        top: 54px;
     1157        z-index: 5;
     1158        background: #fff;
     1159        font-size: 14px;
     1160        width: 300px;
     1161        max-width: calc(100% - 35px);
     1162        border: 1px solid #ddd;
     1163        border-top: none;
     1164        padding: 5px 25px 15px 10px;
     1165        text-align: right;
     1166        display: none;
     1167}
     1168
     1169.control-panel-themes .theme-section {
     1170        width: calc(100% - 50px);
     1171        padding: 0 25px 25px 25px;
     1172        margin: 0;
     1173        display: none !important; /* There is unknown JS that perpetually tries to show all theme sections when more items are added. */
     1174        overflow: hidden;
     1175}
     1176
     1177.control-panel-themes .theme-section.current-section {
     1178        display: list-item !important; /* There is unknown JS that perpetually tries to show all theme sections when more items are added. */
     1179}
     1180
     1181#customize-theme-section-navigation .customize-themes-section-title {
     1182        display: inline-block;
     1183        margin: 0 10px;
     1184        padding: 15px 0;
     1185        background: #fff;
     1186        border: 0;
     1187        border-bottom: 4px solid #fff;
     1188        color: #555;
     1189        cursor: pointer;
     1190}
     1191
     1192.filter-links .themes-section-feature_filter_themes:before {
     1193        content: "\f111";
     1194        font: 16px/1 dashicons;
     1195        position: relative;
     1196        top: 2px;
     1197        margin-right: 4px;
     1198}
     1199
     1200#customize-theme-section-navigation .customize-themes-section-title.themes-section-search_themes {
     1201        border-bottom: none;
     1202        padding: 10px 0;
     1203        max-width: calc(100% - 70px);
     1204}
     1205
     1206#customize-theme-section-navigation .customize-themes-section-title.selected {
     1207        border-bottom: 4px solid #555;
     1208}
     1209
     1210#customize-theme-section-navigation .customize-themes-section-title:hover,
     1211#customize-theme-section-navigation .customize-themes-section-title:focus {
     1212        color: #0073aa;
     1213        border-bottom: 4px solid #0073aa;
     1214        box-shadow: none;
     1215        outline: none;
     1216}
     1217
     1218#customize-theme-section-navigation .customize-themes-section-title.themes-section-search_themes.selected,
     1219#customize-theme-section-navigation .customize-themes-section-title.themes-section-search_themes:hover {
     1220        border-bottom: none;
     1221}
     1222
    10791223#customize-theme-controls .themes.accordion-section-content {
    10801224        position: relative;
    10811225        left: 0;
     
    10831227        width: 100%;
    10841228}
    10851229
    1086 .wp-customizer .theme-browser .themes {
    1087         padding-bottom: 8px;
     1230.theme-section.loading .spinner {
     1231        display: block;
     1232        visibility: visible;
     1233        position: relative;
     1234        clear: both;
     1235        width: 20px;
     1236        height: 20px;
     1237        left: calc(50% - 10px);
     1238        float: none;
     1239        margin-top: 50px;
    10881240}
    10891241
    1090 .wp-customizer .theme-browser .theme {
     1242.customize-themes-section .filter-drawer {
     1243        border-top: none;
     1244        display: block;
     1245        background: transparent;
     1246        padding-top: 5px;
     1247}
     1248
     1249.customize-themes-section .clear-filters {
     1250        margin-left: 8px;
     1251        display: none;
     1252}
     1253
     1254#accordion-section-feature_filter_themes .theme-browser {
     1255        display: none; /* Shown with JS once filters are applied */
     1256}
     1257
     1258.customize-themes-section .no-themes {
     1259        display: none;
     1260}
     1261
     1262#accordion-section-installed_themes .theme .notice-success {
     1263        display: none;
     1264}
     1265
     1266.control-panel-themes .theme-browser .theme .theme-actions .button-primary {
     1267        margin: 0 0 0 8px;
     1268}
     1269
     1270.customize-control-theme .theme {
     1271        width: 100%;
    10911272        margin: 0;
    1092         width: 100%;
    10931273}
    10941274
     1275.customize-control.customize-control-theme { /* override most properties on .customize-control */
     1276        box-sizing: border-box;
     1277        width: 18.4%;
     1278        margin: 0 2% 2% 0;
     1279        padding: 0;
     1280        clear: none;
     1281}
     1282
     1283/* 5 columns above 2100px */
     1284@media screen and (min-width: 2101px) {
     1285        .customize-control.customize-control-theme:nth-child(5n) {
     1286                margin-right: 0;
     1287        }
     1288}
     1289
     1290/* 4 columns up to 2100px */
     1291@media screen and (min-width: 1601px) and (max-width: 2100px) {
     1292        .customize-control.customize-control-theme {
     1293                width: 23.5%;
     1294        }
     1295
     1296        .customize-control.customize-control-theme:nth-child(4n) {
     1297                margin-right: 0;
     1298        }
     1299}
     1300
     1301/* 3 columns up to 1600px */
     1302@media screen and (min-width: 1101px) and (max-width: 1600px) {
     1303        .customize-control.customize-control-theme {
     1304                width: 32%;
     1305        }
     1306
     1307        .customize-control.customize-control-theme:nth-child(3n) {
     1308                margin-right: 0;
     1309        }
     1310}
     1311
     1312/* 2 columns up to 1100px */
     1313@media screen and (min-width: 501px) and (max-width: 1100px) {
     1314        .customize-control.customize-control-theme {
     1315                width: 49%;
     1316        }
     1317
     1318        .customize-control.customize-control-theme:nth-child(even) {
     1319                margin-right: 0;
     1320        }
     1321}
     1322
     1323/* 1 column up to 500 px */
     1324@media screen and (max-width: 500px) {
     1325        .customize-control.customize-control-theme {
     1326                width: 100%;
     1327                margin: 0 0 3% 0;
     1328        }
     1329}
     1330
     1331
     1332.wp-customizer .theme-browser .themes {
     1333        padding-bottom: 8px;
     1334}
     1335
    10951336.wp-customizer .theme-browser .theme .theme-actions {
    10961337        -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
    10971338        opacity: 1;
     
    11121353        width: 100%;
    11131354}
    11141355
    1115 .control-section-themes .accordion-section-title:after,
    1116 .customize-themes-panel .accordion-section-title:after {
     1356#accordion-panel-themes .accordion-section-title:after {
    11171357        display: none;
    11181358}
    11191359
    1120 .customize-themes-panel.control-panel-content {
    1121         border-top: 1px solid #ddd;
     1360#customize-theme-controls .control-panel-themes.current-panel > h3.accordion-section-title {
     1361        left: 0;
    11221362}
    11231363
     1364
    11241365/* Details View */
    11251366.wp-customizer .theme-overlay {
    11261367        display: none;
     
    11411382        z-index: 110;
    11421383}
    11431384
     1385.wp-customizer .theme-overlay .star-rating {
     1386        float: left;
     1387        margin-right: 8px;
     1388}
     1389
     1390.wp-customizer .theme-rating .num-ratings {
     1391        line-height: 20px;
     1392}
     1393
    11441394.wp-customizer .theme-overlay .theme-wrap {
    11451395        left: 90px;
    11461396        right: 90px;
     
    11511401}
    11521402
    11531403.wp-customizer .theme-overlay .theme-actions {
    1154         text-align: right; /* Because there's only one action, match the pattern of media modals and right-align the action. */
     1404        text-align: right; /* Because there're only one or two actions, match the UI pattern of media modals and right-align the action. */
     1405    padding: 10px 15px;
    11551406}
    11561407
     1408.wp-customizer .theme-overlay .theme-actions .theme-install.preview {
     1409        margin-left: 8px;
     1410}
     1411
     1412.control-panel-themes .theme-actions .delete-theme {
     1413        left: 15px;
     1414        right: auto;
     1415}
     1416
     1417.modal-open .in-themes-panel #customize-controls .wp-full-overlay-sidebar-content {
     1418        overflow: visible; /* Prevent the top-level Customizer controls from becoming visible when elements on the right of the details modal are focused. */
     1419}
     1420
    11571421.ie8 .wp-customizer .theme-overlay .theme-header,
    11581422.ie8 .wp-customizer .theme-overlay .theme-about,
    11591423.ie8 .wp-customizer .theme-overlay .theme-actions {
  • src/wp-admin/includes/theme.php

     
    606606 * @since 4.2.0
    607607 */
    608608function customize_themes_print_templates() {
    609         $preview_url = esc_url( add_query_arg( 'theme', '__THEME__' ) ); // Token because esc_url() strips curly braces.
     609        $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
     610        $active_url  = esc_url( remove_query_arg( 'theme', $current_url ) );
     611        $preview_url = esc_url( add_query_arg( 'theme', '__THEME__', $current_url ) ); // Token because esc_url() strips curly braces.
    610612        $preview_url = str_replace( '__THEME__', '{{ data.id }}', $preview_url );
    611613        ?>
    612614        <script type="text/html" id="tmpl-customize-themes-details-view">
     
    619621                        </div>
    620622                        <div class="theme-about wp-clearfix">
    621623                                <div class="theme-screenshots">
    622                                 <# if ( data.screenshot[0] ) { #>
     624                                <# if ( data.screenshot && data.screenshot[0] ) { #>
    623625                                        <div class="screenshot"><img src="{{ data.screenshot[0] }}" alt="" /></div>
    624626                                <# } else { #>
    625627                                        <div class="screenshot blank"></div>
     
    632634                                        <# } #>
    633635                                        <h2 class="theme-name">{{{ data.name }}}<span class="theme-version"><?php printf( __( 'Version: %s' ), '{{ data.version }}' ); ?></span></h2>
    634636                                        <h3 class="theme-author"><?php printf( __( 'By %s' ), '{{{ data.authorAndUri }}}' ); ?></h3>
     637
     638                                        <# if ( data.stars && 0 != data.num_ratings ) { #>
     639                                                <div class="theme-rating">
     640                                                        {{{ data.stars }}}
     641                                                        <span class="num-ratings"><?php echo sprintf( __( '(%s ratings)' ), '{{ data.num_ratings }}' ); ?></span>
     642                                                </div>
     643                                        <# } #>
     644
     645                                        <# if ( data.hasUpdate ) { #>
     646                                                <div class="notice notice-warning notice-alt notice-large" data-slug="{{ data.id }}">
     647                                                        <h3 class="notice-title"><?php _e( 'Update Available' ); ?></h3>
     648                                                        {{{ data.update }}}
     649                                                </div>
     650                                        <# } #>
     651
    635652                                        <p class="theme-description">{{{ data.description }}}</p>
    636653
    637654                                        <# if ( data.parent ) { #>
    638655                                                <p class="parent-theme"><?php printf( __( 'This is a child theme of %s.' ), '<strong>{{{ data.parent }}}</strong>' ); ?></p>
    639656                                        <# } #>
    640 
    641657                                        <# if ( data.tags ) { #>
    642                                                 <p class="theme-tags"><span><?php _e( 'Tags:' ); ?></span> {{ data.tags }}</p>
     658                                                <p class="theme-tags"><span><?php _e( 'Tags:' ); ?></span> {{{ data.tags }}}</p>
    643659                                        <# } #>
    644660                                </div>
    645661                        </div>
    646662
    647                         <# if ( ! data.active ) { #>
    648                                 <div class="theme-actions">
    649                                         <div class="inactive-theme">
    650                                                 <?php
    651                                                 /* translators: %s: Theme name */
    652                                                 $aria_label = sprintf( __( 'Preview %s' ), '{{ data.name }}' );
    653                                                 ?>
    654                                                 <a href="<?php echo $preview_url; ?>" target="_top" class="button button-primary" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Live Preview' ); ?></a>
    655                                         </div>
    656                                 </div>
    657                         <# } #>
     663                        <div class="theme-actions">
     664                                <# if ( data.active ) { #>
     665                                        <?php
     666                                        /* translators: %s: Theme name */
     667                                        $aria_label = sprintf( __( 'Customize %s' ), '{{ data.name }}' );
     668                                        ?>
     669                                        <button type="button" class="button button-primary customize-theme" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Customize' ); ?></a>
     670                                <# } else if ( 'installed' === data.type ) { #>
     671                                        <?php if ( current_user_can( 'delete_themes' ) ) { ?>
     672                                                <# if ( data.actions && data.actions['delete'] ) { #>
     673                                                        <a href="{{{ data.actions['delete'] }}}" data-slug="{{ data.id }}" class="button button-secondary delete-theme"><?php _e( 'Delete' ); ?></a>
     674                                                <# } #>
     675                                        <?php } ?>
     676                                        <button type="button" class="button button-primary preview-theme" data-preview-url="<?php echo esc_attr( $preview_url ); ?>" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Live Preview' ); ?></span>
     677                                <# } else { #>
     678                                        <button type="button" class="button theme-install" data-slug="{{ data.id }}"><?php _e( 'Install' ); ?></button>
     679                                        <button type="button" class="button button-primary theme-install preview" data-slug="{{ data.id }}" data-previewurl="<?php echo esc_attr( $preview_url ); ?>"><?php _e( 'Install & Preview' ); ?></button>
     680                                <# } #>
     681                        </div>
    658682                </div>
    659683        </script>
    660684        <?php
  • src/wp-admin/js/customize-controls.js

     
    22(function( exports, $ ){
    33        var Container, focus, normalizedTransitionendEventName, api = wp.customize;
    44
     5        window.pagenow = 'customize'; // Needed for updates.js to function properly.
     6
    57        /**
    68         * A Customizer Setting.
    79         *
     
    866868        /**
    867869         * wp.customize.ThemesSection
    868870         *
    869          * Custom section for themes that functions similarly to a backwards panel,
    870          * and also handles the theme-details view rendering and navigation.
     871         * Custom section for themes that loads themes by category, and also
     872         * handles the theme-details view rendering and navigation.
    871873         *
    872874         * @constructor
    873875         * @augments wp.customize.Section
     
    879881                template: '',
    880882                screenshotQueue: null,
    881883                $window: $( window ),
     884                loaded: 0,
     885                loading: false,
     886                fullyLoaded: false,
     887                term: '',
    882888
    883889                /**
    884890                 * @since 4.2.0
    885891                 */
    886                 initialize: function () {
    887                         this.$customizeSidebar = $( '.wp-full-overlay-sidebar-content:first' );
    888                         return api.Section.prototype.initialize.apply( this, arguments );
    889                 },
    890 
    891                 /**
    892                  * @since 4.2.0
    893                  */
    894892                ready: function () {
    895893                        var section = this;
    896894                        section.overlay = section.container.find( '.theme-overlay' );
     
    918916                                }
    919917                        });
    920918
    921                         _.bindAll( this, 'renderScreenshots' );
     919                        _.bindAll( this, 'renderScreenshots', 'loadMore', 'checkTerm', 'filtersChecked', 'clearFilters' );
    922920                },
    923921
    924922                /**
     
    925923                 * Override Section.isContextuallyActive method.
    926924                 *
    927925                 * Ignore the active states' of the contained theme controls, and just
    928                  * use the section's own active state instead. This ensures empty search
    929                  * results for themes to cause the section to become inactive.
     926                 * use the section's own active state instead. This prevents empty search
     927                 * results for theme sections from causing the section to become inactive.
    930928                 *
    931929                 * @since 4.2.0
    932930                 *
     
    942940                attachEvents: function () {
    943941                        var section = this;
    944942
    945                         // Expand/Collapse section/panel.
    946                         section.container.find( '.change-theme, .customize-theme' ).on( 'click keydown', function( event ) {
    947                                 if ( api.utils.isKeydownButNotEnterEvent( event ) ) {
    948                                         return;
    949                                 }
    950                                 event.preventDefault(); // Keep this AFTER the key filter above
    951 
    952                                 if ( section.expanded() ) {
    953                                         section.collapse();
    954                                 } else {
     943                        // Expand section/panel. Only collapse when opening another section.
     944                        $( '#customize-theme-section-navigation' ).on( 'click', '.themes-section-' + section.id, function( event ) {
     945                                if ( ! section.expanded() && 'search_themes' !== section.id ) {
    955946                                        section.expand();
    956947                                }
    957948                        });
    958949
    959                         // Theme navigation in details view.
    960                         section.container.on( 'click keydown', '.left', function( event ) {
    961                                 if ( api.utils.isKeydownButNotEnterEvent( event ) ) {
    962                                         return;
    963                                 }
     950                        // Preview installed themes.
     951                        section.container.on( 'click', '.theme-actions .preview-theme', function() {
     952                                var previewUrl = $( this ).data( 'previewUrl' );
    964953
    965                                 event.preventDefault(); // Keep this AFTER the key filter above
     954                                $( '.wp-full-overlay' ).addClass( 'customize-loading' );
    966955
     956                                window.parent.location = previewUrl;
     957                        });
     958       
     959                        // Theme navigation in details view.
     960                        section.container.on( 'click', '.left', function( event ) {
    967961                                section.previousTheme();
    968962                        });
    969963
    970                         section.container.on( 'click keydown', '.right', function( event ) {
    971                                 if ( api.utils.isKeydownButNotEnterEvent( event ) ) {
    972                                         return;
    973                                 }
    974 
    975                                 event.preventDefault(); // Keep this AFTER the key filter above
    976 
     964                        section.container.on( 'click', '.right', function( event ) {
    977965                                section.nextTheme();
    978966                        });
    979967
    980                         section.container.on( 'click keydown', '.theme-backdrop, .close', function( event ) {
    981                                 if ( api.utils.isKeydownButNotEnterEvent( event ) ) {
    982                                         return;
    983                                 }
    984 
    985                                 event.preventDefault(); // Keep this AFTER the key filter above
    986 
     968                        section.container.on( 'click', '.theme-backdrop, .close', function( event ) {
    987969                                section.closeDetails();
    988970                        });
    989971
    990972                        var renderScreenshots = _.throttle( _.bind( section.renderScreenshots, this ), 100 );
    991                         section.container.on( 'input', '#themes-filter', function( event ) {
     973                        $( '#customize-theme-section-navigation' ).on( 'input', '#themes-filter', function( event ) {
    992974                                var count,
    993975                                        term = event.currentTarget.value.toLowerCase().trim().replace( '-', ' ' ),
    994976                                        controls = section.controls();
     
    1001983
    1002984                                // Update theme count.
    1003985                                count = section.container.find( 'li.customize-control:visible' ).length;
    1004                                 section.container.find( '.theme-count' ).text( count );
     986                                $( '.control-panel-themes' ).find( '.theme-count' ).text( count );
    1005987                        });
    1006988
    1007                         // Pre-load the first 3 theme screenshots.
    1008                         api.bind( 'ready', function () {
    1009                                 _.each( section.controls().slice( 0, 3 ), function ( control ) {
    1010                                         var img, src = control.params.theme.screenshot[0];
    1011                                         if ( src ) {
    1012                                                 img = new Image();
    1013                                                 img.src = src;
     989                        // Event listeners for queries with user-entered terms.
     990                        if ( 'search' === section.params.action ) {
     991                                var debounced = _.debounce( section.checkTerm, 500 ); // Wait until there is no input for 500 miliseconds to initiate a search.
     992                                $( '#customize-theme-section-navigation' ).on( 'input', '#wp-filter-search-input', function() {
     993                                        debounced( section );
     994                                        if ( ! section.expanded() ) {
     995                                                section.expand();
    1014996                                        }
    1015997                                });
     998                        } else if ( 'favorites' === section.params.action ) {
     999                                section.container.on( 'click', '.favorites-form-submit', function() {
     1000                                        section.checkTerm( section );
     1001                                });
     1002                                section.container.on( 'keydown', '#wporg-username-input', function( e ) {
     1003                                        if ( api.utils.isKeydownButNotEnterEvent( e ) ) {
     1004                                                return;
     1005                                        }
     1006                                        section.checkTerm( section );
     1007                                });
     1008                        } else if ( 'feature_filter' === section.params.action ) {
     1009                                section.container.on( 'click', '.filter-group input', function() {
     1010                                        section.filtersChecked();
     1011                                });
     1012                                section.container.on( 'click', '.clear-filters', function() {
     1013                                        section.clearFilters();
     1014                                });
     1015                                section.container.on( 'click', '.apply-filters', function() {
     1016                                        section.checkTerm( section );
     1017                                });
     1018                                section.container.on( 'click', '.filtered-by .tags, .filtered-by button', function() {
     1019                                        section.container.find( '.filter-group' ).show();
     1020                                        section.container.find( '.buttons' ).show();
     1021                                        section.container.find( '.filtered-by' ).hide();
     1022                                        section.container.find( '.theme-browser' ).hide();
     1023                                });
     1024                        }
     1025
     1026                        // Move section-expansion buttons to consolidated menu bar in themes panel.
     1027                        api.bind( 'ready', function () {
     1028                                section.container.find( '.customize-themes-section-title' ).appendTo( $( '#customize-theme-section-navigation .filter-links' ) );
    10161029                        });
    10171030                },
    10181031
     
    10371050                        }
    10381051
    10391052                        // Note: there is a second argument 'args' passed
    1040                         var panel = this,
    1041                                 section = panel.contentContainer,
    1042                                 overlay = section.closest( '.wp-full-overlay' ),
    1043                                 container = section.closest( '.wp-full-overlay-sidebar-content' ),
    1044                                 customizeBtn = section.find( '.customize-theme' ),
    1045                                 changeBtn = panel.headContainer.find( '.change-theme' );
     1053                        var section = this,
     1054                                overlay = section.container.closest( '.wp-full-overlay-sidebar-content' ),
     1055                                container = section.container.closest( '.control-panel-content' );
    10461056
    1047                         if ( expanded && ! section.hasClass( 'current-panel' ) ) {
     1057                        if ( expanded ) {
     1058
     1059                                // Load controls if none are loaded yet.
     1060                                if ( 0 === section.loaded ) {
     1061                                        section.loadControls();
     1062                                }
     1063
    10481064                                // Collapse any sibling sections/panels
    10491065                                api.section.each( function ( otherSection ) {
    1050                                         if ( otherSection !== panel ) {
     1066                                        if ( otherSection !== section ) {
    10511067                                                otherSection.collapse( { duration: args.duration } );
    10521068                                        }
    10531069                                });
    1054                                 api.panel.each( function ( otherPanel ) {
    1055                                         otherPanel.collapse( { duration: 0 } );
    1056                                 });
    10571070
    1058                                 panel._animateChangeExpanded( function() {
    1059                                         changeBtn.attr( 'tabindex', '-1' );
    1060                                         customizeBtn.attr( 'tabindex', '0' );
     1071                                section.container.addClass( 'current-section' );
     1072                                $( '#customize-theme-section-navigation .themes-section-' + section.id ).addClass( 'selected' );
     1073                                container.on( 'scroll', _.throttle( section.renderScreenshots, 300 ) );
     1074                                container.on( 'scroll', _.throttle( section.loadMore, 300 ) );
     1075                                if ( args.completeCallback ) {
     1076                                        args.completeCallback();
     1077                                }
     1078                                section.updateCount(); // Show this section's count.
     1079                        } else {
     1080                                section.container.removeClass( 'current-section' );
     1081                                $( '#customize-theme-section-navigation .themes-section-' + section.id ).removeClass( 'selected' );
     1082                                container.off( 'scroll' );
     1083                                if ( args.completeCallback ) {
     1084                                        args.completeCallback();
     1085                                }
     1086                        }
     1087                },
    10611088
    1062                                         customizeBtn.focus();
    1063                                         section.css( 'top', '' );
    1064                                         container.scrollTop( 0 );
     1089                /**
     1090                 * Return the section's content element without detachng from the parent.
     1091                 *
     1092                 * @since 4.7.0
     1093                 */
     1094                getContent: function() {
     1095                        return this.container.find( '.control-section-content' );
     1096                },
    10651097
    1066                                         if ( args.completeCallback ) {
    1067                                                 args.completeCallback();
    1068                                         }
    1069                                 } );
     1098                /**
     1099                 * Load theme data via ajax and add themes to the section as controls.
     1100                 *
     1101                 * @since 4.7.0
     1102                 */
     1103                loadControls: function() {
     1104                        var section = this, params, page, request, search;
    10701105
    1071                                 overlay.addClass( 'in-themes-panel' );
    1072                                 section.addClass( 'current-panel' );
     1106                        if ( section.loading ) {
     1107                                return; // We're already loading a batch of themes.
     1108                        }
    10731109
    1074                         } else if ( ! expanded && section.hasClass( 'current-panel' ) ) {
    1075                                 panel._animateChangeExpanded( function() {
    1076                                         changeBtn.attr( 'tabindex', '0' );
    1077                                         customizeBtn.attr( 'tabindex', '-1' );
     1110                        // Parameters for every API query. Additional params are set in PHP.
     1111                        page = Math.ceil( section.loaded / 100 ) + 1;
     1112                        params = {
     1113                                'customize-themes-nonce': api.settings.nonce['customize-themes'],
     1114                                'wp_customize': 'on',
     1115                                'theme_action': section.params.action,
     1116                                'customized_theme': api.settings.theme.stylesheet,
     1117                                'page': page
     1118                        }
    10781119
    1079                                         changeBtn.focus();
    1080                                         section.css( 'top', '' );
     1120                        // Add fields for special request actions.
     1121                        if ( 'search' === section.params.action ) {
     1122                                if ( '' === section.term ) {
     1123                                        return;
     1124                                } else {
     1125                                        params.search = section.term;
     1126                                }
     1127                        } else if ( 'favorites' === section.params.action ) {
     1128                                if ( '' === section.term ) {
     1129                                        return;
     1130                                } else {
     1131                                        params.user = section.term;
     1132                                }
     1133                        } else if ( 'feature_filter' === section.params.action ) {
     1134                                if ( '' === section.term ) {
     1135                                        return;
     1136                                } else {
     1137                                        params.tags = section.term;
     1138                                }
     1139                        }
    10811140
    1082                                         if ( args.completeCallback ) {
    1083                                                 args.completeCallback();
     1141                        // Load themes.
     1142                        section.container.addClass( 'loading' );
     1143                        section.loading = true;
     1144                        section.container.find( '.no-themes' ).hide();
     1145                        request = wp.ajax.post( 'customize-load-themes', params );
     1146                        request.done(function( data ) {
     1147                                var themes = data.themes,
     1148                                    themeControl, newThemeControls;
     1149                                if ( 0 !== themes.length ) {
     1150                                        newThemeControls = new Array();
     1151                                        // Add controls for each theme.
     1152                                        _.each( themes, function ( theme ) {
     1153                                                customizeId = section.params.action + '_theme_' + theme.id;
     1154                                                themeControl = new api.controlConstructor.theme( customizeId, {
     1155                                                        params: {
     1156                                                                type: 'theme',
     1157                                                                content: '<li id="customize-control-theme-' + section.params.action + '_' + theme.id + '" class="customize-control customize-control-theme"></li>',
     1158                                                                section: section.params.id,
     1159                                                                active: true,
     1160                                                                theme: theme,
     1161                                                                priority: section.loaded + 1
     1162                                                        },
     1163                                                        previewer: api.previewer
     1164                                                } );
     1165
     1166                                                api.control.add( customizeId, themeControl );
     1167                                                newThemeControls.push( themeControl );
     1168                                                section.loaded = section.loaded + 1;
     1169                                                return;
     1170                                        });
     1171                               
     1172                                        if ( 1 === page ) {
     1173                                                // Pre-load the first 3 theme screenshots.
     1174                                                _.each( section.controls().slice( 0, 3 ), function ( control ) {
     1175                                                        var img, src = control.params.theme.screenshot[0];
     1176                                                        if ( src ) {
     1177                                                                img = new Image();
     1178                                                                img.src = src;
     1179                                                        }
     1180                                                });
     1181                                                if ( 'search' === section.params.action ) {
     1182                                                        wp.a11y.speak( api.settings.l10n.themeSearchResults.replace( '%d', data.info.results ) );
     1183                                                }
     1184                                        } else {
     1185                                                Array.prototype.push.apply( section.screenshotQueue, newThemeControls ); // Add new themes to the screenshot queue.
    10841186                                        }
    1085                                 } );
     1187                                        _.delay( section.renderScreenshots, 100 ); // Wait for the controls to become visible.
    10861188
    1087                                 overlay.removeClass( 'in-themes-panel' );
    1088                                 section.removeClass( 'current-panel' );
     1189                                        if ( 'installed' === section.action || 100 > themes.length ) { // If we have less than the requested 100 themes, it's the end of the list.
     1190                                                section.fullyLoaded = true;
     1191                                        }
     1192                                } else {
     1193                                        if ( 0 === section.loaded ) {
     1194                                                section.container.find( '.no-themes' ).show();
     1195                                                wp.a11y.speak( section.container.find( '.no-themes' ).text() );
     1196                                        } else {
     1197                                                section.fullyLoaded = true;
     1198                                        }
     1199                                }
     1200                                if ( 'installed' === section.params.action ) {
     1201                                        section.updateCount();
     1202                                } else {
     1203                                        section.updateCount( data.info.results );
     1204                                }
     1205                                section.container.find( '.unexpected-error' ).hide(); // Hide error notice in case it was previously shown.
     1206
     1207                                // This cannot run on request.always, as section.loading may turn false before the new controls load in the success case.
     1208                                section.container.removeClass( 'loading' );
     1209                                section.loading = false;
     1210                        });
     1211                        request.fail(function( data ) {
     1212                                if ( 'undefined' === typeof data ) {
     1213                                        section.container.find( '.unexpected-error' ).show();
     1214                                        wp.a11y.speak( section.container.find( '.unexpected-error' ).text() );
     1215                                } else if ( typeof console !== 'undefined' && console.error ) {
     1216                                        console.error( data );
     1217                                }
     1218                               
     1219                                // This cannot run on request.always, as section.loading may turn false before the new controls load in the success case.
     1220                                section.container.removeClass( 'loading' );
     1221                                section.loading = false;
     1222                        });
     1223                },
     1224
     1225                /**
     1226                 * Determines whether more themes should be loaded, and loads them.
     1227                 *
     1228                 * @since 4.7.0
     1229                 */
     1230                loadMore: function() {
     1231                        var section = this, container, bottom, threshold, page;
     1232                        if ( ! section.fullyLoaded && ! section.loading ) {
     1233                                container = section.container.closest( '.control-panel-content' );
     1234
     1235                                bottom = container.scrollTop() + container.height();
     1236                                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.
     1237
     1238                                if ( bottom > threshold ) {
     1239                                        section.loadControls();
     1240                                }
    10891241                        }
    10901242                },
    10911243
    10921244                /**
     1245                 * Event handler for search, feature filter, and favorites input that determines if the term has changed and loads new controls as needed.
     1246                 *
     1247                 * @since 4.7.0
     1248                 *
     1249                 * @param api.ThemesSection section The current theme section, passed through the debouncer.
     1250                 */
     1251                checkTerm: function( section ) {
     1252                        var newTerm, filteringBy;
     1253
     1254                        // Find term.
     1255                        if ( 'search' === section.params.action ) {
     1256                                newTerm = $( '#wp-filter-search-input' ).val();
     1257                        } else if ( 'favorites' === section.params.action ) {
     1258                                newTerm = $( '#wporg-username-input' ).val();
     1259                        } else if ( 'feature_filter' === section.params.action ) {
     1260                                newTerm = section.term; // Set separately by filtersChecked(), as they're changed.
     1261                                if ( '' === newTerm ) {
     1262                                        return;
     1263                                }
     1264
     1265                                section.container.find( '.filter-group' ).hide();
     1266                                section.container.find( '.buttons' ).hide();
     1267                                section.container.find( '.filtered-by' ).show();
     1268                                section.container.find( '.theme-browser' ).show();
     1269                                filteringBy = section.container.find( '.filtered-by .tags' );
     1270                                filteringBy.empty();
     1271
     1272                                _.each( newTerm, function( tag ) {
     1273                                        name = $( 'label[for="filter-id-' + tag + '"]' ).text();
     1274                                        filteringBy.append( '<span class="tag">' + name + '</span>' );
     1275                                });
     1276                        } else {
     1277                                return;
     1278                        }
     1279
     1280                        if ( section.term === newTerm && 'feature_filter' !== section.params.action ) {
     1281                                return;
     1282                        }
     1283                        // Clear the controls in the section.
     1284                        _.each( section.controls(), function( control ) {
     1285                                control.container.remove();
     1286                                api.control.remove( control.id );
     1287                        });
     1288                        section.loaded = 0;
     1289                        section.fullyLoaded = false;
     1290                        section.screenshotQueue = null;
     1291
     1292                        if ( '' !== newTerm ) { // Empty term should not show any results.
     1293                                // Run a new query, with loadControls handling paging, etc.
     1294                                section.term = newTerm;
     1295                                section.loadControls();
     1296                        }
     1297                },
     1298               
     1299                /**
     1300                 * Check for filters checked in the feature filter list.
     1301                 *
     1302                 * @since 4.7.0
     1303                 */
     1304                filtersChecked: function() {
     1305                        var section = this,
     1306                            items = section.container.find( '.filter-group' ).find( ':checkbox' ),
     1307                            tags = [];
     1308
     1309                        if ( 'feature_filter' !== section.params.action ) {
     1310                                return false;
     1311                        }
     1312
     1313                        _.each( items.filter( ':checked' ), function( item ) {
     1314                                tags.push( $( item ).prop( 'value' ) );
     1315                        });
     1316
     1317                        // When no filters are checked, restore initial state and return
     1318                        if ( tags.length === 0 ) {
     1319                                section.container.find( '.filter-drawer .apply-filters' ).find( 'span' ).text( '' );
     1320                                section.container.find( '.filter-drawer .clear-filters' ).hide();
     1321                                section.term = '';
     1322                        } else {
     1323                                section.container.find( '.filter-drawer .apply-filters' ).find( 'span' ).text( tags.length );
     1324                                section.container.find( '.filter-drawer .clear-filters' ).css( 'display', 'inline-block' ); // $.show() manually.
     1325                                section.term = tags;
     1326                        }
     1327                },
     1328
     1329                /**
     1330                 * Clear filters from the feature filter list.
     1331                 *
     1332                 * @since 4.7.0
     1333                 */
     1334                clearFilters: function() {
     1335                        var section = this,
     1336                            items = section.container.find( '.filter-group' ).find( ':checkbox' );
     1337
     1338                        _.each( items.filter( ':checked' ), function( item ) {
     1339                                $( item ).prop( 'checked', false );
     1340                        });
     1341                        section.filtersChecked();
     1342                },
     1343
     1344                /**
    10931345                 * Render control's screenshot if the control comes into view.
    10941346                 *
    10951347                 * @since 4.2.0
     
    10971349                renderScreenshots: function( ) {
    10981350                        var section = this;
    10991351
    1100                         // Fill queue initially.
    1101                         if ( section.screenshotQueue === null ) {
    1102                                 section.screenshotQueue = section.controls();
     1352                        // Fill queue initially, or check for more if empty.
     1353                        if ( section.screenshotQueue === null || 0 === section.screenshotQueue.length ) {
     1354                                // Add controls that haven't had their screenshots rendered.
     1355                                section.screenshotQueue = _.filter( section.controls(), function( control ) {
     1356                                        return ! control.screenshotRendered;
     1357                                });
    11031358                        }
    11041359
    1105                         // Are all screenshots rendered?
     1360                        // Are all screenshots rendered (for now)?
    11061361                        if ( ! section.screenshotQueue.length ) {
    11071362                                return;
    11081363                        }
     
    11381393                },
    11391394
    11401395                /**
     1396                 * Update the number of themes in the section.
     1397                 *
     1398                 * @since 4.7.0
     1399                 */
     1400                updateCount: function ( count ) {
     1401                        if ( ! count ) {
     1402                                count = this.loaded;
     1403                        }
     1404                        this.container.closest( '.control-panel-content' ).find( '.theme-count' ).text( count );
     1405                },
     1406
     1407                /**
    11411408                 * Advance the modal to the next theme.
    11421409                 *
    11431410                 * @since 4.2.0
     
    11571424                 * @since 4.2.0
    11581425                 */
    11591426                getNextTheme: function () {
    1160                         var control, next;
    1161                         control = api.control( 'theme_' + this.currentTheme );
     1427                        var section = this, control, next;
     1428                        control = api.control( section.params.action + '_theme_' + this.currentTheme );
    11621429                        next = control.container.next( 'li.customize-control-theme' );
    11631430                        if ( ! next.length ) {
    11641431                                return false;
    11651432                        }
    1166                         next = next[0].id.replace( 'customize-control-', '' );
     1433                        next = next[0].id.replace( 'customize-control-theme-' + section.params.action, section.params.action + '_theme' );
    11671434                        control = api.control( next );
    11681435
    11691436                        return control.params.theme;
     
    11891456                 * @since 4.2.0
    11901457                 */
    11911458                getPreviousTheme: function () {
    1192                         var control, previous;
    1193                         control = api.control( 'theme_' + this.currentTheme );
     1459                        var section = this, control, previous;
     1460                        control = api.control( section.params.action + '_theme_' + this.currentTheme );
    11941461                        previous = control.container.prev( 'li.customize-control-theme' );
    11951462                        if ( ! previous.length ) {
    11961463                                return false;
    11971464                        }
    1198                         previous = previous[0].id.replace( 'customize-control-', '' );
     1465                        previous = previous[0].id.replace( 'customize-control-theme-' + section.params.action, section.params.action + '_theme' );
    11991466                        control = api.control( previous );
    12001467
    12011468                        return control.params.theme;
     
    12431510                closeDetails: function () {
    12441511                        $( 'body' ).removeClass( 'modal-open' );
    12451512                        this.overlay.fadeOut( 'fast' );
    1246                         api.control( 'theme_' + this.currentTheme ).focus();
     1513                        api.control( this.params.action + '_theme_' + this.currentTheme ).container.find( '.theme' ).focus();
    12471514                },
    12481515
    12491516                /**
     
    13231590                        }
    13241591                        if ( ! panel.contentContainer.parent().is( panel.headContainer ) ) {
    13251592                                container.append( panel.contentContainer );
    1326                                 panel.renderContent();
    13271593                        }
     1594                        panel.renderContent();
    13281595
    13291596                        panel.deferred.embedded.resolve();
    13301597                },
     
    15131780                }
    15141781        });
    15151782
     1783
    15161784        /**
     1785         * wp.customize.ThemesPanel
     1786         *
     1787         * Custom section for themes that displays without the customize preview.
     1788         *
     1789         * @constructor
     1790         * @augments wp.customize.Panel
     1791         * @augments wp.customize.Container
     1792         */
     1793        api.ThemesPanel = api.Panel.extend({
     1794                installingThemes: [],
     1795
     1796                /**
     1797                 * @since 4.7.0
     1798                 */
     1799                attachEvents: function () {
     1800                        var panel = this;
     1801
     1802                        // Expand/Collapse panel.
     1803                        panel.headContainer.on( 'click', '.change-theme', function( event ) {
     1804                                panel.expand();
     1805                        });
     1806                        panel.contentContainer.on( 'click', '.customize-theme', function( event ) {
     1807                                panel.collapse();
     1808                        });
     1809
     1810                        // Toggle help display.
     1811                        panel.contentContainer.on( 'click', '.customize-help-toggle', function() {
     1812                                var button = $( this ),
     1813                                    content = button.next( '.customize-panel-description' );
     1814                                button.toggleClass( 'toggled' );
     1815                                content.toggle();
     1816                                if ( button.hasClass( 'toggled' ) ) {
     1817                                        button.attr( 'aria-expanded', 'true' );
     1818                                } else {
     1819                                        button.attr( 'aria-expanded', 'false' );
     1820                                }
     1821                        });
     1822
     1823                        api.bind( 'saved', function() {
     1824                                panel.container.find( '.customize-themes-unsaved-changes' ).hide();
     1825                        });
     1826                       
     1827                        // Save & publish customizer changes.
     1828                        panel.contentContainer.on( 'click', '#customize-themes-save', function() {
     1829                                $( '#save' ).click(); // Trigger customizer save.
     1830                                panel.container.find( '.customize-themes-unsaved-changes' ).hide();
     1831                                api.section( 'installed_themes' ).focus();
     1832                        });
     1833                       
     1834                        // Toggle theme upload view.
     1835                        panel.contentContainer.on( 'click', '.upload-toggle', function() {
     1836                                var button = $( this );
     1837                                panel.container.find( '.upload-theme' ).toggle();
     1838                                if ( 'true' === button.attr( 'aria-expanded' ) ) {
     1839                                        button.attr( 'aria-expanded', 'false' );
     1840                                } else {
     1841                                        button.attr( 'aria-expanded', 'true' );
     1842                                }
     1843                        });
     1844
     1845                        // Install theme.
     1846                        panel.contentContainer.on( 'click', '.theme-install', function( event ) {
     1847                                panel.installTheme( event );
     1848                        });
     1849
     1850                        // Update theme. Theme cards have the class, the details modal has the id.
     1851                        panel.contentContainer.on( 'click', '.update-theme, #update-theme', function( event ) {
     1852                                // #update-theme is a link.
     1853                                event.preventDefault();
     1854                                event.stopPropagation();
     1855
     1856                                panel.updateTheme( event );
     1857                        });
     1858
     1859                        // Update theme.
     1860                        panel.contentContainer.on( 'click', '.delete-theme', function( event ) {
     1861                                panel.deleteTheme( event );
     1862                        });
     1863
     1864                        _.bindAll( this, 'installTheme', 'updateTheme' );
     1865                },
     1866
     1867                /**
     1868                 * Update UI to reflect expanded state
     1869                 *
     1870                 * @since 4.7.0
     1871                 *
     1872                 * @param {Boolean}  expanded
     1873                 * @param {Object}   args
     1874                 * @param {Boolean}  args.unchanged
     1875                 * @param {Callback} args.completeCallback
     1876                 */
     1877                onChangeExpanded: function ( expanded, args ) {
     1878
     1879                        // Immediately call the complete callback if there were no changes
     1880                        if ( args.unchanged ) {
     1881                                if ( args.completeCallback ) {
     1882                                        args.completeCallback();
     1883                                }
     1884                                return;
     1885                        }
     1886
     1887                        // Note: there is a second argument 'args' passed
     1888                        var panel = this,
     1889                                section = panel.container.closest( '.accordion-section' ),
     1890                                overlay = section.closest( '.wp-full-overlay' ),
     1891                                customizeBtn = section.find( '.panel-meta .customize-theme' ),
     1892                                changeBtn = section.find( '.change-theme' ),
     1893                                content = section.find( '.control-panel-content' );
     1894
     1895                        if ( expanded ) {
     1896                                content.show( 0, function() {
     1897                                        overlay.addClass( 'in-themes-panel' );
     1898                                        section.addClass( 'current-panel' );
     1899                                        customizeBtn.attr( 'tabindex', '0' );
     1900                                        customizeBtn.focus();
     1901                                        if ( false === api.state( 'saved' ).get() ) {
     1902                                                panel.container.find( '.customize-themes-unsaved-changes' ).show();
     1903                                        }
     1904                                });
     1905                                // Automatically open the installed themes section.
     1906                                api.section( 'installed_themes' ).expand();
     1907                        } else {
     1908                                section.removeClass( 'current-panel' );
     1909                                overlay.removeClass( 'in-themes-panel' );
     1910                                content.delay( 200 ).hide( 0, function() {
     1911                                        if ( args.completeCallback ) {
     1912                                                args.completeCallback();
     1913                                        }
     1914                                } );
     1915                                customizeBtn.attr( 'tabindex', '-1' );
     1916                                changeBtn.focus();
     1917                        }
     1918                },
     1919
     1920                /**
     1921                 * Return the panel's content element without detachng from the parent.
     1922                 *
     1923                 * @since 4.7.0
     1924                 */
     1925                getContent: function() {
     1926                        return this.container.find( '.control-panel-content' );
     1927                },
     1928
     1929                /**
     1930                 * Install a theme via wp.updates.
     1931                 *
     1932                 * @since 4.7.0
     1933                 */
     1934                installTheme: function( event ) {
     1935                        var preview = false, previewUrl,
     1936                            slug = $( event.target ).data( 'slug' );
     1937
     1938                        if ( -1 !== $.inArray( this.installingThemes, slug ) ) {
     1939                                return; // Theme is already being installed.
     1940                        }
     1941
     1942                        wp.updates.maybeRequestFilesystemCredentials( event );
     1943
     1944                        $( document ).on( 'wp-theme-install-success', function( event, response ) {
     1945                                var theme = false, customizeId, themeControl;
     1946                                if ( preview ) {
     1947                                        window.parent.location = previewUrl;
     1948                                } else {
     1949                                        api.control.each( function( control ) {
     1950                                                if ( 'theme' === control.params.type && control.params.theme.id === response.slug ) {
     1951                                                        theme = control.params.theme; // Used below to add theme control.
     1952                                                        control.rerenderAsInstalled( true );
     1953                                                }
     1954                                        });
     1955
     1956                                        // Don't add the same theme more than once.
     1957                                        if ( ! theme || 'undefined' !== typeof api.control( 'installed_theme_' + theme.id ) ) {
     1958                                                return;
     1959                                        }
     1960
     1961                                        // Add theme control to installed section.
     1962                                        theme.type = 'installed';
     1963                                        customizeId = 'installed_theme_' + theme.id;
     1964                                        themeControl = new api.controlConstructor.theme( customizeId, {
     1965                                                params: {
     1966                                                        type: 'theme',
     1967                                                        content: '<li id="customize-control-theme-installed_' + theme.id + '" class="customize-control customize-control-theme"></li>',
     1968                                                        section: 'installed_themes',
     1969                                                        active: true,
     1970                                                        theme: theme,
     1971                                                        priority: 0 // Add all newly-installed themes to the top.
     1972                                                },
     1973                                                previewer: api.previewer
     1974                                        } );
     1975
     1976                                        api.control.add( customizeId, themeControl );
     1977                                        api.control( customizeId ).container.trigger( 'render-screenshot' );
     1978
     1979                                        // Close the details modal if it's open to the installed theme.
     1980                                        api.section.each( function( section ) {
     1981                                                if ( 'themes' !== section.params.type ) {
     1982                                                        if ( theme.id === section.currentTheme ) { // Don't close the modal if the user has navigated elsewhere.
     1983                                                                section.closeDetails();
     1984                                                        }
     1985                                                }
     1986                                        });
     1987                                }
     1988                        } );
     1989
     1990                        $( document ).on( 'wp-theme-install-failure', function( event, response ) {
     1991                                if ( preview ) {
     1992                                        $( '.wp-full-overlay' ).removeClass( 'customize-loading' );
     1993                                }
     1994                        });
     1995
     1996                        this.installingThemes.push( $( event.target ).data( 'slug' ) ); // Note: we don't remove elements from installingThemes, since they shouldn't be installed again.
     1997                        wp.updates.installTheme( {
     1998                                slug: $( event.target ).data( 'slug' )
     1999                        } );
     2000                       
     2001                        // Also preview the theme as the event is triggered on Install & Preview.
     2002                        if ( $( event.target ).hasClass( 'preview' ) ) {
     2003                                preview = true;
     2004                                $( '.wp-full-overlay' ).addClass( 'customize-loading' );
     2005                                previewUrl = $( event.target ).data( 'previewurl' );
     2006                        }
     2007                },
     2008
     2009                /**
     2010                 * Update a theme via wp.updates.
     2011                 *
     2012                 * @since 4.7.0
     2013                 */
     2014                updateTheme: function( event ) {
     2015                        wp.updates.maybeRequestFilesystemCredentials( event );
     2016
     2017                        $( document ).on( 'wp-theme-update-success', function( event, response ) {
     2018                                // Rerender the control to reflect the update.
     2019                                api.control.each( function( control ) {
     2020                                        if ( 'theme' === control.params.type && control.params.theme.id === response.slug ) {
     2021                                                control.params.theme.hasUpdate = false;
     2022                                                control.rerenderAsInstalled( true );
     2023                                        }
     2024                                });
     2025                        } );
     2026
     2027                        wp.updates.updateTheme( {
     2028                                slug: $( event.target ).closest( '.notice' ).data( 'slug' )
     2029                        } );
     2030                },
     2031
     2032                /**
     2033                 * Delete a theme via wp.updates.
     2034                 *
     2035                 * @since 4.7.0
     2036                 */
     2037                deleteTheme: function( event ) {
     2038                        var panel = this,
     2039                                theme = $( event.target ).data( 'slug' ),
     2040                            section = api.section( 'installed_themes' );
     2041
     2042                        event.preventDefault();
     2043
     2044                        // Confirmation dialog for deleting a theme.
     2045                        if ( ! window.confirm( api.settings.l10n.confirmDeleteTheme ) ) {
     2046                                return;
     2047                        }
     2048
     2049                        wp.updates.maybeRequestFilesystemCredentials( event );
     2050
     2051                        $( document ).one( 'wp-theme-delete-success', function( event, response ) {
     2052                                var control = api.control( 'installed_theme_' + theme );
     2053
     2054                                // Remove theme control.
     2055                                control.container.remove();
     2056                                api.control.remove( control.id );
     2057                               
     2058                                // Update installed count.
     2059                                section.loaded = section.loaded - 1;
     2060                                section.updateCount();
     2061                               
     2062                                // Rerender any other theme controls as uninstalled.
     2063                                api.control.each( function( control ) {
     2064                                        if ( 'theme' === control.params.type && control.params.theme.id === theme ) {
     2065                                                control.rerenderAsInstalled( false );
     2066                                        }
     2067                                });
     2068                        } );
     2069
     2070                        wp.updates.deleteTheme( {
     2071                                slug: theme
     2072                        } );
     2073                       
     2074                        // Close modal and focus the section.
     2075                        section.closeDetails();
     2076                        section.focus();
     2077                }
     2078
     2079        });
     2080
     2081
     2082        /**
    15172083         * A Customizer Control.
    15182084         *
    15192085         * A control provides a UI element that allows a user to modify a Customizer Setting.
     
    28313397        api.ThemeControl = api.Control.extend({
    28323398
    28333399                touchDrag: false,
    2834                 isRendered: false,
     3400                screenshotRendered: false,
    28353401
    28363402                /**
    2837                  * Defer rendering the theme control until the section is displayed.
    2838                  *
    28393403                 * @since 4.2.0
    28403404                 */
    2841                 renderContent: function () {
    2842                         var control = this,
    2843                                 renderContentArgs = arguments;
    2844 
    2845                         api.section( control.section(), function( section ) {
    2846                                 if ( section.expanded() ) {
    2847                                         api.Control.prototype.renderContent.apply( control, renderContentArgs );
    2848                                         control.isRendered = true;
    2849                                 } else {
    2850                                         section.expanded.bind( function( expanded ) {
    2851                                                 if ( expanded && ! control.isRendered ) {
    2852                                                         api.Control.prototype.renderContent.apply( control, renderContentArgs );
    2853                                                         control.isRendered = true;
    2854                                                 }
    2855                                         } );
    2856                                 }
    2857                         } );
    2858                 },
    2859 
    2860                 /**
    2861                  * @since 4.2.0
    2862                  */
    28633405                ready: function() {
    28643406                        var control = this;
    28653407
     
    28793421                                }
    28803422
    28813423                                // Prevent the modal from showing when the user clicks the action button.
    2882                                 if ( $( event.target ).is( '.theme-actions .button' ) ) {
     3424                                if ( $( event.target ).is( '.theme-actions .button, .update-theme' ) ) {
    28833425                                        return;
    28843426                                }
    28853427
    2886                                 var previewUrl = $( this ).data( 'previewUrl' );
    2887 
    2888                                 $( '.wp-full-overlay' ).addClass( 'customize-loading' );
    2889 
    2890                                 window.parent.location = previewUrl;
    2891                         });
    2892 
    2893                         control.container.on( 'click keydown', '.theme-actions .theme-details', function( event ) {
    2894                                 if ( api.utils.isKeydownButNotEnterEvent( event ) ) {
    2895                                         return;
    2896                                 }
    2897 
    2898                                 event.preventDefault(); // Keep this AFTER the key filter above
    2899 
    29003428                                api.section( control.section() ).showDetails( control.params.theme );
    29013429                        });
    29023430
     
    29073435                                if ( source ) {
    29083436                                        $screenshot.attr( 'src', source );
    29093437                                }
     3438                                control.screenshotRendered = true;
    29103439                        });
    29113440                },
    29123441
    29133442                /**
    2914                  * Show or hide the theme based on the presence of the term in the title, description, and author.
     3443                 * Show or hide the theme based on the presence of the term in the title, description, tags, and author.
    29153444                 *
    29163445                 * @since 4.2.0
    29173446                 */
     
    29273456                        } else {
    29283457                                control.deactivate();
    29293458                        }
     3459                },
     3460
     3461                /**
     3462                 * Rerender the theme from its JS template with the installed type.
     3463                 *
     3464                 * @since 4.7.0
     3465                 */
     3466                rerenderAsInstalled: function( installed ) {
     3467                        var control = this, section;
     3468                        if ( installed ) {
     3469                                control.params.theme.type = 'installed';
     3470                        } else {
     3471                                section = api.section( control.params.section );
     3472                                control.params.theme.type = section.params.action;
     3473                        }
     3474                        control.renderContent(); // replaces existing content
     3475                        control.container.trigger( 'render-screenshot' );
    29303476                }
    29313477        });
    29323478
     
    34904036                background:    api.BackgroundControl,
    34914037                theme:         api.ThemeControl
    34924038        };
    3493         api.panelConstructor = {};
     4039        api.panelConstructor = {
     4040                themes: api.ThemesPanel
     4041        };
    34944042        api.sectionConstructor = {
    34954043                themes: api.ThemesSection
    34964044        };
     
    40854633                        // Collapse the most granular expanded object.
    40864634                        collapsedObject = expandedControls[0] || expandedSections[0] || expandedPanels[0];
    40874635                        if ( collapsedObject ) {
     4636                                if ( 'themes' === collapsedObject.params.type ) {
     4637                                        // Themes panel or section.
     4638                                        if ( $( 'body' ).hasClass( 'modal-open' ) ) {
     4639                                                collapsedObject.closeDetails();
     4640                                        } else {
     4641                                                // If we're collapsing a section, collapse the panel also.
     4642                                                wp.customize.panel( 'themes' ).collapse();
     4643                                        }
     4644                                        return;
     4645                                }
    40884646                                collapsedObject.collapse();
    40894647                                event.preventDefault();
    40904648                        }
  • src/wp-admin/js/updates.js

     
    179179                if ( $notice.length ) {
    180180                        $notice.replaceWith( $adminNotice );
    181181                } else {
    182                         $( '.wrap' ).find( '> h1' ).after( $adminNotice );
     182                        if ( 'customize' === pagenow ) {
     183                                $( '.customize-themes-notifications' ).append( $adminNotice );
     184                        } else {
     185                                $( '.wrap' ).find( '> h1' ).after( $adminNotice );
     186                        }
    183187                }
    184188
    185189                $document.trigger( 'wp-updates-notice-added' );
     
    907911                if ( 'themes-network' === pagenow ) {
    908912                        $notice = $( '[data-slug="' + args.slug + '"]' ).find( '.update-message' ).removeClass( 'notice-error' ).addClass( 'updating-message notice-warning' ).find( 'p' );
    909913
     914                } else if ( 'customize' === pagenow ) {
     915                        // Update the theme details UI.
     916                        $notice = $( '#update-theme' ).closest( '.notice' ).removeClass( 'notice-large' );
     917
     918                        $notice.find( 'h3' ).remove();
     919
     920                        // Add the top-level UI, and update both.
     921                        $notice = $notice.add( $( '#customize-control-theme-installed_' + args.slug ).find( '.update-message' ) );
     922                        $notice = $notice.addClass( 'updating-message' ).find( 'p' );
     923
    910924                } else {
    911925                        $notice = $( '#update-theme' ).closest( '.notice' ).removeClass( 'notice-large' );
    912926
     
    949963                        },
    950964                        $notice, newText;
    951965
     966                if ( 'customize' === pagenow ) {
     967                        $theme = wp.customize.control( 'installed_theme_' + response.slug ).container;
     968                }
     969
    952970                if ( 'themes-network' === pagenow ) {
    953971                        $notice = $theme.find( '.update-message' );
    954972
     
    10031021                        return;
    10041022                }
    10051023
     1024                if ( 'customize' === pagenow ) {
     1025                        $theme = wp.customize.control( 'installed_theme_' + response.slug ).container;
     1026                }
     1027
    10061028                if ( 'themes-network' === pagenow ) {
    10071029                        $notice = $theme.find( '.update-message ' );
    10081030                } else {
     
    11391161                        return;
    11401162                }
    11411163
    1142                 if ( $document.find( 'body' ).hasClass( 'full-overlay-active' ) ) {
    1143                         $button = $( '.theme-install[data-slug="' + response.slug + '"]' );
    1144                         $card   = $( '.install-theme-info' ).prepend( $message );
     1164                if ( 'customize' === pagenow ) {
     1165                        if ( $document.find( 'body' ).hasClass( 'modal-open' ) ) {
     1166                                $button = $( '.theme-install[data-slug="' + response.slug + '"]' );
     1167                                $card   = $( '.theme-overlay .theme-info' ).prepend( $message );
     1168                        } else {
     1169                                $button = $( '.theme-install[data-slug="' + response.slug + '"]' );
     1170                                $card   = $button.closest( '.theme' ).addClass( 'theme-install-failed' ).append( $message );
     1171                        }
    11451172                } else {
    1146                         $card   = $( '[data-slug="' + response.slug + '"]' ).removeClass( 'focus' ).addClass( 'theme-install-failed' ).append( $message );
    1147                         $button = $card.find( '.theme-install' );
     1173                        if ( $document.find( 'body' ).hasClass( 'full-overlay-active' ) ) {
     1174                                $button = $( '.theme-install[data-slug="' + response.slug + '"]' );
     1175                                $card   = $( '.install-theme-info' ).prepend( $message );
     1176                        } else {
     1177                                $card   = $( '[data-slug="' + response.slug + '"]' ).removeClass( 'focus' ).addClass( 'theme-install-failed' ).append( $message );
     1178                                $button = $card.find( '.theme-install' );
     1179                        }
    11481180                }
    11491181
    11501182                $button
  • src/wp-includes/class-wp-customize-manager.php

     
    230230
    231231                require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menus-panel.php' );
    232232
     233                require_once( ABSPATH . WPINC . '/customize/class-wp-customize-themes-panel.php' );
    233234                require_once( ABSPATH . WPINC . '/customize/class-wp-customize-themes-section.php' );
    234235                require_once( ABSPATH . WPINC . '/customize/class-wp-customize-sidebar-section.php' );
    235236                require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-section.php' );
     
    289290
    290291                add_action( 'wp_ajax_customize_save',           array( $this, 'save' ) );
    291292                add_action( 'wp_ajax_customize_refresh_nonces', array( $this, 'refresh_nonces' ) );
     293                add_action( 'wp_ajax_customize-load-themes',    array( $this, 'load_themes_ajax' ) );
    292294
    293295                add_action( 'customize_register',                 array( $this, 'register_controls' ) );
    294296                add_action( 'customize_register',                 array( $this, 'register_dynamic_settings' ), 11 ); // allow code to create settings first
     
    302304
    303305                // Export the settings to JS via the _wpCustomizeSettings variable.
    304306                add_action( 'customize_controls_print_footer_scripts', array( $this, 'customize_pane_settings' ), 1000 );
     307
     308                // Add theme update notices.
     309                if ( current_user_can( 'install_themes' ) || current_user_can( 'update_themes' ) ) {
     310                        require_once( ABSPATH . '/wp-admin/includes/update.php' );
     311                        add_action( 'customize_controls_print_footer_scripts', 'wp_print_admin_notice_templates' );
     312                }
    305313        }
    306314
    307315        /**
     
    16261634                foreach ( $this->controls as $control ) {
    16271635                        $control->enqueue();
    16281636                }
     1637                if ( ! is_multisite() && ( current_user_can( 'install_themes' ) || current_user_can( 'update_themes' ) || current_user_can( 'delete_themes' ) ) ) {
     1638                        wp_enqueue_script( 'updates' );
     1639                }
    16291640        }
    16301641
    16311642        /**
     
    17791790                $nonces = array(
    17801791                        'save' => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ),
    17811792                        'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() ),
     1793                        'customize-themes' => wp_create_nonce( 'customize-themes' ),
    17821794                );
    17831795
    17841796                /**
     
    18591871                        'autofocus' => $this->get_autofocus(),
    18601872                        'documentTitleTmpl' => $this->get_document_title_template(),
    18611873                        'previewableDevices' => $this->get_previewable_devices(),
     1874                        'l10n' => array(
     1875                                'confirmDeleteTheme' => __( 'Are you sure you want to delete this theme?' ),
     1876                                /* translators: %d is the number of theme search results, which cannot consider singular vs. plural forms */
     1877                                'themeSearchResults' => __( '%d themes found' ),
     1878                        ),
    18621879                );
    18631880
    18641881                // Prepare Customize Section objects to pass to JavaScript.
     
    19621979
    19631980                /* Panel, Section, and Control Types */
    19641981                $this->register_panel_type( 'WP_Customize_Panel' );
     1982                $this->register_panel_type( 'WP_Customize_Themes_Panel' );
    19651983                $this->register_section_type( 'WP_Customize_Section' );
    19661984                $this->register_section_type( 'WP_Customize_Sidebar_Section' );
     1985                $this->register_section_type( 'WP_Customize_Themes_Section' );
    19671986                $this->register_control_type( 'WP_Customize_Color_Control' );
    19681987                $this->register_control_type( 'WP_Customize_Media_Control' );
    19691988                $this->register_control_type( 'WP_Customize_Upload_Control' );
     
    19731992                $this->register_control_type( 'WP_Customize_Site_Icon_Control' );
    19741993                $this->register_control_type( 'WP_Customize_Theme_Control' );
    19751994
    1976                 /* Themes */
     1995                /* Themes (controls are loaded via ajax) */
    19771996
    1978                 $this->add_section( new WP_Customize_Themes_Section( $this, 'themes', array(
     1997                $this->add_panel( new WP_Customize_Themes_Panel( $this, 'themes', array(
    19791998                        'title'      => $this->theme()->display( 'Name' ),
     1999                        '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 categories in this menu or upload a theme from a <code>.zip</code> file.' ),
    19802000                        'capability' => 'switch_themes',
    19812001                        'priority'   => 0,
    19822002                ) ) );
    19832003
    1984                 // Themes Setting (unused - the theme is considerably more fundamental to the Customizer experience).
    1985                 $this->add_setting( new WP_Customize_Filter_Setting( $this, 'active_theme', array(
     2004                $this->add_section( new WP_Customize_Themes_Section( $this, 'installed_themes', array(
     2005                        'title'      => __( 'Installed' ),
     2006                        'action'     => 'installed',
    19862007                        'capability' => 'switch_themes',
     2008                        'panel'      => 'themes',
     2009                        'priority'   => 0,
    19872010                ) ) );
    19882011
    1989                 require_once( ABSPATH . 'wp-admin/includes/theme.php' );
     2012                $this->add_section( new WP_Customize_Themes_Section( $this, 'featured_themes', array(
     2013                        'title'      => __( 'Featured' ),
     2014                        'action'     => 'featured',
     2015                        'capability' => 'install_themes',
     2016                        'panel'      => 'themes',
     2017                        'priority'   => 5,
     2018                ) ) );
    19902019
    1991                 // Theme Controls.
     2020                $this->add_section( new WP_Customize_Themes_Section( $this, 'popular_themes', array(
     2021                        'title'      => __( 'Popular' ),
     2022                        'action'     => 'popular',
     2023                        'capability' => 'install_themes',
     2024                        'panel'      => 'themes',
     2025                        'priority'   => 10,
     2026                ) ) );
    19922027
    1993                 // Add a control for the active/original theme.
    1994                 if ( ! $this->is_theme_active() ) {
    1995                         $themes = wp_prepare_themes_for_js( array( wp_get_theme( $this->original_stylesheet ) ) );
    1996                         $active_theme = current( $themes );
    1997                         $active_theme['isActiveTheme'] = true;
    1998                         $this->add_control( new WP_Customize_Theme_Control( $this, $active_theme['id'], array(
    1999                                 'theme'    => $active_theme,
    2000                                 'section'  => 'themes',
    2001                                 'settings' => 'active_theme',
    2002                         ) ) );
    2003                 }
     2028                $this->add_section( new WP_Customize_Themes_Section( $this, 'latest_themes', array(
     2029                        'title'      => __( 'Latest' ),
     2030                        'action'     => 'latest',
     2031                        'capability' => 'install_themes',
     2032                        'panel'      => 'themes',
     2033                        'priority'   => 15,
     2034                ) ) );
    20042035
    2005                 $themes = wp_prepare_themes_for_js();
    2006                 foreach ( $themes as $theme ) {
    2007                         if ( $theme['active'] || $theme['id'] === $this->original_stylesheet ) {
    2008                                 continue;
    2009                         }
     2036                $this->add_section( new WP_Customize_Themes_Section( $this, 'favorites_themes', array(
     2037                        'title'      => __( 'Favorites' ),
     2038                        'action'     => 'favorites',
     2039                        'capability' => 'install_themes',
     2040                        'panel'      => 'themes',
     2041                        'priority'   => 20,
     2042                ) ) );
     2043               
     2044                $this->add_section( new WP_Customize_Themes_Section( $this, 'feature_filter_themes', array(
     2045                        'title'      => __( 'Feature Filter' ),
     2046                        'action'     => 'feature_filter',
     2047                        'capability' => 'install_themes',
     2048                        'panel'      => 'themes',
     2049                        'priority'   => 25,
     2050                ) ) );
     2051               
     2052                $this->add_section( new WP_Customize_Themes_Section( $this, 'search_themes', array(
     2053                        'title'      => __( 'Search themes&hellip;' ),
     2054                        'action'     => 'search',
     2055                        'capability' => 'install_themes',
     2056                        'panel'      => 'themes',
     2057                        'priority'   => 30,
     2058                ) ) );
     2059               
     2060                // Themes Setting (unused - the theme is considerably more fundamental to the Customizer experience).
     2061                $this->add_setting( new WP_Customize_Filter_Setting( $this, 'active_theme', array(
     2062                        'capability' => 'switch_themes',
     2063                ) ) );
    20102064
    2011                         $theme_id = 'theme_' . $theme['id'];
    2012                         $theme['isActiveTheme'] = false;
    2013                         $this->add_control( new WP_Customize_Theme_Control( $this, $theme_id, array(
    2014                                 'theme'    => $theme,
    2015                                 'section'  => 'themes',
    2016                                 'settings' => 'active_theme',
    2017                         ) ) );
    2018                 }
    20192065
    20202066                /* Site Identity */
    20212067
     
    23432389        }
    23442390
    23452391        /**
     2392         * Load themes into the theme browsing/installation UI.
     2393         *
     2394         * @since 4.7.0
     2395         * @access public
     2396         */
     2397        public function load_themes_ajax() {
     2398                check_ajax_referer( 'customize-themes', 'customize-themes-nonce' );
     2399
     2400                if ( ! current_user_can( 'switch_themes' ) ) {
     2401                        wp_die( -1 );
     2402                }
     2403
     2404                if ( empty( $_POST['theme_action'] ) ) {
     2405                        wp_send_json_error( 'missing_theme_action' );
     2406                }
     2407
     2408                if ( 'search' === $_POST['theme_action'] && ! array_key_exists( 'search', $_POST ) ) {
     2409                        wp_send_json_error( 'empty_search' );
     2410                } elseif ( 'favorites' === $_POST['theme_action'] && ! array_key_exists( 'user', $_POST ) ) {
     2411                        wp_send_json_error( 'empty_user' );
     2412                } elseif ( 'feature_filter' === $_POST['theme_action'] && ! array_key_exists( 'tags', $_POST ) ) {
     2413                        wp_send_json_error( 'no_features' );
     2414                }
     2415
     2416                require_once( ABSPATH . 'wp-admin/includes/theme.php' );
     2417                if ( 'installed' === $_POST['theme_action'] ) {
     2418                        $themes = array( 'themes' => wp_prepare_themes_for_js() );
     2419                        foreach ( $themes['themes'] as &$theme ) {
     2420                                $theme['type'] = 'installed';
     2421                                // Set active based on customized theme.
     2422                                if ( $_POST['customized_theme'] === $theme['id'] ) {
     2423                                        $theme['active'] = true;
     2424                                } else {
     2425                                        $theme['active'] = false;
     2426                                }
     2427                        }
     2428                } else {
     2429                        if ( ! current_user_can( 'install_themes' ) ) {
     2430                                wp_die( -1 );
     2431                        }
     2432
     2433                        // Arguments for all queries.
     2434                        $args = array(
     2435                                'per_page' => 100,
     2436                                'page' => absint( $_POST['page'] ),
     2437                                'fields' => array(
     2438                                        'slug' => true,
     2439                                        'screenshot' => true,
     2440                                        'description' => true,
     2441                                        'requires' => true,
     2442                                        'rating' => true,
     2443                                        'downloaded' => true,
     2444                                        'downloadLink' => true,
     2445                                        'last_updated' => true,
     2446                                        'homepage' => true,
     2447                                        'num_ratings' => true,
     2448                                        'tags' => true,
     2449                                )
     2450                        );
     2451
     2452                        // Specialized handling for each query.
     2453                        switch ( $_POST['theme_action'] ) {
     2454                                case 'search':
     2455                                        $args['search'] = wp_unslash( $_POST['search'] );
     2456                                        break;
     2457                                case 'favorites':
     2458                                        $args['user'] = wp_unslash(  $_POST['user'] );
     2459                                case 'featured':
     2460                                case 'popular':
     2461                                        $args['browse'] = $_POST['theme_action'];
     2462                                        break;
     2463                                case 'latest':
     2464                                        $args['browse'] = 'new';
     2465                                        break;
     2466                                case 'feature_filter':
     2467                                        $args['tag'] = wp_unslash( $_POST['tags'] );
     2468                                        break;
     2469                        }
     2470
     2471                        // Load themes from the .org API.
     2472                        $themes = themes_api( 'query_themes', $args );
     2473                        if ( is_wp_error( $themes ) ) {
     2474                                wp_send_json_error();
     2475                        }
     2476
     2477                        // Prepare a list of installed themes to check against before the loop.
     2478                        $installed_themes = array();
     2479                        $wp_themes = wp_get_themes();
     2480                        foreach ( $wp_themes as $theme ) {
     2481                                $installed_themes[] = $theme->get_stylesheet();
     2482                        }
     2483                        $update_php = network_admin_url( 'update.php?action=install-theme' );
     2484                        foreach ( $themes->themes as &$theme ) {
     2485                                $theme->install_url = add_query_arg( array(
     2486                                        'theme'    => $theme->slug,
     2487                                        '_wpnonce' => wp_create_nonce( 'install-theme_' . $theme->slug )
     2488                                ), $update_php );
     2489
     2490                                $theme->name        = wp_kses( $theme->name, $themes_allowedtags );
     2491                                $theme->author      = wp_kses( $theme->author, $themes_allowedtags );
     2492                                $theme->version     = wp_kses( $theme->version, $themes_allowedtags );
     2493                                $theme->description = wp_kses( $theme->description, $themes_allowedtags );
     2494                                $theme->tags        = implode( ', ', $theme->tags );
     2495                                $theme->stars       = wp_star_rating( array( 'rating' => $theme->rating, 'type' => 'percent', 'number' => $theme->num_ratings, 'echo' => false ) );
     2496                                $theme->num_ratings = number_format_i18n( $theme->num_ratings );
     2497                                $theme->preview_url = set_url_scheme( $theme->preview_url );
     2498
     2499                                // Handle themes that are already installed as installed themes.
     2500                                if ( in_array( $theme->slug, $installed_themes ) ) {
     2501                                        $theme->type = 'installed';
     2502                                } else {
     2503                                        $theme->type = $_POST['theme_action'];
     2504                                }
     2505
     2506                                // Set active based on customized theme.
     2507                                if ( $_POST['customized_theme'] === $theme->slug ) {
     2508                                        $theme->active = true;
     2509                                } else {
     2510                                        $theme->active = false;
     2511                                }
     2512
     2513                                // Map available theme properties to installed theme properties.
     2514                                $theme->id           = $theme->slug;
     2515                                $theme->screenshot   = array( $theme->screenshot_url );
     2516                                $theme->authorAndUri = $theme->author;
     2517                                unset( $theme->slug );
     2518                                unset( $theme->screenshot_url );
     2519                                unset( $theme->author );
     2520                        }
     2521                }
     2522                wp_send_json_success( $themes );
     2523        }
     2524
     2525
     2526        /**
    23462527         * Callback for validating the header_textcolor value.
    23472528         *
    23482529         * Accepts 'blank', and otherwise uses sanitize_hex_color_no_hash().
  • src/wp-includes/customize/class-wp-customize-theme-control.php

     
    6767                $preview_url = esc_url( add_query_arg( 'theme', '__THEME__', $current_url ) ); // Token because esc_url() strips curly braces.
    6868                $preview_url = str_replace( '__THEME__', '{{ data.theme.id }}', $preview_url );
    6969                ?>
    70                 <# if ( data.theme.isActiveTheme ) { #>
    71                         <div class="theme active" tabindex="0" data-preview-url="<?php echo esc_attr( $active_url ); ?>" aria-describedby="{{ data.theme.id }}-action {{ data.theme.id }}-name">
     70                <# if ( data.theme.active ) { #>
     71                        <div class="theme active" tabindex="0" aria-describedby="{{ data.theme.id }}-action {{ data.theme.id }}-name">
    7272                <# } else { #>
    73                         <div class="theme" tabindex="0" data-preview-url="<?php echo esc_attr( $preview_url ); ?>" aria-describedby="{{ data.theme.id }}-action {{ data.theme.id }}-name">
     73                        <div class="theme" tabindex="0" aria-describedby="{{ data.theme.id }}-action {{ data.theme.id }}-name">
    7474                <# } #>
    7575
    76                         <# if ( data.theme.screenshot[0] ) { #>
     76                        <# if ( data.theme.screenshot && data.theme.screenshot[0] ) { #>
    7777                                <div class="theme-screenshot">
    7878                                        <img data-src="{{ data.theme.screenshot[0] }}" alt="" />
    7979                                </div>
     
    8181                                <div class="theme-screenshot blank"></div>
    8282                        <# } #>
    8383
    84                         <# if ( data.theme.isActiveTheme ) { #>
    85                                 <span class="more-details" id="{{ data.theme.id }}-action"><?php _e( 'Customize' ); ?></span>
    86                         <# } else { #>
    87                                 <span class="more-details" id="{{ data.theme.id }}-action"><?php _e( 'Live Preview' ); ?></span>
     84                        <span class="more-details theme-details" id="{{ data.theme.id }}-action"><?php _e( 'Theme Details' ); ?></span>
     85
     86
     87                        <# if ( 'installed' === data.theme.type && data.theme.hasUpdate ) { #>
     88                                <div class="update-message notice inline notice-warning notice-alt" data-slug="{{ data.theme.id }}"><p><?php _e( 'New version available. <button class="button-link update-theme" type="button">Update now</button>' ); ?></p></div>
    8889                        <# } #>
    8990
    90                         <div class="theme-author"><?php printf( __( 'By %s' ), '{{ data.theme.author }}' ); ?></div>
    91 
    92                         <# if ( data.theme.isActiveTheme ) { #>
     91                        <# if ( data.theme.active ) { #>
    9392                                <h3 class="theme-name" id="{{ data.theme.id }}-name">
    9493                                        <?php
    9594                                        /* translators: %s: theme name */
    96                                         printf( __( '<span>Active:</span> %s' ), '{{{ data.theme.name }}}' );
     95                                        printf( __( '<span>Current:</span> %s' ), '{{ data.theme.name }}' );
    9796                                        ?>
    9897                                </h3>
     98                                <div class="theme-actions">
     99                                        <button type="button" class="button button-primary customize-theme"><?php _e( 'Customize' ); ?></span>
     100                        <# } else if ( 'installed' === data.theme.type ) { #>
     101                                <h3 class="theme-name" id="{{ data.theme.id }}-name">{{ data.theme.name }}</h3>
     102                                <div class="theme-actions">
     103                                        <button type="button" class="button button-primary preview-theme" data-preview-url="<?php echo esc_attr( $preview_url ); ?>"><?php _e( 'Live Preview' ); ?></span>
     104                                </div>
     105                                <div class="notice notice-success notice-alt"><p><?php _e( 'Installed' ); ?></p></div>
    99106                        <# } else { #>
    100                                 <h3 class="theme-name" id="{{ data.theme.id }}-name">{{{ data.theme.name }}}</h3>
     107                                <h3 class="theme-name" id="{{ data.theme.id }}-name">{{ data.theme.name }}</h3>
    101108                                <div class="theme-actions">
    102                                         <button type="button" class="button theme-details"><?php _e( 'Theme Details' ); ?></button>
     109                                        <button type="button" class="button theme-install" data-slug="{{ data.theme.id }}"><?php _e( 'Install' ); ?></button>
     110                                        <button type="button" class="button button-primary theme-install preview" data-slug="{{ data.theme.id }}" data-previewurl="<?php echo esc_attr( $preview_url ); ?>"><?php _e( 'Install & Preview' ); ?></button>
    103111                                </div>
    104                         <# } #>
     112                        <# } #>                 
    105113                </div>
    106114        <?php
    107115        }
  • src/wp-includes/customize/class-wp-customize-themes-panel.php

     
     1<?php
     2/**
     3 * Customize API: WP_Customize_Themes_Panel class
     4 *
     5 * @package WordPress
     6 * @subpackage Customize
     7 * @since 4.7.0
     8 */
     9
     10/**
     11 * Customize Themes Panel Class
     12 *
     13 * @since 4.7.0
     14 *
     15 * @see WP_Customize_Panel
     16 */
     17class WP_Customize_Themes_Panel extends WP_Customize_Panel {
     18
     19        /**
     20         * Panel type.
     21         *
     22         * @since 4.7.0
     23         * @access public
     24         * @var string
     25         */
     26        public $type = 'themes';
     27
     28        /**
     29         * An Underscore (JS) template for rendering this panel's container.
     30         *
     31         * The themes panel renders a custom panel heading with the current theme and a switch themes button.
     32         *
     33         * @see WP_Customize_Panel::print_template()
     34         *
     35         * @since 4.7.0
     36         * @access protected
     37         */
     38        protected function render_template() {
     39                ?>
     40                <li id="accordion-section-{{ data.id }}" class="accordion-section control-panel-themes">
     41                        <h3 class="accordion-section-title">
     42                                <?php
     43                                if ( $this->manager->is_theme_active() ) {
     44                                        echo '<span class="customize-action">' . __( 'Active theme' ) . '</span> {{ data.title }}';
     45                                } else {
     46                                        echo '<span class="customize-action">' . __( 'Previewing theme' ) . '</span> {{ data.title }}';
     47                                }
     48                                ?>
     49
     50                                <?php
     51                                if ( current_user_can( 'switch_themes' ) ) : ?>
     52                                        <button type="button" class="button change-theme"><?php _ex( 'Change', 'theme' ); ?></button>
     53                                <?php endif; ?>
     54                        </h3>
     55                        <ul class="accordion-sub-container control-panel-content"></ul>
     56                </li>
     57                <?php
     58        }
     59
     60        /**
     61         * An Underscore (JS) template for this panel's content (but not its container).
     62         *
     63         * Class variables for this panel class are available in the `data` JS object;
     64         * export custom variables by overriding WP_Customize_Panel::json().
     65         *
     66         * @since 4.7.0
     67         * @access protected
     68         *
     69         * @see WP_Customize_Panel::print_template()
     70         */
     71        protected function content_template() {
     72                ?>
     73                <li class="panel-meta accordion-section customize-info">
     74                        <div class="current-theme">
     75                                <span class="preview-notice">
     76                                        <?php
     77                                        /* translators: %s: the site/panel title in the Customizer */
     78                                        printf( __( 'Current Theme %s' ), '<strong class="panel-title">{{ data.title }}</strong>' );
     79                                        ?>
     80                                </span>
     81                                <button type="button" class="button customize-theme" tabindex="-1"><?php _e( 'Customize' ); ?></button>
     82                        </div>
     83                        <h2><?php _e( 'Themes' ); ?></h2>
     84                        <?php if ( current_user_can( 'install_themes' ) ) : ?>
     85                                <button type="button" class="upload-toggle page-title-action" aria-expanded="false"><?php _e( 'Upload Theme' ); ?></button>
     86                        <?php endif; ?>
     87                </li>
     88                <li class="upload-theme">
     89                        <?php if ( current_user_can( 'install_themes' ) ) : ?>
     90                                <p class="install-help"><?php _e( 'If you have a theme in a <code>.zip</code> format, you may install it by uploading it here.' ); ?></p>
     91                                <div class="wp-upload-form">
     92                                        <input type="file" id="themezip" name="themezip"><label class="screen-reader-text" for="themezip"><?php _e( 'Theme zip file' ); ?></label>
     93                                        <button type="button" id="upload-theme-submit" class="button"><?php _e( 'Install Now' ); ?></button>
     94                                </div>
     95                        <?php endif; ?>
     96                        </div>
     97                </li>
     98                <li id="customize-container"></li><?php // Used as a full-screen overlay transition after clicking to preview a theme. ?>
     99                <li class="customize-themes-notifications">
     100                        <div class="notice notice-warning customize-themes-unsaved-changes" style="display: none;"><p>
     101                                <?php _e( 'You have unsaved changes that will be lost if you preview a new theme.' ); ?>
     102                                <button type="button" id="customize-themes-save" class="button" ><?php _e( 'Save & Publish' ); ?></button>
     103                        </p></div>
     104                </li>
     105                <li id="customize-theme-section-navigation" class="wp-filter">
     106                        <div class="filter-count"><span class="count theme-count">0</span></div>
     107                        <?php if ( current_user_can( 'install_themes' ) && ! is_multisite() ) : ?>
     108                                <# if ( data.description ) { #>
     109                                        <button class="customize-help-toggle dashicons dashicons-editor-help" type="button" aria-expanded="false"><span class="screen-reader-text"><?php _e( 'Help' ); ?></span></button>
     110                                        <div class="description customize-panel-description">
     111                                                {{{ data.description }}}
     112                                        </div>
     113                                <# } #>
     114                                <div class="filter-links"></div>
     115                        <?php else: ?>
     116                                <p class="themes-filter-container">
     117                                        <label for="themes-filter">
     118                                                <span class="screen-reader-text"><?php _e( 'Search installed themes&hellip;' ); ?></span>
     119                                                <input type="text" id="themes-filter" placeholder="<?php esc_attr_e( 'Search installed themes&hellip;' ); ?>" />
     120                                        </label>
     121                                </p>
     122                        <?php endif; ?>
     123                </li>
     124        <?php
     125        }
     126}
  • src/wp-includes/customize/class-wp-customize-themes-section.php

     
    1010/**
    1111 * Customize Themes Section class.
    1212 *
    13  * A UI container for theme controls, which behaves like a backwards Panel.
     13 * A UI container for theme controls, which are displayed in tabbed sections.
    1414 *
    1515 * @since 4.2.0
    1616 *
     
    2828        public $type = 'themes';
    2929
    3030        /**
    31          * Render the themes section, which behaves like a panel.
     31         * Theme section action.
    3232         *
    33          * @since 4.2.0
     33         * Defines the type of themes to load (installed, featured, latest, etc.).
     34         *
     35         * @since 4.7.0
     36         * @access public
     37         * @var string
     38         */
     39        public $action = '';
     40
     41        /**
     42         * Get section parameters for JS.
     43         *
     44         * @since 4.7.0
     45         * @access public
     46         * @return array Exported parameters.
     47         */
     48        public function json() {
     49                $exported = parent::json();
     50                $exported['action'] = $this->action;
     51
     52                return $exported;
     53        }
     54
     55        /**
     56         * Render a themes section as a JS template.
     57         *
     58         * The template is only rendered by PHP once, so all actions are prepared at once on the server side.
     59         *
     60         * @since 4.7.0
    3461         * @access protected
    3562         */
    36         protected function render() {
    37                 $classes = 'accordion-section control-section control-section-' . $this->type;
     63        protected function render_template() {
    3864                ?>
    39                 <li id="accordion-section-<?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
    40                         <h3 class="accordion-section-title">
    41                                 <?php
    42                                 if ( $this->manager->is_theme_active() ) {
    43                                         echo '<span class="customize-action">' . __( 'Active theme' ) . '</span> ' . $this->title;
    44                                 } else {
    45                                         echo '<span class="customize-action">' . __( 'Previewing theme' ) . '</span> ' . $this->title;
    46                                 }
    47                                 ?>
    48 
    49                                 <?php if ( count( $this->controls ) > 0 ) : ?>
    50                                         <button type="button" class="button change-theme" tabindex="0"><?php _ex( 'Change', 'theme' ); ?></button>
    51                                 <?php endif; ?>
    52                         </h3>
    53                         <div class="customize-themes-panel control-panel-content themes-php">
    54                                 <h3 class="accordion-section-title customize-section-title">
    55                                         <span class="customize-action"><?php _e( 'Customizing' ); ?></span>
    56                                         <?php _e( 'Themes' ); ?>
    57                                         <span class="title-count theme-count"><?php echo count( $this->controls ) + 1 /* Active theme */; ?></span>
    58                                 </h3>
    59                                 <h3 class="accordion-section-title customize-section-title">
     65                <li id="accordion-section-{{ data.id }}" class="theme-section">
     66                        <# if ( 'search' === data.action ) { #>
     67                                <div class="search-form customize-themes-section-title themes-section-search_themes">
     68                                        <label class="screen-reader-text" for="wp-filter-search-input">{{ data.title }}</label>
     69                                        <input placeholder="{{ data.title }}" type="search" aria-describedby="live-search-desc" id="wp-filter-search-input" class="wp-filter-search">
     70                                        <span id="live-search-desc" class="screen-reader-text"><?php _e( 'The search results will be updated as you type.' ); ?></span>
     71                                </div>
     72                        <# } else { #>
     73                                <button type="button" class="customize-themes-section-title themes-section-{{ data.id }}">{{ data.title }}</button>
     74                        <# } #>
     75                        <div class="customize-themes-section control-section-content themes-php">
     76                                <# if ( 'favorites' === data.action ) { #>
     77                                        <div class="favorites-form">
     78                                                <p class="install-help"><?php _e( 'If you have marked themes as favorites on WordPress.org, you can browse them here.' ); ?></p>
     79                                                <p>
     80                                                        <label for="wporg-username-input"><?php _e( 'Your WordPress.org username:' ); ?></label>
     81                                                        <input type="search" id="wporg-username-input" value="">
     82                                                        <button type="button" class="button button-secondary favorites-form-submit"><?php _e( 'Get Favorites' ); ?></button>
     83                                                </p>
     84                                        </div>
     85                                <# } else if ( 'feature_filter' === data.action ) { #>
     86                                        <div class="filter-drawer">
     87                                                <div class="buttons">
     88                                                        <button type="button" class="apply-filters button button-secondary"><?php _e( 'Apply Filters' ); ?><span></span></a>
     89                                                        <button type="button" class="clear-filters button button-secondary"><?php _e( 'Clear' ); ?></a>
     90                                                </div>
    6091                                        <?php
    61                                         if ( $this->manager->is_theme_active() ) {
    62                                                 echo '<span class="customize-action">' . __( 'Active theme' ) . '</span> ' . $this->title;
    63                                         } else {
    64                                                 echo '<span class="customize-action">' . __( 'Previewing theme' ) . '</span> ' . $this->title;
     92                                        $feature_list = get_theme_feature_list();
     93                                        foreach ( $feature_list as $feature_name => $features ) {
     94                                                echo '<fieldset class="filter-group">';
     95                                                $feature_name = esc_html( $feature_name );
     96                                                echo '<legend>' . $feature_name . '</legend>';
     97                                                echo '<div class="filter-group-feature">';
     98                                                foreach ( $features as $feature => $feature_name ) {
     99                                                        $feature = esc_attr( $feature );
     100                                                        echo '<input type="checkbox" id="filter-id-' . $feature . '" value="' . $feature . '" /> ';
     101                                                        echo '<label for="filter-id-' . $feature . '">' . $feature_name . '</label><br>';
     102                                                }
     103                                                echo '</div>';
     104                                                echo '</fieldset>';
    65105                                        }
    66106                                        ?>
    67                                         <button type="button" class="button customize-theme"><?php _e( 'Customize' ); ?></button>
    68                                 </h3>
    69 
     107                                                <div class="filtered-by">
     108                                                        <span><?php _e( 'Filtering by:' ); ?></span>
     109                                                        <div class="tags"></div>
     110                                                        <button type="button" class="button-link"><?php _e( 'Edit' ); ?></a>
     111                                                </div>
     112                                        </div>
     113                                <# } #>
    70114                                <div class="theme-overlay" tabindex="0" role="dialog" aria-label="<?php esc_attr_e( 'Theme Details' ); ?>"></div>
    71 
    72                                 <div id="customize-container"></div>
    73                                 <?php if ( count( $this->controls ) > 4 ) : ?>
    74                                         <p><label for="themes-filter">
    75                                                 <span class="screen-reader-text"><?php _e( 'Search installed themes&hellip;' ); ?></span>
    76                                                 <input type="text" id="themes-filter" placeholder="<?php esc_attr_e( 'Search installed themes&hellip;' ); ?>" />
    77                                         </label></p>
    78                                 <?php endif; ?>
    79115                                <div class="theme-browser rendered">
    80                                         <ul class="themes accordion-section-content">
     116                                        <div class="error unexpected-error" style="display: none; "><p><?php _e( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ); ?></p></div>
     117                                        <ul class="themes">
    81118                                        </ul>
     119                                        <p class="no-themes"><?php _e( 'No themes found. Try a different search.' ); ?></p>
     120                                        <p class="spinner"></p>
    82121                                </div>
    83122                        </div>
    84123                </li>