first commit without licensingg

This commit is contained in:
kbe
2025-08-21 14:40:43 +02:00
commit fa8d4e58a4
130 changed files with 82163 additions and 0 deletions

View File

@@ -0,0 +1,361 @@
/**
* Heading
*/
.customize-control-heading {
margin-bottom: 0;
}
/**
* Description
*/
.customize-control-description {
overflow-wrap: break-word;
}
/**
* Checkbox
*/
.customize-control-checkbox + .customize-control-checkbox {
margin-top: -12px;
}
/**
* Radio
*/
.customize-control-radio .customize-inside-control-row {
padding-bottom: 0;
}
/**
* Divider
*/
.customizer-divider {
border-bottom: 1px dashed #dcdcde;
margin: 4px -12px;
}
/**
* Color
*/
.customize-control-color[id*=is_dark],
.customize-control-color-alpha[id*=is_dark] {
position: relative;
}
.customize-control-color[id*=is_dark] .expand-setting,
.customize-control-color-alpha[id*=is_dark] .expand-setting {
position: absolute;
top: -82px;
left: 0;
padding: 10px;
cursor: pointer;
opacity: 0.5;
transition: opacity 0.25s;
}
.customize-control-color[id*=is_dark] .expand-setting:before,
.customize-control-color-alpha[id*=is_dark] .expand-setting:before {
display: block;
background-image: url("data:image/svg+xml,%3Csvg width='14' height='15' viewBox='0 0 14 15' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5.66536 4.16683C5.66523 5.09392 5.94124 6.00005 6.45818 6.76964C6.97513 7.53923 7.70959 8.1374 8.56788 8.48787C9.42618 8.83835 10.3694 8.92523 11.2773 8.73744C12.1852 8.54965 13.0165 8.09571 13.6654 7.4335V7.50016C13.6654 11.1822 10.6807 14.1668 6.9987 14.1668C3.3167 14.1668 0.332031 11.1822 0.332031 7.50016C0.332031 3.81816 3.3167 0.833496 6.9987 0.833496H7.06536C6.62139 1.26758 6.26879 1.78614 6.02835 2.35862C5.78791 2.93109 5.66449 3.54591 5.66536 4.16683ZM1.66536 7.50016C1.66488 8.69015 2.06238 9.84611 2.79463 10.7841C3.52687 11.7222 4.55179 12.3883 5.70631 12.6767C6.86082 12.9651 8.07862 12.859 9.16593 12.3755C10.2532 11.8919 11.1476 11.0586 11.7067 10.0082C10.7117 10.2426 9.67322 10.2189 8.68991 9.93931C7.7066 9.65973 6.81103 9.13355 6.08817 8.41069C5.36531 7.68783 4.83913 6.79226 4.55955 5.80895C4.27997 4.82564 4.25627 3.7872 4.4907 2.79216C3.63708 3.24692 2.92322 3.92527 2.42554 4.75459C1.92785 5.58391 1.66508 6.53297 1.66536 7.50016Z' fill='%23000000'/%3E%3C/svg%3E%0A");
background-size: contain;
width: 14px;
height: 15px;
content: "";
}
.customize-control-color[id*=is_dark] .expand-setting:hover,
.customize-control-color-alpha[id*=is_dark] .expand-setting:hover {
opacity: 1;
}
.customize-control-color[id*=is_dark].customize-control-color-open .expand-setting,
.customize-control-color-alpha[id*=is_dark].customize-control-color-open .expand-setting {
opacity: 1;
}
.customize-control-color[id*=is_dark]:not(.customize-control-color-open),
.customize-control-color-alpha[id*=is_dark]:not(.customize-control-color-open) {
margin-bottom: 0;
}
.customize-control-color[id*=is_dark]:not(.customize-control-color-open) .customize-control-title,
.customize-control-color-alpha[id*=is_dark]:not(.customize-control-color-open) .customize-control-title {
display: none;
}
.customize-control-color[id*=is_dark]:not(.customize-control-color-open) .customize-control-content,
.customize-control-color-alpha[id*=is_dark]:not(.customize-control-color-open) .customize-control-content {
display: none;
}
.customize-control-color[id*=is_dark]:not(.customize-control-color-open) .wp-picker-container,
.customize-control-color-alpha[id*=is_dark]:not(.customize-control-color-open) .wp-picker-container {
display: none;
}
/**
* Select2
*/
.select2-dropdown {
border-color: rgba(0, 0, 0, 0.1);
border-radius: 0;
}
.select2-container {
min-width: 100px;
width: 100% !important;
}
.select2-container--open .select2-dropdown--above,
.select2-container--open .select2-dropdown--below {
z-index: 9999999;
min-width: 100px;
}
.select2-container--default .select2-search--dropdown .select2-search__field {
border-color: rgba(0, 0, 0, 0.1);
}
.select2-container--default .select2-selection--multiple,
.select2-container--default .select2-selection--single {
border-color: rgba(0, 0, 0, 0.1);
border-radius: 0;
}
.select2-container--default .select2-selection--multiple .select2-selection__choice {
background-color: rgba(255, 255, 255, 0);
background-color: transparent;
border: none;
border-radius: 0;
}
.wp-customizer .select2-container {
z-index: 8 !important;
}
.wp-customizer .select2-container.select2-container--open {
z-index: 999999 !important;
}
/**
* Collapsibles
*/
.customize-control-collapsible .customize-collapsible {
position: relative;
margin: 0 -12px;
border-top: 1px solid rgba(0, 0, 0, 0.05);
}
.customize-control-collapsible .customize-collapsible h3 {
display: block;
position: relative;
margin: 0;
padding: 10px 14px;
color: #555;
background: white;
line-height: 21px;
user-select: none;
cursor: pointer;
}
.customize-control-collapsible .customize-collapsible h3:after {
position: absolute;
top: 12px;
left: 14px;
color: #a0a5aa;
font: 400 20px/1 dashicons;
content: "\f343";
}
.customize-control-collapsible .customize-collapsible h3:hover {
color: #0073aa;
background: #f5f5f5;
}
.customize-control-collapsible .customize-collapsible h3:hover:after {
color: #0073aa;
}
.customize-control-collapsible.customize-control-collapsed {
margin-bottom: 0;
}
.customize-control-collapsible.customize-control-collapsed .customize-collapsible h3:after {
content: "\f347";
}
.customize-control-hidden {
height: 0 !important;
overflow: hidden !important;
visibility: hidden;
padding: 0;
}
/**
* Alpha Color Picker CSS
*/
.customize-control-color-alpha .wp-picker-container .iris-picker {
border-bottom: none;
}
.customize-control-color-alpha .wp-picker-container {
max-width: 257px;
}
.customize-control-color-alpha .wp-picker-open + .wp-picker-input-wrap {
width: 100%;
}
.customize-control-color-alpha .wp-picker-input-wrap input[type=text].wp-color-picker.color-alpha-control {
float: right;
width: 195px;
}
.customize-control-color-alpha .wp-picker-input-wrap .button {
margin-right: 0;
float: left;
}
.wp-picker-container .wp-picker-open ~ .wp-picker-holder .color-alpha-picker-container {
display: block;
}
.color-alpha-picker-container {
border: 1px solid #dfdfdf;
border-top: none;
display: none;
background: #FFF;
padding: 0 11px 10px;
position: relative;
}
.color-alpha-picker-container .ui-widget-content,
.color-alpha-picker-container .ui-widget-header,
.color-alpha-picker-wrap .ui-state-focus {
background: transparent;
border: none;
}
.color-alpha-picker-wrap a.iris-square-value:focus {
-webkit-box-shadow: none;
box-shadow: none;
}
.color-alpha-picker-container .ui-slider {
position: relative;
z-index: 1;
height: 24px;
text-align: center;
margin: 0 auto;
width: 88%;
width: calc(100% - 28px);
}
.color-alpha-picker-container .ui-slider-handle,
.color-alpha-picker-container .ui-widget-content .ui-state-default {
color: #777;
background-color: #FFF;
text-shadow: 0 1px 0 #FFF;
text-decoration: none;
position: absolute;
z-index: 2;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
border: 1px solid #aaa;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
margin-top: -2px;
top: 0;
height: 26px;
width: 26px;
cursor: ew-resize;
font-size: 0;
padding: 0;
line-height: 27px;
margin-right: -14px;
}
.color-alpha-picker-container .ui-slider-handle.alpha {
font-size: 12px;
}
.color-alpha-picker-container .click-zone {
width: 14px;
height: 24px;
display: block;
position: absolute;
right: 10px;
}
.color-alpha-picker-container .max-click-zone {
left: 10px;
right: auto;
}
.color-alpha-picker-container .transparency {
height: 24px;
width: 100%;
background-color: #FFF;
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOkAAAAYCAYAAAAf+dpfAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MzY5NzJDNTEwNzA3MTFFNEExREREODYzQUFCRDhDREMiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MzY5NzJDNTIwNzA3MTFFNEExREREODYzQUFCRDhDREMiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDozNjk3MkM0RjA3MDcxMUU0QTFEREQ4NjNBQUJEOENEQyIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDozNjk3MkM1MDA3MDcxMUU0QTFEREQ4NjNBQUJEOENEQyIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PndQ2kgAAAbKSURBVHjarFyLUexIDFS7LhfSIJuXEmRDGiTjPt7VwnnNSN2SvVUUsLbno9Gn1aMx3t7eGBF/f+Lx+/j3r98vLy883Pd9bY//P/vh/v3z8zMW93//vZ/+56L9cz/H787t/7p+GtN+an8/tX1+nl/tH+/dF+N4+u7R/l6M5+n+r/b3ZPz76rmv9s9t79X8zfEf5aPGs5/ks6/kkI1rIf9sTMf2M5n/Gk+iP3uiU8f1tX5O7Ve6fW6/ujcO7cf52vb4ApF/UHTy/R0W93PRLk7PVX2ePzTvW12H2Vd2H4vrSJzb+Xkac8dCplnfKL5n0jeScWAxxmq+2Tho6lE1LxprguTeWAQWxn2f41xhrLOSmdTh19dXbgulQbFwWAwQpqFhoTDKKFxjVIuuFIcNobqOhcmiIpk7DSWmMQYaBsMbZBcJ4opkfZnIm4neQfSZzZMNo2BDrtV9HAQO+7M1O1xNiqYnoeFxYXrXjiAx9JbRUNBK2ZRhZIoEsR4som6IthDzCMPCEZ3XoYN+uDDmEA6AhhFXbcF0Tiz0jMncXWcmnfFmCrETWbAwSscbZRMP8zn1DAvjh1ggmsbNgaJ3kAEXkQZDB4OGA8zmB8P5XHUEk3mhGO8EjZ31OtNT3uT8nv7fzBxwshBI8liYUZGDhXFyRzW/bt9d2WSOw83F3P5ULpdxDlleTCMXQ3O9OnwDzDkqp+3yE1W+qbgOp1+Fav67/+PjA5sB2zJv7ij/FEpOcqEzvMFwQVzIOEEYFfmAqFn2K1GKhUNzU4kOenLGQ5EzsuEMOwTllUiPApJn/WYcjoVkjsSRm78oGAFh0HeybhXscxcZSWRDQXYgehFjAqNh/M8EscCUr8qdHT6iA6FhOhEXhkLI2HXWE2fn6BwSh0vDEf60e4ykLvOpYA0bofwOwcFEAlM4iKZSsckeVhENwiAzj83IGeRsTEjyOYdkgeGcJulLV+5xozFeRXpuEIskJWQVSRUL5k6gMk5Hcacw9So0dPZ33VyaQ4fTjbQwmMNObu7kn47MVUSGiOhTp86LPEF3nbsRNks/Ul3YDMigJtGl2tU+mGovg63TvUxlaNU+HCPfcoCpZE4hiUvtwyArKgWBYYAwUARNHViNnw2dUGvYTUvY1J8rQSyMNU2JIzQHh+GE74AYNJ2IgiEdYWPA8rlEGIvcKowUwiWbYMgPppKh2T4M0sfpwyWNusZ6ldmHYSNqXD/j+At3/3nUCrp7YPGolY0i93x65lCLeB7cvhrdqX0pvK/2Hcbt55ox/qdnD7WaavMcj/Gz0T5P8lGKgEct60rR96T9VSFJFp2P8nHyaDxqfSsnuB/7WqxvVTn0XSueIZxKP63UYyH/Sod4qBW3qrqS9c10Foda3299XUZSZ5EmeH6a51XwSUHTKfEEERVcxhpGHuJUXykiR5FFmdOoSj4RNYvs5o0O29zdtlMIZsLEuwisI+PMobS22DbTILqQUW3exg3G5C5YNAXaLbTAQCEY/WJ0pzKq4ygR9TaGm5NW5ZiOQUviROjdlYMcnYDgOBwMZV+mT1vSQITebHYT4xARQU0KRj7qtMmmsbo5zaTMcepYHPaTpoOtTspEc70rA1f7mTTapCC2OoUOE+N0A9QE1ZUE358/f7gZiz4txuZFCOJs1VQM5WoP0knqV4o13VaZeNiOUlRQHYUHp2EgWa2qYwwYKGWVblSB48rxx0n6paqrspNiNGzh1/ze39/TnFQVEV9RTN7QRhSe1mEU3bFkJZAuPFYlbjSRh3veN9vaWBF3CF2kr1hWNCAojdSlUuiuE1fRthtk3O2lq5+nfqtIehWCOZUh3ShRGZFzTM1FBM4haYfU6NT4UsBFDmAcjFSme55yCscr54fwa8Mx1JkpSenowfTAA9113YQiTGCEs3E/OaHgRLku/HZPY6CAOs552m5hQNdYuvASFw2tuxeu3h6hrmUQ0zVIXtQpDudSOfeKo/i5lsFdDDxR5+A3DDIIgoHs5ItTQmRKLig2zy19c48PKjrfOWQ/UWYWhJVTtdUlZKpctdI1lXp1DBzRe/ODE0XLdPMId6tXeky8T7Ut43hDpYCriSI0ne8sQjTyqY7i0BhHZoQQnn16AFx5+G5UV0X7V+Coyrc7xngX6dctoe067WUkdZReecLulgQuCM+Bq07Ehzkf5308FIwljO9XyumOFw1ZQBjctMSzm8e7RftRIK2704Ru5J1uacmtKefNDKoouwuHuweEpzlqBy5NCZTq/KZzoFtFH+ccq6scCpJWkat684WKjAp9KIio0iOHQ2HcuyetonkVKR0U8LTW/wowAHlscs+3mD4sAAAAAElFTkSuQmCC");
box-shadow: 0 0 5px rgba(0, 0, 0, 0.4) inset;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
padding: 0;
margin-top: -24px;
}
@media only screen and (max-width: 782px) {
.customize-control-color-alpha .wp-picker-input-wrap input[type=text].wp-color-picker.color-alpha-control {
width: 184px;
}
}
@media only screen and (max-width: 640px) {
.customize-control-color-alpha .wp-picker-input-wrap input[type=text].wp-color-picker.color-alpha-control {
width: 172px;
height: 33px;
}
}
/**
* Typography
*/
.customize-control-typography {
position: relative;
}
.customize-control-typography .wrapper {
padding: 10px;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
border: 1px solid rgba(0, 0, 0, 0.1);
}
.customize-control-typography .wrapper h5 {
margin: 0.67em 0 0;
}
.customize-control-typography .wrapper .font-family,
.customize-control-typography .wrapper .font-size,
.customize-control-typography .wrapper .letter-spacing,
.customize-control-typography .wrapper .line-height,
.customize-control-typography .wrapper .text-align,
.customize-control-typography .wrapper .text-transform,
.customize-control-typography .wrapper .variant {
width: 100%;
float: none;
clear: both;
}
.customize-control-typography .wrapper .font-size,
.customize-control-typography .wrapper .letter-spacing,
.customize-control-typography .wrapper .line-height,
.customize-control-typography .wrapper .text-transform {
width: 48%;
}
.customize-control-typography .wrapper .text-align .text-align-choices {
display: flex;
}
.customize-control-typography .wrapper .text-align .text-align-choices label {
width: 100%;
padding: 5px;
text-align: center;
border: 1px solid rgba(255, 255, 255, 0);
}
.customize-control-typography .wrapper .text-align .text-align-choices input {
display: none;
}
.customize-control-typography .wrapper .text-align .text-align-choices input:checked + label {
border-color: #0085ba;
}
/*# sourceMappingURL=customizer.css.map */

View File

