Ticket #37661: 37661.6.diff
File 37661.6.diff, 86.4 KB (added by , 9 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; … … 406 393 display: block; 407 394 float: left; 408 395 width: 48px; 409 height: 7 1px;396 height: 70px; 410 397 padding: 0 24px 0 0; 411 398 margin: 0; 412 399 background: #fff; … … 420 407 } 421 408 422 409 .customize-section-back { 423 height: 7 4px;410 height: 73px; 424 411 } 425 412 426 413 .ios .customize-panel-back { … … 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 .customize-themes-full-container { 1028 position: fixed; 1029 top: 0; 1030 left: 0; 1031 transition: .18s left ease-in-out; 1032 margin: 0 0 0 300px; 1033 padding:25px; 1034 overflow-y: scroll; 1035 width: calc(100% - 350px); 1036 height: calc(100% - 50px); 1037 background: #eee; 1038 z-index: 10; 1055 1039 } 1056 1040 1057 #customize-controls .customize-themes-panel .accordion-section-title:first-child { 1058 margin-top: 0; 1041 /* Animations for opening the themes panel */ 1042 #customize-header-actions .save, 1043 #customize-header-actions .spinner, 1044 #customize-header-actions .customize-controls-preview-toggle { 1045 position: relative; 1046 top: 0; 1047 transition: .18s top ease-in-out; 1059 1048 } 1060 1049 1061 #customize-controls .customize-themes-panel .accordion-section-title:nth-child(2) { 1050 #customize-footer-actions, 1051 #customize-footer-actions .collapse-sidebar { 1052 bottom: 0; 1053 transition: .18s bottom ease-in-out; 1054 } 1055 1056 .in-themes-panel:not( '.animating' ) #customize-header-actions .save, 1057 .in-themes-panel:not( '.animating' ) #customize-header-actions .spinner, 1058 .in-themes-panel:not( '.animating' ) #customize-header-actions .customize-controls-preview-toggle, 1059 .in-themes-panel:not( '.animating' ) #customize-preview, 1060 .in-themes-panel:not( '.animating' ) #customize-footer-actions { 1061 visibility: hidden; 1062 } 1063 1064 .in-themes-panel #customize-header-actions .save, 1065 .in-themes-panel #customize-header-actions .spinner, 1066 .in-themes-panel #customize-header-actions .customize-controls-preview-toggle { 1067 top: -45px; 1068 } 1069 1070 .in-themes-panel #customize-footer-actions, 1071 .in-themes-panel #customize-footer-actions .collapse-sidebar { 1072 bottom: -45px; 1073 } 1074 1075 /* Don't show the theme count while the panel opens, as it's in the wrong place during the animation */ 1076 .animating .control-panel-themes .filter-theme-count { 1077 display: none; 1078 } 1079 1080 .in-themes-panel.wp-full-overlay .wp-full-overlay-sidebar-content { 1081 bottom: 0; 1082 } 1083 1084 @keyframes themes-fade-in { 1085 0% { 1086 opacity: 0; 1087 } 1088 100% { 1089 opacity: 1; 1090 } 1091 } 1092 1093 .control-panel-themes .customize-themes-full-container.animate { 1094 animation: .5s themes-fade-in 1; 1095 } 1096 1097 .control-panel-themes .filter-themes-count { 1098 position: fixed; 1099 top: 0; 1100 left: 48px; 1101 width: 222px; 1102 padding: 6px 15px; 1103 margin: 0; 1104 line-height: 32px; 1105 text-align: right; 1106 z-index: 10; 1107 } 1108 1109 .control-panel-themes .filter-themes-count .themes-displayed { 1110 font-weight: 600; 1111 color: #555d66; 1112 } 1113 1114 .control-panel-themes .filter-themes-count .see-themes, 1115 .control-panel-themes .filter-themes-count .filter-themes { 1116 display: none; 1117 } 1118 1119 1120 /* Mobile - toggle between themes and filters */ 1121 @media screen and (max-width:600px) { 1122 .control-panel-themes .filter-themes-count { 1123 width: calc(100% - 93px); 1124 } 1125 1126 .control-panel-themes .filter-themes-count .themes-displayed { 1127 display: none; 1128 } 1129 1130 .wp-full-overlay:not(.showing-themes) .control-panel-themes .filter-themes-count .see-themes { 1131 display: block; 1132 float: right; 1133 } 1134 1135 .wp-full-overlay.showing-themes .control-panel-themes .filter-themes-count .filter-themes { 1136 display: block; 1137 float: right; 1138 } 1139 1140 .control-panel-themes .customize-themes-full-container { 1141 width: calc(100% - 50px); 1142 margin: 0; 1143 top: 46px; 1144 height: calc(100% - 96px); 1145 z-index: 1; 1146 display: none; 1147 } 1148 1149 .showing-themes .control-panel-themes .customize-themes-full-container { 1150 display: block; 1151 } 1152 } 1153 1154 .control-panel-themes .customize-themes-notifications .notice { 1155 margin: 0 0 25px 0; 1156 } 1157 1158 .customize-themes-full-container .customize-themes-section { 1159 display: none !important; /* There is unknown JS that perpetually tries to show all theme sections when more items are added. */ 1160 overflow: hidden; 1161 } 1162 1163 .customize-themes-full-container .customize-themes-section.current-section { 1164 display: list-item !important; /* There is unknown JS that perpetually tries to show all theme sections when more items are added. */ 1165 } 1166 1167 .theme-section .customize-themes-text-before { 1168 padding: 0 0 8px 15px; 1169 margin: 15px 0 0 0; 1170 line-height: 16px; 1171 border-bottom: 1px solid #ddd; 1172 color: #555d66; 1173 } 1174 1175 .control-panel-themes .customize-themes-section-title { 1176 width: 100%; 1177 background: #fff; 1178 box-shadow: none; 1179 outline: none; 1180 border-top: none; 1181 border-bottom: 1px solid #ddd; 1182 border-left: 4px solid #fff; 1183 border-right: none; 1184 cursor: pointer; 1185 padding: 10px 15px; 1186 position: relative; 1187 text-align: left; 1062 1188 font-size: 14px; 1063 1189 font-weight: 600; 1190 color: #555d66; 1191 text-shadow: none; 1064 1192 } 1065 1193 1066 #customize-controls .customize-themes-panel > h2 { 1067 padding: 15px 8px 0 8px; 1194 .control-panel-themes .theme-section { 1195 margin: 0; 1196 position: relative; 1068 1197 } 1069 1198 1070 #customize-theme-controls .customize-themes-panel .accordion-section-content { 1199 .control-panel-themes .customize-themes-section-title:focus, 1200 .control-panel-themes .customize-themes-section-title:hover { 1201 border-left-color: #0073aa; 1202 color: #0073aa; 1203 background: #f5f5f5; 1204 } 1205 1206 .control-panel-themes .theme-section .customize-themes-section-title.selected:after { 1207 content: "\f147"; 1208 font: 16px/1 dashicons; 1209 box-sizing: border-box; 1210 width: 20px; 1211 height: 20px; 1212 padding: 3px 3px 1px 1px; /* Re-align the icon to the smaller grid */ 1213 border-radius: 100%; 1214 position: absolute; 1215 right: 15px; 1216 background: #0073aa; 1217 color: #fff; 1218 } 1219 1220 .control-panel-themes .customize-themes-section-title.selected { 1221 color: #0073aa; 1222 } 1223 1224 .control-panel-themes .customize-themes-section-title.themes-section-search_themes { 1225 border-left: none; 1226 padding: 5px 50px 5px 15px; 1227 width: auto; 1228 } 1229 1230 .control-panel-themes .customize-themes-section-title.themes-section-search_themes:after { 1231 content: "\f179"; 1232 font: 20px/1 dashicons; 1233 position: absolute; 1234 right: 15px; 1235 bottom: 11px; 1236 } 1237 1238 .control-panel-themes .customize-themes-section-title.themes-section-feature_filter_themes:after, 1239 .control-panel-themes .customize-themes-section-title.themes-section-favorites_themes:after { 1240 content: "\f140"; 1241 font: 20px/1 dashicons; 1242 position: absolute; 1243 right: 15px; 1244 top: 8px; 1245 } 1246 1247 .control-panel-themes .customize-themes-section-title.themes-section-search_themes .wp-filter-search { 1248 width: 100%; 1249 } 1250 1251 .control-panel-themes .customize-themes-section-title.themes-section-search_themes.selected, 1252 .control-panel-themes .customize-themes-section-title.themes-section-search_themes:hover { 1253 background: #fff; 1254 cursor: default; 1255 } 1256 1257 .control-panel-themes .customize-themes-section-title.themes-section-feature_filter_themes { 1258 margin-top: 15px; 1259 border-top: 1px solid #ddd; 1260 } 1261 1262 .control-panel-themes .filter-details { 1263 background: #f5f5f5; 1264 margin: 0; 1265 padding: 8px 15px; 1266 border-top: none; 1267 border-bottom: 1px solid #ddd; 1268 display: none; 1269 } 1270 1271 .control-panel-themes .customize-themes-section-title.selected.details-open { 1272 border-bottom-color: #f5f5f5; 1273 background: #f5f5f5; 1274 } 1275 1276 .control-panel-themes .favorites-form.filter-details label { 1277 padding-bottom: 6px; 1278 display: inline-block; 1279 } 1280 1281 .control-panel-themes .filter-details .filter-group { 1282 float: none; 1283 width: 100%; 1071 1284 background: transparent; 1072 display: block; 1285 border: none; 1286 padding: 5px 0; 1287 box-shadow: none; 1073 1288 } 1074 1289 1075 .customize-control.customize-control-theme { 1076 margin-bottom: 8px; 1290 .control-panel-themes .filter-details .filter-group legend button { 1291 padding: 8px 15px 6px 15px; 1292 line-height: 14px; 1293 border-bottom: 1px solid #ccc; 1077 1294 } 1078 1295 1296 .control-panel-themes .filter-details .filter-group legend { 1297 position: relative; 1298 top: 0; 1299 } 1300 1301 .control-panel-themes .filter-details .filter-group legend button:after { 1302 content: "\f140"; 1303 font: 20px/1 dashicons; 1304 position: relative; 1305 top: 4px; 1306 margin-left: 0px; 1307 } 1308 1309 .control-panel-themes .filter-details .filter-group legend button:hover, 1310 .control-panel-themes .filter-details .filter-group legend button:focus { 1311 color: #0073aa; 1312 border-bottom-color: #0073aa; /* Color change for focus style should be acceptable because border-bottom is barely visible previously. */ 1313 outline: none; 1314 box-shadow: none; 1315 } 1316 1317 .control-panel-themes .filter-details .filter-group legend button.open:after { 1318 content: "\f142"; 1319 top: 5px; 1320 } 1321 1322 .control-panel-themes .filter-details .filter-group .filter-group-feature { 1323 display: none; 1324 margin: 4px 0 0 15px; 1325 } 1326 1079 1327 #customize-theme-controls .themes.accordion-section-content { 1080 1328 position: relative; 1081 1329 left: 0; … … 1083 1331 width: 100%; 1084 1332 } 1085 1333 1086 .wp-customizer .theme-browser .themes { 1087 padding-bottom: 8px; 1334 .customize-themes-section.loading .spinner { 1335 display: block; 1336 visibility: visible; 1337 position: relative; 1338 clear: both; 1339 width: 20px; 1340 height: 20px; 1341 left: calc(50% - 10px); 1342 float: none; 1343 margin-top: 50px; 1088 1344 } 1089 1345 1090 .wp-customizer .theme-browser .theme { 1346 .customize-themes-section .filter-drawer { 1347 border-top: none; 1348 display: block; 1349 background: transparent; 1350 padding-top: 5px; 1351 } 1352 1353 .customize-themes-section .clear-filters { 1354 margin-left: 8px; 1355 display: none; 1356 } 1357 1358 .customize-themes-section .no-themes { 1359 display: none; 1360 } 1361 1362 .themes-section-installed_themes .theme .notice-success { 1363 display: none; /* Hide "installed" notice on installed themes tab. */ 1364 } 1365 1366 .control-panel-themes .theme-browser .theme .theme-actions .button-primary { 1367 margin: 0 0 0 8px; 1368 } 1369 1370 .customize-control-theme .theme { 1371 width: 100%; 1091 1372 margin: 0; 1092 width: 100%;1093 1373 } 1094 1374 1375 .customize-control.customize-control-theme { /* override most properties on .customize-control */ 1376 box-sizing: border-box; 1377 width: 18.4%; 1378 margin: 0 2% 2% 0; 1379 padding: 0; 1380 clear: none; 1381 } 1382 1383 /* 5 columns above 2100px */ 1384 @media screen and (min-width: 2101px) { 1385 .customize-control.customize-control-theme:nth-child(5n) { 1386 margin-right: 0; 1387 } 1388 } 1389 1390 /* 4 columns up to 2100px */ 1391 @media screen and (min-width: 1601px) and (max-width: 2100px) { 1392 .customize-control.customize-control-theme { 1393 width: 23.5%; 1394 } 1395 1396 .customize-control.customize-control-theme:nth-child(4n) { 1397 margin-right: 0; 1398 } 1399 } 1400 1401 /* 3 columns up to 1600px */ 1402 @media screen and (min-width: 1201px) and (max-width: 1600px) { 1403 .customize-control.customize-control-theme { 1404 width: 32%; 1405 } 1406 1407 .customize-control.customize-control-theme:nth-child(3n) { 1408 margin-right: 0; 1409 } 1410 } 1411 1412 /* 2 columns up to 1200px */ 1413 @media screen and (min-width: 851px) and (max-width: 1200px) { 1414 .customize-control.customize-control-theme { 1415 width: 49%; 1416 } 1417 1418 .customize-control.customize-control-theme:nth-child(even) { 1419 margin-right: 0; 1420 } 1421 } 1422 1423 /* 1 column up to 850 px */ 1424 @media screen and (max-width: 850px) { 1425 .customize-control.customize-control-theme { 1426 width: 100%; 1427 margin: 0 0 3% 0; 1428 } 1429 } 1430 1431 .wp-customizer .theme-browser .themes { 1432 padding-bottom: 8px; 1433 } 1434 1095 1435 .wp-customizer .theme-browser .theme .theme-actions { 1096 -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";1097 1436 opacity: 1; 1098 1437 } 1099 1438 … … 1112 1451 width: 100%; 1113 1452 } 1114 1453 1115 .control-section-themes .accordion-section-title:after,1116 .customize-themes-panel .accordion-section-title:after {1117 display: none;1118 }1119 1120 .customize-themes-panel.control-panel-content {1121 border-top: 1px solid #ddd;1122 }1123 1124 1454 /* Details View */ 1125 1455 .wp-customizer .theme-overlay { 1126 1456 display: none; … … 1135 1465 z-index: 109; 1136 1466 } 1137 1467 1468 /* Avoid a z-index war by resetting elements that should be under the overlay. 1469 This is likely required because of the way that sections and panels are positioned. */ 1470 .wp-customizer.modal-open #customize-header-actions, 1471 .wp-customizer.modal-open .control-panel-themes .filter-themes-count, 1472 .wp-customizer.modal-open .control-panel-themes .customize-themes-section-title.selected:after { 1473 z-index: -1; 1474 } 1475 1138 1476 .wp-customizer .theme-overlay .theme-backdrop { 1139 1477 background: rgba( 238, 238, 238, 0.75 ); 1140 1478 position: fixed; … … 1141 1479 z-index: 110; 1142 1480 } 1143 1481 1482 .wp-customizer .theme-overlay .star-rating { 1483 float: left; 1484 margin-right: 8px; 1485 } 1486 1487 .wp-customizer .theme-rating .num-ratings { 1488 line-height: 20px; 1489 } 1490 1144 1491 .wp-customizer .theme-overlay .theme-wrap { 1145 1492 left: 90px; 1146 1493 right: 90px; … … 1147 1494 top: 45px; 1148 1495 bottom: 45px; 1149 1496 z-index: 120; 1150 max-width: 1740px; /* To ensure that theme screenshots are not displayed larger than 880px wide. */1151 1497 } 1152 1498 1153 1499 .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. */ 1500 text-align: right; /* Because there're only one or two actions, match the UI pattern of media modals and right-align the action. */ 1501 padding: 10px 15px; 1155 1502 } 1156 1503 1504 .wp-customizer .theme-overlay .theme-actions .theme-install.preview { 1505 margin-left: 8px; 1506 } 1507 1508 .control-panel-themes .theme-actions .delete-theme { 1509 left: 15px; /* these override themes.css on mobile */ 1510 right: auto; 1511 bottom: auto; 1512 position: absolute; 1513 } 1514 1515 .modal-open .in-themes-panel #customize-controls .wp-full-overlay-sidebar-content { 1516 overflow: visible; /* Prevent the top-level Customizer controls from becoming visible when elements on the right of the details modal are focused. */ 1517 } 1518 1157 1519 .ie8 .wp-customizer .theme-overlay .theme-header, 1158 1520 .ie8 .wp-customizer .theme-overlay .theme-about, 1159 1521 .ie8 .wp-customizer .theme-overlay .theme-actions { -
src/wp-admin/css/themes.css
570 570 float: left; 571 571 margin: 0 30px 0 0; 572 572 width: 55%; 573 max-width: 880px;573 max-width: 1200px; /* Recommended theme screenshot width, set here to avoid stretching */ 574 574 text-align: center; 575 575 } 576 576 -
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: '', 888 filterContainer: $(), 882 889 883 890 /** 884 891 * @since 4.2.0 885 892 */ 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 893 ready: function () { 895 894 var section = this; 896 895 section.overlay = section.container.find( '.theme-overlay' ); … … 918 917 } 919 918 }); 920 919 921 _.bindAll( this, 'renderScreenshots' );920 _.bindAll( this, 'renderScreenshots', 'loadMore', 'checkTerm', 'filtersChecked' ); 922 921 }, 923 922 924 923 /** … … 925 924 * Override Section.isContextuallyActive method. 926 925 * 927 926 * 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.927 * use the section's own active state instead. This prevents empty search 928 * results for theme sections from causing the section to become inactive. 930 929 * 931 930 * @since 4.2.0 932 931 * … … 942 941 attachEvents: function () { 943 942 var section = this; 944 943 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 944 section.filterContainer = $( '#accordion-section-' + section.id ); 951 945 952 if ( section.expanded() ) { 953 section.collapse(); 954 } else { 946 // Expand section/panel. Only collapse when opening another section. 947 section.filterContainer.on( 'click', 'button.customize-themes-section-title', function( event ) { 948 // Open the section. 949 if ( ! section.expanded() ) { 955 950 section.expand(); 956 951 } 957 });958 952 959 // Theme navigation in details view. 960 section.container.on( 'click keydown', '.left', function( event ) { 961 if ( api.utils.isKeydownButNotEnterEvent( event ) ) { 962 return; 953 // Toggle filters. 954 if ( section.filterContainer.find( '.filter-details' ).length ) { 955 section.filterContainer.find( '.customize-themes-section-title' ).toggleClass( 'details-open' ) 956 .attr('aria-expanded', function ( i, attr ) { 957 return attr === 'true' ? 'false' : 'true'; 958 }); 959 section.filterContainer.find( '.filter-details' ).slideToggle( 180 ); 963 960 } 961 }); 964 962 965 event.preventDefault(); // Keep this AFTER the key filter above 963 // Preview installed themes. 964 section.container.on( 'click', '.theme-actions .preview-theme', function() { 965 var previewUrl = $( this ).data( 'previewUrl' ); 966 966 967 $( '.wp-full-overlay' ).addClass( 'customize-loading' ); 968 969 window.parent.location = previewUrl; 970 }); 971 972 // Theme navigation in details view. 973 section.container.on( 'click', '.left', function( event ) { 967 974 section.previousTheme(); 968 975 }); 969 976 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 977 section.container.on( 'click', '.right', function( event ) { 977 978 section.nextTheme(); 978 979 }); 979 980 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 981 section.container.on( 'click', '.theme-backdrop, .close', function( event ) { 987 982 section.closeDetails(); 988 983 }); 989 984 990 985 var renderScreenshots = _.throttle( _.bind( section.renderScreenshots, this ), 100 ); 991 section.container.on( 'input', '#themes-filter', function( event ) { 986 987 // Only used when there is only one section - installed themes. 988 $( '.control-panel-themes' ).on( 'input', '#themes-filter', function( event ) { 992 989 var count, 993 990 term = event.currentTarget.value.toLowerCase().trim().replace( '-', ' ' ), 994 991 controls = section.controls(); … … 1000 997 renderScreenshots(); 1001 998 1002 999 // Update theme count. 1003 count = section.cont ainer.find( 'li.customize-control:visible' ).length;1004 section.container.find( '.theme-count' ).text( count );1000 count = section.contentContainer.find( 'li.customize-control:visible' ).length; 1001 $( '.control-panel-themes' ).find( '.theme-count' ).text( count ); 1005 1002 }); 1006 1003 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;1004 // Event listeners for queries with user-entered terms. 1005 if ( 'search' === section.params.action ) { 1006 var debounced = _.debounce( section.checkTerm, 500 ); // Wait until there is no input for 500 miliseconds to initiate a search. 1007 $( '.control-panel-themes' ).on( 'input', '#wp-filter-search-input', function() { 1008 debounced( section ); 1009 if ( ! section.expanded() ) { 1010 section.expand(); 1014 1011 } 1015 1012 }); 1013 1014 // Focus the input if the icon is clicked. 1015 section.filterContainer.find( '.search-form' ).on( 'click', function( e ) { 1016 if ( ! $( e.currentTarget ).hasClass( 'wp-filter-search' ) ) { 1017 $( e.currentTarget ).find( '.wp-filter-search' ).focus(); 1018 } 1019 }); 1020 } else if ( 'favorites' === section.params.action ) { 1021 section.container.on( 'click', '.favorites-form-submit', function() { 1022 section.checkTerm( section ); 1023 }); 1024 section.container.on( 'keydown', '#wporg-username-input', function( e ) { 1025 if ( api.utils.isKeydownButNotEnterEvent( e ) ) { 1026 return; 1027 } 1028 section.checkTerm( section ); 1029 }); 1030 } else if ( 'feature_filter' === section.params.action ) { 1031 section.container.on( 'click', '.filter-group input', function() { 1032 section.filtersChecked(); 1033 section.checkTerm( section ); 1034 }); 1035 1036 // Toggle feature filter sections. 1037 section.container.on( 'click', '.filter-group legend button', function( e ) { 1038 $( e.currentTarget ).toggleClass( 'open' ).attr('aria-expanded', function ( i, attr ) { 1039 return attr === 'true' ? 'false' : 'true'; 1040 }) 1041 .parent().next( '.filter-group-feature' ).slideToggle( 180 ); 1042 }); 1043 } 1044 1045 // Move section controls to the themes area. 1046 api.bind( 'ready', function () { 1047 section.contentContainer = section.container.find( '.customize-themes-section' ); 1048 section.contentContainer.appendTo( $( '.customize-themes-full-container' ) ); 1049 section.container.add( section.filterContainer ); 1016 1050 }); 1017 1051 }, 1018 1052 … … 1037 1071 } 1038 1072 1039 1073 // 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' ); 1074 var section = this, 1075 container = section.contentContainer.closest( '.customize-themes-full-container' ); 1046 1076 1047 if ( expanded && ! section.hasClass( 'current-panel' ) ) { 1077 if ( expanded ) { 1078 1079 // Load controls if none are loaded yet. 1080 if ( 0 === section.loaded ) { 1081 section.loadControls(); 1082 } 1083 1048 1084 // Collapse any sibling sections/panels 1049 1085 api.section.each( function ( otherSection ) { 1050 if ( otherSection !== panel) {1086 if ( otherSection !== section ) { 1051 1087 otherSection.collapse( { duration: args.duration } ); 1052 1088 } 1053 1089 }); 1054 api.panel.each( function ( otherPanel ) {1055 otherPanel.collapse( { duration: 0 } );1056 });1057 1090 1058 panel._animateChangeExpanded( function() { 1059 changeBtn.attr( 'tabindex', '-1' ); 1060 customizeBtn.attr( 'tabindex', '0' ); 1091 section.contentContainer.addClass( 'current-section' ); 1092 section.filterContainer.find( '.customize-themes-section-title' ).addClass( 'selected' ); 1061 1093 1062 customizeBtn.focus(); 1063 section.css( 'top', '' ); 1064 container.scrollTop( 0 ); 1094 container.on( 'scroll', _.throttle( section.renderScreenshots, 300 ) ); 1095 container.on( 'scroll', _.throttle( section.loadMore, 300 ) ); 1065 1096 1066 if ( args.completeCallback ) { 1067 args.completeCallback(); 1068 } 1069 } ); 1097 if ( args.completeCallback ) { 1098 args.completeCallback(); 1099 } 1100 section.updateCount(); // Show this section's count. 1101 } else { 1102 section.contentContainer.removeClass( 'current-section' ); 1070 1103 1071 overlay.addClass( 'in-themes-panel' ); 1072 section.addClass( 'current-panel' ); 1104 // Always hide, even if they don't exist or are already hidden. 1105 section.filterContainer.find( '.customize-themes-section-title' ).removeClass( 'selected details-open' ).attr( 'aria-expanded', 'false' ); 1106 section.filterContainer.find( '.filter-details' ).slideUp( 180 ); 1073 1107 1074 } else if ( ! expanded && section.hasClass( 'current-panel' ) ) { 1075 panel._animateChangeExpanded( function() { 1076 changeBtn.attr( 'tabindex', '0' ); 1077 customizeBtn.attr( 'tabindex', '-1' ); 1108 container.off( 'scroll' ); 1078 1109 1079 changeBtn.focus(); 1080 section.css( 'top', '' ); 1110 if ( args.completeCallback ) { 1111 args.completeCallback(); 1112 } 1113 } 1114 }, 1081 1115 1082 if ( args.completeCallback ) { 1083 args.completeCallback(); 1116 /** 1117 * Return the section's content element without detachng from the parent. 1118 * 1119 * @since 4.7.0 1120 */ 1121 getContent: function() { 1122 return this.container.find( '.control-section-content' ); 1123 }, 1124 1125 /** 1126 * Load theme data via ajax and add themes to the section as controls. 1127 * 1128 * @since 4.7.0 1129 */ 1130 loadControls: function() { 1131 var section = this, params, page, request, search; 1132 1133 if ( section.loading ) { 1134 return; // We're already loading a batch of themes. 1135 } 1136 1137 // Parameters for every API query. Additional params are set in PHP. 1138 page = Math.ceil( section.loaded / 100 ) + 1; 1139 params = { 1140 'customize-themes-nonce': api.settings.nonce['customize-themes'], 1141 'wp_customize': 'on', 1142 'theme_action': section.params.action, 1143 'customized_theme': api.settings.theme.stylesheet, 1144 'page': page 1145 } 1146 1147 // Add fields for special request actions. 1148 if ( 'search' === section.params.action ) { 1149 if ( '' === section.term ) { 1150 return; 1151 } else { 1152 params.search = section.term; 1153 } 1154 } else if ( 'favorites' === section.params.action ) { 1155 if ( '' === section.term ) { 1156 return; 1157 } else { 1158 params.user = section.term; 1159 } 1160 } else if ( 'feature_filter' === section.params.action ) { 1161 if ( '' === section.term ) { 1162 return; 1163 } else { 1164 params.tags = section.term; 1165 } 1166 } 1167 1168 // Load themes. 1169 section.container.addClass( 'loading' ); 1170 section.loading = true; 1171 section.container.find( '.no-themes' ).hide(); 1172 request = wp.ajax.post( 'customize-load-themes', params ); 1173 request.done(function( data ) { 1174 var themes = data.themes, 1175 themeControl, newThemeControls; 1176 if ( 0 !== themes.length ) { 1177 newThemeControls = new Array(); 1178 // Add controls for each theme. 1179 _.each( themes, function ( theme ) { 1180 customizeId = section.params.action + '_theme_' + theme.id; 1181 themeControl = new api.controlConstructor.theme( customizeId, { 1182 params: { 1183 type: 'theme', 1184 content: '<li id="customize-control-theme-' + section.params.action + '_' + theme.id + '" class="customize-control customize-control-theme"></li>', 1185 section: section.params.id, 1186 active: true, 1187 theme: theme, 1188 priority: section.loaded + 1 1189 }, 1190 previewer: api.previewer 1191 } ); 1192 1193 api.control.add( customizeId, themeControl ); 1194 newThemeControls.push( themeControl ); 1195 section.loaded = section.loaded + 1; 1196 return; 1197 }); 1198 1199 if ( 1 === page ) { 1200 // Pre-load the first 3 theme screenshots. 1201 _.each( section.controls().slice( 0, 3 ), function ( control ) { 1202 var img, src = control.params.theme.screenshot[0]; 1203 if ( src ) { 1204 img = new Image(); 1205 img.src = src; 1206 } 1207 }); 1208 if ( 'search' === section.params.action ) { 1209 wp.a11y.speak( api.settings.l10n.themeSearchResults.replace( '%d', data.info.results ) ); 1210 } 1211 } else { 1212 Array.prototype.push.apply( section.screenshotQueue, newThemeControls ); // Add new themes to the screenshot queue. 1084 1213 } 1085 } );1214 _.delay( section.renderScreenshots, 100 ); // Wait for the controls to become visible. 1086 1215 1087 overlay.removeClass( 'in-themes-panel' ); 1088 section.removeClass( 'current-panel' ); 1216 if ( 'installed' === section.action || 100 > themes.length ) { // If we have less than the requested 100 themes, it's the end of the list. 1217 section.fullyLoaded = true; 1218 } 1219 } else { 1220 if ( 0 === section.loaded ) { 1221 section.container.find( '.no-themes' ).show(); 1222 wp.a11y.speak( section.container.find( '.no-themes' ).text() ); 1223 } else { 1224 section.fullyLoaded = true; 1225 } 1226 } 1227 if ( 'installed' === section.params.action ) { 1228 section.updateCount(); 1229 } else { 1230 section.updateCount( data.info.results ); 1231 } 1232 section.container.find( '.unexpected-error' ).hide(); // Hide error notice in case it was previously shown. 1233 1234 // This cannot run on request.always, as section.loading may turn false before the new controls load in the success case. 1235 section.container.removeClass( 'loading' ); 1236 section.loading = false; 1237 }); 1238 request.fail(function( data ) { 1239 if ( 'undefined' === typeof data ) { 1240 section.container.find( '.unexpected-error' ).show(); 1241 wp.a11y.speak( section.container.find( '.unexpected-error' ).text() ); 1242 } else if ( typeof console !== 'undefined' && console.error ) { 1243 console.error( data ); 1244 } 1245 1246 // This cannot run on request.always, as section.loading may turn false before the new controls load in the success case. 1247 section.container.removeClass( 'loading' ); 1248 section.loading = false; 1249 }); 1250 }, 1251 1252 /** 1253 * Determines whether more themes should be loaded, and loads them. 1254 * 1255 * @since 4.7.0 1256 */ 1257 loadMore: function() { 1258 var section = this, container, bottom, threshold, page; 1259 if ( ! section.fullyLoaded && ! section.loading ) { 1260 container = section.container.closest( '.customize-themes-full-container' ); 1261 1262 bottom = container.scrollTop() + container.height(); 1263 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. 1264 1265 if ( bottom > threshold ) { 1266 section.loadControls(); 1267 } 1089 1268 } 1090 1269 }, 1091 1270 1092 1271 /** 1272 * Event handler for search, feature filter, and favorites input that determines if the term has changed and loads new controls as needed. 1273 * 1274 * @since 4.7.0 1275 * 1276 * @param api.ThemesSection section The current theme section, passed through the debouncer. 1277 */ 1278 checkTerm: function( section ) { 1279 var newTerm, filteringBy; 1280 1281 // Find term. 1282 if ( 'search' === section.params.action ) { 1283 newTerm = $( '#wp-filter-search-input' ).val(); 1284 } else if ( 'favorites' === section.params.action ) { 1285 newTerm = $( '#wporg-username-input' ).val(); 1286 } else if ( 'feature_filter' === section.params.action ) { 1287 newTerm = section.term; // Set separately by filtersChecked(), as they're changed. 1288 if ( '' === newTerm ) { 1289 return; 1290 } 1291 } else { 1292 return; 1293 } 1294 1295 if ( section.term === newTerm && 'feature_filter' !== section.params.action ) { 1296 return; 1297 } 1298 // Clear the controls in the section. 1299 _.each( section.controls(), function( control ) { 1300 control.container.remove(); 1301 api.control.remove( control.id ); 1302 }); 1303 section.loaded = 0; 1304 section.fullyLoaded = false; 1305 section.screenshotQueue = null; 1306 1307 if ( '' !== newTerm ) { // Empty term should not show any results. 1308 // Run a new query, with loadControls handling paging, etc. 1309 section.term = newTerm; 1310 section.loadControls(); 1311 } 1312 }, 1313 1314 /** 1315 * Check for filters checked in the feature filter list. 1316 * 1317 * @since 4.7.0 1318 */ 1319 filtersChecked: function() { 1320 var section = this, 1321 items = section.container.find( '.filter-group' ).find( ':checkbox' ), 1322 tags = []; 1323 1324 if ( 'feature_filter' !== section.params.action ) { 1325 return false; 1326 } 1327 1328 _.each( items.filter( ':checked' ), function( item ) { 1329 tags.push( $( item ).prop( 'value' ) ); 1330 }); 1331 1332 // When no filters are checked, restore initial state and return 1333 if ( tags.length === 0 ) { 1334 section.term = ''; 1335 } else { 1336 section.term = tags; 1337 } 1338 }, 1339 1340 /** 1093 1341 * Render control's screenshot if the control comes into view. 1094 1342 * 1095 1343 * @since 4.2.0 … … 1097 1345 renderScreenshots: function( ) { 1098 1346 var section = this; 1099 1347 1100 // Fill queue initially. 1101 if ( section.screenshotQueue === null ) { 1102 section.screenshotQueue = section.controls(); 1348 // Fill queue initially, or check for more if empty. 1349 if ( section.screenshotQueue === null || 0 === section.screenshotQueue.length ) { 1350 // Add controls that haven't had their screenshots rendered. 1351 section.screenshotQueue = _.filter( section.controls(), function( control ) { 1352 return ! control.screenshotRendered; 1353 }); 1103 1354 } 1104 1355 1105 // Are all screenshots rendered ?1356 // Are all screenshots rendered (for now)? 1106 1357 if ( ! section.screenshotQueue.length ) { 1107 1358 return; 1108 1359 } … … 1138 1389 }, 1139 1390 1140 1391 /** 1392 * Update the number of themes in the section. 1393 * 1394 * @since 4.7.0 1395 */ 1396 updateCount: function ( count ) { 1397 if ( ! count ) { 1398 count = this.loaded; 1399 } 1400 this.container.closest( '.control-panel-content' ).find( '.theme-count' ).text( count ); 1401 }, 1402 1403 /** 1141 1404 * Advance the modal to the next theme. 1142 1405 * 1143 1406 * @since 4.2.0 … … 1157 1420 * @since 4.2.0 1158 1421 */ 1159 1422 getNextTheme: function () { 1160 var control, next;1161 control = api.control( 'theme_' + this.currentTheme );1423 var section = this, control, next; 1424 control = api.control( section.params.action + '_theme_' + this.currentTheme ); 1162 1425 next = control.container.next( 'li.customize-control-theme' ); 1163 1426 if ( ! next.length ) { 1164 1427 return false; 1165 1428 } 1166 next = next[0].id.replace( 'customize-control- ', '' );1429 next = next[0].id.replace( 'customize-control-theme-' + section.params.action, section.params.action + '_theme' ); 1167 1430 control = api.control( next ); 1168 1431 1169 1432 return control.params.theme; … … 1189 1452 * @since 4.2.0 1190 1453 */ 1191 1454 getPreviousTheme: function () { 1192 var control, previous;1193 control = api.control( 'theme_' + this.currentTheme );1455 var section = this, control, previous; 1456 control = api.control( section.params.action + '_theme_' + this.currentTheme ); 1194 1457 previous = control.container.prev( 'li.customize-control-theme' ); 1195 1458 if ( ! previous.length ) { 1196 1459 return false; 1197 1460 } 1198 previous = previous[0].id.replace( 'customize-control- ', '' );1461 previous = previous[0].id.replace( 'customize-control-theme-' + section.params.action, section.params.action + '_theme' ); 1199 1462 control = api.control( previous ); 1200 1463 1201 1464 return control.params.theme; … … 1243 1506 closeDetails: function () { 1244 1507 $( 'body' ).removeClass( 'modal-open' ); 1245 1508 this.overlay.fadeOut( 'fast' ); 1246 api.control( 'theme_' + this.currentTheme).focus();1509 api.control( this.params.action + '_theme_' + this.currentTheme ).container.find( '.theme' ).focus(); 1247 1510 }, 1248 1511 1249 1512 /** … … 1323 1586 } 1324 1587 if ( ! panel.contentContainer.parent().is( panel.headContainer ) ) { 1325 1588 container.append( panel.contentContainer ); 1326 panel.renderContent();1327 1589 } 1590 panel.renderContent(); 1328 1591 1329 1592 panel.deferred.embedded.resolve(); 1330 1593 }, … … 1513 1776 } 1514 1777 }); 1515 1778 1779 1516 1780 /** 1781 * wp.customize.ThemesPanel 1782 * 1783 * Custom section for themes that displays without the customize preview. 1784 * 1785 * @constructor 1786 * @augments wp.customize.Panel 1787 * @augments wp.customize.Container 1788 */ 1789 api.ThemesPanel = api.Panel.extend({ 1790 installingThemes: [], 1791 1792 /** 1793 * @since 4.7.0 1794 */ 1795 attachEvents: function () { 1796 var panel = this; 1797 1798 // Attach regular panel events. 1799 api.Panel.prototype.attachEvents.apply( this ); 1800 1801 // Collapse panel to customize the current theme. 1802 panel.contentContainer.on( 'click', '.customize-theme', function( event ) { 1803 panel.collapse(); 1804 }); 1805 1806 // Toggle between filtering and browsing themes on mobile. 1807 panel.contentContainer.on( 'click', '.see-themes, .filter-themes', function( event ) { 1808 $( '.wp-full-overlay' ).toggleClass( 'showing-themes' ); 1809 }); 1810 1811 // Hide unsaved changes notice on save. 1812 api.bind( 'saved', function() { 1813 panel.container.find( '.customize-themes-unsaved-changes' ).hide(); 1814 }); 1815 1816 // Save & publish customized settings. 1817 panel.contentContainer.on( 'click', '#customize-themes-save', function() { 1818 $( '#save' ).click(); // Trigger customizer save. 1819 panel.container.find( '.customize-themes-unsaved-changes' ).hide(); 1820 api.section( 'installed_themes' ).focus(); 1821 }); 1822 1823 // Install (and maybe preview) a theme. 1824 panel.contentContainer.on( 'click', '.theme-install', function( event ) { 1825 panel.installTheme( event ); 1826 }); 1827 1828 // Update a theme. Theme cards have the class, the details modal has the id. 1829 panel.contentContainer.on( 'click', '.update-theme, #update-theme', function( event ) { 1830 // #update-theme is a link. 1831 event.preventDefault(); 1832 event.stopPropagation(); 1833 1834 panel.updateTheme( event ); 1835 }); 1836 1837 // Delete a theme. 1838 panel.contentContainer.on( 'click', '.delete-theme', function( event ) { 1839 panel.deleteTheme( event ); 1840 }); 1841 1842 _.bindAll( this, 'installTheme', 'updateTheme' ); 1843 1844 // Move the themes container after the theme section headers. 1845 panel.contentContainer.find( '.customize-themes-full-container-container' ).appendTo( panel.contentContainer ); 1846 }, 1847 1848 /** 1849 * Update UI to reflect expanded state 1850 * 1851 * @since 4.7.0 1852 * 1853 * @param {Boolean} expanded 1854 * @param {Object} args 1855 * @param {Boolean} args.unchanged 1856 * @param {Callback} args.completeCallback 1857 */ 1858 onChangeExpanded: function ( expanded, args ) { 1859 1860 // Expand/collapse the panel normally. 1861 api.Panel.prototype.onChangeExpanded.apply( this, [ expanded, args ] ); 1862 1863 // Immediately call the complete callback if there were no changes 1864 if ( args.unchanged ) { 1865 if ( args.completeCallback ) { 1866 args.completeCallback(); 1867 } 1868 return; 1869 } 1870 1871 // Note: there is a second argument 'args' passed 1872 var panel = this, 1873 overlay = panel.headContainer.closest( '.wp-full-overlay' ); 1874 1875 if ( expanded ) { 1876 // Move the themes container after the theme section headers. Only needs to happen the first time, no harm doing it again. 1877 panel.contentContainer.find( '.customize-themes-full-container-container' ).appendTo( panel.contentContainer ); 1878 1879 overlay.addClass( 'in-themes-panel' ) 1880 .delay( 200 ).find( '.customize-themes-full-container' ).addClass( 'animate' ); 1881 1882 if ( false === api.state( 'saved' ).get() ) { 1883 panel.container.find( '.customize-themes-unsaved-changes' ).show(); 1884 } 1885 1886 // Automatically open the installed themes section. 1887 api.section( 'installed_themes' ).expand(); 1888 } else { 1889 overlay.removeClass( 'in-themes-panel' ) 1890 .find( '.customize-themes-full-container' ).removeClass( 'animate' ); 1891 } 1892 }, 1893 1894 /** 1895 * Install a theme via wp.updates. 1896 * 1897 * @since 4.7.0 1898 */ 1899 installTheme: function( event ) { 1900 var preview = false, previewUrl, 1901 slug = $( event.target ).data( 'slug' ); 1902 1903 if ( -1 !== $.inArray( this.installingThemes, slug ) ) { 1904 return; // Theme is already being installed. 1905 } 1906 1907 wp.updates.maybeRequestFilesystemCredentials( event ); 1908 1909 $( document ).on( 'wp-theme-install-success', function( event, response ) { 1910 var theme = false, customizeId, themeControl; 1911 if ( preview ) { 1912 window.parent.location = previewUrl; 1913 } else { 1914 api.control.each( function( control ) { 1915 if ( 'theme' === control.params.type && control.params.theme.id === response.slug ) { 1916 theme = control.params.theme; // Used below to add theme control. 1917 control.rerenderAsInstalled( true ); 1918 } 1919 }); 1920 1921 // Don't add the same theme more than once. 1922 if ( ! theme || 'undefined' !== typeof api.control( 'installed_theme_' + theme.id ) ) { 1923 return; 1924 } 1925 1926 // Add theme control to installed section. 1927 theme.type = 'installed'; 1928 customizeId = 'installed_theme_' + theme.id; 1929 themeControl = new api.controlConstructor.theme( customizeId, { 1930 params: { 1931 type: 'theme', 1932 content: '<li id="customize-control-theme-installed_' + theme.id + '" class="customize-control customize-control-theme"></li>', 1933 section: 'installed_themes', 1934 active: true, 1935 theme: theme, 1936 priority: 0 // Add all newly-installed themes to the top. 1937 }, 1938 previewer: api.previewer 1939 } ); 1940 1941 api.control.add( customizeId, themeControl ); 1942 api.control( customizeId ).container.trigger( 'render-screenshot' ); 1943 1944 // Close the details modal if it's open to the installed theme. 1945 api.section.each( function( section ) { 1946 if ( 'themes' !== section.params.type ) { 1947 if ( theme.id === section.currentTheme ) { // Don't close the modal if the user has navigated elsewhere. 1948 section.closeDetails(); 1949 } 1950 } 1951 }); 1952 } 1953 } ); 1954 1955 $( document ).on( 'wp-theme-install-failure', function( event, response ) { 1956 if ( preview ) { 1957 $( '.wp-full-overlay' ).removeClass( 'customize-loading' ); 1958 } 1959 }); 1960 1961 this.installingThemes.push( $( event.target ).data( 'slug' ) ); // Note: we don't remove elements from installingThemes, since they shouldn't be installed again. 1962 wp.updates.installTheme( { 1963 slug: $( event.target ).data( 'slug' ) 1964 } ); 1965 1966 // Also preview the theme as the event is triggered on Install & Preview. 1967 if ( $( event.target ).hasClass( 'preview' ) ) { 1968 preview = true; 1969 $( '.wp-full-overlay' ).addClass( 'customize-loading' ); 1970 previewUrl = $( event.target ).data( 'previewurl' ); 1971 } 1972 }, 1973 1974 /** 1975 * Update a theme via wp.updates. 1976 * 1977 * @since 4.7.0 1978 */ 1979 updateTheme: function( event ) { 1980 wp.updates.maybeRequestFilesystemCredentials( event ); 1981 1982 $( document ).on( 'wp-theme-update-success', function( event, response ) { 1983 // Rerender the control to reflect the update. 1984 api.control.each( function( control ) { 1985 if ( 'theme' === control.params.type && control.params.theme.id === response.slug ) { 1986 control.params.theme.hasUpdate = false; 1987 control.rerenderAsInstalled( true ); 1988 } 1989 }); 1990 } ); 1991 1992 wp.updates.updateTheme( { 1993 slug: $( event.target ).closest( '.notice' ).data( 'slug' ) 1994 } ); 1995 }, 1996 1997 /** 1998 * Delete a theme via wp.updates. 1999 * 2000 * @since 4.7.0 2001 */ 2002 deleteTheme: function( event ) { 2003 var panel = this, 2004 theme = $( event.target ).data( 'slug' ), 2005 section = api.section( 'installed_themes' ); 2006 2007 event.preventDefault(); 2008 2009 // Confirmation dialog for deleting a theme. 2010 if ( ! window.confirm( api.settings.l10n.confirmDeleteTheme ) ) { 2011 return; 2012 } 2013 2014 wp.updates.maybeRequestFilesystemCredentials( event ); 2015 2016 $( document ).one( 'wp-theme-delete-success', function( event, response ) { 2017 var control = api.control( 'installed_theme_' + theme ); 2018 2019 // Remove theme control. 2020 control.container.remove(); 2021 api.control.remove( control.id ); 2022 2023 // Update installed count. 2024 section.loaded = section.loaded - 1; 2025 section.updateCount(); 2026 2027 // Rerender any other theme controls as uninstalled. 2028 api.control.each( function( control ) { 2029 if ( 'theme' === control.params.type && control.params.theme.id === theme ) { 2030 control.rerenderAsInstalled( false ); 2031 } 2032 }); 2033 } ); 2034 2035 wp.updates.deleteTheme( { 2036 slug: theme 2037 } ); 2038 2039 // Close modal and focus the section. 2040 section.closeDetails(); 2041 section.focus(); 2042 } 2043 2044 }); 2045 2046 2047 /** 1517 2048 * A Customizer Control. 1518 2049 * 1519 2050 * A control provides a UI element that allows a user to modify a Customizer Setting. … … 2831 3362 api.ThemeControl = api.Control.extend({ 2832 3363 2833 3364 touchDrag: false, 2834 isRendered: false,3365 screenshotRendered: false, 2835 3366 2836 3367 /** 2837 * Defer rendering the theme control until the section is displayed.2838 *2839 3368 * @since 4.2.0 2840 3369 */ 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 3370 ready: function() { 2864 3371 var control = this; 2865 3372 … … 2879 3386 } 2880 3387 2881 3388 // Prevent the modal from showing when the user clicks the action button. 2882 if ( $( event.target ).is( '.theme-actions .button ' ) ) {3389 if ( $( event.target ).is( '.theme-actions .button, .update-theme' ) ) { 2883 3390 return; 2884 3391 } 2885 3392 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 3393 api.section( control.section() ).showDetails( control.params.theme ); 2901 3394 }); 2902 3395 … … 2907 3400 if ( source ) { 2908 3401 $screenshot.attr( 'src', source ); 2909 3402 } 3403 control.screenshotRendered = true; 2910 3404 }); 2911 3405 }, 2912 3406 2913 3407 /** 2914 * Show or hide the theme based on the presence of the term in the title, description, and author.3408 * Show or hide the theme based on the presence of the term in the title, description, tags, and author. 2915 3409 * 2916 3410 * @since 4.2.0 2917 3411 */ … … 2927 3421 } else { 2928 3422 control.deactivate(); 2929 3423 } 3424 }, 3425 3426 /** 3427 * Rerender the theme from its JS template with the installed type. 3428 * 3429 * @since 4.7.0 3430 */ 3431 rerenderAsInstalled: function( installed ) { 3432 var control = this, section; 3433 if ( installed ) { 3434 control.params.theme.type = 'installed'; 3435 } else { 3436 section = api.section( control.params.section ); 3437 control.params.theme.type = section.params.action; 3438 } 3439 control.renderContent(); // replaces existing content 3440 control.container.trigger( 'render-screenshot' ); 2930 3441 } 2931 3442 }); 2932 3443 … … 3490 4001 background: api.BackgroundControl, 3491 4002 theme: api.ThemeControl 3492 4003 }; 3493 api.panelConstructor = {}; 4004 api.panelConstructor = { 4005 themes: api.ThemesPanel 4006 }; 3494 4007 api.sectionConstructor = { 3495 4008 themes: api.ThemesSection 3496 4009 }; … … 4085 4598 // Collapse the most granular expanded object. 4086 4599 collapsedObject = expandedControls[0] || expandedSections[0] || expandedPanels[0]; 4087 4600 if ( collapsedObject ) { 4601 if ( 'themes' === collapsedObject.params.type ) { 4602 // Themes panel or section. 4603 if ( $( 'body' ).hasClass( 'modal-open' ) ) { 4604 collapsedObject.closeDetails(); 4605 } else { 4606 // If we're collapsing a section, collapse the panel also. 4607 wp.customize.panel( 'themes' ).collapse(); 4608 } 4609 return; 4610 } 4088 4611 collapsedObject.collapse(); 4089 4612 event.preventDefault(); 4090 4613 } -
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 /** … … 1617 1625 foreach ( $this->controls as $control ) { 1618 1626 $control->enqueue(); 1619 1627 } 1628 if ( ! is_multisite() && ( current_user_can( 'install_themes' ) || current_user_can( 'update_themes' ) || current_user_can( 'delete_themes' ) ) ) { 1629 wp_enqueue_script( 'updates' ); 1630 } 1620 1631 } 1621 1632 1622 1633 /** … … 1770 1781 $nonces = array( 1771 1782 'save' => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ), 1772 1783 'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() ), 1784 'customize-themes' => wp_create_nonce( 'customize-themes' ), 1773 1785 ); 1774 1786 1775 1787 /** … … 1850 1862 'autofocus' => $this->get_autofocus(), 1851 1863 'documentTitleTmpl' => $this->get_document_title_template(), 1852 1864 'previewableDevices' => $this->get_previewable_devices(), 1865 'l10n' => array( 1866 'confirmDeleteTheme' => __( 'Are you sure you want to delete this theme?' ), 1867 /* translators: %d is the number of theme search results, which cannot consider singular vs. plural forms */ 1868 'themeSearchResults' => __( '%d themes found' ), 1869 ), 1853 1870 ); 1854 1871 1855 1872 // Prepare Customize Section objects to pass to JavaScript. … … 1953 1970 1954 1971 /* Panel, Section, and Control Types */ 1955 1972 $this->register_panel_type( 'WP_Customize_Panel' ); 1973 $this->register_panel_type( 'WP_Customize_Themes_Panel' ); 1956 1974 $this->register_section_type( 'WP_Customize_Section' ); 1957 1975 $this->register_section_type( 'WP_Customize_Sidebar_Section' ); 1976 $this->register_section_type( 'WP_Customize_Themes_Section' ); 1958 1977 $this->register_control_type( 'WP_Customize_Color_Control' ); 1959 1978 $this->register_control_type( 'WP_Customize_Media_Control' ); 1960 1979 $this->register_control_type( 'WP_Customize_Upload_Control' ); … … 1964 1983 $this->register_control_type( 'WP_Customize_Site_Icon_Control' ); 1965 1984 $this->register_control_type( 'WP_Customize_Theme_Control' ); 1966 1985 1967 /* Themes */1986 /* Themes (controls are loaded via ajax) */ 1968 1987 1969 $this->add_section( new WP_Customize_Themes_Section( $this, 'themes', array( 1970 'title' => $this->theme()->display( 'Name' ), 1971 'capability' => 'switch_themes', 1972 'priority' => 0, 1988 $this->add_panel( new WP_Customize_Themes_Panel( $this, 'themes', array( 1989 'title' => $this->theme()->display( 'Name' ), 1990 'description' => __( 'Once themes are installed, you can live-preview them on your site, customize them, and publish your new design. Browse available themes via the filters in this menu.' ), 1991 'capability' => 'switch_themes', 1992 'priority' => 0, 1973 1993 ) ) ); 1974 1994 1975 // Themes Setting (unused - the theme is considerably more fundamental to the Customizer experience). 1976 $this->add_setting( new WP_Customize_Filter_Setting( $this, 'active_theme', array( 1977 'capability' => 'switch_themes', 1995 $this->add_section( new WP_Customize_Themes_Section( $this, 'installed_themes', array( 1996 'title' => __( 'Installed' ), 1997 'text_before' => __( 'Your local site' ), 1998 'action' => 'installed', 1999 'capability' => 'switch_themes', 2000 'panel' => 'themes', 2001 'priority' => 0, 1978 2002 ) ) ); 1979 2003 1980 require_once( ABSPATH . 'wp-admin/includes/theme.php' ); 2004 $this->add_section( new WP_Customize_Themes_Section( $this, 'search_themes', array( 2005 'title' => __( 'Search themes…' ), 2006 'text_before' => __( 'Browse all WordPress.org themes' ), 2007 'action' => 'search', 2008 'capability' => 'install_themes', 2009 'panel' => 'themes', 2010 'priority' => 5, 2011 ) ) ); 1981 2012 1982 // Theme Controls. 2013 $this->add_section( new WP_Customize_Themes_Section( $this, 'featured_themes', array( 2014 'title' => __( 'Featured' ), 2015 'action' => 'featured', 2016 'capability' => 'install_themes', 2017 'panel' => 'themes', 2018 'priority' => 10, 2019 ) ) ); 1983 2020 1984 // Add a control for the active/original theme. 1985 if ( ! $this->is_theme_active() ) { 1986 $themes = wp_prepare_themes_for_js( array( wp_get_theme( $this->original_stylesheet ) ) ); 1987 $active_theme = current( $themes ); 1988 $active_theme['isActiveTheme'] = true; 1989 $this->add_control( new WP_Customize_Theme_Control( $this, $active_theme['id'], array( 1990 'theme' => $active_theme, 1991 'section' => 'themes', 1992 'settings' => 'active_theme', 1993 ) ) ); 1994 } 2021 $this->add_section( new WP_Customize_Themes_Section( $this, 'popular_themes', array( 2022 'title' => __( 'Popular' ), 2023 'action' => 'popular', 2024 'capability' => 'install_themes', 2025 'panel' => 'themes', 2026 'priority' => 15, 2027 ) ) ); 1995 2028 1996 $themes = wp_prepare_themes_for_js(); 1997 foreach ( $themes as $theme ) { 1998 if ( $theme['active'] || $theme['id'] === $this->original_stylesheet ) { 1999 continue; 2000 } 2029 $this->add_section( new WP_Customize_Themes_Section( $this, 'latest_themes', array( 2030 'title' => __( 'Latest' ), 2031 'action' => 'latest', 2032 'capability' => 'install_themes', 2033 'panel' => 'themes', 2034 'priority' => 20, 2035 ) ) ); 2001 2036 2002 $theme_id = 'theme_' . $theme['id']; 2003 $theme['isActiveTheme'] = false; 2004 $this->add_control( new WP_Customize_Theme_Control( $this, $theme_id, array( 2005 'theme' => $theme, 2006 'section' => 'themes', 2007 'settings' => 'active_theme', 2008 ) ) ); 2009 } 2037 $this->add_section( new WP_Customize_Themes_Section( $this, 'feature_filter_themes', array( 2038 'title' => __( 'Feature Filter' ), 2039 'action' => 'feature_filter', 2040 'capability' => 'install_themes', 2041 'panel' => 'themes', 2042 'priority' => 25, 2043 ) ) ); 2010 2044 2045 $this->add_section( new WP_Customize_Themes_Section( $this, 'favorites_themes', array( 2046 'title' => __( 'Favorites' ), 2047 'action' => 'favorites', 2048 'capability' => 'install_themes', 2049 'panel' => 'themes', 2050 'priority' => 30, 2051 ) ) ); 2052 2053 // Themes Setting (unused - the theme is considerably more fundamental to the Customizer experience). 2054 $this->add_setting( new WP_Customize_Filter_Setting( $this, 'active_theme', array( 2055 'capability' => 'switch_themes', 2056 ) ) ); 2057 2058 2011 2059 /* Site Identity */ 2012 2060 2013 2061 $this->add_section( 'title_tagline', array( … … 2334 2382 } 2335 2383 2336 2384 /** 2385 * Load themes into the theme browsing/installation UI. 2386 * 2387 * @since 4.7.0 2388 * @access public 2389 */ 2390 public function load_themes_ajax() { 2391 check_ajax_referer( 'customize-themes', 'customize-themes-nonce' ); 2392 2393 if ( ! current_user_can( 'switch_themes' ) ) { 2394 wp_die( -1 ); 2395 } 2396 2397 if ( empty( $_POST['theme_action'] ) ) { 2398 wp_send_json_error( 'missing_theme_action' ); 2399 } 2400 2401 if ( 'search' === $_POST['theme_action'] && ! array_key_exists( 'search', $_POST ) ) { 2402 wp_send_json_error( 'empty_search' ); 2403 } elseif ( 'favorites' === $_POST['theme_action'] && ! array_key_exists( 'user', $_POST ) ) { 2404 wp_send_json_error( 'empty_user' ); 2405 } elseif ( 'feature_filter' === $_POST['theme_action'] && ! array_key_exists( 'tags', $_POST ) ) { 2406 wp_send_json_error( 'no_features' ); 2407 } 2408 2409 require_once( ABSPATH . 'wp-admin/includes/theme.php' ); 2410 if ( 'installed' === $_POST['theme_action'] ) { 2411 $themes = array( 'themes' => wp_prepare_themes_for_js() ); 2412 foreach ( $themes['themes'] as &$theme ) { 2413 $theme['type'] = 'installed'; 2414 // Set active based on customized theme. 2415 if ( $_POST['customized_theme'] === $theme['id'] ) { 2416 $theme['active'] = true; 2417 } else { 2418 $theme['active'] = false; 2419 } 2420 } 2421 } else { 2422 if ( ! current_user_can( 'install_themes' ) ) { 2423 wp_die( -1 ); 2424 } 2425 2426 // Arguments for all queries. 2427 $args = array( 2428 'per_page' => 100, 2429 'page' => absint( $_POST['page'] ), 2430 'fields' => array( 2431 'slug' => true, 2432 'screenshot' => true, 2433 'description' => true, 2434 'requires' => true, 2435 'rating' => true, 2436 'downloaded' => true, 2437 'downloadLink' => true, 2438 'last_updated' => true, 2439 'homepage' => true, 2440 'num_ratings' => true, 2441 'tags' => true, 2442 ) 2443 ); 2444 2445 // Specialized handling for each query. 2446 switch ( $_POST['theme_action'] ) { 2447 case 'search': 2448 $args['search'] = wp_unslash( $_POST['search'] ); 2449 break; 2450 case 'favorites': 2451 $args['user'] = wp_unslash( $_POST['user'] ); 2452 case 'featured': 2453 case 'popular': 2454 $args['browse'] = $_POST['theme_action']; 2455 break; 2456 case 'latest': 2457 $args['browse'] = 'new'; 2458 break; 2459 case 'feature_filter': 2460 $args['tag'] = wp_unslash( $_POST['tags'] ); 2461 break; 2462 } 2463 2464 // Load themes from the .org API. 2465 $themes = themes_api( 'query_themes', $args ); 2466 if ( is_wp_error( $themes ) ) { 2467 wp_send_json_error(); 2468 } 2469 2470 // Prepare a list of installed themes to check against before the loop. 2471 $installed_themes = array(); 2472 $wp_themes = wp_get_themes(); 2473 foreach ( $wp_themes as $theme ) { 2474 $installed_themes[] = $theme->get_stylesheet(); 2475 } 2476 $update_php = network_admin_url( 'update.php?action=install-theme' ); 2477 foreach ( $themes->themes as &$theme ) { 2478 $theme->install_url = add_query_arg( array( 2479 'theme' => $theme->slug, 2480 '_wpnonce' => wp_create_nonce( 'install-theme_' . $theme->slug ) 2481 ), $update_php ); 2482 2483 $theme->name = wp_kses( $theme->name, $themes_allowedtags ); 2484 $theme->author = wp_kses( $theme->author, $themes_allowedtags ); 2485 $theme->version = wp_kses( $theme->version, $themes_allowedtags ); 2486 $theme->description = wp_kses( $theme->description, $themes_allowedtags ); 2487 $theme->tags = implode( ', ', $theme->tags ); 2488 $theme->stars = wp_star_rating( array( 'rating' => $theme->rating, 'type' => 'percent', 'number' => $theme->num_ratings, 'echo' => false ) ); 2489 $theme->num_ratings = number_format_i18n( $theme->num_ratings ); 2490 $theme->preview_url = set_url_scheme( $theme->preview_url ); 2491 2492 // Handle themes that are already installed as installed themes. 2493 if ( in_array( $theme->slug, $installed_themes ) ) { 2494 $theme->type = 'installed'; 2495 } else { 2496 $theme->type = $_POST['theme_action']; 2497 } 2498 2499 // Set active based on customized theme. 2500 if ( $_POST['customized_theme'] === $theme->slug ) { 2501 $theme->active = true; 2502 } else { 2503 $theme->active = false; 2504 } 2505 2506 // Map available theme properties to installed theme properties. 2507 $theme->id = $theme->slug; 2508 $theme->screenshot = array( $theme->screenshot_url ); 2509 $theme->authorAndUri = $theme->author; 2510 unset( $theme->slug ); 2511 unset( $theme->screenshot_url ); 2512 unset( $theme->author ); 2513 } 2514 } 2515 wp_send_json_success( $themes ); 2516 } 2517 2518 2519 /** 2337 2520 * Callback for validating the header_textcolor value. 2338 2521 * 2339 2522 * 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.section }}-{{ 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.section }}-{{ 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.section }}-{{ 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 ) { #> 93 <h3 class="theme-name" id="{{ data.theme.id }}-name"> 91 <# if ( data.theme.active ) { #> 92 <h3 class="theme-name" id="{{ data.section }}-{{ 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.section }}-{{ 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.section }}-{{ 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="filter-themes-count"> 74 <span class="themes-displayed"><?php 75 /* translators: %s: number of themes displayed, plural forms cannot be accomodated here so assume plurality */ 76 echo sprintf( __( 'Displaying %s themes' ), '<span class="theme-count">0</span>' ); 77 ?></span> 78 <button type="button" class="button button-primary see-themes"><?php 79 /* translators: %s: number of themes displayed, plural forms cannot be accomodated here so assume plurality */ 80 echo sprintf( __( 'See %s themes' ), '<span class="theme-count">0</span>' ); 81 ?></button> 82 <button type="button" class="button button-primary filter-themes"><?php _e( 'Filter themes' ); ?></button> 83 </li> 84 <li class="panel-meta customize-info accordion-section <# if ( ! data.description ) { #> cannot-expand<# } #>"> 85 <button class="customize-panel-back" tabindex="-1"><span class="screen-reader-text"><?php _e( 'Back' ); ?></span></button> 86 <div class="accordion-section-title"> 87 <span class="preview-notice"><?php 88 /* translators: %s: themes panel title in the Customizer */ 89 echo sprintf( __( 'You are browsing %s' ), '<strong class="panel-title">' . __( 'Themes' ) . '</strong>' ); // Separate strings for consistency with other panels. 90 ?></span> 91 <?php if ( current_user_can( 'install_themes' ) && ! is_multisite() ) : ?> 92 <# if ( data.description ) { #> 93 <button class="customize-help-toggle dashicons dashicons-editor-help" tabindex="0" aria-expanded="false"><span class="screen-reader-text"><?php _e( 'Help' ); ?></span></button> 94 <# } #> 95 <?php endif; ?> 96 </div> 97 <?php if ( current_user_can( 'install_themes' ) && ! is_multisite() ) : ?> 98 <# if ( data.description ) { #> 99 <div class="description customize-panel-description"> 100 {{{ data.description }}} 101 </div> 102 <# } #> 103 <?php endif; ?> 104 </li> 105 <li id="customize-container"></li><?php // Used as a full-screen overlay transition after clicking to preview a theme. ?> 106 <li class="customize-themes-full-container-container"> 107 <ul class="customize-themes-full-container"> 108 <li class="customize-themes-notifications"> 109 <div class="notice notice-warning customize-themes-unsaved-changes" style="display: none;"><p> 110 <?php _e( 'You have unsaved changes that will be lost if you preview a new theme.' ); ?> 111 <button type="button" id="customize-themes-save" class="button" ><?php _e( 'Save & Publish' ); ?></button> 112 </p></div> 113 </li> 114 </ul> 115 </li> 116 <?php 117 } 118 } -
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 * Text before theme section heading. 43 * 44 * @since 4.7.0 45 * @access public 46 * @var string 47 */ 48 public $text_before = ''; 49 50 /** 51 * Get section parameters for JS. 52 * 53 * @since 4.7.0 54 * @access public 55 * @return array Exported parameters. 56 */ 57 public function json() { 58 $exported = parent::json(); 59 $exported['action'] = $this->action; 60 $exported['text_before'] = $this->text_before; 61 62 return $exported; 63 } 64 65 /** 66 * Render a themes section as a JS template. 67 * 68 * The template is only rendered by PHP once, so all actions are prepared at once on the server side. 69 * 70 * @since 4.7.0 34 71 * @access protected 35 72 */ 36 protected function render() { 37 $classes = 'accordion-section control-section control-section-' . $this->type; 73 protected function render_template() { 38 74 ?> 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; 75 <li id="accordion-section-{{ data.id }}" class="theme-section"> 76 <# if ( '' !== data.text_before ) { #> 77 <p class="customize-themes-text-before">{{ data.text_before }}</p> 78 <# } #> 79 <# if ( 'search' === data.action ) { #> 80 <div class="search-form customize-themes-section-title themes-section-search_themes"> 81 <label class="screen-reader-text" for="wp-filter-search-input">{{ data.title }}</label> 82 <input placeholder="{{ data.title }}" type="search" aria-describedby="live-search-desc" id="wp-filter-search-input" class="wp-filter-search"> 83 <span id="live-search-desc" class="screen-reader-text"><?php _e( 'The search results will be updated as you type.' ); ?></span> 84 </div> 85 <# } else { #> 86 <# if ( 'favorites' === data.action || 'feature_filter' === data.action ) { 87 var attr = ' aria-expanded="false"'; 44 88 } 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"> 89 var attr = ''; 90 } #> 91 <button type="button" class="customize-themes-section-title themes-section-{{ data.id }}"{{{ attr }}}>{{ data.title }}</button> 92 <# } #> 93 <?php if ( ! current_user_can( 'install_themes' ) || is_multisite() ) : ?> 94 <# if ( 'installed' === data.action ) { #> 95 <p class="themes-filter-container"> 96 <label for="themes-filter"> 97 <span class="screen-reader-text"><?php _e( 'Search installed themes…' ); ?></span> 98 <input type="text" id="themes-filter" placeholder="<?php esc_attr_e( 'Search installed themes…' ); ?>" /> 99 </label> 100 </p> 101 <# } #> 102 <?php endif; ?> 103 <# if ( 'favorites' === data.action ) { #> 104 <div class="favorites-form filter-details"> 105 <p class="install-help"><?php _e( 'If you have marked themes as favorites on WordPress.org, you can browse them here.' ); ?></p> 106 <p> 107 <label for="wporg-username-input"><?php _e( 'Your WordPress.org username:' ); ?></label> 108 <input type="search" id="wporg-username-input" value=""> 109 <button type="button" class="button button-secondary favorites-form-submit"><?php _e( 'Get Favorites' ); ?></button> 110 </p> 111 </div> 112 <# } else if ( 'feature_filter' === data.action ) { #> 113 <div class="filter-drawer filter-details"> 60 114 <?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; 115 $feature_list = get_theme_feature_list(); 116 foreach ( $feature_list as $feature_name => $features ) { 117 echo '<fieldset class="filter-group">'; 118 $feature_name = esc_html( $feature_name ); 119 echo '<legend><button type="button" class="button-link" aria-expanded="false">' . $feature_name . '</button></legend>'; 120 echo '<div class="filter-group-feature">'; 121 foreach ( $features as $feature => $feature_name ) { 122 $feature = esc_attr( $feature ); 123 echo '<input type="checkbox" id="filter-id-' . $feature . '" value="' . $feature . '" /> '; 124 echo '<label for="filter-id-' . $feature . '">' . $feature_name . '</label><br>'; 125 } 126 echo '</div>'; 127 echo '</fieldset>'; 65 128 } 66 129 ?> 67 <button type="button" class="button customize-theme"><?php _e( 'Customize' ); ?></button>68 </h3>69 130 </div> 131 <# } #> 132 <div class="customize-themes-section themes-section-{{ data.id }} control-section-content themes-php"> 70 133 <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 134 <div class="theme-browser rendered"> 80 <ul class="themes accordion-section-content"> 135 <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> 136 <ul class="themes"> 81 137 </ul> 138 <p class="no-themes"><?php _e( 'No themes found. Try a different search.' ); ?></p> 139 <p class="spinner"></p> 82 140 </div> 83 141 </div> 84 142 </li>