Ticket #37661: 37661.4.diff
File 37661.4.diff, 82.1 KB (added by , 8 years ago) |
---|
-
src/wp-admin/css/customize-controls.css
271 271 } 272 272 273 273 #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 { 276 275 -webkit-transform: none; 277 276 -ms-transform: none; 278 277 transform: none; 279 278 } 280 279 281 #customize-theme-controls .customize-themes-panel.customize-pane-child,282 280 .section-open #customize-theme-controls .customize-pane-parent, 283 281 .in-sub-panel #customize-theme-controls .customize-pane-parent, 284 282 .section-open #customize-info, 285 283 .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 { 289 285 visibility: hidden; 290 286 height: 0; 291 287 overflow: hidden; … … 296 292 297 293 .section-open #customize-theme-controls .customize-pane-parent.busy, 298 294 .in-sub-panel #customize-theme-controls .customize-pane-parent.busy, 299 .in-themes-panel #customize-theme-controls .customize-pane-parent.busy,300 295 .section-open #customize-info.busy, 301 296 .in-sub-panel #customize-info.busy, 302 .in-themes-panel #customize-info.busy,303 297 .busy.section-open.in-sub-panel #customize-theme-controls .customize-pane-child.current-panel, 304 298 #customize-theme-controls .customize-pane-child.open, 305 299 #customize-theme-controls .customize-pane-child.current-panel, … … 309 303 overflow: auto; 310 304 } 311 305 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 319 306 #customize-theme-controls .customize-pane-child.accordion-section-content, 320 307 #customize-theme-controls .customize-pane-child.accordion-sub-container { 321 308 display: block; … … 996 983 animation: customize-reload .75s; 997 984 } 998 985 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 { 1001 992 cursor: default; 1002 993 background: #fff; 1003 994 color: #555; … … 1004 995 border-top: 1px solid #ddd; 1005 996 border-bottom: 1px solid #ddd; 1006 997 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 */ 1008 1001 } 1009 1002 1010 1003 #customize-theme-controls .control-section-themes .customize-themes-panel .accordion-section-title:first-child:hover, /* Not a focusable element. */ … … 1012 1005 border-top: 0; 1013 1006 } 1014 1007 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, 1030 1009 #customize-controls .customize-section-title span.customize-action { 1031 1010 font-size: 13px; 1032 1011 display: block; … … 1033 1012 font-weight: 400; 1034 1013 } 1035 1014 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 { 1038 1016 position: absolute; 1039 1017 right: 10px; 1040 1018 top: 50%; … … 1042 1020 font-weight: 400; 1043 1021 } 1044 1022 1045 #customize- controls .control-section-themes .accordion-section-title:before{1023 #customize-theme-controls .control-panel-themes > .accordion-section-title:after { 1046 1024 display: none; 1047 1025 } 1048 1026 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; 1055 1040 } 1056 1041 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; 1059 1044 } 1060 1045 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; 1064 1051 } 1065 1052 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 { 1067 1061 padding: 15px 8px 0 8px; 1068 1062 } 1069 1063 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; 1071 1133 background: transparent; 1072 display: block; 1134 border: none; 1135 box-shadow: none; 1136 cursor: pointer; 1137 color: #555; 1073 1138 } 1074 1139 1075 .c ustomize-control.customize-control-theme{1076 margin-bottom: 8px;1140 .control-panel-themes .wp-filter .customize-help-toggle:hover { 1141 color: #0073aa; 1077 1142 } 1078 1143 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 1079 1223 #customize-theme-controls .themes.accordion-section-content { 1080 1224 position: relative; 1081 1225 left: 0; … … 1083 1227 width: 100%; 1084 1228 } 1085 1229 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; 1088 1240 } 1089 1241 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%; 1091 1272 margin: 0; 1092 width: 100%;1093 1273 } 1094 1274 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 1095 1336 .wp-customizer .theme-browser .theme .theme-actions { 1096 1337 -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; 1097 1338 opacity: 1; … … 1112 1353 width: 100%; 1113 1354 } 1114 1355 1115 .control-section-themes .accordion-section-title:after, 1116 .customize-themes-panel .accordion-section-title:after { 1356 #accordion-panel-themes .accordion-section-title:after { 1117 1357 display: none; 1118 1358 } 1119 1359 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; 1122 1362 } 1123 1363 1364 1124 1365 /* Details View */ 1125 1366 .wp-customizer .theme-overlay { 1126 1367 display: none; … … 1141 1382 z-index: 110; 1142 1383 } 1143 1384 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 1144 1394 .wp-customizer .theme-overlay .theme-wrap { 1145 1395 left: 90px; 1146 1396 right: 90px; … … 1151 1401 } 1152 1402 1153 1403 .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; 1155 1406 } 1156 1407 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 1157 1421 .ie8 .wp-customizer .theme-overlay .theme-header, 1158 1422 .ie8 .wp-customizer .theme-overlay .theme-about, 1159 1423 .ie8 .wp-customizer .theme-overlay .theme-actions { -
src/wp-admin/includes/theme.php
606 606 * @since 4.2.0 607 607 */ 608 608 function 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. 610 612 $preview_url = str_replace( '__THEME__', '{{ data.id }}', $preview_url ); 611 613 ?> 612 614 <script type="text/html" id="tmpl-customize-themes-details-view"> … … 619 621 </div> 620 622 <div class="theme-about wp-clearfix"> 621 623 <div class="theme-screenshots"> 622 <# if ( data.screenshot [0] ) { #>624 <# if ( data.screenshot && data.screenshot[0] ) { #> 623 625 <div class="screenshot"><img src="{{ data.screenshot[0] }}" alt="" /></div> 624 626 <# } else { #> 625 627 <div class="screenshot blank"></div> … … 632 634 <# } #> 633 635 <h2 class="theme-name">{{{ data.name }}}<span class="theme-version"><?php printf( __( 'Version: %s' ), '{{ data.version }}' ); ?></span></h2> 634 636 <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 635 652 <p class="theme-description">{{{ data.description }}}</p> 636 653 637 654 <# if ( data.parent ) { #> 638 655 <p class="parent-theme"><?php printf( __( 'This is a child theme of %s.' ), '<strong>{{{ data.parent }}}</strong>' ); ?></p> 639 656 <# } #> 640 641 657 <# 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> 643 659 <# } #> 644 660 </div> 645 661 </div> 646 662 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> 658 682 </div> 659 683 </script> 660 684 <?php -
src/wp-admin/js/customize-controls.js
2 2 (function( exports, $ ){ 3 3 var Container, focus, normalizedTransitionendEventName, api = wp.customize; 4 4 5 window.pagenow = 'customize'; // Needed for updates.js to function properly. 6 5 7 /** 6 8 * A Customizer Setting. 7 9 * … … 866 868 /** 867 869 * wp.customize.ThemesSection 868 870 * 869 * Custom section for themes that functions similarly to a backwards panel,870 * and alsohandles 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. 871 873 * 872 874 * @constructor 873 875 * @augments wp.customize.Section … … 879 881 template: '', 880 882 screenshotQueue: null, 881 883 $window: $( window ), 884 loaded: 0, 885 loading: false, 886 fullyLoaded: false, 887 term: '', 882 888 883 889 /** 884 890 * @since 4.2.0 885 891 */ 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.0893 */894 892 ready: function () { 895 893 var section = this; 896 894 section.overlay = section.container.find( '.theme-overlay' ); … … 918 916 } 919 917 }); 920 918 921 _.bindAll( this, 'renderScreenshots' );919 _.bindAll( this, 'renderScreenshots', 'loadMore', 'checkTerm', 'filtersChecked', 'clearFilters' ); 922 920 }, 923 921 924 922 /** … … 925 923 * Override Section.isContextuallyActive method. 926 924 * 927 925 * Ignore the active states' of the contained theme controls, and just 928 * use the section's own active state instead. This ensures empty search929 * results for theme s to causethe 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. 930 928 * 931 929 * @since 4.2.0 932 930 * … … 942 940 attachEvents: function () { 943 941 var section = this; 944 942 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 ) { 955 946 section.expand(); 956 947 } 957 948 }); 958 949 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' ); 964 953 965 event.preventDefault(); // Keep this AFTER the key filter above954 $( '.wp-full-overlay' ).addClass( 'customize-loading' ); 966 955 956 window.parent.location = previewUrl; 957 }); 958 959 // Theme navigation in details view. 960 section.container.on( 'click', '.left', function( event ) { 967 961 section.previousTheme(); 968 962 }); 969 963 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 ) { 977 965 section.nextTheme(); 978 966 }); 979 967 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 ) { 987 969 section.closeDetails(); 988 970 }); 989 971 990 972 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 ) { 992 974 var count, 993 975 term = event.currentTarget.value.toLowerCase().trim().replace( '-', ' ' ), 994 976 controls = section.controls(); … … 1001 983 1002 984 // Update theme count. 1003 985 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 ); 1005 987 }); 1006 988 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(); 1014 996 } 1015 997 }); 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' ) ); 1016 1029 }); 1017 1030 }, 1018 1031 … … 1037 1050 } 1038 1051 1039 1052 // 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' ); 1046 1056 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 1048 1064 // Collapse any sibling sections/panels 1049 1065 api.section.each( function ( otherSection ) { 1050 if ( otherSection !== panel) {1066 if ( otherSection !== section ) { 1051 1067 otherSection.collapse( { duration: args.duration } ); 1052 1068 } 1053 1069 }); 1054 api.panel.each( function ( otherPanel ) {1055 otherPanel.collapse( { duration: 0 } );1056 });1057 1070 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 }, 1061 1088 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 }, 1065 1097 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; 1070 1105 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 } 1073 1109 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 } 1078 1119 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 } 1081 1140 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. 1084 1186 } 1085 } );1187 _.delay( section.renderScreenshots, 100 ); // Wait for the controls to become visible. 1086 1188 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 } 1089 1241 } 1090 1242 }, 1091 1243 1092 1244 /** 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 /** 1093 1345 * Render control's screenshot if the control comes into view. 1094 1346 * 1095 1347 * @since 4.2.0 … … 1097 1349 renderScreenshots: function( ) { 1098 1350 var section = this; 1099 1351 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 }); 1103 1358 } 1104 1359 1105 // Are all screenshots rendered ?1360 // Are all screenshots rendered (for now)? 1106 1361 if ( ! section.screenshotQueue.length ) { 1107 1362 return; 1108 1363 } … … 1138 1393 }, 1139 1394 1140 1395 /** 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 /** 1141 1408 * Advance the modal to the next theme. 1142 1409 * 1143 1410 * @since 4.2.0 … … 1157 1424 * @since 4.2.0 1158 1425 */ 1159 1426 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 ); 1162 1429 next = control.container.next( 'li.customize-control-theme' ); 1163 1430 if ( ! next.length ) { 1164 1431 return false; 1165 1432 } 1166 next = next[0].id.replace( 'customize-control- ', '' );1433 next = next[0].id.replace( 'customize-control-theme-' + section.params.action, section.params.action + '_theme' ); 1167 1434 control = api.control( next ); 1168 1435 1169 1436 return control.params.theme; … … 1189 1456 * @since 4.2.0 1190 1457 */ 1191 1458 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 ); 1194 1461 previous = control.container.prev( 'li.customize-control-theme' ); 1195 1462 if ( ! previous.length ) { 1196 1463 return false; 1197 1464 } 1198 previous = previous[0].id.replace( 'customize-control- ', '' );1465 previous = previous[0].id.replace( 'customize-control-theme-' + section.params.action, section.params.action + '_theme' ); 1199 1466 control = api.control( previous ); 1200 1467 1201 1468 return control.params.theme; … … 1243 1510 closeDetails: function () { 1244 1511 $( 'body' ).removeClass( 'modal-open' ); 1245 1512 this.overlay.fadeOut( 'fast' ); 1246 api.control( 'theme_' + this.currentTheme).focus();1513 api.control( this.params.action + '_theme_' + this.currentTheme ).container.find( '.theme' ).focus(); 1247 1514 }, 1248 1515 1249 1516 /** … … 1323 1590 } 1324 1591 if ( ! panel.contentContainer.parent().is( panel.headContainer ) ) { 1325 1592 container.append( panel.contentContainer ); 1326 panel.renderContent();1327 1593 } 1594 panel.renderContent(); 1328 1595 1329 1596 panel.deferred.embedded.resolve(); 1330 1597 }, … … 1513 1780 } 1514 1781 }); 1515 1782 1783 1516 1784 /** 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 /** 1517 2083 * A Customizer Control. 1518 2084 * 1519 2085 * A control provides a UI element that allows a user to modify a Customizer Setting. … … 2831 3397 api.ThemeControl = api.Control.extend({ 2832 3398 2833 3399 touchDrag: false, 2834 isRendered: false,3400 screenshotRendered: false, 2835 3401 2836 3402 /** 2837 * Defer rendering the theme control until the section is displayed.2838 *2839 3403 * @since 4.2.0 2840 3404 */ 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.02862 */2863 3405 ready: function() { 2864 3406 var control = this; 2865 3407 … … 2879 3421 } 2880 3422 2881 3423 // 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' ) ) { 2883 3425 return; 2884 3426 } 2885 3427 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 above2899 2900 3428 api.section( control.section() ).showDetails( control.params.theme ); 2901 3429 }); 2902 3430 … … 2907 3435 if ( source ) { 2908 3436 $screenshot.attr( 'src', source ); 2909 3437 } 3438 control.screenshotRendered = true; 2910 3439 }); 2911 3440 }, 2912 3441 2913 3442 /** 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. 2915 3444 * 2916 3445 * @since 4.2.0 2917 3446 */ … … 2927 3456 } else { 2928 3457 control.deactivate(); 2929 3458 } 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' ); 2930 3476 } 2931 3477 }); 2932 3478 … … 3490 4036 background: api.BackgroundControl, 3491 4037 theme: api.ThemeControl 3492 4038 }; 3493 api.panelConstructor = {}; 4039 api.panelConstructor = { 4040 themes: api.ThemesPanel 4041 }; 3494 4042 api.sectionConstructor = { 3495 4043 themes: api.ThemesSection 3496 4044 }; … … 4085 4633 // Collapse the most granular expanded object. 4086 4634 collapsedObject = expandedControls[0] || expandedSections[0] || expandedPanels[0]; 4087 4635 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 } 4088 4646 collapsedObject.collapse(); 4089 4647 event.preventDefault(); 4090 4648 } -
src/wp-admin/js/updates.js
179 179 if ( $notice.length ) { 180 180 $notice.replaceWith( $adminNotice ); 181 181 } 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 } 183 187 } 184 188 185 189 $document.trigger( 'wp-updates-notice-added' ); … … 907 911 if ( 'themes-network' === pagenow ) { 908 912 $notice = $( '[data-slug="' + args.slug + '"]' ).find( '.update-message' ).removeClass( 'notice-error' ).addClass( 'updating-message notice-warning' ).find( 'p' ); 909 913 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 910 924 } else { 911 925 $notice = $( '#update-theme' ).closest( '.notice' ).removeClass( 'notice-large' ); 912 926 … … 949 963 }, 950 964 $notice, newText; 951 965 966 if ( 'customize' === pagenow ) { 967 $theme = wp.customize.control( 'installed_theme_' + response.slug ).container; 968 } 969 952 970 if ( 'themes-network' === pagenow ) { 953 971 $notice = $theme.find( '.update-message' ); 954 972 … … 1003 1021 return; 1004 1022 } 1005 1023 1024 if ( 'customize' === pagenow ) { 1025 $theme = wp.customize.control( 'installed_theme_' + response.slug ).container; 1026 } 1027 1006 1028 if ( 'themes-network' === pagenow ) { 1007 1029 $notice = $theme.find( '.update-message ' ); 1008 1030 } else { … … 1139 1161 return; 1140 1162 } 1141 1163 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 } 1145 1172 } 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 } 1148 1180 } 1149 1181 1150 1182 $button -
src/wp-includes/class-wp-customize-manager.php
230 230 231 231 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menus-panel.php' ); 232 232 233 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-themes-panel.php' ); 233 234 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-themes-section.php' ); 234 235 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-sidebar-section.php' ); 235 236 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-section.php' ); … … 289 290 290 291 add_action( 'wp_ajax_customize_save', array( $this, 'save' ) ); 291 292 add_action( 'wp_ajax_customize_refresh_nonces', array( $this, 'refresh_nonces' ) ); 293 add_action( 'wp_ajax_customize-load-themes', array( $this, 'load_themes_ajax' ) ); 292 294 293 295 add_action( 'customize_register', array( $this, 'register_controls' ) ); 294 296 add_action( 'customize_register', array( $this, 'register_dynamic_settings' ), 11 ); // allow code to create settings first … … 302 304 303 305 // Export the settings to JS via the _wpCustomizeSettings variable. 304 306 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 } 305 313 } 306 314 307 315 /** … … 1626 1634 foreach ( $this->controls as $control ) { 1627 1635 $control->enqueue(); 1628 1636 } 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 } 1629 1640 } 1630 1641 1631 1642 /** … … 1779 1790 $nonces = array( 1780 1791 'save' => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ), 1781 1792 'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() ), 1793 'customize-themes' => wp_create_nonce( 'customize-themes' ), 1782 1794 ); 1783 1795 1784 1796 /** … … 1859 1871 'autofocus' => $this->get_autofocus(), 1860 1872 'documentTitleTmpl' => $this->get_document_title_template(), 1861 1873 '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 ), 1862 1879 ); 1863 1880 1864 1881 // Prepare Customize Section objects to pass to JavaScript. … … 1962 1979 1963 1980 /* Panel, Section, and Control Types */ 1964 1981 $this->register_panel_type( 'WP_Customize_Panel' ); 1982 $this->register_panel_type( 'WP_Customize_Themes_Panel' ); 1965 1983 $this->register_section_type( 'WP_Customize_Section' ); 1966 1984 $this->register_section_type( 'WP_Customize_Sidebar_Section' ); 1985 $this->register_section_type( 'WP_Customize_Themes_Section' ); 1967 1986 $this->register_control_type( 'WP_Customize_Color_Control' ); 1968 1987 $this->register_control_type( 'WP_Customize_Media_Control' ); 1969 1988 $this->register_control_type( 'WP_Customize_Upload_Control' ); … … 1973 1992 $this->register_control_type( 'WP_Customize_Site_Icon_Control' ); 1974 1993 $this->register_control_type( 'WP_Customize_Theme_Control' ); 1975 1994 1976 /* Themes */1995 /* Themes (controls are loaded via ajax) */ 1977 1996 1978 $this->add_ section( new WP_Customize_Themes_Section( $this, 'themes', array(1997 $this->add_panel( new WP_Customize_Themes_Panel( $this, 'themes', array( 1979 1998 '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.' ), 1980 2000 'capability' => 'switch_themes', 1981 2001 'priority' => 0, 1982 2002 ) ) ); 1983 2003 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', 1986 2007 'capability' => 'switch_themes', 2008 'panel' => 'themes', 2009 'priority' => 0, 1987 2010 ) ) ); 1988 2011 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 ) ) ); 1990 2019 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 ) ) ); 1992 2027 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 ) ) ); 2004 2035 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…' ), 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 ) ) ); 2010 2064 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 }2019 2065 2020 2066 /* Site Identity */ 2021 2067 … … 2343 2389 } 2344 2390 2345 2391 /** 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 /** 2346 2527 * Callback for validating the header_textcolor value. 2347 2528 * 2348 2529 * Accepts 'blank', and otherwise uses sanitize_hex_color_no_hash(). -
src/wp-includes/customize/class-wp-customize-theme-control.php
67 67 $preview_url = esc_url( add_query_arg( 'theme', '__THEME__', $current_url ) ); // Token because esc_url() strips curly braces. 68 68 $preview_url = str_replace( '__THEME__', '{{ data.theme.id }}', $preview_url ); 69 69 ?> 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"> 72 72 <# } 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"> 74 74 <# } #> 75 75 76 <# if ( data.theme.screenshot [0] ) { #>76 <# if ( data.theme.screenshot && data.theme.screenshot[0] ) { #> 77 77 <div class="theme-screenshot"> 78 78 <img data-src="{{ data.theme.screenshot[0] }}" alt="" /> 79 79 </div> … … 81 81 <div class="theme-screenshot blank"></div> 82 82 <# } #> 83 83 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> 88 89 <# } #> 89 90 90 <div class="theme-author"><?php printf( __( 'By %s' ), '{{ data.theme.author }}' ); ?></div> 91 92 <# if ( data.theme.isActiveTheme ) { #> 91 <# if ( data.theme.active ) { #> 93 92 <h3 class="theme-name" id="{{ data.theme.id }}-name"> 94 93 <?php 95 94 /* translators: %s: theme name */ 96 printf( __( '<span> Active:</span> %s' ), '{{{ data.theme.name }}}' );95 printf( __( '<span>Current:</span> %s' ), '{{ data.theme.name }}' ); 97 96 ?> 98 97 </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> 99 106 <# } 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> 101 108 <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> 103 111 </div> 104 <# } #> 112 <# } #> 105 113 </div> 106 114 <?php 107 115 } -
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 */ 17 class 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…' ); ?></span> 119 <input type="text" id="themes-filter" placeholder="<?php esc_attr_e( 'Search installed themes…' ); ?>" /> 120 </label> 121 </p> 122 <?php endif; ?> 123 </li> 124 <?php 125 } 126 } -
src/wp-includes/customize/class-wp-customize-themes-section.php
10 10 /** 11 11 * Customize Themes Section class. 12 12 * 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. 14 14 * 15 15 * @since 4.2.0 16 16 * … … 28 28 public $type = 'themes'; 29 29 30 30 /** 31 * Render the themes section, which behaves like a panel.31 * Theme section action. 32 32 * 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 34 61 * @access protected 35 62 */ 36 protected function render() { 37 $classes = 'accordion-section control-section control-section-' . $this->type; 63 protected function render_template() { 38 64 ?> 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> 60 91 <?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>'; 65 105 } 66 106 ?> 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 <# } #> 70 114 <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…' ); ?></span>76 <input type="text" id="themes-filter" placeholder="<?php esc_attr_e( 'Search installed themes…' ); ?>" />77 </label></p>78 <?php endif; ?>79 115 <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’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"> 81 118 </ul> 119 <p class="no-themes"><?php _e( 'No themes found. Try a different search.' ); ?></p> 120 <p class="spinner"></p> 82 121 </div> 83 122 </div> 84 123 </li>