@@ -0,0 +1,361 @@
/**
* Heading
*/
.customize-control-heading {
margin-bottom: 0;
}
/**
* Description
*/
.customize-control-description {
overflow-wrap: break-word;
}
/**
* Checkbox
*/
.customize-control-checkbox + .customize-control-checkbox {
margin-top: -12px;
}
/**
* Radio
*/
.customize-control-radio .customize-inside-control-row {
padding-bottom: 0;
}
/**
* Divider
*/
.customizer-divider {
border-bottom: 1px dashed #dcdcde;
margin: 4px -12px;
}
/**
* Color
*/
.customize-control-color[id*=is_dark],
.customize-control-color-alpha[id*=is_dark] {
position: relative;
}
.customize-control-color[id*=is_dark] .expand-setting,
.customize-control-color-alpha[id*=is_dark] .expand-setting {
position: absolute;
top: -82px;
right: 0;
padding: 10px;
cursor: pointer;
opacity: 0.5;
transition: opacity 0.25s;
}
.customize-control-color[id*=is_dark] .expand-setting:before,
.customize-control-color-alpha[id*=is_dark] .expand-setting:before {
display: block;
background-image: url("data:image/svg+xml,%3Csvg width='14' height='15' viewBox='0 0 14 15' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5.66536 4.16683C5.66523 5.09392 5.94124 6.00005 6.45818 6.76964C6.97513 7.53923 7.70959 8.1374 8.56788 8.48787C9.42618 8.83835 10.3694 8.92523 11.2773 8.73744C12.1852 8.54965 13.0165 8.09571 13.6654 7.4335V7.50016C13.6654 11.1822 10.6807 14.1668 6.9987 14.1668C3.3167 14.1668 0.332031 11.1822 0.332031 7.50016C0.332031 3.81816 3.3167 0.833496 6.9987 0.833496H7.06536C6.62139 1.26758 6.26879 1.78614 6.02835 2.35862C5.78791 2.93109 5.66449 3.54591 5.66536 4.16683ZM1.66536 7.50016C1.66488 8.69015 2.06238 9.84611 2.79463 10.7841C3.52687 11.7222 4.55179 12.3883 5.70631 12.6767C6.86082 12.9651 8.07862 12.859 9.16593 12.3755C10.2532 11.8919 11.1476 11.0586 11.7067 10.0082C10.7117 10.2426 9.67322 10.2189 8.68991 9.93931C7.7066 9.65973 6.81103 9.13355 6.08817 8.41069C5.36531 7.68783 4.83913 6.79226 4.55955 5.80895C4.27997 4.82564 4.25627 3.7872 4.4907 2.79216C3.63708 3.24692 2.92322 3.92527 2.42554 4.75459C1.92785 5.58391 1.66508 6.53297 1.66536 7.50016Z' fill='%23000000'/%3E%3C/svg%3E%0A");
background-size: contain;
width: 14px;
height: 15px;
content: "";
}
.customize-control-color[id*=is_dark] .expand-setting:hover,
.customize-control-color-alpha[id*=is_dark] .expand-setting:hover {
opacity: 1;
}
.customize-control-color[id*=is_dark].customize-control-color-open .expand-setting,
.customize-control-color-alpha[id*=is_dark].customize-control-color-open .expand-setting {
opacity: 1;
}
.customize-control-color[id*=is_dark]:not(.customize-control-color-open),
.customize-control-color-alpha[id*=is_dark]:not(.customize-control-color-open) {
margin-bottom: 0;
}
.customize-control-color[id*=is_dark]:not(.customize-control-color-open) .customize-control-title,
.customize-control-color-alpha[id*=is_dark]:not(.customize-control-color-open) .customize-control-title {
display: none;
}
.customize-control-color[id*=is_dark]:not(.customize-control-color-open) .customize-control-content,
.customize-control-color-alpha[id*=is_dark]:not(.customize-control-color-open) .customize-control-content {
display: none;
}
.customize-control-color[id*=is_dark]:not(.customize-control-color-open) .wp-picker-container,
.customize-control-color-alpha[id*=is_dark]:not(.customize-control-color-open) .wp-picker-container {
display: none;
}
/**
* Select2
*/
.select2-dropdown {
border-color: rgba(0, 0, 0, 0.1);
border-radius: 0;
}
.select2-container {
min-width: 100px;
width: 100% !important;
}
.select2-container--open .select2-dropdown--above,
.select2-container--open .select2-dropdown--below {
z-index: 9999999;
min-width: 100px;
}
.select2-container--default .select2-search--dropdown .select2-search__field {
border-color: rgba(0, 0, 0, 0.1);
}
.select2-container--default .select2-selection--multiple,
.select2-container--default .select2-selection--single {
border-color: rgba(0, 0, 0, 0.1);
border-radius: 0;
}
.select2-container--default .select2-selection--multiple .select2-selection__choice {
background-color: rgba(255, 255, 255, 0);
background-color: transparent;
border: none;
border-radius: 0;
}
.wp-customizer .select2-container {
z-index: 8 !important;
}
.wp-customizer .select2-container.select2-container--open {
z-index: 999999 !important;
}
/**
* Collapsibles
*/
.customize-control-collapsible .customize-collapsible {
position: relative;
margin: 0 -12px;
border-top: 1px solid rgba(0, 0, 0, 0.05);
}
.customize-control-collapsible .customize-collapsible h3 {
display: block;
position: relative;
margin: 0;
padding: 10px 14px;
color: #555;
background: white;
line-height: 21px;
user-select: none;
cursor: pointer;
}
.customize-control-collapsible .customize-collapsible h3:after {
position: absolute;
top: 12px;
right: 14px;
color: #a0a5aa;
font: 400 20px/1 dashicons;
content: "\f343";
}
.customize-control-collapsible .customize-collapsible h3:hover {
color: #0073aa;
background: #f5f5f5;
}
.customize-control-collapsible .customize-collapsible h3:hover:after {
color: #0073aa;
}
.customize-control-collapsible.customize-control-collapsed {
margin-bottom: 0;
}
.customize-control-collapsible.customize-control-collapsed .customize-collapsible h3:after {
content: "\f347";
}
.customize-control-hidden {
height: 0 !important;
overflow: hidden !important;
visibility: hidden;
padding: 0;
}
/**
* Alpha Color Picker CSS
*/
.customize-control-color-alpha .wp-picker-container .iris-picker {
border-bottom: none;
}
.customize-control-color-alpha .wp-picker-container {
max-width: 257px;
}
.customize-control-color-alpha .wp-picker-open + .wp-picker-input-wrap {
width: 100%;
}
.customize-control-color-alpha .wp-picker-input-wrap input[type=text].wp-color-picker.color-alpha-control {
float: left;
width: 195px;
}
.customize-control-color-alpha .wp-picker-input-wrap .button {
margin-left: 0;
float: right;
}
.wp-picker-container .wp-picker-open ~ .wp-picker-holder .color-alpha-picker-container {
display: block;
}
.color-alpha-picker-container {
border: 1px solid #dfdfdf;
border-top: none;
display: none;
background: #FFF;
padding: 0 11px 10px;
position: relative;
}
.color-alpha-picker-container .ui-widget-content,
.color-alpha-picker-container .ui-widget-header,
.color-alpha-picker-wrap .ui-state-focus {
background: transparent;
border: none;
}
.color-alpha-picker-wrap a.iris-square-value:focus {
-webkit-box-shadow: none;
box-shadow: none;
}
.color-alpha-picker-container .ui-slider {
position: relative;
z-index: 1;
height: 24px;
text-align: center;
margin: 0 auto;
width: 88%;
width: calc(100% - 28px);
}
.color-alpha-picker-container .ui-slider-handle,
.color-alpha-picker-container .ui-widget-content .ui-state-default {
color: #777;
background-color: #FFF;
text-shadow: 0 1px 0 #FFF;
text-decoration: none;
position: absolute;
z-index: 2;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
border: 1px solid #aaa;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
margin-top: -2px;
top: 0;
height: 26px;
width: 26px;
cursor: ew-resize;
font-size: 0;
padding: 0;
line-height: 27px;
margin-left: -14px;
}
.color-alpha-picker-container .ui-slider-handle.alpha {
font-size: 12px;
}
.color-alpha-picker-container .click-zone {
width: 14px;
height: 24px;
display: block;
position: absolute;
left: 10px;
}
.color-alpha-picker-container .max-click-zone {
right: 10px;
left: auto;
}
.color-alpha-picker-container .transparency {
height: 24px;
width: 100%;
background-color: #FFF;
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOkAAAAYCAYAAAAf+dpfAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MzY5NzJDNTEwNzA3MTFFNEExREREODYzQUFCRDhDREMiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MzY5NzJDNTIwNzA3MTFFNEExREREODYzQUFCRDhDREMiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDozNjk3MkM0RjA3MDcxMUU0QTFEREQ4NjNBQUJEOENEQyIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDozNjk3MkM1MDA3MDcxMUU0QTFEREQ4NjNBQUJEOENEQyIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PndQ2kgAAAbKSURBVHjarFyLUexIDFS7LhfSIJuXEmRDGiTjPt7VwnnNSN2SvVUUsLbno9Gn1aMx3t7eGBF/f+Lx+/j3r98vLy883Pd9bY//P/vh/v3z8zMW93//vZ/+56L9cz/H787t/7p+GtN+an8/tX1+nl/tH+/dF+N4+u7R/l6M5+n+r/b3ZPz76rmv9s9t79X8zfEf5aPGs5/ks6/kkI1rIf9sTMf2M5n/Gk+iP3uiU8f1tX5O7Ve6fW6/ujcO7cf52vb4ApF/UHTy/R0W93PRLk7PVX2ePzTvW12H2Vd2H4vrSJzb+Xkac8dCplnfKL5n0jeScWAxxmq+2Tho6lE1LxprguTeWAQWxn2f41xhrLOSmdTh19dXbgulQbFwWAwQpqFhoTDKKFxjVIuuFIcNobqOhcmiIpk7DSWmMQYaBsMbZBcJ4opkfZnIm4neQfSZzZMNo2BDrtV9HAQO+7M1O1xNiqYnoeFxYXrXjiAx9JbRUNBK2ZRhZIoEsR4som6IthDzCMPCEZ3XoYN+uDDmEA6AhhFXbcF0Tiz0jMncXWcmnfFmCrETWbAwSscbZRMP8zn1DAvjh1ggmsbNgaJ3kAEXkQZDB4OGA8zmB8P5XHUEk3mhGO8EjZ31OtNT3uT8nv7fzBxwshBI8liYUZGDhXFyRzW/bt9d2WSOw83F3P5ULpdxDlleTCMXQ3O9OnwDzDkqp+3yE1W+qbgOp1+Fav67/+PjA5sB2zJv7ij/FEpOcqEzvMFwQVzIOEEYFfmAqFn2K1GKhUNzU4kOenLGQ5EzsuEMOwTllUiPApJn/WYcjoVkjsSRm78oGAFh0HeybhXscxcZSWRDQXYgehFjAqNh/M8EscCUr8qdHT6iA6FhOhEXhkLI2HXWE2fn6BwSh0vDEf60e4ykLvOpYA0bofwOwcFEAlM4iKZSsckeVhENwiAzj83IGeRsTEjyOYdkgeGcJulLV+5xozFeRXpuEIskJWQVSRUL5k6gMk5Hcacw9So0dPZ33VyaQ4fTjbQwmMNObu7kn47MVUSGiOhTp86LPEF3nbsRNks/Ul3YDMigJtGl2tU+mGovg63TvUxlaNU+HCPfcoCpZE4hiUvtwyArKgWBYYAwUARNHViNnw2dUGvYTUvY1J8rQSyMNU2JIzQHh+GE74AYNJ2IgiEdYWPA8rlEGIvcKowUwiWbYMgPppKh2T4M0sfpwyWNusZ6ldmHYSNqXD/j+At3/3nUCrp7YPGolY0i93x65lCLeB7cvhrdqX0pvK/2Hcbt55ox/qdnD7WaavMcj/Gz0T5P8lGKgEct60rR96T9VSFJFp2P8nHyaDxqfSsnuB/7WqxvVTn0XSueIZxKP63UYyH/Sod4qBW3qrqS9c10Foda3299XUZSZ5EmeH6a51XwSUHTKfEEERVcxhpGHuJUXykiR5FFmdOoSj4RNYvs5o0O29zdtlMIZsLEuwisI+PMobS22DbTILqQUW3exg3G5C5YNAXaLbTAQCEY/WJ0pzKq4ygR9TaGm5NW5ZiOQUviROjdlYMcnYDgOBwMZV+mT1vSQITebHYT4xARQU0KRj7qtMmmsbo5zaTMcepYHPaTpoOtTspEc70rA1f7mTTapCC2OoUOE+N0A9QE1ZUE358/f7gZiz4txuZFCOJs1VQM5WoP0knqV4o13VaZeNiOUlRQHYUHp2EgWa2qYwwYKGWVblSB48rxx0n6paqrspNiNGzh1/ze39/TnFQVEV9RTN7QRhSe1mEU3bFkJZAuPFYlbjSRh3veN9vaWBF3CF2kr1hWNCAojdSlUuiuE1fRthtk3O2lq5+nfqtIehWCOZUh3ShRGZFzTM1FBM4haYfU6NT4UsBFDmAcjFSme55yCscr54fwa8Mx1JkpSenowfTAA9113YQiTGCEs3E/OaHgRLku/HZPY6CAOs552m5hQNdYuvASFw2tuxeu3h6hrmUQ0zVIXtQpDudSOfeKo/i5lsFdDDxR5+A3DDIIgoHs5ItTQmRKLig2zy19c48PKjrfOWQ/UWYWhJVTtdUlZKpctdI1lXp1DBzRe/ODE0XLdPMId6tXeky8T7Ut43hDpYCriSI0ne8sQjTyqY7i0BhHZoQQnn16AFx5+G5UV0X7V+Coyrc7xngX6dctoe067WUkdZReecLulgQuCM+Bq07Ehzkf5308FIwljO9XyumOFw1ZQBjctMSzm8e7RftRIK2704Ru5J1uacmtKefNDKoouwuHuweEpzlqBy5NCZTq/KZzoFtFH+ccq6scCpJWkat684WKjAp9KIio0iOHQ2HcuyetonkVKR0U8LTW/wowAHlscs+3mD4sAAAAAElFTkSuQmCC");
box-shadow: 0 0 5px rgba(0, 0, 0, 0.4) inset;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
padding: 0;
margin-top: -24px;
}
@media only screen and (max-width: 782px) {
.customize-control-color-alpha .wp-picker-input-wrap input[type=text].wp-color-picker.color-alpha-control {
width: 184px;
}
}
@media only screen and (max-width: 640px) {
.customize-control-color-alpha .wp-picker-input-wrap input[type=text].wp-color-picker.color-alpha-control {
width: 172px;
height: 33px;
}
}
/**
* Typography
*/
.customize-control-typography {
position: relative;
}
.customize-control-typography .wrapper {
padding: 10px;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
border: 1px solid rgba(0, 0, 0, 0.1);
}
.customize-control-typography .wrapper h5 {
margin: 0.67em 0 0;
}
.customize-control-typography .wrapper .font-family,
.customize-control-typography .wrapper .font-size,
.customize-control-typography .wrapper .letter-spacing,
.customize-control-typography .wrapper .line-height,
.customize-control-typography .wrapper .text-align,
.customize-control-typography .wrapper .text-transform,
.customize-control-typography .wrapper .variant {
width: 100%;
float: none;
clear: both;
}
.customize-control-typography .wrapper .font-size,
.customize-control-typography .wrapper .letter-spacing,
.customize-control-typography .wrapper .line-height,
.customize-control-typography .wrapper .text-transform {
width: 48%;
}
.customize-control-typography .wrapper .text-align .text-align-choices {
display: flex;
}
.customize-control-typography .wrapper .text-align .text-align-choices label {
width: 100%;
padding: 5px;
text-align: center;
border: 1px solid rgba(255, 255, 255, 0);
}
.customize-control-typography .wrapper .text-align .text-align-choices input {
display: none;
}
.customize-control-typography .wrapper .text-align .text-align-choices input:checked + label {
border-color: #0085ba;
}
/*# sourceMappingURL=customizer.css.map */

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,324 @@
<?php
/**
* Customizer
*
* @package Revision
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'CSCO_Customizer' ) ) {
/**
* Class Theme Customizer
*/
class CSCO_Customizer {
/**
* A reference to an instance of this class.
*
* @var object
*/
private static $instance = null;
/**
* An array of all our panels.
*
* @var array
*/
public static $panels = array();
/**
* An array of all our sections.
*
* @var array
*/
public static $sections = array();
/**
* An array of all our fields.
*
* @var array
*/
public static $fields = array();
/**
* An array of field dependencies.
*
* @var array
*/
private static $dependencies = array();
/**
* Returns the instance.
*
* @return object
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* The class constructor
*/
public function __construct() {
/** Include file helper */
require_once get_theme_file_path( '/core/customizer/class-helper.php' );
/** Include fonts modules */
require_once get_theme_file_path( '/core/customizer/modules/class-fonts.php' );
require_once get_theme_file_path( '/core/customizer/modules/class-fonts-google.php' );
require_once get_theme_file_path( '/core/customizer/modules/class-fonts-theme.php' );
require_once get_theme_file_path( '/core/customizer/modules/class-output-styles.php' );
/** Include files of controls */
if ( class_exists( 'WP_Customize_Control' ) ) {
require_once get_theme_file_path( '/core/customizer/controls/class-control-dimension.php' );
require_once get_theme_file_path( '/core/customizer/controls/class-control-divider.php' );
require_once get_theme_file_path( '/core/customizer/controls/class-control-heading.php' );
require_once get_theme_file_path( '/core/customizer/controls/class-control-multicheck.php' );
require_once get_theme_file_path( '/core/customizer/controls/class-control-collapsible.php' );
require_once get_theme_file_path( '/core/customizer/controls/class-control-color-alpha.php' );
require_once get_theme_file_path( '/core/customizer/controls/class-control-typography.php' );
}
/** Initialize actions */
add_action( 'customize_register', array( $this, 'customizer_register' ) );
add_action( 'customize_controls_enqueue_scripts', array( $this, 'customizer_controls_enqueue_scripts' ) );
add_filter( 'csco_customizer_field_add_setting_args', array( $this, 'field_add_setting_args' ) );
add_filter( 'csco_customizer_field_add_control_args', array( $this, 'field_add_control_args' ) );
}
/**
* Create a new panel.
*
* @param string $id The ID for this panel.
* @param array $args The panel arguments.
*
* @return void
*/
public static function add_panel( $id = '', $args = array() ) {
self::$panels[ $id ] = $args;
}
/**
* Create a new section.
*
* @param string $id The ID for this section.
* @param array $args The section arguments.
*
* @return void
*/
public static function add_section( $id, $args ) {
self::$sections[ $id ] = $args;
}
/**
* Create a new field
*
* @param array $args The field's arguments.
*
* @return void
*/
public static function add_field( $args ) {
if ( isset( $args['settings'] ) && isset( $args['type'] ) ) {
self::$fields[ $args['settings'] ] = $args;
}
}
/**
* Register new panels, sections and fields
*
* @param object $wp_customize The component name.
*
* @return void
*/
public function customizer_register( $wp_customize ) {
// Set panels.
foreach ( self::$panels as $panel_id => $panel_args ) {
$wp_customize->add_panel( $panel_id, $panel_args );
}
// Set sections.
foreach ( self::$sections as $section_id => $section_args ) {
$wp_customize->add_section( $section_id, $section_args );
}
// Register the custom control type.
$wp_customize->register_control_type( 'CSCO_Customize_Typography_Control' );
$wp_customize->register_control_type( 'CSCO_Customize_Multicheck_Control' );
// Set fields.
foreach ( self::$fields as $field_id => $field_args ) {
/**
* The csco_customizer_field_add_setting_args hook.
*
* @since 1.0.0
*/
$params = apply_filters( 'csco_customizer_field_add_setting_args', $field_args, $wp_customize );
call_user_func( array( $wp_customize, 'add_setting' ), $field_id, $params );
/**
* The csco_customizer_field_add_control_args hook.
*
* @since 1.0.0
*/
$args = apply_filters( 'csco_customizer_field_add_control_args', $field_args, $wp_customize );
switch ( $field_args['type'] ) {
case 'color':
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, $field_id, $args ) );
break;
case 'image':
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, $field_id, $args ) );
break;
case 'dimension':
$wp_customize->add_control( new CSCO_Customize_Dimension_Control( $wp_customize, $field_id, $args ) );
break;
case 'divider':
$wp_customize->add_control( new CSCO_Customize_Divider_Control( $wp_customize, $field_id, $args ) );
break;
case 'heading':
$wp_customize->add_control( new CSCO_Customize_Heading_Control( $wp_customize, $field_id, $args ) );
break;
case 'multicheck':
$wp_customize->add_control( new CSCO_Customize_Multicheck_Control( $wp_customize, $field_id, $args ) );
break;
case 'collapsible':
$wp_customize->add_control( new CSCO_Customize_Collapsible_Control( $wp_customize, $field_id, $args ) );
break;
case 'color-alpha':
$wp_customize->add_control( new CSCO_Customize_Color_Alpha_Control( $wp_customize, $field_id, $args ) );
break;
case 'typography':
$wp_customize->add_control( new CSCO_Customize_Typography_Control( $wp_customize, $field_id, $args ) );
break;
default:
$wp_customize->add_control( $field_id, $args );
break;
}
}
}
/**
* Filter setting arguments.
*
* @param array $args The field arguments.
*
* @return array
*/
public function field_add_setting_args( $args ) {
$args = array(
'type' => isset( $args['type_mod'] ) ? $args['type_mod'] : 'theme_mod',
'capability' => isset( $args['capability'] ) ? $args['capability'] : 'edit_theme_options',
'theme_supports' => isset( $args['theme_supports'] ) ? $args['theme_supports'] : '',
'default' => isset( $args['default'] ) ? $args['default'] : '',
'transport' => isset( $args['transport'] ) ? $args['transport'] : 'refresh',
'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : '',
'sanitize_js_callback' => isset( $args['sanitize_js_callback'] ) ? $args['sanitize_js_callback'] : '',
);
return $args;
}
/**
* Filter control arguments.
*
* @param array $args The field arguments.
*
* @return array
*/
public function field_add_control_args( $args ) {
if ( isset( $args['active_callback'] ) ) {
if ( is_array( $args['active_callback'] ) ) {
if ( ! is_callable( $args['active_callback'] ) ) {
foreach ( $args['active_callback'] as $key => $val ) {
if ( is_callable( $val ) ) {
unset( $args['active_callback'][ $key ] );
}
}
if ( isset( $args['active_callback'][0] ) ) {
$args['required'] = $args['active_callback'];
}
}
}
if ( ! empty( $args['required'] ) ) {
self::$dependencies[ $args['settings'] ] = $args['required'];
$args['active_callback'] = '__return_true';
return $args;
}
// No need to proceed any further if we're using the default value.
if ( '__return_true' === $args['active_callback'] ) {
return $args;
}
// Make sure the function is callable, otherwise fallback to __return_true.
if ( ! is_callable( $args['active_callback'] ) ) {
$args['active_callback'] = '__return_true';
}
}
return $args;
}
/**
* Enqueue Customizer control scripts.
*
* @return void
*/
public function customizer_controls_enqueue_scripts() {
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker' );
// Register customize selectWoo scripts.
wp_register_script( 'selectWoo', get_theme_file_uri( '/core/customizer/assets/selectWoo.full.min.js' ), array( 'jquery' ), filemtime( get_theme_file_path( '/core/customizer/assets/selectWoo.full.min.js' ) ), true );
// Register customize scripts.
wp_register_script( 'cs-customizer', get_theme_file_uri( '/core/customizer/assets/customizer.js' ), array( 'jquery', 'customize-controls', 'selectWoo' ), filemtime( get_theme_file_path( '/core/customizer/assets/customizer.js' ) ), true );
// Localize customize scripts.
wp_localize_script( 'cs-customizer', 'cscoCustomizerConfig', array(
'dependencies' => self::$dependencies,
'advanced_settings' => esc_html__( 'Advanced settings', 'revision' ),
'noFileSelected' => esc_html__( 'No File Selected', 'revision' ),
'remove' => esc_html__( 'Remove', 'revision' ),
'default' => esc_html__( 'Default', 'revision' ),
'selectFile' => esc_html__( 'Select File', 'revision' ),
'standardFonts' => esc_html__( 'Standard Fonts', 'revision' ),
'googleFonts' => esc_html__( 'Google Fonts', 'revision' ),
'defaultCSSValues' => esc_html__( 'CSS Defaults', 'revision' ),
'defaultBrowserFamily' => esc_html__( 'Default Browser Font-Family', 'revision' ),
) );
// Enqueue customize scripts.
wp_enqueue_script( 'cs-customizer' );
// Register customize select2 style.
wp_register_style( 'selectWoo', get_theme_file_uri( '/core/customizer/assets/selectWoo.min.css' ), array(), filemtime( get_theme_file_path( '/core/customizer/assets/selectWoo.min.css' ) ) );
// Register customize style.
wp_register_style( 'cs-customizer', get_theme_file_uri( '/core/customizer/assets/customizer.css' ), array( 'selectWoo' ), filemtime( get_theme_file_path( '/core/customizer/assets/customizer.css' ) ) );
// Enqueue customize style.
wp_enqueue_style( 'cs-customizer' );
}
}
if ( ! function_exists( 'csco_customizer' ) ) {
/**
* Returns instanse of the Theme Customizer class.
*
* @return object
*/
function csco_customizer() {
return CSCO_Customizer::get_instance();
}
}
csco_customizer();
}

View File

@@ -0,0 +1,199 @@
<?php
/**
* Helper methods
*
* @package Revision
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* A simple object containing static methods.
*/
class CSCO_Customizer_Helper {
/**
* Get the value of a field.
*
* @param string $field_id The field ID.
*/
public static function get_value( $field_id = '' ) {
// Make sure value is defined.
$value = __return_empty_string();
// We're using theme_mods so just get the value using get_theme_mod.
$default_value = __return_null();
if ( isset( CSCO_Customizer::$fields[ $field_id ] ) && isset( CSCO_Customizer::$fields[ $field_id ]['default'] ) ) {
$default_value = CSCO_Customizer::$fields[ $field_id ]['default'];
}
$value = get_theme_mod( $field_id, $default_value );
/**
* The csco_customizer_values_get_value hook.
*
* @since 1.0.0
*/
return apply_filters( 'csco_customizer_values_get_value', $value, $field_id );
}
/**
* Compares the 2 values given the condition
*
* @param mixed $value1 The 1st value in the comparison.
* @param mixed $value2 The 2nd value in the comparison.
* @param string $operator The operator we'll use for the comparison.
* @return boolean whether The comparison has succeded (true) or failed (false).
*/
public static function compare_values( $value1, $value2, $operator ) {
if ( '===' === $operator ) {
return $value1 === $value2;
}
if ( '!==' === $operator ) {
return $value1 !== $value2;
}
if ( ( '!=' === $operator || 'not equal' === $operator ) ) {
return $value1 != $value2; // phpcs:ignore WordPress.PHP.StrictComparisons
}
if ( ( '>=' === $operator || 'greater or equal' === $operator || 'equal or greater' === $operator ) ) {
return $value2 >= $value1;
}
if ( ( '<=' === $operator || 'smaller or equal' === $operator || 'equal or smaller' === $operator ) ) {
return $value2 <= $value1;
}
if ( ( '>' === $operator || 'greater' === $operator ) ) {
return $value2 > $value1;
}
if ( ( '<' === $operator || 'smaller' === $operator ) ) {
return $value2 < $value1;
}
if ( 'contains' === $operator || 'in' === $operator ) {
if ( is_array( $value1 ) && is_array( $value2 ) ) {
foreach ( $value2 as $val ) {
if ( in_array( $val, $value1 ) ) { // phpcs:ignore WordPress.PHP.StrictInArray
return true;
}
}
return false;
}
if ( is_array( $value1 ) && ! is_array( $value2 ) ) {
return in_array( $value2, $value1 ); // phpcs:ignore WordPress.PHP.StrictInArray
}
if ( is_array( $value2 ) && ! is_array( $value1 ) ) {
return in_array( $value1, $value2 ); // phpcs:ignore WordPress.PHP.StrictInArray
}
return ( false !== strrpos( $value1, $value2 ) || false !== strpos( $value2, $value1 ) );
}
return $value1 == $value2; // phpcs:ignore WordPress.PHP.StrictComparisons
}
/**
* Process the active_callback parameter.
*
* @param array $field The current field.
*/
public static function active_callback( $field ) {
if ( isset( $field['active_callback'] ) && is_array( $field['active_callback'] ) ) {
if ( ! is_callable( $field['active_callback'] ) ) {
foreach ( $field['active_callback'] as $key => $val ) {
if ( is_callable( $val ) ) {
unset( $field['active_callback'][ $key ] );
}
}
if ( isset( $field['active_callback'][0] ) ) {
$field['required'] = $field['active_callback'];
}
}
}
// Only continue if field dependencies are met.
if ( isset( $field['required'] ) && ! empty( $field['required'] ) ) {
$valid = true;
foreach ( $field['required'] as $requirement ) {
if ( isset( $requirement['setting'] ) && isset( $requirement['value'] ) && isset( $requirement['operator'] ) ) {
$controller_value = self::get_value( $requirement['setting'] );
if ( ! self::compare_values( $controller_value, $requirement['value'], $requirement['operator'] ) ) {
$valid = false;
}
}
}
if ( ! $valid ) {
return false;
}
}
return true;
}
/**
* Sanitizes typography controls
*
* @param array $value The value.
*/
public static function typography_sanitize( $value ) {
if ( ! is_array( $value ) ) {
return array();
}
foreach ( $value as $key => $val ) {
switch ( $key ) {
case 'font-family':
$value['font-family'] = sanitize_text_field( $val );
break;
case 'font-weight':
if ( isset( $value['variant'] ) ) {
break;
}
$value['variant'] = $val;
if ( isset( $value['font-style'] ) && 'italic' === $value['font-style'] ) {
$value['variant'] = ( '400' !== $val || 400 !== $val ) ? $value['variant'] . 'italic' : 'italic';
}
break;
case 'variant':
// Use 'regular' instead of 400 for font-variant.
$value['variant'] = ( 400 === $val || '400' === $val ) ? 'regular' : $val;
// Get font-weight from variant.
$value['font-weight'] = filter_var( $value['variant'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
$value['font-weight'] = ( 'regular' === $value['variant'] || 'italic' === $value['variant'] ) ? 400 : absint( $value['font-weight'] );
// Get font-style from variant.
if ( ! isset( $value['font-style'] ) ) {
$value['font-style'] = ( false === strpos( $value['variant'], 'italic' ) ) ? 'normal' : 'italic';
}
break;
case 'font-size':
case 'letter-spacing':
case 'word-spacing':
case 'line-height':
$value[ $key ] = '' === trim( $value[ $key ] ) ? '' : sanitize_text_field( $val );
break;
case 'text-align':
if ( ! in_array( $val, array( '', 'inherit', 'left', 'center', 'right', 'justify' ), true ) ) {
$value['text-align'] = '';
}
break;
case 'text-transform':
if ( ! in_array( $val, array( '', 'none', 'capitalize', 'uppercase', 'lowercase', 'initial', 'inherit' ), true ) ) {
$value['text-transform'] = '';
}
break;
case 'text-decoration':
if ( ! in_array( $val, array( '', 'none', 'underline', 'overline', 'line-through', 'initial', 'inherit' ), true ) ) {
$value['text-transform'] = '';
}
break;
}
}
return $value;
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* Customizer Collapsible
*
* @package Revision
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'CSCO_Customize_Collapsible_Control' ) ) {
/**
* Class Customize Collapsible
*/
class CSCO_Customize_Collapsible_Control extends WP_Customize_Control {
/**
* The field type.
*
* @var string
*/
public $type = 'collapsible';
/**
* Render the control content.
*/
protected function render_content() {
$collapsed_class = null;
if ( isset( $this->input_attrs['collapsed'] ) && $this->input_attrs['collapsed'] ) {
$collapsed_class = 'customize-collapsed';
}
?>
<div class="customize-collapsible <?php echo esc_attr( $collapsed_class ); ?>"><h3><?php echo esc_html( $this->label ); ?></h3></div>
<?php
}
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* Customizer Color Alpha
*
* @package Revision
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'CSCO_Customize_Color_Alpha_Control' ) ) {
/**
* Class Customize Color Alpha
*/
class CSCO_Customize_Color_Alpha_Control extends WP_Customize_Control {
/**
* The field type.
*
* @var string
*/
public $type = 'color-alpha';
/**
* Add support for palettes to be passed in.
*
* Supported palette values are true, false, or an array of RGBa and Hex colors.
*
* @var bool
*/
public $palette;
/**
* Add support for showing the opacity value on the slider handle.
*
* @var bool
*/
public $alpha;
/**
* Render the control.
*/
public function render_content() {
if ( is_array( $this->palette ) ) {
$palette = implode( '|', $this->palette );
} else {
$palette = ( false === $this->palette || 'false' === $this->palette ) ? 'false' : 'true';
}
$alpha = ( false === $this->alpha || 'false' === $this->alpha ) ? 'false' : 'true';
?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php
if ( isset( $this->description ) && $this->description ) {
?>
<span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
<?php
}
?>
</label>
<input class="color-alpha-control" type="text" data-alpha="<?php echo esc_attr( $alpha ); ?>" data-palette="<?php echo esc_attr( $palette ); ?>" data-default-color="<?php echo esc_attr( $this->settings['default']->default ); ?>" <?php $this->link(); ?> />
<?php
}
}
}

View File

@@ -0,0 +1,47 @@
<?php
/**
* Customizer Dimension
*
* @package Revision
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'CSCO_Customize_Dimension_Control' ) ) {
/**
* Class Customize Dimension
*/
class CSCO_Customize_Dimension_Control extends WP_Customize_Control {
/**
* The field type.
*
* @var string
*/
public $type = 'dimension';
/**
* Render the control content.
*/
protected function render_content() {
?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php
if ( isset( $this->description ) && $this->description ) {
?>
<span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
<?php
}
?>
<input type="text" <?php $this->link(); ?> value="<?php echo esc_attr( $this->value() ); ?>"/>
</label>
<?php
}
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* Customizer Divider
*
* @package Revision
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'CSCO_Customize_Divider_Control' ) ) {
/**
* Class Customize Divider
*/
class CSCO_Customize_Divider_Control extends WP_Customize_Control {
/**
* The field type.
*
* @var string
*/
public $type = 'divider';
/**
* Render the control content.
*/
protected function render_content() {
?>
<div class="customizer-divider"></div>
<?php
}
}
}

View File

@@ -0,0 +1,45 @@
<?php
/**
* Customizer Heading
*
* @package Revision
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'CSCO_Customize_Heading_Control' ) ) {
/**
* Class Customize Heading
*/
class CSCO_Customize_Heading_Control extends WP_Customize_Control {
/**
* The field type.
*
* @var string
*/
public $type = 'heading';
/**
* Render the control content.
*/
protected function render_content() {
?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php
if ( isset( $this->description ) && $this->description ) {
?>
<span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
<?php
}
?>
</label>
<?php
}
}
}

View File

@@ -0,0 +1,115 @@
<?php
/**
* Customizer Multicheck
*
* @package Revision
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'CSCO_Customize_Multicheck_Control' ) ) {
/**
* Class Customize Multicheck
*/
class CSCO_Customize_Multicheck_Control extends WP_Customize_Control {
/**
* The field type.
*
* @var string
*/
public $type = 'multicheck';
/**
* Constructor.
*
* @param WP_Customize_Manager $manager Customizer bootstrap instance.
* @param string $id Control ID.
* @param array $args The args.
*/
public function __construct( $manager, $id, $args = array() ) {
parent::__construct( $manager, $id, $args );
// Init choices.
if ( ! is_array( $this->choices ) ) {
$this->choices = array();
}
}
/**
* Render the control's content.
*/
protected function render_content() {}
/**
* Sets the $sanitize_callback
*/
protected function sanitize_callback() {
// If a custom sanitize_callback has been defined,
// then we don't need to proceed any further.
if ( ! empty( $this->sanitize_callback ) ) {
return;
}
$this->sanitize_callback = array( $this, 'sanitize' );
}
/**
* The sanitize method that will be used as a falback
*
* @param string|array $value The control's value.
*/
public function sanitize( $value ) {
$value = ( ! is_array( $value ) ) ? explode( ',', $value ) : $value;
return ( ! empty( $value ) ) ? array_map( 'sanitize_text_field', $value ) : array();
}
/**
* Refresh the parameters passed to the JavaScript via JSON.
*
* @see WP_Customize_Control::to_json()
*/
public function to_json() {
parent::to_json();
// Value.
$this->json['value'] = $this->value();
// The link.
$this->json['link'] = $this->get_link();
// Choices.
$this->json['choices'] = $this->choices;
// The ID.
$this->json['id'] = $this->id;
}
/**
* An Underscore (JS) template for this control's content (but not its container).
*
* Class variables for this control class are available in the `data` JS object;
* export custom variables by overriding {@see WP_Customize_Control::to_json()}.
*
* @see WP_Customize_Control::print_template()
*/
protected function content_template() {
?>
<# if ( ! data.choices ) { return; } #>
<# if ( data.label ) { #><span class="customize-control-title">{{{ data.label }}}</span><# } #>
<# if ( data.description ) { #><span class="description customize-control-description">{{{ data.description }}}</span><# } #>
<ul>
<# for ( key in data.choices ) { #>
<li><label<# if ( _.contains( data.value, key ) ) { #> class="checked"<# } #>><input {{{ data.inputAttrs }}} type="checkbox" value="{{ key }}"<# if ( _.contains( data.value, key ) ) { #> checked<# } #> />{{ data.choices[ key ] }}</label></li>
<# } #>
</ul>
<?php
}
}
}

View File

