Ticket #37661: 37661.5.diff
File 37661.5.diff, 83.2 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: 1s themes-fade-in 1; /* Sounds long until you see it */ 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 line-height: 32px; 1104 text-align: right; 1105 z-index: 10; 1106 } 1107 1108 .control-panel-themes .filter-themes-count .themes-displayed { 1109 font-weight: 600; 1110 color: #555d66; 1111 } 1112 1113 .control-panel-themes .filter-themes-count .see-themes, 1114 .control-panel-themes .filter-themes-count .filter-themes { 1115 display: none; 1116 } 1117 1118 1119 /* Mobile - toggle between themes and filters */ 1120 @media screen and (max-width:600px) { 1121 .control-panel-themes .filter-themes-count { 1122 width: calc(100% - 93px); 1123 } 1124 1125 .control-panel-themes .filter-themes-count .themes-displayed { 1126 display: none; 1127 } 1128 1129 .wp-full-overlay:not(.showing-themes) .control-panel-themes .filter-themes-count .see-themes { 1130 display: block; 1131 float: right; 1132 } 1133 1134 .wp-full-overlay.showing-themes .control-panel-themes .filter-themes-count .filter-themes { 1135 display: block; 1136 float: right; 1137 } 1138 1139 .control-panel-themes .customize-themes-full-container { 1140 width: calc(100% - 50px); 1141 margin: 0; 1142 top: 46px; 1143 height: calc(100% - 96px); 1144 z-index: 1; 1145 display: none; 1146 } 1147 1148 .showing-themes .control-panel-themes .customize-themes-full-container { 1149 display: block; 1150 } 1151 } 1152 1153 .control-panel-themes .customize-themes-notifications .notice { 1154 margin: 0 0 25px 0; 1155 } 1156 1157 .customize-themes-full-container .customize-themes-section { 1158 display: none !important; /* There is unknown JS that perpetually tries to show all theme sections when more items are added. */ 1159 overflow: hidden; 1160 } 1161 1162 .customize-themes-full-container .customize-themes-section.current-section { 1163 display: list-item !important; /* There is unknown JS that perpetually tries to show all theme sections when more items are added. */ 1164 } 1165 1166 .theme-section .customize-themes-text-before { 1167 padding: 0 0 8px 15px; 1168 margin: 15px 0 0 0; 1169 line-height: 16px; 1170 border-bottom: 1px solid #ddd; 1171 color: #555d66; 1172 } 1173 1174 .control-panel-themes .customize-themes-section-title { 1175 width: 100%; 1176 background: #fff; 1177 box-shadow: none; 1178 outline: none; 1179 border-top: none; 1180 border-bottom: 1px solid #ddd; 1181 border-left: 4px solid #fff; 1182 border-right: none; 1183 cursor: pointer; 1184 padding: 10px 15px; 1185 position: relative; 1186 text-align: left; 1062 1187 font-size: 14px; 1063 1188 font-weight: 600; 1189 color: #555d66; 1190 text-shadow: none; 1064 1191 } 1065 1192 1066 #customize-controls .customize-themes-panel > h2 { 1067 padding: 15px 8px 0 8px; 1193 .control-panel-themes .theme-section { 1194 margin: 0; 1195 position: relative; 1068 1196 } 1069 1197 1070 #customize-theme-controls .customize-themes-panel .accordion-section-content { 1071 background: transparent; 1072 display: block; 1198 .control-panel-themes .customize-themes-section-title:focus, 1199 .control-panel-themes .customize-themes-section-title:hover { 1200 border-left-color: #0073aa; 1201 color: #0073aa; 1202 background: #f5f5f5; 1073 1203 } 1074 1204 1075 .customize-control.customize-control-theme { 1076 margin-bottom: 8px; 1205 .control-panel-themes .theme-section .customize-themes-section-title.selected:after { 1206 content: "\f147"; 1207 font: 16px/1 dashicons; 1208 box-sizing: border-box; 1209 width: 20px; 1210 height: 20px; 1211 padding: 3px 3px 1px 1px; /* Re-align the icon to the smaller grid */ 1212 border-radius: 100%; 1213 position: absolute; 1214 right: 15px; 1215 background: #0073aa; 1216 color: #fff; 1077 1217 } 1078 1218 1219 .control-panel-themes .customize-themes-section-title.selected { 1220 color: #0073aa; 1221 } 1222 1223 .control-panel-themes .customize-themes-section-title.themes-section-search_themes { 1224 border-left: none; 1225 padding: 5px 50px 5px 15px; 1226 width: auto; 1227 } 1228 1229 .control-panel-themes .customize-themes-section-title.themes-section-search_themes:after { 1230 content: "\f179"; 1231 font: 20px/1 dashicons; 1232 position: absolute; 1233 right: 15px; 1234 bottom: 11px; 1235 } 1236 1237 .control-panel-themes .customize-themes-section-title.themes-section-feature_filter_themes:after, 1238 .control-panel-themes .customize-themes-section-title.themes-section-favorites_themes:after { 1239 content: "\f140"; 1240 font: 20px/1 dashicons; 1241 position: absolute; 1242 right: 15px; 1243 top: 8px; 1244 } 1245 1246 .control-panel-themes .customize-themes-section-title.themes-section-search_themes .wp-filter-search { 1247 width: 100%; 1248 } 1249 1250 .control-panel-themes .customize-themes-section-title.themes-section-search_themes.selected, 1251 .control-panel-themes .customize-themes-section-title.themes-section-search_themes:hover { 1252 background: #fff; 1253 cursor: default; 1254 } 1255 1256 .control-panel-themes .customize-themes-section-title.themes-section-feature_filter_themes { 1257 margin-top: 15px; 1258 border-top: 1px solid #ddd; 1259 } 1260 1261 .control-panel-themes .filter-details { 1262 background: #f5f5f5; 1263 margin: 0; 1264 padding: 0 15px; 1265 border-bottom: 1px solid #ddd; 1266 display: none; 1267 } 1268 1269 .control-panel-themes .customize-themes-section-title.selected.details-open { 1270 border-bottom-color: #f5f5f5; 1271 background: #f5f5f5; 1272 } 1273 1274 .control-panel-themes .filter-details .filter-group { 1275 float: none; 1276 width: 100%; 1277 background: transparent; 1278 border: none; 1279 padding: 5px 0; 1280 box-shadow: none; 1281 } 1282 1079 1283 #customize-theme-controls .themes.accordion-section-content { 1080 1284 position: relative; 1081 1285 left: 0; … … 1083 1287 width: 100%; 1084 1288 } 1085 1289 1086 .wp-customizer .theme-browser .themes { 1087 padding-bottom: 8px; 1290 .customize-themes-section.loading .spinner { 1291 display: block; 1292 visibility: visible; 1293 position: relative; 1294 clear: both; 1295 width: 20px; 1296 height: 20px; 1297 left: calc(50% - 10px); 1298 float: none; 1299 margin-top: 50px; 1088 1300 } 1089 1301 1090 .wp-customizer .theme-browser .theme { 1302 .customize-themes-section .filter-drawer { 1303 border-top: none; 1304 display: block; 1305 background: transparent; 1306 padding-top: 5px; 1307 } 1308 1309 .customize-themes-section .clear-filters { 1310 margin-left: 8px; 1311 display: none; 1312 } 1313 1314 .customize-themes-section .no-themes { 1315 display: none; 1316 } 1317 1318 .themes-section-installed_themes .theme .notice-success { 1319 display: none; /* Hide "installed" notice on installed themes tab. */ 1320 } 1321 1322 .control-panel-themes .theme-browser .theme .theme-actions .button-primary { 1323 margin: 0 0 0 8px; 1324 } 1325 1326 .customize-control-theme .theme { 1327 width: 100%; 1091 1328 margin: 0; 1092 width: 100%;1093 1329 } 1094 1330 1331 .customize-control.customize-control-theme { /* override most properties on .customize-control */ 1332 box-sizing: border-box; 1333 width: 18.4%; 1334 margin: 0 2% 2% 0; 1335 padding: 0; 1336 clear: none; 1337 } 1338 1339 /* 5 columns above 2100px */ 1340 @media screen and (min-width: 2101px) { 1341 .customize-control.customize-control-theme:nth-child(5n) { 1342 margin-right: 0; 1343 } 1344 } 1345 1346 /* 4 columns up to 2100px */ 1347 @media screen and (min-width: 1601px) and (max-width: 2100px) { 1348 .customize-control.customize-control-theme { 1349 width: 23.5%; 1350 } 1351 1352 .customize-control.customize-control-theme:nth-child(4n) { 1353 margin-right: 0; 1354 } 1355 } 1356 1357 /* 3 columns up to 1600px */ 1358 @media screen and (min-width: 1201px) and (max-width: 1600px) { 1359 .customize-control.customize-control-theme { 1360 width: 32%; 1361 } 1362 1363 .customize-control.customize-control-theme:nth-child(3n) { 1364 margin-right: 0; 1365 } 1366 } 1367 1368 /* 2 columns up to 1200px */ 1369 @media screen and (min-width: 851px) and (max-width: 1200px) { 1370 .customize-control.customize-control-theme { 1371 width: 49%; 1372 } 1373 1374 .customize-control.customize-control-theme:nth-child(even) { 1375 margin-right: 0; 1376 } 1377 } 1378 1379 /* 1 column up to 850 px */ 1380 @media screen and (max-width: 850px) { 1381 .customize-control.customize-control-theme { 1382 width: 100%; 1383 margin: 0 0 3% 0; 1384 } 1385 } 1386 1387 .wp-customizer .theme-browser .themes { 1388 padding-bottom: 8px; 1389 } 1390 1095 1391 .wp-customizer .theme-browser .theme .theme-actions { 1096 -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";1097 1392 opacity: 1; 1098 1393 } 1099 1394 … … 1112 1407 width: 100%; 1113 1408 } 1114 1409 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 1410 /* Details View */ 1125 1411 .wp-customizer .theme-overlay { 1126 1412 display: none; … … 1135 1421 z-index: 109; 1136 1422 } 1137 1423 1424 /* Avoid a z-index war by resetting elements that should be under the overlay. 1425 This is likely required because of the way that sections and panels are positioned. */ 1426 .wp-customizer.modal-open #customize-header-actions, 1427 .wp-customizer.modal-open .control-panel-themes .filter-themes-count, 1428 .wp-customizer.modal-open .control-panel-themes .customize-themes-section-title.selected:after { 1429 z-index: -1; 1430 } 1431 1138 1432 .wp-customizer .theme-overlay .theme-backdrop { 1139 1433 background: rgba( 238, 238, 238, 0.75 ); 1140 1434 position: fixed; … … 1141 1435 z-index: 110; 1142 1436 } 1143 1437 1438 .wp-customizer .theme-overlay .star-rating { 1439 float: left; 1440 margin-right: 8px; 1441 } 1442 1443 .wp-customizer .theme-rating .num-ratings { 1444 line-height: 20px; 1445 } 1446 1144 1447 .wp-customizer .theme-overlay .theme-wrap { 1145 1448 left: 90px; 1146 1449 right: 90px; … … 1147 1450 top: 45px; 1148 1451 bottom: 45px; 1149 1452 z-index: 120; 1150 max-width: 1740px; /* To ensure that theme screenshots are not displayed larger than 880px wide. */1151 1453 } 1152 1454 1153 1455 .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. */ 1456 text-align: right; /* Because there're only one or two actions, match the UI pattern of media modals and right-align the action. */ 1457 padding: 10px 15px; 1155 1458 } 1156 1459 1460 .wp-customizer .theme-overlay .theme-actions .theme-install.preview { 1461 margin-left: 8px; 1462 } 1463 1464 .control-panel-themes .theme-actions .delete-theme { 1465 left: 15px; 1466 right: auto; 1467 } 1468 1469 .modal-open .in-themes-panel #customize-controls .wp-full-overlay-sidebar-content { 1470 overflow: visible; /* Prevent the top-level Customizer controls from becoming visible when elements on the right of the details modal are focused. */ 1471 } 1472 1157 1473 .ie8 .wp-customizer .theme-overlay .theme-header, 1158 1474 .ie8 .wp-customizer .theme-overlay .theme-about, 1159 1475 .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', function( event ) { 948 if ( ! section.expanded() && 'search_themes' !== section.id ) { 955 949 section.expand(); 956 950 } 957 951 }); 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; 963 } 953 // Preview installed themes. 954 section.container.on( 'click', '.theme-actions .preview-theme', function() { 955 var previewUrl = $( this ).data( 'previewUrl' ); 964 956 965 event.preventDefault(); // Keep this AFTER the key filter above957 $( '.wp-full-overlay' ).addClass( 'customize-loading' ); 966 958 959 window.parent.location = previewUrl; 960 }); 961 962 // Theme navigation in details view. 963 section.container.on( 'click', '.left', function( event ) { 967 964 section.previousTheme(); 968 965 }); 969 966 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 967 section.container.on( 'click', '.right', function( event ) { 977 968 section.nextTheme(); 978 969 }); 979 970 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 971 section.container.on( 'click', '.theme-backdrop, .close', function( event ) { 987 972 section.closeDetails(); 988 973 }); 989 974 990 975 var renderScreenshots = _.throttle( _.bind( section.renderScreenshots, this ), 100 ); 991 section.container.on( 'input', '#themes-filter', function( event ) {976 $( '.control-panel-themes' ).on( 'input', '#themes-filter', function( event ) { 992 977 var count, 993 978 term = event.currentTarget.value.toLowerCase().trim().replace( '-', ' ' ), 994 979 controls = section.controls(); … … 1000 985 renderScreenshots(); 1001 986 1002 987 // Update theme count. 1003 count = section.cont ainer.find( 'li.customize-control:visible' ).length;1004 section.container.find( '.theme-count' ).text( count );988 count = section.contentContainer.find( 'li.customize-control:visible' ).length; 989 $( '.control-panel-themes' ).find( '.theme-count' ).text( count ); 1005 990 }); 1006 991 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;992 // Event listeners for queries with user-entered terms. 993 if ( 'search' === section.params.action ) { 994 var debounced = _.debounce( section.checkTerm, 500 ); // Wait until there is no input for 500 miliseconds to initiate a search. 995 $( '.control-panel-themes' ).on( 'input', '#wp-filter-search-input', function() { 996 debounced( section ); 997 if ( ! section.expanded() ) { 998 section.expand(); 1014 999 } 1015 1000 }); 1001 } else if ( 'favorites' === section.params.action ) { 1002 section.container.on( 'click', '.favorites-form-submit', function() { 1003 section.checkTerm( section ); 1004 }); 1005 section.container.on( 'keydown', '#wporg-username-input', function( e ) { 1006 if ( api.utils.isKeydownButNotEnterEvent( e ) ) { 1007 return; 1008 } 1009 section.checkTerm( section ); 1010 }); 1011 } else if ( 'feature_filter' === section.params.action ) { 1012 section.container.on( 'click', '.filter-group input', function() { 1013 section.filtersChecked(); 1014 section.checkTerm( section ); 1015 }); 1016 } 1017 1018 // Move section controls to the themes area. 1019 api.bind( 'ready', function () { 1020 section.contentContainer = section.container.find( '.customize-themes-section' ); 1021 section.contentContainer.appendTo( $( '.customize-themes-full-container' ) ); 1022 section.container.add( section.filterContainer ); 1016 1023 }); 1017 1024 }, 1018 1025 … … 1037 1044 } 1038 1045 1039 1046 // 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' ); 1047 var section = this, 1048 container = section.contentContainer.closest( '.customize-themes-full-container' ); 1046 1049 1047 if ( expanded && ! section.hasClass( 'current-panel' ) ) { 1050 if ( expanded ) { 1051 1052 // Load controls if none are loaded yet. 1053 if ( 0 === section.loaded ) { 1054 section.loadControls(); 1055 } 1056 1048 1057 // Collapse any sibling sections/panels 1049 1058 api.section.each( function ( otherSection ) { 1050 if ( otherSection !== panel) {1059 if ( otherSection !== section ) { 1051 1060 otherSection.collapse( { duration: args.duration } ); 1052 1061 } 1053 1062 }); 1054 api.panel.each( function ( otherPanel ) {1055 otherPanel.collapse( { duration: 0 } );1056 });1057 1063 1058 panel._animateChangeExpanded( function() { 1059 changeBtn.attr( 'tabindex', '-1' ); 1060 customizeBtn.attr( 'tabindex', '0' ); 1064 section.contentContainer.addClass( 'current-section' ); 1065 section.filterContainer.find( '.customize-themes-section-title' ).addClass( 'selected' ); 1066 if ( section.filterContainer.find( '.filter-details' ).length ) { 1067 section.filterContainer.find( '.customize-themes-section-title' ).addClass( 'details-open' ); 1068 section.filterContainer.find( '.filter-details' ).slideDown( 180 ); 1069 } 1061 1070 1062 customizeBtn.focus(); 1063 section.css( 'top', '' ); 1064 container.scrollTop( 0 ); 1071 container.on( 'scroll', _.throttle( section.renderScreenshots, 300 ) ); 1072 container.on( 'scroll', _.throttle( section.loadMore, 300 ) ); 1065 1073 1066 if ( args.completeCallback ) { 1067 args.completeCallback(); 1068 } 1069 } ); 1074 if ( args.completeCallback ) { 1075 args.completeCallback(); 1076 } 1077 section.updateCount(); // Show this section's count. 1078 } else { 1079 section.contentContainer.removeClass( 'current-section' ); 1080 section.filterContainer.find( '.customize-themes-section-title' ).removeClass( 'selected details-open' ); 1081 section.filterContainer.find( '.filter-details' ).slideUp( 180 ); 1070 1082 1071 overlay.addClass( 'in-themes-panel' ); 1072 section.addClass( 'current-panel' ); 1083 container.off( 'scroll' ); 1073 1084 1074 } else if ( ! expanded && section.hasClass( 'current-panel' ) ) { 1075 panel._animateChangeExpanded( function() { 1076 changeBtn.attr( 'tabindex', '0' ); 1077 customizeBtn.attr( 'tabindex', '-1' ); 1085 if ( args.completeCallback ) { 1086 args.completeCallback(); 1087 } 1088 } 1089 }, 1078 1090 1079 changeBtn.focus(); 1080 section.css( 'top', '' ); 1091 /** 1092 * Return the section's content element without detachng from the parent. 1093 * 1094 * @since 4.7.0 1095 */ 1096 getContent: function() { 1097 return this.container.find( '.control-section-content' ); 1098 }, 1081 1099 1082 if ( args.completeCallback ) { 1083 args.completeCallback(); 1100 /** 1101 * Load theme data via ajax and add themes to the section as controls. 1102 * 1103 * @since 4.7.0 1104 */ 1105 loadControls: function() { 1106 var section = this, params, page, request, search; 1107 1108 if ( section.loading ) { 1109 return; // We're already loading a batch of themes. 1110 } 1111 1112 // Parameters for every API query. Additional params are set in PHP. 1113 page = Math.ceil( section.loaded / 100 ) + 1; 1114 params = { 1115 'customize-themes-nonce': api.settings.nonce['customize-themes'], 1116 'wp_customize': 'on', 1117 'theme_action': section.params.action, 1118 'customized_theme': api.settings.theme.stylesheet, 1119 'page': page 1120 } 1121 1122 // Add fields for special request actions. 1123 if ( 'search' === section.params.action ) { 1124 if ( '' === section.term ) { 1125 return; 1126 } else { 1127 params.search = section.term; 1128 } 1129 } else if ( 'favorites' === section.params.action ) { 1130 if ( '' === section.term ) { 1131 return; 1132 } else { 1133 params.user = section.term; 1134 } 1135 } else if ( 'feature_filter' === section.params.action ) { 1136 if ( '' === section.term ) { 1137 return; 1138 } else { 1139 params.tags = section.term; 1140 } 1141 } 1142 1143 // Load themes. 1144 section.container.addClass( 'loading' ); 1145 section.loading = true; 1146 section.container.find( '.no-themes' ).hide(); 1147 request = wp.ajax.post( 'customize-load-themes', params ); 1148 request.done(function( data ) { 1149 var themes = data.themes, 1150 themeControl, newThemeControls; 1151 if ( 0 !== themes.length ) { 1152 newThemeControls = new Array(); 1153 // Add controls for each theme. 1154 _.each( themes, function ( theme ) { 1155 customizeId = section.params.action + '_theme_' + theme.id; 1156 themeControl = new api.controlConstructor.theme( customizeId, { 1157 params: { 1158 type: 'theme', 1159 content: '<li id="customize-control-theme-' + section.params.action + '_' + theme.id + '" class="customize-control customize-control-theme"></li>', 1160 section: section.params.id, 1161 active: true, 1162 theme: theme, 1163 priority: section.loaded + 1 1164 }, 1165 previewer: api.previewer 1166 } ); 1167 1168 api.control.add( customizeId, themeControl ); 1169 newThemeControls.push( themeControl ); 1170 section.loaded = section.loaded + 1; 1171 return; 1172 }); 1173 1174 if ( 1 === page ) { 1175 // Pre-load the first 3 theme screenshots. 1176 _.each( section.controls().slice( 0, 3 ), function ( control ) { 1177 var img, src = control.params.theme.screenshot[0]; 1178 if ( src ) { 1179 img = new Image(); 1180 img.src = src; 1181 } 1182 }); 1183 if ( 'search' === section.params.action ) { 1184 wp.a11y.speak( api.settings.l10n.themeSearchResults.replace( '%d', data.info.results ) ); 1185 } 1186 } else { 1187 Array.prototype.push.apply( section.screenshotQueue, newThemeControls ); // Add new themes to the screenshot queue. 1084 1188 } 1085 } );1189 _.delay( section.renderScreenshots, 100 ); // Wait for the controls to become visible. 1086 1190 1087 overlay.removeClass( 'in-themes-panel' ); 1088 section.removeClass( 'current-panel' ); 1191 if ( 'installed' === section.action || 100 > themes.length ) { // If we have less than the requested 100 themes, it's the end of the list. 1192 section.fullyLoaded = true; 1193 } 1194 } else { 1195 if ( 0 === section.loaded ) { 1196 section.container.find( '.no-themes' ).show(); 1197 wp.a11y.speak( section.container.find( '.no-themes' ).text() ); 1198 } else { 1199 section.fullyLoaded = true; 1200 } 1201 } 1202 if ( 'installed' === section.params.action ) { 1203 section.updateCount(); 1204 } else { 1205 section.updateCount( data.info.results ); 1206 } 1207 section.container.find( '.unexpected-error' ).hide(); // Hide error notice in case it was previously shown. 1208 1209 // This cannot run on request.always, as section.loading may turn false before the new controls load in the success case. 1210 section.container.removeClass( 'loading' ); 1211 section.loading = false; 1212 }); 1213 request.fail(function( data ) { 1214 if ( 'undefined' === typeof data ) { 1215 section.container.find( '.unexpected-error' ).show(); 1216 wp.a11y.speak( section.container.find( '.unexpected-error' ).text() ); 1217 } else if ( typeof console !== 'undefined' && console.error ) { 1218 console.error( data ); 1219 } 1220 1221 // This cannot run on request.always, as section.loading may turn false before the new controls load in the success case. 1222 section.container.removeClass( 'loading' ); 1223 section.loading = false; 1224 }); 1225 }, 1226 1227 /** 1228 * Determines whether more themes should be loaded, and loads them. 1229 * 1230 * @since 4.7.0 1231 */ 1232 loadMore: function() { 1233 var section = this, container, bottom, threshold, page; 1234 if ( ! section.fullyLoaded && ! section.loading ) { 1235 container = section.container.closest( '.customize-themes-full-container' ); 1236 1237 bottom = container.scrollTop() + container.height(); 1238 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. 1239 1240 if ( bottom > threshold ) { 1241 section.loadControls(); 1242 } 1089 1243 } 1090 1244 }, 1091 1245 1092 1246 /** 1247 * Event handler for search, feature filter, and favorites input that determines if the term has changed and loads new controls as needed. 1248 * 1249 * @since 4.7.0 1250 * 1251 * @param api.ThemesSection section The current theme section, passed through the debouncer. 1252 */ 1253 checkTerm: function( section ) { 1254 var newTerm, filteringBy; 1255 1256 // Find term. 1257 if ( 'search' === section.params.action ) { 1258 newTerm = $( '#wp-filter-search-input' ).val(); 1259 } else if ( 'favorites' === section.params.action ) { 1260 newTerm = $( '#wporg-username-input' ).val(); 1261 } else if ( 'feature_filter' === section.params.action ) { 1262 newTerm = section.term; // Set separately by filtersChecked(), as they're changed. 1263 if ( '' === newTerm ) { 1264 return; 1265 } 1266 } else { 1267 return; 1268 } 1269 1270 if ( section.term === newTerm && 'feature_filter' !== section.params.action ) { 1271 return; 1272 } 1273 // Clear the controls in the section. 1274 _.each( section.controls(), function( control ) { 1275 control.container.remove(); 1276 api.control.remove( control.id ); 1277 }); 1278 section.loaded = 0; 1279 section.fullyLoaded = false; 1280 section.screenshotQueue = null; 1281 1282 if ( '' !== newTerm ) { // Empty term should not show any results. 1283 // Run a new query, with loadControls handling paging, etc. 1284 section.term = newTerm; 1285 section.loadControls(); 1286 } 1287 }, 1288 1289 /** 1290 * Check for filters checked in the feature filter list. 1291 * 1292 * @since 4.7.0 1293 */ 1294 filtersChecked: function() { 1295 var section = this, 1296 items = section.container.find( '.filter-group' ).find( ':checkbox' ), 1297 tags = []; 1298 1299 if ( 'feature_filter' !== section.params.action ) { 1300 return false; 1301 } 1302 1303 _.each( items.filter( ':checked' ), function( item ) { 1304 tags.push( $( item ).prop( 'value' ) ); 1305 }); 1306 1307 // When no filters are checked, restore initial state and return 1308 if ( tags.length === 0 ) { 1309 section.term = ''; 1310 } else { 1311 section.term = tags; 1312 } 1313 }, 1314 1315 /** 1093 1316 * Render control's screenshot if the control comes into view. 1094 1317 * 1095 1318 * @since 4.2.0 … … 1097 1320 renderScreenshots: function( ) { 1098 1321 var section = this; 1099 1322 1100 // Fill queue initially. 1101 if ( section.screenshotQueue === null ) { 1102 section.screenshotQueue = section.controls(); 1323 // Fill queue initially, or check for more if empty. 1324 if ( section.screenshotQueue === null || 0 === section.screenshotQueue.length ) { 1325 // Add controls that haven't had their screenshots rendered. 1326 section.screenshotQueue = _.filter( section.controls(), function( control ) { 1327 return ! control.screenshotRendered; 1328 }); 1103 1329 } 1104 1330 1105 // Are all screenshots rendered ?1331 // Are all screenshots rendered (for now)? 1106 1332 if ( ! section.screenshotQueue.length ) { 1107 1333 return; 1108 1334 } … … 1138 1364 }, 1139 1365 1140 1366 /** 1367 * Update the number of themes in the section. 1368 * 1369 * @since 4.7.0 1370 */ 1371 updateCount: function ( count ) { 1372 if ( ! count ) { 1373 count = this.loaded; 1374 } 1375 this.container.closest( '.control-panel-content' ).find( '.theme-count' ).text( count ); 1376 }, 1377 1378 /** 1141 1379 * Advance the modal to the next theme. 1142 1380 * 1143 1381 * @since 4.2.0 … … 1157 1395 * @since 4.2.0 1158 1396 */ 1159 1397 getNextTheme: function () { 1160 var control, next;1161 control = api.control( 'theme_' + this.currentTheme );1398 var section = this, control, next; 1399 control = api.control( section.params.action + '_theme_' + this.currentTheme ); 1162 1400 next = control.container.next( 'li.customize-control-theme' ); 1163 1401 if ( ! next.length ) { 1164 1402 return false; 1165 1403 } 1166 next = next[0].id.replace( 'customize-control- ', '' );1404 next = next[0].id.replace( 'customize-control-theme-' + section.params.action, section.params.action + '_theme' ); 1167 1405 control = api.control( next ); 1168 1406 1169 1407 return control.params.theme; … … 1189 1427 * @since 4.2.0 1190 1428 */ 1191 1429 getPreviousTheme: function () { 1192 var control, previous;1193 control = api.control( 'theme_' + this.currentTheme );1430 var section = this, control, previous; 1431 control = api.control( section.params.action + '_theme_' + this.currentTheme ); 1194 1432 previous = control.container.prev( 'li.customize-control-theme' ); 1195 1433 if ( ! previous.length ) { 1196 1434 return false; 1197 1435 } 1198 previous = previous[0].id.replace( 'customize-control- ', '' );1436 previous = previous[0].id.replace( 'customize-control-theme-' + section.params.action, section.params.action + '_theme' ); 1199 1437 control = api.control( previous ); 1200 1438 1201 1439 return control.params.theme; … … 1243 1481 closeDetails: function () { 1244 1482 $( 'body' ).removeClass( 'modal-open' ); 1245 1483 this.overlay.fadeOut( 'fast' ); 1246 api.control( 'theme_' + this.currentTheme).focus();1484 api.control( this.params.action + '_theme_' + this.currentTheme ).container.find( '.theme' ).focus(); 1247 1485 }, 1248 1486 1249 1487 /** … … 1323 1561 } 1324 1562 if ( ! panel.contentContainer.parent().is( panel.headContainer ) ) { 1325 1563 container.append( panel.contentContainer ); 1326 panel.renderContent();1327 1564 } 1565 panel.renderContent(); 1328 1566 1329 1567 panel.deferred.embedded.resolve(); 1330 1568 }, … … 1513 1751 } 1514 1752 }); 1515 1753 1754 1516 1755 /** 1756 * wp.customize.ThemesPanel 1757 * 1758 * Custom section for themes that displays without the customize preview. 1759 * 1760 * @constructor 1761 * @augments wp.customize.Panel 1762 * @augments wp.customize.Container 1763 */ 1764 api.ThemesPanel = api.Panel.extend({ 1765 installingThemes: [], 1766 1767 /** 1768 * @since 4.7.0 1769 */ 1770 attachEvents: function () { 1771 var panel = this; 1772 1773 // Attach regular panel events. 1774 api.Panel.prototype.attachEvents.apply( this ); 1775 1776 // Collapse panel to customize the current theme. 1777 panel.contentContainer.on( 'click', '.customize-theme', function( event ) { 1778 panel.collapse(); 1779 }); 1780 1781 // Toggle between filtering and browsing themes on mobile. 1782 panel.contentContainer.on( 'click', '.see-themes, .filter-themes', function( event ) { 1783 $( '.wp-full-overlay' ).toggleClass( 'showing-themes' ); 1784 }); 1785 1786 // Hide unsaved changes notice on save. 1787 api.bind( 'saved', function() { 1788 panel.container.find( '.customize-themes-unsaved-changes' ).hide(); 1789 }); 1790 1791 // Save & publish customized settings. 1792 panel.contentContainer.on( 'click', '#customize-themes-save', function() { 1793 $( '#save' ).click(); // Trigger customizer save. 1794 panel.container.find( '.customize-themes-unsaved-changes' ).hide(); 1795 api.section( 'installed_themes' ).focus(); 1796 }); 1797 1798 // Install (and maybe preview) a theme. 1799 panel.contentContainer.on( 'click', '.theme-install', function( event ) { 1800 panel.installTheme( event ); 1801 }); 1802 1803 // Update a theme. Theme cards have the class, the details modal has the id. 1804 panel.contentContainer.on( 'click', '.update-theme, #update-theme', function( event ) { 1805 // #update-theme is a link. 1806 event.preventDefault(); 1807 event.stopPropagation(); 1808 1809 panel.updateTheme( event ); 1810 }); 1811 1812 // Delete a theme. 1813 panel.contentContainer.on( 'click', '.delete-theme', function( event ) { 1814 panel.deleteTheme( event ); 1815 }); 1816 1817 _.bindAll( this, 'installTheme', 'updateTheme' ); 1818 }, 1819 1820 /** 1821 * Update UI to reflect expanded state 1822 * 1823 * @since 4.7.0 1824 * 1825 * @param {Boolean} expanded 1826 * @param {Object} args 1827 * @param {Boolean} args.unchanged 1828 * @param {Callback} args.completeCallback 1829 */ 1830 onChangeExpanded: function ( expanded, args ) { 1831 1832 // Expand/collapse the panel normally. 1833 api.Panel.prototype.onChangeExpanded.apply( this, [ expanded, args ] ); 1834 1835 // Immediately call the complete callback if there were no changes 1836 if ( args.unchanged ) { 1837 if ( args.completeCallback ) { 1838 args.completeCallback(); 1839 } 1840 return; 1841 } 1842 1843 // Note: there is a second argument 'args' passed 1844 var panel = this, 1845 overlay = panel.headContainer.closest( '.wp-full-overlay' ); 1846 1847 // Move the themes container after the theme section headers. Only needs to happen the first time, no harm doing it again. 1848 panel.contentContainer.find( '.customize-themes-full-container' ).appendTo( panel.contentContainer ); 1849 1850 if ( expanded ) { 1851 overlay.addClass( 'in-themes-panel' ) 1852 .delay( 200 ).find( '.customize-themes-full-container' ).addClass( 'animate' ); 1853 1854 if ( false === api.state( 'saved' ).get() ) { 1855 panel.container.find( '.customize-themes-unsaved-changes' ).show(); 1856 } 1857 1858 // Automatically open the installed themes section. 1859 api.section( 'installed_themes' ).expand(); 1860 } else { 1861 overlay.removeClass( 'in-themes-panel' ) 1862 .find( '.customize-themes-full-container' ).removeClass( 'animate' ); 1863 } 1864 }, 1865 1866 /** 1867 * Install a theme via wp.updates. 1868 * 1869 * @since 4.7.0 1870 */ 1871 installTheme: function( event ) { 1872 var preview = false, previewUrl, 1873 slug = $( event.target ).data( 'slug' ); 1874 1875 if ( -1 !== $.inArray( this.installingThemes, slug ) ) { 1876 return; // Theme is already being installed. 1877 } 1878 1879 wp.updates.maybeRequestFilesystemCredentials( event ); 1880 1881 $( document ).on( 'wp-theme-install-success', function( event, response ) { 1882 var theme = false, customizeId, themeControl; 1883 if ( preview ) { 1884 window.parent.location = previewUrl; 1885 } else { 1886 api.control.each( function( control ) { 1887 if ( 'theme' === control.params.type && control.params.theme.id === response.slug ) { 1888 theme = control.params.theme; // Used below to add theme control. 1889 control.rerenderAsInstalled( true ); 1890 } 1891 }); 1892 1893 // Don't add the same theme more than once. 1894 if ( ! theme || 'undefined' !== typeof api.control( 'installed_theme_' + theme.id ) ) { 1895 return; 1896 } 1897 1898 // Add theme control to installed section. 1899 theme.type = 'installed'; 1900 customizeId = 'installed_theme_' + theme.id; 1901 themeControl = new api.controlConstructor.theme( customizeId, { 1902 params: { 1903 type: 'theme', 1904 content: '<li id="customize-control-theme-installed_' + theme.id + '" class="customize-control customize-control-theme"></li>', 1905 section: 'installed_themes', 1906 active: true, 1907 theme: theme, 1908 priority: 0 // Add all newly-installed themes to the top. 1909 }, 1910 previewer: api.previewer 1911 } ); 1912 1913 api.control.add( customizeId, themeControl ); 1914 api.control( customizeId ).container.trigger( 'render-screenshot' ); 1915 1916 // Close the details modal if it's open to the installed theme. 1917 api.section.each( function( section ) { 1918 if ( 'themes' !== section.params.type ) { 1919 if ( theme.id === section.currentTheme ) { // Don't close the modal if the user has navigated elsewhere. 1920 section.closeDetails(); 1921 } 1922 } 1923 }); 1924 } 1925 } ); 1926 1927 $( document ).on( 'wp-theme-install-failure', function( event, response ) { 1928 if ( preview ) { 1929 $( '.wp-full-overlay' ).removeClass( 'customize-loading' ); 1930 } 1931 }); 1932 1933 this.installingThemes.push( $( event.target ).data( 'slug' ) ); // Note: we don't remove elements from installingThemes, since they shouldn't be installed again. 1934 wp.updates.installTheme( { 1935 slug: $( event.target ).data( 'slug' ) 1936 } ); 1937 1938 // Also preview the theme as the event is triggered on Install & Preview. 1939 if ( $( event.target ).hasClass( 'preview' ) ) { 1940 preview = true; 1941 $( '.wp-full-overlay' ).addClass( 'customize-loading' ); 1942 previewUrl = $( event.target ).data( 'previewurl' ); 1943 } 1944 }, 1945 1946 /** 1947 * Update a theme via wp.updates. 1948 * 1949 * @since 4.7.0 1950 */ 1951 updateTheme: function( event ) { 1952 wp.updates.maybeRequestFilesystemCredentials( event ); 1953 1954 $( document ).on( 'wp-theme-update-success', function( event, response ) { 1955 // Rerender the control to reflect the update. 1956 api.control.each( function( control ) { 1957 if ( 'theme' === control.params.type && control.params.theme.id === response.slug ) { 1958 control.params.theme.hasUpdate = false; 1959 control.rerenderAsInstalled( true ); 1960 } 1961 }); 1962 } ); 1963 1964 wp.updates.updateTheme( { 1965 slug: $( event.target ).closest( '.notice' ).data( 'slug' ) 1966 } ); 1967 }, 1968 1969 /** 1970 * Delete a theme via wp.updates. 1971 * 1972 * @since 4.7.0 1973 */ 1974 deleteTheme: function( event ) { 1975 var panel = this, 1976 theme = $( event.target ).data( 'slug' ), 1977 section = api.section( 'installed_themes' ); 1978 1979 event.preventDefault(); 1980 1981 // Confirmation dialog for deleting a theme. 1982 if ( ! window.confirm( api.settings.l10n.confirmDeleteTheme ) ) { 1983 return; 1984 } 1985 1986 wp.updates.maybeRequestFilesystemCredentials( event ); 1987 1988 $( document ).one( 'wp-theme-delete-success', function( event, response ) { 1989 var control = api.control( 'installed_theme_' + theme ); 1990 1991 // Remove theme control. 1992 control.container.remove(); 1993 api.control.remove( control.id ); 1994 1995 // Update installed count. 1996 section.loaded = section.loaded - 1; 1997 section.updateCount(); 1998 1999 // Rerender any other theme controls as uninstalled. 2000 api.control.each( function( control ) { 2001 if ( 'theme' === control.params.type && control.params.theme.id === theme ) { 2002 control.rerenderAsInstalled( false ); 2003 } 2004 }); 2005 } ); 2006 2007 wp.updates.deleteTheme( { 2008 slug: theme 2009 } ); 2010 2011 // Close modal and focus the section. 2012 section.closeDetails(); 2013 section.focus(); 2014 } 2015 2016 }); 2017 2018 2019 /** 1517 2020 * A Customizer Control. 1518 2021 * 1519 2022 * A control provides a UI element that allows a user to modify a Customizer Setting. … … 2831 3334 api.ThemeControl = api.Control.extend({ 2832 3335 2833 3336 touchDrag: false, 2834 isRendered: false,3337 screenshotRendered: false, 2835 3338 2836 3339 /** 2837 * Defer rendering the theme control until the section is displayed.2838 *2839 3340 * @since 4.2.0 2840 3341 */ 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 3342 ready: function() { 2864 3343 var control = this; 2865 3344 … … 2879 3358 } 2880 3359 2881 3360 // Prevent the modal from showing when the user clicks the action button. 2882 if ( $( event.target ).is( '.theme-actions .button ' ) ) {3361 if ( $( event.target ).is( '.theme-actions .button, .update-theme' ) ) { 2883 3362 return; 2884 3363 } 2885 3364 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 3365 api.section( control.section() ).showDetails( control.params.theme ); 2901 3366 }); 2902 3367 … … 2907 3372 if ( source ) { 2908 3373 $screenshot.attr( 'src', source ); 2909 3374 } 3375 control.screenshotRendered = true; 2910 3376 }); 2911 3377 }, 2912 3378 2913 3379 /** 2914 * Show or hide the theme based on the presence of the term in the title, description, and author.3380 * Show or hide the theme based on the presence of the term in the title, description, tags, and author. 2915 3381 * 2916 3382 * @since 4.2.0 2917 3383 */ … … 2927 3393 } else { 2928 3394 control.deactivate(); 2929 3395 } 3396 }, 3397 3398 /** 3399 * Rerender the theme from its JS template with the installed type. 3400 * 3401 * @since 4.7.0 3402 */ 3403 rerenderAsInstalled: function( installed ) { 3404 var control = this, section; 3405 if ( installed ) { 3406 control.params.theme.type = 'installed'; 3407 } else { 3408 section = api.section( control.params.section ); 3409 control.params.theme.type = section.params.action; 3410 } 3411 control.renderContent(); // replaces existing content 3412 control.container.trigger( 'render-screenshot' ); 2930 3413 } 2931 3414 }); 2932 3415 … … 3490 3973 background: api.BackgroundControl, 3491 3974 theme: api.ThemeControl 3492 3975 }; 3493 api.panelConstructor = {}; 3976 api.panelConstructor = { 3977 themes: api.ThemesPanel 3978 }; 3494 3979 api.sectionConstructor = { 3495 3980 themes: api.ThemesSection 3496 3981 }; … … 4085 4570 // Collapse the most granular expanded object. 4086 4571 collapsedObject = expandedControls[0] || expandedSections[0] || expandedPanels[0]; 4087 4572 if ( collapsedObject ) { 4573 if ( 'themes' === collapsedObject.params.type ) { 4574 // Themes panel or section. 4575 if ( $( 'body' ).hasClass( 'modal-open' ) ) { 4576 collapsedObject.closeDetails(); 4577 } else { 4578 // If we're collapsing a section, collapse the panel also. 4579 wp.customize.panel( 'themes' ).collapse(); 4580 } 4581 return; 4582 } 4088 4583 collapsedObject.collapse(); 4089 4584 event.preventDefault(); 4090 4585 } -
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' ), 1988 $this->add_panel( new WP_Customize_Themes_Panel( $this, 'themes', array( 1989 'title' => __( 'Themes' ), 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 categories in this menu.' ), 1971 1991 'capability' => 'switch_themes', 1972 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.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 <div 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 </div> 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">{{ data.title }}</strong>' ); 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 <ul class="customize-themes-full-container"> 107 <li class="customize-themes-notifications"> 108 <div class="notice notice-warning customize-themes-unsaved-changes" style="display: none;"><p> 109 <?php _e( 'You have unsaved changes that will be lost if you preview a new theme.' ); ?> 110 <button type="button" id="customize-themes-save" class="button" ><?php _e( 'Save & Publish' ); ?></button> 111 </p></div> 112 </li> 113 </ul> 114 <?php 115 } 116 } -
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; 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"> 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 <button type="button" class="customize-themes-section-title themes-section-{{ data.id }}">{{ data.title }}</button> 87 <# } #> 88 <?php if ( ! current_user_can( 'install_themes' ) || is_multisite() ) : ?> 89 <# if ( 'installed' === data.action ) { #> 90 <p class="themes-filter-container"> 91 <label for="themes-filter"> 92 <span class="screen-reader-text"><?php _e( 'Search installed themes…' ); ?></span> 93 <input type="text" id="themes-filter" placeholder="<?php esc_attr_e( 'Search installed themes…' ); ?>" /> 94 </label> 95 </p> 96 <# } #> 97 <?php endif; ?> 98 <# if ( 'favorites' === data.action ) { #> 99 <div class="favorites-form filter-details"> 100 <p class="install-help"><?php _e( 'If you have marked themes as favorites on WordPress.org, you can browse them here.' ); ?></p> 101 <p> 102 <label for="wporg-username-input"><?php _e( 'Your WordPress.org username:' ); ?></label> 103 <input type="search" id="wporg-username-input" value=""> 104 <button type="button" class="button button-secondary favorites-form-submit"><?php _e( 'Get Favorites' ); ?></button> 105 </p> 106 </div> 107 <# } else if ( 'feature_filter' === data.action ) { #> 108 <div class="filter-drawer filter-details"> 60 109 <?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; 110 $feature_list = get_theme_feature_list(); 111 foreach ( $feature_list as $feature_name => $features ) { 112 echo '<fieldset class="filter-group">'; 113 $feature_name = esc_html( $feature_name ); 114 echo '<legend>' . $feature_name . '</legend>'; 115 echo '<div class="filter-group-feature">'; 116 foreach ( $features as $feature => $feature_name ) { 117 $feature = esc_attr( $feature ); 118 echo '<input type="checkbox" id="filter-id-' . $feature . '" value="' . $feature . '" /> '; 119 echo '<label for="filter-id-' . $feature . '">' . $feature_name . '</label><br>'; 120 } 121 echo '</div>'; 122 echo '</fieldset>'; 65 123 } 66 124 ?> 67 <button type="button" class="button customize-theme"><?php _e( 'Customize' ); ?></button>68 </h3>69 125 </div> 126 <# } #> 127 <div class="customize-themes-section themes-section-{{ data.id }} control-section-content themes-php"> 70 128 <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 129 <div class="theme-browser rendered"> 80 <ul class="themes accordion-section-content"> 130 <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> 131 <ul class="themes"> 81 132 </ul> 133 <p class="no-themes"><?php _e( 'No themes found. Try a different search.' ); ?></p> 134 <p class="spinner"></p> 82 135 </div> 83 136 </div> 84 137 </li>