@@ -0,0 +1,278 @@
<?php
/**
* Customizer Typography
*
* @package Revision
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'CSCO_Customize_Typography_Control' ) ) {
/**
* Class Customize Typography
*/
class CSCO_Customize_Typography_Control extends WP_Customize_Control {
/**
* Control's Type.
*
* @var string
*/
public $type = 'typography';
/**
* Constructor.
*
* @param WP_Customize_Manager $manager Customizer bootstrap instance.
* @param string $id Control ID.
* @param array $args The args.
*/
public function __construct( $manager, $id, $args = array() ) {
parent::__construct( $manager, $id, $args );
// Init choices.
if ( ! is_array( $this->choices ) ) {
$this->choices = array();
}
/**
* The csco_customizer_fonts_choices hook.
*
* @since 1.0.0
*/
$this->choices = apply_filters( 'csco_customizer_fonts_choices', wp_parse_args(
$this->choices,
array(
'variant' => array(),
'fonts' => array(
'standard' => array(),
'google' => array(),
),
)
) );
}
/**
* Render the control's content.
*/
protected function render_content() {}
/**
* Refresh the parameters passed to the JavaScript via JSON.
*
* @see WP_Customize_Control::to_json()
*/
public function to_json() {
parent::to_json();
// Default value.
$this->json['default'] = $this->setting->default;
if ( isset( $this->default ) ) {
$this->json['default'] = $this->default;
}
// Value.
$this->json['value'] = $this->value();
// The link.
$this->json['link'] = $this->get_link();
// Choices.
$this->json['choices'] = $this->choices;
// The ID.
$this->json['id'] = $this->id;
// The filter value.
if ( is_array( $this->json['value'] ) ) {
foreach ( array_keys( $this->json['value'] ) as $key ) {
if ( ! in_array( $key, array( 'variant', 'font-weight', 'font-style' ), true ) && ! isset( $this->json['default'][ $key ] ) ) {
unset( $this->json['value'][ $key ] );
}
if ( ! isset( $this->json['default'][ $key ] ) ) {
unset( $this->json['value'][ $key ] );
}
if ( isset( $this->json['default'][ $key ] ) && false === $this->json['default'][ $key ] ) {
unset( $this->json['value'][ $key ] );
}
}
}
$this->json['show_variants'] = true;
}
/**
* An Underscore (JS) template for this control's content (but not its container).
*
* Class variables for this control class are available in the `data` JS object;
* export custom variables by overriding {@see WP_Customize_Control::to_json()}.
*
* @see WP_Customize_Control::print_template()
*/
protected function content_template() {
?>
<label class="customizer-text">
<# if ( data.label ) { #><span class="customize-control-title">{{{ data.label }}}</span><# } #>
<# if ( data.description ) { #><span class="description customize-control-description">{{{ data.description }}}</span><# } #>
</label>
<div class="wrapper">
<# if ( ! _.isUndefined( data.default['font-family'] ) ) { #>
<# data.value['font-family'] = data.value['font-family'] || data['default']['font-family']; #>
<# if ( data.choices['fonts'] ) { data.fonts = data.choices['fonts']; } #>
<div class="font-family">
<h5><?php esc_html_e( 'Font Family', 'revision' ); ?></h5>
<select {{{ data.inputAttrs }}} id="cs-typography-font-family-{{{ data.id }}}" placeholder="<?php esc_attr_e( 'Select Font Family', 'revision' ); ?>"></select>
</div>
<# if ( true === data.show_variants || false !== data.default.variant ) { #>
<div class="variant cs-variant-wrapper">
<h5><?php esc_html_e( 'Variant', 'revision' ); ?></h5>
<select {{{ data.inputAttrs }}} class="variant" id="cs-typography-variant-{{{ data.id }}}"></select>
</div>
<# } #>
<# } #>
<# if ( ! _.isUndefined( data.default['font-size'] ) ) { #>
<# data.value['font-size'] = data.value['font-size'] || data['default']['font-size']; #>
<div class="font-size">
<h5><?php esc_html_e( 'Font Size', 'revision' ); ?></h5>
<input {{{ data.inputAttrs }}} type="text" value="{{ data.value['font-size'] }}"/>
</div>
<# } #>
<# if ( ! _.isUndefined( data.default['line-height'] ) ) { #>
<# data.value['line-height'] = data.value['line-height'] || data['default']['line-height']; #>
<div class="line-height">
<h5><?php esc_html_e( 'Line Height', 'revision' ); ?></h5>
<input {{{ data.inputAttrs }}} type="text" value="{{ data.value['line-height'] }}"/>
</div>
<# } #>
<# if ( ! _.isUndefined( data.default['letter-spacing'] ) ) { #>
<# data.value['letter-spacing'] = data.value['letter-spacing'] || data['default']['letter-spacing']; #>
<div class="letter-spacing">
<h5><?php esc_html_e( 'Letter Spacing', 'revision' ); ?></h5>
<input {{{ data.inputAttrs }}} type="text" value="{{ data.value['letter-spacing'] }}"/>
</div>
<# } #>
<# if ( ! _.isUndefined( data.default['word-spacing'] ) ) { #>
<# data.value['word-spacing'] = data.value['word-spacing'] || data['default']['word-spacing']; #>
<div class="word-spacing">
<h5><?php esc_html_e( 'Word Spacing', 'revision' ); ?></h5>
<input {{{ data.inputAttrs }}} type="text" value="{{ data.value['word-spacing'] }}"/>
</div>
<# } #>
<# if ( ! _.isUndefined( data.default['text-align'] ) ) { #>
<# data.value['text-align'] = data.value['text-align'] || data['default']['text-align']; #>
<div class="text-align">
<h5><?php esc_html_e( 'Text Align', 'revision' ); ?></h5>
<div class="text-align-choices">
<input {{{ data.inputAttrs }}} type="radio" value="inherit" name="_customize-typography-text-align-radio-{{ data.id }}" id="{{ data.id }}-text-align-inherit" <# if ( data.value['text-align'] === 'inherit' ) { #> checked="checked"<# } #>>
<label for="{{ data.id }}-text-align-inherit">
<span class="dashicons dashicons-editor-removeformatting"></span>
<span class="screen-reader-text"><?php esc_html_e( 'Inherit', 'revision' ); ?></span>
</label>
</input>
<input {{{ data.inputAttrs }}} type="radio" value="left" name="_customize-typography-text-align-radio-{{ data.id }}" id="{{ data.id }}-text-align-left" <# if ( data.value['text-align'] === 'left' ) { #> checked="checked"<# } #>>
<label for="{{ data.id }}-text-align-left">
<span class="dashicons dashicons-editor-alignleft"></span>
<span class="screen-reader-text"><?php esc_html_e( 'Left', 'revision' ); ?></span>
</label>
</input>
<input {{{ data.inputAttrs }}} type="radio" value="center" name="_customize-typography-text-align-radio-{{ data.id }}" id="{{ data.id }}-text-align-center" <# if ( data.value['text-align'] === 'center' ) { #> checked="checked"<# } #>>
<label for="{{ data.id }}-text-align-center">
<span class="dashicons dashicons-editor-aligncenter"></span>
<span class="screen-reader-text"><?php esc_html_e( 'Center', 'revision' ); ?></span>
</label>
</input>
<input {{{ data.inputAttrs }}} type="radio" value="right" name="_customize-typography-text-align-radio-{{ data.id }}" id="{{ data.id }}-text-align-right" <# if ( data.value['text-align'] === 'right' ) { #> checked="checked"<# } #>>
<label for="{{ data.id }}-text-align-right">
<span class="dashicons dashicons-editor-alignright"></span>
<span class="screen-reader-text"><?php esc_html_e( 'Right', 'revision' ); ?></span>
</label>
</input>
<input {{{ data.inputAttrs }}} type="radio" value="justify" name="_customize-typography-text-align-radio-{{ data.id }}" id="{{ data.id }}-text-align-justify" <# if ( data.value['text-align'] === 'justify' ) { #> checked="checked"<# } #>>
<label for="{{ data.id }}-text-align-justify">
<span class="dashicons dashicons-editor-justify"></span>
<span class="screen-reader-text"><?php esc_html_e( 'Justify', 'revision' ); ?></span>
</label>
</input>
</div>
</div>
<# } #>
<# if ( ! _.isUndefined( data.default['text-transform'] ) ) { #>
<# data.value['text-transform'] = data.value['text-transform'] || data['default']['text-transform']; #>
<div class="text-transform">
<h5><?php esc_html_e( 'Text Transform', 'revision' ); ?></h5>
<select {{{ data.inputAttrs }}} id="cs-typography-text-transform-{{{ data.id }}}">
<option value=""<# if ( '' === data.value['text-transform'] ) { #>selected<# } #>></option>
<option value="none"<# if ( 'none' === data.value['text-transform'] ) { #>selected<# } #>><?php esc_html_e( 'None', 'revision' ); ?></option>
<option value="capitalize"<# if ( 'capitalize' === data.value['text-transform'] ) { #>selected<# } #>><?php esc_html_e( 'Capitalize', 'revision' ); ?></option>
<option value="uppercase"<# if ( 'uppercase' === data.value['text-transform'] ) { #>selected<# } #>><?php esc_html_e( 'Uppercase', 'revision' ); ?></option>
<option value="lowercase"<# if ( 'lowercase' === data.value['text-transform'] ) { #>selected<# } #>><?php esc_html_e( 'Lowercase', 'revision' ); ?></option>
<option value="initial"<# if ( 'initial' === data.value['text-transform'] ) { #>selected<# } #>><?php esc_html_e( 'Initial', 'revision' ); ?></option>
<option value="inherit"<# if ( 'inherit' === data.value['text-transform'] ) { #>selected<# } #>><?php esc_html_e( 'Inherit', 'revision' ); ?></option>
</select>
</div>
<# } #>
<# if ( ! _.isUndefined( data.default['text-decoration'] ) ) { #>
<# data.value['text-decoration'] = data.value['text-decoration'] || data['default']['text-decoration']; #>
<div class="text-decoration">
<h5><?php esc_html_e( 'Text Decoration', 'revision' ); ?></h5>
<select {{{ data.inputAttrs }}} id="cs-typography-text-decoration-{{{ data.id }}}">
<option value=""<# if ( '' === data.value['text-decoration'] ) { #>selected<# } #>></option>
<option value="none"<# if ( 'none' === data.value['text-decoration'] ) { #>selected<# } #>><?php esc_html_e( 'None', 'revision' ); ?></option>
<option value="underline"<# if ( 'underline' === data.value['text-decoration'] ) { #>selected<# } #>><?php esc_html_e( 'Underline', 'revision' ); ?></option>
<option value="overline"<# if ( 'overline' === data.value['text-decoration'] ) { #>selected<# } #>><?php esc_html_e( 'Overline', 'revision' ); ?></option>
<option value="line-through"<# if ( 'line-through' === data.value['text-decoration'] ) { #>selected<# } #>><?php esc_html_e( 'Line-Through', 'revision' ); ?></option>
<option value="initial"<# if ( 'initial' === data.value['text-decoration'] ) { #>selected<# } #>><?php esc_html_e( 'Initial', 'revision' ); ?></option>
<option value="inherit"<# if ( 'inherit' === data.value['text-decoration'] ) { #>selected<# } #>><?php esc_html_e( 'Inherit', 'revision' ); ?></option>
</select>
</div>
<# } #>
</div>
<input class="typography-hidden-value" type="hidden" {{{ data.link }}}>
<?php
}
/**
* Formats variants.
*
* @param array $variants The variants.
* @return array
*/
protected function format_variants_array( $variants ) {
$all_variants = CSCO_Customizer_Fonts::get_all_variants();
$final_variants = array();
foreach ( $variants as $variant ) {
if ( is_string( $variant ) ) {
$final_variants[] = array(
'id' => $variant,
'label' => isset( $all_variants[ $variant ] ) ? $all_variants[ $variant ] : $variant,
);
} elseif ( is_array( $variant ) && isset( $variant['id'] ) && isset( $variant['label'] ) ) {
$final_variants[] = $variant;
}
}
return $final_variants;
}
}
}

View File

@@ -0,0 +1,218 @@
<?php
/**
* Customizer Fonts Google
*
* @package Revision
*/
if ( ! class_exists( 'CSCO_Customizer_Fonts_Google' ) ) {
/**
* Customizer Fonts Google Class.
*/
final class CSCO_Customizer_Fonts_Google {
/**
* The array of fonts
*
* @var array
*/
public $fonts_output = array();
/**
* An array of all google fonts.
*
* @var array
*/
private $google_fonts = array();
/**
* Fonts to load.
*
* @var array
*/
protected $fonts_to_load = array();
/**
* The class constructor.
*/
public function __construct() {
$this->google_fonts = CSCO_Customizer_Fonts::get_google_fonts();
/** Initialize actions */
add_action( 'wp_loaded', array( $this, 'populate_fonts' ) );
add_filter( 'wp_resource_hints', array( $this, 'resource_hints' ), 10, 2 );
if ( ! is_admin() || is_customize_preview() ) {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_google_fonts' ), 999 );
} else {
add_action( 'enqueue_block_assets', array( $this, 'enqueue_google_fonts' ), 999 );
}
}
/**
* Loader for Google Fonts.
*/
public function populate_fonts() {
// Go through our fields and populate $this->fonts_output.
$this->loop_fields();
// Goes through $this->fonts_output and adds or removes things as needed.
$this->process_fonts();
foreach ( $this->fonts_output as $font => $weights ) {
foreach ( $weights as $key => $value ) {
if ( 'italic' === $value ) {
$weights[ $key ] = '400i';
} else {
$weights[ $key ] = str_replace( array( 'regular', 'bold', 'italic' ), array( '400', '', 'i' ), $value );
}
}
$this->fonts_to_load[] = array(
'family' => $font,
'weights' => $weights,
);
}
}
/**
* Goes through all our fields and then populates the $this->fonts_output property.
*/
public function loop_fields() {
$fields = CSCO_Customizer::$fields;
if ( is_array( $fields ) && $fields ) {
foreach ( $fields as $field ) {
if ( ! isset( $field['type'] ) || false === strpos( $field['type'], 'typography' ) ) {
continue;
}
// Check active callback.
if ( ! CSCO_Customizer_Helper::active_callback( $field ) ) {
continue;
}
// Get the value.
$value = CSCO_Customizer_Helper::get_value( $field['settings'] );
// If we don't have a font-family then we can skip this.
if ( ! isset( $value['font-family'] ) ) {
continue;
}
// If not a google-font, then we can skip this.
if ( ! isset( $value['font-family'] ) || ! CSCO_Customizer_Fonts::is_google_font( $value['font-family'] ) ) {
continue;
}
// Set a default value for variants.
if ( ! isset( $value['variant'] ) ) {
$value['variant'] = 'regular';
}
// Add the requested google-font.
if ( ! isset( $this->fonts_output[ $value['font-family'] ] ) ) {
$this->fonts_output[ $value['font-family'] ] = array();
}
if ( ! in_array( $value['variant'], $this->fonts_output[ $value['font-family'] ], true ) ) {
$this->fonts_output[ $value['font-family'] ][] = $value['variant'];
}
if ( isset( $field['choices']['variant'] ) && is_array( $field['choices']['variant'] ) ) {
foreach ( $field['choices']['variant'] as $extra_variant ) {
if ( ! in_array( $extra_variant, $this->fonts_output[ $value['font-family'] ], true ) ) {
$this->fonts_output[ $value['font-family'] ][] = $extra_variant;
}
}
}
}
}
}
/**
* Determines the vbalidity of the selected font as well as its properties.
* This is vital to make sure that the google-font script that we'll generate later
* does not contain any invalid options.
*/
public function process_fonts() {
// Early exit if font-family is empty.
if ( empty( $this->fonts_output ) ) {
return;
}
foreach ( $this->fonts_output as $font => $variants ) {
// Determine if this is indeed a google font or not.
// If it's not, then just remove it from the array.
if ( ! array_key_exists( $font, $this->google_fonts ) ) {
unset( $this->fonts_output[ $font ] );
continue;
}
// Get all valid font variants for this font.
$font_variants = array();
if ( isset( $this->google_fonts[ $font ]['variants'] ) ) {
$font_variants = $this->google_fonts[ $font ]['variants'];
}
foreach ( $variants as $variant ) {
// If this is not a valid variant for this font-family
// then unset it and move on to the next one.
if ( ! in_array( strval( $variant ), $font_variants, true ) ) {
$variant_key = array_search( $variant, $this->fonts_output[ $font ], true );
unset( $this->fonts_output[ $font ][ $variant_key ] );
continue;
}
}
}
}
/**
* Add preconnect for Google Fonts.
*
* @param array $urls URLs to print for resource hints.
* @param string $relation_type The relation type the URLs are printed.
*/
public function resource_hints( $urls, $relation_type ) {
$fonts_to_load = $this->fonts_output;
if ( ! empty( $fonts_to_load ) && 'preconnect' === $relation_type ) {
$urls[] = array(
'href' => 'https://fonts.gstatic.com',
'crossorigin',
);
}
return $urls;
}
/**
* Enqueue Google fonts.
*/
public function enqueue_google_fonts() {
foreach ( $this->fonts_to_load as $font ) {
// Set family.
$family = str_replace( ' ', '+', trim( $font['family'] ) );
// Set weights.
$weights = join( ',', $font['weights'] );
/**
* The csco_customizer_google_fonts_subset hook.
*
* @since 1.0.0
*/
$subset = apply_filters( 'csco_customizer_google_fonts_subset', 'latin,latin-ext,cyrillic,cyrillic-ext,vietnamese' );
$url = "https://fonts.googleapis.com/css?family={$family}:{$weights}&subset={$subset}&display=swap";
wp_enqueue_style( md5( $url ), $url, array(), csco_get_theme_data( 'Version' ) );
}
}
}
new CSCO_Customizer_Fonts_Google();
}

View File

@@ -0,0 +1,250 @@
<?php
/**
* Customizer Theme Fonts Google
*
* @package Revision
*/
if ( ! class_exists( 'CSCO_Customizer_Fonts_Theme' ) ) {
/**
* Customizer Fonts Theme Class.
*/
final class CSCO_Customizer_Fonts_Theme {
/**
* The theme fonts.
*
* @var array
*/
public $fonts_output = array();
/**
* The theme all variants.
*
* @var array
*/
public $variants_output = array();
/**
* The class constructor
*/
public function __construct() {
/**
* The csco_theme_fonts hook.
*
* @since 1.0.0
*/
$this->fonts_output = apply_filters( 'csco_theme_fonts', array() );
/** Initialize actions */
add_action( 'wp', array( $this, 'process_fonts' ) );
add_filter( 'admin_init', array( $this, 'set_variants_output' ) );
add_filter( 'template_redirect', array( $this, 'set_variants_output' ) );
add_filter( 'csco_customizer_dynamic_css', array( $this, 'dynamic_css_fonts_stack' ) );
add_filter( 'csco_customizer_fonts_choices', array( $this, 'customizer_fonts_choices' ), 999 );
if ( ! is_admin() || is_customize_preview() ) {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_theme_fonts' ), 999 );
} else {
add_action( 'enqueue_block_assets', array( $this, 'enqueue_theme_fonts' ), 999 );
}
}
/**
* Get stack the variants that are used in the theme.
*/
public function set_variants_output() {
$fields = CSCO_Customizer::$fields;
$extra_variants = array();
if ( is_array( $fields ) && $fields ) {
foreach ( $fields as $field ) {
if ( ! isset( $field['type'] ) || false === strpos( $field['type'], 'typography' ) ) {
continue;
}
// Check active callback.
if ( ! CSCO_Customizer_Helper::active_callback( $field ) ) {
continue;
}
$field_value = CSCO_Customizer_Helper::get_value( $field['settings'] );
if ( ! isset( $field_value['font-family'] ) || ! $field_value['font-family'] ) {
continue;
}
// Set font-family.
$font_family = $field_value['font-family'];
// Set font-weight.
$font_weight = ( isset( $field_value['font-weight'] ) && $field_value['font-weight'] ) ? $field_value['font-weight'] : 400;
$font_weight = ( 'regular' === $font_weight ) ? 400 : absint( $font_weight );
// Set font-style.
$font_style = ( isset( $field_value['font-style'] ) && $field_value['font-style'] ) ? $field_value['font-style'] : 'normal';
// Add hash.
array_push( $extra_variants, $font_family . $font_weight . $font_style );
if ( ! isset( $field['choices']['variant'] ) || ! $field['choices']['variant'] ) {
continue;
}
// Add all possible variations from choices.
foreach ( $field['choices']['variant'] as $variant ) {
// Get font-weight from variant.
$font_weight = $this->get_font_weight( $variant );
// Get font-style from variant.
$font_style = $this->get_font_style( $variant );
// Add hash of choices.
array_push( $extra_variants, $font_family . $font_weight . $font_style );
}
}
}
$this->variants_output = $extra_variants;
}
/**
* Process fonts
*/
public function process_fonts() {
foreach ( $this->fonts_output as $key => $font ) {
if ( ! isset( $font['name'] ) || ! isset( $font['variants'] ) ) {
unset( $this->fonts_output[ $key ] );
}
}
}
/**
* Add new fonts for choices
*
* @param array $fonts List fonts.
*/
public function customizer_fonts_choices( $fonts ) {
if ( is_customize_preview() ) {
// Add new section.
if ( $this->fonts_output ) {
$fonts['fonts']['families']['theme'] = array(
'text' => esc_html__( 'Theme Fonts', 'revision' ),
'children' => array(),
);
}
// Add new font.
foreach ( $this->fonts_output as $slug => $font ) {
$fonts['fonts']['families']['theme']['children'][] = array(
'text' => $font['name'],
'id' => $slug,
);
$fonts['fonts']['variants'][ $slug ] = $font['variants'];
}
}
return $fonts;
}
/**
* Extend font stack for dynamic styles
*
* @param string $style The dynamic css.
*/
public function dynamic_css_fonts_stack( $style ) {
foreach ( $this->fonts_output as $slug => $font ) {
$style = str_replace( sprintf( 'font-family:%s;', $slug ), sprintf( 'font-family:%s,-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";', $slug ), $style );
}
return $style;
}
/**
* Get font-weight from variant.
*
* @param string $variant The variant of font.
*/
public function get_font_weight( $variant = 'regular' ) {
$font_weight = filter_var( $variant, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
return ( 'regular' === $variant || 'italic' === $variant ) ? 400 : absint( $font_weight );
}
/**
* Get font-style from variant.
*
* @param string $variant The variant of font.
*/
public function get_font_style( $variant = 'regular' ) {
return ( false === strpos( $variant, 'italic' ) ) ? 'normal' : 'italic';
}
/**
* Gets all our styles and returns them as a string.
*
* @param string $method Webfonts Load Method.
*/
public function get_styles_theme_fonts( $method = null ) {
ob_start();
foreach ( $this->fonts_output as $slug => $font ) {
foreach ( $font['variants'] as $variant ) {
$font_family = $slug;
// Get font-weight from variant.
$font_weight = $this->get_font_weight( $variant );
// Get font-style from variant.
$font_style = $this->get_font_style( $variant );
// Get font path.
$font_path = get_theme_file_uri( sprintf( 'assets/static/fonts/%s-%s', $slug, $variant ) );
// Get hash from font.
$hash = $font_family . $font_weight . $font_style;
// Check whether the font is used in the theme.
if ( ! in_array( $hash, $this->variants_output, true ) ) {
continue;
}
?>
@font-face {
font-family: <?php echo esc_html( $slug ); ?>;
src: url('<?php echo esc_html( $font_path ); ?>.woff2') format('woff2'),
url('<?php echo esc_html( $font_path ); ?>.woff') format('woff');
font-weight: <?php echo esc_html( $font_weight ); ?>;
font-style: <?php echo esc_html( $font_style ); ?>;
font-display: swap;
}
<?php
}
}
$styles = ob_get_clean();
// Remove extra characters.
$styles = str_replace( array( "\t", "\r", "\n" ), '', $styles );
return $styles;
}
/**
* Enqueue theme fonts.
*/
public function enqueue_theme_fonts() {
wp_register_style( 'cs-theme-fonts', false, array(), csco_get_theme_data( 'Version' ) );
wp_enqueue_style( 'cs-theme-fonts' );
wp_add_inline_style( 'cs-theme-fonts', $this->get_styles_theme_fonts() );
}
}
new CSCO_Customizer_Fonts_Theme();
}

View File

@@ -0,0 +1,194 @@
<?php
/**
* Customizer Fonts
*
* @package Revision
*/
if ( ! class_exists( 'CSCO_Customizer_Fonts' ) ) {
/**
* Customizer Fonts Class.
*/
final class CSCO_Customizer_Fonts {
/**
* An array of our google fonts.
*
* @static
* @var null|object
*/
public static $google_fonts = null;
/**
* The class constructor.
*/
public function __construct() {
/** Initialize actions */
add_action( 'wp_ajax_csco_typography_fonts_google_all_get', array( $this, 'get_googlefonts_json' ) );
add_action( 'wp_ajax_nopriv_csco_typography_fonts_google_all_get', array( $this, 'get_googlefonts_json' ) );
add_action( 'wp_ajax_csco_typography_fonts_standard_all_get', array( $this, 'get_standardfonts_json' ) );
add_action( 'wp_ajax_nopriv_csco_typography_fonts_standard_all_get', array( $this, 'get_standardfonts_json' ) );
}
/**
* Gets the googlefonts JSON file.
*
* @return void
*/
public function get_googlefonts_json() {
require get_theme_file_path( '/core/customizer/assets/webfonts.json' ); // phpcs:ignore.
wp_die();
}
/**
* Get the standard fonts JSON.
*
* @return void
*/
public function get_standardfonts_json() {
echo wp_json_encode( self::get_standard_fonts() );
wp_die();
}
/**
* Returns an array of all available variants.
*
* @static
* @return array
*/
public static function get_all_variants() {
return array(
'100' => esc_html__( 'Ultra-Light 100', 'revision' ),
'100light' => esc_html__( 'Ultra-Light 100', 'revision' ),
'100italic' => esc_html__( 'Ultra-Light 100 Italic', 'revision' ),
'200' => esc_html__( 'Light 200', 'revision' ),
'200italic' => esc_html__( 'Light 200 Italic', 'revision' ),
'300' => esc_html__( 'Book 300', 'revision' ),
'300italic' => esc_html__( 'Book 300 Italic', 'revision' ),
'400' => esc_html__( 'Normal 400', 'revision' ),
'regular' => esc_html__( 'Normal 400', 'revision' ),
'italic' => esc_html__( 'Normal 400 Italic', 'revision' ),
'500' => esc_html__( 'Medium 500', 'revision' ),
'500italic' => esc_html__( 'Medium 500 Italic', 'revision' ),
'600' => esc_html__( 'Semi-Bold 600', 'revision' ),
'600bold' => esc_html__( 'Semi-Bold 600', 'revision' ),
'600italic' => esc_html__( 'Semi-Bold 600 Italic', 'revision' ),
'700' => esc_html__( 'Bold 700', 'revision' ),
'700italic' => esc_html__( 'Bold 700 Italic', 'revision' ),
'800' => esc_html__( 'Extra-Bold 800', 'revision' ),
'800bold' => esc_html__( 'Extra-Bold 800', 'revision' ),
'800italic' => esc_html__( 'Extra-Bold 800 Italic', 'revision' ),
'900' => esc_html__( 'Ultra-Bold 900', 'revision' ),
'900bold' => esc_html__( 'Ultra-Bold 900', 'revision' ),
'900italic' => esc_html__( 'Ultra-Bold 900 Italic', 'revision' ),
);
}
/**
* Return an array of standard websafe fonts.
*
* @return array Standard websafe fonts.
*/
public static function get_standard_fonts() {
$standard_fonts = array(
'serif' => array(
'label' => 'Serif',
'stack' => 'Georgia,Times,"Times New Roman",serif',
),
'sans-serif' => array(
'label' => 'Sans Serif',
'stack' => '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif',
),
'monospace' => array(
'label' => 'Monospace',
'stack' => 'Monaco,"Lucida Sans Typewriter","Lucida Typewriter","Courier New",Courier,monospace',
),
);
/**
* The csco_customizer_fonts_standard_fonts hook.
*
* @since 1.0.0
*/
return apply_filters( 'csco_customizer_fonts_standard_fonts', $standard_fonts );
}
/**
* Return an array of all available Google Fonts.
*
* @return array All Google Fonts.
*/
public static function get_google_fonts() {
// Get fonts from cache.
self::$google_fonts = get_site_transient( 'csco_customizer_googlefonts_cache' );
/**
* Reset the cache if we're using action=cs-googlefonts-reset-cache in the URL.
*
* Note to code reviewers:
* There's no need to check nonces or anything else, this is a simple true/false evaluation.
*/
if ( ! empty( $_GET['action'] ) && 'cs-googlefonts-reset-cache' === $_GET['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification
self::$google_fonts = false;
}
// If cache is populated, return cached fonts array.
if ( self::$google_fonts ) {
return self::$google_fonts;
}
// If we got this far, cache was empty so we need to get from JSON.
ob_start();
require get_theme_file_path( '/core/customizer/assets/webfonts.json' ); // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude
$fonts_json = ob_get_clean();
$fonts = json_decode( $fonts_json, true );
$google_fonts = array();
if ( is_array( $fonts ) ) {
foreach ( $fonts['items'] as $font ) {
$google_fonts[ $font['family'] ] = array(
'label' => $font['family'],
'variants' => $font['variants'],
'category' => $font['category'],
);
}
}
/**
* Apply the 'csco_customizer_fonts_google_fonts' filter
*
* The csco_customizer_fonts_google_fonts hook.
*
* @since 1.0.0
*/
self::$google_fonts = apply_filters( 'csco_customizer_fonts_google_fonts', $google_fonts );
/**
* Save the array in cache.
*
* The csco_customizer_googlefonts_transient_time hook.
*
* @since 1.0.0
*/
$cache_time = apply_filters( 'csco_customizer_googlefonts_transient_time', DAY_IN_SECONDS );
set_site_transient( 'csco_customizer_googlefonts_cache', self::$google_fonts, $cache_time );
return self::$google_fonts;
}
/**
* Determine if a font-name is a valid google font or not.
*
* @param string $fontname The name of the font we want to check.
* @return bool
*/
public static function is_google_font( $fontname ) {
return ( array_key_exists( $fontname, self::$google_fonts ) );
}
}
new CSCO_Customizer_Fonts();
}

View File

@@ -0,0 +1,240 @@
<?php
/**
* Theme Customizer Output Styles
*
* @package Revision
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'CSCO_Customizer_Output_Styles' ) ) {
/**
* Class Theme Customizer Output
*/
class CSCO_Customizer_Output_Styles {
/**
* The class constructor
*/
public function __construct() {
if ( ! is_admin() || is_customize_preview() ) {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_output_styles' ), 999 );
} else {
add_action( 'enqueue_block_assets', array( $this, 'enqueue_output_styles' ), 999 );
}
}
/**
* Gets all our styles and returns them as a string.
*/
public function get_output_styles() {
$output_styles = __return_empty_string();
// Get an array of all our fields.
$fields = CSCO_Customizer::$fields;
// Check if we need to exit early.
if ( empty( $fields ) || ! is_array( $fields ) ) {
return;
}
// Initially we're going to format our styles as an array.
// This is going to make processing them a lot easier
// and make sure there are no duplicate styles etc.
$css = array();
// Start parsing our fields.
foreach ( $fields as $field ) {
// No need to process fields without an output, or an improperly-formatted output.
if ( ! isset( $field['output'] ) || empty( $field['output'] ) || ! is_array( $field['output'] ) ) {
continue;
}
// Get the value of this field.
$value = CSCO_Customizer_Helper::get_value( $field['settings'] );
// Check active callback.
if ( ! CSCO_Customizer_Helper::active_callback( $field ) ) {
continue;
}
// Start parsing the output arguments of the field.
foreach ( $field['output'] as $output ) {
if ( is_admin() && ! is_customize_preview() ) {
// Check if this is an admin style.
if ( ! isset( $output['context'] ) || ! in_array( 'editor', $output['context'], true ) ) {
continue;
}
} elseif ( isset( $output['context'] ) && ! in_array( 'front', $output['context'], true ) ) {
// Check if this is a frontend style.
continue;
}
$output = wp_parse_args(
$output, array(
'element' => '',
'property' => '',
'media_query' => 'global',
'prefix' => '',
'units' => '',
'suffix' => '',
'value_pattern' => '$',
'choice' => '',
'convert' => '',
)
);
// If element is an array, convert it to a string.
if ( is_array( $output['element'] ) ) {
$output['element'] = implode( ',', $output['element'] );
}
// Simple fields.
if ( ! is_array( $value ) ) {
$value_pattern = str_replace( '$', ( $value ? $value : '' ), $output['value_pattern'] );
if ( 'rgb' === $output['convert'] ) {
$value_pattern = csco_hex2rgba( $value_pattern, false );
}
if ( ! empty( $output['element'] ) && ! empty( $output['property'] ) && $value_pattern ) {
$css[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $value_pattern . $output['units'] . $output['suffix'];
}
} else {
if ( 'typography' === $field['type'] ) {
$value = CSCO_Customizer_Helper::typography_sanitize( $value );
$properties = array(
'font-family',
'font-size',
'variant',
'font-weight',
'font-style',
'letter-spacing',
'word-spacing',
'line-height',
'text-align',
'text-transform',
'text-decoration',
'color',
);
foreach ( $properties as $property ) {
// Early exit if the value is not in the defaults.
if ( ! isset( $field['default'][ $property ] ) ) {
continue;
}
// Early exit if the value is not saved in the values.
if ( ! isset( $value[ $property ] ) || ! $value[ $property ] ) {
continue;
}
// Take care of variants.
if ( 'variant' === $property && isset( $value['variant'] ) && ! empty( $value['variant'] ) ) {
// Get the font_weight.
$font_weight = str_replace( 'italic', '', $value['variant'] );
$font_weight = in_array( $font_weight, array( '', 'regular' ), true ) ? '400' : $font_weight;
$css[ $output['media_query'] ][ $output['element'] ]['font-weight'] = $font_weight;
// Is this italic?
$is_italic = ( false !== strpos( $value['variant'], 'italic' ) );
if ( $is_italic ) {
$css[ $output['media_query'] ][ $output['element'] ]['font-style'] = 'italic';
}
continue;
}
$css[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $value[ $property ] . $output['suffix'];
}
} elseif ( 'multicolor' === $field['type'] ) {
if ( ! empty( $output['element'] ) && ! empty( $output['property'] ) && ! empty( $output['choice'] ) ) {
$css[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $value[ $output['choice'] ] . $output['units'] . $output['suffix'];
}
} else {
foreach ( $value as $key => $subvalue ) {
$property = $key;
if ( false !== strpos( $output['property'], '%%' ) ) {
$property = str_replace( '%%', $key, $output['property'] );
} elseif ( ! empty( $output['property'] ) ) {
$output['property'] = $output['property'] . '-' . $key;
}
if ( 'background-image' === $output['property'] && false === strpos( $subvalue, 'url(' ) ) {
$subvalue = sprintf( 'url("%s")', set_url_scheme( $subvalue ) );
}
if ( $subvalue ) {
$css[ $output['media_query'] ][ $output['element'] ][ $property ] = $subvalue;
}
}
}
}
}
}
// Process the array of CSS properties and produce the final CSS.
if ( ! is_array( $css ) || empty( $css ) ) {
return null;
}
foreach ( $css as $media_query => $styles ) {
$output_styles .= ( 'global' !== $media_query ) ? $media_query . '{' : '';
foreach ( $styles as $style => $style_array ) {
$css_for_style = '';
foreach ( $style_array as $property => $value ) {
if ( is_string( $value ) && '' !== $value ) {
$css_for_style .= sprintf( '%s:%s;', $property, $value );
} elseif ( is_array( $value ) ) {
foreach ( $value as $subvalue ) {
if ( is_string( $subvalue ) && '' !== $subvalue ) {
$css_for_style .= sprintf( '%s:%s;', $property, $subvalue );
}
}
}
$value = ( is_string( $value ) ) ? $value : '';
}
if ( '' !== $css_for_style ) {
$output_styles .= $style . sprintf( '{%s}', $css_for_style );
}
}
$output_styles .= ( 'global' !== $media_query ) ? '}' : '';
}
/**
* The csco_customizer_output_styles hook.
*
* @since 1.0.0
*/
$output_styles = apply_filters( 'csco_customizer_output_styles', $output_styles );
return $output_styles;
}
/**
* Enqueue output styles.
*/
public function enqueue_output_styles() {
wp_register_style( 'cs-customizer-output-styles', false, array(), csco_get_theme_data( 'Version' ) );
wp_enqueue_style( 'cs-customizer-output-styles' );
wp_add_inline_style( 'cs-customizer-output-styles', $this->get_output_styles() );
}
}
new CSCO_Customizer_Output_Styles();
}

View File

@@ -0,0 +1,365 @@
/* Theme Dashboard */
.cs-theme-dashboard .button {
transition: 0.25s;
box-shadow: none !important;
outline: none !important;
}
.cs-theme-dashboard .cs-button {
padding: 6px 22px;
}
.cs-theme-dashboard .cs-button:not(:hover) {
background: transparent;
}
.cs-theme-dashboard .cs-button-primary {
padding: 6px 22px;
}
.cs-theme-dashboard .cs-separator {
background: #F0F0F0;
height: 1px;
margin-bottom: 2rem;
}
.cs-theme-dashboard .cs-title {
font-weight: 600;
font-size: 0.8125rem;
color: #1E1E1E;
}
.cs-theme-dashboard .cs-heading {
font-weight: 600;
font-size: 1rem;
color: #1E1E1E;
}
.cs-theme-dashboard .cs-description {
font-size: 0.8125rem;
color: #697B96;
}
.cs-theme-dashboard .cs-description:not(:first-child) {
margin-top: 1rem;
}
.cs-theme-dashboard .cs-badge {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0px 6px;
border-radius: 9px;
text-transform: uppercase;
}
.cs-theme-dashboard .cs-badge-success {
background: #DEF3ED;
color: #3FB28F;
}
.cs-theme-dashboard .cs-badge-info {
background: #007CBA;
color: #FFFFFF;
}
.cs-theme-dashboard .cs-badge-warning {
background: #F8E4E4;
color: #F58787;
}
.cs-theme-dashboard .cs-header {
display: flex;
align-items: center;
justify-content: space-between;
background: #FFFFFF;
margin: 0 -20px 0 0;
margin-bottom: 20px;
padding: 0 24px;
}
.cs-theme-dashboard .cs-header .cs-header-left {
display: flex;
align-items: center;
height: 100%;
}
.cs-theme-dashboard .cs-header .cs-header-right {
display: flex;
align-items: center;
height: 100%;
}
.cs-theme-dashboard .cs-header .cs-header-col {
display: flex;
align-items: center;
border-left: 1px solid #f0f0f0;
padding: 0 24px;
height: 100%;
min-height: 60px;
}
.cs-theme-dashboard .cs-header .cs-header-col:first-child {
padding-right: 0;
}
.cs-theme-dashboard .cs-header .cs-header-col-logo {
border-left: none;
}
.cs-theme-dashboard .cs-header .cs-logo a {
display: inline-block;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
font-size: 1.25rem;
color: #000000;
text-decoration: none;
}
.cs-theme-dashboard .cs-header .cs-logo a:focus {
box-shadow: none;
}
.cs-theme-dashboard .cs-header .cs-link-documentation {
display: flex;
align-items: center;
text-decoration: none;
}
.cs-theme-dashboard .cs-header .cs-link-documentation:hover span {
text-decoration: underline;
}
.cs-theme-dashboard .cs-header .cs-link-documentation i {
display: flex;
align-items: center;
font-size: 1rem;
margin-right: 0.5rem;
}
.cs-theme-dashboard .cs-hero {
background: #FFFFFF;
display: flex;
border-radius: 2px;
margin-top: 20px;
}
.cs-theme-dashboard .cs-hero .cs-hero-hello {
margin-top: 1rem;
font-weight: 600;
font-size: 1rem;
color: #1E1E1E;
}
.cs-theme-dashboard .cs-hero .cs-hero-title {
margin-top: 1rem;
font-weight: 600;
font-size: 2rem;
line-height: 1.2;
color: #1E1E1E;
}
.cs-theme-dashboard .cs-hero .cs-badge {
transform: translateY(-10px);
font-weight: normal;
font-size: 0.8125rem;
}
.cs-theme-dashboard .cs-hero .cs-hero-desc {
margin-top: 1rem;
color: #1E1E1E;
}
.cs-theme-dashboard .cs-hero .cs-hero-go {
margin-top: 1.5rem;
padding: 6px 22px;
}
@keyframes spin {
100% {
transform: rotate(360deg);
}
}
.cs-theme-dashboard .cs-hero .cs-hero-notion {
font-size: 0.75rem;
margin-top: 0.5rem;
color: #697B96;
}
.cs-theme-dashboard .cs-hero .cs-hero-warning {
margin-top: 0.5rem;
color: #dc3232;
}
.cs-theme-dashboard .cs-hero .cs-hero-content {
padding: 24px;
}
.cs-theme-dashboard .cs-hero .cs-hero-image {
display: none;
}
.cs-theme-dashboard .cs-hero .cs-hero-image span {
position: relative;
display: inline-block;
}
.cs-theme-dashboard .cs-hero .cs-hero-image img {
display: block;
zoom: 0.5;
}
@media (min-width: 1360px) {
.cs-theme-dashboard .cs-hero .cs-hero-image {
display: flex;
flex-direction: column;
justify-content: flex-end;
}
}
.cs-theme-dashboard .cs-main {
display: flex;
flex-wrap: wrap;
margin-top: 20px;
}
.cs-theme-dashboard .cs-main-content {
display: flex;
flex-direction: column;
flex: 1 0 100%;
max-width: 100%;
width: 100%;
}
.cs-theme-dashboard .cs-main-content .cs-hero {
margin-top: 0;
margin-bottom: 20px;
max-width: 100%;
width: 100%;
}
.cs-theme-dashboard .cs-main-content .form-table {
margin-top: 0;
}
.cs-theme-dashboard .cs-main-content .form-table th {
padding: 12px 0 12px 10px;
}
.cs-theme-dashboard .cs-main-content .form-table td {
padding: 12px 10px;
}
@media (min-width: 960px) {
.cs-theme-dashboard .cs-main-content {
flex: 1 0 calc(100% - 296px);
max-width: calc(100% - 296px);
width: 100%;
margin-left: 20px;
}
}
.cs-theme-dashboard .cs-main-sidebar {
flex: 1 0 100%;
max-width: 100%;
width: 100%;
margin-top: 20px;
}
@media (min-width: 960px) {
.cs-theme-dashboard .cs-main-sidebar {
flex: 1 0 276px;
max-width: 276px;
width: 100%;
margin-top: 0;
}
}
.cs-theme-dashboard .cs-panel {
display: flex;
flex-direction: column;
background: #FFFFFF;
border-radius: 0px 0px 2px 2px;
border-radius: 2px;
}
.cs-theme-dashboard .cs-panel + .cs-panel {
margin-top: 20px;
}
.cs-theme-dashboard .cs-panel .cs-panel-head {
padding: 16px 24px;
border-bottom: 1px solid #f0f0f0;
}
.cs-theme-dashboard .cs-panel .cs-panel-title {
font-size: 0.8125rem;
margin: 0;
}
.cs-theme-dashboard .cs-panel .cs-panel-content {
height: 100%;
padding: 24px;
}
.cs-theme-dashboard .cs-panel-tabs {
display: flex;
flex-direction: column;
flex-wrap: wrap;
}
@media (min-width: 960px) {
.cs-theme-dashboard .cs-panel-tabs {
flex-direction: row;
}
}
@media (min-width: 960px) {
.cs-theme-dashboard .cs-panel-tabs .cs-panel-tab {
margin: -16px 0;
margin-left: 40px;
border-bottom: 4px solid transparent;
}
}
.cs-theme-dashboard .cs-panel-tabs .cs-panel-tab a {
display: block;
padding: 14px 16px;
color: inherit;
text-decoration: none;
box-shadow: none;
}
@media (min-width: 960px) {
.cs-theme-dashboard .cs-panel-tabs .cs-panel-tab a {
display: inline-block;
padding: 16px 0;
}
}
.cs-theme-dashboard .cs-panel-tabs .cs-panel-tab-active {
background: #f8f9fd;
border-radius: 2px;
}
@media (min-width: 960px) {
.cs-theme-dashboard .cs-panel-tabs .cs-panel-tab-active {
background: transparent;
border-color: #007CBA;
border-radius: 0;
}
}
.cs-theme-dashboard .cs-panel-content-tabs .cs-panel-tab {
display: none;
}
.cs-theme-dashboard .cs-panel-content-tabs .cs-panel-tab.cs-panel-tab-active {
display: block;
}
.cs-theme-dashboard .cs-panel-general {
flex: 1;
max-width: 100%;
width: 100%;
}
.cs-theme-dashboard .cs-panel-support .cs-button-wrap {
margin-top: auto;
padding-top: 1rem;
}
.cs-theme-dashboard .cs-panel-community .cs-button-wrap {
margin-top: auto;
padding-top: 1rem;
}
.cs-theme-dashboard .cs-panel-changelog .cs-panel-head {
display: flex;
align-items: center;
justify-content: space-between;
}
.cs-theme-dashboard .cs-panel-changelog .cs-changelog-link {
display: inline-block;
margin-top: 1rem;
text-decoration: none;
}
.cs-theme-dashboard .cs-panel-changelog .cs-changelog-link:hover {
text-decoration: underline;
}
.notice.cs-theme-dashboard-notice {
margin: 20px 0;
border: none;
box-shadow: none;
padding: 0 !important;
background: transparent;
}
.notice.cs-theme-dashboard-notice + .notice.updated {
display: none;
}
.cs-activation .cs-activation-postbox {
margin-right: -24px;
margin-left: -2px;
padding-right: 24px;
padding-left: 24px;
}
.cs-activation .cs-activation-postbox + .cs-activation-postbox {
border-top: 1px solid #f0f0f0;
margin-top: 2rem;
padding-top: 1rem;
}
.cs-activation .cs-theme-license-msg {
font-size: 14px;
margin-bottom: 0;
}
.cs-activation .cs-theme-license-form {
max-width: 864px;
}
.cs-activation .cs-theme-license-updates {
display: flex;
}
.cs-activation .cs-theme-license-newsletter {
margin: 10px 0 0 15px;
}
.cs-activation .cs-theme-license-supported_until {
color: red;
}
/*# sourceMappingURL=theme-dashboard.css.map */

View File

@@ -0,0 +1,365 @@
/* Theme Dashboard */
.cs-theme-dashboard .button {
transition: 0.25s;
box-shadow: none !important;
outline: none !important;
}
.cs-theme-dashboard .cs-button {
padding: 6px 22px;
}
.cs-theme-dashboard .cs-button:not(:hover) {
background: transparent;
}
.cs-theme-dashboard .cs-button-primary {
padding: 6px 22px;
}
.cs-theme-dashboard .cs-separator {
background: #F0F0F0;
height: 1px;
margin-bottom: 2rem;
}
.cs-theme-dashboard .cs-title {
font-weight: 600;
font-size: 0.8125rem;
color: #1E1E1E;
}
.cs-theme-dashboard .cs-heading {
font-weight: 600;
font-size: 1rem;
color: #1E1E1E;
}
.cs-theme-dashboard .cs-description {
font-size: 0.8125rem;
color: #697B96;
}
.cs-theme-dashboard .cs-description:not(:first-child) {
margin-top: 1rem;
}
.cs-theme-dashboard .cs-badge {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0px 6px;
border-radius: 9px;
text-transform: uppercase;
}
.cs-theme-dashboard .cs-badge-success {
background: #DEF3ED;
color: #3FB28F;
}
.cs-theme-dashboard .cs-badge-info {
background: #007CBA;
color: #FFFFFF;
}
.cs-theme-dashboard .cs-badge-warning {
background: #F8E4E4;
color: #F58787;
}
.cs-theme-dashboard .cs-header {
display: flex;
align-items: center;
justify-content: space-between;
background: #FFFFFF;
margin: 0 0 0 -20px;
margin-bottom: 20px;
padding: 0 24px;
}
.cs-theme-dashboard .cs-header .cs-header-left {
display: flex;
align-items: center;
height: 100%;
}
.cs-theme-dashboard .cs-header .cs-header-right {
display: flex;
align-items: center;
height: 100%;
}
.cs-theme-dashboard .cs-header .cs-header-col {
display: flex;
align-items: center;
border-right: 1px solid #f0f0f0;
padding: 0 24px;
height: 100%;
min-height: 60px;
}
.cs-theme-dashboard .cs-header .cs-header-col:first-child {
padding-left: 0;
}
.cs-theme-dashboard .cs-header .cs-header-col-logo {
border-right: none;
}
.cs-theme-dashboard .cs-header .cs-logo a {
display: inline-block;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
font-size: 1.25rem;
color: #000000;
text-decoration: none;
}
.cs-theme-dashboard .cs-header .cs-logo a:focus {
box-shadow: none;
}
.cs-theme-dashboard .cs-header .cs-link-documentation {
display: flex;
align-items: center;
text-decoration: none;
}
.cs-theme-dashboard .cs-header .cs-link-documentation:hover span {
text-decoration: underline;
}
.cs-theme-dashboard .cs-header .cs-link-documentation i {
display: flex;
align-items: center;
font-size: 1rem;
margin-left: 0.5rem;
}
.cs-theme-dashboard .cs-hero {
background: #FFFFFF;
display: flex;
border-radius: 2px;
margin-top: 20px;
}
.cs-theme-dashboard .cs-hero .cs-hero-hello {
margin-top: 1rem;
font-weight: 600;
font-size: 1rem;
color: #1E1E1E;
}
.cs-theme-dashboard .cs-hero .cs-hero-title {
margin-top: 1rem;
font-weight: 600;
font-size: 2rem;
line-height: 1.2;
color: #1E1E1E;
}
.cs-theme-dashboard .cs-hero .cs-badge {
transform: translateY(-10px);
font-weight: normal;
font-size: 0.8125rem;
}
.cs-theme-dashboard .cs-hero .cs-hero-desc {
margin-top: 1rem;
color: #1E1E1E;
}
.cs-theme-dashboard .cs-hero .cs-hero-go {
margin-top: 1.5rem;
padding: 6px 22px;
}
@keyframes spin {
100% {
transform: rotate(360deg);
}
}
.cs-theme-dashboard .cs-hero .cs-hero-notion {
font-size: 0.75rem;
margin-top: 0.5rem;
color: #697B96;
}
.cs-theme-dashboard .cs-hero .cs-hero-warning {
margin-top: 0.5rem;
color: #dc3232;
}
.cs-theme-dashboard .cs-hero .cs-hero-content {
padding: 24px;
}
.cs-theme-dashboard .cs-hero .cs-hero-image {
display: none;
}
.cs-theme-dashboard .cs-hero .cs-hero-image span {
position: relative;
display: inline-block;
}
.cs-theme-dashboard .cs-hero .cs-hero-image img {
display: block;
zoom: 0.5;
}
@media (min-width: 1360px) {
.cs-theme-dashboard .cs-hero .cs-hero-image {
display: flex;
flex-direction: column;
justify-content: flex-end;
}
}
.cs-theme-dashboard .cs-main {
display: flex;
flex-wrap: wrap;
margin-top: 20px;
}
.cs-theme-dashboard .cs-main-content {
display: flex;
flex-direction: column;
flex: 1 0 100%;
max-width: 100%;
width: 100%;
}
.cs-theme-dashboard .cs-main-content .cs-hero {
margin-top: 0;
margin-bottom: 20px;
max-width: 100%;
width: 100%;
}
.cs-theme-dashboard .cs-main-content .form-table {
margin-top: 0;
}
.cs-theme-dashboard .cs-main-content .form-table th {
padding: 12px 10px 12px 0;
}
.cs-theme-dashboard .cs-main-content .form-table td {
padding: 12px 10px;
}
@media (min-width: 960px) {
.cs-theme-dashboard .cs-main-content {
flex: 1 0 calc(100% - 296px);
max-width: calc(100% - 296px);
width: 100%;
margin-right: 20px;
}
}
.cs-theme-dashboard .cs-main-sidebar {
flex: 1 0 100%;
max-width: 100%;
width: 100%;
margin-top: 20px;
}
@media (min-width: 960px) {
.cs-theme-dashboard .cs-main-sidebar {
flex: 1 0 276px;
max-width: 276px;
width: 100%;
margin-top: 0;
}
}
.cs-theme-dashboard .cs-panel {
display: flex;
flex-direction: column;
background: #FFFFFF;
border-radius: 0px 0px 2px 2px;
border-radius: 2px;
}
.cs-theme-dashboard .cs-panel + .cs-panel {
margin-top: 20px;
}
.cs-theme-dashboard .cs-panel .cs-panel-head {
padding: 16px 24px;
border-bottom: 1px solid #f0f0f0;
}
.cs-theme-dashboard .cs-panel .cs-panel-title {
font-size: 0.8125rem;
margin: 0;
}
.cs-theme-dashboard .cs-panel .cs-panel-content {
height: 100%;
padding: 24px;
}
.cs-theme-dashboard .cs-panel-tabs {
display: flex;
flex-direction: column;
flex-wrap: wrap;
}
@media (min-width: 960px) {
.cs-theme-dashboard .cs-panel-tabs {
flex-direction: row;
}
}
@media (min-width: 960px) {
.cs-theme-dashboard .cs-panel-tabs .cs-panel-tab {
margin: -16px 0;
margin-right: 40px;
border-bottom: 4px solid transparent;
}
}
.cs-theme-dashboard .cs-panel-tabs .cs-panel-tab a {
display: block;
padding: 14px 16px;
color: inherit;
text-decoration: none;
box-shadow: none;
}
@media (min-width: 960px) {
.cs-theme-dashboard .cs-panel-tabs .cs-panel-tab a {
display: inline-block;
padding: 16px 0;
}
}
.cs-theme-dashboard .cs-panel-tabs .cs-panel-tab-active {
background: #f8f9fd;
border-radius: 2px;
}
@media (min-width: 960px) {
.cs-theme-dashboard .cs-panel-tabs .cs-panel-tab-active {
background: transparent;
border-color: #007CBA;
border-radius: 0;
}
}
.cs-theme-dashboard .cs-panel-content-tabs .cs-panel-tab {
display: none;
}
.cs-theme-dashboard .cs-panel-content-tabs .cs-panel-tab.cs-panel-tab-active {
display: block;
}
.cs-theme-dashboard .cs-panel-general {
flex: 1;
max-width: 100%;
width: 100%;
}
.cs-theme-dashboard .cs-panel-support .cs-button-wrap {
margin-top: auto;
padding-top: 1rem;
}
.cs-theme-dashboard .cs-panel-community .cs-button-wrap {
margin-top: auto;
padding-top: 1rem;
}
.cs-theme-dashboard .cs-panel-changelog .cs-panel-head {
display: flex;
align-items: center;
justify-content: space-between;
}
.cs-theme-dashboard .cs-panel-changelog .cs-changelog-link {
display: inline-block;
margin-top: 1rem;
text-decoration: none;
}
.cs-theme-dashboard .cs-panel-changelog .cs-changelog-link:hover {
text-decoration: underline;
}
.notice.cs-theme-dashboard-notice {
margin: 20px 0;
border: none;
box-shadow: none;
padding: 0 !important;
background: transparent;
}
.notice.cs-theme-dashboard-notice + .notice.updated {
display: none;
}
.cs-activation .cs-activation-postbox {
margin-left: -24px;
margin-right: -2px;
padding-left: 24px;
padding-right: 24px;
}
.cs-activation .cs-activation-postbox + .cs-activation-postbox {
border-top: 1px solid #f0f0f0;
margin-top: 2rem;
padding-top: 1rem;
}
.cs-activation .cs-theme-license-msg {
font-size: 14px;
margin-bottom: 0;
}
.cs-activation .cs-theme-license-form {
max-width: 864px;
}
.cs-activation .cs-theme-license-updates {
display: flex;
}
.cs-activation .cs-theme-license-newsletter {
margin: 10px 15px 0 0;
}
.cs-activation .cs-theme-license-supported_until {
color: red;
}
/*# sourceMappingURL=theme-dashboard.css.map */

View File

@@ -0,0 +1,53 @@
( function( $ ) {
"use strict";
/** ----------------------------------------------------------------------------
* Theme Dashboard */
var cscoThemeDashboard = {};
( function() {
var $this;
cscoThemeDashboard = {
/** Initialize */
init: function( e ) {
$this = cscoThemeDashboard;
// Init events.
$this.events( e );
},
/** Events */
events: function( e ) {
$( document ).on( 'click', '.cs-panel-tabs .cs-panel-tab a', function( e ) {
$this.activePanel( e, this );
});
},
/** Active Panel */
activePanel: function( e, object ) {
let $index = $( object ).closest( '.cs-panel-tab' ).index();
// Set location.
window.history.replaceState( '', '', $( object ).attr( 'href' ) );
// Nav Tabs.
$( object ).closest( '.cs-panel-tab' ).addClass( 'cs-panel-tab-active' ).siblings().removeClass( 'cs-panel-tab-active' );
// Content Tabs.
$( '.cs-panel-content-tabs .cs-panel-tab' ).eq( $index ).addClass( 'cs-panel-tab-active' ).siblings().removeClass( 'cs-panel-tab-active' );
e.preventDefault();
},
};
} )();
// Initialize.
cscoThemeDashboard.init();
} )( jQuery );

View File

@@ -0,0 +1,391 @@
<?php
/**
* Theme Dashboard
*
* @package Revision
*/
if ( ! class_exists( 'CSCO_Theme_Dashboard' ) ) {
/**
* Theme Dashboard Class.
*/
class CSCO_Theme_Dashboard {
/**
* The slug name to refer to this menu by.
*
* @var string $menu_slug The menu slug.
*/
public $menu_slug = 'theme-dashboard';
/**
* The settings of page.
*
* @var array $settings The settings.
*/
public $settings = array();
/**
* Constructor.
*/
public function __construct() {
$self = $this;
/** Include files */
if ( ! function_exists( 'get_plugin_data' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
/** Initialize actions */
add_action( 'init', array( $this, 'set_settings' ) );
add_action( 'init', function () use ( $self ) {
add_action( 'admin_menu', array( $self, 'add_menu_page' ) );
} );
add_action( 'admin_notices', array( $this, 'notice' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ), 5 );
add_action( 'admin_enqueue_scripts', array( $this, 'notice_enqueue_scripts' ), 5 );
add_action( 'wp_ajax_csco_dashboard_dismissed_handler', array( $this, 'dismissed_handler' ) );
add_action( 'switch_theme', array( $this, 'reset_notices' ) );
add_action( 'after_switch_theme', array( $this, 'reset_notices' ) );
}
/**
* Add menu page
*/
public function add_menu_page() {
add_submenu_page( 'themes.php', esc_html__( 'Theme Dashboard', 'revision' ), esc_html__( 'Theme Dashboard', 'revision' ), 'manage_options', $this->menu_slug, array( $this, 'render_page' ), 1 );
}
/**
* Settings
*
* @param array $settings The settings.
*/
public function set_settings( $settings ) {
$theme = wp_get_theme( get_template() );
// Hero.
/* translators: Theme Name */
$this->settings['hero_title'] = sprintf( esc_html__( 'Welcome to %1$s', 'revision' ), $theme->get('Name') );
/* translators: Theme Name */
$this->settings['hero_desc'] = sprintf( esc_html__( '%1$s is now installed and activated. To help you with the next step, we\'ve gathered together on this page all the resources you might need. We hope you enjoy using this theme.', 'revision' ), $theme->get('Name') );
$this->settings['hero_image'] = __return_false();
// Documentation.
$this->settings['documentation_link'] = sprintf( 'https://codesupply.co/documentation/%s/', $theme->get('TextDomain') );
// Changelog.
$this->settings['changelog_link'] = sprintf( 'https://codesupply.co/documentation/%s/changelog/', $theme->get('TextDomain') );
// Support.
$this->settings['support_link'] = 'https://codesupply.co/support/';
// Community.
$this->settings['community_link'] = 'https://www.facebook.com/codesupplyco/';
}
/**
* Render Hero
*
* @param string $location The location.
*/
public function render_hero( $location = null ) {
global $pagenow;
$theme = wp_get_theme( get_template() );
$screen = get_current_screen();
?>
<div class="cs-hero">
<div class="cs-hero-content">
<div class="cs-hero-hello">
<?php esc_html_e( 'Hello, ', 'revision' ); ?>
<?php
$current_user = wp_get_current_user();
echo esc_html( $current_user->display_name );
?>
<?php esc_html_e( '👋🏻', 'revision' ); ?>
</div>
<div class="cs-hero-title">
<?php echo wp_kses( $this->settings['hero_title'], 'content' ); ?>
</div>
<?php if ( isset( $this->settings['hero_desc'] ) && $this->settings['hero_desc'] ) { ?>
<div class="cs-hero-desc">
<?php echo wp_kses( $this->settings['hero_desc'], 'content' ); ?>
</div>
<?php } ?>
<a href="<?php echo esc_url( admin_url( '/themes.php?page=theme-demos' ) ); ?>" class="cs-hero-go button button-primary">
<?php esc_html_e( 'Go to Theme Demos', 'revision' ); ?>
</a>
</div>
<?php if ( isset( $this->settings['hero_image'] ) && $this->settings['hero_image'] ) { ?>
<div class="cs-hero-image">
<span>
<img src="<?php echo esc_url( $this->settings['hero_image'] ); ?>">
</span>
</div>
<?php } ?>
</div>
<?php
}
/**
* Render page
*/
public function render_page() {
?>
<div class="cs-wrap cs-theme-dashboard">
<div class="cs-header">
<div class="cs-header-left">
<div class="cs-header-col cs-header-col-logo">
<div class="cs-logo">
<a target="_blank" href="<?php echo esc_url( 'https://codesupply.co/' ); ?>">
Code Supply Co.
</a>
</div>
</div>
</div>
<div class="cs-header-right">
<a href="<?php echo esc_url( $this->settings['documentation_link'] ); ?>" class="cs-link-documentation" target="_blank">
<span><?php esc_html_e( 'Documentation', 'revision' ); ?></span>
<i class="dashicons dashicons-external"></i>
</a>
</div>
</div>
<div class="wrap">
<h1 class="hidden"><?php esc_html_e( 'Theme Dashboard', 'revision' ); ?></h1>
<div class="cs-main">
<div class="cs-main-content">
<?php $this->render_hero(); ?>
<?php
$dashboard_tabs = apply_filters( 'csco_theme_dashboard_tabs', array() );
if ( $dashboard_tabs ) {
// Sort priority.
usort( $dashboard_tabs, function ( $item1, $item2 ) {
if ( $item1['priority'] === $item2['priority'] ) {
return 0;
}
return $item1['priority'] < $item2['priority'] ? -1 : 1;
});
// Set active tab.
$active_tab = isset( $_GET['tab'] ) ? esc_attr( $_GET['tab'] ) : $dashboard_tabs[0]['slug']; // phpcs:ignore.
?>
<div class="cs-panel cs-panel-general">
<div class="cs-panel-head cs-panel-tabs">
<?php
foreach ( $dashboard_tabs as $tab_data ) {
$tab_url = add_query_arg( array(
'page' => $this->menu_slug,
'tab' => $tab_data['slug'],
), admin_url( 'themes.php' ) );
$tab_status = __return_empty_string();
if ( $active_tab === $tab_data['slug'] ) {
$tab_status = 'cs-panel-tab-active';
}
?>
<div class="cs-panel-tab <?php echo esc_attr( $tab_status ); ?>">
<h3 class="cs-panel-title">
<a href="<?php echo esc_url( $tab_url ); ?>">
<?php echo esc_html( $tab_data['label'] ); ?>
</a>
</h3>
</div>
<?php
}
?>
</div>
<div class="cs-panel-content cs-panel-content-tabs">
<?php
foreach ( $dashboard_tabs as $tab_data ) {
$tab_status = __return_empty_string();
if ( $active_tab === $tab_data['slug'] ) {
$tab_status = 'cs-panel-tab-active';
}
?>
<div id="<?php echo esc_url( $tab_data['slug'] ); ?>" class="cs-panel-tab <?php echo esc_attr( $tab_status ); ?>">
<?php call_user_func( 'printf', '%s', $tab_data['content'] ); ?>
</div>
<?php
}
?>
</div>
</div>
<?php } ?>
</div>
<div class="cs-main-sidebar">
<div class="cs-panel cs-panel-changelog">
<div class="cs-panel-head">
<h3 class="cs-panel-title"><?php esc_html_e( 'Changelog', 'revision' ); ?></h3>
</div>
<div class="cs-panel-content">
<div class="cs-description"><?php esc_html_e( 'Keep informed with the latest changes about each theme.', 'revision' ); ?></div>
<a href="<?php echo esc_url( $this->settings['changelog_link'] ); ?>" class="cs-changelog-link" target="_blank">
<?php echo esc_html_e( 'See the Changelog', 'revision' ); ?>
</a>
</div>
</div>
<div class="cs-panel cs-panel-support">
<div class="cs-panel-head">
<h3 class="cs-panel-title"><?php esc_html_e( 'Support', 'revision' ); ?></h3>
</div>
<div class="cs-panel-content">
<div class="cs-content-primary">
<div class="cs-title">
<?php echo esc_html__( 'Need help? We\'re here for you!', 'revision' ); ?>
</div>
<div class="cs-description"><?php esc_html_e( 'Have a question? Hit a bug? Get the help you need, when you need it from our friendly support staff.', 'revision' ); ?></div>
<div class="cs-button-wrap">
<a href="<?php echo esc_url( $this->settings['support_link'] ); ?>" class="cs-button button" target="_blank">
<?php echo esc_html_e( 'Get Support', 'revision' ); ?>
</a>
</div>
</div>
</div>
</div>
<div class="cs-panel cs-panel-community">
<div class="cs-panel-head">
<h3 class="cs-panel-title"><?php esc_html_e( 'Community', 'revision' ); ?></h3>
</div>
<div class="cs-panel-content">
<div class="cs-title">
<?php echo esc_html__( 'Join our Facebook community', 'revision' ); ?>
</div>
<div class="cs-description"><?php esc_html_e( 'Discuss products and ask for community support or help the community.', 'revision' ); ?></div>
<div class="cs-button-wrap">
<a href="<?php echo esc_url( $this->settings['community_link'] ); ?>" class="cs-button button" target="_blank">
<?php echo esc_html_e( 'Join Now', 'revision' ); ?>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
}
/**
* Notice
*/
public function notice() {
global $pagenow;
$screen = get_current_screen();
if ( 'themes.php' === $pagenow && 'themes' === $screen->base ) {
$transient_name = sprintf( '%s_hero_notice', get_template() );
if ( ! get_transient( $transient_name ) ) {
?>
<div class="cs-dashboard-notice notice notice-success cs-theme-dashboard cs-theme-dashboard-notice is-dismissible" data-notice="<?php echo esc_attr( $transient_name ); ?>">
<?php $this->render_hero( 'themes' ); ?>
</div>
<?php
}
}
}
/**
* Purified from the database information about notification.
*/
public function reset_notices() {
delete_transient( sprintf( '%s_hero_notice', get_template() ) );
}
/**
* Dismissed handler
*/
public function dismissed_handler() {
wp_verify_nonce( null );
if ( isset( $_POST['notice'] ) ) { // Input var ok; sanitization ok.
set_transient( sanitize_text_field( wp_unslash( $_POST['notice'] ) ), true, 90 * DAY_IN_SECONDS ); // Input var ok.
}
}
/**
* Notice Enqunue Scripts
*
* @param string $page Current page.
*/
public function notice_enqueue_scripts( $page ) {
wp_enqueue_script( 'jquery' );
ob_start();
?>
<script>
jQuery(function($) {
$( document ).on( 'click', '.cs-dashboard-notice .notice-dismiss', function () {
jQuery.post( 'ajax_url', {
action: 'csco_dashboard_dismissed_handler',
notice: $( this ).closest( '.cs-dashboard-notice' ).data( 'notice' ),
});
} );
});
</script>
<?php
$script = str_replace( 'ajax_url', admin_url( 'admin-ajax.php' ), ob_get_clean() );
wp_add_inline_script( 'jquery', str_replace( array( '<script>', '</script>' ), '', $script ) );
}
/**
* This function will register scripts and styles for admin dashboard.
*
* @param string $page Current page.
*/
public function admin_enqueue_scripts( $page ) {
wp_enqueue_script( 'csco-theme-dashboard', get_theme_file_uri( '/core/theme-dashboard/assets/theme-dashboard.js' ), array( 'jquery' ), filemtime( get_theme_file_path( '/core/theme-dashboard/assets/theme-dashboard.js' ) ), true );
wp_localize_script( 'csco-theme-dashboard', 'cscoThemeDashboardConfig', array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'nonce' ),
'failed_message' => esc_html__( 'Something went wrong, contact support.', 'revision' ),
) );
// Styles.
wp_enqueue_style( 'csco-theme-dashboard', get_theme_file_uri( '/core/theme-dashboard/assets/theme-dashboard.css' ), array(), filemtime( get_theme_file_path( '/core/theme-dashboard/assets/theme-dashboard.css' ) ) );
// Add RTL support.
wp_style_add_data( 'revision', 'rtl', 'replace' );
}
}
new CSCO_Theme_Dashboard();
}

View File

@@ -0,0 +1,601 @@
/* Demos Page */
.cs-demos-page .button {
transition: 0.25s;
box-shadow: none !important;
outline: none !important;
}
.cs-demos-page .cs-button {
padding: 6px 22px;
}
.cs-demos-page .cs-button:not(:hover) {
background: transparent;
}
.cs-demos-page .cs-badge {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0px 6px;
border-radius: 9px;
text-transform: uppercase;
}
.cs-demos-page .cs-badge-success {
background: #DEF3ED;
color: #3FB28F;
}
.cs-demos-page .cs-badge-info {
background: #007CBA;
color: #FFFFFF;
}
.cs-demos-page .cs-badge-warning {
background: #F8E4E4;
color: #F58787;
}
.cs-demos-page .cs-switcher {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 1rem;
}
.cs-demos-page .cs-switcher .cs-switch {
border: 1px solid #000000;
box-sizing: border-box;
color: #fff;
cursor: pointer;
display: flex;
height: 1.75rem;
height: 18px;
padding: 0;
position: relative;
vertical-align: middle;
width: 36px;
margin-right: 0.5rem;
border-radius: 9px;
}
.cs-demos-page .cs-switcher .cs-switch .cs-switch-slider {
position: absolute;
top: 3px;
right: 4px;
width: 10px;
height: 10px;
z-index: 1;
background: #000000;
border-radius: 50%;
transition: right 0.25s ease;
}
.cs-demos-page .cs-switcher .cs-tooltip {
position: absolute;
top: calc(100% + 5px);
left: 0;
min-width: 150px;
max-width: 200px;
text-align: center;
padding: 4px 8px;
font-size: 12px;
background: #1E1E1E;
color: #FFF;
border-radius: 2px;
opacity: 0;
visibility: hidden;
z-index: 4;
}
.cs-demos-page .cs-switcher .cs-tooltip-desc {
position: absolute;
top: calc(100% + 5px);
right: 0;
min-width: 150px;
max-width: 200px;
text-align: center;
padding: 4px 8px;
font-size: 12px;
background: #1E1E1E;
color: #FFF;
border-radius: 2px;
opacity: 0;
visibility: hidden;
z-index: 4;
}
.cs-demos-page .cs-switcher .cs-checkbox {
position: absolute;
margin: 0 !important;
padding: 0 !important;
border: none;
top: 0;
right: 0;
width: 100%;
height: 100%;
opacity: 0;
z-index: 2;
appearance: none;
}
.cs-demos-page .cs-switcher .cs-checkbox[readony], .cs-demos-page .cs-switcher .cs-checkbox:disabled {
opacity: 0;
}
.cs-demos-page .cs-switcher .cs-checkbox[readony] ~ .cs-switch, .cs-demos-page .cs-switcher .cs-checkbox:disabled ~ .cs-switch {
opacity: 0.5;
}
.cs-demos-page .cs-switcher .cs-checkbox[readony]:hover ~ .cs-tooltip {
opacity: 1;
visibility: visible;
}
.cs-demos-page .cs-switcher .cs-checkbox:checked ~ .cs-switch {
border-color: #007dba;
background: #007dba;
}
.cs-demos-page .cs-switcher .cs-checkbox:checked ~ .cs-switch .cs-switch-slider {
background: #FFFFFF;
top: 3px;
right: calc(50% + 4px);
}
.cs-demos-page .cs-switcher .cs-tooltip-help {
position: relative;
z-index: 3;
margin-left: auto;
cursor: pointer;
}
.cs-demos-page .cs-switcher .cs-tooltip-help:hover {
color: #2271b1;
}
.cs-demos-page .cs-switcher .cs-tooltip-help:hover ~ .cs-tooltip-desc {
opacity: 1;
visibility: visible;
}
.cs-demos-page .cs-header {
display: flex;
align-items: center;
justify-content: space-between;
background: #FFFFFF;
margin: 0 -20px 0 0;
margin-bottom: 20px;
padding: 0 24px;
}
.cs-demos-page .cs-header .cs-header-left {
display: flex;
align-items: center;
height: 100%;
}
.cs-demos-page .cs-header .cs-header-right {
display: flex;
align-items: center;
height: 100%;
}
.cs-demos-page .cs-header .cs-header-col {
display: flex;
align-items: center;
border-left: 1px solid #f0f0f0;
padding: 0 24px;
height: 100%;
min-height: 60px;
}
.cs-demos-page .cs-header .cs-header-col:first-child {
padding-right: 0;
}
.cs-demos-page .cs-header .cs-header-col-logo {
border-left: none;
}
.cs-demos-page .cs-header .cs-header-col-logo:only-child {
border-left: none;
}
@media (min-width: 960px) {
.cs-demos-page .cs-header .cs-header-col-logo {
border-left: 1px solid #f0f0f0;
}
}
.cs-demos-page .cs-header .cs-logo a {
display: inline-block;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
font-size: 20px;
color: #000000;
text-decoration: none;
}
.cs-demos-page .cs-header .cs-logo a:focus {
box-shadow: none;
}
.cs-demos-page .cs-demos {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
grid-gap: 20px;
margin-top: 20px;
}
.cs-demos-page .cs-demos .cs-demo-item {
display: none;
background: #FFFFFF;
border-radius: 2px;
overflow: hidden;
}
.cs-demos-page .cs-demos .cs-demo-item:not([data-preview=false]) {
cursor: pointer;
}
.cs-demos-page .cs-demos .cs-demo-item.cs-demo-item-active {
display: block;
}
.cs-demos-page .cs-demos .cs-demo-thumbnail {
background: #ededed;
position: relative;
}
.cs-demos-page .cs-demos .cs-demo-thumbnail:before {
display: table;
width: 0;
height: 100%;
padding-bottom: 56%;
content: "";
}
.cs-demos-page .cs-demos .cs-demo-thumbnail img {
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
width: 100%;
height: 100%;
object-fit: cover;
object-position: top center;
}
.cs-demos-page .cs-demos .cs-demo-preview {
background: rgba(255, 255, 255, 0.75);
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
text-decoration: none;
opacity: 0;
transition: opacity 0.5s;
}
.cs-demos-page .cs-demos .cs-demo-preview span {
display: flex;
align-items: center;
justify-content: center;
padding: 15px 40px;
background-color: rgba(0, 0, 0, 0.7);
border-radius: 3px;
font-size: 13px;
color: #FFFFFF;
transition: background-color 0.5s;
}
.cs-demos-page .cs-demos .cs-demo-item:hover .cs-demo-preview {
opacity: 1;
}
.cs-demos-page .cs-demos .cs-demo-data {
border-top: 1px solid #ededed;
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 16px;
}
.cs-demos-page .cs-demos .cs-demo-info {
display: flex;
align-items: center;
}
.cs-demos-page .cs-demos .cs-demo-name {
font-weight: 600;
}
.cs-demos-page .cs-demos .cs-demo-badge {
margin-right: 0.5rem;
}
.cs-demos-page .cs-demos .cs-demo-actions {
opacity: 0;
transition: opacity 0.5s;
}
.cs-demos-page .cs-demos .cs-demo-actions .button {
padding: 2px 16px;
}
.cs-demos-page .cs-demos .cs-demo-item:hover .cs-demo-actions {
opacity: 1;
}
.cs-demos-page .cs-import-theme {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: rgba(0, 0, 0, 0.75);
visibility: hidden;
position: fixed;
top: 0;
right: 0;
left: 0;
bottom: 0;
z-index: 99999999;
opacity: 0;
padding: 20px;
transition: 0.5s opacity 0s, 0s visibility 0.5s;
}
.cs-import-theme-active .cs-demos-page .cs-import-theme {
visibility: visible;
opacity: 1;
transition: 0.5s opacity 0s, 0s visibility 0s;
}
.cs-import-theme-active .cs-demos-page .cs-import-theme .cs-import-overlay {
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
width: 100%;
height: 100%;
}
.cs-demos-page .cs-import-theme .cs-import-popup {
position: relative;
background: #FFFFFF;
width: 100%;
max-width: 320px;
box-shadow: 0px 16px 32px -8px rgba(0, 0, 0, 0.05);
border-radius: 2px;
overflow: hidden;
overflow-y: auto;
}
.cs-demos-page .cs-import-theme .cs-import-header {
border-bottom: 1px solid #f0f0f0;
padding: 12px 24px;
font-weight: 600;
color: #1E1E1E;
}
.cs-demos-page .cs-import-theme .cs-import-subheader {
font-size: 11px;
text-transform: uppercase;
color: #697B96;
}
.cs-demos-page .cs-import-theme .cs-import-kits {
margin-top: 1rem;
}
.cs-demos-page .cs-import-theme .cs-import-kits form:first-child .cs-switcher {
margin-top: 0;
}
.cs-demos-page .cs-import-theme .cs-kits-header {
font-size: 11px;
text-transform: uppercase;
color: #697B96;
}
.cs-demos-page .cs-import-theme .cs-msg-warning {
font-size: 11px;
margin-top: 0.5rem;
color: #dc3232;
}
.cs-demos-page .cs-import-theme .cs-import-step {
display: none;
}
.cs-demos-page .cs-import-theme .cs-import-step-active {
display: flex;
flex-direction: column;
}
.cs-demos-page .cs-import-theme .cs-import-start .cs-import-plugins {
padding: 24px;
}
.cs-demos-page .cs-import-theme .cs-import-start .cs-import-content {
border-top: 1px solid #f0f0f0;
padding: 24px;
}
.cs-demos-page .cs-import-theme .cs-import-start .cs-import-content:first-child {
border-top: none;
}
.cs-demos-page .cs-import-theme .cs-import-start .cs-import-load {
display: flex;
align-items: center;
justify-content: center;
padding: 40px;
}
@keyframes spin {
100% {
transform: rotate(360deg);
}
}
.cs-demos-page .cs-import-theme .cs-import-start .cs-import-load:after {
animation: spin 4s linear infinite;
font-family: "dashicons";
font-size: 2rem;
content: "\f113";
}
.cs-demos-page .cs-import-theme .cs-import-start .cs-msg-warning {
margin: 0;
padding: 24px;
}
.cs-demos-page .cs-import-theme .cs-import-start .cs-import-actions {
display: flex;
justify-content: flex-end;
border-top: 1px solid #f0f0f0;
padding: 24px;
}
.cs-demos-page .cs-import-theme .cs-import-start .cs-import-actions .button {
padding: 6px 22px;
margin-left: 0.4rem;
}
.cs-demos-page .cs-import-theme .cs-import-process .cs-import-output {
padding: 24px;
}
.cs-demos-page .cs-import-theme .cs-import-process .cs-import-desc {
color: #1E1E1E;
}
.cs-demos-page .cs-import-theme .cs-import-process .cs-import-progress {
margin-top: 2rem;
}
.cs-demos-page .cs-import-theme .cs-import-process .cs-import-progress-label {
font-size: 12px;
color: #697B96;
margin-bottom: 0.25rem;
}
.cs-demos-page .cs-import-theme .cs-import-process .cs-import-progress-label:empty {
display: none;
}
.cs-demos-page .cs-import-theme .cs-import-process .cs-import-progress-bar {
position: relative;
width: 100%;
height: 4px;
background: #F0F0F0;
border-radius: 2px;
overflow: hidden;
}
.cs-demos-page .cs-import-theme .cs-import-process .cs-import-progress-indicator {
--cs-indicator: 0%;
background: #007CBA;
position: absolute;
top: 0;
right: 0;
height: 100%;
width: var(--cs-indicator);
}
.cs-demos-page .cs-import-theme .cs-import-process .cs-import-progress-sublabel {
margin-top: 0.5rem;
font-size: 10px;
color: #007CBA;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-info {
padding: 76px 24px 24px;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-logo {
display: flex;
align-items: center;
justify-content: center;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-logo svg {
display: block;
margin: 0 auto;
fill: #DEF3ED;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-title {
margin-top: 2rem;
font-size: 1rem;
font-weight: 600;
text-align: center;
color: #1E1E1E;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-desc {
margin-top: 1rem;
text-align: center;
color: #1E1E1E;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-customize {
margin-top: 1.5rem;
display: flex;
align-items: center;
justify-content: center;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-customize .button {
padding: 6px 22px;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-actions {
display: flex;
align-items: center;
justify-content: center;
border-top: 1px solid #f0f0f0;
padding: 24px;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-actions .cs-link {
margin-left: 1rem;
text-decoration: none;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-actions .cs-link:hover {
text-decoration: underline;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-actions .button {
padding: 6px 22px;
}
.cs-demos-page .cs-import-theme-active {
overflow: hidden;
}
.cs-demos-page .cs-preview {
display: flex;
flex-direction: column;
background: #f1f1f1;
visibility: hidden;
position: fixed;
top: 0;
right: 0;
left: 0;
bottom: 0;
z-index: 99999998;
opacity: 0;
transition: 0.5s opacity 0s, 0s visibility 0.5s;
}
.cs-preview-active .cs-demos-page .cs-preview {
visibility: visible;
opacity: 1;
transition: 0.5s opacity 0s, 0s visibility 0s;
}
.cs-demos-page .cs-preview .cs-preview-iframe {
width: 100%;
height: 100%;
}
.cs-demos-page .cs-preview .cs-header {
margin: 0;
box-shadow: inset 0px -1px 0px #F0F0F0;
padding-right: 0px;
}
@media (min-width: 960px) {
.cs-demos-page .cs-preview .cs-header {
padding-right: 24px;
}
}
.cs-demos-page .cs-preview .cs-header .button {
padding: 5px 22px;
}
.cs-demos-page .cs-preview .cs-header .cs-arrow {
display: flex;
align-items: center;
justify-content: center;
text-decoration: none;
color: #000000;
transition: 0.25s;
padding: 0 24px;
height: 100%;
outline: none;
}
.cs-demos-page .cs-preview .cs-header .cs-arrow:hover {
background: #f8f9fa;
}
.cs-demos-page .cs-preview .cs-header .cs-arrow:focus {
box-shadow: none;
}
.cs-demos-page .cs-preview .cs-header .cs-arrow:before {
font-family: "dashicons";
font-size: 18px;
}
.cs-demos-page .cs-preview .cs-header .cs-arrow.cs-inactive {
color: #CCCCCC;
cursor: default;
}
.cs-demos-page .cs-preview .cs-header .cs-arrow.cs-prev-demo:before {
content: "\f341";
}
.cs-demos-page .cs-preview .cs-header .cs-arrow.cs-next-demo:before {
content: "\f345";
}
.cs-demos-page .cs-preview .cs-header .cs-header-logo {
display: none;
}
@media (min-width: 960px) {
.cs-demos-page .cs-preview .cs-header .cs-header-logo {
display: flex;
}
}
.cs-demos-page .cs-preview .cs-header .cs-header-info {
display: none;
border-left: none;
}
@media (min-width: 960px) {
.cs-demos-page .cs-preview .cs-header .cs-header-info {
display: flex;
}
}
.cs-demos-page .cs-preview .cs-header .cs-header-arrow {
padding: 0;
}
.cs-demos-page .cs-preview .cs-header .cs-demo-name {
font-size: 1rem;
font-weight: 600;
color: #000000;
}
.cs-demos-page .cs-preview .cs-header .cs-preview-cancel {
margin-left: 0.5rem;
}
.cs-demos-page .cs-preview .cs-header .cs-preview-cancel .button:not(:hover) {
background: transparent;
}
.cs-demos-page .cs-preview-active {
overflow: hidden;
}
/*# sourceMappingURL=theme-demos.css.map */

View File

@@ -0,0 +1,601 @@
/* Demos Page */
.cs-demos-page .button {
transition: 0.25s;
box-shadow: none !important;
outline: none !important;
}
.cs-demos-page .cs-button {
padding: 6px 22px;
}
.cs-demos-page .cs-button:not(:hover) {
background: transparent;
}
.cs-demos-page .cs-badge {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0px 6px;
border-radius: 9px;
text-transform: uppercase;
}
.cs-demos-page .cs-badge-success {
background: #DEF3ED;
color: #3FB28F;
}
.cs-demos-page .cs-badge-info {
background: #007CBA;
color: #FFFFFF;
}
.cs-demos-page .cs-badge-warning {
background: #F8E4E4;
color: #F58787;
}
.cs-demos-page .cs-switcher {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 1rem;
}
.cs-demos-page .cs-switcher .cs-switch {
border: 1px solid #000000;
box-sizing: border-box;
color: #fff;
cursor: pointer;
display: flex;
height: 1.75rem;
height: 18px;
padding: 0;
position: relative;
vertical-align: middle;
width: 36px;
margin-left: 0.5rem;
border-radius: 9px;
}
.cs-demos-page .cs-switcher .cs-switch .cs-switch-slider {
position: absolute;
top: 3px;
left: 4px;
width: 10px;
height: 10px;
z-index: 1;
background: #000000;
border-radius: 50%;
transition: left 0.25s ease;
}
.cs-demos-page .cs-switcher .cs-tooltip {
position: absolute;
top: calc(100% + 5px);
right: 0;
min-width: 150px;
max-width: 200px;
text-align: center;
padding: 4px 8px;
font-size: 12px;
background: #1E1E1E;
color: #FFF;
border-radius: 2px;
opacity: 0;
visibility: hidden;
z-index: 4;
}
.cs-demos-page .cs-switcher .cs-tooltip-desc {
position: absolute;
top: calc(100% + 5px);
left: 0;
min-width: 150px;
max-width: 200px;
text-align: center;
padding: 4px 8px;
font-size: 12px;
background: #1E1E1E;
color: #FFF;
border-radius: 2px;
opacity: 0;
visibility: hidden;
z-index: 4;
}
.cs-demos-page .cs-switcher .cs-checkbox {
position: absolute;
margin: 0 !important;
padding: 0 !important;
border: none;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
z-index: 2;
appearance: none;
}
.cs-demos-page .cs-switcher .cs-checkbox[readony], .cs-demos-page .cs-switcher .cs-checkbox:disabled {
opacity: 0;
}
.cs-demos-page .cs-switcher .cs-checkbox[readony] ~ .cs-switch, .cs-demos-page .cs-switcher .cs-checkbox:disabled ~ .cs-switch {
opacity: 0.5;
}
.cs-demos-page .cs-switcher .cs-checkbox[readony]:hover ~ .cs-tooltip {
opacity: 1;
visibility: visible;
}
.cs-demos-page .cs-switcher .cs-checkbox:checked ~ .cs-switch {
border-color: #007dba;
background: #007dba;
}
.cs-demos-page .cs-switcher .cs-checkbox:checked ~ .cs-switch .cs-switch-slider {
background: #FFFFFF;
top: 3px;
left: calc(50% + 4px);
}
.cs-demos-page .cs-switcher .cs-tooltip-help {
position: relative;
z-index: 3;
margin-right: auto;
cursor: pointer;
}
.cs-demos-page .cs-switcher .cs-tooltip-help:hover {
color: #2271b1;
}
.cs-demos-page .cs-switcher .cs-tooltip-help:hover ~ .cs-tooltip-desc {
opacity: 1;
visibility: visible;
}
.cs-demos-page .cs-header {
display: flex;
align-items: center;
justify-content: space-between;
background: #FFFFFF;
margin: 0 0 0 -20px;
margin-bottom: 20px;
padding: 0 24px;
}
.cs-demos-page .cs-header .cs-header-left {
display: flex;
align-items: center;
height: 100%;
}
.cs-demos-page .cs-header .cs-header-right {
display: flex;
align-items: center;
height: 100%;
}
.cs-demos-page .cs-header .cs-header-col {
display: flex;
align-items: center;
border-right: 1px solid #f0f0f0;
padding: 0 24px;
height: 100%;
min-height: 60px;
}
.cs-demos-page .cs-header .cs-header-col:first-child {
padding-left: 0;
}
.cs-demos-page .cs-header .cs-header-col-logo {
border-right: none;
}
.cs-demos-page .cs-header .cs-header-col-logo:only-child {
border-right: none;
}
@media (min-width: 960px) {
.cs-demos-page .cs-header .cs-header-col-logo {
border-right: 1px solid #f0f0f0;
}
}
.cs-demos-page .cs-header .cs-logo a {
display: inline-block;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
font-size: 20px;
color: #000000;
text-decoration: none;
}
.cs-demos-page .cs-header .cs-logo a:focus {
box-shadow: none;
}
.cs-demos-page .cs-demos {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
grid-gap: 20px;
margin-top: 20px;
}
.cs-demos-page .cs-demos .cs-demo-item {
display: none;
background: #FFFFFF;
border-radius: 2px;
overflow: hidden;
}
.cs-demos-page .cs-demos .cs-demo-item:not([data-preview=false]) {
cursor: pointer;
}
.cs-demos-page .cs-demos .cs-demo-item.cs-demo-item-active {
display: block;
}
.cs-demos-page .cs-demos .cs-demo-thumbnail {
background: #ededed;
position: relative;
}
.cs-demos-page .cs-demos .cs-demo-thumbnail:before {
display: table;
width: 0;
height: 100%;
padding-bottom: 56%;
content: "";
}
.cs-demos-page .cs-demos .cs-demo-thumbnail img {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
object-fit: cover;
object-position: top center;
}
.cs-demos-page .cs-demos .cs-demo-preview {
background: rgba(255, 255, 255, 0.75);
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
text-decoration: none;
opacity: 0;
transition: opacity 0.5s;
}
.cs-demos-page .cs-demos .cs-demo-preview span {
display: flex;
align-items: center;
justify-content: center;
padding: 15px 40px;
background-color: rgba(0, 0, 0, 0.7);
border-radius: 3px;
font-size: 13px;
color: #FFFFFF;
transition: background-color 0.5s;
}
.cs-demos-page .cs-demos .cs-demo-item:hover .cs-demo-preview {
opacity: 1;
}
.cs-demos-page .cs-demos .cs-demo-data {
border-top: 1px solid #ededed;
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 16px;
}
.cs-demos-page .cs-demos .cs-demo-info {
display: flex;
align-items: center;
}
.cs-demos-page .cs-demos .cs-demo-name {
font-weight: 600;
}
.cs-demos-page .cs-demos .cs-demo-badge {
margin-left: 0.5rem;
}
.cs-demos-page .cs-demos .cs-demo-actions {
opacity: 0;
transition: opacity 0.5s;
}
.cs-demos-page .cs-demos .cs-demo-actions .button {
padding: 2px 16px;
}
.cs-demos-page .cs-demos .cs-demo-item:hover .cs-demo-actions {
opacity: 1;
}
.cs-demos-page .cs-import-theme {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: rgba(0, 0, 0, 0.75);
visibility: hidden;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 99999999;
opacity: 0;
padding: 20px;
transition: 0.5s opacity 0s, 0s visibility 0.5s;
}
.cs-import-theme-active .cs-demos-page .cs-import-theme {
visibility: visible;
opacity: 1;
transition: 0.5s opacity 0s, 0s visibility 0s;
}
.cs-import-theme-active .cs-demos-page .cs-import-theme .cs-import-overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
}
.cs-demos-page .cs-import-theme .cs-import-popup {
position: relative;
background: #FFFFFF;
width: 100%;
max-width: 320px;
box-shadow: 0px 16px 32px -8px rgba(0, 0, 0, 0.05);
border-radius: 2px;
overflow: hidden;
overflow-y: auto;
}
.cs-demos-page .cs-import-theme .cs-import-header {
border-bottom: 1px solid #f0f0f0;
padding: 12px 24px;
font-weight: 600;
color: #1E1E1E;
}
.cs-demos-page .cs-import-theme .cs-import-subheader {
font-size: 11px;
text-transform: uppercase;
color: #697B96;
}
.cs-demos-page .cs-import-theme .cs-import-kits {
margin-top: 1rem;
}
.cs-demos-page .cs-import-theme .cs-import-kits form:first-child .cs-switcher {
margin-top: 0;
}
.cs-demos-page .cs-import-theme .cs-kits-header {
font-size: 11px;
text-transform: uppercase;
color: #697B96;
}
.cs-demos-page .cs-import-theme .cs-msg-warning {
font-size: 11px;
margin-top: 0.5rem;
color: #dc3232;
}
.cs-demos-page .cs-import-theme .cs-import-step {
display: none;
}
.cs-demos-page .cs-import-theme .cs-import-step-active {
display: flex;
flex-direction: column;
}
.cs-demos-page .cs-import-theme .cs-import-start .cs-import-plugins {
padding: 24px;
}
.cs-demos-page .cs-import-theme .cs-import-start .cs-import-content {
border-top: 1px solid #f0f0f0;
padding: 24px;
}
.cs-demos-page .cs-import-theme .cs-import-start .cs-import-content:first-child {
border-top: none;
}
.cs-demos-page .cs-import-theme .cs-import-start .cs-import-load {
display: flex;
align-items: center;
justify-content: center;
padding: 40px;
}
@keyframes spin {
100% {
transform: rotate(360deg);
}
}
.cs-demos-page .cs-import-theme .cs-import-start .cs-import-load:after {
animation: spin 4s linear infinite;
font-family: "dashicons";
font-size: 2rem;
content: "\f113";
}
.cs-demos-page .cs-import-theme .cs-import-start .cs-msg-warning {
margin: 0;
padding: 24px;
}
.cs-demos-page .cs-import-theme .cs-import-start .cs-import-actions {
display: flex;
justify-content: flex-end;
border-top: 1px solid #f0f0f0;
padding: 24px;
}
.cs-demos-page .cs-import-theme .cs-import-start .cs-import-actions .button {
padding: 6px 22px;
margin-right: 0.4rem;
}
.cs-demos-page .cs-import-theme .cs-import-process .cs-import-output {
padding: 24px;
}
.cs-demos-page .cs-import-theme .cs-import-process .cs-import-desc {
color: #1E1E1E;
}
.cs-demos-page .cs-import-theme .cs-import-process .cs-import-progress {
margin-top: 2rem;
}
.cs-demos-page .cs-import-theme .cs-import-process .cs-import-progress-label {
font-size: 12px;
color: #697B96;
margin-bottom: 0.25rem;
}
.cs-demos-page .cs-import-theme .cs-import-process .cs-import-progress-label:empty {
display: none;
}
.cs-demos-page .cs-import-theme .cs-import-process .cs-import-progress-bar {
position: relative;
width: 100%;
height: 4px;
background: #F0F0F0;
border-radius: 2px;
overflow: hidden;
}
.cs-demos-page .cs-import-theme .cs-import-process .cs-import-progress-indicator {
--cs-indicator: 0%;
background: #007CBA;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: var(--cs-indicator);
}
.cs-demos-page .cs-import-theme .cs-import-process .cs-import-progress-sublabel {
margin-top: 0.5rem;
font-size: 10px;
color: #007CBA;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-info {
padding: 76px 24px 24px;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-logo {
display: flex;
align-items: center;
justify-content: center;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-logo svg {
display: block;
margin: 0 auto;
fill: #DEF3ED;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-title {
margin-top: 2rem;
font-size: 1rem;
font-weight: 600;
text-align: center;
color: #1E1E1E;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-desc {
margin-top: 1rem;
text-align: center;
color: #1E1E1E;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-customize {
margin-top: 1.5rem;
display: flex;
align-items: center;
justify-content: center;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-customize .button {
padding: 6px 22px;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-actions {
display: flex;
align-items: center;
justify-content: center;
border-top: 1px solid #f0f0f0;
padding: 24px;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-actions .cs-link {
margin-right: 1rem;
text-decoration: none;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-actions .cs-link:hover {
text-decoration: underline;
}
.cs-demos-page .cs-import-theme .cs-import-finish .cs-import-actions .button {
padding: 6px 22px;
}
.cs-demos-page .cs-import-theme-active {
overflow: hidden;
}
.cs-demos-page .cs-preview {
display: flex;
flex-direction: column;
background: #f1f1f1;
visibility: hidden;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 99999998;
opacity: 0;
transition: 0.5s opacity 0s, 0s visibility 0.5s;
}
.cs-preview-active .cs-demos-page .cs-preview {
visibility: visible;
opacity: 1;
transition: 0.5s opacity 0s, 0s visibility 0s;
}
.cs-demos-page .cs-preview .cs-preview-iframe {
width: 100%;
height: 100%;
}
.cs-demos-page .cs-preview .cs-header {
margin: 0;
box-shadow: inset 0px -1px 0px #F0F0F0;
padding-left: 0px;
}
@media (min-width: 960px) {
.cs-demos-page .cs-preview .cs-header {
padding-left: 24px;
}
}
.cs-demos-page .cs-preview .cs-header .button {
padding: 5px 22px;
}
.cs-demos-page .cs-preview .cs-header .cs-arrow {
display: flex;
align-items: center;
justify-content: center;
text-decoration: none;
color: #000000;
transition: 0.25s;
padding: 0 24px;
height: 100%;
outline: none;
}
.cs-demos-page .cs-preview .cs-header .cs-arrow:hover {
background: #f8f9fa;
}
.cs-demos-page .cs-preview .cs-header .cs-arrow:focus {
box-shadow: none;
}
.cs-demos-page .cs-preview .cs-header .cs-arrow:before {
font-family: "dashicons";
font-size: 18px;
}
.cs-demos-page .cs-preview .cs-header .cs-arrow.cs-inactive {
color: #CCCCCC;
cursor: default;
}
.cs-demos-page .cs-preview .cs-header .cs-arrow.cs-prev-demo:before {
content: "\f341";
}
.cs-demos-page .cs-preview .cs-header .cs-arrow.cs-next-demo:before {
content: "\f345";
}
.cs-demos-page .cs-preview .cs-header .cs-header-logo {
display: none;
}
@media (min-width: 960px) {
.cs-demos-page .cs-preview .cs-header .cs-header-logo {
display: flex;
}
}
.cs-demos-page .cs-preview .cs-header .cs-header-info {
display: none;
border-right: none;
}
@media (min-width: 960px) {
.cs-demos-page .cs-preview .cs-header .cs-header-info {
display: flex;
}
}
.cs-demos-page .cs-preview .cs-header .cs-header-arrow {
padding: 0;
}
.cs-demos-page .cs-preview .cs-header .cs-demo-name {
font-size: 1rem;
font-weight: 600;
color: #000000;
}
.cs-demos-page .cs-preview .cs-header .cs-preview-cancel {
margin-right: 0.5rem;
}
.cs-demos-page .cs-preview .cs-header .cs-preview-cancel .button:not(:hover) {
background: transparent;
}
.cs-demos-page .cs-preview-active {
overflow: hidden;
}
/*# sourceMappingURL=theme-demos.css.map */

View File

@@ -0,0 +1,337 @@
( function( $ ) {
"use strict";
/** ----------------------------------------------------------------------------
* Theme Demos */
var cscoThemeDemos = {};
( function() {
var $this;
cscoThemeDemos = {
/** Initialize */
init: function( e ) {
$this = cscoThemeDemos;
// Init events.
$this.events( e );
},
/** Events */
events: function( e ) {
$( document ).on( 'click', '.cs-demo-import-open', function( e ) {
$this.openImportDemo( e, this );
});
$( document ).on( 'click', '.cs-demo-import-close, .cs-import-overlay', function( e ) {
$this.closeImportDemo( e, this );
});
$( document ).on( 'click', '.cs-demo-import-start', function( e ) {
$this.startImportDemo( e, this );
});
$( document ).on( 'click', '.cs-demo-item', function( e ) {
$this.openPreviewDemo( e, this );
});
$( document ).on( 'click', '.cs-prev-demo', function( e ) {
$this.openPreviewPrevDemo( e, this );
});
$( document ).on( 'click', '.cs-next-demo', function( e ) {
$this.openPreviewNextDemo( e, this );
});
$( document ).on( 'click', '.cs-preview-cancel a', function( e ) {
$this.closePreviewDemo( e, this );
});
},
/** Open import demo */
openImportDemo: function( e, object ) {
// Get demo id.
var $demo_id = $( object ).data( 'id' );
// Body import.
$( 'body' ).addClass( 'cs-import-theme-active' );
// Variables.
var data = {
'action': 'csco_html_import_data',
'nonce': cscoThemeDemosConfig.nonce,
'demo_id': $demo_id,
};
// Reset current step.
$( '.cs-import-step' ).removeClass( 'cs-import-step-active' );
$( '.cs-import-step' ).first().addClass( 'cs-import-step-active' );
// Remove warning.
$( '.cs-import-theme .cs-msg-warning' ).remove();
// Reset variables.
$( '.cs-import-start .cs-import-output' ).html( '' );
$( '.cs-import-start .cs-import-output' ).addClass( 'cs-import-load' );
$( '.cs-import-process .cs-import-progress-label' ).html( '' );
$( '.cs-import-process .cs-import-progress-indicator' ).attr( 'style', '--cs-indicator: 0%;' );
$( '.cs-import-process .cs-import-progress-sublabel' ).html( '0%' );
// Send Request.
$.post( cscoThemeDemosConfig.ajax_url, data, function( response ) {
$( '.cs-import-start .cs-import-output' ).removeClass( 'cs-import-load' );
if ( response.success ) {
$( '.cs-import-start .cs-import-output' ).html( response.data );
} else if ( response.data ) {
$( '.cs-import-start .cs-import-output' ).html( `<div class="cs-msg-warning">${response.data}</div>` );
} else {
$( '.cs-import-start .cs-import-output' ).html( `<div class="cs-msg-warning">${cscoThemeDemosConfig.failed_message}</div>` );
}
} ).fail( function( xhr, textStatus, e ) {
$( '.cs-import-start .cs-import-output' ).removeClass( 'cs-import-load' );
$( '.cs-import-start .cs-import-output' ).html( `<div class="cs-msg-warning">${cscoThemeDemosConfig.failed_message}</div>` );
} );
e.preventDefault();
},
/** Close import demo */
closeImportDemo: function( e, object ) {
// Remove import from body.
$( 'body' ).removeClass( 'cs-import-theme-active' );
e.preventDefault();
},
/** Start import demo */
startImportDemo: function( e, object ) {
// Change process.
$( '.cs-import-step' ).removeClass( 'cs-import-step-active' );
$( '.cs-import-process' ).addClass( 'cs-import-step-active' );
// Run Import.
setTimeout( function() {
$this.importContent( e, object );
}, 10 );
e.preventDefault();
},
/** Open preview demo */
openPreviewDemo: function( e, object ) {
if ( ! $( e.target ).is( '.cs-demo-import-open, .cs-demo-import-url' ) ) {
$this.openPreview( e, object );
e.preventDefault();
}
},
/** Open preview prev demo */
openPreviewPrevDemo: function( e, object ) {
var prev = $( '.cs-demo-item-open' ).prev( '.cs-demo-item-active' );
if ( prev.length > 0 ) {
$this.openPreview( e, prev );
}
e.preventDefault();
},
/** Open preview next demo */
openPreviewNextDemo: function( e, object ) {
var next = $( '.cs-demo-item-open' ).next( '.cs-demo-item-active' );
if ( next.length > 0 ) {
$this.openPreview( e, next );
}
e.preventDefault();
},
/** Close preview */
closePreviewDemo: function( e, object ) {
// Remove current class from items.
$( '.cs-demo-item' ).removeClass( 'cs-demo-item-open' );
// Remove preview from body.
$( 'body' ).removeClass( 'cs-preview-active' );
// Remove url from iframe.
$( '.cs-preview .cs-preview-iframe' ).removeAttr( 'src' );
e.preventDefault();
},
/** Import indicator */
importIndicator: function( e, object, $data ) {
// Set indicator.
var indicator = Math.round( 100 / $data.steps * $data.index );
// Change indicator.
$( '.cs-import-process .cs-import-progress-indicator' ).attr( 'style', `--cs-indicator: ${indicator}%;` );
$( '.cs-import-process .cs-import-progress-sublabel' ).html( `${indicator}%` );
},
/** Import step */
importStep: function( e, object, $data ) {
if ( ! $( 'body' ).hasClass( 'cs-import-theme-active' ) ) {
return;
}
// Done.
if ( $data.index >= $data.steps ) {
// Change step.
setTimeout(function(){
$( '.cs-import-step' ).removeClass( 'cs-import-step-active' );
$( '.cs-import-finish' ).addClass( 'cs-import-step-active' );
$( document ).trigger( 'DOMImportFinish' );
}, 200 );
return;
}
var currentAction = $( $data.forms ).eq( $data.index ).find( 'input[name="action"]').val();
// Set progress label.
$( '.cs-import-progress-label' ).html( $( $data.forms ).eq( $data.index ).find( 'input[name="step_name"]').val() );
// Send Request.
$.post( {
url: cscoThemeDemosConfig.ajax_url,
type: 'POST',
data: $( $data.forms ).eq( $data.index ).serialize(),
timeout: 0,
} ).done( function( response ) {
if ( response.success || 'elementor_recreate_kit' === currentAction ) {
if ( 'undefined' !== typeof response.status && 'newAJAX' === response.status ) {
$this.importStep( e, object, $data );
} else {
$data.index = $data.index + 1;
$this.importIndicator( e, object, $data );
$this.importStep( e, object, $data );
}
} else if ( response.data ) {
$( '.cs-import-progress' ).after( `<div class="cs-msg-warning">${response.data}</div>` );
} else {
$( '.cs-import-progress' ).after( `<div class="cs-msg-warning">${cscoThemeDemosConfig.failed_message}</div>` );
}
} ).fail( function( xhr, textStatus, e ) {
// Pre import.
if ( 'elementor_recreate_kit' === currentAction ) {
$data.index = $data.index + 1;
$this.importIndicator( e, object, $data );
$this.importStep( e, object, $data );
} else {
$( '.cs-import-progress' ).after( `<div class="cs-msg-warning">${cscoThemeDemosConfig.failed_message}</div>` );
}
} );
},
/** Import content */
importContent: function( e, object ) {
var forms = $( '.cs-import-start form' ).filter(function( index, element ){
if ( $( element ).find( '.cs-checkbox' ).prop( 'checked' ) ) {
return true;
} else {
return false;
}
});
var steps = forms.length;
if ( steps <= 0 ) {
return
}
$this.importStep( e, object, {
'forms': forms,
'steps': steps,
'index': 0
} );
},
/** Open preview */
openPreview: function( e, object ) {
let demo_id = $( object ).data( 'id' );
let preview = $( object ).data( 'preview' );
let name = $( object ).data( 'name' );
let type = $( object ).data( 'type' );
if ( 'false' === preview ) {
return;
}
// Remove current class from siblings items.
$( object ).siblings().removeClass( 'cs-demo-item-open' );
// Current item.
$( object ).addClass( 'cs-demo-item-open' );
// Set demo id.
$( '.cs-preview .cs-demo-import-open' ).attr( 'data-id', demo_id );
// Prev Next Buttons.
$( '.cs-preview' ).find( '.cs-prev-demo, .cs-next-demo' ).removeClass( 'cs-inactive' );
let prev = $( object ).prev( '.cs-demo-item-active' );
if ( prev.length <= 0 ) {
$( '.cs-preview .cs-prev-demo' ).addClass( 'cs-inactive' );
}
let next = $( object ).next( '.cs-demo-item-active' );
if ( next.length <= 0 ) {
$( '.cs-preview .cs-next-demo' ).addClass( 'cs-inactive' );
}
// Reset header info.
$( '.cs-preview .cs-header-info' ).html( '' );
// Add name to info.
if ( name ) {
$( '.cs-preview .cs-header-info' ).prepend( `<div class="cs-demo-name">${name}</div>` );
}
$( '.cs-preview .cs-preview-actions' ).html( $( object ).find( '.cs-demo-actions' ).html() );
// Set url in iframe.
$( '.cs-preview .cs-preview-iframe' ).attr( 'src', preview );
// Body preview.
$( 'body' ).addClass( 'cs-preview-active' );
},
};
} )();
// Initialize.
cscoThemeDemos.init();
} )( jQuery );

View File

@@ -0,0 +1,527 @@
<?php
/**
* Theme Demos
*
* @package Revision
*/
if ( ! class_exists( 'CSCO_Theme_Demos' ) ) {
/**
* Theme Demos class.
*/
class CSCO_Theme_Demos {
/**
* The slug name to refer to this menu by.
*
* @var string $menu_slug The menu slug.
*/
public $menu_slug = 'theme-demos';
/**
* The dashboard menu slug.
*
* @var string $dashboard_menu_slug The dashboard menu slug.
*/
public $dashboard_menu_slug = 'theme-dashboard';
/**
* The demos of page.
*
* @var array $demos The demos.
*/
public $demos = array();
/**
* Constructor.
*/
public function __construct() {
$self = $this;
if ( ! function_exists( 'get_plugin_data' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
require_once get_theme_file_path( '/core/theme-demos/import/class-widget-importer.php' );
require_once get_theme_file_path( '/core/theme-demos/import/class-customizer-importer.php' );
// Include import.
require_once get_theme_file_path( '/core/theme-demos/import/class-manager-import.php' );
// Actions.
add_action( 'init', array( $this, 'set_demos' ) );
add_action( 'init', function () use ( $self ) {
add_action( 'admin_menu', array( $self, 'add_menu_page' ) );
} );
add_action( 'wp_ajax_csco_html_import_data', array( $this, 'html_import_data' ) );
add_action( 'wp_ajax_nopriv_csco_html_import_data', array( $this, 'html_import_data' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ), 5 );
}
/**
* Add menu page
*/
public function add_menu_page() {
add_submenu_page( 'themes.php', esc_html__( 'Theme Demos', 'revision' ), esc_html__( 'Theme Demos', 'revision' ), 'manage_options', $this->menu_slug, array( $this, 'html_carcase' ), 2 );
}
/**
* Get plugin status.
*
* @param string $plugin_path Plugin path.
*/
public function get_plugin_status( $plugin_path ) {
if ( ! current_user_can( 'install_plugins' ) ) {
return;
}
if ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin_path ) ) {
return 'not_installed';
} elseif ( in_array( $plugin_path, (array) get_option( 'active_plugins', array() ), true ) || is_plugin_active_for_network( $plugin_path ) ) {
return 'active';
} else {
return 'inactive';
}
}
/**
* Demos
*
* @param array $demos The demos.
*/
public function set_demos( $demos ) {
/**
* The csco_register_demos_list hook.
*
* @since 1.0.0
*/
$this->demos = apply_filters( 'csco_register_demos_list', $this->demos );
}
/**
* Html Import Data
*/
public function html_import_data() {
global $wpdb;
check_ajax_referer( 'nonce', 'nonce' );
$demo_id = isset( $_POST['demo_id'] ) ? sanitize_text_field( $_POST['demo_id'] ) : false;
if ( $demo_id ) {
if ( ! isset( $this->demos[ $demo_id ] ) ) {
wp_send_json_error( esc_html__( 'Invalid demo content id.', 'revision' ) );
wp_die();
}
// Reset import data.
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s", $wpdb->esc_like( 'csco_importer_data_' ) . '%' ) ); // db call ok; no-cache ok.
$demo_data = $this->demos[ $demo_id ];
ob_start();
$demo_plugins = isset( $demo_data['plugins'] ) ? $demo_data['plugins'] : array();
if ( $demo_plugins ) {
foreach ( $demo_plugins as $key => $plugin ) {
if ( ! isset( $plugin['name'] ) ) {
unset( $demo_plugins[ $key ] );
continue;
}
if ( ! isset( $plugin['slug'] ) ) {
unset( $demo_plugins[ $key ] );
continue;
}
if ( ! isset( $plugin['path'] ) ) {
unset( $demo_plugins[ $key ] );
continue;
}
if ( 'active' === $this->get_plugin_status( $plugin['path'] ) ) {
unset( $demo_plugins[ $key ] );
continue;
}
}
}
?>
<div class="cs-import-data">
<?php if ( $demo_plugins ) { ?>
<div class="cs-import-plugins">
<div class="cs-import-subheader">
<?php esc_html_e( 'Install Plugins', 'revision' ); ?>
</div>
<?php
foreach ( $demo_plugins as $plugin ) {
$required = isset( $plugin['required'] ) ? $plugin['required'] : false;
?>
<form>
<div class="cs-switcher">
<?php echo esc_html( $plugin['name'] ); ?> <input class="cs-checkbox" type="checkbox" name="<?php echo esc_attr( $plugin['slug'] ); ?>" value="1" <?php echo wp_kses( $required ? 'readony onclick="return false;"' : null, 'content' ); ?> checked>
<?php if ( isset( $plugin['desc'] ) && $plugin['desc'] ) { ?>
<div class="cs-tooltip-help"><i class="dashicons dashicons-editor-help"></i></div>
<div class="cs-tooltip-desc"><?php echo esc_html( $plugin['desc'] ); ?></div>
<?php } ?>
<div class="cs-switch"><span class="cs-switch-slider"></span></div>
<div class="cs-tooltip"><?php esc_html_e( 'Required plugin will be installed', 'revision' ); ?></div>
</div>
<input type="hidden" name="plugin_slug" value="<?php echo esc_attr( $plugin['slug'] ); ?>">
<input type="hidden" name="plugin_path" value="<?php echo esc_attr( $plugin['path'] ); ?>">
<input type="hidden" name="step_name" value="<?php esc_attr_e( 'Installing and activating', 'revision' ); ?> <?php echo esc_attr( $plugin['name'] ); ?>...">
<input type="hidden" name="nonce" value="<?php echo esc_attr( wp_create_nonce( 'nonce' ) ); ?>">
<input type="hidden" name="action" value="csco_import_plugin">
</form>
<?php } ?>
</div>
<?php } ?>
<div class="cs-import-content">
<form class="hidden">
<input type="hidden" name="step_name" value="<?php esc_attr_e( 'Pre import...', 'revision' ); ?>">
<input type="hidden" name="_nonce" value="<?php echo esc_attr( wp_create_nonce( 'elementor_recreate_kit' ) ); ?>">
<input type="hidden" name="action" value="elementor_recreate_kit">
<input class="cs-checkbox" type="checkbox" name="pre_import" value="1" checked>
</form>
<div class="cs-import-subheader">
<?php esc_html_e( 'Import Content', 'revision' ); ?>
</div>
<?php
if ( isset( $demo_data['import']['content'] ) && is_array( $demo_data['import']['content'] ) && $demo_data['import']['content'] ) {
$kits = $demo_data['import']['content'];
?>
<div class="cs-import-kits">
<?php foreach ( $kits as $kit ) { ?>
<form>
<div class="cs-switcher">
<?php echo esc_html( $kit['label'] ); ?> <input class="cs-checkbox" type="checkbox" name="url" value="<?php echo esc_attr( $kit['url'] ); ?>" checked>
<?php if ( isset( $kit['desc'] ) && $kit['desc'] ) { ?>
<div class="cs-tooltip-help"><i class="dashicons dashicons-editor-help"></i></div>
<div class="cs-tooltip-desc"><?php echo esc_html( $kit['desc'] ); ?></div>
<?php } ?>
<div class="cs-switch"><span class="cs-switch-slider"></span></div>
<input type="hidden" name="type" value="<?php echo esc_attr( isset( $kit['type'] ) ? $kit['type'] : 'default' ); ?>">
<input type="hidden" name="step_name" value="<?php esc_attr_e( 'Importing', 'revision' ); ?> <?php echo esc_attr( $kit['label'] ); ?> ...">
<input type="hidden" name="nonce" value="<?php echo esc_attr( wp_create_nonce( 'nonce' ) ); ?>">
<input type="hidden" name="action" value="csco_import_contents">
</div>
</form>
<?php } ?>
</div>
<?php } ?>
<?php if ( isset( $demo_data['import']['customizer'] ) && $demo_data['import']['customizer'] ) { ?>
<form>
<div class="cs-switcher">
<?php esc_html_e( 'Customizer', 'revision' ); ?> <input class="cs-checkbox" type="checkbox" name="url" value="<?php echo esc_attr( $demo_data['import']['customizer'] ); ?>" checked>
<div class="cs-switch"><span class="cs-switch-slider"></span></div>
</div>
<input type="hidden" name="step_name" value="<?php esc_attr_e( 'Importing customizer options...', 'revision' ); ?>">
<input type="hidden" name="nonce" value="<?php echo esc_attr( wp_create_nonce( 'nonce' ) ); ?>">
<input type="hidden" name="action" value="csco_import_customizer">
</form>
<?php } ?>
<?php if ( isset( $demo_data['import']['options'] ) && $demo_data['import']['options'] ) { ?>
<form>
<div class="cs-switcher">
<?php esc_html_e( 'Options', 'revision' ); ?> <input class="cs-checkbox" type="checkbox" name="url" value="<?php echo esc_attr( $demo_data['import']['options'] ); ?>" checked>
<div class="cs-switch"><span class="cs-switch-slider"></span></div>
</div>
<input type="hidden" name="step_name" value="<?php esc_attr_e( 'Importing options...', 'revision' ); ?>">
<input type="hidden" name="nonce" value="<?php echo esc_attr( wp_create_nonce( 'nonce' ) ); ?>">
<input type="hidden" name="action" value="csco_import_options">
</form>
<?php } ?>
<?php if ( isset( $demo_data['import']['widgets'] ) && $demo_data['import']['widgets'] ) { ?>
<form>
<div class="cs-switcher">
<?php esc_html_e( 'Widgets', 'revision' ); ?> <input class="cs-checkbox" type="checkbox" name="url" value="<?php echo esc_attr( $demo_data['import']['widgets'] ); ?>" checked>
<div class="cs-switch"><span class="cs-switch-slider"></span></div>
</div>
<input type="hidden" name="step_name" value="<?php esc_attr_e( 'Importing widgets...', 'revision' ); ?>">
<input type="hidden" name="nonce" value="<?php echo esc_attr( wp_create_nonce( 'nonce' ) ); ?>">
<input type="hidden" name="action" value="csco_import_widgets">
</form>
<?php } ?>
<form class="hidden">
<div class="cs-switcher">
<?php esc_html_e( 'Finish', 'revision' ); ?> <input class="cs-checkbox" type="checkbox" name="finish" value="1" checked>
<div class="cs-switch"><span class="cs-switch-slider"></span></div>
</div>
<input type="hidden" name="step_name" value="<?php esc_attr_e( 'Finishing setup...', 'revision' ); ?>">
<input type="hidden" name="nonce" value="<?php echo esc_attr( wp_create_nonce( 'nonce' ) ); ?>">
<input type="hidden" name="action" value="csco_import_finish">
</form>
</div>
</div>
<div class="cs-import-actions">
<div class="cs-import-theme-cancel">
<a href="#" class="cs-button cs-demo-import-close button">
<?php esc_html_e( 'Cancel', 'revision' ); ?>
</a>
</div>
<div class="cs-import-theme-start">
<a href="#" class="cs-demo-import-start button button-primary">
<?php esc_html_e( 'Import', 'revision' ); ?>
</a>
</div>
</div>
<?php
wp_send_json_success( ob_get_clean() );
} else {
wp_send_json_error( esc_html__( 'Demo content id not set.', 'revision' ) );
}
wp_die();
}
/**
* Html Carcase
*/
public function html_carcase() {
?>
<div class="cs-wrap cs-demos-page">
<div class="cs-header">
<div class="cs-header-left">
<div class="cs-header-col cs-header-col-logo">
<div class="cs-logo">
<a target="_blank" href="<?php echo esc_url( 'https://codesupply.co/' ); ?>">
Code Supply Co.
</a>
</div>
</div>
</div>
</div>
<div class="wrap">
<h1 class="hidden"><?php esc_html_e( 'Theme Demos', 'revision' ); ?></h1>
<?php
if ( $this->demos ) {
?>
<div class="cs-demos">
<?php
foreach ( $this->demos as $demo_id => $demo ) {
// Demo Variables.
$name = isset( $demo['name'] ) && $demo['name'] ? $demo['name'] : null;
$preview = isset( $demo['preview'] ) && $demo['preview'] ? $demo['preview'] : 'false';
?>
<div class="cs-demo-item cs-demo-item-active"
data-id="<?php echo esc_attr( $demo_id ); ?>"
data-name="<?php echo esc_attr( $name ); ?>"
data-preview="<?php echo esc_url( $preview ); ?>">
<div class="cs-demo-outer">
<div class="cs-demo-thumbnail">
<?php if ( isset( $demo['thumbnail'] ) && $demo['thumbnail'] ) { ?>
<img src="<?php echo esc_url( $demo['thumbnail'] ); ?>">
<?php } ?>
<?php if ( isset( $demo['preview'] ) && $demo['preview'] ) { ?>
<div class="cs-demo-preview">
<span>
<?php esc_html_e( 'Preview Demo', 'revision' ); ?>
</span>
</div>
<?php } ?>
</div>
<div class="cs-demo-data">
<div class="cs-demo-info">
<?php if ( isset( $demo['name'] ) && $demo['name'] ) { ?>
<div class="cs-demo-name"><?php echo esc_html( $demo['name'] ); ?></div>
<?php } ?>
</div>
<div class="cs-demo-actions">
<div class="cs-demo-import">
<a href="#" target="_blank" data-id="<?php echo esc_attr( $demo_id ); ?>" class="cs-demo-import-open button button-primary">
<?php esc_html_e( 'Import', 'revision' ); ?>
</a>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
<?php } ?>
</div>
<div class="cs-import-theme">
<div class="cs-import-overlay"></div>
<div class="cs-import-popup">
<div class="cs-import-container">
<div class="cs-import-step cs-import-step-active cs-import-start">
<div class="cs-import-header">
<?php esc_html_e( 'Import Theme', 'revision' ); ?>
</div>
<div class="cs-import-output"></div>
</div>
<div class="cs-import-step cs-import-process">
<div class="cs-import-header">
<?php esc_html_e( 'Installing', 'revision' ); ?>
</div>
<div class="cs-import-output">
<div class="cs-import-desc">
<?php esc_html_e( 'Please be patient and don\'t refresh this page, the import process may take a while, this also depends on your server.', 'revision' ); ?>
</div>
<div class="cs-import-progress">
<div class="cs-import-progress-label"></div>
<div class="cs-import-progress-bar">
<div class="cs-import-progress-indicator"></div>
</div>
<div class="cs-import-progress-sublabel">0%</div>
</div>
</div>
</div>
<div class="cs-import-step cs-import-finish">
<div class="cs-import-info">
<div class="cs-import-logo">
<svg class="progress-icon" width="96" height="96" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
<g class="tick-icon" stroke-width="1" stroke="#3FB28F" transform="translate(1, 1.2)">
<path id="tick-outline-path" d="M14 28c7.732 0 14-6.268 14-14S21.732 0 14 0 0 6.268 0 14s6.268 14 14 14z"/>
<path id="tick-path" d="M6.173 16.252l5.722 4.228 9.22-12.69"/>
</g>
</svg>
</div>
<div class="cs-import-title">
<?php esc_html_e( 'Imported Succefully', 'revision' ); ?>
</div>
<div class="cs-import-desc">
<?php esc_html_e( 'Go ahead, customize the text, images and design to make it yours!', 'revision' ); ?>
</div>
<div class="cs-import-customize">
<a href="<?php echo esc_url( admin_url( '/customize.php' ) ); ?>" class="button button-primary" target="_blank">
<?php esc_html_e( 'Customize', 'revision' ); ?>
</a>
</div>
</div>
<div class="cs-import-actions">
<a href="<?php echo esc_url( add_query_arg( 'page', $this->dashboard_menu_slug, admin_url( 'themes.php' ) ) ); ?>" class="cs-link">
<?php esc_html_e( 'Return to Dashboard', 'revision' ); ?>
</a>
<a href="<?php echo esc_url( home_url() ); ?>" class="cs-button button" target="_blank">
<?php esc_html_e( 'View Site', 'revision' ); ?>
</a>
</div>
</div>
</div>
</div>
</div>
<div class="cs-preview">
<div class="cs-header">
<div class="cs-header-left">
<div class="cs-header-col cs-header-logo">
<div class="cs-logo">
<a target="_blank" href="<?php echo esc_url( 'https://codesupply.co/' ); ?>">
Code Supply Co.
</a>
</div>
</div>
<div class="cs-header-col cs-header-arrow">
<a href="#" class="cs-arrow cs-prev-demo"></a>
</div>
<div class="cs-header-col cs-header-arrow">
<a href="#" class="cs-arrow cs-next-demo"></a>
</div>
<div class="cs-header-col cs-header-info"></div>
</div>
<div class="cs-header-right">
<div class="cs-preview-cancel">
<a href="#" class="button">
<?php esc_html_e( 'Cancel', 'revision' ); ?>
</a>
</div>
<div class="cs-preview-actions"></div>
</div>
</div>
<i<?php echo esc_attr( 'frame' ); ?> id="cs-preview-i<?php echo esc_attr( 'frame' ); ?>" class="cs-preview-i<?php echo esc_attr( 'frame' ); ?>"></i<?php echo esc_attr( 'frame' ); ?>>
</div>
</div>
<?php
}
/**
* This function will register scripts and styles for admin dashboard.
*
* @param string $page Current page.
*/
public function admin_enqueue_scripts( $page ) {
wp_enqueue_script( 'cs-theme-demos', get_theme_file_uri( '/core/theme-demos/assets/theme-demos.js' ), array( 'jquery' ), filemtime( get_theme_file_path( '/core/theme-demos/assets/theme-demos.js' ) ), true );
wp_localize_script( 'cs-theme-demos', 'cscoThemeDemosConfig', array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'nonce' ),
'failed_message' => esc_html__( 'Something went wrong, contact support.', 'revision' ),
) );
// Styles.
wp_enqueue_style( 'cs-theme-demos', get_theme_file_uri( '/core/theme-demos/assets/theme-demos.css' ), array(), filemtime( get_theme_file_path( '/core/theme-demos/assets/theme-demos.css' ) ) );
// Add RTL support.
wp_style_add_data( 'revision', 'rtl', 'replace' );
}
}
new CSCO_Theme_Demos();
}

View File

@@ -0,0 +1,185 @@
<?php
/**
* Class for the customizer importer.
*
* Code is mostly from the Customizer Export/Import plugin.
*
* @see https://wordpress.org/plugins/customizer-export-import/
* @package Revision
*/
/**
* Customizer Importer
*/
class CSCO_Customizer_Importer {
/**
* Import customizer.
*
* @param array $data The data.
*/
public static function import( $data ) {
// Try to import the customizer settings.
return self::import_customizer_options( $data );
}
/**
* Imports uploaded mods and calls WordPress core customize_save actions so
* themes that hook into them can act before mods are saved to the database.
*
* Update: WP core customize_save actions were removed, because of some errors.
*
* @param array $data The data.
* @return void|WP_Error
*/
public static function import_customizer_options( $data ) {
// Setup global vars.
global $wp_customize;
// Data check.
if ( ! is_array( $data ) || ! isset( $data['mods'] ) ) {
return new WP_Error(
'customizer_import_data_error',
esc_html__( 'Error: The customizer import file is not in a correct format. Please make sure to use the correct customizer import file.', 'revision' )
);
}
/**
* Import images.
*
* The csco_customizer_import_images hook.
*
* @since 1.0.0
*/
if ( apply_filters( 'csco_customizer_import_images', true ) ) {
$data['mods'] = self::import_customizer_images( $data['mods'] );
}
// Import custom options.
if ( isset( $data['options'] ) ) {
// Require modified customizer options class.
if ( ! class_exists( 'WP_Customize_Setting' ) ) {
require_once ABSPATH . 'wp-includes/class-wp-customize-setting.php';
}
if ( ! class_exists( 'CSCO_Customizer_Option' ) ) {
require_once get_theme_file_path( '/core/theme-demos/import/class-customizer-option.php' );
}
foreach ( $data['options'] as $option_key => $option_value ) {
$option = new CSCO_Customizer_Option( $wp_customize, $option_key, array(
'default' => '',
'type' => 'option',
'capability' => 'edit_theme_options',
) );
$option->import( $option_value );
}
}
/**
* The csco_enable_wp_customize_save_hooks hook.
*
* @since 1.0.0
*/
$use_wp_customize_save_hooks = apply_filters( 'csco_enable_wp_customize_save_hooks', false );
if ( $use_wp_customize_save_hooks ) {
/**
* The customize_save hook.
*
* @since 1.0.0
*/
do_action( 'customize_save', $wp_customize );
}
// Import mods.
if ( isset( $data['mods'] ) && $data['mods'] ) {
foreach ( $data['mods'] as $key => & $value ) {
if ( $use_wp_customize_save_hooks ) {
/**
* The customize_save_{$key} hook.
*
* @since 1.0.0
*/
do_action( 'customize_save_' . $key, $wp_customize );
}
// Save the mod.
set_theme_mod( $key, $value );
}
}
// Import mods Adobe Fonts.
if ( isset( $data['mods_adobe'] ) && $data['mods_adobe'] ) {
foreach ( $data['mods_adobe'] as $key => & $value ) {
if ( $use_wp_customize_save_hooks ) {
/**
* The customize_save_{$key} hook.
*
* @since 1.0.0
*/
do_action( 'customize_save_' . $key, $wp_customize );
}
$token = get_option( 'powerkit_typekit_fonts_token' );
$kit = get_option( 'powerkit_typekit_fonts_kit' );
$kit_fonts = get_option( 'pk_typekit_' . $kit . '_s' );
$families = ( $kit_fonts ) ? $kit_fonts['kit']['families'] : false;
$font_found = false;
// Search for the font slug from a theme_mod in the active Adobe font kit.
if ( isset( $value['font-family'] ) && $families ) {
foreach ( $families as $k => $v ) {
if ( isset( $v['slug'] ) && $value['font-family'] === $v['slug'] ) {
$font_found = true;
break;
}
if ( isset( $v['css_names'][0] ) && $value['font-family'] === $v['css_names'][0] ) {
$font_found = true;
break;
}
}
}
// Set default font family.
if ( is_array( $value ) && ( ! $token || ! $kit || ! $font_found ) ) {
$value['font-family'] = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif';
}
// Save the mod.
set_theme_mod( $key, $value );
}
}
if ( $use_wp_customize_save_hooks ) {
/**
* The customize_save_after hook.
*
* @since 1.0.0
*/
do_action( 'customize_save_after', $wp_customize );
}
}
/**
* Helper function: Customizer import - imports images for settings saved as mods.
*
* @param array $mods An array of customizer mods.
* @return array The mods array with any new import data.
*/
private static function import_customizer_images( $mods ) {
foreach ( $mods as $key => $val ) {
if ( CSCO_Manager_Import::is_image_url( $val ) ) {
$data = CSCO_Manager_Import::import_custom_image( $val );
if ( ! is_wp_error( $data ) ) {
$mods[ $key ] = $data->url;
}
}
}
return $mods;
}
}

View File

@@ -0,0 +1,23 @@
<?php
/**
* A class that extends WP_Customize_Setting so we can access
* the protected updated method when importing options.
*
* Used in the Customizer importer.
*
* @since 1.0.0
* @package Revision
*/
final class CSCO_Customizer_Option extends WP_Customize_Setting {
/**
* Import an option value for this setting.
*
* @since 1.0.0
* @param mixed $value The option value.
* @return void
*/
public function import( $value ) {
$this->update( $value );
}
}

View File

@@ -0,0 +1,901 @@
<?php
/**
* Manager Import.
*
* @package Revision
*/
/**
* Manager Import Class
*/
class CSCO_Manager_Import {
/**
* Singleton instance
*
* @var CSCO_Manager_Import
*/
private static $instance;
/**
* Sites Server API URL
*
* @var string
*/
public $api_url;
/**
* Get singleton instance.
*
* @return CSCO_Manager_Import
*/
public static function instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Time in milliseconds, marking the beginning of the import.
*
* @var float
*/
private $microtime;
/**
* Class constructor
*/
public function __construct() {
add_action( 'after_setup_theme', array( $this, 'init' ) );
}
/**
* Initialize plugin.
*/
public function init() {
add_action( 'upload_mimes', array( $this, 'add_custom_mimes' ) );
add_filter( 'wp_check_filetype_and_ext', array( $this, 'real_mime_type_for_xml' ), 10, 4 );
add_filter( 'admin_init', array( $this, 'ajax_runtime_hide_errors' ), 0 );
add_filter( 'query', array( $this, 'ajax_wpdb_hide_errors' ), 0 );
add_action( 'wp_ajax_csco_import_plugin', array( $this, 'ajax_import_plugin' ) );
add_action( 'wp_ajax_csco_import_contents', array( $this, 'ajax_import_contents' ) );
add_action( 'wp_ajax_csco_import_customizer', array( $this, 'ajax_import_customizer' ) );
add_action( 'wp_ajax_csco_import_widgets', array( $this, 'ajax_import_widgets' ) );
add_action( 'wp_ajax_csco_import_options', array( $this, 'ajax_import_options' ) );
add_action( 'wp_ajax_csco_import_finish', array( $this, 'ajax_import_finish' ) );
}
/**
* Pre Plugin Setup
*/
public function pre_plugin_setup() {
/* Woocommerce */
add_filter( 'woocommerce_prevent_automatic_wizard_redirect', '__return_false' );
add_filter( 'woocommerce_enable_setup_wizard', '__return_false' );
/* Elementor */
set_transient( 'elementor_activation_redirect', false );
}
/**
* Helper function: Import image.
*
* @param string $url Image url.
* @param bool $retina Support retina.
* @return array The import data.
*/
public static function import_custom_image( $url, $retina = true ) {
$data = self::sideload_image( $url );
if ( $retina ) {
// Upload @2x image.
self::sideload_image(
str_replace( array( '.jpg', '.jpeg', '.png', '.gif', '.webp' ),
array( '@2x.jpg', '@2x.jpeg', '@2x.png', '@2x.gif', '@2x.webp' ),
$url
)
);
}
if ( ! is_wp_error( $data ) ) {
return $data;
}
}
/**
* Taken from the core media_sideload_image function and
* modified to return an array of data instead of html.
*
* @param string $file The image file path.
* @return array An array of image data.
*/
public static function sideload_image( $file ) {
$data = new stdClass();
if ( ! function_exists( 'media_handle_sideload' ) ) {
call_user_func( 'require_once', ABSPATH . 'wp-admin/includes/media.php' );
call_user_func( 'require_once', ABSPATH . 'wp-admin/includes/file.php' );
call_user_func( 'require_once', ABSPATH . 'wp-admin/includes/image.php' );
}
if ( ! empty( $file ) ) {
// Set variables for storage, fix file filename for query strings.
preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png|webp)\b/i', $file, $matches );
$file_array = array();
$file_array['name'] = basename( $matches[0] );
// Download file to temp location.
$file_array['tmp_name'] = download_url( $file );
// If error storing temporarily, return the error.
if ( is_wp_error( $file_array['tmp_name'] ) ) {
return $file_array['tmp_name'];
}
// Do the validation and storage stuff.
$id = media_handle_sideload( $file_array, 0 );
// If error storing permanently, unlink.
if ( is_wp_error( $id ) ) {
unlink( $file_array['tmp_name'] );
return $id;
}
// Build the object to return.
$meta = wp_get_attachment_metadata( $id );
$data->attachment_id = $id;
$data->url = wp_get_attachment_url( $id );
$data->thumbnail_url = wp_get_attachment_thumb_url( $id );
$data->height = $meta['height'];
$data->width = $meta['width'];
}
return $data;
}
/**
* Checks to see whether a string is an image url or not.
*
* @param string $string The string to check.
* @return bool Whether the string is an image url or not.
*/
public static function is_image_url( $string = '' ) {
if ( is_string( $string ) ) {
if ( preg_match( '/\.(jpg|jpeg|png|gif|webp)/i', $string ) ) {
return true;
}
}
return false;
}
/**
* Add custom mimes for the uploader.
*
* @param array $mimes The mimes.
*/
public function add_custom_mimes( $mimes ) {
// Allow XML files.
$mimes['xml'] = 'text/xml';
// Allow JSON files.
$mimes['json'] = 'application/json';
return $mimes;
}
/**
* Filters the "real" file type of the given file.
*
* @param array $wp_check_filetype_and_ext The wp_check_filetype_and_ext.
* @param string $file The file.
* @param string $filename The filename.
* @param array $mimes The mimes.
*/
public function real_mime_type_for_xml( $wp_check_filetype_and_ext, $file, $filename, $mimes ) {
if ( '.xml' === substr( $filename, -4 ) ) {
$wp_check_filetype_and_ext['ext'] = 'xml';
$wp_check_filetype_and_ext['type'] = 'text/xml';
}
return $wp_check_filetype_and_ext;
}
/**
* Get plugin status.
*
* @param string $plugin_path Plugin path.
*/
public function get_plugin_status( $plugin_path ) {
if ( ! current_user_can( 'install_plugins' ) ) {
return;
}
if ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin_path ) ) {
return 'not_installed';
} elseif ( in_array( $plugin_path, (array) get_option( 'active_plugins', array() ), true ) || is_plugin_active_for_network( $plugin_path ) ) {
return 'active';
} else {
return 'inactive';
}
}
/**
* Install a plugin.
*
* @param string $plugin_slug Plugin slug.
*/
public function install_plugin( $plugin_slug ) {
if ( ! current_user_can( 'install_plugins' ) ) {
return;
}
if ( ! function_exists( 'plugins_api' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
}
if ( ! class_exists( 'WP_Upgrader' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
}
if ( false === filter_var( $plugin_slug, FILTER_VALIDATE_URL ) ) {
$api = plugins_api(
'plugin_information',
array(
'slug' => $plugin_slug,
'fields' => array(
'short_description' => false,
'sections' => false,
'requires' => false,
'rating' => false,
'ratings' => false,
'downloaded' => false,
'last_updated' => false,
'added' => false,
'tags' => false,
'compatibility' => false,
'homepage' => false,
'donate_link' => false,
),
)
);
$download_link = $api->download_link;
} else {
$download_link = $plugin_slug;
}
// Use AJAX upgrader skin instead of plugin installer skin.
// ref: function wp_ajax_install_plugin().
$upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() );
$this->pre_plugin_setup();
$install = $upgrader->install( $download_link );
if ( false === $install ) {
return false;
} else {
return true;
}
}
/**
* Activate a plugin.
*
* @param string $plugin_path Plugin path.
*/
public function activate_plugin( $plugin_path ) {
if ( ! current_user_can( 'install_plugins' ) ) {
return false;
}
$this->pre_plugin_setup();
$activate = activate_plugin( $plugin_path, '', false, true );
if ( is_wp_error( $activate ) ) {
return false;
} else {
return true;
}
}
/**
* Detect ajax import.
*/
public function is_ajax_import() {
if ( __return_false() ) {
check_ajax_referer();
}
$current_action = __return_empty_string();
if ( isset( $_REQUEST['action'] ) ) {
$current_action = sanitize_text_field( $_REQUEST['action'] );
}
if ( preg_match( '/csco_import/', $current_action ) ) {
return $current_action;
}
}
/**
* Hide errors for wpdb
*
* @param object $query The query.
*/
public function ajax_wpdb_hide_errors( $query ) {
global $wpdb;
if ( $this->is_ajax_import() ) {
$wpdb->hide_errors();
}
return $query;
}
/**
* Hide errors for runtime
*/
public function ajax_runtime_hide_errors() {
call_user_func( 'ini_set', 'display_errors', 'Off' );
}
/**
* Ajax import start
*/
public function ajax_import_start() {
ob_start();
}
/**
* Ajax import end
*/
public function ajax_import_end() {
ob_end_flush();
}
/**
* Sends a JSON response back to an Ajax request, indicating failure.
*
* @param mixed $data Data to encode as JSON, then print and die.
*/
public function send_json_error( $data = null ) {
$log = trim( ob_get_clean() );
if ( $log ) {
$data .= sprintf( '%s', PHP_EOL . $log );
}
wp_send_json_error( $data );
}
/**
* Sends a JSON response back to an Ajax request, indicating success.
*
* @param mixed $data Data to encode as JSON, then print and die.
*/
public function send_json_success( $data = null ) {
$log = trim( ob_get_clean() );
if ( $log ) {
$data .= sprintf( '%s', PHP_EOL . $log );
}
wp_send_json_success( $data );
}
/**
* AJAX callback to install and activate a plugin.
*/
public function ajax_import_plugin() {
set_time_limit( 0 );
$this->ajax_import_start();
check_ajax_referer( 'nonce', 'nonce' );
if ( ! isset( $_POST['plugin_slug'] ) || ! sanitize_text_field( $_POST['plugin_slug'] ) ) {
$this->send_json_error( esc_html__( 'Unknown slug in a plugin.', 'revision' ) );
}
if ( ! isset( $_POST['plugin_path'] ) || ! sanitize_text_field( $_POST['plugin_path'] ) ) {
$this->send_json_error( esc_html__( 'Unknown path in a plugin.', 'revision' ) );
}
$plugin_slug = sanitize_text_field( $_POST['plugin_slug'] );
$plugin_path = sanitize_text_field( $_POST['plugin_path'] );
if ( ! current_user_can( 'install_plugins' ) ) {
$this->send_json_error( esc_html__( 'Insufficient permissions to install the plugin.', 'revision' ) );
}
if ( 'not_installed' === $this->get_plugin_status( $plugin_path ) ) {
$this->install_plugin( $plugin_slug );
$this->activate_plugin( $plugin_path );
} elseif ( 'inactive' === $this->get_plugin_status( $plugin_path ) ) {
$this->activate_plugin( $plugin_path );
}
if ( 'active' === $this->get_plugin_status( $plugin_path ) ) {
$this->send_json_success();
}
/**
* The csco_import_plugin hook.
*
* @since 1.0.0
*/
do_action( 'csco_import_plugin', $plugin_slug, $plugin_path );
$this->send_json_error( esc_html__( 'Failed to initialize or activate importer plugin.', 'revision' ) );
$this->ajax_import_end();
}
/**
* AJAX callback to import contents and media files from contents.xml.
*/
public function ajax_import_contents() {
$this->ajax_import_start();
check_ajax_referer( 'nonce', 'nonce' );
$import_type = 'default';
if ( ! isset( $_POST['url'] ) || ! sanitize_text_field( $_POST['url'] ) ) {
$this->send_json_error( esc_html__( 'The url address of the demo content is not specified.', 'revision' ) );
}
if ( isset( $_POST['type'] ) && sanitize_text_field( $_POST['type'] ) ) {
$import_type = sanitize_text_field( $_POST['type'] );
}
$file_url = sanitize_text_field( $_POST['url'] );
$xml_file_hash_id = 'csco_importer_data_' . md5( $file_url );
$xml_file_path = get_transient( $xml_file_hash_id );
if ( ! $xml_file_path ) {
if ( ! current_user_can( 'edit_theme_options' ) ) {
$this->send_json_error( esc_html__( 'You are not permitted to import contents.', 'revision' ) );
}
if ( ! isset( $file_url ) ) {
$this->send_json_error( esc_html__( 'No XML file specified.', 'revision' ) );
}
/**
* Download contents.xml
*/
if ( ! function_exists( 'download_url' ) ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
}
$url = wp_unslash( $file_url );
$timeout_seconds = 5;
add_filter( 'https_ssl_verify', '__return_false' );
// Download file to temp dir.
$temp_file = download_url( $url, $timeout_seconds );
add_filter( 'https_local_ssl_verify', '__return_false' );
if ( is_wp_error( $temp_file ) ) {
$this->send_json_error( $temp_file->get_error_message() );
}
// Array based on $_FILE as seen in PHP file uploads.
$file_args = array(
'name' => basename( $url ),
'tmp_name' => $temp_file,
'error' => 0,
'size' => filesize( $temp_file ),
);
$overrides = array(
// This tells WordPress to not look for the POST form
// fields that would normally be present. Default is true.
// Since the file is being downloaded from a remote server,
// there will be no form fields.
'test_form' => false,
// Setting this to false lets WordPress allow empty files not recommended.
'test_size' => true,
// A properly uploaded file will pass this test.
// There should be no reason to override this one.
'test_upload' => true,
'mimes' => array(
'xml' => 'text/xml',
),
);
// Move the temporary file into the uploads directory.
$download_response = wp_handle_sideload( $file_args, $overrides );
// Error when downloading XML file.
if ( isset( $download_response['error'] ) ) {
$this->send_json_error( $download_response['error'] );
}
// Define the downloaded contents.xml file path.
$xml_file_path = $download_response['file'];
set_transient( $xml_file_hash_id, $xml_file_path, HOUR_IN_SECONDS );
}
/**
* Import content and media files using WXR Importer.
*/
if ( ! class_exists( 'WP_Importer' ) ) {
if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
define( 'WP_LOAD_IMPORTERS', true );
}
require_once ABSPATH . 'wp-admin/includes/class-wp-importer.php';
}
/**
* Import Core.
*/
require_once get_theme_file_path( '/core/theme-demos/import/wp-content-importer-v2/WPImporterLogger.php' );
require_once get_theme_file_path( '/core/theme-demos/import/wp-content-importer-v2/WPImporterLoggerCLI.php' );
require_once get_theme_file_path( '/core/theme-demos/import/wp-content-importer-v2/WXRImportInfo.php' );
require_once get_theme_file_path( '/core/theme-demos/import/wp-content-importer-v2/WXRImporter.php' );
require_once get_theme_file_path( '/core/theme-demos/import/wp-content-importer-v2/Logger.php' );
/**
* Prepare the importer.
*/
// Time to run the import!
set_time_limit( 0 );
$this->microtime = microtime( true );
// Are we allowed to create users?
add_filter( 'wxr_importer.pre_process.user', '__return_null' );
// Check, if we need to send another AJAX request and set the importing author to the current user.
add_filter( 'wxr_importer.pre_process.post', array( $this, 'ajax_request_maybe' ) );
// Set the WordPress Importer v2 as the importer used in this plugin.
// More: https://github.com/humanmade/WordPress-Importer.
$importer = new CSCO_WXRImporter( array(
'fetch_attachments' => true,
'default_author' => get_current_user_id(),
) );
/**
* Logger options for the logger used in the importer.
*
* The csco_logger_options hook.
*
* @since 1.0.0
*/
$logger_options = apply_filters( 'csco_logger_options', array(
'logger_min_level' => 'warning',
) );
// Configure logger instance and set it to the importer.
$logger = new CSCO_Logger();
$logger->min_level = $logger_options['logger_min_level'];
// Set logger.
$importer->set_logger( $logger );
/**
* Process import.
*/
$importer->import( $xml_file_path );
// Is error ?.
if ( is_wp_error( $importer ) ) {
$this->send_json_error( $importer->get_error_message() );
}
if ( $logger->error_output ) {
$this->send_json_error( $logger->error_output );
}
/**
* The csco_import_contents hook.
*
* @since 1.0.0
*/
do_action( 'csco_import_contents' );
/**
* Return successful AJAX.
*/
$this->send_json_success();
$this->ajax_import_end();
}
/**
* Check if we need to create a new AJAX request, so that server does not timeout.
*
* @param array $data current post data.
* @return array
*/
public function ajax_request_maybe( $data ) {
$time = microtime( true ) - $this->microtime;
/**
* We should make a new ajax call, if the time is right.
*
* The csco_time_for_one_ajax_call hook.
*
* @since 1.0.0
*/
if ( $time > apply_filters( 'csco_time_for_one_ajax_call', 22 ) ) {
$response = array(
'success' => true,
'status' => 'newAJAX',
'message' => 'Time for new AJAX request!: ' . $time,
);
// Send the request for a new AJAX call.
wp_send_json( $response );
}
// Set importing author to the current user.
// Fixes the [WARNING] Could not find the author for ... log warning messages.
$current_user_obj = wp_get_current_user();
$data['post_author'] = $current_user_obj->user_login;
return $data;
}
/**
* AJAX callback to import customizer settings from customizer.json.
*/
public function ajax_import_customizer() {
set_time_limit( 0 );
$this->ajax_import_start();
check_ajax_referer( 'nonce', 'nonce' );
if ( ! isset( $_POST['url'] ) || ! sanitize_text_field( $_POST['url'] ) ) {
$this->send_json_error( esc_html__( 'The url address of the demo content is not specified.', 'revision' ) );
}
$file_url = sanitize_text_field( $_POST['url'] );
if ( ! current_user_can( 'edit_theme_options' ) ) {
$this->send_json_error( esc_html__( 'You are not permitted to import customizer.', 'revision' ) );
}
if ( ! isset( $file_url ) ) {
$this->send_json_error( esc_html__( 'No customizer JSON file specified.', 'revision' ) );
}
/**
* Process customizer.json.
*/
// Get JSON data from customizer.json.
$raw = wp_remote_get( wp_unslash( $file_url ), array(
'sslverify' => false,
) );
// Abort if customizer.json response code is not successful.
if ( 200 !== wp_remote_retrieve_response_code( $raw ) ) {
$this->send_json_error();
}
// Decode raw JSON string to associative array.
$data = json_decode( wp_remote_retrieve_body( $raw ), true );
$customizer = new CSCO_Customizer_Importer();
// Import.
$results = $customizer->import( $data );
if ( is_wp_error( $results ) ) {
$error_message = $results->get_error_message();
$this->send_json_error( $error_message );
}
/**
* The csco_import_customizer hook.
*
* @since 1.0.0
*/
do_action( 'csco_import_customizer', $data );
/**
* Return successful AJAX.
*/
$this->send_json_success();
$this->ajax_import_end();
}
/**
* AJAX callback to import widgets on all sidebars from widgets.json.
*/
public function ajax_import_widgets() {
set_time_limit( 0 );
$this->ajax_import_start();
check_ajax_referer( 'nonce', 'nonce' );
if ( ! isset( $_POST['url'] ) || ! sanitize_text_field( $_POST['url'] ) ) {
$this->send_json_error( esc_html__( 'The url address of the demo content is not specified.', 'revision' ) );
}
$file_url = sanitize_text_field( $_POST['url'] );
if ( ! current_user_can( 'edit_theme_options' ) ) {
$this->send_json_error( esc_html__( 'You are not permitted to import widgets.', 'revision' ) );
}
if ( ! isset( $file_url ) ) {
$this->send_json_error( esc_html__( 'No widgets WIE file specified.', 'revision' ) );
}
/**
* Process widgets.json.
*/
// Get JSON data from widgets.json.
$raw = wp_remote_get( wp_unslash( $file_url ), array(
'sslverify' => false,
) );
// Abort if customizer.json response code is not successful.
if ( 200 !== (int) wp_remote_retrieve_response_code( $raw ) ) {
$this->send_json_error();
}
// Decode raw JSON string to associative array.
$data = json_decode( wp_remote_retrieve_body( $raw ) );
$widgets = new CSCO_Widget_Importer();
// Import.
$results = $widgets->import( $data );
if ( is_wp_error( $results ) ) {
$error_message = $results->get_error_message();
$this->send_json_error( $error_message );
}
/**
* The csco_import_widgets hook.
*
* @since 1.0.0
*/
do_action( 'csco_import_widgets' );
/**
* Return successful AJAX.
*/
$this->send_json_success();
$this->ajax_import_end();
}
/**
* AJAX callback to import other options from options.json.
*/
public function ajax_import_options() {
set_time_limit( 0 );
$this->ajax_import_start();
check_ajax_referer( 'nonce', 'nonce' );
if ( ! isset( $_POST['url'] ) || ! sanitize_text_field( $_POST['url'] ) ) {
$this->send_json_error( esc_html__( 'The url address of the demo content is not specified.', 'revision' ) );
}
$file_url = sanitize_text_field( $_POST['url'] );
if ( ! current_user_can( 'edit_theme_options' ) ) {
$this->send_json_error( esc_html__( 'You are not permitted to import options.', 'revision' ) );
}
if ( ! isset( $file_url ) ) {
$this->send_json_error( esc_html__( 'No options JSON file specified.', 'revision' ) );
}
/**
* Process options.json.
*/
// Get JSON data from options.json.
$raw = wp_remote_get( wp_unslash( $file_url ), array(
'sslverify' => false,
) );
// Abort if customizer.json response code is not successful.
if ( 200 !== (int) wp_remote_retrieve_response_code( $raw ) ) {
$this->send_json_error();
}
// Decode raw JSON string to associative array.
$array = json_decode( wp_remote_retrieve_body( $raw ), true );
/**
* Import options to DB.
*/
foreach ( $array as $key => $value ) {
// Skip option key with "__" prefix, because it will be treated specifically via the action hook.
if ( '__' === substr( $key, 0, 2 ) ) {
continue;
}
// Insert to options table.
update_option( $key, $value );
}
/**
* The csco_import_options hook.
*
* @since 1.0.0
*/
do_action( 'csco_import_options', $array );
/**
* Return successful AJAX.
*/
$this->send_json_success();
$this->ajax_import_end();
}
/**
* AJAX callback to finish import.
*/
public function ajax_import_finish() {
set_time_limit( 0 );
$this->ajax_import_start();
/**
* The csco_finish_import hook.
*
* @since 1.0.0
*/
do_action( 'csco_finish_import' );
/**
* Return successful AJAX.
*/
$this->send_json_success();
$this->ajax_import_end();
}
}
new CSCO_Manager_Import();

View File

@@ -0,0 +1,317 @@
<?php
/**
* Class for the widget importer.
*
* Code is mostly from the Widget Importer & Exporter plugin.
*
* @see https://wordpress.org/plugins/widget-importer-exporter/
* @package Revision
*/
/**
* Widget Importer
*/
class CSCO_Widget_Importer {
/**
* Import widgets from WIE or JSON file.
*
* @param array $data The data.
*/
public static function import( $data ) {
// Import widgets and return result.
return self::import_data( $data );
}
/**
* Import widget JSON data
*
* @global array $wp_registered_sidebars
* @param object $data JSON widget data.
* @return array $results
*/
private static function import_data( $data ) {
global $wp_registered_sidebars;
// Have valid data? If no data or could not decode.
if ( empty( $data ) || ! is_object( $data ) ) {
return new WP_Error(
'corrupted_widget_import_data',
__( 'Error: Widget import data could not be read. Please try a different file.', 'revision' )
);
}
/**
* Hook before import.
*
* The csco_widget_importer_before_widgets_import hook.
*
* @since 1.0.0
*/
do_action( 'csco_widget_importer_before_widgets_import' );
/**
* The csco_before_widgets_import_data hook.
*
* @since 1.0.0
*/
$data = apply_filters( 'csco_before_widgets_import_data', $data );
// Get all available widgets site supports.
$available_widgets = self::available_widgets();
// Get all existing widget instances.
$widget_instances = array();
foreach ( $available_widgets as $widget_data ) {
$widget_instances[ $widget_data['id_base'] ] = get_option( 'widget_' . $widget_data['id_base'] );
}
// Begin results.
$results = array();
// Loop import data's sidebars.
foreach ( $data as $sidebar_id => $widgets ) {
// Skip inactive widgets (should not be in export file).
if ( 'wp_inactive_widgets' === $sidebar_id ) {
continue;
}
// Check if sidebar is available on this site. Otherwise add widgets to inactive, and say so.
if ( isset( $wp_registered_sidebars[ $sidebar_id ] ) ) {
$sidebar_available = true;
$use_sidebar_id = $sidebar_id;
$sidebar_message_type = 'success';
$sidebar_message = '';
} else {
$sidebar_available = false;
$use_sidebar_id = 'wp_inactive_widgets'; // Add to inactive if sidebar does not exist in theme.
$sidebar_message_type = 'error';
$sidebar_message = __( 'Sidebar does not exist in theme (moving widget to Inactive)', 'revision' );
}
// Result for sidebar.
$results[ $sidebar_id ]['name'] = ! empty( $wp_registered_sidebars[ $sidebar_id ]['name'] ) ? $wp_registered_sidebars[ $sidebar_id ]['name'] : $sidebar_id; // Sidebar name if theme supports it; otherwise ID.
$results[ $sidebar_id ]['message_type'] = $sidebar_message_type;
$results[ $sidebar_id ]['message'] = $sidebar_message;
$results[ $sidebar_id ]['widgets'] = array();
// Loop widgets.
foreach ( $widgets as $widget_instance_id => $widget ) {
$fail = false;
// Get id_base (remove -# from end) and instance ID number.
$id_base = preg_replace( '/-[0-9]+$/', '', $widget_instance_id );
$instance_id_number = str_replace( $id_base . '-', '', $widget_instance_id );
// Does site support this widget?
if ( ! $fail && ! isset( $available_widgets[ $id_base ] ) ) {
$fail = true;
$widget_message_type = 'error';
$widget_message = __( 'Site does not support widget', 'revision' ); // Explain why widget not imported.
}
// Filter to modify settings object before conversion to array and import.
// Leave this filter here for backwards compatibility with manipulating objects (before conversion to array below).
// Ideally the newer wie_widget_settings_array below will be used instead of this.
/**
* Filter to modify settings object before conversion to array and import.
* Leave this filter here for backwards compatibility with manipulating objects (before conversion to array below).
* Ideally the newer wie_widget_settings_array below will be used instead of this.
*
* The csco_widget_settings hook.
*
* @since 1.0.0
*/
$widget = apply_filters( 'csco_widget_settings', $widget ); // Object.
// Convert multidimensional objects to multidimensional arrays.
// Some plugins like Jetpack Widget Visibility store settings as multidimensional arrays.
// Without this, they are imported as objects and cause fatal error on Widgets page.
// If this creates problems for plugins that do actually intend settings in objects then may need to consider other approach: https://wordpress.org/support/topic/problem-with-array-of-arrays.
// It is probably much more likely that arrays are used than objects, however.
$widget = json_decode( json_encode( $widget ), true );
/**
* Filter to modify settings array.
* This is preferred over the older wie_widget_settings filter above.
* Do before identical check because changes may make it identical to end result (such as URL replacements).
*
* The csco_widget_settings_array hook.
*
* @since 1.0.0
*/
$widget = apply_filters( 'csco_widget_settings_array', $widget );
// Does widget with identical settings already exist in same sidebar?
if ( ! $fail && isset( $widget_instances[ $id_base ] ) ) {
// Get existing widgets in this sidebar.
$sidebars_widgets = get_option( 'sidebars_widgets' );
$sidebar_widgets = isset( $sidebars_widgets[ $use_sidebar_id ] ) ? $sidebars_widgets[ $use_sidebar_id ] : array(); // Check Inactive if that's where will go.
// Loop widgets with ID base.
$single_widget_instances = ! empty( $widget_instances[ $id_base ] ) ? $widget_instances[ $id_base ] : array();
foreach ( $single_widget_instances as $check_id => $check_widget ) {
// Is widget in same sidebar and has identical settings?
if ( in_array( "$id_base-$check_id", $sidebar_widgets ) && (array) $widget == $check_widget ) {
$fail = true;
$widget_message_type = 'warning';
$widget_message = __( 'Widget already exists', 'revision' ); // Explain why widget not imported.
break;
}
}
}
// No failure.
if ( ! $fail ) {
// Add widget instance.
$single_widget_instances = get_option( 'widget_' . $id_base ); // All instances for that widget ID base, get fresh every time.
$single_widget_instances = ! empty( $single_widget_instances ) ? $single_widget_instances : array( '_multiwidget' => 1 ); // Start fresh if have to.
$single_widget_instances[] = $widget; // Add it.
// Get the key it was given.
end( $single_widget_instances );
$new_instance_id_number = key( $single_widget_instances );
// If key is 0, make it 1.
// When 0, an issue can occur where adding a widget causes data from other widget to load, and the widget doesn't stick (reload wipes it).
if ( '0' === strval( $new_instance_id_number ) ) {
$new_instance_id_number = 1;
$single_widget_instances[ $new_instance_id_number ] = $single_widget_instances[0];
unset( $single_widget_instances[0] );
}
// Move _multiwidget to end of array for uniformity.
if ( isset( $single_widget_instances['_multiwidget'] ) ) {
$multiwidget = $single_widget_instances['_multiwidget'];
unset( $single_widget_instances['_multiwidget'] );
$single_widget_instances['_multiwidget'] = $multiwidget;
}
// Update option with new widget.
update_option( 'widget_' . $id_base, $single_widget_instances );
// Assign widget instance to sidebar.
$sidebars_widgets = get_option( 'sidebars_widgets' ); // Which sidebars have which widgets, get fresh every time.
// Avoid rarely fatal error when the option is an empty string
// https://github.com/churchthemes/widget-importer-exporter/pull/11.
if ( ! $sidebars_widgets ) {
$sidebars_widgets = array();
}
$new_instance_id = $id_base . '-' . $new_instance_id_number; // Use ID number from new widget instance.
$sidebars_widgets[ $use_sidebar_id ][] = $new_instance_id; // Add new instance to sidebar.
update_option( 'sidebars_widgets', $sidebars_widgets ); // Save the amended data.
// After widget import action.
$after_widget_import = array(
'sidebar' => $use_sidebar_id,
'sidebar_old' => $sidebar_id,
'widget' => $widget,
'widget_type' => $id_base,
'widget_id' => $new_instance_id,
'widget_id_old' => $widget_instance_id,
'widget_id_num' => $new_instance_id_number,
'widget_id_num_old' => $instance_id_number,
);
/**
* The csco_widget_importer_after_single_widget_import hook.
*
* @since 1.0.0
*/
do_action( 'csco_widget_importer_after_single_widget_import', $after_widget_import );
// Success message.
if ( $sidebar_available ) {
$widget_message_type = 'success';
$widget_message = __( 'Imported', 'revision' );
} else {
$widget_message_type = 'warning';
$widget_message = __( 'Imported to Inactive', 'revision' );
}
}
// Result for widget instance.
$results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['name'] = isset( $available_widgets[ $id_base ]['name'] ) ? $available_widgets[ $id_base ]['name'] : $id_base; // Widget name or ID if name not available (not supported by site).
$results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['title'] = ! empty( $widget['title'] ) ? $widget['title'] : __( 'No Title', 'revision' ); // Show "No Title" if widget instance is untitled.
$results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message_type'] = $widget_message_type;
$results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message'] = $widget_message;
}
}
/**
* Hook after import.
*
* The csco_widget_importer_after_widgets_import hook.
*
* @since 1.0.0
*/
do_action( 'csco_widget_importer_after_widgets_import' );
/**
* Return results.
*
* The csco_widget_import_results hook.
*
* @since 1.0.0
*/
return apply_filters( 'csco_widget_import_results', $results );
}
/**
* Available widgets.
*
* Gather site's widgets into array with ID base, name, etc.
*
* @global array $wp_registered_widget_controls
* @return array $available_widgets, Widget information
*/
private static function available_widgets() {
global $wp_registered_widget_controls;
$widget_controls = $wp_registered_widget_controls;
$available_widgets = array();
foreach ( $widget_controls as $widget ) {
if ( ! empty( $widget['id_base'] ) && ! isset( $available_widgets[ $widget['id_base'] ] ) ) {
$available_widgets[ $widget['id_base'] ]['id_base'] = $widget['id_base'];
$available_widgets[ $widget['id_base'] ]['name'] = $widget['name'];
}
}
/**
* The csco_available_widgets hook.
*
* @since 1.0.0
*/
return apply_filters( 'csco_available_widgets', $available_widgets );
}
/**
* Format results for log file
*
* @param array $results widget import results.
*/
private static function format_results_for_log( $results ) {
if ( empty( $results ) ) {
esc_html_e( 'No results for widget import!', 'revision' );
}
// Loop sidebars.
foreach ( $results as $sidebar ) {
echo esc_html( $sidebar['name'] ) . ' : ' . esc_html( $sidebar['message'] ) . PHP_EOL . PHP_EOL;
// Loop widgets.
foreach ( $sidebar['widgets'] as $widget ) {
echo esc_html( $widget['name'] ) . ' - ' . esc_html( $widget['title'] ) . ' - ' . esc_html( $widget['message'] ) . PHP_EOL;
}
echo PHP_EOL;
}
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* Logger Class
*
* @package Revision
*/
/**
* Logger Class
*/
class CSCO_Logger extends CSCO_WPImporterLoggerCLI {
/**
* Variable for front-end error display.
*
* @var string
*/
public $error_output = '';
/**
* Overwritten log function from CSCO_WP_Importer_Logger_CLI.
*
* Logs with an arbitrary level.
*
* @param mixed $level level of reporting.
* @param string $message log message.
* @param array $context context to the log message.
*/
public function log( $level, $message, array $context = array() ) {
// Save error messages for front-end display.
$this->error_output( $level, $message, $context = array() );
if ( $this->level_to_numeric( $level ) < $this->level_to_numeric( $this->min_level ) ) {
return;
}
}
/**
* Save messages for error output.
* Only the messages greater then Error.
*
* @param mixed $level level of reporting.
* @param string $message log message.
* @param array $context context to the log message.
*/
public function error_output( $level, $message, array $context = array() ) {
if ( $this->level_to_numeric( $level ) < $this->level_to_numeric( 'error' ) ) {
return;
}
$this->error_output .= sprintf( '[%s] %s<br>', strtoupper( $level ), $message );
}
}

View File

@@ -0,0 +1,126 @@
<?php
/**
* Describes a logger instance
*
* Based on PSR-3: http://www.php-fig.org/psr/psr-3/
*
* The message MUST be a string or object implementing __toString().
*
* The message MAY contain placeholders in the form: {foo} where foo
* will be replaced by the context data in key "foo".
*
* The context array can contain arbitrary data, the only assumption that
* can be made by implementors is that if an Exception instance is given
* to produce a stack trace, it MUST be in a key named "exception".
*
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
* for the full interface specification.
*/
class CSCO_WPImporterLogger {
/**
* System is unusable.
*
* @param string $message The message.
* @param array $context The context.
*/
public function emergency( $message, array $context = array() ) {
return $this->log( 'emergency', $message, $context );
}
/**
* Action must be taken immediately.
*
* Example: Entire website down, database unavailable, etc. This should
* trigger the SMS alerts and wake you up.
*
* @param string $message The message.
* @param array $context The context.
*/
public function alert( $message, array $context = array() ) {
return $this->log( 'alert', $message, $context );
}
/**
* Critical conditions.
*
* Example: Application component unavailable, unexpected exception.
*
* @param string $message The message.
* @param array $context The context.
*/
public function critical( $message, array $context = array() ) {
return $this->log( 'critical', $message, $context );
}
/**
* Runtime errors that do not require immediate action but should typically
* be logged and monitored.
*
* @param string $message The message.
* @param array $context The context.
*/
public function error( $message, array $context = array() ) {
return $this->log( 'error', $message, $context );
}
/**
* Exceptional occurrences that are not errors.
*
* Example: Use of deprecated APIs, poor use of an API, undesirable things
* that are not necessarily wrong.
*
* @param string $message The message.
* @param array $context The context.
*/
public function warning( $message, array $context = array() ) {
return $this->log( 'warning', $message, $context );
}
/**
* Normal but significant events.
*
* @param string $message The message.
* @param array $context The context.
*/
public function notice( $message, array $context = array() ) {
return $this->log( 'notice', $message, $context );
}
/**
* Interesting events.
*
* Example: User logs in, SQL logs.
*
* @param string $message The message.
* @param array $context The context.
*/
public function info( $message, array $context = array() ) {
return $this->log( 'info', $message, $context );
}
/**
* Detailed debug information.
*
* @param string $message The message.
* @param array $context The context.
*/
public function debug( $message, array $context = array() ) {
return $this->log( 'debug', $message, $context );
}
/**
* Logs with an arbitrary level.
*
* @param mixed $level The level.
* @param string $message The message.
* @param array $context The context.
*/
public function log( $level, $message, array $context = array() ) {
$this->messages[] = array(
'timestamp' => time(),
'level' => $level,
'message' => $message,
'context' => $context,
);
}
}

View File

@@ -0,0 +1,47 @@
<?php
/**
* WP Importer Logger CLI Class
*
* @package Revision
*/
/**
* WP Importer Logger CLI Class
*/
class CSCO_WPImporterLoggerCLI extends CSCO_WPImporterLogger {
public $min_level = 'notice';
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string $message
* @param array $context
* @return null
*/
public function log( $level, $message, array $context = array() ) {
if ( $this->level_to_numeric( $level ) < $this->level_to_numeric( $this->min_level ) ) {
return;
}
call_user_func( 'printf', '[%s] %s' . PHP_EOL, strtoupper( $level ), $message );
}
public static function level_to_numeric( $level ) {
$levels = array(
'emergency' => 8,
'alert' => 7,
'critical' => 6,
'error' => 5,
'warning' => 4,
'notice' => 3,
'info' => 2,
'debug' => 1,
);
if ( ! isset( $levels[ $level ] ) ) {
return 0;
}
return $levels[ $level ];
}
}

View File

@@ -0,0 +1,20 @@
<?php
/**
* WP Importer Info Class
*/
/**
* WP Importer Info Class
*/
class CSCO_WXRImportInfo {
public $home;
public $siteurl;
public $title;
public $users = array();
public $post_count = 0;
public $media_count = 0;
public $comment_count = 0;
public $term_count = 0;
public $generator = '';
public $version;
}

File diff suppressed because it is too large Load Diff