Add gravity flow demo
This commit is contained in:
461
backend/wordpress/wp-content/plugins/view-admin-as/assets/css/view-admin-as.css
Executable file
461
backend/wordpress/wp-content/plugins/view-admin-as/assets/css/view-admin-as.css
Executable file
@@ -0,0 +1,461 @@
|
||||
/*!
|
||||
* View Admin As
|
||||
* https://wordpress.org/plugins/view-admin-as/
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.1
|
||||
* @version 1.8
|
||||
* @preserve
|
||||
*/
|
||||
|
||||
/**
|
||||
* Overlay
|
||||
*/
|
||||
.vaa-loader-icon {width: 96px; height: 96px; background: transparent url('../img/loader.gif') center center no-repeat; background-size: contain;}
|
||||
|
||||
#vaa-overlay {position: fixed; top: 0; left: 0; height: 100%; width: 100%; background: rgba(255,255,255,0.85); display: none; z-index: 999999999;}
|
||||
#vaa-overlay .vaa-loader-icon {position: fixed; top: 50%; left: 50%; margin: -48px 0 0 -48px; display: block;}
|
||||
|
||||
#vaa-overlay .vaa-popup {
|
||||
max-width: 75%;
|
||||
min-width: 50%;
|
||||
max-height: 50%;
|
||||
min-height: 20px;
|
||||
margin: 0 25%;
|
||||
padding: 10px;
|
||||
top: 10%;
|
||||
background: #fcfcfc;
|
||||
box-shadow: 0 1px 1px rgba(0,0,0,0.15), 0 0 1px 3px #fff;
|
||||
border: 2px solid #666;
|
||||
position: relative;
|
||||
}
|
||||
#vaa-overlay .vaa-popup > .remove {position: absolute; right: -10px; top: -10px; background: #FFF; width: 20px; height: 20px; cursor: pointer;}
|
||||
#vaa-overlay .vaa-popup .vaa-popup-content {overflow: hidden; overflow-y: auto;}
|
||||
#vaa-overlay .vaa-popup .vaa-popup-content ul li {margin-left: 20px; list-style: disc outside;}
|
||||
#vaa-overlay .vaa-popup .vaa-popup-content .button .icon {line-height: inherit; height: auto; width: auto;}
|
||||
#vaa-overlay .vaa-popup.vaa-message {border-color: #0075b3;}
|
||||
#vaa-overlay .vaa-popup.vaa-warning {border-color: #C8730C;}
|
||||
#vaa-overlay .vaa-popup.vaa-error {border-color: #dc3232;}
|
||||
#vaa-overlay .vaa-popup.vaa-success {border-color: #46b450;}
|
||||
|
||||
/**
|
||||
* Notices
|
||||
*/
|
||||
#wpadminbar .vaa-notice {display: inline-block; padding: 0 5px 0 10px; background: #fff;}
|
||||
#wpadminbar .vaa-notice.vaa-message,
|
||||
#wpadminbar .vaa-notice.vaa-message .ab-icon:before {color: #0075B3 !important;}
|
||||
#wpadminbar .vaa-notice.vaa-warning,
|
||||
#wpadminbar .vaa-notice.vaa-warning .ab-icon:before {color: #C8730C !important;}
|
||||
#wpadminbar .vaa-notice.vaa-error,
|
||||
#wpadminbar .vaa-notice.vaa-error .ab-icon:before {color: #dc3232 !important;}
|
||||
#wpadminbar .vaa-notice.vaa-success,
|
||||
#wpadminbar .vaa-notice.vaa-success .ab-icon:before {color: #46b450 !important;}
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-notice {display: block; clear: both; margin-bottom: 3px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-notice button {vertical-align: baseline; margin: 0 0 0 -5px; padding: 1px 10px;}
|
||||
|
||||
#wpadminbar .vaa-notice .remove,
|
||||
#wpadminbar #wp-admin-bar-vaa .remove {cursor: pointer; top: 2px; float: right; margin-right: 0; margin-left: 6px;}
|
||||
|
||||
/**
|
||||
* General
|
||||
*/
|
||||
#wpadminbar #wp-admin-bar-vaa ul li,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item {clear: both; z-index: auto;}
|
||||
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper .ab-item > span {line-height: 26px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item > span.remove {font-size: 16px; line-height: 16px; top: 1px;}
|
||||
|
||||
#wpadminbar #wp-admin-bar-vaa b,
|
||||
#wpadminbar #wp-admin-bar-vaa strong,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item.ab-bold,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item .ab-bold,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-bold > .ab-item,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-bold > .ab-item * {font-weight: bold !important;}
|
||||
#wpadminbar #wp-admin-bar-vaa i,
|
||||
#wpadminbar #wp-admin-bar-vaa em,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item.ab-italic,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item .ab-italic,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-italic > .ab-item,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-italic > .ab-item * {font-style: italic !important;}
|
||||
|
||||
#wpadminbar #wp-admin-bar-vaa code {font-family: Consolas, Monaco, monospace; background: rgba(0,0,0,0.1); padding: 1px 5px 2px; line-height: normal;}
|
||||
|
||||
/* Semi transparent groups */
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-sub-transparent > * {opacity: 0.5; transition: opacity 0.2s;}
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-sub-transparent:hover > *,
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-sub-transparent .active,
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-sub-transparent .active ~ * {opacity: 1;}
|
||||
|
||||
/* Search results */
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-results {margin: 6px 0; padding: 0;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-results.vaa-auto-max-height {margin-right: 10px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-results:empty {display: none;}
|
||||
|
||||
/* Spacing for first level sub groups */
|
||||
#wpadminbar #wp-admin-bar-vaa ul.ab-sub-secondary + ul.ab-sub-secondary {margin-top: 3px;}
|
||||
/* Spacing for second level sub groups and lower */
|
||||
#wpadminbar #wp-admin-bar-vaa .menupop ul + ul,
|
||||
#wpadminbar #wp-admin-bar-vaa .menupop ul.ab-sub-secondary + ul.ab-sub-secondary {margin-top: 2px;}
|
||||
/* Spacing for third level sub groups and lower */
|
||||
#wpadminbar #wp-admin-bar-vaa .menupop .menupop ul + ul,
|
||||
#wpadminbar #wp-admin-bar-vaa .menupop .menupop ul.ab-sub-secondary + ul.ab-sub-secondary {margin-top: 1px;}
|
||||
/* Remove unneeded spacing */
|
||||
#wpadminbar #wp-admin-bar-vaa ul:not(.ab-sub-secondary) + ul.ab-sub-secondary,
|
||||
#wpadminbar #wp-admin-bar-vaa ul.ab-sub-secondary + ul:not(.ab-sub-secondary) {margin-top: 0;}
|
||||
|
||||
/* Toggle groups */
|
||||
#wpadminbar #wp-admin-bar-vaa .menupop .ab-sub-wrapper ul.vaa-toggle-group {padding: 3px 0 4px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .menupop .ab-sub-wrapper ul.vaa-toggle-group li.active ~ li:last-child {padding-bottom: 3px;}
|
||||
|
||||
/* Auto height */
|
||||
#wpadminbar #wp-admin-bar-vaa .auto-height > .ab-item {height: auto;}
|
||||
|
||||
/* Descriptions */
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item .description {height: auto; line-height: 1.2; font-size: 0.8em; font-style: italic; margin-bottom: 7px; white-space: normal; color: inherit;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item .description:first-child:not(:only-child) {margin-bottom: 0;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item .description .ab-icon {line-height: 1 !important; font-size: 1em !important; padding: 1px 0; margin-right: 3px; width: auto; height: 1em;}
|
||||
|
||||
/* First level group titles */
|
||||
#wpadminbar #wp-admin-bar-vaa.menupop .ab-vaa-title > .ab-item {font-weight: bold; line-height: 26px; font-size: 1.1em; text-transform: uppercase;}
|
||||
|
||||
/* Current view items */
|
||||
#wpadminbar #wp-admin-bar-vaa .current > .ab-item,
|
||||
#wpadminbar #wp-admin-bar-vaa .current > .ab-item .vaa-view-data,
|
||||
#wpadminbar #wp-admin-bar-vaa .current > input:checked + label,
|
||||
#wpadminbar #wp-admin-bar-vaa .current-parent > .ab-item,
|
||||
#wpadminbar #wp-admin-bar-vaa .current-parent > .ab-item .vaa-view-data,
|
||||
#wpadminbar #wp-admin-bar-vaa .current-parent > label {font-weight: bold;}
|
||||
#wpadminbar #wp-admin-bar-vaa .current > .ab-item::after,
|
||||
#wpadminbar #wp-admin-bar-vaa .current > label::after {content: '\f177'; font-family: 'dashicons'; margin: 0 5px; font-size: 17px; vertical-align: middle; font-weight: normal;}
|
||||
#wpadminbar #wp-admin-bar-vaa .current.ab-vaa-title > .ab-item::after {vertical-align: top;}
|
||||
|
||||
/**
|
||||
* Icon fixes
|
||||
*/
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item .ab-icon.alignright {float: right; margin-right: 0; margin-left: 6px;}
|
||||
#wpadminbar #wp-admin-bar-vaa > .ab-item .ab-icon {top: 2px;}
|
||||
#wpadminbar #wp-admin-bar-vaa > .ab-item .ab-label {float: left;} /* IE fix */
|
||||
#wpadminbar #wp-admin-bar-vaa > .ab-item .ab-label .ab-icon {margin-right: -3px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-icon.vaa-icon-image {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
background-size: 100% auto !important;
|
||||
background: center left no-repeat;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
#wpadminbar > #wp-toolbar > #wp-admin-bar-root-default #wp-admin-bar-vaa .vaa-has-icon > .ab-item > .ab-icon, /* Fix when located on admin bar default */
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-has-icon > .ab-item .ab-icon {
|
||||
float: none;
|
||||
font-weight: normal !important;
|
||||
font-size: 16px;
|
||||
line-height: 16px;
|
||||
vertical-align: text-bottom;
|
||||
padding: 0;
|
||||
}
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-has-icon > .ab-item::before {display: none;}
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-has-icon.menupop > .ab-item {padding-left: 10px; padding-right: 10px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-has-icon.ab-vaa-title > .ab-item > .ab-icon {font-size: 18px; line-height: 20px; margin: 0 5px 0 -1px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-has-icon.ab-vaa-title > .ab-item > .ab-icon.vaa-icon-image {width: 18px; height: 18px;}
|
||||
|
||||
/* Subgroups with icons */
|
||||
#wpadminbar .ab-top-secondary .menupop .vaa-menupop > .ab-item {padding-left: 2em; padding-right: 1em;}
|
||||
#wpadminbar .ab-top-secondary .menupop .vaa-menupop > .ab-item .ab-icon {margin-left: -20px; margin-right: 4px;}
|
||||
|
||||
#wpadminbar #wp-admin-bar-vaa.menupop ul.ab-sub-secondary {position: static;}
|
||||
#wpadminbar #wp-admin-bar-vaa.menupop .menupop > .ab-item:before {top: 1px;}
|
||||
|
||||
#wpadminbar #vaa-combine-views-selection .ab-item {padding-right: 28px;}
|
||||
#wpadminbar #vaa-combine-views-selection .ab-item .remove {position: absolute; right: 4px;}
|
||||
|
||||
/**
|
||||
* Buttons
|
||||
*/
|
||||
#wpadminbar #wp-admin-bar-vaa button > .ab-icon {margin: 0 5px 0 -5px; padding: 0; top: 0;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item > label + button {margin: 0 0 0 12px; vertical-align: baseline;}
|
||||
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-button-container > .ab-item {overflow: hidden; height: auto;}
|
||||
#wpadminbar #wp-admin-bar-vaa button {
|
||||
float: none;
|
||||
text-decoration: none;
|
||||
font-size: 13px;
|
||||
line-height: 20px;
|
||||
height: 20px;
|
||||
margin: 3px 0;
|
||||
padding: 0 10px 1px;
|
||||
vertical-align: middle;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Button icon fixes
|
||||
*/
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-icon {padding: 0 2px 1px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-icon .ab-icon {margin: 0;}
|
||||
#wpadminbar #wp-admin-bar-vaa button.vaa-icon .ab-icon {padding: 0;}
|
||||
|
||||
/**
|
||||
* Help tooltips
|
||||
*/
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-tooltip {
|
||||
position: absolute !important;
|
||||
display: none;
|
||||
opacity: 0;
|
||||
transition: all .2s;
|
||||
right: 12px;
|
||||
top: 0;
|
||||
padding: 10px 15px;
|
||||
width: 140px;
|
||||
height: auto;
|
||||
font-size: 11px;
|
||||
line-height: 1.2em;
|
||||
text-align: center;
|
||||
white-space: normal;
|
||||
border-radius: 3px;
|
||||
border: 1px solid rgba(175,175,175,0.5);
|
||||
box-shadow: 0 0 15px rgba(0,0,0,0.2);
|
||||
z-index: 99999;
|
||||
}
|
||||
#wpadminbar > #wp-toolbar > #wp-admin-bar-root-default #wp-admin-bar-vaa .vaa-help, /* Fix when located on admin bar default */
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-help {
|
||||
float: right;
|
||||
text-align: right;
|
||||
padding: 0;
|
||||
font-size: 16px;
|
||||
line-height: inherit !important;
|
||||
margin: 0 0 0 5px
|
||||
}
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-help ~ label + select,
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-help ~ label + input,
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-help ~ input + label {margin-right: 20px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-help:hover {cursor: help;}
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-help:hover .vaa-tooltip {display: inline-block; opacity: 1;}
|
||||
|
||||
/**
|
||||
* Auto max height
|
||||
* Min height = height of a single node
|
||||
*/
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-auto-max-height {min-height: 26px; overflow-y: auto; transition: max-height .3s;}
|
||||
|
||||
/**
|
||||
* Form elements
|
||||
*/
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect .ab-item,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-input .ab-item,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-file .ab-item,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-search .ab-item,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-filter .ab-item,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item {height: auto; clear: both;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-input .ab-item input,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-file .ab-item input,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-search .ab-item input,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-filter .ab-item input,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item select {display: inline-block; background: #fff; color: #555; margin: 5px 0; padding: 3px; border: 0; line-height: normal; height: auto; width: 100%; box-sizing: border-box;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item select {padding: 2px 3px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item label + input,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item label + select {margin-top: 0;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-textarea .ab-item {height: auto; line-height: normal;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-textarea .ab-item textarea {width: 100%; padding: 5px; margin-top: 5px; box-sizing: border-box; line-height: normal;}
|
||||
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item select + button.input-overlay,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item input + button.input-overlay {position: absolute; right: 10px; margin: 5px 0;}
|
||||
|
||||
#wpadminbar #wp-admin-bar-vaa input.checkbox,
|
||||
#wpadminbar #wp-admin-bar-vaa input.radio {display: inline-block; height: 16px; width: 16px; vertical-align: text-bottom; box-sizing: border-box; cursor: pointer;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item input.checkbox,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item input.radio {margin: 0 6px 0 0;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item input.radio {border-radius: 100%;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item input.checkbox + label,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item input.checkbox + label *,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item input.radio + label,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item input.radio + label * {line-height: 18px; vertical-align: text-top; display: inline-block;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item input.checkbox + label:hover,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item input.radio + label:hover {cursor: pointer;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item input.radio + label + br {line-height: 0;}
|
||||
|
||||
#wpadminbar #wp-admin-bar-vaa input.checkbox.vaa-right,
|
||||
#wpadminbar #wp-admin-bar-vaa input.radio.vaa-right {position: absolute; top: 5px; right: 1em; z-index: 99;}
|
||||
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item .vaa-radio-wrapper {line-height: 20px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item .vaa-radio-wrapper p.description,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item .vaa-radio-wrapper:first-of-type {margin-top: 6px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item .vaa-radio-wrapper:last-of-type {margin-bottom: 6px;}
|
||||
|
||||
/* Multipleselect */
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect {max-height: 400px; min-width: 250px; overflow: hidden; overflow-y: auto; margin: 6px 0; padding: 0; border: solid transparent; border-width: 0 10px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect .ab-empty-item {height: auto; overflow: hidden; margin: 0; padding: 5px 10px; background-color: #fff;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect .ab-empty-item .ab-item {color: #333;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect.vaa-small {max-height: 100px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect .remove:before {color: #333;}
|
||||
|
||||
/**
|
||||
* Node columns
|
||||
*/
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-column-one-half {width: 50%; display: block; float: left; clear: none;}
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-column-one-half .ab-item {min-width: 0;}
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-column-one-half.vaa-column-first .ab-item {padding-right: 1px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-column-one-half.vaa-column-last .ab-item {padding-left: 1px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-clear-float {clear: both;}
|
||||
|
||||
/**
|
||||
* Toggle
|
||||
*/
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle > .ab-item {padding-right: 34px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle > .ab-item:hover {cursor: pointer;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle > .ab-item::after {content: "\f140"; font-family: 'dashicons'; position: absolute; right: 10px; margin: 0; font-size: 20px; font-weight: normal;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle.active > .ab-item::after {content: "\f142";}
|
||||
|
||||
/**
|
||||
* Full width view
|
||||
*/
|
||||
#wpadminbar #wp-admin-bar-vaa.fullPopupActive .ab-sub-wrapper,
|
||||
#wpadminbar #wp-admin-bar-vaa.fullPopupActive .ab-sub-wrapper .ab-item {display: none;}
|
||||
#wpadminbar #wp-admin-bar-vaa.fullPopupActive > .ab-sub-wrapper {display: block;}
|
||||
#wpadminbar #wp-admin-bar-vaa.fullPopupActive > .ab-sub-wrapper > .ab-submenu {padding: 0;}
|
||||
#wpadminbar #wp-admin-bar-vaa.fullPopupActive .ab-sub-wrapper.fullPopup {position: fixed; display: block; visibility: visible; overflow: hidden; z-index: 999; max-height: 90%; width: 90%; margin: 5%; top: 0; left: 0; box-shadow: 0 0 50px rgba(0,0,0,0.3);}
|
||||
#wpadminbar #wp-admin-bar-vaa.fullPopupActive .ab-sub-wrapper.fullPopup .ab-item {display: block;}
|
||||
#wpadminbar #wp-admin-bar-vaa.fullPopupActive .ab-sub-wrapper.fullPopup > ul::after {display: table; clear: both; content: ' ';}
|
||||
|
||||
/* Capability nodes */
|
||||
#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #apply-caps-view {float: left; margin-right: 5px;}
|
||||
#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #reset-caps-view,
|
||||
#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #open-caps-popup,
|
||||
#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #close-caps-popup {float: right; margin-left: 5px; height: auto;}
|
||||
#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #close-caps-popup {display: none;}
|
||||
#wpadminbar #wp-admin-bar-vaa.fullPopupActive #wp-admin-bar-vaa-caps .ab-sub-wrapper.fullPopup #close-caps-popup {display: block;}
|
||||
#wpadminbar #wp-admin-bar-vaa.fullPopupActive #wp-admin-bar-vaa-caps .ab-sub-wrapper.fullPopup #open-caps-popup {display: none;}
|
||||
#wpadminbar #wp-admin-bar-vaa.fullPopupActive #wp-admin-bar-vaa-caps .ab-sub-wrapper.fullPopup #wp-admin-bar-vaa-caps-select-options .vaa-cap-item {width: 250px; float: left; clear: none;}
|
||||
#wpadminbar #wp-admin-bar-vaa.fullPopupActive #wp-admin-bar-vaa-caps .ab-sub-wrapper.fullPopup #wp-admin-bar-vaa-caps-select-options .vaa-cap-item .remove {margin-right: 6px;}
|
||||
|
||||
#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps-popup:hover {cursor: pointer;}
|
||||
|
||||
/**
|
||||
* Location: My Account
|
||||
*/
|
||||
#wpadminbar #wp-admin-bar-my-account-default {z-index: 999999;} /* Box shadow fix */
|
||||
#wpadminbar #wp-admin-bar-my-account #wp-admin-bar-vaa > .ab-item .ab-label {line-height: 26px;}
|
||||
#wpadminbar #wp-admin-bar-my-account #wp-admin-bar-vaa > .ab-item .ab-icon {top: 0;}
|
||||
|
||||
/**
|
||||
* Custom VAA toolbar
|
||||
*/
|
||||
#vaa_toolbar #wpadminbar {position: fixed !important; width: auto; min-width: 0; right: 0; left: auto; border-radius: 0 0 0 5px;}
|
||||
#vaa_toolbar #wpadminbar #wp-admin-bar-vaa > .ab-item .ab-icon {margin-left: 0;}
|
||||
#vaa_toolbar #wpadminbar #wp-admin-bar-vaa > .ab-item .ab-label {display: none;}
|
||||
#vaa_toolbar #wpadminbar #wp-admin-bar-vaa:hover > .ab-item .ab-icon {margin-left: 6px;}
|
||||
#vaa_toolbar #wpadminbar #wp-admin-bar-vaa:hover > .ab-item .ab-label {display: inline-block;}
|
||||
|
||||
/**
|
||||
* Responsive
|
||||
*/
|
||||
@media screen and (min-width: 783px) {
|
||||
/* Full popup form elements */
|
||||
#wpadminbar #wp-admin-bar-vaa.fullPopupActive .ab-sub-wrapper.fullPopup ul {overflow: hidden;}
|
||||
#wpadminbar #wp-admin-bar-vaa.fullPopupActive .ab-sub-wrapper.fullPopup ul li.ab-vaa-input,
|
||||
#wpadminbar #wp-admin-bar-vaa.fullPopupActive .ab-sub-wrapper.fullPopup ul li.ab-vaa-select {float: left; clear: none; width: auto;}
|
||||
#wpadminbar #wp-admin-bar-vaa.fullPopupActive .ab-sub-wrapper.fullPopup ul li.ab-vaa-input button {margin: 5px 0;}
|
||||
#wpadminbar #wp-admin-bar-vaa.fullPopupActive .ab-sub-wrapper.fullPopup ul li.ab-vaa-input input,
|
||||
#wpadminbar #wp-admin-bar-vaa.fullPopupActive .ab-sub-wrapper.fullPopup ul li.ab-vaa-select select {width: auto;}
|
||||
#wpadminbar #wp-admin-bar-vaa.fullPopupActive .ab-sub-wrapper.fullPopup ul li.ab-vaa-input input + button.input-overlay,
|
||||
#wpadminbar #wp-admin-bar-vaa.fullPopupActive .ab-sub-wrapper.fullPopup ul li.ab-vaa-select select + button.input-overlay {position: static; vertical-align: top;}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 782px) {
|
||||
|
||||
/**
|
||||
* General
|
||||
*/
|
||||
#wpadminbar #wp-admin-bar-vaa {display: block; position: static;}
|
||||
#wpadminbar #wp-admin-bar-vaa > .ab-item > .ab-icon {margin-left: 0;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper {width: 100%;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper .ab-sub-wrapper {position: static; top: auto; margin: 0; -webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none;}
|
||||
|
||||
#wpadminbar #wp-admin-bar-vaa.menupop .menupop > .ab-item:before {content: '';}
|
||||
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item .vaa-hide-responsive {display: none;}
|
||||
|
||||
#wpadminbar #wp-admin-bar-vaa .menupop > .ab-sub-wrapper .ab-item.description,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item p.description {display: block !important; padding-left: 0; padding-right: 0; margin-bottom: 0;}
|
||||
|
||||
/**
|
||||
* Help tooltip
|
||||
*/
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-help {display: block; padding: 8px 0; float: none; text-align: left; margin: 0;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item .vaa-help:empty {display: none;}
|
||||
/* Always display tooltip on mobile view. */
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-tooltip {
|
||||
font-size: 13px;
|
||||
display: inline-block;
|
||||
position: static !important;
|
||||
opacity: 1;
|
||||
border: 0;
|
||||
padding: 0 !important;
|
||||
margin-left: 5px !important;
|
||||
width: auto;
|
||||
vertical-align: text-top;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notices
|
||||
*/
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-notice {line-height: 42px; font-size: 16px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-notice .ab-icon {height: auto;}
|
||||
|
||||
#wpadminbar #wp-admin-bar-vaa > div > ul,
|
||||
#wpadminbar #wp-admin-bar-vaa .menupop > .ab-sub-wrapper .ab-submenu {padding: 5px 0;}
|
||||
#wpadminbar #wp-admin-bar-vaa .menupop > .ab-sub-wrapper .ab-item {padding: 8px 44px; white-space: normal; height: auto;}
|
||||
#wpadminbar #wp-admin-bar-vaa .menupop > .ab-sub-wrapper .ab-item > .ab-item {padding: 8px 0;}
|
||||
#wpadminbar #wp-admin-bar-vaa .menupop > .ab-sub-wrapper:last-child .ab-item.description {margin-bottom: 0;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item > span.remove,
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-has-icon .ab-item .ab-icon {width: auto; height: auto; font-size: 22px !important; margin-right: 10px; vertical-align: text-top;}
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-has-icon .ab-item .ab-icon.vaa-icon-image {width: 22px; height: 22px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-title.vaa-has-icon > .ab-item > .ab-icon {font-size: 30px !important; margin-left: -6px; margin-top: -1px; vertical-align: top;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-title.vaa-has-icon > .ab-item > .ab-icon.vaa-icon-image {width: 30px; height: 30px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-has-icon.menupop > .ab-item {padding-left: 12px; padding-right: 12px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-title.vaa-has-icon.menupop > .ab-item {padding-left: 16px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .vaa-menupop div li {margin-left: 12px;}
|
||||
|
||||
/**
|
||||
* Icon fixes
|
||||
*/
|
||||
#wpadminbar #vaa-combine-views-selection .ab-item {padding-right: 48px;}
|
||||
#wpadminbar #vaa-combine-views-selection .ab-item > span.remove {margin-right: 0; padding: 10px; top: 0; right: 0;}
|
||||
|
||||
/**
|
||||
* Toggle
|
||||
*/
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper .vaa-role-item.menupop > .ab-item {padding-left: 15px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle > .ab-item::after,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper .vaa-menupop.menupop > .ab-item:after {content: "\f140"; font-family: 'dashicons'; position: absolute; right: 10px; top: 8px; margin: 0; font-size: 30px; font-weight: normal;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle.active > .ab-item::after,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper .vaa-menupop.menupop.active > .ab-item:after {content: "\f142";}
|
||||
|
||||
/**
|
||||
* Form elements
|
||||
*/
|
||||
#wpadminbar #wp-admin-bar-vaa button {font-size: 16px; padding: 5px 15px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-input .ab-item input,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-search .ab-item input,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-filter .ab-item input {padding: 8px 12px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item select {padding: 7px 12px;}
|
||||
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item select + button.input-overlay,
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item input + button.input-overlay {right: 44px; padding: 6px 10px 7px; font-size: 14px;}
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect {border-width: 0 44px; max-height: 300px !important;}
|
||||
#wpadminbar #wp-admin-bar-vaa .menupop > .ab-sub-wrapper .ab-vaa-multipleselect > .ab-item {padding: 8px 16px;}
|
||||
|
||||
#wpadminbar #wp-admin-bar-vaa input.checkbox,
|
||||
#wpadminbar #wp-admin-bar-vaa input.radio {width: 24px; height: 24px;}
|
||||
|
||||
#wpadminbar #wp-admin-bar-vaa input.checkbox.vaa-right,
|
||||
#wpadminbar #wp-admin-bar-vaa input.radio.vaa-right {top: 9px; right: 11px;}
|
||||
|
||||
#wpadminbar #wp-admin-bar-vaa .ab-item .vaa-radio-wrapper {margin: 6px 0;}
|
||||
|
||||
/**
|
||||
* Custom VAA toolbar
|
||||
*/
|
||||
#vaa_toolbar {display: none !important;}
|
||||
}
|
||||
11
backend/wordpress/wp-content/plugins/view-admin-as/assets/css/view-admin-as.min.css
vendored
Executable file
11
backend/wordpress/wp-content/plugins/view-admin-as/assets/css/view-admin-as.min.css
vendored
Executable file
File diff suppressed because one or more lines are too long
BIN
backend/wordpress/wp-content/plugins/view-admin-as/assets/img/loader.gif
Executable file
BIN
backend/wordpress/wp-content/plugins/view-admin-as/assets/img/loader.gif
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
1860
backend/wordpress/wp-content/plugins/view-admin-as/assets/js/view-admin-as.js
Executable file
1860
backend/wordpress/wp-content/plugins/view-admin-as/assets/js/view-admin-as.js
Executable file
File diff suppressed because it is too large
Load Diff
11
backend/wordpress/wp-content/plugins/view-admin-as/assets/js/view-admin-as.min.js
vendored
Executable file
11
backend/wordpress/wp-content/plugins/view-admin-as/assets/js/view-admin-as.min.js
vendored
Executable file
File diff suppressed because one or more lines are too long
917
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-api.php
Executable file
917
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-api.php
Executable file
@@ -0,0 +1,917 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Class API
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* API class that holds general functions.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.6
|
||||
* @version 1.8
|
||||
*/
|
||||
final class VAA_API
|
||||
{
|
||||
/**
|
||||
* Check if a user has full access to this plugin.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param \WP_User|int $user The user to check.
|
||||
* @return bool
|
||||
*/
|
||||
public static function user_has_full_access( $user ) {
|
||||
if ( ! $user instanceof WP_User ) {
|
||||
$user = get_user_by( 'ID', $user );
|
||||
if ( ! $user ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( is_multisite() ) {
|
||||
return is_super_admin( $user->ID );
|
||||
}
|
||||
|
||||
/**
|
||||
* For single installations is_super_admin() isn't enough since it only checks for `delete_users`.
|
||||
* @since 1.7.6
|
||||
* @link https://wordpress.org/support/topic/required-capabilities-2/
|
||||
*/
|
||||
$caps = array(
|
||||
'edit_users',
|
||||
'delete_plugins',
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter the capabilities required to gain full access to this plugin.
|
||||
* Note: Single site only!
|
||||
* Note: is_super_admin() is always checked!
|
||||
*
|
||||
* @since 1.8
|
||||
* @param array $caps The default capabilities.
|
||||
* @param \WP_User $user The user that is being validated.
|
||||
* @return array
|
||||
*/
|
||||
$caps = apply_filters( 'view_admin_as_full_access_capabilities', $caps, $user );
|
||||
|
||||
foreach ( $caps as $cap ) {
|
||||
if ( ! $user->has_cap( $cap ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return is_super_admin( $user->ID );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the user is a super admin.
|
||||
* This check is more strict for single installations since it checks VAA_API::user_has_full_access.
|
||||
* It will validate the original user while in a view and no parameter is passed.
|
||||
*
|
||||
* @see \VAA_API::user_has_full_access()
|
||||
* @see \VAA_View_Admin_As_Store::cur_user_has_full_access()
|
||||
*
|
||||
* @since 1.6.3
|
||||
* @since 1.8 Check full access.
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param int|\WP_User $user (optional) Default: current user.
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_super_admin( $user = null ) {
|
||||
if ( null === $user || view_admin_as()->store()->is_curUser( $user ) ) {
|
||||
return view_admin_as()->store()->cur_user_has_full_access();
|
||||
}
|
||||
|
||||
return self::user_has_full_access( $user );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the user is a superior admin.
|
||||
* It will validate the original user while in a view and no parameter is passed.
|
||||
*
|
||||
* @since 1.5.3
|
||||
* @since 1.6 Moved to this class from main class
|
||||
* @since 1.6.3 Improve is_super_admin() check
|
||||
* @since 1.8 Enhance code to reflect VAA_API::is_super_admin() changes.
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param int|\WP_User $user_id (optional) Default: current user.
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_superior_admin( $user_id = null ) {
|
||||
|
||||
// If it's the current user or null, don't pass the user ID to make sure we check the original user status.
|
||||
$is_super_admin = self::is_super_admin(
|
||||
( null !== $user_id && view_admin_as()->store()->is_curUser( $user_id ) ) ? null : $user_id
|
||||
);
|
||||
|
||||
// Full access is required.
|
||||
if ( ! $is_super_admin ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( null === $user_id ) {
|
||||
$user_id = view_admin_as()->store()->get_originalUserData( 'ID' );
|
||||
} elseif ( $user_id instanceof WP_User ) {
|
||||
$user_id = $user_id->ID;
|
||||
}
|
||||
|
||||
// Is it one of the manually configured superior admins?
|
||||
return (bool) ( in_array( (int) $user_id, self::get_superior_admins(), true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the superior admin ID's (filter since 1.5.2)
|
||||
*
|
||||
* @since 1.5.3
|
||||
* @since 1.6 Moved to this class from main class
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_superior_admins() {
|
||||
static $superior_admins;
|
||||
if ( ! is_null( $superior_admins ) ) return $superior_admins;
|
||||
|
||||
/**
|
||||
* Grant admins the capability to view other admins. There is no UI for this!
|
||||
*
|
||||
* @since 1.5.2
|
||||
* @param array
|
||||
* @return int[] Requires a returned array of user ID's
|
||||
*/
|
||||
$superior_admins = array_unique( array_map( 'absint', array_filter(
|
||||
(array) apply_filters( 'view_admin_as_superior_admins', array() ),
|
||||
'is_numeric' // Only allow numeric values (user id's)
|
||||
) ) );
|
||||
|
||||
return $superior_admins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the provided data is the same as the current view.
|
||||
*
|
||||
* @see \VAA_View_Admin_As_Controller::is_current_view()
|
||||
*
|
||||
* @since 1.7.1
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param bool $type Only compare a single view type instead of all view data?
|
||||
* If set, the data value should be the single view type data.
|
||||
* If data is `null` then it will return true if that view type is active.
|
||||
* If data is `false` then it will return true if this is the only active view type.
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_current_view( $data, $type = null ) {
|
||||
$controller = view_admin_as()->controller();
|
||||
if ( $controller ) {
|
||||
return $controller->is_current_view( $data, $type );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar function to current_user_can().
|
||||
*
|
||||
* @see \VAA_View_Admin_As_View::current_view_can()
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param string $cap The capability.
|
||||
* @param array $caps (optional) Capabilities to compare to.
|
||||
* Defaults to the selected caps for the current view.
|
||||
* @return bool
|
||||
*/
|
||||
public static function current_view_can( $cap, $caps = array() ) {
|
||||
$view = view_admin_as()->view();
|
||||
if ( $view ) {
|
||||
return $view->current_view_can( $cap, $caps );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the current user modified?
|
||||
*
|
||||
* @see \VAA_View_Admin_As_View::current_view_can()
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_user_modified() {
|
||||
$view = view_admin_as()->view();
|
||||
if ( $view ) {
|
||||
return $view->is_user_modified();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is any toolbar showing?
|
||||
* Do not use this before the `init` hook.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_toolbar_showing() {
|
||||
|
||||
if ( is_admin_bar_showing() || self::is_vaa_toolbar_showing() ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is our custom toolbar showing?
|
||||
* Do not use this before the `init` hook.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_vaa_toolbar_showing() {
|
||||
|
||||
if ( class_exists( 'VAA_View_Admin_As_Toolbar' ) ) {
|
||||
return (bool) VAA_View_Admin_As_Toolbar::$showing;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the customizer admin container currently rendering?
|
||||
*
|
||||
* @since 1.7.6
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_customizer_admin() {
|
||||
|
||||
if ( is_customize_preview() && is_admin() ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a view type is enabled. Pass an array to check multiple view types.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param string|array $type The view type key.
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_view_type_enabled( $type ) {
|
||||
$type = view_admin_as()->get_view_types( $type );
|
||||
if ( is_array( $type ) ) {
|
||||
foreach ( $type as $view_type ) {
|
||||
if ( ! $view_type instanceof VAA_View_Admin_As_Type || ! $view_type->is_enabled() ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if ( $type instanceof VAA_View_Admin_As_Type ) {
|
||||
return $type->is_enabled();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a VAA action link.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param array $data View type data.
|
||||
* @param string $nonce The nonce.
|
||||
* @param string $url (optional) A URL. Of not passed it will generate a link from the current URL.
|
||||
* @return string
|
||||
*/
|
||||
public static function get_vaa_action_link( $data, $nonce, $url = null ) {
|
||||
|
||||
$params = array(
|
||||
'action' => 'view_admin_as',
|
||||
'view_admin_as' => $data, // wp_json_encode( array( $type, $data ) ),
|
||||
'_vaa_nonce' => (string) $nonce,
|
||||
);
|
||||
|
||||
// @todo fix WP referrer/nonce checks and allow switching on any page without ajax.
|
||||
// @see https://codex.wordpress.org/Function_Reference/check_admin_referer
|
||||
if ( empty( $url ) ) {
|
||||
if ( is_admin() ) {
|
||||
$url = is_network_admin() ? network_admin_url() : admin_url();
|
||||
} else {
|
||||
// Since 1.7.5 Frontend url.
|
||||
$url = get_site_url();
|
||||
}
|
||||
}
|
||||
|
||||
$url = add_query_arg( $params, ( $url ) ? $url : false );
|
||||
|
||||
return esc_url( $url, array( 'http', 'https' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the "reset-view" parameter to the current URL.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param string $url (optional) Use a defined url create the reset link.
|
||||
* @param bool $all (optional) Reset all views link?
|
||||
* @return string
|
||||
*/
|
||||
public static function get_reset_link( $url = null, $all = false ) {
|
||||
$params = 'reset-view';
|
||||
if ( $all ) {
|
||||
$params = 'reset-all-views';
|
||||
}
|
||||
$url = add_query_arg( $params, '', ( $url ) ? $url : false );
|
||||
return esc_url( $url, array( 'http', 'https' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the "reset-view" or "reset-all-views" parameter to the current URL.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param string $url (optional) Use a defined url to remove the reset link.
|
||||
* @return string
|
||||
*/
|
||||
public static function remove_reset_link( $url = '' ) {
|
||||
$url = remove_query_arg( array( 'reset-view', 'reset-all-views' ), ( $url ) ? $url : false );
|
||||
return esc_url( $url, array( 'http', 'https' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get full array or array key(s).
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.7.5 Option to pass an array of keys. Will always return an array (even if not found) + third require_all option.
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param array $array The requested array.
|
||||
* @param string|array $key (optional) Return only a key of the requested array.
|
||||
* @param bool $require_all (optional) In case of an array of keys, return `null` if not all keys are present?
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get_array_data( $array, $key = null, $require_all = false ) {
|
||||
if ( null !== $key ) {
|
||||
if ( ! is_array( $array ) ) {
|
||||
return null;
|
||||
}
|
||||
// @since 1.7.5 Search for multiple keys.
|
||||
if ( is_array( $key ) ) {
|
||||
$return = array();
|
||||
foreach ( $key as $k ) {
|
||||
if ( isset( $array[ $k ] ) ) {
|
||||
$return[ $k ] = $array[ $k ];
|
||||
}
|
||||
}
|
||||
if ( $require_all && array_diff_key( array_flip( $key ), $return ) ) {
|
||||
return null;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
if ( isset( $array[ $key ] ) ) {
|
||||
return $array[ $key ];
|
||||
}
|
||||
return null; // return null if key is not found
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set full array or array key.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param array $array Original array.
|
||||
* @param mixed $var The new value.
|
||||
* @param string $key (optional) The array key for the value.
|
||||
* @param bool $append (optional) If the key doesn't exist in the original array, append it.
|
||||
* @return mixed
|
||||
*/
|
||||
public static function set_array_data( $array, $var, $key = null, $append = false ) {
|
||||
if ( null !== $key ) {
|
||||
if ( true === $append && ! is_array( $array ) ) {
|
||||
$array = array();
|
||||
}
|
||||
if ( is_array( $array ) && ( true === $append || isset( $array[ $key ] ) ) ) {
|
||||
$array[ $key ] = $var;
|
||||
return $array;
|
||||
}
|
||||
|
||||
// Notify user if in debug mode
|
||||
_doing_it_wrong(
|
||||
__METHOD__,
|
||||
'View Admin As: Key <code>' . (string) $key . '</code> does not exist',
|
||||
null
|
||||
);
|
||||
|
||||
// return no changes if key is not found or appending is not allowed.
|
||||
return $array;
|
||||
}
|
||||
return $var;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if two arrays are the same.
|
||||
* Does NOT support recursive arrays!
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param array $array1 Array one.
|
||||
* @param array $array2 Array two.
|
||||
* @param bool $recursive (optional) Compare recursively.
|
||||
* @param bool $strict (optional) Strict comparison? Only available when comparing recursive.
|
||||
* @return bool
|
||||
*/
|
||||
public static function array_equal( $array1, $array2, $recursive = true, $strict = false ) {
|
||||
if ( ! is_array( $array1 ) || ! is_array( $array2 ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( $recursive ) {
|
||||
return (
|
||||
self::array_diff_assoc_recursive( $array1, $array2, $strict ) === self::array_diff_assoc_recursive( $array2, $array1, $strict )
|
||||
);
|
||||
}
|
||||
// Check for recursive arrays.
|
||||
$arr1 = array_filter( $array1, 'is_scalar' );
|
||||
$arr2 = array_filter( $array2, 'is_scalar' );
|
||||
if ( $array1 !== $arr1 || $array2 !== $arr2 ) {
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
count( $arr1 ) === count( $arr2 ) &&
|
||||
array_diff_assoc( $arr1, $arr2 ) === array_diff_assoc( $arr2, $arr1 )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive version of `array_diff_assoc()`.
|
||||
*
|
||||
* @since 1.7.3
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param array $array1 Array one.
|
||||
* @param array $array2 Array two.
|
||||
* @param bool $strict Strict comparison?
|
||||
* @return array
|
||||
*/
|
||||
public static function array_diff_assoc_recursive( $array1, $array2, $strict = false ) {
|
||||
$return = array();
|
||||
|
||||
foreach ( $array1 as $key => $value ) {
|
||||
if ( array_key_exists( $key, $array2 ) ) {
|
||||
if ( is_array( $value ) ) {
|
||||
if ( is_array( $array2[ $key ] ) ) {
|
||||
$diff = self::array_diff_assoc_recursive( $value, $array2[ $key ], $strict );
|
||||
if ( $diff ) {
|
||||
$return[ $key ] = $diff;
|
||||
}
|
||||
} else {
|
||||
$return[ $key ] = $value;
|
||||
}
|
||||
} else {
|
||||
if ( $strict ) {
|
||||
if ( $value !== $array2[ $key ] ) {
|
||||
$return[ $key ] = $value;
|
||||
}
|
||||
} else {
|
||||
if ( (string) $value !== (string) $array2[ $key ] ) {
|
||||
$return[ $key ] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$return[ $key ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an array has a key and optional compare or validate the value.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param array $array
|
||||
* @param string $key
|
||||
* @param array $args {
|
||||
* Optional array of match arguments.
|
||||
* @type mixed $compare A value to compare against (NOTE: strict comparison!).
|
||||
* @type string|array $validation A variable function check, example: 'is_int' or 'MyClass::check'.
|
||||
* }
|
||||
* @return bool
|
||||
*/
|
||||
public static function array_has( $array, $key, $args = array() ) {
|
||||
$isset = ( isset( $array[ $key ] ) );
|
||||
if ( empty( $args ) || ! $isset ) {
|
||||
return $isset;
|
||||
}
|
||||
$value = $array[ $key ];
|
||||
if ( isset( $args['compare'] ) ) {
|
||||
return ( $args['compare'] === $value );
|
||||
}
|
||||
if ( ! empty( $args['validation'] ) ) {
|
||||
$validation = $args['validation'];
|
||||
// Don't accept unavailable validation methods.
|
||||
if ( ! is_callable( $validation ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( is_array( $validation ) ) {
|
||||
return (bool) call_user_func( $validation, $value );
|
||||
}
|
||||
return (bool) $validation( $value );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a string starts with a given string?
|
||||
*
|
||||
* @since 1.4
|
||||
* @since 1.7 Moved from VAA_View_Admin_As_Role_Defaults.
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param string $haystack The string to search in.
|
||||
* @param string $needle The string to search for.
|
||||
* @return bool
|
||||
*/
|
||||
public static function starts_with( $haystack, $needle ) {
|
||||
// Search backwards starting from haystack length characters from the end.
|
||||
return '' === $needle || 0 === strpos( $haystack, $needle );
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a string ends with a given string?
|
||||
*
|
||||
* @since 1.4
|
||||
* @since 1.7 Moved from VAA_View_Admin_As_Role_Defaults.
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param string $haystack The string to search in.
|
||||
* @param string $needle The string to search for.
|
||||
* @return bool
|
||||
*/
|
||||
public static function ends_with( $haystack, $needle ) {
|
||||
// Search forward starting from end minus needle length characters.
|
||||
return '' === $needle || ( strlen( $haystack ) - strlen( $needle ) === strrpos( $haystack, $needle ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare with the current WordPress version.
|
||||
* Returns true when it's the provided version or newer.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @since 1.7.2 Only check full version numbers by default.
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @global string $wp_version WordPress version.
|
||||
* @param int|string $version The WP version to check.
|
||||
* @param bool $only_full_versions Only validate full versions without dev notes (RC1, dev, etc).
|
||||
* @return bool
|
||||
*/
|
||||
public static function validate_wp_version( $version, $only_full_versions = true ) {
|
||||
global $wp_version;
|
||||
$version = strtolower( $version );
|
||||
$compare = strtolower( $wp_version );
|
||||
if ( $only_full_versions ) {
|
||||
// Only leave the version numbers.
|
||||
$version = explode( '-', $version );
|
||||
$version = $version[0];
|
||||
$compare = explode( '-', $compare );
|
||||
$compare = $compare[0];
|
||||
}
|
||||
return (bool) version_compare( $version, $compare, '<=' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enhancement for is_callable(), also check for class_exists() or method_exists() when an array is passed.
|
||||
* Prevents incorrect `true` when a class has a __call() method.
|
||||
* Can also handle error notices.
|
||||
*
|
||||
* @since 1.7.4
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param callable|array $callable The callable data.
|
||||
* @param bool|string $do_notice Add an error notice when it isn't?
|
||||
* Pass `debug` to only show notice when WP_DEBUG is enabled.
|
||||
* @param bool $syntax_only See is_callable() docs.
|
||||
* @return bool
|
||||
*/
|
||||
public static function exists_callable( $callable, $do_notice = false, $syntax_only = false ) {
|
||||
$pass = is_callable( $callable, $syntax_only );
|
||||
if ( $pass && is_array( $callable ) ) {
|
||||
if ( 1 === count( $callable ) ) {
|
||||
$pass = class_exists( $callable[0] );
|
||||
} else {
|
||||
$pass = method_exists( $callable[0], $callable[1] );
|
||||
}
|
||||
}
|
||||
if ( ! $pass && $do_notice ) {
|
||||
if ( 'debug' === $do_notice ) {
|
||||
$do_notice = ( defined( 'WP_DEBUG' ) && WP_DEBUG );
|
||||
}
|
||||
if ( ! is_string( $do_notice ) ) {
|
||||
$callable = self::callable_to_string( $callable );
|
||||
$do_notice = sprintf(
|
||||
// Translators: %s stands for the requested class, method or function.
|
||||
__( '%s does not exist or is not callable.', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'<code>' . $callable . '</code>'
|
||||
);
|
||||
}
|
||||
view_admin_as()->add_error_notice( $callable, array(
|
||||
'message' => $do_notice,
|
||||
) );
|
||||
}
|
||||
return (boolean) $pass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert callable variable to string for display.
|
||||
*
|
||||
* @since 1.7.4
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param callable|array $callable
|
||||
* @return string
|
||||
*/
|
||||
public static function callable_to_string( $callable ) {
|
||||
if ( is_string( $callable ) ) {
|
||||
return $callable;
|
||||
}
|
||||
if ( is_object( $callable ) ) {
|
||||
$callable = array( $callable, '' );
|
||||
}
|
||||
if ( is_array( $callable ) ) {
|
||||
if ( is_object( $callable[0] ) ) {
|
||||
$callable[0] = get_class( $callable[0] );
|
||||
$callable = implode( '->', $callable );
|
||||
} else {
|
||||
$callable = implode( '::', $callable );
|
||||
}
|
||||
}
|
||||
return (string) $callable;
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX request validator. Verifies caller and nonce.
|
||||
* Returns the requested data.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param string $nonce The nonce to validate
|
||||
* @param string $key The key to fetch.
|
||||
* @param string $type The type of request.
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get_ajax_request( $nonce, $key = null, $type = 'post' ) {
|
||||
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
|
||||
return self::get_request( $nonce, $key, $type );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normal request validator. Verifies caller and nonce.
|
||||
* Returns the requested data.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param string $nonce The nonce to validate
|
||||
* @param string $key The key to fetch.
|
||||
* @param string $type The type of request.
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get_normal_request( $nonce, $key = null, $type = 'post' ) {
|
||||
if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) {
|
||||
return self::get_request( $nonce, $key, $type );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request validator. Verifies caller and nonce.
|
||||
* Returns the requested data.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param string $nonce The nonce to validate
|
||||
* @param string $key The key to fetch.
|
||||
* @param string $type The type of request.
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get_request( $nonce, $key = null, $type = 'post' ) {
|
||||
// @codingStandardsIgnoreLine >> Ignore $_GET and $_POST issues.
|
||||
$data = ( 'get' === strtolower( (string) $type ) ) ? $_GET : $_POST;
|
||||
if ( isset( $data[ $key ] ) && isset( $data['_vaa_nonce'] ) && wp_verify_nonce( $data['_vaa_nonce'], $nonce ) ) {
|
||||
$request = self::get_array_data( $data, $key );
|
||||
$request = self::maybe_json_decode( $request, true, true );
|
||||
return $request;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX request check.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param string $key The key to fetch.
|
||||
* @param string $type The type of request.
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_ajax_request( $key = null, $type = 'post' ) {
|
||||
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
|
||||
return self::is_request( $key, $type );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normal request check.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param string $key The key to fetch.
|
||||
* @param string $type The type of request.
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_normal_request( $key = null, $type = 'post' ) {
|
||||
if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) {
|
||||
return self::is_request( $key, $type );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is a request made.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param string $key The key to check.
|
||||
* @param string $type The type of request.
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_request( $key = null, $type = 'post' ) {
|
||||
// @codingStandardsIgnoreLine >> Ignore $_GET and $_POST issues.
|
||||
$data = ( 'get' === strtolower( (string) $type ) ) ? $_GET : $_POST;
|
||||
if ( isset( $data[ $key ] ) ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the value contains JSON.
|
||||
* It the value is an array it will be parsed recursively.
|
||||
*
|
||||
* @link https://stackoverflow.com/questions/6041741/fastest-way-to-check-if-a-string-is-json-in-php
|
||||
*
|
||||
* @since 1.7.5
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @param mixed $value The value to be checked for JSON data.
|
||||
* @param bool $assoc See json_decode().
|
||||
* @param bool $decode Decode with html_entity_decode() and stripcslashes()?
|
||||
* @return mixed
|
||||
*/
|
||||
public static function maybe_json_decode( $value, $assoc = true, $decode = false ) {
|
||||
if ( ! is_string( $value ) ) {
|
||||
if ( is_array( $value ) ) {
|
||||
foreach ( $value as $key => $val ) {
|
||||
$value[ $key ] = self::maybe_json_decode( $val, $assoc, $decode );
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
if ( 0 !== strpos( $value, '[' ) && 0 !== strpos( $value, '{' ) ) {
|
||||
return $value;
|
||||
}
|
||||
if ( $decode ) {
|
||||
$value = stripcslashes( html_entity_decode( $value ) );
|
||||
}
|
||||
$var = json_decode( $value, $assoc );
|
||||
if ( null !== $var ) {
|
||||
return $var;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enhanced is_admin() function with AJAX support.
|
||||
*
|
||||
* @see is_admin()
|
||||
*
|
||||
* @since 1.7.4
|
||||
* @access public
|
||||
* @static
|
||||
* @api
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_admin() {
|
||||
if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) {
|
||||
return is_admin();
|
||||
}
|
||||
// It's an ajax call, is_admin() would always return `true`. Compare the referrer url with the admin url.
|
||||
return ( false !== strpos( (string) wp_get_referer(), admin_url() ) );
|
||||
}
|
||||
|
||||
} // End class VAA_API.
|
||||
224
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-base.php
Executable file
224
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-base.php
Executable file
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Class Base
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Base class that gets the VAA data from the main class.
|
||||
* Use this class as an extender for other classes.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.5
|
||||
* @since 1.7.3 Renamed from VAA_View_Admin_As_Class_Base
|
||||
* @version 1.8
|
||||
*/
|
||||
abstract class VAA_View_Admin_As_Base
|
||||
{
|
||||
/**
|
||||
* View Admin As object.
|
||||
*
|
||||
* @since 1.5
|
||||
* @var \VAA_View_Admin_As
|
||||
*/
|
||||
protected $vaa = null;
|
||||
|
||||
/**
|
||||
* View Admin As store object.
|
||||
*
|
||||
* @since 1.6
|
||||
* @var \VAA_View_Admin_As_Store
|
||||
*/
|
||||
protected $store = null;
|
||||
|
||||
/**
|
||||
* Custom capabilities.
|
||||
*
|
||||
* @since 1.6
|
||||
* @var string[]
|
||||
*/
|
||||
protected $capabilities = array();
|
||||
|
||||
/**
|
||||
* Construct function.
|
||||
* Protected to make sure it isn't declared elsewhere.
|
||||
*
|
||||
* @since 1.5.3
|
||||
* @since 1.6 $vaa param.
|
||||
* @access protected
|
||||
* @param \VAA_View_Admin_As $vaa (optional) Pass VAA object.
|
||||
*/
|
||||
protected function __construct( $vaa = null ) {
|
||||
// Load resources.
|
||||
$this->load_vaa( $vaa );
|
||||
}
|
||||
|
||||
/**
|
||||
* Init function to store data from the main class and enable functionality based on the current view.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.6 $vaa param.
|
||||
* @access public
|
||||
* @final
|
||||
* @param \VAA_View_Admin_As $vaa (optional) Pass VAA object.
|
||||
* @return void
|
||||
*/
|
||||
final public function load_vaa( $vaa = null ) {
|
||||
$this->vaa = $vaa;
|
||||
if ( ! is_object( $vaa ) || 'VAA_View_Admin_As' !== get_class( $vaa ) ) {
|
||||
$this->vaa = view_admin_as();
|
||||
}
|
||||
if ( $this->vaa && 'VAA_View_Admin_As_Store' !== get_class( $this ) ) {
|
||||
$this->store = $this->vaa->store();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the main functionality enabled?
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @final
|
||||
* @return bool
|
||||
*/
|
||||
final public function is_vaa_enabled() {
|
||||
return (bool) $this->vaa->is_enabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the AJAX call is ok.
|
||||
* Must always be used before AJAX data is processed.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function is_valid_ajax() {
|
||||
if ( defined( 'VAA_DOING_AJAX' ) && VAA_DOING_AJAX && $this->is_vaa_enabled() ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extender function for WP current_user_can().
|
||||
* Also checks if VAA is enabled.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @param string $capability (optional) The capability to check when the user isn't a super admin.
|
||||
* @return bool
|
||||
*/
|
||||
public function current_user_can( $capability = null ) {
|
||||
if ( $capability ) {
|
||||
return ( $this->is_vaa_enabled() && ( VAA_API::is_super_admin() || current_user_can( $capability ) ) );
|
||||
}
|
||||
return ( $this->is_vaa_enabled() && VAA_API::is_super_admin() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add capabilities.
|
||||
* Used for the _vaa_add_capabilities hook.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @param array $caps The capabilities.
|
||||
* @return string[]
|
||||
*/
|
||||
public function add_capabilities( $caps ) {
|
||||
foreach ( (array) $this->capabilities as $cap ) {
|
||||
$caps[ $cap ] = $cap;
|
||||
}
|
||||
return $caps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new action to this plugin hooks registry.
|
||||
*
|
||||
* @since 1.8
|
||||
* @see \VAA_View_Admin_As_Hooks::add_action()
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function add_action( $hook, $callback, $priority = 10, $accepted_args = 1 ) {
|
||||
view_admin_as()->hooks()->add_action( $hook, $callback, $priority, $accepted_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new filter to this plugin hooks registry.
|
||||
*
|
||||
* @since 1.8
|
||||
* @see \VAA_View_Admin_As_Hooks::add_filter()
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function add_filter( $hook, $callback, $priority = 10, $accepted_args = 1 ) {
|
||||
view_admin_as()->hooks()->add_filter( $hook, $callback, $priority, $accepted_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to output a string if trying to use the object as a string.
|
||||
*
|
||||
* @since 1.5.1
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function __toString() {
|
||||
return get_class( $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to keep the object from being cloned.
|
||||
*
|
||||
* @since 1.5.1
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function __clone() {
|
||||
_doing_it_wrong(
|
||||
__FUNCTION__,
|
||||
esc_html( get_class( $this ) . ': ' . __( 'This class does not want to be cloned', VIEW_ADMIN_AS_DOMAIN ) ),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to keep the object from being unserialized.
|
||||
*
|
||||
* @since 1.5.1
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function __wakeup() {
|
||||
_doing_it_wrong(
|
||||
__FUNCTION__,
|
||||
esc_html( get_class( $this ) . ': ' . __( 'This class does not want to wake up', VIEW_ADMIN_AS_DOMAIN ) ),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to prevent a fatal error when calling a method that does not exist.
|
||||
*
|
||||
* @since 1.5.1
|
||||
* @access public
|
||||
* @param string $method The method name.
|
||||
* @param array $args The method arguments.
|
||||
* @return null
|
||||
*/
|
||||
public function __call( $method = '', $args = array() ) {
|
||||
_doing_it_wrong(
|
||||
esc_html( get_class( $this ) . "::{$method}" ),
|
||||
esc_html__( 'Method does not exist.', VIEW_ADMIN_AS_DOMAIN ),
|
||||
null
|
||||
);
|
||||
unset( $method, $args );
|
||||
return null;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_Class_Base.
|
||||
584
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-compat.php
Executable file
584
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-compat.php
Executable file
@@ -0,0 +1,584 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Class Compat
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compatibility class.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.6
|
||||
* @version 1.8
|
||||
* @uses \VAA_View_Admin_As_Base Extends class
|
||||
*/
|
||||
final class VAA_View_Admin_As_Compat extends VAA_View_Admin_As_Base
|
||||
{
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @since 1.6
|
||||
* @static
|
||||
* @var \VAA_View_Admin_As_Compat
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* Populate the instance.
|
||||
*
|
||||
* @since 1.6
|
||||
* @since 1.6.1 $vaa param.
|
||||
* @access protected
|
||||
* @param \VAA_View_Admin_As $vaa The main VAA object.
|
||||
*/
|
||||
protected function __construct( $vaa ) {
|
||||
self::$_instance = $this;
|
||||
parent::__construct( $vaa );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix compatibility issues.
|
||||
*
|
||||
* @since 0.1
|
||||
* @since 1.6 Moved third_party_compatibility() to this class from main class.
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
$this->add_action( 'vaa_view_admin_as_init', array( $this, 'init_after' ) );
|
||||
|
||||
/**
|
||||
* Add our caps to the members plugin.
|
||||
* Hook `members_get_capabilities` also used by:
|
||||
* - User Role Editor (URE) >> Own filter: `ure_full_capabilites`
|
||||
* - WPFront User Role Editor
|
||||
* - Capability Manager Enhanced >> Own filter: `capsman_get_capabilities`
|
||||
* - Pods
|
||||
* - Yoast SEO 5.8+
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
$this->add_filter( 'members_get_capabilities', array( $this, 'get_vaa_capabilities' ) );
|
||||
$this->add_action( 'members_register_cap_groups', array( $this, 'action_members_register_cap_group' ) );
|
||||
|
||||
/**
|
||||
* Add our caps to the User Role Editor plugin (URE).
|
||||
* @since 1.6.4
|
||||
*/
|
||||
$this->add_filter( 'ure_capabilities_groups_tree', array( $this, 'filter_ure_capabilities_groups_tree' ) );
|
||||
$this->add_filter( 'ure_custom_capability_groups', array( $this, 'filter_ure_custom_capability_groups' ), 10, 2 );
|
||||
|
||||
/**
|
||||
* Get all capabilities.
|
||||
* @since 1.5
|
||||
*/
|
||||
$this->add_filter( 'view_admin_as_get_capabilities', array( $this, 'get_capabilities' ), 10, 2 );
|
||||
|
||||
/**
|
||||
* WP Admin UI Customize 1.5.11+.
|
||||
* @since 1.7.4
|
||||
*/
|
||||
// wauc_admin_bar_default_load
|
||||
$this->add_filter( 'wauc_admin_bar_menu_add_nodes', array( $this, 'filter_wauc_admin_bar_menu_add_nodes' ), 10, 2 );
|
||||
$this->add_filter( 'wauc_admin_bar_filter_load', array( $this, 'filter_wauc_admin_bar_filter_load' ) );
|
||||
$this->add_filter( 'wauc_admin_bar_menu_widget_no_submenu', array( $this, 'filter_wauc_admin_bar_menu_widget_no_submenu' ) );
|
||||
$this->add_filter( 'wauc_admin_bar_menu_widget_title_readonly_vaa', '__return_true' );
|
||||
$this->add_filter( 'wauc_admin_bar_menu_widget_disable_target_vaa', '__return_true' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix compatibility issues on load.
|
||||
* Called from 'vaa_view_admin_as_init' hook (after loading all data).
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function init_after() {
|
||||
|
||||
if ( $this->store->get_view() &&
|
||||
(int) $this->store->get_curUser()->ID === (int) $this->store->get_selectedUser()->ID
|
||||
) {
|
||||
// Only apply the filter if the current user is modified.
|
||||
$this->add_filter( 'pods_is_admin', array( $this, 'filter_pods_caps_check' ), 99, 2 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get's current capabilities and merges with capabilities from other plugins.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @see \VAA_View_Admin_As_Compat::init()
|
||||
*
|
||||
* @param array $caps The capabilities.
|
||||
* @param bool[] $args Pass arguments to get only certain capabilities.
|
||||
* @return array Both key and values are the capabilities.
|
||||
*/
|
||||
public function get_capabilities( $caps = array(), $args = array() ) {
|
||||
|
||||
$args = wp_parse_args( $args, array(
|
||||
'vaa' => true, // Get VAA related capabilities?
|
||||
'wp' => true, // Get WP core related capabilities?
|
||||
'plugins' => true, // Get capabilities from plugin hooks and filters?
|
||||
) );
|
||||
|
||||
if ( $args['vaa'] ) {
|
||||
$caps = $this->get_vaa_capabilities( $caps );
|
||||
}
|
||||
|
||||
if ( $args['wp'] ) {
|
||||
$caps = $this->get_wordpress_capabilities( $caps );
|
||||
}
|
||||
|
||||
if ( $args['plugins'] ) {
|
||||
$caps = $this->get_plugin_capabilities( $caps );
|
||||
}
|
||||
|
||||
// @since 1.8 Make sure both keys and values are capabilities.
|
||||
$all_caps = array();
|
||||
foreach ( $caps as $cap_key => $cap ) {
|
||||
if ( is_string( $cap ) && ! is_numeric( $cap ) ) {
|
||||
$all_caps[ $cap ] = $cap;
|
||||
} else {
|
||||
$all_caps[ $cap_key ] = $cap_key;
|
||||
}
|
||||
}
|
||||
|
||||
return $all_caps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add our capabilities to an existing list of capabilities.
|
||||
*
|
||||
* @since 1.6
|
||||
* @since 1.7.3 Renamed from add_capabilities().
|
||||
* @access public
|
||||
* @see \VAA_View_Admin_As_Compat::init()
|
||||
*
|
||||
* @param array $caps The capabilities.
|
||||
* @return array
|
||||
*/
|
||||
public function get_vaa_capabilities( $caps = array() ) {
|
||||
|
||||
// Allow VAA modules to add their capabilities.
|
||||
foreach ( (array) apply_filters( 'view_admin_as_add_capabilities', array( 'view_admin_as' ) ) as $cap ) {
|
||||
$caps[ $cap ] = $cap;
|
||||
}
|
||||
|
||||
return $caps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all capabilities from WP core or WP objects.
|
||||
*
|
||||
* @since 1.7.1
|
||||
* @param array $caps The capabilities.
|
||||
* @return array
|
||||
*/
|
||||
public function get_wordpress_capabilities( $caps = array() ) {
|
||||
|
||||
// @since 1.7.1 Store available capabilities existing in roles.
|
||||
foreach ( $this->store->get_roles() as $key => $role ) {
|
||||
if ( is_array( $role->capabilities ) ) {
|
||||
foreach ( $role->capabilities as $cap => $grant ) {
|
||||
$caps[ (string) $cap ] = $cap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.7.1 Add post type and taxonomy caps.
|
||||
* @since 1.7.3 Prevent duplicate array keys.
|
||||
*/
|
||||
$wp_objects = array_merge(
|
||||
array_values( (array) get_post_types( array(), 'objects' ) ),
|
||||
array_values( (array) get_taxonomies( array(), 'objects' ) )
|
||||
);
|
||||
foreach ( $wp_objects as $obj ) {
|
||||
if ( isset( $obj->cap ) ) {
|
||||
// WP stores the object caps as general_cap_name => actual_cap.
|
||||
$caps = array_merge( array_combine( (array) $obj->cap, (array) $obj->cap ), $caps );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Other WordPress capabilities.
|
||||
* @since 1.7.4
|
||||
*/
|
||||
$caps = array_merge( array(
|
||||
// @since 4.9
|
||||
'activate_plugin',
|
||||
'deactivate_plugin',
|
||||
'deactivate_plugins',
|
||||
'install_languages',
|
||||
'update_languages',
|
||||
), $caps );
|
||||
|
||||
/**
|
||||
* Network capabilities.
|
||||
* @since 1.5.3
|
||||
* @since 1.7.2 Added new WP 4.8 caps.
|
||||
* https://make.wordpress.org/core/2017/05/22/multisite-focused-changes-in-4-8/
|
||||
* @see https://codex.wordpress.org/Roles_and_Capabilities
|
||||
*/
|
||||
if ( is_multisite() ) {
|
||||
$network_caps = array(
|
||||
'manage_network',
|
||||
'manage_sites',
|
||||
'manage_network_users',
|
||||
'manage_network_plugins',
|
||||
'manage_network_themes',
|
||||
'manage_network_options',
|
||||
);
|
||||
if ( VAA_API::validate_wp_version( '4.8' ) ) {
|
||||
$network_caps[] = 'upgrade_network';
|
||||
$network_caps[] = 'setup_network';
|
||||
}
|
||||
$caps = array_merge( array_combine( $network_caps, $network_caps ), $caps );
|
||||
}
|
||||
|
||||
return $caps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all capabilities from other plugins.
|
||||
*
|
||||
* Disable some PHPMD checks for this method.
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
* @todo Refactor to enable above checks?
|
||||
*
|
||||
* @since 1.7.1
|
||||
* @param array $caps The capabilities.
|
||||
* @return array
|
||||
*/
|
||||
public function get_plugin_capabilities( $caps = array() ) {
|
||||
|
||||
// WooCommerce caps are not accessible but are assigned to roles on install.
|
||||
// get_wordpress_capabilities() will find them.
|
||||
|
||||
// @since 1.7.1 Gravity Forms.
|
||||
if ( VAA_API::exists_callable( array( 'GFCommon', 'all_caps' ) ) ) {
|
||||
$caps = array_merge( (array) GFCommon::all_caps(), $caps );
|
||||
}
|
||||
|
||||
// @since 1.7.1 User Role Editor.
|
||||
if ( VAA_API::exists_callable( array( 'URE_Own_Capabilities', 'get_caps' ) ) ) {
|
||||
$caps = array_merge( (array) URE_Own_Capabilities::get_caps(), $caps );
|
||||
}
|
||||
$caps = apply_filters( 'ure_full_capabilites', $caps );
|
||||
|
||||
// @since 1.7.1 WPFront User Role Editor.
|
||||
if ( class_exists( 'WPFront_User_Role_Editor' ) && ! empty( WPFront_User_Role_Editor::$ROLE_CAPS ) ) {
|
||||
$caps = array_merge( (array) WPFront_User_Role_Editor::$ROLE_CAPS, $caps );
|
||||
}
|
||||
|
||||
// @since 1.7.1 User Roles and Capabilities.
|
||||
if ( VAA_API::exists_callable( array( 'Solvease_Roles_Capabilities_User_Caps', 'solvease_roles_capabilities_caps' ) ) ) {
|
||||
$caps = array_merge( (array) Solvease_Roles_Capabilities_User_Caps::solvease_roles_capabilities_caps(), $caps );
|
||||
}
|
||||
|
||||
// @since 1.7.1 bbPress.
|
||||
if ( function_exists( 'bbp_get_caps_for_role' ) ) {
|
||||
if ( function_exists( 'bbp_get_keymaster_role' ) ) {
|
||||
$bbp_keymaster_role = bbp_get_keymaster_role();
|
||||
} else {
|
||||
$bbp_keymaster_role = apply_filters( 'bbp_get_keymaster_role', 'bbp_keymaster' );
|
||||
}
|
||||
$caps = array_merge( (array) bbp_get_caps_for_role( $bbp_keymaster_role ), $caps );
|
||||
}
|
||||
|
||||
// @since 1.7.1 BuddyPress.
|
||||
if ( class_exists( 'BuddyPress' ) ) {
|
||||
$caps = array_merge(
|
||||
array(
|
||||
'bp_moderate',
|
||||
'bp_xprofile_change_field_visibility',
|
||||
// @todo Check usage of capabilities below.
|
||||
/*
|
||||
'throttle',
|
||||
'keep_gate',
|
||||
'moderate_comments',
|
||||
'edit_cover_image',
|
||||
'edit_avatar',
|
||||
'edit_favorites',
|
||||
'edit_favorites_of',
|
||||
'add_tag_to',
|
||||
'edit_tag_by_on',
|
||||
'change_user_password',
|
||||
'moderate',
|
||||
'browse_deleted',
|
||||
'view_by_ip',
|
||||
'write_posts',
|
||||
'write_topic',
|
||||
'write_topics',
|
||||
'move_topic',
|
||||
'stick_topic',
|
||||
'close_topic',
|
||||
'edit_topic',
|
||||
'delete_topic',
|
||||
'delete_forum',
|
||||
'manage_forums',
|
||||
'manage_tags',
|
||||
*/
|
||||
),
|
||||
// @see bp_get_community_caps() >> bp-core-caps.php.
|
||||
apply_filters( 'bp_get_community_caps', array() ),
|
||||
$caps
|
||||
);
|
||||
} // End if().
|
||||
|
||||
// @since 1.7.4 Yoast SEO 5.5+ Load integration on front end.
|
||||
if ( ! is_admin() ) {
|
||||
/**
|
||||
* @since 1.8 Yoast SEO - Check for API function.
|
||||
* @link https://github.com/Yoast/wordpress-seo/pull/9365
|
||||
*/
|
||||
if ( function_exists( 'wpseo_get_capabilities' ) ) {
|
||||
$caps = array_merge( (array) wpseo_get_capabilities(), $caps );
|
||||
} elseif ( defined( 'WPSEO_VERSION' ) ) {
|
||||
$yoast_seo_caps = array(
|
||||
'wpseo_bulk_edit',
|
||||
'wpseo_edit_advanced_metadata',
|
||||
'wpseo_manage_options',
|
||||
);
|
||||
$caps = array_merge( $yoast_seo_caps, $caps );
|
||||
}
|
||||
}
|
||||
|
||||
// Members.
|
||||
if ( function_exists( 'members_get_plugin_capabilities' ) ) {
|
||||
$caps = array_merge( (array) members_get_plugin_capabilities(), $caps );
|
||||
}
|
||||
// Get caps from multiple plugins through the Members filter.
|
||||
$caps = apply_filters( 'members_get_capabilities', $caps );
|
||||
|
||||
// Pods.
|
||||
$caps = apply_filters( 'pods_roles_get_capabilities', $caps );
|
||||
|
||||
return $caps;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix compatibility issues Pods Framework 2.0+.
|
||||
*
|
||||
* @since 1.0.1
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.6.2 Check for all provided capabilities.
|
||||
* @access public
|
||||
* @see \VAA_View_Admin_As_Compat::init()
|
||||
*
|
||||
* @param bool $bool Boolean provided by the pods_is_admin hook (not used).
|
||||
* @param array $caps String or Array provided by the pods_is_admin hook.
|
||||
* @return bool
|
||||
*/
|
||||
public function filter_pods_caps_check( $bool, $caps ) {
|
||||
|
||||
foreach ( (array) $caps as $capability ) {
|
||||
if ( $this->vaa->view()->current_view_can( $capability ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add our capabilities to our own group in the Members plugin.
|
||||
*
|
||||
* @see members_register_cap_group()
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @see \VAA_View_Admin_As_Compat::init()
|
||||
*/
|
||||
public function action_members_register_cap_group() {
|
||||
if ( ! function_exists( 'members_register_cap_group' ) ) {
|
||||
return;
|
||||
}
|
||||
// Register the vaa group.
|
||||
members_register_cap_group( 'view_admin_as',
|
||||
array(
|
||||
'label' => esc_html__( 'View Admin As', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'caps' => $this->get_vaa_capabilities(),
|
||||
'icon' => 'dashicons-visibility',
|
||||
'diff_added' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add our our own capability group in the URE plugin.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @access public
|
||||
* @see \VAA_View_Admin_As_Compat::init()
|
||||
* @see \URE_Capabilities_Groups_Manager::get_groups_tree()
|
||||
* @param array $groups Current groups
|
||||
* @return array
|
||||
*/
|
||||
public function filter_ure_capabilities_groups_tree( $groups ) {
|
||||
$groups = (array) $groups;
|
||||
$groups['view_admin_as'] = array(
|
||||
'caption' => esc_html__( 'View Admin As', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'parent' => 'custom',
|
||||
'level' => 3,
|
||||
);
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add our capabilities to our own group in the URE plugin.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @access public
|
||||
* @see \VAA_View_Admin_As_Compat::init()
|
||||
* @see \URE_Capabilities_Groups_Manager::get_cap_groups()
|
||||
* @param array $groups Current capability groups
|
||||
* @param string $cap_id Capability identifier
|
||||
* @return array
|
||||
*/
|
||||
public function filter_ure_custom_capability_groups( $groups, $cap_id ) {
|
||||
if ( in_array( $cap_id, $this->get_vaa_capabilities(), true ) ) {
|
||||
$groups = (array) $groups;
|
||||
$groups[] = 'view_admin_as';
|
||||
}
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force user setting location when WAUC is active.
|
||||
*
|
||||
* Disable some PHPMD checks for this method.
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
* @todo Refactor to enable above checks?
|
||||
*
|
||||
* @since 1.7.4
|
||||
* @access public
|
||||
* @see \WP_Admin_UI_Customize::admin_bar_menu()
|
||||
* @param array $wauc_nodes
|
||||
* @param array $all_nodes
|
||||
* @return array
|
||||
*/
|
||||
public function filter_wauc_admin_bar_menu_add_nodes( $wauc_nodes, $all_nodes ) {
|
||||
|
||||
$admin_menu_location = $this->store->get_userSettings( 'admin_menu_location' );
|
||||
$vaa_root = VAA_View_Admin_As_Admin_Bar::$root;
|
||||
|
||||
$check = array(
|
||||
'depth' => 'main',
|
||||
);
|
||||
if ( 'my-account' === $admin_menu_location ) {
|
||||
$check['depth'] = 'sub';
|
||||
$check['location'] = 'right';
|
||||
$check['parent'] = $admin_menu_location;
|
||||
}
|
||||
|
||||
// Compat when this node is added twice.
|
||||
foreach ( $wauc_nodes as $location => $levels ) {
|
||||
foreach ( $levels as $depth => $nodes ) {
|
||||
foreach ( $nodes as $id => $node ) {
|
||||
if ( isset( $node['id'] ) && $vaa_root === $node['id'] ) {
|
||||
|
||||
$current = array(
|
||||
'depth' => $depth,
|
||||
'location' => $location,
|
||||
'parent' => $node['parent'],
|
||||
);
|
||||
|
||||
foreach ( $check as $key => $val ) {
|
||||
if ( $val !== $current[ $key ] ) {
|
||||
unset( $wauc_nodes[ $location ][ $depth ][ $id ] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure all VAA nodes will be added.
|
||||
$wauc_nodes['vaa'] = array( 'sub' => array() );
|
||||
foreach ( $all_nodes as $node ) {
|
||||
$id = ( ! empty( $node->id ) ) ? $node->id : null;
|
||||
if ( $vaa_root !== $id && 0 === strpos( $id, $vaa_root ) ) {
|
||||
$wauc_nodes['vaa']['sub'][] = (array) $node;
|
||||
}
|
||||
}
|
||||
|
||||
return $wauc_nodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove our nodes from the WAUC admin bar editor.
|
||||
* @since 1.7.4
|
||||
* @access public
|
||||
* @see \WP_Admin_UI_Customize::admin_bar_filter_load()
|
||||
* @param array $all_nodes
|
||||
* @return array
|
||||
*/
|
||||
public function filter_wauc_admin_bar_filter_load( $all_nodes ) {
|
||||
|
||||
if ( empty( $all_nodes['right'] ) ) {
|
||||
return $all_nodes;
|
||||
}
|
||||
|
||||
$slug = VAA_View_Admin_As_Admin_Bar::$root;
|
||||
|
||||
foreach ( (array) $all_nodes['right'] as $location => $nodes ) {
|
||||
if ( 0 !== strpos( $location, 'sub' ) ) {
|
||||
continue;
|
||||
}
|
||||
foreach ( $nodes as $key => $node ) {
|
||||
// Check if node ID starts with `vaa-` and node parent starts with `vaa`.
|
||||
if ( 0 === strpos( $node->id , $slug . '-' ) && 0 === strpos( $node->parent , $slug ) ) {
|
||||
unset( $all_nodes['right'][ $location ][ $key ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
return $all_nodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove submenu options for WAUC.
|
||||
* @since 1.7.4
|
||||
* @see \WP_Admin_UI_Customize::admin_bar_menu_widget()
|
||||
* @param array $no_submenu
|
||||
* @return array
|
||||
*/
|
||||
public function filter_wauc_admin_bar_menu_widget_no_submenu( $no_submenu ) {
|
||||
$no_submenu[] = VAA_View_Admin_As_Admin_Bar::$root;
|
||||
return $no_submenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Instance.
|
||||
*
|
||||
* Ensures only one instance of this class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @static
|
||||
* @param \VAA_View_Admin_As $caller The referrer class.
|
||||
* @return \VAA_View_Admin_As_Compat $this
|
||||
*/
|
||||
public static function get_instance( $caller = null ) {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self( $caller );
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_Compat.
|
||||
640
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-controller.php
Executable file
640
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-controller.php
Executable file
@@ -0,0 +1,640 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Class Controller
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* View controller class. Handles all view data.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.7
|
||||
* @version 1.8
|
||||
* @uses \VAA_View_Admin_As_Base Extends class
|
||||
*/
|
||||
final class VAA_View_Admin_As_Controller extends VAA_View_Admin_As_Base
|
||||
{
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @since 1.6
|
||||
* @static
|
||||
* @var \VAA_View_Admin_As_Controller
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* Expiration time for view data.
|
||||
*
|
||||
* @since 1.3.4 (as $metaExpiration).
|
||||
* @since 1.6.2 Moved from main class.
|
||||
* @var int
|
||||
*/
|
||||
private $viewExpiration = 86400; // one day: ( 24 * 60 * 60 ).
|
||||
|
||||
/**
|
||||
* VAA_View_Admin_As_Controller constructor.
|
||||
*
|
||||
* @since 1.6
|
||||
* @since 1.6.1 $vaa param.
|
||||
* @access protected
|
||||
* @param \VAA_View_Admin_As $vaa The main VAA object.
|
||||
*/
|
||||
protected function __construct( $vaa ) {
|
||||
self::$_instance = $this;
|
||||
parent::__construct( $vaa );
|
||||
|
||||
// When a user logs in or out, reset the view to default.
|
||||
$this->add_action( 'wp_login', array( $this, 'cleanup_views' ), 10, 2 );
|
||||
$this->add_action( 'wp_login', array( $this, 'reset_view' ), 10, 2 );
|
||||
$this->add_action( 'wp_logout', array( $this, 'reset_view' ) );
|
||||
|
||||
// Not needed, the delete_user actions already remove all metadata, keep code for possible future use.
|
||||
//$this->add_action( 'remove_user_from_blog', array( $this->store, 'delete_user_meta' ) );
|
||||
//$this->add_action( 'wpmu_delete_user', array( $this->store, 'delete_user_meta' ) );
|
||||
//$this->add_action( 'wp_delete_user', array( $this->store, 'delete_user_meta' ) );
|
||||
|
||||
/**
|
||||
* Change expiration time for view meta.
|
||||
*
|
||||
* @example You can set it to 1 to always clear everything after login.
|
||||
* @example 0 will be overwritten!
|
||||
*
|
||||
* @param int $viewExpiration 86400 (1 day in seconds).
|
||||
* @return int
|
||||
*/
|
||||
$this->viewExpiration = absint( apply_filters( 'view_admin_as_view_expiration', $this->viewExpiration ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes after VAA is enabled.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
/**
|
||||
* Reset view to default if something goes wrong.
|
||||
*
|
||||
* @since 0.1
|
||||
* @since 1.2 Only check for key
|
||||
* @example http://www.your.domain/wp-admin/?reset-view
|
||||
*/
|
||||
if ( VAA_API::is_request( 'reset-view', 'get' ) ) {
|
||||
$this->reset_view();
|
||||
}
|
||||
/**
|
||||
* Clear all user views.
|
||||
*
|
||||
* @since 1.3.4
|
||||
* @example http://www.your.domain/wp-admin/?reset-all-views
|
||||
*/
|
||||
if ( VAA_API::is_request( 'reset-all-views', 'get' ) ) {
|
||||
$this->reset_all_views();
|
||||
}
|
||||
|
||||
// Reset hook.
|
||||
$this->add_filter( 'view_admin_as_handle_ajax_reset', array( $this, 'reset_view' ) );
|
||||
|
||||
// Validation & update hooks for visitor view.
|
||||
$this->add_filter( 'view_admin_as_validate_view_data_visitor', '__return_true' );
|
||||
$this->add_filter( 'view_admin_as_update_view_visitor', array( $this, 'filter_update_view' ), 10, 3 );
|
||||
|
||||
// Get the current view.
|
||||
$this->store->set_view( $this->get_view() );
|
||||
|
||||
// Short circuit needed for visitor view (BEFORE the current user is set).
|
||||
if ( VAA_API::is_ajax_request( 'view_admin_as' ) ) {
|
||||
$this->ajax_view_admin_as();
|
||||
} else {
|
||||
// Admin selector ajax return (fallback).
|
||||
$this->add_action( 'wp_ajax_view_admin_as', array( $this, 'ajax_view_admin_as' ) );
|
||||
//$this->add_action( 'wp_ajax_nopriv_view_admin_as', array( $this, 'ajax_view_admin_as' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX listener.
|
||||
* Gets the AJAX input. If it is valid: pass it to the handler.
|
||||
*
|
||||
* @since 0.1
|
||||
* @since 1.3 Added caps handler.
|
||||
* @since 1.4 Added module handler.
|
||||
* @since 1.5 Validate a nonce.
|
||||
* Added global and user setting handler.
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.6.2 Added visitor view handler + JSON view data.
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function ajax_view_admin_as() {
|
||||
|
||||
$data = VAA_API::get_ajax_request( $this->store->get_nonce(), 'view_admin_as' );
|
||||
if ( ! $data ) {
|
||||
wp_send_json_error( __( 'Cheatin uh?', VIEW_ADMIN_AS_DOMAIN ) );
|
||||
die();
|
||||
}
|
||||
|
||||
define( 'VAA_DOING_AJAX', true );
|
||||
|
||||
$data = $this->validate_data_keys( $data );
|
||||
|
||||
$success = false;
|
||||
if ( ! empty( $data ) ) {
|
||||
$success = $this->ajax_handler( $data );
|
||||
}
|
||||
|
||||
if ( true === $success ) {
|
||||
wp_send_json_success( $success ); // ahw yeah.
|
||||
die();
|
||||
} elseif ( $success ) {
|
||||
wp_send_json( $success );
|
||||
die();
|
||||
}
|
||||
|
||||
wp_send_json_error( array(
|
||||
'type' => 'error',
|
||||
'text' => esc_html__( 'Something went wrong, please try again.', VIEW_ADMIN_AS_DOMAIN ),
|
||||
) );
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX handler.
|
||||
* Applies the data input.
|
||||
*
|
||||
* @since 1.7
|
||||
* @param array $data Post data.
|
||||
* @return array|bool
|
||||
*/
|
||||
private function ajax_handler( $data ) {
|
||||
$success = false;
|
||||
$view_types = array();
|
||||
|
||||
// Stop selecting the same view!
|
||||
if ( $this->is_current_view( $data ) ) {
|
||||
wp_send_json_error( array(
|
||||
'type' => 'message',
|
||||
'text' => esc_html__( 'This view is already selected!', VIEW_ADMIN_AS_DOMAIN ),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax return filters.
|
||||
*
|
||||
* @see `view_admin_as_update_view_{$key}`
|
||||
* @see `view_admin_as_handle_ajax_{$key}`
|
||||
*
|
||||
* @since 1.7
|
||||
* @param null $null Null.
|
||||
* @param mixed $value View data value.
|
||||
* @param string $key View data key.
|
||||
* @return bool|array {
|
||||
* In case of array. Uses wp_json_return() structure.
|
||||
* @type bool $success Send JSON success or error?
|
||||
* @type array $data {
|
||||
* Optional extra data to send with the JSON return.
|
||||
* In case of a view the page normally refreshes.
|
||||
* @type string $redirect (URL) Redirect the user? (Only works on success).
|
||||
* @type string $display Options: notice A notice type in the admin bar
|
||||
* popup A popup/overlay with content
|
||||
* @type string $type Options: success Ureka! (green) - Default when $success is true
|
||||
* error Send an error (red) - Default when $success is false
|
||||
* message Just a message (blue)
|
||||
* warning Send a warning (orange)
|
||||
* @type string $text The text to show
|
||||
* @type array $list Show multiple messages (Popup only)
|
||||
* @type string $textarea Textarea content (Popup only)
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
foreach ( $data as $key => $value ) {
|
||||
if ( $this->is_view_type( $key ) ) {
|
||||
$view_types[] = $key;
|
||||
$success = apply_filters( 'view_admin_as_update_view_' . $key, null, $value, $key );
|
||||
} else {
|
||||
$success = apply_filters( 'view_admin_as_handle_ajax_' . $key, null, $value, $key );
|
||||
}
|
||||
if ( true !== $success ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $view_types ) ) {
|
||||
return $success;
|
||||
}
|
||||
|
||||
// Update the view on success.
|
||||
if ( true === $success || ( isset( $success['success'] ) && true === $success['success'] ) ) {
|
||||
|
||||
// Remove view type keys that are not in the new view anymore.
|
||||
$view = $this->store->get_view();
|
||||
$view = array_intersect_key( $view, array_flip( $view_types ) );
|
||||
$this->store->set_view( $view );
|
||||
|
||||
$this->update_view();
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update regular view types.
|
||||
*
|
||||
* @since 1.7
|
||||
* @param null $null Null.
|
||||
* @param mixed $data The view data.
|
||||
* @param string $type The view type.
|
||||
* @return bool|array
|
||||
*/
|
||||
public function filter_update_view( $null, $data, $type ) {
|
||||
$success = $null;
|
||||
if ( ! empty( $data ) && ! empty( $type ) ) {
|
||||
$this->store->set_view( $data, $type, true );
|
||||
$success = true;
|
||||
}
|
||||
if ( $success && 'visitor' === $type && VAA_API::is_admin() ) {
|
||||
$success = array(
|
||||
'success' => true,
|
||||
'data' => array(
|
||||
'redirect' => esc_url( home_url() ),
|
||||
),
|
||||
);
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the provided data is the same as the current view.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7.2 Data options: `null` for active view & `false` for only/single view.
|
||||
* @param mixed $data The view data to compare with.
|
||||
* @param bool $type Only compare a single view type instead of all view data?
|
||||
* If set, the data value should be the single view type data or `null`.
|
||||
* If data is `null` then it will return true if that view type is active.
|
||||
* If data is `false` then it will return true if this is the only active view type.
|
||||
* @return bool
|
||||
*/
|
||||
public function is_current_view( $data, $type = null ) {
|
||||
if ( ! empty( $type ) ) {
|
||||
$current = $this->store->get_view( $type );
|
||||
if ( ! $current ) {
|
||||
return false;
|
||||
}
|
||||
if ( is_array( $data ) ) {
|
||||
return VAA_API::array_equal( $data, $current );
|
||||
}
|
||||
if ( null === $data ) {
|
||||
return true;
|
||||
}
|
||||
if ( false === $data ) {
|
||||
return ( 1 === count( $this->store->get_view() ) );
|
||||
}
|
||||
return ( (string) $data === (string) $current );
|
||||
}
|
||||
return VAA_API::array_equal( $data, $this->store->get_view() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Is it a view type?
|
||||
*
|
||||
* @since 1.7
|
||||
* @param string $type View type name to check
|
||||
* @return bool
|
||||
*/
|
||||
public function is_view_type( $type ) {
|
||||
return ( in_array( $type, $this->get_view_types(), true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the available view type keys.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @return string[]
|
||||
*/
|
||||
public function get_view_types() {
|
||||
static $view_types;
|
||||
if ( ! is_null( $view_types ) ) return $view_types;
|
||||
|
||||
$view_types = array_keys( (array) view_admin_as()->get_view_types() );
|
||||
$view_types[] = 'visitor';
|
||||
|
||||
/**
|
||||
* Add basic view types for automated use in JS and through VAA.
|
||||
*
|
||||
* - Menu items require the class vaa-{TYPE}-item (through the add_node() meta key).
|
||||
* - Menu items require the href attribute (the node needs to be an <a> element).
|
||||
* @see \VAA_View_Admin_As_Form::do_view_title()
|
||||
*
|
||||
* @deprecated 1.8
|
||||
*
|
||||
* @since 1.6.2
|
||||
* @param array $array Empty array.
|
||||
* @return array An array of strings (view types).
|
||||
*/
|
||||
$dep_view_types = apply_filters( 'view_admin_as_view_types', array() );
|
||||
if ( $dep_view_types ) {
|
||||
|
||||
/** @see https://developer.wordpress.org/reference/functions/apply_filters_deprecated/ */
|
||||
if ( function_exists( '_deprecated_hook' ) ) {
|
||||
_deprecated_hook( 'view_admin_as_view_types', 1.8, 'view_admin_as()->register_view_type()' );
|
||||
}
|
||||
|
||||
$view_types = array_unique( array_merge(
|
||||
array_filter( $dep_view_types, 'is_string' ),
|
||||
$view_types
|
||||
) );
|
||||
}
|
||||
|
||||
return $view_types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current view for the current session.
|
||||
*
|
||||
* @since 1.3.4
|
||||
* @since 1.5 Single mode.
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.7 Private method. Use store.
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
private function get_view() {
|
||||
|
||||
$view_mode = $this->store->get_userSettings( 'view_mode' );
|
||||
|
||||
// Static actions.
|
||||
$request = VAA_API::get_normal_request( $this->store->get_nonce(), 'view_admin_as', 'get' );
|
||||
if ( $request && 'browse' === $view_mode ) {
|
||||
$this->store->set_view( $this->validate_view_data( $request ) );
|
||||
$this->update_view();
|
||||
// Trigger page refresh.
|
||||
// @todo fix WP referrer/nonce checks and allow switching on any page without ajax. See VAA_API.
|
||||
if ( is_network_admin() ) {
|
||||
wp_redirect( network_admin_url() );
|
||||
} else {
|
||||
wp_redirect( admin_url() );
|
||||
}
|
||||
}
|
||||
|
||||
// Single mode.
|
||||
$request = VAA_API::get_normal_request( $this->store->get_nonce(), 'view_admin_as' );
|
||||
if ( $request && 'single' === $view_mode ) {
|
||||
return $this->validate_view_data( $request );
|
||||
}
|
||||
|
||||
// Browse mode.
|
||||
if ( 'browse' === $view_mode ) {
|
||||
$meta = $this->store->get_userMeta( 'views' );
|
||||
if ( isset( $meta[ $this->store->get_curUserSession() ]['view'] ) ) {
|
||||
return $this->validate_view_data( $meta[ $this->store->get_curUserSession() ]['view'] );
|
||||
}
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update view for the current session.
|
||||
*
|
||||
* @since 1.3.4
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @access public
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function update_view() {
|
||||
$data = $this->validate_view_data( $this->store->get_view() );
|
||||
if ( $data ) {
|
||||
$meta = $this->store->get_userMeta( 'views' );
|
||||
// Make sure it is an array (no array means no valid data so we can safely clear it).
|
||||
if ( ! is_array( $meta ) ) {
|
||||
$meta = array();
|
||||
}
|
||||
// Add the new view metadata and expiration date.
|
||||
$meta[ $this->store->get_curUserSession() ] = array(
|
||||
'view' => $data,
|
||||
'expire' => ( time() + (int) $this->viewExpiration ),
|
||||
);
|
||||
// Update metadata (returns: true on success, false on failure).
|
||||
return $this->store->update_userMeta( $meta, 'views', true );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset view to default.
|
||||
* This function is also attached to the wp_login and wp_logout hook.
|
||||
*
|
||||
* @since 1.3.4
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @access public
|
||||
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/wp_login
|
||||
*
|
||||
* @param string $user_login (not used) String provided by the wp_login hook.
|
||||
* @param \WP_User $user User object provided by the wp_login hook.
|
||||
* @return bool
|
||||
*/
|
||||
public function reset_view( $user_login = null, $user = null ) {
|
||||
|
||||
// function is not triggered by the wp_login action hook.
|
||||
if ( null === $user ) {
|
||||
$user = $this->store->get_curUser();
|
||||
}
|
||||
if ( ! empty( $user->ID ) ) {
|
||||
// Do not use the store as it currently doesn't support a different user ID.
|
||||
$meta = get_user_meta( $user->ID, $this->store->get_userMetaKey(), true );
|
||||
// Check if this user session has metadata.
|
||||
if ( isset( $meta['views'][ $this->store->get_curUserSession() ] ) ) {
|
||||
// Remove metadata from this session.
|
||||
unset( $meta['views'][ $this->store->get_curUserSession() ] );
|
||||
// Update current metadata if it is the current user.
|
||||
if ( $this->store->get_curUser() && (int) $this->store->get_curUser()->ID === (int) $user->ID ) {
|
||||
$this->store->set_userMeta( $meta );
|
||||
}
|
||||
// Update db metadata (returns: true on success, false on failure).
|
||||
return update_user_meta( $user->ID, $this->store->get_userMetaKey(), $meta );
|
||||
}
|
||||
}
|
||||
// No meta found, no reset needed.
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all expired View Admin As metadata for this user.
|
||||
* This function is also attached to the wp_login hook.
|
||||
*
|
||||
* @since 1.3.4
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @access public
|
||||
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/wp_login
|
||||
*
|
||||
* @param string $user_login (not used) String provided by the wp_login hook.
|
||||
* @param \WP_User $user User object provided by the wp_login hook.
|
||||
* @return bool
|
||||
*/
|
||||
public function cleanup_views( $user_login = null, $user = null ) {
|
||||
|
||||
// function is not triggered by the wp_login action hook.
|
||||
if ( null === $user ) {
|
||||
$user = $this->store->get_curUser();
|
||||
}
|
||||
if ( ! empty( $user->ID ) ) {
|
||||
// Do not use the store as it currently doesn't support a different user ID.
|
||||
$meta = get_user_meta( $user->ID, $this->store->get_userMetaKey(), true );
|
||||
// If meta exists, loop it.
|
||||
if ( isset( $meta['views'] ) ) {
|
||||
|
||||
foreach ( (array) $meta['views'] as $key => $value ) {
|
||||
// Check expiration date: if it doesn't exist or is in the past, remove it.
|
||||
if ( ! isset( $meta['views'][ $key ]['expire'] ) || time() > (int) $meta['views'][ $key ]['expire'] ) {
|
||||
unset( $meta['views'][ $key ] );
|
||||
}
|
||||
}
|
||||
// Update current metadata if it is the current user.
|
||||
if ( $this->store->get_curUser() && (int) $this->store->get_curUser()->ID === (int) $user->ID ) {
|
||||
$this->store->set_userMeta( $meta );
|
||||
}
|
||||
// Update db metadata (returns: true on success, false on failure).
|
||||
return update_user_meta( $user->ID, $this->store->get_userMetaKey(), $meta );
|
||||
}
|
||||
}
|
||||
// No meta found, no cleanup needed.
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all View Admin As metadata for this user.
|
||||
*
|
||||
* @since 1.3.4
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @access public
|
||||
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/wp_login
|
||||
*
|
||||
* @param string $user_login (not used) String provided by the wp_login hook.
|
||||
* @param \WP_User $user User object provided by the wp_login hook.
|
||||
* @return bool
|
||||
*/
|
||||
public function reset_all_views( $user_login = null, $user = null ) {
|
||||
|
||||
// function is not triggered by the wp_login action hook.
|
||||
if ( null === $user ) {
|
||||
$user = $this->store->get_curUser();
|
||||
}
|
||||
if ( ! empty( $user->ID ) ) {
|
||||
$meta = get_user_meta( $user->ID, $this->store->get_userMetaKey(), true );
|
||||
// If meta exists, reset it.
|
||||
if ( isset( $meta['views'] ) ) {
|
||||
$meta['views'] = array();
|
||||
// Update current metadata if it is the current user.
|
||||
if ( $this->store->get_curUser() && (int) $this->store->get_curUser()->ID === (int) $user->ID ) {
|
||||
$this->store->set_userMeta( $meta );
|
||||
}
|
||||
// Update db metadata (returns: true on success, false on failure).
|
||||
return update_user_meta( $user->ID, $this->store->get_userMetaKey(), $meta );
|
||||
}
|
||||
}
|
||||
// No meta found, no reset needed.
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all unsupported keys.
|
||||
*
|
||||
* @since 1.7
|
||||
* @param array $data Input data.
|
||||
* @return array
|
||||
*/
|
||||
public function validate_data_keys( $data ) {
|
||||
|
||||
if ( ! is_array( $data ) || empty( $data ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$allowed_keys = array_unique( array_merge(
|
||||
// View types.
|
||||
$this->get_view_types(),
|
||||
// Module keys.
|
||||
array_keys( $this->vaa->get_modules() ),
|
||||
// VAA core keys.
|
||||
array( 'setting', 'user_setting', 'reset' )
|
||||
) );
|
||||
|
||||
$data = array_intersect_key( $data, array_flip( $allowed_keys ) );
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate data before changing the view.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.7 Changed name to `validate_view_data` from `validate_view_as_data`
|
||||
* @access public
|
||||
*
|
||||
* @param array $data Unvalidated data.
|
||||
* @return array $data Validated data.
|
||||
*/
|
||||
public function validate_view_data( $data ) {
|
||||
|
||||
if ( ! is_array( $data ) || empty( $data ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// Only leave keys that are view types.
|
||||
$data = array_intersect_key( $data, array_flip( $this->get_view_types() ) );
|
||||
|
||||
// We only want allowed keys and data, otherwise it's not added through this plugin.
|
||||
foreach ( $data as $key => $value ) {
|
||||
|
||||
/**
|
||||
* Validate the data.
|
||||
* Hook is required!
|
||||
*
|
||||
* @since 1.6.2
|
||||
* @since 1.7 Added third $key parameter
|
||||
* @param null $null Ensures a validation filter is required.
|
||||
* @param mixed $value Unvalidated view data.
|
||||
* @param string $key The data key.
|
||||
* @return mixed validated view data.
|
||||
*/
|
||||
$data[ $key ] = apply_filters( 'view_admin_as_validate_view_data_' . $key, null, $value, $key );
|
||||
|
||||
if ( null === $data[ $key ] ) {
|
||||
unset( $data[ $key ] );
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Instance.
|
||||
*
|
||||
* Ensures only one instance of this class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @static
|
||||
* @param \VAA_View_Admin_As $caller The referrer class.
|
||||
* @return \VAA_View_Admin_As_Controller $this
|
||||
*/
|
||||
public static function get_instance( $caller = null ) {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self( $caller );
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_Controller.
|
||||
746
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-form.php
Executable file
746
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-form.php
Executable file
@@ -0,0 +1,746 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Form
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Form elements for View Admin As.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.7.2
|
||||
* @since 1.8 Moved to the includes folder.
|
||||
* @version 1.8
|
||||
*/
|
||||
class VAA_View_Admin_As_Form
|
||||
{
|
||||
/**
|
||||
* Generate a view type title and it's view related data.
|
||||
* The data is used in javascript to switch a view.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7.2 Moved to this class from admin bar class.
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @param string $title The title content.
|
||||
* @param string|\VAA_View_Admin_As_Type $type The view type.
|
||||
* @param string $value The view value.
|
||||
* @param array $attr (optional) Array of other attributes.
|
||||
* @param string $elem (optional) HTML element type.
|
||||
* @return string
|
||||
*/
|
||||
public static function do_view_title( $title, $type, $value, $attr = array(), $elem = 'span' ) {
|
||||
$attr = (array) $attr;
|
||||
$class = ( ! empty( $attr['class'] ) ) ? ' ' . $attr['class'] : '';
|
||||
$attr['class'] = 'vaa-view-data' . $class;
|
||||
if ( $type instanceof VAA_View_Admin_As_Type ) {
|
||||
$attr['vaa-view-type'] = $type->get_type();
|
||||
$attr['vaa-view-type-label'] = $type->get_label_singular();
|
||||
} else {
|
||||
$attr['vaa-view-type'] = $type;
|
||||
}
|
||||
$attr['vaa-view-value'] = $value;
|
||||
$attr = self::parse_to_html_attr( $attr );
|
||||
return '<' . $elem . ' ' . $attr . '>' . $title . '</' . $elem . '>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get multiple form elements in one call.
|
||||
* Note: Method calls are limited to one parameter!
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @param array $args An array of key => value (form method first parameter).
|
||||
* @return string
|
||||
*/
|
||||
public static function do_multiple( $args ) {
|
||||
$return = array();
|
||||
foreach ( $args as $key => $value ) {
|
||||
$method = $key;
|
||||
if ( is_callable( array( 'VAA_View_Admin_As_Form', $key ) ) ) {
|
||||
$return[] = self::$method( $value );
|
||||
} elseif ( is_callable( array( 'VAA_View_Admin_As_Form', 'do_' . $key ) ) ) {
|
||||
$method = 'do_' . $key;
|
||||
$return[] = self::$method( $value );
|
||||
}
|
||||
}
|
||||
return implode( '', $return );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate button HTML for node.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @since 1.6.2 Added $element option.
|
||||
* @since 1.7.2 Moved to this class from admin bar class.
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @param array $args {
|
||||
* (required) An array of field arguments.
|
||||
* @type string $name (required)
|
||||
* @type string $id (optional) Will be generated from $name if empty.
|
||||
* @type string $label (optional)
|
||||
* @type string $class (optional)
|
||||
* @type string $element (optional)
|
||||
* @type array $attr (optional)
|
||||
* @type array $auto_js (optional) See VAA_View_Admin_As_Form::enable_auto_js().
|
||||
* }
|
||||
* @return string
|
||||
*/
|
||||
public static function do_button( $args ) {
|
||||
$id = esc_attr( ( ! empty( $args['id'] ) ) ? $args['id'] : $args['name'] );
|
||||
$name = str_replace( '-', '_', esc_attr( $args['name'] ) );
|
||||
$elem = ( ! empty( $args['element'] ) ) ? $args['element'] : 'button';
|
||||
$label = ( ! empty( $args['label'] ) ) ? $args['label'] : '';
|
||||
$class = ( ! empty( $args['class'] ) ) ? ' ' . $args['class'] : '';
|
||||
|
||||
$args['attr']['id'] = $id;
|
||||
$args['attr']['name'] = $name;
|
||||
$args['attr']['class'] = 'button' . $class;
|
||||
if ( isset( $args['value'] ) ) {
|
||||
if ( is_bool( $args['value'] ) ) {
|
||||
$args['value'] = (int) $args['value'];
|
||||
}
|
||||
$args['attr']['value'] = (string) $args['value'];
|
||||
};
|
||||
|
||||
$attr = $args['attr'];
|
||||
if ( ! empty( $args['auto_js'] ) && empty( $args['auto_js']['event'] ) ) {
|
||||
$args['auto_js']['event'] = 'click';
|
||||
}
|
||||
$attr = self::enable_auto_js( $attr, $args );
|
||||
$attr = self::parse_to_html_attr( $attr );
|
||||
|
||||
return '<' . $elem . ' ' . $attr . '>' . $label . '</' . $elem . '>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate text input HTML for node.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @since 1.6.3 Automatic show/hide description option.
|
||||
* @since 1.7.2 Moved to this class from admin bar class.
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @param array $args {
|
||||
* (required) An array of field arguments.
|
||||
* @type string $name (required)
|
||||
* @type string $id (optional) Will be generated from $name if empty.
|
||||
* @type string $placeholder (optional)
|
||||
* @type string $default (optional)
|
||||
* @type string $value (optional)
|
||||
* @type string $label (optional)
|
||||
* @type string $description (optional)
|
||||
* @type string $help (optional)
|
||||
* @type string $class (optional)
|
||||
* @type array $type (optional) Optional input type attribute.
|
||||
* @type array $attr (optional)
|
||||
* @type array $auto_js (optional) See VAA_View_Admin_As_Form::enable_auto_js().
|
||||
* @type bool $auto_showhide (optional) Pass `true` or int for auto show/hide description. Integer stands for the delay (default: 200).
|
||||
* }
|
||||
* @return string
|
||||
*/
|
||||
public static function do_input( $args ) {
|
||||
$html = '';
|
||||
|
||||
$id = esc_attr( ( ! empty( $args['id'] ) ) ? $args['id'] : $args['name'] );
|
||||
$name = str_replace( '-', '_', esc_attr( $args['name'] ) );
|
||||
$default = ( ! empty( $args['default'] ) ) ? $args['default'] : '';
|
||||
$placeholder = ( ! empty( $args['placeholder'] ) ) ? $args['placeholder'] : '';
|
||||
$class = ( ! empty( $args['class'] ) ) ? $args['class'] : '';
|
||||
|
||||
$args['attr']['type'] = ( ! empty( $args['type'] ) ) ? $args['type'] : 'text';
|
||||
$args['attr']['id'] = $id;
|
||||
$args['attr']['name'] = $name;
|
||||
$args['attr']['placeholder'] = $placeholder;
|
||||
$args['attr']['value'] = ( ! empty( $args['value'] ) ) ? $args['value'] : $default;
|
||||
$args['attr']['class'] = $class;
|
||||
|
||||
$attr = $args['attr'];
|
||||
$attr = self::enable_auto_js( $attr, $args );
|
||||
$attr = self::parse_to_html_attr( $attr );
|
||||
|
||||
$label_attr = array();
|
||||
$desc_attr = array();
|
||||
self::enable_auto_showhide( $id . '-desc', $label_attr, $desc_attr, $args );
|
||||
|
||||
$html .= self::do_help( $args, array(), array(), $label_attr );
|
||||
$html .= self::do_label( $args, $id, $label_attr );
|
||||
$html .= '<input ' . $attr . '/>';
|
||||
$html .= self::do_description( $args, $desc_attr );
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate checkbox HTML for node.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @since 1.6.3 Automatic show/hide description option + removable option.
|
||||
* @since 1.7.2 Moved to this class from admin bar class.
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @param array $args {
|
||||
* (required) An array of field arguments.
|
||||
* @type string $name (required)
|
||||
* @type string $id (optional) Will be generated from $name if empty.
|
||||
* @type string $compare (optional)
|
||||
* @type string $value (optional)
|
||||
* @type string $checkbox_value (optional) Default: 1.
|
||||
* @type string $label (optional)
|
||||
* @type string $description (optional)
|
||||
* @type string $help (optional)
|
||||
* @type string $class (optional)
|
||||
* @type array $attr (optional)
|
||||
* @type array $auto_js (optional) See VAA_View_Admin_As_Form::enable_auto_js().
|
||||
* @type bool $auto_showhide (optional) Pass `true` or int for auto show/hide description. Integer stands for the delay (default: 200).
|
||||
* @type bool $removable (optional)
|
||||
* }
|
||||
* @return string
|
||||
*/
|
||||
public static function do_checkbox( $args ) {
|
||||
$html = '';
|
||||
|
||||
$id = esc_attr( ( ! empty( $args['id'] ) ) ? $args['id'] : $args['name'] );
|
||||
$name = str_replace( '-', '_', esc_attr( $args['name'] ) );
|
||||
|
||||
if ( empty( $args['value'] ) ) {
|
||||
$args['value'] = null;
|
||||
}
|
||||
if ( empty( $args['compare'] ) ) {
|
||||
$args['compare'] = 1;
|
||||
}
|
||||
$checked = checked( $args['value'], $args['compare'], false );
|
||||
$class = ( ! empty( $args['class'] ) ) ? ' ' . $args['class'] : '';
|
||||
|
||||
$args['attr']['type'] = 'checkbox';
|
||||
$args['attr']['id'] = $id;
|
||||
$args['attr']['name'] = $name;
|
||||
$args['attr']['value'] = ( ! empty( $args['checkbox_value'] ) ) ? $args['checkbox_value'] : '1';
|
||||
$args['attr']['class'] = 'checkbox' . $class;
|
||||
|
||||
$attr = $args['attr'];
|
||||
$attr = self::enable_auto_js( $attr, $args );
|
||||
$attr = self::parse_to_html_attr( $attr );
|
||||
|
||||
$label_attr = array();
|
||||
$desc_attr = array();
|
||||
self::enable_auto_showhide( $id . '-desc', $label_attr, $desc_attr, $args );
|
||||
|
||||
$html .= self::do_help( $args, array(), array(), $label_attr );
|
||||
$html .= '<input ' . $attr . ' ' . $checked . '/>';
|
||||
$html .= self::do_label( $args, $id, $label_attr );
|
||||
|
||||
if ( ! empty( $args['removable'] ) ) {
|
||||
$html .= self::do_icon( 'dashicons-dismiss remove', array( 'title' => __( 'Remove', VIEW_ADMIN_AS_DOMAIN ) ) );
|
||||
}
|
||||
|
||||
$html .= self::do_description( $args, $desc_attr );
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate radio HTML for node.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @since 1.6.3 Automatic show/hide description option.
|
||||
* @since 1.7.2 Moved to this class from admin bar class.
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @param array $args {
|
||||
* (required) An array of arrays with field arguments.
|
||||
* @type string $name (required)
|
||||
* @type string $id (optional) Will be generated from $name if empty.
|
||||
* @type string $value (optional)
|
||||
* @type string $description (optional)
|
||||
* @type array $auto_js (optional) See VAA_View_Admin_As_Form::enable_auto_js().
|
||||
* @type bool $auto_showhide (optional) Pass `true` or int for auto show/hide description. Integer stands for the delay (default: 200).
|
||||
* @type array $values {
|
||||
* Array of radio options data.
|
||||
* @type array {
|
||||
* @type string $compare (required)
|
||||
* @type string $label (optional)
|
||||
* @type string $description (optional)
|
||||
* @type string $help (optional)
|
||||
* @type string $class (optional)
|
||||
* @type array $attr (optional)
|
||||
* @type bool $auto_showhide (optional) Overwrite $data.
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* @return string
|
||||
*/
|
||||
public static function do_radio( $args ) {
|
||||
$html = '';
|
||||
|
||||
if ( ! empty( $args['values'] ) ) {
|
||||
foreach ( $args['values'] as $val ) {
|
||||
|
||||
$id = esc_attr( ( ( ! empty( $args['id'] ) ) ? $args['id'] : $args['name'] ) . '-' . $val['compare'] );
|
||||
$name = str_replace( '-', '_', esc_attr( $args['name'] ) );
|
||||
|
||||
if ( empty( $args['value'] ) ) {
|
||||
$args['value'] = null;
|
||||
}
|
||||
$checked = checked( $args['value'], $val['compare'], false );
|
||||
$class = ( ! empty( $val['class'] ) ) ? ' ' . $val['class'] : '';
|
||||
$class .= ' ' . esc_attr( $args['name'] );
|
||||
|
||||
$val['attr']['type'] = 'radio';
|
||||
$val['attr']['id'] = $id;
|
||||
$val['attr']['name'] = $name;
|
||||
$val['attr']['value'] = $val['compare'];
|
||||
$val['attr']['class'] = 'radio' . $class;
|
||||
|
||||
$attr = $val['attr'];
|
||||
$attr = self::enable_auto_js( $attr, $args );
|
||||
$attr = self::parse_to_html_attr( $attr );
|
||||
|
||||
$label_attr = array();
|
||||
$desc_attr = array();
|
||||
// Custom validation required.
|
||||
if ( ( ! empty( $val['auto_showhide'] ) ) ||
|
||||
( ! isset( $val['auto_showhide'] ) && ! empty( $args['auto_showhide'] ) )
|
||||
) {
|
||||
self::enable_auto_showhide( $id . '-desc', $label_attr, $desc_attr );
|
||||
}
|
||||
|
||||
$html .= '<div class="vaa-radio-wrapper">';
|
||||
$html .= self::do_help( $val, array(), array(), $label_attr );
|
||||
$html .= '<input ' . $attr . ' ' . $checked . '/>';
|
||||
$html .= self::do_label( $val, $id, $label_attr );
|
||||
$html .= '<br>';
|
||||
$html .= self::do_description( $val, $desc_attr );
|
||||
$html .= '</div>';
|
||||
|
||||
} // End foreach().
|
||||
|
||||
$html .= self::do_description( $args );
|
||||
|
||||
} // End if().
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate selectbox HTML for node.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @since 1.6.3 Automatic show/hide description option.
|
||||
* @since 1.7.2 Moved to this class from admin bar class.
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @param array $args {
|
||||
* (required) An array of arrays with field arguments.
|
||||
* @type string $name (required)
|
||||
* @type string $id (optional) Will be generated from $name if empty.
|
||||
* @type string $value (optional)
|
||||
* @type string $label (optional)
|
||||
* @type string $description (optional)
|
||||
* @type string $help (optional)
|
||||
* @type string $class (optional)
|
||||
* @type array $attr (optional)
|
||||
* @type array $auto_js (optional) See VAA_View_Admin_As_Form::enable_auto_js().
|
||||
* @type bool $auto_showhide (optional) Pass `true` or int for auto show/hide description. Integer stands for the delay (default: 200).
|
||||
* @type array $values {
|
||||
* Arrays of selectbox value data.
|
||||
* @type array {
|
||||
* @type string $compare (required)
|
||||
* @type string $value (optional) Alias for compare.
|
||||
* @type string $label (optional)
|
||||
* @type string $class (optional)
|
||||
* @type array $attr (optional)
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* @return string
|
||||
*/
|
||||
public static function do_select( $args ) {
|
||||
$html = '';
|
||||
|
||||
if ( ! empty( $args['values'] ) ) {
|
||||
$id = esc_attr( ( ! empty( $args['id'] ) ) ? $args['id'] : $args['name'] );
|
||||
$name = str_replace( '-', '_', esc_attr( $args['name'] ) );
|
||||
|
||||
$label_attr = array();
|
||||
$desc_attr = array();
|
||||
self::enable_auto_showhide( $id . '-desc', $label_attr, $desc_attr, $args );
|
||||
|
||||
$html .= self::do_help( $args, array(), array(), $label_attr );
|
||||
$html .= self::do_label( $args, $id, $label_attr );
|
||||
|
||||
if ( empty( $args['value'] ) ) {
|
||||
$args['value'] = null;
|
||||
}
|
||||
|
||||
$class = ( ! empty( $args['class'] ) ) ? ' ' . $args['class'] : '';
|
||||
|
||||
$args['attr']['id'] = $id;
|
||||
$args['attr']['name'] = $name;
|
||||
$args['attr']['class'] = 'selectbox' . $class;
|
||||
|
||||
$attr = $args['attr'];
|
||||
$attr = self::enable_auto_js( $attr, $args );
|
||||
$attr = self::parse_to_html_attr( $attr );
|
||||
|
||||
$html .= '<select ' . $attr . '>';
|
||||
|
||||
foreach ( $args['values'] as $val ) {
|
||||
|
||||
if ( empty( $val['compare'] ) ) {
|
||||
$val['compare'] = ( ! empty( $val['value'] ) ) ? $val['value'] : false;
|
||||
}
|
||||
$label = ( ! empty( $val['label'] ) ) ? $val['label'] : $val['compare'];
|
||||
$selected = selected( $args['value'], $val['compare'], false );
|
||||
|
||||
$val['attr']['value'] = $val['compare'];
|
||||
$attr = self::parse_to_html_attr( $val['attr'] );
|
||||
|
||||
$html .= '<option ' . $attr . ' ' . $selected . '>' . $label . '</option>';
|
||||
|
||||
}
|
||||
$html .= '</select>';
|
||||
|
||||
$html .= self::do_description( $args, $desc_attr );
|
||||
|
||||
} // End if().
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns icon html for WP admin bar.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @since 1.6.3 Added second $attr parameter.
|
||||
* @since 1.7.2 Moved to this class from admin bar class.
|
||||
* @since 1.7.3 Added third $content parameter.
|
||||
* @since 1.7.6 Support SVG and file icons + Base64 encoded strings (just like WP admin menu's).
|
||||
* @static
|
||||
*
|
||||
* @param string $icon The icon class, file or base64 encoded string.
|
||||
* @param array $attr (optional) Extra attributes.
|
||||
* @param string $content (optional) Icon content.
|
||||
* @return string
|
||||
*/
|
||||
public static function do_icon( $icon, $attr = array(), $content = '' ) {
|
||||
$class = 'ab-icon';
|
||||
|
||||
if ( false === strpos( $icon, '/' ) &&
|
||||
0 !== strpos( $icon, 'data:' ) &&
|
||||
0 !== strpos( $icon, 'http' )
|
||||
) {
|
||||
// It's an icon class.
|
||||
$class .= ' dashicons ' . $icon;
|
||||
} else {
|
||||
// It's a Base64 encoded string or file URL.
|
||||
$class .= ' vaa-icon-image';
|
||||
$attr = self::merge_attr( $attr, array(
|
||||
'style' => array( 'background-image: url("' . $icon . '") !important' ),
|
||||
) );
|
||||
}
|
||||
|
||||
if ( ! empty( $attr['class'] ) ) {
|
||||
$class .= ' ' . (string) $attr['class'];
|
||||
}
|
||||
$attr['class'] = $class;
|
||||
$attr['aria-hidden'] = 'true';
|
||||
$attr = self::parse_to_html_attr( $attr );
|
||||
return '<span ' . $attr . '>' . $content . '</span>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns label html for WP admin bar.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @since 1.6.3 Added third $attr parameter.
|
||||
* @since 1.7.2 Moved to this class from admin bar class.
|
||||
* @static
|
||||
*
|
||||
* @param string|array $label The label. Also accepts an array with a `label` key.
|
||||
* @param string $for (optional) Add `for` attribute.
|
||||
* @param array $attr (optional) Extra attributes.
|
||||
* @return string
|
||||
*/
|
||||
public static function do_label( $label, $for = '', $attr = array() ) {
|
||||
if ( is_array( $label ) ) {
|
||||
if ( empty( $label['label'] ) ) {
|
||||
return '';
|
||||
}
|
||||
$label = $label['label'];
|
||||
}
|
||||
$attr['for'] = $for;
|
||||
$attr = self::parse_to_html_attr( $attr );
|
||||
return '<label ' . $attr . '>' . $label . '</label>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description html for WP admin bar.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @since 1.6.3 Added second $attr parameter.
|
||||
* @since 1.7.2 Moved to this class from admin bar class.
|
||||
* @since 1.7.5 Third parameter: element type.
|
||||
* @static
|
||||
*
|
||||
* @param string|array $text The description text. Also accepts an array with a `description` key.
|
||||
* @param array $attr (optional) Extra attributes.
|
||||
* @param string $elem (optional) HTML element type. Default: paragraph.
|
||||
* @return string
|
||||
*/
|
||||
public static function do_description( $text, $attr = array(), $elem = 'p' ) {
|
||||
if ( is_array( $text ) ) {
|
||||
if ( empty( $text['description'] ) ) {
|
||||
return '';
|
||||
}
|
||||
$text = $text['description'];
|
||||
} elseif ( ! is_string( $text ) ) {
|
||||
return '';
|
||||
}
|
||||
$attr['class'] = 'ab-item description' . ( ( ! empty( $attr['class'] ) ) ? ' ' . $attr['class'] : '');
|
||||
$attr = self::parse_to_html_attr( $attr );
|
||||
return '<' . $elem . ' ' . $attr . '>' . $text . '</' . $elem . '>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns help tooltip html for WP admin bar.
|
||||
* It will also change auto show/hide trigger to the help icon if the help text is a boolean true instead of a string.
|
||||
* @todo document this properly.
|
||||
*
|
||||
* @since 1.7.3
|
||||
* @static
|
||||
*
|
||||
* @param string|array $text The help text. Also accepts an array with a `help` key.
|
||||
* @param array $help_attr (optional) Extra help icon attributes.
|
||||
* @param array $tooltip_attr (optional) Extra tooltip attributes.
|
||||
* @param array $showhide_attr (optional) Overwrite existing show/hide attributes.
|
||||
* @return string
|
||||
*/
|
||||
public static function do_help( $text, $help_attr = array(), $tooltip_attr = array(), &$showhide_attr = array() ) {
|
||||
if ( is_array( $text ) ) {
|
||||
if ( empty( $text['help'] ) ) {
|
||||
return '';
|
||||
}
|
||||
$text = $text['help'];
|
||||
} elseif ( ! $text ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Reset auto show/hide settings is $test is true. Disables show/hide on the label and sets it on the help icon.
|
||||
$help_attr = self::merge_attr( $help_attr, array(
|
||||
'class' => 'vaa-help',
|
||||
) );
|
||||
if ( true === $text ) {
|
||||
// Do nothing is auto show/hide isn't enabled.
|
||||
if ( ! isset( $showhide_attr['vaa-showhide'] ) ) {
|
||||
return '';
|
||||
}
|
||||
$help_attr['class'] .= ' ab-vaa-showhide';
|
||||
$help_attr['vaa-showhide'] = $showhide_attr['vaa-showhide'];
|
||||
unset( $showhide_attr['vaa-showhide'] );
|
||||
}
|
||||
|
||||
if ( is_string( $text ) ) {
|
||||
// ab-sub-wrapper for background, ab-item for text color.
|
||||
$tooltip_attr = self::merge_attr( array(
|
||||
'class' => 'ab-item ab-sub-wrapper vaa-tooltip',
|
||||
), $tooltip_attr );
|
||||
$tooltip_attr = self::parse_to_html_attr( $tooltip_attr );
|
||||
$text = '<span ' . $tooltip_attr . '>' . $text . '</span>';
|
||||
} else {
|
||||
$text = '';
|
||||
}
|
||||
|
||||
return self::do_icon( 'dashicons-editor-help', $help_attr, $text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto-generate a JSON attribute for automatic JS handling.
|
||||
*
|
||||
* @internal Please do not use this yet since it's in development and subject to changes.
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @static
|
||||
*
|
||||
* @param array $attr The attributes array to append to.
|
||||
* @param array $args {
|
||||
* The form element args. Below parameters should be in the `auto_js` key.
|
||||
*
|
||||
* @type string $setting (required) The setting key.
|
||||
* @type string $confirm (optional) Let JS generate a confirm box before running ajax?
|
||||
* @type string $refresh (optional) Refresh after ajax return?
|
||||
* @type string $key (optional, if values exists). The option key.
|
||||
* @type array $values {
|
||||
* The array of options. Alias: `value`.
|
||||
* All options need to be key => value pairs. See type documentation.
|
||||
* Recursive arrays supported (values in values).
|
||||
* If a key parameter exists this array will be added as the values of that key.
|
||||
*
|
||||
* @type bool $required (optional) Whether this option is required or not (default: true).
|
||||
* @type string $element (optional) The HTML element to use as selector (overwrites current element).
|
||||
* @type string $attr (optional) Get an attribute value instead of using .val()?
|
||||
* @type bool $json (optional) Parse value as JSON? (Default parser only).
|
||||
* @type string $parser (optional) The value processor.
|
||||
* `default` or empty : Normal handling.
|
||||
* (single checkbox or input/textarea value)
|
||||
* `multiple` or `multi` : Get multiple values.
|
||||
* (default: name => value | checkbox: value => checked)
|
||||
* `selected` : Get selected values only.
|
||||
* (default: non empty values | checkbox: values of checked elements)
|
||||
* }
|
||||
* }
|
||||
* @return array
|
||||
*/
|
||||
public static function enable_auto_js( $attr, $args ) {
|
||||
if ( ! empty( $args['auto_js'] ) ) {
|
||||
|
||||
// Auto-generate values array based upon key and value keys.
|
||||
if ( ! empty( $args['auto_js']['key'] ) ) {
|
||||
if ( empty( $args['auto_js']['values'] ) ) {
|
||||
// Single value data.
|
||||
$value = null;
|
||||
if ( ! empty( $args['auto_js']['value'] ) ) {
|
||||
$value = $args['auto_js']['value'];
|
||||
}
|
||||
} else {
|
||||
// Set the values as the values of the supplied key.
|
||||
$value = array( 'values' => $args['auto_js']['values'] );
|
||||
}
|
||||
$values = array( $args['auto_js']['key'] => $value );
|
||||
$args['auto_js']['values'] = $values;
|
||||
}
|
||||
unset( $args['auto_js']['key'] );
|
||||
unset( $args['auto_js']['value'] );
|
||||
|
||||
$attr['vaa-auto-js'] = wp_json_encode( $args['auto_js'] );
|
||||
}
|
||||
return $attr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update auto show/hide trigger and target attributes to enable auto show/hide functionality.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7.2 Moved to this class from admin bar class.
|
||||
* @since 1.7.3 Renamed from `enable_auto_showhide_desc` + allow multiple values for trigger.
|
||||
* @static
|
||||
*
|
||||
* @param string $target The target element.
|
||||
* @param array $trigger_attr Trigger element attributes.
|
||||
* @param array $target_attr (optional) Target element attributes.
|
||||
* @param array $args {
|
||||
* (optional)Pass the full arguments array for auto_showhide key validation.
|
||||
*
|
||||
* @type bool|int|array $auto_showhide {
|
||||
* Pass `true` for default handling of the first function parameter target.
|
||||
* Pass an integer to just set the delay for the first function parameter target.
|
||||
* Pass an array for full target data (multiple allowed), see parameters below. This will overwrite the first function parameter.
|
||||
*
|
||||
* @type array {
|
||||
* @type string $target The selector string for jQuery.
|
||||
* @type int $delay (optional) Set the delay in milliseconds.
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* @return void
|
||||
*/
|
||||
public static function enable_auto_showhide( $target, &$trigger_attr = array(), &$target_attr = array(), $args = array() ) {
|
||||
if ( ! empty( $args ) && empty( $args['auto_showhide'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$trigger_target = '.' . $target;
|
||||
if ( ! empty( $args['auto_showhide'] ) && ! is_bool( $args['auto_showhide'] ) ) {
|
||||
// Just the delay, keep the target value.
|
||||
if ( is_numeric( $args['auto_showhide'] ) ) {
|
||||
$trigger_target = wp_json_encode( array(
|
||||
'target' => $trigger_target,
|
||||
'delay' => $args['auto_showhide'],
|
||||
) );
|
||||
}
|
||||
// Full data. Multiple targets allowed,
|
||||
elseif ( is_array( $args['auto_showhide'] ) ) {
|
||||
$trigger_target = wp_json_encode( $args['auto_showhide'] );
|
||||
}
|
||||
}
|
||||
|
||||
$trigger_attr = self::merge_attr( $trigger_attr, array(
|
||||
'class' => 'ab-vaa-showhide',
|
||||
'vaa-showhide' => $trigger_target,
|
||||
) );
|
||||
|
||||
// @todo Find a way to auto create multiple targets.
|
||||
if ( ! empty( $target ) ) {
|
||||
$target_attr = self::merge_attr( $target_attr, array(
|
||||
'class' => $target,
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge two arrays of attributes into one, combining values.
|
||||
* It currently doesn't convert variable types.
|
||||
*
|
||||
* @since 1.7.3
|
||||
* @static
|
||||
*
|
||||
* @param array $attr The current attributes.
|
||||
* @param array $new The new attributes. Attribute names as key.
|
||||
* @return string[]
|
||||
*/
|
||||
public static function merge_attr( $attr, $new ) {
|
||||
foreach ( $new as $key => $value ) {
|
||||
if ( empty( $attr[ $key ] ) ) {
|
||||
$attr[ $key ] = $value;
|
||||
continue;
|
||||
}
|
||||
if ( is_array( $attr[ $key ] ) ) {
|
||||
$attr[ $key ] = array_merge( $attr[ $key ], (array) $value );
|
||||
continue;
|
||||
}
|
||||
if ( is_array( $value ) ) {
|
||||
$value = implode( ' ', $value );
|
||||
}
|
||||
$attr[ $key ] .= ( ! empty( $value ) ) ? ' ' . $value : '';
|
||||
}
|
||||
return $attr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array of attributes to a HTML string format starting with a space.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @since 1.7 Renamed from `parse_attr_to_html`
|
||||
* @since 1.7.2 Support array values. (Example: CSS classes). Moved to this class from admin bar class.
|
||||
* @static
|
||||
*
|
||||
* @param array $array Array to parse. (attribute => value pairs)
|
||||
* @return string
|
||||
*/
|
||||
public static function parse_to_html_attr( $array ) {
|
||||
$str = '';
|
||||
if ( is_array( $array ) && ! empty( $array ) ) {
|
||||
foreach ( $array as $attr => $value ) {
|
||||
if ( is_array( $value ) ) {
|
||||
$value = implode( ' ', $value );
|
||||
}
|
||||
$array[ $attr ] = esc_attr( $attr ) . '="' . esc_attr( $value ) . '"';
|
||||
}
|
||||
$str = implode( ' ', $array );
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_Form.
|
||||
455
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-hooks.php
Executable file
455
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-hooks.php
Executable file
@@ -0,0 +1,455 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Class Hooks
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hooks class that holds all registered actions and filters.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @link https://github.com/JoryHogeveen/view-admin-as/wiki/Actions-&-Filters
|
||||
* @since 1.8
|
||||
* @version 1.8
|
||||
*/
|
||||
class VAA_View_Admin_As_Hooks
|
||||
{
|
||||
/**
|
||||
* The array of actions registered with WordPress.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access protected
|
||||
* @var array $actions The actions registered with WordPress.
|
||||
*/
|
||||
protected $_actions = array();
|
||||
|
||||
/**
|
||||
* The array of filters registered with WordPress.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access protected
|
||||
* @var array $filters The filters registered with WordPress.
|
||||
*/
|
||||
protected $_filters = array();
|
||||
|
||||
/**
|
||||
* Convert callable into an identifier.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access protected
|
||||
* @see _wp_filter_build_unique_id()
|
||||
* @param string $hook The name of the WordPress hook (that is, actions or filters).
|
||||
* @param callable $callback The callable.
|
||||
* @param int $priority The priority at which the function would be fired. Default: 10.
|
||||
* @return string
|
||||
*/
|
||||
protected function _get_identifier( $hook, $callback, $priority ) {
|
||||
if ( function_exists( '_wp_filter_build_unique_id' ) ) {
|
||||
return _wp_filter_build_unique_id( $hook, $callback, $priority );
|
||||
}
|
||||
// Fallback since `_wp_filter_build_unique_id()` is a private WP function.
|
||||
return VAA_API::callable_to_string( $callback );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new action to the collection to be registered with WordPress.
|
||||
*
|
||||
* @since 1.8
|
||||
* @see add_action()
|
||||
* @param string $hook The name of the WordPress action.
|
||||
* @param callable $callback The callable.
|
||||
* @param int $priority (optional) The priority at which the function should be fired. Default: 10.
|
||||
* @param int $accepted_args (optional) The number of arguments that should be passed to the $callback. Default: 1.
|
||||
*/
|
||||
public function add_action( $hook, $callback, $priority = 10, $accepted_args = 1 ) {
|
||||
add_action( $hook, $callback, $priority, $accepted_args );
|
||||
$this->_actions = $this->_add( $this->_actions, $hook, $callback, $priority, $accepted_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new filter to the collection to be registered with WordPress.
|
||||
*
|
||||
* @since 1.8
|
||||
* @see add_filter()
|
||||
* @param string $hook The name of the WordPress filter.
|
||||
* @param callable $callback The callable.
|
||||
* @param int $priority (optional) The priority at which the function should be fired. Default: 10.
|
||||
* @param int $accepted_args (optional) The number of arguments that should be passed to the $callback. Default: 1.
|
||||
*/
|
||||
public function add_filter( $hook, $callback, $priority = 10, $accepted_args = 1 ) {
|
||||
add_filter( $hook, $callback, $priority, $accepted_args );
|
||||
$this->_filters = $this->_add( $this->_filters, $hook, $callback, $priority, $accepted_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* A utility function that is used to register the hooks into a single collection.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access protected
|
||||
* @param array[] $hooks The collection of hooks (that is, actions or filters).
|
||||
* @param string $hook The name of the WordPress filter that is being registered.
|
||||
* @param callable $callback The callable.
|
||||
* @param int $priority The priority at which the function should be fired.
|
||||
* @param int $accepted_args The number of arguments that should be passed to the $callback.
|
||||
* @return array The collection of actions and filters registered with WordPress.
|
||||
*/
|
||||
protected function _add( $hooks, $hook, $callback, $priority, $accepted_args ) {
|
||||
if ( ! isset( $hooks[ $hook ] ) ) {
|
||||
$hooks[ $hook ] = array();
|
||||
}
|
||||
if ( ! isset( $hooks[ $hook ][ $priority ] ) ) {
|
||||
$hooks[ $hook ][ $priority ] = array();
|
||||
}
|
||||
$hooks[ $hook ][ $priority ][ $this->_get_identifier( $hook, $callback, $priority ) ] = array(
|
||||
'hook' => $hook,
|
||||
'callback' => $callback,
|
||||
'priority' => $priority,
|
||||
'accepted_args' => $accepted_args,
|
||||
);
|
||||
ksort( $hooks[ $hook ] );
|
||||
return $hooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an action from the collection registered with WordPress.
|
||||
*
|
||||
* @since 1.8
|
||||
* @see remove_action()
|
||||
* @param string $hook The name of the WordPress action.
|
||||
* @param callable $callback The callable.
|
||||
* @param int $priority (optional) The priority at which the function would be fired. Default: 10.
|
||||
* Pass `null` to let this class try to find the priority.
|
||||
*/
|
||||
public function remove_action( $hook, $callback, $priority = 10 ) {
|
||||
$priority = $this->_validate_priority( $this->_actions, $hook, $callback, $priority );
|
||||
remove_action( $hook, $callback, $priority );
|
||||
$this->_actions = $this->_remove( $this->_actions, $hook, $callback, $priority );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a filter from the collection registered with WordPress.
|
||||
*
|
||||
* @since 1.8
|
||||
* @see remove_filter()
|
||||
* @param string $hook The name of the WordPress filter.
|
||||
* @param callable $callback The callable.
|
||||
* @param int $priority (optional) The priority at which the function would be fired. Default: 10.
|
||||
* Pass `null` to let this class try to find the priority.
|
||||
*/
|
||||
public function remove_filter( $hook, $callback, $priority = 10 ) {
|
||||
$priority = $this->_validate_priority( $this->_filters, $hook, $callback, $priority );
|
||||
remove_filter( $hook, $callback, $priority );
|
||||
$this->_filters = $this->_remove( $this->_filters, $hook, $callback, $priority );
|
||||
}
|
||||
|
||||
/**
|
||||
* A utility function that is used to remove registered hooks from a single collection.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access protected
|
||||
* @param array[] $hooks The collection of hooks (that is, actions or filters).
|
||||
* @param string $hook The name of the WordPress filter.
|
||||
* @param callable $callback The callable.
|
||||
* @param int $priority The priority at which the function should be fired.
|
||||
* @return array The collection of actions and filters registered with WordPress.
|
||||
*/
|
||||
protected function _remove( $hooks, $hook, $callback, $priority ) {
|
||||
unset( $hooks[ $hook ][ $priority ][ $this->_get_identifier( $hook, $callback, $priority ) ] );
|
||||
if ( empty( $hooks[ $hook ][ $priority ] ) ) {
|
||||
unset( $hooks[ $hook ][ $priority ] );
|
||||
}
|
||||
return $hooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all hooks from the collection registered with WordPress.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param string $hook The name of the WordPress action.
|
||||
* @param int|bool $priority (optional) The priority at which the function would be fired. Default: false (all).
|
||||
*/
|
||||
public function remove_all_hooks( $hook, $priority = false ) {
|
||||
$this->remove_all_actions( $hook, $priority );
|
||||
$this->remove_all_filters( $hook, $priority );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all actions from the collection registered with WordPress.
|
||||
*
|
||||
* @since 1.8
|
||||
* @see remove_all_actions()
|
||||
* @param string $hook The name of the WordPress action.
|
||||
* @param int|bool $priority (optional) The priority at which the function would be fired. Default: false (all).
|
||||
*/
|
||||
public function remove_all_actions( $hook, $priority = false ) {
|
||||
remove_all_actions( $hook, $priority );
|
||||
$this->_actions = $this->_remove_all( $this->_actions, $hook, $priority );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all filters from the collection registered with WordPress.
|
||||
*
|
||||
* @since 1.8
|
||||
* @see remove_all_filters()
|
||||
* @param string $hook The name of the WordPress filter.
|
||||
* @param int|bool $priority (optional) The priority at which the function would be fired. Default: false (all).
|
||||
*/
|
||||
public function remove_all_filters( $hook, $priority = false ) {
|
||||
remove_all_filters( $hook, $priority );
|
||||
$this->_filters = $this->_remove_all( $this->_filters, $hook, $priority );
|
||||
}
|
||||
|
||||
/**
|
||||
* A utility function that is used to remove all registered hooks from a single collection.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access protected
|
||||
* @param array[] $hooks The collection of hooks (that is, actions or filters).
|
||||
* @param string $hook The name of the WordPress filter.
|
||||
* @param int|bool $priority The priority at which the function should be fired.
|
||||
* @return array The collection of actions and filters registered with WordPress.
|
||||
*/
|
||||
protected function _remove_all( $hooks, $hook, $priority ) {
|
||||
if ( false !== $priority ) {
|
||||
unset( $hooks[ $hook ][ $priority ] );
|
||||
return $hooks;
|
||||
}
|
||||
unset( $hooks[ $hook ] );
|
||||
return $hooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all plugin hooks from the collection registered with WordPress.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param string $hook (optional) The name of the WordPress action.
|
||||
* @param int|bool $priority (optional) The priority at which the function would be fired. Default: false (all).
|
||||
* @param string $class (optional) Only remove filters from a specific class.
|
||||
*/
|
||||
public function remove_own_hooks( $hook = null, $priority = false, $class = '' ) {
|
||||
$this->remove_own_actions( $hook, $priority, $class );
|
||||
$this->remove_own_filters( $hook, $priority, $class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all plugin actions from the collection registered with WordPress.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param string $hook (optional) The name of the WordPress action.
|
||||
* @param int|bool $priority (optional) The priority at which the function would be fired. Default: false (all).
|
||||
* @param string $class (optional) Only remove filters from a specific class.
|
||||
*/
|
||||
public function remove_own_actions( $hook = null, $priority = false, $class = '' ) {
|
||||
$this->_actions = $this->_remove_own( $this->_actions, $hook, $priority, 'remove_action', $class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all plugin filters from the collection registered with WordPress.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param string $hook (optional) The name of the WordPress filter.
|
||||
* @param int|bool $priority (optional) The priority at which the function would be fired. Default: false (all).
|
||||
* @param string $class (optional) Only remove filters from a specific class.
|
||||
*/
|
||||
public function remove_own_filters( $hook = null, $priority = false, $class = '' ) {
|
||||
$this->_filters = $this->_remove_own( $this->_filters, $hook, $priority, 'remove_filter', $class );
|
||||
}
|
||||
|
||||
/**
|
||||
* A utility function that is used to remove all registered plugin hooks from a single collection.
|
||||
*
|
||||
* Disable some PHPMD checks for this method.
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
* @todo Refactor to enable above checks?
|
||||
*
|
||||
* @since 1.8
|
||||
* @access protected
|
||||
* @param array[] $hooks The collection of hooks (that is, actions or filters).
|
||||
* @param string $hook The name of the WordPress filter.
|
||||
* @param int|bool $priority The priority at which the function should be fired.
|
||||
* @param callable $function The function to use for removal.
|
||||
* @param string $class Only remove filters from a specific class.
|
||||
* @return array The collection of actions and filters registered with WordPress.
|
||||
*/
|
||||
protected function _remove_own( $hooks, $hook, $priority, $function, $class ) {
|
||||
|
||||
// Remove specific priority from hook.
|
||||
if ( false !== $priority ) {
|
||||
if ( isset( $hooks[ $hook ][ $priority ] ) ) {
|
||||
foreach ( (array) $hooks[ $hook ][ $priority ] as $id => $args ) {
|
||||
if ( $class ) {
|
||||
$class_compare = ( isset( $args['callback'][0] ) ) ? $args['callback'][0] : '';
|
||||
if ( is_object( $class_compare ) ) {
|
||||
$class_compare = get_class( $class_compare );
|
||||
}
|
||||
if ( $class !== $class_compare ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Remove it from WordPress.
|
||||
$this->$function( $hook, $args['callback'], $priority );
|
||||
unset( $hooks[ $hook ][ $priority ][ $id ] );
|
||||
}
|
||||
if ( empty( $hooks[ $hook ][ $priority ] ) ) {
|
||||
unset( $hooks[ $hook ][ $priority ] );
|
||||
}
|
||||
}
|
||||
return $hooks;
|
||||
}
|
||||
|
||||
// Remove specific hook.
|
||||
if ( null !== $hook ) {
|
||||
if ( isset( $hooks[ $hook ] ) ) {
|
||||
foreach ( (array) $hooks[ $hook ] as $priority => $foo ) {
|
||||
$hooks = $this->_remove_own( $hooks, $hook, $priority, $function, $class );
|
||||
}
|
||||
if ( empty( $hooks[ $hook ] ) ) {
|
||||
unset( $hooks[ $hook ] );
|
||||
}
|
||||
}
|
||||
return $hooks;
|
||||
}
|
||||
|
||||
// Remove everything.
|
||||
foreach ( (array) $hooks as $hook => $foo ) {
|
||||
$hooks = $this->_remove_own( $hooks, $hook, false, $function, $class );
|
||||
}
|
||||
|
||||
return $hooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the priority value.
|
||||
* If it's passed as `null` it will attempt to find it.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param array[] $hooks The collection of hooks (that is, actions or filters).
|
||||
* @param string $hook The name of the WordPress filter.
|
||||
* @param callable $callback The callable.
|
||||
* @param int $priority The priority at which the function should be fired.
|
||||
* @return int Default: 10.
|
||||
*/
|
||||
protected function _validate_priority( $hooks, $hook, $callback, $priority ) {
|
||||
if ( ! is_numeric( $priority ) ) {
|
||||
$priority = $this->_find_priority( $hooks, $hook, $callback );
|
||||
if ( ! $priority ) {
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
return (int) $priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the priority of a hook if unknown.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param array[] $hooks The collection of hooks (that is, actions or filters).
|
||||
* @param string $hook The name of the WordPress filter.
|
||||
* @param callable $callback The callable.
|
||||
* @return int
|
||||
*/
|
||||
protected function _find_priority( $hooks, $hook, $callback ) {
|
||||
if ( ! isset( $hooks[ $hook ] ) ) {
|
||||
return null;
|
||||
}
|
||||
foreach ( (array) $hooks[ $hook ] as $priority => $registered ) {
|
||||
foreach ( $registered as $args ) {
|
||||
if ( $callback === $args['callback'] ) {
|
||||
return $priority;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all registered hooks data.
|
||||
* Can be used for debugging.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param string|array $keys The hook array keys to look for. Each key stands for a level deeper in the array.
|
||||
* Order: hook type >> hook name >> priority >> function id >> hook args.
|
||||
* In case of a string it will stand for the hook type.
|
||||
* @param bool $objects Return the full object of a callback? Default: false, can cause PHP memory issues.
|
||||
* @return array[]|mixed
|
||||
*/
|
||||
public function _get_hooks( $keys = null, $objects = false ) {
|
||||
$data = array(
|
||||
'actions' => $this->_actions,
|
||||
'filters' => $this->_filters,
|
||||
);
|
||||
if ( ! $objects ) {
|
||||
// Don't return full objects.
|
||||
$data = $this->_convert_callback( $data );
|
||||
}
|
||||
if ( $keys ) {
|
||||
$keys = (array) $keys;
|
||||
foreach ( $keys as $key ) {
|
||||
$data = VAA_API::get_array_data( $data, $key );
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all registered actions.
|
||||
* Can be used for debugging.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param string|array $keys The hook array keys to look for. Each key stands for a level deeper in the array.
|
||||
* Order: hook name >> priority >> function id >> hook args.
|
||||
* In case of a string it will stand for the hook name.
|
||||
* @param bool $objects Return the full object of a callback? Default: false, can cause PHP memory issues.
|
||||
* @return array[]|mixed
|
||||
*/
|
||||
public function _get_actions( $keys = null, $objects = false ) {
|
||||
$keys = (array) $keys;
|
||||
array_unshift( $keys, 'actions' );
|
||||
return $this->_get_hooks( $keys, $objects );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all registered filters.
|
||||
* Can be used for debugging.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param string|array $keys The hook array keys to look for. Each key stands for a level deeper in the array.
|
||||
* Order: hook name >> priority >> function id >> hook args.
|
||||
* In case of a string it will stand for the hook name.
|
||||
* @param bool $objects Return the full object of a callback? Default: false, can cause PHP memory issues.
|
||||
* @return array[]|mixed
|
||||
*/
|
||||
public function _get_filters( $keys = null, $objects = false ) {
|
||||
$keys = (array) $keys;
|
||||
array_unshift( $keys, 'filters' );
|
||||
return $this->_get_hooks( $keys, $objects );
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert object types into object class names instead of full object data.
|
||||
* @since 1.8
|
||||
* @param array $hooks The collection of hooks (that is, actions or filters).
|
||||
* @return array
|
||||
*/
|
||||
protected function _convert_callback( $hooks ) {
|
||||
foreach ( (array) $hooks as $key => $val ) {
|
||||
if ( is_object( $val ) ) {
|
||||
$hooks[ $key ] = get_class( $val );
|
||||
continue;
|
||||
}
|
||||
if ( is_array( $val ) ) {
|
||||
$hooks[ $key ] = $this->_convert_callback( $val );
|
||||
}
|
||||
}
|
||||
return $hooks;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_Hooks.
|
||||
230
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-module.php
Executable file
230
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-module.php
Executable file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Class Module
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Base class for modules that use option data etc.
|
||||
* Use this class as an extender for VAA modules other than view types.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.5 (This was one class with VAA_View_Admin_As_Class_Base)
|
||||
* @version 1.8
|
||||
* @uses \VAA_View_Admin_As_Base Extends class
|
||||
*/
|
||||
abstract class VAA_View_Admin_As_Module extends VAA_View_Admin_As_Base
|
||||
{
|
||||
/**
|
||||
* Option key.
|
||||
*
|
||||
* @since 1.5
|
||||
* @var string
|
||||
*/
|
||||
protected $optionKey = '';
|
||||
|
||||
/**
|
||||
* Option data.
|
||||
*
|
||||
* @since 1.5
|
||||
* @var mixed
|
||||
*/
|
||||
protected $optionData = false;
|
||||
|
||||
/**
|
||||
* Enable functionalities?
|
||||
*
|
||||
* @since 1.5
|
||||
* @var bool
|
||||
*/
|
||||
protected $enable = false;
|
||||
|
||||
/**
|
||||
* Script localization data.
|
||||
*
|
||||
* @since 1.6
|
||||
* @var array
|
||||
*/
|
||||
protected $scriptLocalization = array();
|
||||
|
||||
/**
|
||||
* Is enabled?
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function is_enabled() {
|
||||
return (bool) $this->enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set plugin enabled true/false.
|
||||
*
|
||||
* @since 1.5.1
|
||||
* @since 1.6.2 Make database update optional.
|
||||
* @since 1.8 Make this method public.
|
||||
* @access public
|
||||
* @param bool $bool Enable or disable?
|
||||
* @param bool $update_db Do database update? (default true).
|
||||
* @return bool
|
||||
*/
|
||||
public function set_enable( $bool = false, $update_db = true ) {
|
||||
$success = true;
|
||||
if ( $update_db && $this->get_optionKey() ) {
|
||||
$success = $this->update_optionData( (bool) $bool, 'enable', true );
|
||||
}
|
||||
if ( $success ) {
|
||||
$this->enable = (bool) $bool;
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for ajax return data.
|
||||
* Merges second param with data defaults.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @param bool $success Success return.
|
||||
* @param array $data Array of detailed info.
|
||||
* @param string $type Notice type.
|
||||
* @return array
|
||||
*/
|
||||
public function ajax_data_return( $success, $data, $type = null ) {
|
||||
if ( ! is_string( $type ) ) {
|
||||
$type = ( $success ) ? 'success' : 'error';
|
||||
}
|
||||
$data = wp_parse_args( $data, array(
|
||||
'display' => 'notice',
|
||||
'type' => $type,
|
||||
) );
|
||||
return array(
|
||||
'success' => (bool) $success,
|
||||
'data' => $data,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for ajax notice return data.
|
||||
* Merges second param with data defaults.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @param bool $success Success return.
|
||||
* @param array $data Array of detailed info.
|
||||
* @param string $type Notice type.
|
||||
* @return array
|
||||
*/
|
||||
public function ajax_data_notice( $success, $data, $type = null ) {
|
||||
$data['display'] = 'notice';
|
||||
return $this->ajax_data_return( $success, $data, $type );
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for ajax popup return data.
|
||||
* Merges second param with data defaults.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @param bool $success Success return.
|
||||
* @param array $data Array of detailed info.
|
||||
* @param string $type Popup type.
|
||||
* @return array
|
||||
*/
|
||||
public function ajax_data_popup( $success, $data, $type = null ) {
|
||||
$data['display'] = 'popup';
|
||||
return $this->ajax_data_return( $success, $data, $type );
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple data validation.
|
||||
* Meant to be overwritten by subclass.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @param null $null Null.
|
||||
* @param mixed $data The view data.
|
||||
* @return mixed
|
||||
*/
|
||||
public function validate_view_data( $null, $data = null ) {
|
||||
if ( $data ) {
|
||||
return $data;
|
||||
}
|
||||
return $null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class localisation strings
|
||||
* @param string $key (optional) Data key.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_scriptLocalization( $key = null ) {
|
||||
return VAA_API::get_array_data( $this->scriptLocalization, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the option key as used in the options table.
|
||||
* @return string
|
||||
*/
|
||||
public function get_optionKey() {
|
||||
return (string) $this->optionKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class option data.
|
||||
* @param string $key (optional) Data key.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_optionData( $key = null ) {
|
||||
return VAA_API::get_array_data( $this->optionData, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the class localisation strings
|
||||
* @param mixed $val Data.
|
||||
* @param string $key (optional) Data key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
*/
|
||||
protected function set_scriptLocalization( $val, $key = null, $append = false ) {
|
||||
$this->scriptLocalization = (array) VAA_API::set_array_data( $this->scriptLocalization, $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the option key as used in the options table.
|
||||
* @param string $val Option key.
|
||||
*/
|
||||
protected function set_optionKey( $val ) {
|
||||
$this->optionKey = (string) $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the class option data.
|
||||
* @param mixed $val Data.
|
||||
* @param string $key (optional) Data key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
*/
|
||||
protected function set_optionData( $val, $key = null, $append = false ) {
|
||||
$this->optionData = VAA_API::set_array_data( $this->optionData, $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the class option data.
|
||||
* @param mixed $val Data.
|
||||
* @param string $key (optional) Data key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
* @return bool
|
||||
*/
|
||||
protected function update_optionData( $val, $key = null, $append = false ) {
|
||||
$this->set_optionData( $val, $key, $append );
|
||||
return update_option( $this->get_optionKey(), $this->optionData );
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_Module.
|
||||
926
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-settings.php
Executable file
926
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-settings.php
Executable file
@@ -0,0 +1,926 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Class Settings
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings class that stores the VAA settings for use.
|
||||
*
|
||||
* @see VAA_View_Admin_As_Store
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.7
|
||||
* @version 1.8
|
||||
* @uses \VAA_View_Admin_As_Base Extends class
|
||||
*/
|
||||
class VAA_View_Admin_As_Settings extends VAA_View_Admin_As_Base
|
||||
{
|
||||
/**
|
||||
* The key to use for filters.
|
||||
* Passed to __construct() as first parameter.
|
||||
*
|
||||
* @since 1.8
|
||||
* @var string
|
||||
*/
|
||||
private $_filter_postfix = '';
|
||||
|
||||
/**
|
||||
* Is this option for a network installation?
|
||||
* Can only be set with set_for_network().
|
||||
*
|
||||
* @since 1.7.5
|
||||
* @see \VAA_View_Admin_As_Settings::store_optionData()
|
||||
* @var bool
|
||||
*/
|
||||
protected $for_network = false;
|
||||
|
||||
/**
|
||||
* The user ID for whom this metadata is for.
|
||||
* Can only be set with store_userMeta().
|
||||
*
|
||||
* @since 1.7.5
|
||||
* @see \VAA_View_Admin_As_Settings::store_userMeta()
|
||||
* @var int
|
||||
*/
|
||||
protected $for_user = null;
|
||||
|
||||
/**
|
||||
* Database option key.
|
||||
* Always starts with `vaa_`.
|
||||
* Keys are parsed with underscores as spacing.
|
||||
*
|
||||
* @since 1.4
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.7 Moved to this class from store class.
|
||||
* @var string
|
||||
*/
|
||||
protected $optionKey = null;
|
||||
|
||||
/**
|
||||
* Database option data.
|
||||
*
|
||||
* @since 1.4
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.7 Moved to this class from store class.
|
||||
* @var array
|
||||
*/
|
||||
protected $optionData = array();
|
||||
|
||||
/**
|
||||
* User meta key for settings ans views.
|
||||
* Always starts with `vaa-`.
|
||||
* Keys are parsed with dashes as spacing.
|
||||
*
|
||||
* @since 1.3.4
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.7 Moved to this class from store class.
|
||||
* @var string
|
||||
*/
|
||||
protected $userMetaKey = null;
|
||||
|
||||
/**
|
||||
* User meta value for settings ans views.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.7 Moved to this class from store class.
|
||||
* @var array
|
||||
*/
|
||||
protected $userMeta = array();
|
||||
|
||||
/**
|
||||
* User meta from all users.
|
||||
*
|
||||
* @since 1.8
|
||||
* @var array
|
||||
*/
|
||||
protected $allUserMeta = array();
|
||||
|
||||
/**
|
||||
* Array of default settings.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.7 Moved to this class from store class.
|
||||
* @var array
|
||||
*/
|
||||
protected $defaultSettings = array();
|
||||
|
||||
/**
|
||||
* Array of allowed settings.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.7 Moved to this class from store class.
|
||||
* @var array
|
||||
*/
|
||||
protected $allowedSettings = array();
|
||||
|
||||
/**
|
||||
* Array of default settings.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.5.2 Added force_group_users.
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.6.1 Added freeze_locale.
|
||||
* @since 1.7 Moved to this class from store class.
|
||||
* @var array
|
||||
*/
|
||||
protected $defaultUserSettings = array();
|
||||
|
||||
/**
|
||||
* Array of allowed settings.
|
||||
* Setting name (key) => array( values ).
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.5.2 Added force_group_users.
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.6.1 Added freeze_locale.
|
||||
* @since 1.7 Moved to this class from store class.
|
||||
* @var array
|
||||
*/
|
||||
protected $allowedUserSettings = array();
|
||||
|
||||
/**
|
||||
* Sets the default data.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access protected
|
||||
* @param string $id Identifier for this settings instance.
|
||||
* @param array $args {
|
||||
* (optional) Setting arguments.
|
||||
* @type array $default The default settings (option)
|
||||
* @type array $allowed The allowed settings (option). Use arrays to define all possible values for a setting.
|
||||
* @type array $default_user The default user settings (meta)
|
||||
* @type array $allowed_user The allowed user settings (meta). Use arrays to define all possible values for a setting.
|
||||
* }
|
||||
*/
|
||||
protected function __construct( $id, $args = array() ) {
|
||||
parent::__construct();
|
||||
|
||||
if ( empty( $id ) || ! is_string( $id ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$args = wp_parse_args( $args, array(
|
||||
'default' => array(),
|
||||
'allowed' => array(),
|
||||
'default_user' => array(),
|
||||
'allowed_user' => array(),
|
||||
) );
|
||||
|
||||
$default = $args['default'];
|
||||
$allowed = $args['allowed'];
|
||||
|
||||
$default_user = $args['default_user'];
|
||||
$allowed_user = $args['allowed_user'];
|
||||
|
||||
if ( 'VAA_View_Admin_As_Store' === get_class( $this ) ) {
|
||||
|
||||
$this->set_optionKey( 'vaa_view_admin_as' );
|
||||
$this->set_optionData( array(
|
||||
'db_version' => null,
|
||||
'settings' => null,
|
||||
) );
|
||||
|
||||
$this->set_userMetaKey( 'vaa-view-admin-as' );
|
||||
$this->set_userMeta( array(
|
||||
'settings' => null,
|
||||
'views' => null,
|
||||
) );
|
||||
|
||||
$default = array(
|
||||
'view_types' => array(),
|
||||
);
|
||||
$allowed = array(
|
||||
'view_types' => array(), // No restriction to values.
|
||||
);
|
||||
|
||||
$default_user = array(
|
||||
'admin_menu_location' => 'top-secondary',
|
||||
'disable_super_admin' => true,
|
||||
'force_group_users' => false,
|
||||
'freeze_locale' => false,
|
||||
'hide_customizer' => false,
|
||||
'hide_front' => false,
|
||||
'view_mode' => 'browse',
|
||||
);
|
||||
$allowed_user = array(
|
||||
'admin_menu_location' => array( 'top-secondary', 'my-account' ),
|
||||
'disable_super_admin' => array( true, false ),
|
||||
'force_group_users' => array( true, false ),
|
||||
'freeze_locale' => array( true, false ),
|
||||
'hide_customizer' => array( true, false ),
|
||||
'hide_front' => array( true, false ),
|
||||
'view_mode' => array( 'browse', 'single' ),
|
||||
);
|
||||
|
||||
// @todo Remove?
|
||||
$this->add_filter( 'view_admin_as_validate_view_data_setting', array( $this, 'filter_validate_settings' ), 10, 3 );
|
||||
$this->add_filter( 'view_admin_as_validate_view_data_user_setting', array( $this, 'filter_validate_settings' ), 10, 3 );
|
||||
|
||||
$this->add_filter( 'view_admin_as_handle_ajax_setting', array( $this, 'filter_update_settings' ), 10, 3 );
|
||||
$this->add_filter( 'view_admin_as_handle_ajax_user_setting', array( $this, 'filter_update_settings' ), 10, 3 );
|
||||
|
||||
// Make identifier empty for the filters.
|
||||
$id = '';
|
||||
|
||||
} else {
|
||||
|
||||
if ( 'view-admin-as' === sanitize_title_with_dashes( $id ) ) {
|
||||
_doing_it_wrong(
|
||||
__METHOD__,
|
||||
sprintf(
|
||||
// Translators: %1$s stands for an option key and %2$s stands for a class name.
|
||||
__( 'The setting key %1$s is reserved for class %2$s', VIEW_ADMIN_AS_DOMAIN ),
|
||||
$id, 'VAA_View_Admin_As_Store'
|
||||
),
|
||||
''
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->set_optionKey( 'vaa_' . $id );
|
||||
$this->set_userMetaKey( 'vaa-' . $id );
|
||||
|
||||
// Append underscore to the identifier for the filters.
|
||||
$id = '_' . $id;
|
||||
|
||||
} // End if().
|
||||
|
||||
$this->_filter_postfix = $id;
|
||||
|
||||
/**
|
||||
* Set the default global settings.
|
||||
*
|
||||
* @since 1.7
|
||||
* @param array
|
||||
* @return array
|
||||
*/
|
||||
$this->set_defaultSettings( apply_filters( 'view_admin_as_default_global_settings' . $id, $default ) );
|
||||
|
||||
/**
|
||||
* Set the allowed global settings.
|
||||
*
|
||||
* @since 1.7
|
||||
* @param array {
|
||||
* Settings array (key = setting name).
|
||||
* @type array Array of allowed values.
|
||||
* }
|
||||
* @return array
|
||||
*/
|
||||
$this->set_allowedSettings( apply_filters( 'view_admin_as_allowed_global_settings' . $id, $allowed ) );
|
||||
|
||||
/**
|
||||
* Set the default settings for users.
|
||||
*
|
||||
* @since 1.7
|
||||
* @param array
|
||||
* @return array
|
||||
*/
|
||||
$this->set_defaultUserSettings( apply_filters( 'view_admin_as_default_user_settings' . $id, $default_user ) );
|
||||
|
||||
/**
|
||||
* Set the allowed settings for users.
|
||||
*
|
||||
* @since 1.7
|
||||
* @param array {
|
||||
* Settings array (key = setting name).
|
||||
* @type array Array of allowed values.
|
||||
* }
|
||||
* @return array
|
||||
*/
|
||||
$this->set_allowedUserSettings( apply_filters( 'view_admin_as_allowed_user_settings' . $id, $allowed_user ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate hook for settings.
|
||||
*
|
||||
* @since 1.7
|
||||
* @param null $null Default return (invalid).
|
||||
* @param mixed $data The view data.
|
||||
* @param string $key The data key.
|
||||
* @return mixed
|
||||
*/
|
||||
public function filter_validate_settings( $null, $data, $key ) {
|
||||
if ( ! empty( $data ) && ! empty( $key ) ) {
|
||||
if ( 'setting' === $key ) {
|
||||
return $this->validate_settings( $data, 'global', false );
|
||||
}
|
||||
if ( 'user_setting' === $key ) {
|
||||
return $this->validate_settings( $data, 'user', false );
|
||||
}
|
||||
}
|
||||
return $null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate hook for settings.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7.3 Renamed from filter_store_settings().
|
||||
* @param null $null Default return (invalid).
|
||||
* @param mixed $data The view data.
|
||||
* @param string $key The data key.
|
||||
* @return mixed
|
||||
*/
|
||||
public function filter_update_settings( $null, $data, $key ) {
|
||||
if ( ! empty( $data ) && ! empty( $key ) ) {
|
||||
if ( 'setting' === $key ) {
|
||||
return $this->update_settings( $data, 'global' );
|
||||
}
|
||||
if ( 'user_setting' === $key ) {
|
||||
return $this->update_settings( $data, 'user' );
|
||||
}
|
||||
}
|
||||
return $null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate setting data based on allowed settings.
|
||||
* Will also merge with the default settings unless third $merge parameter is false.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.7 Moved to this class from store class. Added third $merge parameter.
|
||||
* @access public
|
||||
*
|
||||
* @param array $settings The new settings.
|
||||
* @param string $type The type of settings (global / user).
|
||||
* @param bool $merge Merge with defaults? (will return all settings).
|
||||
* @return array|bool $settings / false
|
||||
*/
|
||||
public function validate_settings( $settings, $type, $merge = true ) {
|
||||
if ( 'global' === $type ) {
|
||||
$defaults = $this->get_defaultSettings();
|
||||
$allowed = $this->get_allowedSettings();
|
||||
} elseif ( 'user' === $type ) {
|
||||
$defaults = $this->get_defaultUserSettings();
|
||||
$allowed = $this->get_allowedUserSettings();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $merge ) {
|
||||
return $this->parse_settings( $settings, $defaults, $allowed );
|
||||
}
|
||||
|
||||
foreach ( $settings as $setting => $value ) {
|
||||
// Only pass the settings if the key and value matched the data in the allowed settings.
|
||||
if ( ! array_key_exists( $setting, $allowed ) ) {
|
||||
unset( $settings[ $setting ] );
|
||||
}
|
||||
// If setting key is allowed value is empty we don't need to validate.
|
||||
if ( ! empty( $allowed[ $setting ] ) && ! in_array( $value, $allowed[ $setting ], true ) ) {
|
||||
unset( $settings[ $setting ] );
|
||||
}
|
||||
}
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store settings based on allowed settings.
|
||||
* Also merges with the default settings.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.7 Moved to this class from store class.
|
||||
* @since 1.7.3 Renamed from store_settings().
|
||||
* @access public
|
||||
*
|
||||
* @param array $settings The new settings.
|
||||
* @param string $type The type of settings (global / user).
|
||||
* @return bool
|
||||
*/
|
||||
public function update_settings( $settings, $type ) {
|
||||
if ( 'global' === $type ) {
|
||||
$current = $this->get_settings();
|
||||
$defaults = $this->get_defaultSettings();
|
||||
$allowed = $this->get_allowedSettings();
|
||||
} elseif ( 'user' === $type ) {
|
||||
$current = $this->get_userSettings();
|
||||
$defaults = $this->get_defaultUserSettings();
|
||||
$allowed = $this->get_allowedUserSettings();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if ( ! is_array( $current ) ) {
|
||||
$current = $defaults;
|
||||
}
|
||||
|
||||
$settings = apply_filters(
|
||||
'view_admin_as_update_' . $type . '_settings' . $this->_filter_postfix,
|
||||
$settings, $current, $defaults, $allowed
|
||||
);
|
||||
|
||||
$settings = $this->validate_settings( $settings, $type, false );
|
||||
|
||||
foreach ( $settings as $setting => $value ) {
|
||||
$current[ $setting ] = $value;
|
||||
// Some settings need a reset.
|
||||
if ( in_array( $setting, array( 'view_mode' ), true ) ) {
|
||||
view_admin_as()->controller()->reset_view();
|
||||
}
|
||||
}
|
||||
|
||||
$new = $this->parse_settings( $current, $defaults, $allowed );
|
||||
|
||||
if ( 'global' === $type ) {
|
||||
return $this->update_optionData( $new, 'settings', true );
|
||||
} elseif ( 'user' === $type ) {
|
||||
return $this->update_userMeta( $new, 'settings', true );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the settings.
|
||||
* Checks if the setting exists, removes it otherwise.
|
||||
* Checks if the setting is allowed, otherwise sets it to the default value.
|
||||
*
|
||||
* @since 1.7
|
||||
* @param array $settings The new settings.
|
||||
* @param array $defaults The default settings.
|
||||
* @param array $allowed The allowed settings.
|
||||
* @return array
|
||||
*/
|
||||
public function parse_settings( $settings, $defaults, $allowed ) {
|
||||
$settings = wp_parse_args( $settings, $defaults );
|
||||
foreach ( $settings as $setting => $value ) {
|
||||
if ( ! array_key_exists( $setting, $allowed ) ) {
|
||||
// We don't have such a setting.
|
||||
unset( $settings[ $setting ] );
|
||||
} elseif ( ! empty( $allowed[ $setting ] ) && ! in_array( $value, $allowed[ $setting ], true ) ) {
|
||||
// Set it to default if the allowed values are set and the value isn't allowed.
|
||||
$settings[ $setting ] = $defaults[ $setting ];
|
||||
}
|
||||
}
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the meta key results for all users.
|
||||
*
|
||||
* @since 1.8
|
||||
* @global \wpdb $wpdb
|
||||
* @return array {
|
||||
* User ID's as array keys.
|
||||
* @type array $meta_values The meta values. Column ID's as array keys.
|
||||
* }
|
||||
*/
|
||||
public function get_all_user_meta() {
|
||||
if ( ! empty( $this->allUserMeta ) ) {
|
||||
return $this->allUserMeta;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
$key = $this->get_userMetaKey();
|
||||
|
||||
// @todo Use WP_Meta_Query ?
|
||||
$sql = 'SELECT * FROM ' . $wpdb->usermeta . ' WHERE meta_key = %s';
|
||||
// @codingStandardsIgnoreLine >> $wpdb->prepare(), check returning false error.
|
||||
$results = (array) $wpdb->get_results( $wpdb->prepare( $sql, $key ) );
|
||||
|
||||
$metas = array();
|
||||
|
||||
foreach ( $results as $key => $meta ) {
|
||||
if ( ! isset( $metas[ $meta->user_id ] ) ) {
|
||||
$metas[ $meta->user_id ] = array();
|
||||
}
|
||||
if ( ! empty( $meta->meta_value ) ) {
|
||||
$metas[ $meta->user_id ][ $meta->umeta_id ] = maybe_unserialize( $meta->meta_value );
|
||||
}
|
||||
}
|
||||
|
||||
$this->allUserMeta = $metas;
|
||||
|
||||
return $metas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the meta values for other users.
|
||||
* Should be used together with get_all_user_meta() to get column id's.
|
||||
*
|
||||
* @since 1.8
|
||||
* @see \VAA_View_Admin_As_Settings::get_all_user_meta()
|
||||
* @param mixed $value
|
||||
* @param int $user_id
|
||||
* @param int $column_id
|
||||
* @return bool
|
||||
*/
|
||||
public function update_other_user_meta( $value, $user_id, $column_id = null ) {
|
||||
if ( ! $this->allUserMeta ) {
|
||||
$this->get_all_user_meta();
|
||||
}
|
||||
|
||||
// Validate settings.
|
||||
$value = wp_parse_args( $value, array(
|
||||
'settings' => array(),
|
||||
) );
|
||||
$value['settings'] = $this->validate_settings( $value['settings'], 'user', true );
|
||||
|
||||
if ( ! isset( $this->allUserMeta[ $user_id ] ) ) {
|
||||
$column_id = 0;
|
||||
$this->allUserMeta[ $user_id ] = array( $column_id => $value );
|
||||
}
|
||||
|
||||
if ( ! is_int( $column_id ) ) {
|
||||
reset( $this->allUserMeta[ $user_id ] );
|
||||
$column_id = key( $this->allUserMeta[ $user_id ] );
|
||||
}
|
||||
|
||||
$this->allUserMeta[ $user_id ][ $column_id ] = $value;
|
||||
|
||||
// @todo handle multiple columns.
|
||||
return update_user_meta( $user_id, $this->get_userMetaKey(), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete or reset all View Admin As metadata for this user.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.6.2 Option to remove the VAA metadata for all users.
|
||||
* @since 1.7 Moved to this class from store class.
|
||||
* @access public
|
||||
*
|
||||
* @param int|string $user_id ID of the user being deleted/removed (pass `all` for all users).
|
||||
* @param \WP_User $user User object provided by the wp_login hook.
|
||||
* @param bool $reset_only Only reset (not delete) the user meta.
|
||||
* @return bool
|
||||
*/
|
||||
public function delete_user_meta( $user_id = null, $user = null, $reset_only = true ) {
|
||||
/**
|
||||
* Set the first parameter to `all` to remove the meta value for all users.
|
||||
* @since 1.6.2
|
||||
*/
|
||||
if ( 'all' === $user_id ) {
|
||||
return $this->delete_all_user_meta( $reset_only );
|
||||
}
|
||||
|
||||
$id = false;
|
||||
if ( is_numeric( $user_id ) ) {
|
||||
// Delete hooks.
|
||||
$id = (int) $user_id;
|
||||
} elseif ( isset( $user->ID ) ) {
|
||||
// Login/Logout hooks.
|
||||
$id = (int) $user->ID;
|
||||
}
|
||||
if ( $id ) {
|
||||
$success = true;
|
||||
if ( $reset_only ) {
|
||||
// Reset db metadata (returns: true on success, false on failure).
|
||||
if ( get_user_meta( $id, $this->get_userMetaKey() ) ) {
|
||||
$success = update_user_meta( $id, $this->get_userMetaKey(), false );
|
||||
}
|
||||
} else {
|
||||
// Remove db metadata (returns: true on success, false on failure).
|
||||
$success = delete_user_meta( $id, $this->get_userMetaKey() );
|
||||
}
|
||||
// Update current metadata if it is the current user.
|
||||
if ( $success && (int) get_current_user_id() === $id ) {
|
||||
$this->set_userMeta( false );
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
// No user or metadata found, no deletion needed.
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete or reset all View Admin As metadata for all users.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
*
|
||||
* @see https://developer.wordpress.org/reference/classes/wpdb/update/
|
||||
* @see https://developer.wordpress.org/reference/classes/wpdb/delete/
|
||||
*
|
||||
* @global \wpdb $wpdb
|
||||
* @param bool $reset_only Only reset (not delete) the user meta.
|
||||
* @return bool
|
||||
*/
|
||||
public function delete_all_user_meta( $reset_only = true ) {
|
||||
global $wpdb;
|
||||
if ( $reset_only ) {
|
||||
// Reset.
|
||||
return (bool) $wpdb->update(
|
||||
$wpdb->usermeta, // table.
|
||||
array( 'meta_value' => '' ), // data.
|
||||
array( 'meta_key' => $this->get_userMetaKey() ) // where.
|
||||
);
|
||||
} else {
|
||||
// Delete.
|
||||
return (bool) $wpdb->delete(
|
||||
$wpdb->usermeta, // table.
|
||||
array( 'meta_key' => $this->get_userMetaKey() ) // where.
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the option key as used in the options table.
|
||||
* @return string
|
||||
*/
|
||||
public function get_optionKey() {
|
||||
return (string) $this->optionKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user meta key as used in the usermeta table.
|
||||
* @return string
|
||||
*/
|
||||
public function get_userMetaKey() {
|
||||
return (string) $this->userMetaKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the option data as used in the options table.
|
||||
* @param string $key Key in the option array.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_optionData( $key = null ) {
|
||||
return VAA_API::get_array_data( $this->optionData, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user metadata as used in the usermeta table.
|
||||
* @param string $key Key in the meta array.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_userMeta( $key = null ) {
|
||||
return VAA_API::get_array_data( $this->userMeta, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default settings.
|
||||
* @param string $key Setting key.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_defaultSettings( $key = null ) {
|
||||
return VAA_API::get_array_data( $this->defaultSettings, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default user settings.
|
||||
* @param string $key Setting key.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_defaultUserSettings( $key = null ) {
|
||||
return VAA_API::get_array_data( $this->defaultUserSettings, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the allowed settings.
|
||||
* @param string $key Setting key.
|
||||
* @return array
|
||||
*/
|
||||
public function get_allowedSettings( $key = null ) {
|
||||
return (array) VAA_API::get_array_data( $this->allowedSettings, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the allowed user settings.
|
||||
* @param string $key Setting key.
|
||||
* @return array
|
||||
*/
|
||||
public function get_allowedUserSettings( $key = null ) {
|
||||
return (array) VAA_API::get_array_data( $this->allowedUserSettings, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the settings.
|
||||
* @param string $key Setting key.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_settings( $key = null ) {
|
||||
return VAA_API::get_array_data(
|
||||
$this->validate_settings(
|
||||
$this->get_optionData( 'settings' ),
|
||||
'global'
|
||||
),
|
||||
$key
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user settings.
|
||||
* @param string $key Setting key.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_userSettings( $key = null ) {
|
||||
return VAA_API::get_array_data(
|
||||
$this->validate_settings(
|
||||
$this->get_userMeta( 'settings' ),
|
||||
'user'
|
||||
),
|
||||
$key
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the option key as used in the options table.
|
||||
* @param string $val Option key.
|
||||
* @return void
|
||||
*/
|
||||
protected function set_optionKey( $val ) {
|
||||
$this->optionKey = (string) str_replace( array( ' ', '-' ), '_', sanitize_title_with_dashes( $val ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the option key as used in the options table.
|
||||
* @param string $val Option key.
|
||||
* @return void
|
||||
*/
|
||||
protected function set_userMetaKey( $val ) {
|
||||
$this->userMetaKey = (string) sanitize_title_with_dashes( $val );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default settings.
|
||||
* @param array $val Settings.
|
||||
* @param string $key (optional) Setting key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
* @return void
|
||||
*/
|
||||
protected function set_defaultSettings( $val, $key = null, $append = false ) {
|
||||
$this->defaultSettings = VAA_API::set_array_data( $this->defaultSettings, $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default user settings.
|
||||
* @param array $val Settings.
|
||||
* @param string $key (optional) Setting key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
* @return void
|
||||
*/
|
||||
protected function set_defaultUserSettings( $val, $key = null, $append = false ) {
|
||||
$this->defaultUserSettings = VAA_API::set_array_data( $this->defaultUserSettings, $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the allowed settings.
|
||||
* @param mixed $val Settings.
|
||||
* @param string $key (optional) Setting key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
* @return void
|
||||
*/
|
||||
protected function set_allowedSettings( $val, $key = null, $append = false ) {
|
||||
$this->allowedSettings = VAA_API::set_array_data( $this->allowedSettings, $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the allowed user settings.
|
||||
* @param mixed $val Settings.
|
||||
* @param string $key (optional) Setting key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
* @return void
|
||||
*/
|
||||
protected function set_allowedUserSettings( $val, $key = null, $append = false ) {
|
||||
$this->allowedUserSettings = VAA_API::set_array_data( $this->allowedUserSettings, $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the settings.
|
||||
* @param mixed $val Settings.
|
||||
* @param string $key (optional) Setting key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
* @return void
|
||||
*/
|
||||
public function set_settings( $val, $key = null, $append = false ) {
|
||||
$this->set_optionData(
|
||||
$this->validate_settings(
|
||||
VAA_API::set_array_data( $this->get_settings(), $val, $key, $append ),
|
||||
'global'
|
||||
),
|
||||
'settings',
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user settings.
|
||||
* @param mixed $val Settings.
|
||||
* @param string $key (optional) Setting key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
* @return void
|
||||
*/
|
||||
public function set_userSettings( $val, $key = null, $append = false ) {
|
||||
$this->set_userMeta(
|
||||
$this->validate_settings(
|
||||
VAA_API::set_array_data( $this->get_userSettings(), $val, $key, $append ),
|
||||
'user'
|
||||
),
|
||||
'settings',
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the plugin option data.
|
||||
* @param mixed $val Data.
|
||||
* @param string $key (optional) Data key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
* @return void
|
||||
*/
|
||||
public function set_optionData( $val, $key = null, $append = false ) {
|
||||
$this->optionData = VAA_API::set_array_data( $this->optionData, $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user metadata.
|
||||
* @param mixed $val Data.
|
||||
* @param string $key (optional) Data key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
* @return void
|
||||
*/
|
||||
public function set_userMeta( $val, $key = null, $append = false ) {
|
||||
$this->userMeta = VAA_API::set_array_data( $this->userMeta, $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the option data.
|
||||
* @param bool $network Is network option?
|
||||
* @since 1.7.x
|
||||
*/
|
||||
protected function store_optionData( $network = false ) {
|
||||
$this->set_for_network( $network );
|
||||
|
||||
if ( $this->is_for_network() ) {
|
||||
$this->set_optionData( get_site_option( $this->get_optionKey() ) );
|
||||
} else {
|
||||
$this->set_optionData( get_option( $this->get_optionKey() ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the user meta.
|
||||
* @since 1.7.x
|
||||
* @param int $user_id The user ID this metadata is for.
|
||||
* @param bool $single NOT SUPPORTED YET!
|
||||
*/
|
||||
protected function store_userMeta( $user_id, $single = true ) {
|
||||
if ( ! is_int( $user_id ) ) {
|
||||
return;
|
||||
}
|
||||
$this->for_user = $user_id;
|
||||
$this->set_userMeta( get_user_meta( $this->for_user, $this->get_userMetaKey(), true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the plugin option data.
|
||||
* @param mixed $val Data.
|
||||
* @param string $key (optional) Data key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
* @return bool
|
||||
*/
|
||||
public function update_optionData( $val, $key = null, $append = false ) {
|
||||
$this->set_optionData( $val, $key, $append );
|
||||
|
||||
if ( $this->is_for_network() ) {
|
||||
return update_site_option( $this->get_optionKey(), $this->get_optionData() );
|
||||
}
|
||||
return update_option( $this->get_optionKey(), $this->get_optionData() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the user metadata.
|
||||
* @param mixed $val Data.
|
||||
* @param string $key (optional) Data key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
* @return bool
|
||||
*/
|
||||
public function update_userMeta( $val, $key = null, $append = false ) {
|
||||
$this->set_userMeta( $val, $key, $append );
|
||||
return update_user_meta( $this->for_user, $this->get_userMetaKey(), $this->get_userMeta() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this instance if for a network option.
|
||||
* @since 1.7.x
|
||||
* @param bool $bool
|
||||
*/
|
||||
protected function set_for_network( $bool ) {
|
||||
$this->for_network = (bool) $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this instance if for a network option.
|
||||
* @since 1.7.x
|
||||
* @return bool
|
||||
*/
|
||||
public function is_for_network() {
|
||||
return (bool) $this->for_network;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_Settings.
|
||||
557
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-store.php
Executable file
557
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-store.php
Executable file
@@ -0,0 +1,557 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Class Store
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Store class that stores the VAA data for use.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.6
|
||||
* @version 1.8
|
||||
* @uses \VAA_View_Admin_As_Settings Extends class
|
||||
*/
|
||||
final class VAA_View_Admin_As_Store extends VAA_View_Admin_As_Settings
|
||||
{
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @since 1.6
|
||||
* @static
|
||||
* @var \VAA_View_Admin_As_Store
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* The nonce.
|
||||
*
|
||||
* @since 1.3.4
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @var string
|
||||
*/
|
||||
private $nonce = '';
|
||||
|
||||
/**
|
||||
* The parsed nonce.
|
||||
*
|
||||
* @since 1.6.2
|
||||
* @var string
|
||||
*/
|
||||
private $nonce_parsed = '';
|
||||
|
||||
/**
|
||||
* View type data.
|
||||
* You can add custom view data with VAA_View_Admin_As_Store::set_data().
|
||||
*
|
||||
* @see \VAA_View_Admin_As_Store::set_data()
|
||||
* @since 1.7
|
||||
* @var array {
|
||||
* Default view data.
|
||||
* @type bool[] $caps Since 1.3 Array of available capabilities.
|
||||
* @type \WP_Role[] $roles Since 0.1 Array of available roles (WP_Role objects).
|
||||
* @type string[] $rolenames Since 1.6.4 Array of role names (used for role translations).
|
||||
* @type \WP_User[] $users Since 0.1 Array of available users (WP_User objects).
|
||||
* @type string[] $languages Since 1.8 Array of available locale/languages.
|
||||
* }
|
||||
*/
|
||||
private $data = array(
|
||||
'caps' => array(),
|
||||
'roles' => array(),
|
||||
'rolenames' => array(),
|
||||
'users' => array(),
|
||||
'languages' => array(),
|
||||
);
|
||||
|
||||
/**
|
||||
* Current (initial) user object.
|
||||
*
|
||||
* @since 0.1
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @var \WP_User
|
||||
*/
|
||||
private $curUser;
|
||||
|
||||
/**
|
||||
* Current (initial) user session.
|
||||
*
|
||||
* @since 1.3.4
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @var string
|
||||
*/
|
||||
private $curUserSession = '';
|
||||
|
||||
/**
|
||||
* Current (initial) user data.
|
||||
* Will contain all properties of the original current user object.
|
||||
*
|
||||
* @since 1.6.3
|
||||
* @since 1.7.3 Not static anymore.
|
||||
* @var array
|
||||
*/
|
||||
private $curUserData = array();
|
||||
|
||||
/**
|
||||
* Does the current (initial) user has full access to all features of this plugin?
|
||||
*
|
||||
* @since 1.6.3
|
||||
* @since 1.7.3 Not static anymore.
|
||||
* @since 1.7.6 Renamed from $isCurUserSuperAdmin
|
||||
* @var bool
|
||||
*/
|
||||
private $curUserHasFullAccess = false;
|
||||
|
||||
/**
|
||||
* Selected view data as stored in the user meta.
|
||||
* Format: array( VIEW_TYPE => VIEW_DATA ).
|
||||
*
|
||||
* @since 0.1
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @var array
|
||||
*/
|
||||
private $view = array();
|
||||
|
||||
/**
|
||||
* The selected user object (if a view is selected).
|
||||
* Can be the same as $curUser depending on the selected view.
|
||||
*
|
||||
* @since 0.1
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @var \WP_User
|
||||
*/
|
||||
private $selectedUser;
|
||||
|
||||
/**
|
||||
* The selected capabilities (if a view is selected).
|
||||
*
|
||||
* @since 1.6.2
|
||||
* @var bool[]
|
||||
*/
|
||||
private $selectedCaps = array();
|
||||
|
||||
/**
|
||||
* Populate the instance.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function __construct() {
|
||||
parent::__construct( 'view-admin-as' );
|
||||
self::$_instance = $this;
|
||||
|
||||
$this->init( true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the current user and other user related data.
|
||||
*
|
||||
* @since 1.6.3 Moved to this class.
|
||||
* @access public
|
||||
* @param bool $redo (optional) Force re-init?
|
||||
*/
|
||||
public function init( $redo = false ) {
|
||||
static $done = false;
|
||||
if ( $done && ! $redo ) return;
|
||||
|
||||
$this->set_nonce( 'view-admin-as' );
|
||||
|
||||
// Get the current user.
|
||||
$this->set_curUser( wp_get_current_user() );
|
||||
|
||||
// Get the current user session (WP 4.0+).
|
||||
$this->set_curUserSession( (string) wp_get_session_token() );
|
||||
|
||||
$this->curUserHasFullAccess = VAA_API::user_has_full_access( $this->get_curUser() );
|
||||
$this->curUserData = get_object_vars( $this->get_curUser() );
|
||||
|
||||
// Get database settings.
|
||||
$this->store_optionData( VAA_View_Admin_As::is_network_active() );
|
||||
// Get database settings of the current user.
|
||||
$this->store_userMeta( get_current_user_id() );
|
||||
|
||||
$done = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the current (original) user has full access to this plugin?
|
||||
* @since 1.8
|
||||
* @return bool
|
||||
*/
|
||||
public function cur_user_has_full_access() {
|
||||
return (bool) $this->curUserHasFullAccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare user to the current (original) user.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param \WP_User|int $user The user to compare.
|
||||
* @return bool
|
||||
*/
|
||||
public function is_curUser( $user ) {
|
||||
if ( $user instanceof WP_User ) {
|
||||
$user = $user->ID;
|
||||
}
|
||||
if ( ! is_numeric( $user ) ) {
|
||||
return false;
|
||||
}
|
||||
return (bool) ( (int) $this->get_curUser()->ID === (int) $user );
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for is_super_admin().
|
||||
* Will validate the original user if it is the current user or no user ID is passed.
|
||||
* This can prevent invalid checks after a view is applied.
|
||||
*
|
||||
* @see \VAA_API::is_super_admin()
|
||||
* @deprecated
|
||||
* @todo Remove in 1.9
|
||||
*
|
||||
* @since 1.6.3
|
||||
* @since 1.7.3 Not static anymore.
|
||||
* @access public
|
||||
* @param int $user_id (optional).
|
||||
* @return bool
|
||||
*/
|
||||
public function is_super_admin( $user_id = null ) {
|
||||
_deprecated_function( __FUNCTION__, '1.8', 'VAA_API::is_super_admin()' );
|
||||
if ( null === $user_id || (int) $this->curUser->ID === (int) $user_id ) {
|
||||
return $this->curUserHasFullAccess;
|
||||
}
|
||||
return VAA_API::user_has_full_access( $user_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data from the current user, similar to the WP_User object.
|
||||
* Unlike the current user object this data isn't modified after in a view.
|
||||
* This has all public WP_User properties stored as an array.
|
||||
*
|
||||
* @since 1.6.3
|
||||
* @since 1.7.3 Not static anymore.
|
||||
* @access public
|
||||
* @param string $key (optional).
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_originalUserData( $key = null ) {
|
||||
return VAA_API::get_array_data( $this->curUserData, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current user.
|
||||
* @return \WP_User $curUser Current user object.
|
||||
*/
|
||||
public function get_curUser() {
|
||||
return $this->curUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current user session.
|
||||
* @return string
|
||||
*/
|
||||
public function get_curUserSession() {
|
||||
return (string) $this->curUserSession;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get view data (meta).
|
||||
* @since 1.7
|
||||
* @param string $key Key for array.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_view( $key = null ) {
|
||||
return VAA_API::get_array_data( $this->view, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get view type data
|
||||
*
|
||||
* @since 1.7
|
||||
* @param string $type Type key.
|
||||
* @param string $key (optional) Type data key.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_data( $type, $key = null ) {
|
||||
if ( isset( $this->data[ $type ] ) ) {
|
||||
return VAA_API::get_array_data( $this->data[ $type ], $key );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available capabilities.
|
||||
* @param string $key Cap name.
|
||||
* @return bool[]|bool Array of capabilities or a single capability value.
|
||||
*/
|
||||
public function get_caps( $key = null ) {
|
||||
return $this->get_data( 'caps', $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available roles.
|
||||
* @param string $key Role slug/key.
|
||||
* @return \WP_Role[]|\WP_Role Array of role objects or a single role object.
|
||||
*/
|
||||
public function get_roles( $key = null ) {
|
||||
return $this->get_data( 'roles', $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the role names. Translated by default.
|
||||
* If key is provided but not found it will return the key (untranslated).
|
||||
* @since 1.6.4
|
||||
* @param string $key Role slug.
|
||||
* @param bool $translate Translate the role name?
|
||||
* @return string[]|string
|
||||
*/
|
||||
public function get_rolenames( $key = null, $translate = true ) {
|
||||
$val = $this->get_data( 'rolenames', $key );
|
||||
if ( ! $val ) {
|
||||
|
||||
/**
|
||||
* Try to fetch role name from WP core. No security risk here.
|
||||
* Check for the wp_roles() function in WP 4.3+.
|
||||
* @since 1.8
|
||||
*/
|
||||
if ( function_exists( 'wp_roles' ) ) {
|
||||
$wp_roles = wp_roles();
|
||||
} else {
|
||||
global $wp_roles;
|
||||
}
|
||||
if ( isset( $wp_roles->role_names[ $key ] ) ) {
|
||||
$this->set_rolenames( $wp_roles->role_names[ $key ], $key, true );
|
||||
return $this->get_rolenames( $key, $translate );
|
||||
}
|
||||
|
||||
return ( $key ) ? $key : $val;
|
||||
}
|
||||
if ( $translate ) {
|
||||
if ( is_array( $val ) ) {
|
||||
$val = array_map( 'translate_user_role', $val );
|
||||
} else {
|
||||
$val = translate_user_role( $val );
|
||||
}
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available users.
|
||||
* @param string $key User key.
|
||||
* @return \WP_User[]|\WP_User Array of user objects or a single user object.
|
||||
*/
|
||||
public function get_users( $key = null ) {
|
||||
return $this->get_data( 'users', $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available languages.
|
||||
* @param string $key Locale key.
|
||||
* @return string[]|string Array of language names or a single language name.
|
||||
*/
|
||||
public function get_languages( $key = null ) {
|
||||
return $this->get_data( 'languages', $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selected user object of a view.
|
||||
* @return \WP_User
|
||||
*/
|
||||
public function get_selectedUser() {
|
||||
return $this->selectedUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get selected capabilities of a view.
|
||||
* @param string $key Cap name.
|
||||
* @return bool[]|bool Array of capabilities or a single capability value.
|
||||
*/
|
||||
public function get_selectedCaps( $key = null ) {
|
||||
return VAA_API::get_array_data( $this->selectedCaps, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the nonce.
|
||||
* @param string $parsed Return parsed nonce?
|
||||
* @return string
|
||||
*/
|
||||
public function get_nonce( $parsed = null ) {
|
||||
return ( $parsed ) ? $this->nonce_parsed : $this->nonce;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plugin version.
|
||||
* @todo Move to API.
|
||||
* @return string
|
||||
*/
|
||||
public function get_version() {
|
||||
return strtolower( (string) VIEW_ADMIN_AS_VERSION );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plugin database version.
|
||||
* @todo Move to API.
|
||||
* @return string
|
||||
*/
|
||||
public function get_dbVersion() {
|
||||
return strtolower( (string) VIEW_ADMIN_AS_DB_VERSION );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current user object.
|
||||
* @param \WP_User $val User object.
|
||||
* @return void
|
||||
*/
|
||||
public function set_curUser( WP_User $val ) {
|
||||
$this->curUser = $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current user session.
|
||||
* @param string $val User session ID.
|
||||
* @return void
|
||||
*/
|
||||
public function set_curUserSession( $val ) {
|
||||
$this->curUserSession = (string) $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the view data.
|
||||
* @param mixed $val Value.
|
||||
* @param string $key (optional) View key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
* @return void
|
||||
*/
|
||||
public function set_view( $val, $key = null, $append = false ) {
|
||||
$this->view = (array) VAA_API::set_array_data( $this->view, $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set view type data.
|
||||
*
|
||||
* @since 1.7
|
||||
* @param string $type
|
||||
* @param mixed $val
|
||||
* @param string $key
|
||||
* @param bool $append
|
||||
* @return void
|
||||
*/
|
||||
public function set_data( $type, $val, $key = null, $append = false ) {
|
||||
if ( VAA_API::exists_callable( array( $this, 'set_' . $type ) ) ) {
|
||||
$method = 'set_' . $type;
|
||||
$this->$method( $val, $key, $append );
|
||||
return;
|
||||
}
|
||||
$current = ( isset( $this->data[ $type ] ) ) ? $this->data[ $type ] : array();
|
||||
$this->data[ $type ] = (array) VAA_API::set_array_data( $current, $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the available capabilities.
|
||||
* @param mixed $val Value.
|
||||
* @param string $key (optional) Cap key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
* @return void
|
||||
*/
|
||||
public function set_caps( $val, $key = null, $append = false ) {
|
||||
$this->data['caps'] = (array) VAA_API::set_array_data( $this->data['caps'], $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the available roles.
|
||||
* @param mixed $val Value.
|
||||
* @param string $key (optional) Role name.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
* @return void
|
||||
*/
|
||||
public function set_roles( $val, $key = null, $append = false ) {
|
||||
$this->data['roles'] = (array) VAA_API::set_array_data( $this->data['roles'], $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the role name translations.
|
||||
* @since 1.6.4
|
||||
* @param mixed $val Value.
|
||||
* @param string $key (optional) Role name.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
* @return void
|
||||
*/
|
||||
public function set_rolenames( $val, $key = null, $append = false ) {
|
||||
$this->data['rolenames'] = (array) VAA_API::set_array_data( $this->data['rolenames'], $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the available users.
|
||||
* @param mixed $val Value.
|
||||
* @param string $key (optional) User key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
* @return void
|
||||
*/
|
||||
public function set_users( $val, $key = null, $append = false ) {
|
||||
$this->data['users'] = (array) VAA_API::set_array_data( $this->data['users'], $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the languages.
|
||||
* @since 1.8
|
||||
* @param mixed $val Value.
|
||||
* @param string $key (optional) Role name.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
* @return void
|
||||
*/
|
||||
public function set_languages( $val, $key = null, $append = false ) {
|
||||
$this->data['languages'] = (array) VAA_API::set_array_data( $this->data['languages'], $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the selected user object for the current view.
|
||||
* @param \WP_User $val User object.
|
||||
* @return void
|
||||
*/
|
||||
public function set_selectedUser( $val ) {
|
||||
$this->selectedUser = $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the selected capabilities for the current view.
|
||||
* @param array $val Selected capabilities.
|
||||
* @return void
|
||||
*/
|
||||
public function set_selectedCaps( $val ) {
|
||||
$this->selectedCaps = array_filter( (array) $val );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the nonce.
|
||||
* Also sets a parsed version of the nonce with wp_create_nonce().
|
||||
* @param string $val Nonce.
|
||||
* @return void
|
||||
*/
|
||||
public function set_nonce( $val ) {
|
||||
$this->nonce = (string) $val;
|
||||
$this->nonce_parsed = wp_create_nonce( (string) $val );
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Instance.
|
||||
*
|
||||
* Ensures only one instance of this class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @static
|
||||
* @param \VAA_View_Admin_As $caller The referrer class.
|
||||
* @return \VAA_View_Admin_As_Store $this
|
||||
*/
|
||||
public static function get_instance( $caller = null ) {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self( $caller );
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_Store.
|
||||
475
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-type.php
Executable file
475
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-type.php
Executable file
@@ -0,0 +1,475 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - View Type
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* View Type class base.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.8
|
||||
* @version 1.8
|
||||
* @uses \VAA_View_Admin_As_Base Extends class
|
||||
*/
|
||||
abstract class VAA_View_Admin_As_Type extends VAA_View_Admin_As_Base
|
||||
{
|
||||
/**
|
||||
* View type settings.
|
||||
*
|
||||
* @since 1.8
|
||||
* @var array
|
||||
*/
|
||||
private $settings = array(
|
||||
'enabled' => true,
|
||||
);
|
||||
|
||||
/**
|
||||
* The view type.
|
||||
*
|
||||
* @since 1.8
|
||||
* @var string
|
||||
*/
|
||||
protected $type = '';
|
||||
|
||||
/**
|
||||
* The view type label.
|
||||
*
|
||||
* @since 1.8
|
||||
* @var string
|
||||
*/
|
||||
protected $label = '';
|
||||
|
||||
/**
|
||||
* The view type singular label.
|
||||
*
|
||||
* @since 1.8
|
||||
* @var string
|
||||
*/
|
||||
protected $label_singular = '';
|
||||
|
||||
/**
|
||||
* The view type description.
|
||||
*
|
||||
* @since 1.8
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '';
|
||||
|
||||
/**
|
||||
* The icon for this view type.
|
||||
*
|
||||
* @since 1.8
|
||||
* @var string
|
||||
*/
|
||||
protected $icon = '';
|
||||
|
||||
/**
|
||||
* Selected view.
|
||||
*
|
||||
* @since 1.8
|
||||
* @var mixed
|
||||
*/
|
||||
protected $selected = null;
|
||||
|
||||
/**
|
||||
* Does the original user has access?
|
||||
*
|
||||
* @since 1.8
|
||||
* @var bool
|
||||
*/
|
||||
protected $user_has_access = false;
|
||||
|
||||
/**
|
||||
* The hook priorities for this type.
|
||||
*
|
||||
* @since 1.8
|
||||
* @var int[]
|
||||
*/
|
||||
protected $priorities = array(
|
||||
'toolbar' => 10,
|
||||
'view_title' => 10,
|
||||
'validate_view_data' => 10,
|
||||
'update_view' => 10,
|
||||
'do_view' => 10,
|
||||
);
|
||||
|
||||
/**
|
||||
* The capability required for this view type.
|
||||
*
|
||||
* @since 1.8
|
||||
* @var string
|
||||
*/
|
||||
protected $cap = 'view_admin_as';
|
||||
|
||||
/**
|
||||
* Populate the instance.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access protected
|
||||
* @param \VAA_View_Admin_As $vaa The main VAA object.
|
||||
*/
|
||||
protected function __construct( $vaa ) {
|
||||
static $done;
|
||||
if ( ! $done ) {
|
||||
$this->add_filter( 'view_admin_as_update_global_settings', array( 'VAA_View_Admin_As_Type', 'filter_update_view_types' ), 1, 3 );
|
||||
$done = true;
|
||||
}
|
||||
|
||||
parent::__construct( $vaa );
|
||||
|
||||
$this->vaa->register_view_type( array(
|
||||
'id' => $this->type,
|
||||
'instance' => $this,
|
||||
) );
|
||||
|
||||
$this->user_has_access = $this->current_user_can( $this->cap );
|
||||
|
||||
if ( ! $this->has_access() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$view_types = $this->store->get_settings( 'view_types' );
|
||||
if ( isset( $view_types[ $this->type ] ) ) {
|
||||
$this->settings = $view_types[ $this->type ];
|
||||
}
|
||||
|
||||
if ( $this->is_enabled() ) {
|
||||
$this->add_action( 'vaa_view_admin_as_pre_init', array( $this, 'init' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the original user has access to this view type?
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function has_access() {
|
||||
return (bool) ( $this->is_vaa_enabled() && $this->user_has_access );
|
||||
}
|
||||
|
||||
/**
|
||||
* Is enabled?
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function is_enabled() {
|
||||
return ( ! empty( $this->settings['enabled'] ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set plugin enabled true/false.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param bool $bool Enable or disable?
|
||||
* @param bool $update_db Do database update? (default true).
|
||||
* @return bool
|
||||
*/
|
||||
public function set_enable( $bool = false, $update_db = true ) {
|
||||
$success = true;
|
||||
if ( $update_db ) {
|
||||
$success = $this->update_settings( (bool) $bool, 'enable', true );
|
||||
}
|
||||
if ( $success ) {
|
||||
$this->settings['enabled'] = (bool) $bool;
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup module and hooks.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access protected
|
||||
* @return bool Successful init?
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
$this->store_data();
|
||||
|
||||
if ( $this->has_access() && $this->get_data() ) {
|
||||
$this->init_hooks();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup hooks.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access protected
|
||||
*/
|
||||
protected function init_hooks() {
|
||||
|
||||
$this->add_action( 'vaa_admin_bar_menu', array( $this, 'admin_bar_menu' ), $this->get_priority( 'toolbar' ), 2 );
|
||||
|
||||
$this->add_filter( 'view_admin_as_validate_view_data_' . $this->type, array( $this, 'validate_view_data' ), $this->get_priority( 'validate_view_data' ), 3 );
|
||||
$this->add_filter( 'view_admin_as_update_view_' . $this->type, array( $this, 'update_view' ), $this->get_priority( 'update_view' ), 3 );
|
||||
|
||||
$this->add_action( 'vaa_view_admin_as_do_view', array( $this, 'do_view' ), $this->get_priority( 'do_view' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply this view type if active.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @return bool Is this view type active?
|
||||
*/
|
||||
public function do_view() {
|
||||
|
||||
$this->selected = $this->store->get_view( $this->type );
|
||||
|
||||
if ( $this->selected ) {
|
||||
|
||||
$this->add_filter( 'vaa_admin_bar_view_titles', array( $this, 'view_title' ), $this->get_priority( 'view_title' ) );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method for the view object.
|
||||
* Adds the actions and filters to modify the current user object.
|
||||
* Can only be run once.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function init_user_modifications() {
|
||||
$this->vaa->view()->init_user_modifications();
|
||||
}
|
||||
|
||||
/**
|
||||
* View update handler (Ajax probably), called from main handler.
|
||||
*
|
||||
* @since 1.8 Renamed from `ajax_handler`
|
||||
* @access public
|
||||
* @param null $null Null.
|
||||
* @param array $data The ajax data for this module.
|
||||
* @param string $type The view type.
|
||||
* @return bool
|
||||
*/
|
||||
public function update_view( $null, $data, $type = null ) {
|
||||
|
||||
if ( $type !== $this->type ) {
|
||||
return $null;
|
||||
}
|
||||
|
||||
if ( $this->get_data( $data ) ) {
|
||||
$this->store->set_view( $data, $this->type, true );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate data for this view type
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param null $null Default return (invalid)
|
||||
* @param mixed $data The view data
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function validate_view_data( $null, $data = null );
|
||||
|
||||
/**
|
||||
* Change the VAA admin bar menu title.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param array $titles The current title(s).
|
||||
* @return array
|
||||
*/
|
||||
abstract public function view_title( $titles = array() );
|
||||
|
||||
/**
|
||||
* Add the admin bar items.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The root item.
|
||||
*/
|
||||
abstract public function admin_bar_menu( $admin_bar, $root );
|
||||
|
||||
/**
|
||||
* Store the available languages.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access private
|
||||
*/
|
||||
abstract public function store_data();
|
||||
|
||||
/**
|
||||
* Set the view type data.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param mixed $val
|
||||
* @param string $key (optional) The data key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
*/
|
||||
public function set_data( $val, $key = null, $append = true ) {
|
||||
$this->store->set_data( $this->type, $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view type data.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param string $key (optional) The data key.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_data( $key = null ) {
|
||||
return $this->store->get_data( $this->type, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view type id.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_type() {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view type label.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_label() {
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view type singular label.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_label_singular() {
|
||||
return $this->label_singular;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view type description.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an action priority.
|
||||
* Default: toolbar priority.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param string $key
|
||||
* @return int
|
||||
*/
|
||||
public function get_priority( $key = 'toolbar' ) {
|
||||
return (int) ( isset( $this->priorities[ $key ] ) ) ? $this->priorities[ $key ] : 10;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view type settings.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param string $key Key in the setting array.
|
||||
* @return mixed
|
||||
*/
|
||||
final public function get_settings( $key = null ) {
|
||||
return VAA_API::get_array_data( $this->settings, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the view type settings.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param mixed $val Settings.
|
||||
* @param string $key (optional) Setting key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
* @return void
|
||||
*/
|
||||
final public function set_settings( $val, $key = null, $append = false ) {
|
||||
$this->settings = VAA_API::set_array_data( $this->settings, $val, $key, $append );
|
||||
|
||||
$view_types = (array) $this->store->get_settings( 'view_types' );
|
||||
$view_types[ $this->type ] = $this->get_settings();
|
||||
$settings = array(
|
||||
'view_types' => $view_types,
|
||||
);
|
||||
$this->store->set_settings( $settings );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the view type settings in the database.
|
||||
* Also sets the settings within this instance and VAA store.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param mixed $val Settings.
|
||||
* @param string $key (optional) Setting key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
* @return bool
|
||||
*/
|
||||
final public function update_settings( $val, $key = null, $append = false ) {
|
||||
$this->set_settings( $val, $key, $append ); // Also updates store.
|
||||
return $this->store->update_optionData( $this->store->get_optionData() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the active view types.
|
||||
*
|
||||
* @since 1.8
|
||||
* @static
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
final public static function filter_update_view_types( $data ) {
|
||||
if ( empty( $data['view_types'] ) ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
foreach ( $data['view_types'] as $type => $settings ) {
|
||||
$type = view_admin_as()->get_view_types( $type );
|
||||
if ( ! $type instanceof VAA_View_Admin_As_Type ) {
|
||||
unset( $data['view_types'][ $type ] );
|
||||
continue;
|
||||
}
|
||||
$type->set_settings( $settings );
|
||||
}
|
||||
|
||||
$data['view_types'] = view_admin_as()->store()->get_settings( 'view_types' );
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_Type.
|
||||
167
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-update.php
Executable file
167
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-update.php
Executable file
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Class Update
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update class used for version control and updates.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.6
|
||||
* @version 1.7.4
|
||||
* @uses \VAA_View_Admin_As_Base Extends class
|
||||
*/
|
||||
final class VAA_View_Admin_As_Update extends VAA_View_Admin_As_Base
|
||||
{
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @since 1.6
|
||||
* @static
|
||||
* @var \VAA_View_Admin_As_Update
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* Is this a new installation?
|
||||
*
|
||||
* @since 1.7
|
||||
* @static
|
||||
* @var bool
|
||||
*/
|
||||
public static $fresh_install = false;
|
||||
|
||||
/**
|
||||
* Populate the instance.
|
||||
*
|
||||
* @since 1.6
|
||||
* @since 1.6.1 $vaa param.
|
||||
* @access protected
|
||||
* @param \VAA_View_Admin_As $vaa The main VAA object.
|
||||
*/
|
||||
protected function __construct( $vaa ) {
|
||||
self::$_instance = $this;
|
||||
parent::__construct( $vaa );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the correct DB version in the DB.
|
||||
*
|
||||
* @since 1.4
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_db_update() {
|
||||
$db_version = strtolower( $this->store->get_optionData( 'db_version' ) );
|
||||
if ( ! $db_version ) {
|
||||
self::$fresh_install = true;
|
||||
}
|
||||
if ( self::$fresh_install || version_compare( $db_version, $this->store->get_dbVersion(), '<' ) ) {
|
||||
$this->db_update();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update settings.
|
||||
*
|
||||
* @since 1.4
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
private function db_update() {
|
||||
$defaults = array(
|
||||
'db_version' => $this->store->get_dbVersion(),
|
||||
);
|
||||
|
||||
$current_db_version = strtolower( $this->store->get_optionData( 'db_version' ) );
|
||||
|
||||
// No need to run update script if it's a clean installation.
|
||||
if ( $current_db_version ) {
|
||||
|
||||
// Clear the user views for update to 1.5+.
|
||||
if ( version_compare( $current_db_version, '1.5', '<' ) ) {
|
||||
/**
|
||||
* Reset user meta for all users.
|
||||
* @since 1.6.2 Use `all` param from delete_user_meta().
|
||||
*/
|
||||
$this->store->delete_user_meta( 'all', false, true ); // true for reset_only.
|
||||
// Reset currently loaded data.
|
||||
$this->store->set_userMeta( false );
|
||||
}
|
||||
|
||||
if ( version_compare( $current_db_version, '1.7.2', '<' ) ) {
|
||||
$this->update_1_7_2();
|
||||
}
|
||||
}
|
||||
|
||||
// Update version, append if needed.
|
||||
$this->store->set_optionData( $this->store->get_dbVersion(), 'db_version', true );
|
||||
// Update option data.
|
||||
$this->store->update_optionData( wp_parse_args( $this->store->get_optionData(), $defaults ) );
|
||||
|
||||
// Main update finished, hook used to update modules.
|
||||
do_action( 'vaa_view_admin_as_db_update' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update to version 1.7.2.
|
||||
* Changes yes/no options to boolean types.
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
private function update_1_7_2() {
|
||||
|
||||
$meta = $this->store->get_all_user_meta();
|
||||
|
||||
foreach ( $meta as $user_id => $values ) {
|
||||
foreach ( $values as $column_id => $value ) {
|
||||
if ( ! empty( $value['settings'] ) && is_array( $value['settings'] ) ) {
|
||||
foreach ( $value['settings'] as $key => $val ) {
|
||||
if ( is_bool( $val ) ) {
|
||||
// Update already done.
|
||||
continue;
|
||||
}
|
||||
if ( in_array( $key, array( 'force_group_users', 'freeze_locale', 'hide_front' ), true ) ) {
|
||||
$value['settings'][ $key ] = ( 'yes' === $val );
|
||||
}
|
||||
}
|
||||
$this->store->update_other_user_meta( $value, $user_id, $column_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Re-init VAA store.
|
||||
$this->store->init( true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Instance.
|
||||
*
|
||||
* Ensures only one instance of this class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @static
|
||||
* @param \VAA_View_Admin_As $caller The referrer class.
|
||||
* @return \VAA_View_Admin_As_Update $this
|
||||
*/
|
||||
public static function get_instance( $caller = null ) {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self( $caller );
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_Update.
|
||||
926
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-vaa.php
Executable file
926
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-vaa.php
Executable file
@@ -0,0 +1,926 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Class Init (Main class)
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin initializer class.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 0.1
|
||||
* @version 1.8
|
||||
*/
|
||||
final class VAA_View_Admin_As
|
||||
{
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @since 1.4.1
|
||||
* @static
|
||||
* @var \VAA_View_Admin_As
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* Enable functionalities for this user?
|
||||
*
|
||||
* @since 0.1
|
||||
* @var bool
|
||||
*/
|
||||
private $enable = false;
|
||||
|
||||
/**
|
||||
* Var that holds all the notices.
|
||||
*
|
||||
* @since 1.5.1
|
||||
* @var array[] {
|
||||
* @type string $message The notice message.
|
||||
* @type string $type (optional) The WP notice type class(es).
|
||||
* }
|
||||
*/
|
||||
private $notices = array();
|
||||
|
||||
/**
|
||||
* VAA Hooks.
|
||||
*
|
||||
* @since 1.8
|
||||
* @var \VAA_View_Admin_As_Hooks
|
||||
*/
|
||||
private $hooks = null;
|
||||
|
||||
/**
|
||||
* VAA Store.
|
||||
*
|
||||
* @since 1.6
|
||||
* @var \VAA_View_Admin_As_Store
|
||||
*/
|
||||
private $store = null;
|
||||
|
||||
/**
|
||||
* VAA Controller.
|
||||
*
|
||||
* @since 1.6
|
||||
* @var \VAA_View_Admin_As_Controller
|
||||
*/
|
||||
private $controller = null;
|
||||
|
||||
/**
|
||||
* VAA View handler.
|
||||
*
|
||||
* @since 1.6
|
||||
* @var \VAA_View_Admin_As_View
|
||||
*/
|
||||
private $view = null;
|
||||
|
||||
/**
|
||||
* VAA UI classes that are loaded.
|
||||
*
|
||||
* @since 1.5
|
||||
* @see \VAA_View_Admin_As::load_ui()
|
||||
* @var object[]
|
||||
*/
|
||||
private $ui = array();
|
||||
|
||||
/**
|
||||
* Other VAA modules that are loaded.
|
||||
*
|
||||
* @since 1.4
|
||||
* @see \VAA_View_Admin_As::load_modules()
|
||||
* @see \VAA_View_Admin_As::register_module()
|
||||
* @var \VAA_View_Admin_As_Module[]
|
||||
*/
|
||||
private $modules = array();
|
||||
|
||||
/**
|
||||
* View types.
|
||||
*
|
||||
* @since 1.8
|
||||
* @see \VAA_View_Admin_As::load_modules()
|
||||
* @see \VAA_View_Admin_As::register_view_type()
|
||||
* @var \VAA_View_Admin_As_Type[]
|
||||
*/
|
||||
private $view_types = array();
|
||||
|
||||
/**
|
||||
* Class registry
|
||||
*
|
||||
* @since 1.8
|
||||
* @var array
|
||||
*/
|
||||
private $classes = array(
|
||||
'VAA_API' => 'includes/class-api.php',
|
||||
'VAA_View_Admin_As_Base' => 'includes/class-base.php',
|
||||
'VAA_View_Admin_As_Hooks' => 'includes/class-hooks.php',
|
||||
'VAA_View_Admin_As_Settings' => 'includes/class-settings.php',
|
||||
'VAA_View_Admin_As_Store' => 'includes/class-store.php',
|
||||
'VAA_View_Admin_As_Controller' => 'includes/class-controller.php',
|
||||
'VAA_View_Admin_As_View' => 'includes/class-view.php',
|
||||
'VAA_View_Admin_As_Update' => 'includes/class-update.php',
|
||||
'VAA_View_Admin_As_Compat' => 'includes/class-compat.php',
|
||||
'VAA_View_Admin_As_Type' => 'includes/class-type.php',
|
||||
'VAA_View_Admin_As_Module' => 'includes/class-module.php',
|
||||
'VAA_View_Admin_As_Form' => 'includes/class-form.php',
|
||||
);
|
||||
|
||||
/**
|
||||
* Init function to register plugin hook.
|
||||
* Private to make sure it isn't declared elsewhere.
|
||||
*
|
||||
* @since 0.1
|
||||
* @since 1.3.3 Changes init hook to plugins_loaded for theme compatibility.
|
||||
* @since 1.4.1 Creates instance.
|
||||
* @since 1.5 Make private.
|
||||
* @since 1.5.1 Added notice on class name conflict + validate versions.
|
||||
* @since 1.8 spl_autoload_register().
|
||||
* @access private
|
||||
*/
|
||||
private function __construct() {
|
||||
self::$_instance = $this;
|
||||
|
||||
spl_autoload_register( array( $this, '_autoload' ) );
|
||||
|
||||
add_action( 'init', array( $this, 'load_textdomain' ) );
|
||||
|
||||
if ( is_admin() ) {
|
||||
add_action( 'admin_notices', array( $this, 'do_admin_notices' ) );
|
||||
}
|
||||
|
||||
// Returns false on conflict.
|
||||
if ( ! $this->validate_versions() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Lets start!
|
||||
add_action( 'plugins_loaded', array( $this, 'init' ), -99999 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Class autoloader if needed.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access private
|
||||
* @internal
|
||||
* @param string $class The class name.
|
||||
*/
|
||||
public function _autoload( $class ) {
|
||||
if ( 0 !== strpos( $class, 'VAA_' ) ) {
|
||||
return;
|
||||
}
|
||||
if ( isset( $this->classes[ $class ] ) ) {
|
||||
$this->include_file( VIEW_ADMIN_AS_DIR . $this->classes[ $class ], $class );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate function that checks if the plugin is already loaded.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @param bool $redo (optional) Force re-init?
|
||||
*/
|
||||
public function init( $redo = false ) {
|
||||
static $done = false;
|
||||
if ( $done && ! $redo ) return;
|
||||
|
||||
// We can't do this check before `plugins_loaded` hook.
|
||||
if ( ! is_user_logged_in() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! $done && ! $this->load() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->run();
|
||||
|
||||
$done = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that our classes don't exist yet.
|
||||
* Returns false on conflict.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access private
|
||||
* @return bool Load successfully completed?
|
||||
*/
|
||||
private function load() {
|
||||
|
||||
foreach ( $this->classes as $class => $file ) {
|
||||
if ( ! $this->include_file( VIEW_ADMIN_AS_DIR . $file, $class ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the plugin!
|
||||
* Check current user, load necessary data and register all used hooks.
|
||||
*
|
||||
* @since 0.1
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
private function run() {
|
||||
|
||||
$this->hooks = new VAA_View_Admin_As_Hooks();
|
||||
$this->store = VAA_View_Admin_As_Store::get_instance( $this );
|
||||
$this->controller = VAA_View_Admin_As_Controller::get_instance( $this );
|
||||
$this->view = VAA_View_Admin_As_View::get_instance( $this );
|
||||
|
||||
$this->set_enabled();
|
||||
|
||||
$this->load_modules();
|
||||
|
||||
// Check if a database update is needed.
|
||||
VAA_View_Admin_As_Update::get_instance( $this )->maybe_db_update();
|
||||
|
||||
if ( $this->is_enabled() ) {
|
||||
|
||||
if ( VAA_View_Admin_As_Update::$fresh_install ) {
|
||||
$this->welcome_notice();
|
||||
}
|
||||
|
||||
// Fix some compatibility issues, more to come!
|
||||
VAA_View_Admin_As_Compat::get_instance( $this )->init();
|
||||
|
||||
/**
|
||||
* Plugin enabled + update and compat scripts done.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param \VAA_View_Admin_As $this The main View Admin As object instance.
|
||||
*/
|
||||
do_action( 'vaa_view_admin_as_pre_init', $this );
|
||||
|
||||
$this->controller->init();
|
||||
$this->view->init();
|
||||
|
||||
$this->load_ui();
|
||||
|
||||
/**
|
||||
* Init is finished. Hook is used for other classes related to View Admin As.
|
||||
*
|
||||
* @since 1.5
|
||||
* @param \VAA_View_Admin_As $this The main View Admin As object instance.
|
||||
*/
|
||||
do_action( 'vaa_view_admin_as_init', $this );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to enable plugin functionality.
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function set_enabled() {
|
||||
$this->enable = $this->validate_user();
|
||||
return $this->enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is enabled?
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function is_enabled() {
|
||||
return (bool) $this->enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate if the current user has access to the functionalities.
|
||||
*
|
||||
* @since 0.1 Check if the current user had administrator rights (is_super_admin).
|
||||
* Disable plugin functions for network admin pages.
|
||||
* @since 1.4 Make sure we have a session for the current user.
|
||||
* @since 1.5.1 If a user has the correct capability (view_admin_as + edit_users) this plugin is also enabled, use with care.
|
||||
* Note that in network installations the non-admin user also needs the manage_network_users
|
||||
* capability (of not the edit_users will return false).
|
||||
* @since 1.5.3 Enable on network pages for superior admins.
|
||||
* @since 1.6.3 Created this function.
|
||||
* @access public
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validate_user() {
|
||||
$valid = false;
|
||||
|
||||
if ( ( VAA_API::is_super_admin()
|
||||
|| ( current_user_can( 'view_admin_as' ) && current_user_can( 'edit_users' ) ) )
|
||||
&& ( ! is_network_admin() || VAA_API::is_superior_admin( $this->store->get_curUser()->ID ) )
|
||||
&& $this->store->get_curUserSession()
|
||||
) {
|
||||
$valid = true;
|
||||
}
|
||||
|
||||
return $valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include a file. Optionally checks if the class already exists.
|
||||
*
|
||||
* @since 1.7.1
|
||||
* @access public
|
||||
*
|
||||
* @param string $file The file name.
|
||||
* @param string $class (optional) The class name.
|
||||
* @return bool
|
||||
*/
|
||||
public function include_file( $file, $class = '' ) {
|
||||
static $loaded = array();
|
||||
|
||||
if ( in_array( $file, $loaded, true ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( ! file_exists( $file ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load file.
|
||||
if ( empty( $class ) || ! class_exists( $class, false ) ) {
|
||||
include_once $file;
|
||||
} else {
|
||||
$this->add_error_notice( $class . '::' . __METHOD__, array(
|
||||
'type' => 'notice-error',
|
||||
'message' => __( 'Plugin not fully loaded because of a conflict with an other plugin or theme', VIEW_ADMIN_AS_DOMAIN )
|
||||
// Translators: %s stands for the class name.
|
||||
. ' <code>(' . sprintf( __( 'Class %s already exists', VIEW_ADMIN_AS_DOMAIN ), $class ) . ')</code>',
|
||||
) );
|
||||
return false;
|
||||
}
|
||||
|
||||
$loaded[] = $file;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to include files. Checks class existence and throws an error if needed.
|
||||
* Also adds the class to a supplied group if available.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @param array[]|string[] $includes {
|
||||
* An array of files to include.
|
||||
* @type string $file The file to include. Directory starts from the plugin folder.
|
||||
* @type string $class The class name.
|
||||
* }
|
||||
* @param array $group A reference array.
|
||||
* @return array $group
|
||||
*/
|
||||
public function load_files( $includes, &$group = null ) {
|
||||
|
||||
$group = (array) $group;
|
||||
|
||||
foreach ( $includes as $key => $inc ) {
|
||||
|
||||
if ( is_string( $inc ) ) {
|
||||
$inc = array(
|
||||
'file' => $inc,
|
||||
);
|
||||
if ( is_string( $key ) ) {
|
||||
$inc['class'] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $inc['file'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$class = ( ! empty( $inc['class'] ) ) ? $inc['class'] : '';
|
||||
|
||||
$this->include_file( VIEW_ADMIN_AS_DIR . $inc['file'], $class );
|
||||
|
||||
// If it's a class file, add the class instance to the group.
|
||||
if ( ! empty( $class ) && VAA_API::exists_callable( array( $class, 'get_instance' ) ) ) {
|
||||
$group[ $key ] = call_user_func( array( $class, 'get_instance' ), $this );
|
||||
}
|
||||
}
|
||||
return $group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the user interface.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.5.1 Added notice on class name conflict.
|
||||
* @since 1.6 Added our toolbar class.
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
private function load_ui() {
|
||||
|
||||
$includes = array(
|
||||
'ui' => array(
|
||||
'file' => 'ui/class-ui.php',
|
||||
'class' => 'VAA_View_Admin_As_UI',
|
||||
),
|
||||
'admin_bar' => array(
|
||||
'file' => 'ui/class-admin-bar.php',
|
||||
'class' => 'VAA_View_Admin_As_Admin_Bar',
|
||||
),
|
||||
);
|
||||
|
||||
// Compat for < 4.2 since it breaks due to WP calling require() instead of require_once().
|
||||
if ( VAA_API::validate_wp_version( '4.2' ) ) {
|
||||
$includes['toolbar'] = array(
|
||||
'file' => 'ui/class-toolbar.php',
|
||||
'class' => 'VAA_View_Admin_As_Toolbar',
|
||||
);
|
||||
}
|
||||
|
||||
// Include UI files and add them to the `ui` property.
|
||||
$this->load_files( $includes, $this->ui );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the modules.
|
||||
*
|
||||
* @since 1.5
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
private function load_modules() {
|
||||
|
||||
$includes = array(
|
||||
'role_switcher' => array(
|
||||
'file' => 'modules/class-roles.php',
|
||||
'class' => 'VAA_View_Admin_As_Roles',
|
||||
),
|
||||
'user_switcher' => array(
|
||||
'file' => 'modules/class-users.php',
|
||||
'class' => 'VAA_View_Admin_As_Users',
|
||||
),
|
||||
'capability_switcher' => array(
|
||||
'file' => 'modules/class-caps.php',
|
||||
'class' => 'VAA_View_Admin_As_Caps',
|
||||
),
|
||||
'language_switcher' => array(
|
||||
'file' => 'modules/class-languages.php',
|
||||
'class' => 'VAA_View_Admin_As_Languages',
|
||||
),
|
||||
'role_defaults' => array(
|
||||
'file' => 'modules/class-role-defaults.php',
|
||||
'class' => 'VAA_View_Admin_As_Role_Defaults',
|
||||
),
|
||||
'role_manager' => array(
|
||||
'file' => 'modules/class-role-manager.php',
|
||||
'class' => 'VAA_View_Admin_As_Role_Manager',
|
||||
),
|
||||
);
|
||||
|
||||
if ( VAA_API::exists_callable( array( 'RUA_App', 'instance' ) ) ) {
|
||||
$includes['rua_level'] = array(
|
||||
'file' => 'modules/class-restrict-user-access.php',
|
||||
'class' => 'VAA_View_Admin_As_RUA',
|
||||
);
|
||||
}
|
||||
|
||||
if ( VAA_API::exists_callable( array( 'Groups_Group', 'get_groups' ) ) ) {
|
||||
$includes['groups'] = array(
|
||||
'file' => 'modules/class-groups.php',
|
||||
'class' => 'VAA_View_Admin_As_Groups',
|
||||
);
|
||||
}
|
||||
|
||||
// Run include code but do not register modules yet (leave that to the modules).
|
||||
$this->load_files( $includes );
|
||||
|
||||
/**
|
||||
* Modules loaded. Hook is used for other modules related to View Admin As.
|
||||
*
|
||||
* @since 1.6.2
|
||||
* @param \VAA_View_Admin_As $this The main View Admin As object instance.
|
||||
*/
|
||||
do_action( 'vaa_view_admin_as_modules_loaded', $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load plugin textdomain.
|
||||
*
|
||||
* @since 1.2
|
||||
* @since 1.6 Hooked into init hook, check for is_enabled() required.
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function load_textdomain() {
|
||||
|
||||
if ( ! $this->is_enabled() && empty( $this->notices ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
load_plugin_textdomain( VIEW_ADMIN_AS_DOMAIN );
|
||||
|
||||
/**
|
||||
* Frontend translation of roles is not working by default (Darn you WordPress!).
|
||||
* Needs to be in init action to work.
|
||||
* @see https://core.trac.wordpress.org/ticket/37539
|
||||
*/
|
||||
$wp_mo = WP_LANG_DIR . '/admin-' . get_locale() . '.mo';
|
||||
if ( ! is_admin() && file_exists( $wp_mo ) ) {
|
||||
load_textdomain( 'default', $wp_mo );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hooks class.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @return \VAA_View_Admin_As_Hooks
|
||||
*/
|
||||
public function hooks() {
|
||||
return $this->hooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the store class.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @return \VAA_View_Admin_As_Store
|
||||
*/
|
||||
public function store() {
|
||||
return $this->store;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the controller class.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @return \VAA_View_Admin_As_Controller
|
||||
*/
|
||||
public function controller() {
|
||||
return $this->controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view class.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @return \VAA_View_Admin_As_View
|
||||
*/
|
||||
public function view() {
|
||||
return $this->view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get UI classes.
|
||||
* If a key is provided it will only return that UI class.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @access public
|
||||
* @see \VAA_View_Admin_As::load_ui()
|
||||
* @param string $key (optional) UI class name.
|
||||
* @return \VAA_View_Admin_As_Module|\VAA_View_Admin_As_Module[]
|
||||
*/
|
||||
public function get_ui( $key = null ) {
|
||||
return VAA_API::get_array_data( $this->ui, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get view types.
|
||||
* If a key is provided it will only return that view type.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param string $key (optional) The type key.
|
||||
* @param bool $check_access (optional) Check if the user has access? Default: true.
|
||||
* @return \VAA_View_Admin_As_Type|\VAA_View_Admin_As_Type[]
|
||||
*/
|
||||
public function get_view_types( $key = null, $check_access = true ) {
|
||||
$view_types = $this->view_types;
|
||||
if ( $check_access ) {
|
||||
foreach ( $view_types as $type => $instance ) {
|
||||
if ( ! $instance->has_access() ) {
|
||||
unset( $view_types[ $type ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
$view_types = VAA_API::get_array_data( $view_types, $key );
|
||||
return $view_types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register view types.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param array $data {
|
||||
* Required. An array of module info.
|
||||
* @type string $id The view type name, choose wisely since this is used for validation.
|
||||
* @type VAA_View_Admin_As_Type $instance The view type class reference/instance.
|
||||
* }
|
||||
* @return bool Successfully registered?
|
||||
*/
|
||||
public function register_view_type( $data ) {
|
||||
if ( ! empty( $data['id'] ) && is_string( $data['id'] ) &&
|
||||
! empty( $data['instance'] ) && $data['instance'] instanceof VAA_View_Admin_As_Type
|
||||
) {
|
||||
$this->view_types[ $data['id'] ] = $data['instance'];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current modules.
|
||||
* If a key is provided it will only return that module.
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @see VAA_View_Admin_As::load_modules()
|
||||
* @param string $key (optional) The module key.
|
||||
* @return object|object[]
|
||||
*/
|
||||
public function get_modules( $key = null ) {
|
||||
return VAA_API::get_array_data( $this->modules, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register extra modules.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @param array $data {
|
||||
* Required. An array of module info.
|
||||
* @type string $id The module name, choose wisely since this is used for validation.
|
||||
* @type VAA_View_Admin_As_Module $instance The module class reference/instance.
|
||||
* }
|
||||
* @return bool Successfully registered?
|
||||
*/
|
||||
public function register_module( $data ) {
|
||||
if ( ! empty( $data['id'] ) && is_string( $data['id'] ) &&
|
||||
! empty( $data['instance'] ) && $data['instance'] instanceof VAA_View_Admin_As_Module
|
||||
) {
|
||||
$this->modules[ $data['id'] ] = $data['instance'];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a welcome notice for new users.
|
||||
*
|
||||
* @since 1.7
|
||||
* @access public
|
||||
*/
|
||||
public function welcome_notice() {
|
||||
$this->add_notice( 'vaa-welcome', array(
|
||||
'type' => 'notice-success',
|
||||
'message' => sprintf(
|
||||
// Translators: %s stands for `Dashboard` (link element).
|
||||
__( 'For the best experience you can start from the %s since not all views are allowed to access all admin pages.', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'<a class="button button-primary" href="' . admin_url() . '">' . __( 'Dashboard' ) . '</a>'
|
||||
),
|
||||
'prepend' => __( 'Thank you for installing View Admin As!', VIEW_ADMIN_AS_DOMAIN ),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add error notices to generate.
|
||||
* Automatically generated a bug report link at the end of the notice.
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @access public
|
||||
*
|
||||
* @param string $id
|
||||
* @param array $notice {
|
||||
* Required array.
|
||||
* @type string $message The notice message.
|
||||
* @type string $type (optional) The WP notice type class(es).
|
||||
* @type string $prepend (optional) Prepend the message (bold). Default: View Admin As.
|
||||
* Pass `false` or `null` to remove.
|
||||
* }
|
||||
* @return void
|
||||
*/
|
||||
public function add_error_notice( $id, $notice ) {
|
||||
if ( empty( $notice['message'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notice['type'] = ( ! empty( $notice['type'] ) ) ? $notice['type'] : 'notice-error';
|
||||
|
||||
// @todo Add debug_backtrace to body?
|
||||
$report = array(
|
||||
'title' => __( 'Error', VIEW_ADMIN_AS_DOMAIN ) . ': ' . $id,
|
||||
'body' => $notice['message'],
|
||||
);
|
||||
$report_link = add_query_arg( $report, 'https://github.com/JoryHogeveen/view-admin-as/issues/new' );
|
||||
|
||||
$notice['message'] = $notice['message']
|
||||
. ' <a href="' . $report_link . '" target="_blank">'
|
||||
. __( 'Click here to report this error!', VIEW_ADMIN_AS_DOMAIN )
|
||||
. '</a>';
|
||||
|
||||
$this->add_notice( $id, $notice );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add notices to generate.
|
||||
*
|
||||
* @since 1.5.1
|
||||
* @access public
|
||||
*
|
||||
* @param string $id
|
||||
* @param array $notice {
|
||||
* Required array.
|
||||
* @type string $message The notice message.
|
||||
* @type string $type (optional) The WP notice type class(es).
|
||||
* @type string $prepend (optional) Prepend the message (bold). Default: View Admin As.
|
||||
* Pass `false` or `null` to remove.
|
||||
* }
|
||||
* @return void
|
||||
*/
|
||||
public function add_notice( $id, $notice ) {
|
||||
if ( ! empty( $notice['message'] ) ) {
|
||||
$notice = array_merge( array(
|
||||
'type' => '',
|
||||
'prepend' => __( 'View Admin As', VIEW_ADMIN_AS_DOMAIN ),
|
||||
), $notice );
|
||||
|
||||
if ( $notice['prepend'] ) {
|
||||
$notice['message'] = '<strong>' . $notice['prepend'] . ':</strong> ' . $notice['message'];
|
||||
}
|
||||
$this->notices[ $id ] = array(
|
||||
'type' => $notice['type'],
|
||||
'message' => $notice['message'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Echo admin notices.
|
||||
*
|
||||
* @since 1.5.1
|
||||
* @access public
|
||||
* @see 'admin_notices'
|
||||
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/admin_notices
|
||||
* @return void
|
||||
*/
|
||||
public function do_admin_notices() {
|
||||
foreach ( $this->notices as $notice ) {
|
||||
if ( isset( $notice['type'] ) && ! empty( $notice['message'] ) ) {
|
||||
echo '<div class="' . $notice['type'] . ' notice is-dismissible"><p>' . $notice['message'] . '</p></div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate plugin activate.
|
||||
* Checks for valid resources.
|
||||
*
|
||||
* @since 1.5.1
|
||||
* @since 1.6 Returns conflict status.
|
||||
* @access private
|
||||
* @global string $wp_version WordPress version.
|
||||
* @return bool
|
||||
*/
|
||||
private function validate_versions() {
|
||||
global $wp_version;
|
||||
// Start positive!
|
||||
$valid = true;
|
||||
|
||||
// Validate WP.
|
||||
$min_wp_version = '4.1';
|
||||
if ( version_compare( $wp_version, $min_wp_version, '<' ) ) {
|
||||
$this->add_notice( 'wp-version', array(
|
||||
'type' => 'notice-error',
|
||||
'message' => sprintf(
|
||||
// Translators: %1$s stands for "WordPress", %2$s stands for the version.
|
||||
__( 'Plugin deactivated, %1$s version %2$s or higher is required', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'WordPress',
|
||||
$min_wp_version
|
||||
),
|
||||
) );
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
if ( ! $valid ) {
|
||||
// Too bad..
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
deactivate_plugins( VIEW_ADMIN_AS_BASENAME );
|
||||
}
|
||||
|
||||
return $valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets update class to run a DB update.
|
||||
* @since 1.8
|
||||
*/
|
||||
public static function run_db_update() {
|
||||
// Make sure the main class is initialized.
|
||||
view_admin_as();
|
||||
// Set the update class to a fresh installation which will trigger the update.
|
||||
VAA_View_Admin_As_Update::$fresh_install = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this plugin network enabled.
|
||||
*
|
||||
* @since 1.7.5
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_network_active() {
|
||||
static $check;
|
||||
if ( is_bool( $check ) ) {
|
||||
return $check;
|
||||
}
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
$check = (bool) is_plugin_active_for_network( VIEW_ADMIN_AS_BASENAME );
|
||||
return $check;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main View Admin As instance.
|
||||
* Ensures only one instance of View Admin As is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.4.1
|
||||
* @access public
|
||||
* @static
|
||||
* @see view_admin_as()
|
||||
* @return \VAA_View_Admin_As $this The main View Admin As object instance.
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to output a string if trying to use the object as a string.
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function __toString() {
|
||||
return get_class( $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to keep the object from being cloned.
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function __clone() {
|
||||
_doing_it_wrong(
|
||||
__FUNCTION__,
|
||||
esc_html( get_class( $this ) . ': ' . __( 'This class does not want to be cloned', VIEW_ADMIN_AS_DOMAIN ) ),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to keep the object from being unserialized.
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function __wakeup() {
|
||||
_doing_it_wrong(
|
||||
__FUNCTION__,
|
||||
esc_html( get_class( $this ) . ': ' . __( 'This class does not want to wake up', VIEW_ADMIN_AS_DOMAIN ) ),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to prevent a fatal error when calling a method that doesn't exist.
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @param string $method The method name.
|
||||
* @param array $args The method arguments.
|
||||
* @return null
|
||||
*/
|
||||
public function __call( $method = '', $args = array() ) {
|
||||
_doing_it_wrong(
|
||||
esc_html( get_class( $this ) . "::{$method}" ),
|
||||
esc_html__( 'Method does not exist.', VIEW_ADMIN_AS_DOMAIN ),
|
||||
null
|
||||
);
|
||||
unset( $method, $args );
|
||||
return null;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As.
|
||||
535
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-view.php
Executable file
535
backend/wordpress/wp-content/plugins/view-admin-as/includes/class-view.php
Executable file
@@ -0,0 +1,535 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Class View
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* View handler class.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.6
|
||||
* @since 1.7 Class got split up: data handling/updating is now in VAA_View_Admin_As_Controller.
|
||||
* @version 1.8
|
||||
* @uses \VAA_View_Admin_As_Base Extends class
|
||||
*/
|
||||
final class VAA_View_Admin_As_View extends VAA_View_Admin_As_Base
|
||||
{
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @since 1.6
|
||||
* @static
|
||||
* @var \VAA_View_Admin_As_View
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* Is the current user modified?
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @var bool
|
||||
*/
|
||||
private $is_user_modified = false;
|
||||
|
||||
/**
|
||||
* VAA_View_Admin_As_View constructor.
|
||||
*
|
||||
* @since 1.6
|
||||
* @since 1.6.1 $vaa param.
|
||||
* @access protected
|
||||
* @param \VAA_View_Admin_As $vaa The main VAA object.
|
||||
*/
|
||||
protected function __construct( $vaa ) {
|
||||
self::$_instance = $this;
|
||||
parent::__construct( $vaa );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes after VAA is enabled.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function init() {
|
||||
if ( $this->store->get_view() ) {
|
||||
$this->do_view();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply view data.
|
||||
*
|
||||
* @since 1.6.3 Put logic in it's own function.
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
private function do_view() {
|
||||
|
||||
// @since 1.6.4 Set the current user as the selected user by default.
|
||||
$this->store->set_selectedUser( $this->store->get_curUser() );
|
||||
$this->store->set_selectedCaps( $this->store->get_curUser()->allcaps );
|
||||
|
||||
/**
|
||||
* VISITOR.
|
||||
* Current user object views (switches current user).
|
||||
*
|
||||
* @since 1.6.2 Visitor view.
|
||||
*/
|
||||
if ( $this->store->get_view( 'visitor' ) ) {
|
||||
|
||||
/**
|
||||
* Change current user object so changes can be made on various screen settings.
|
||||
* wp_set_current_user() returns the new user object.
|
||||
*
|
||||
* If it is a visitor view it will convert the false return from 'user' to 0.
|
||||
*/
|
||||
$this->store->set_selectedUser( wp_set_current_user( 0 ) );
|
||||
|
||||
// @since 1.6.2 Set the caps for this view (user view).
|
||||
if ( isset( $this->store->get_selectedUser()->allcaps ) ) {
|
||||
$this->store->set_selectedCaps( $this->store->get_selectedUser()->allcaps );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* View data is set, apply the view.
|
||||
* This hook can be used by other modules to enable a view.
|
||||
*
|
||||
* Temporary modifications to the current user are set on priority 99.
|
||||
* This functionality has a separate action: `vaa_view_admin_as_modify_current_user`.
|
||||
*
|
||||
* @since 1.6.3
|
||||
* @param array
|
||||
*/
|
||||
do_action( 'vaa_view_admin_as_do_view', $this->store->get_view() );
|
||||
|
||||
/**
|
||||
* Force own locale on view.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @since 1.7.5 Add filter `view_admin_as_freeze_locale`.
|
||||
*
|
||||
* @param bool $freeze_locale The user setting.
|
||||
* @return bool
|
||||
*/
|
||||
$freeze_locale = apply_filters( 'view_admin_as_freeze_locale', $this->store->get_userSettings( 'freeze_locale' ) );
|
||||
if ( $freeze_locale && (int) $this->store->get_curUser()->ID !== (int) $this->store->get_selectedUser()->ID ) {
|
||||
$this->add_action( 'after_setup_theme', array( $this, 'freeze_locale' ), 0 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the actions and filters to modify the current user object.
|
||||
* Can only be run once.
|
||||
*
|
||||
* @since 1.6.3
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function init_user_modifications() {
|
||||
static $done;
|
||||
if ( $done ) return;
|
||||
|
||||
$this->is_user_modified = true;
|
||||
|
||||
$this->add_action( 'vaa_view_admin_as_do_view', array( $this, 'modify_user' ), 99 );
|
||||
|
||||
/**
|
||||
* Make sure the $current_user view data isn't overwritten again by switch_blog functions.
|
||||
* @see This filter is documented in wp-includes/ms-blogs.php
|
||||
* @since 1.6.3
|
||||
*/
|
||||
$this->add_action( 'switch_blog', array( $this, 'modify_user' ) );
|
||||
|
||||
/**
|
||||
* Prevent some meta updates for the current user while in modification to the current user are active.
|
||||
* @since 1.6.3
|
||||
*/
|
||||
$this->add_filter( 'update_user_metadata' , array( $this, 'filter_prevent_update_user_metadata' ), 999999999, 3 );
|
||||
|
||||
/**
|
||||
* Get capabilities and user level from current user view object instead of database.
|
||||
* @since 1.6.4
|
||||
*/
|
||||
$this->add_filter( 'get_user_metadata' , array( $this, 'filter_overrule_get_user_metadata' ), 999999999, 3 );
|
||||
|
||||
// `user_has_cap` priority.
|
||||
$priority = -999999999;
|
||||
if ( $this->store->get_view( 'caps' ) ) {
|
||||
// Overwrite everything when the capability view is active.
|
||||
remove_all_filters( 'user_has_cap' );
|
||||
$priority = 999999999;
|
||||
}
|
||||
/**
|
||||
* The priority value of the VAA `user_has_cap` filter.
|
||||
* Runs as first by default.
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @param int $priority
|
||||
* @return int
|
||||
*/
|
||||
$priority = (int) apply_filters( 'view_admin_as_user_has_cap_priority', $priority );
|
||||
|
||||
/**
|
||||
* Change the capabilities.
|
||||
*
|
||||
* @since 1.7.1
|
||||
* @since 1.7.2 Changed priority to set is at the beginning instead of as last
|
||||
* to allow other plugins to filter based on the modified user.
|
||||
*/
|
||||
$this->add_filter( 'user_has_cap', array( $this, 'filter_user_has_cap' ), $priority, 4 );
|
||||
|
||||
/**
|
||||
* Map the capabilities (map_meta_cap is used for compatibility with network admins).
|
||||
* Filter as last to check other plugin changes as well.
|
||||
*
|
||||
* @since 0.1
|
||||
*/
|
||||
$this->add_filter( 'map_meta_cap', array( $this, 'filter_map_meta_cap' ), 999999999, 4 );
|
||||
|
||||
/**
|
||||
* Disable super admin status for the current user.
|
||||
* @since 1.7.3
|
||||
* @since 1.8 Check for multisite.
|
||||
*/
|
||||
if ( is_multisite() &&
|
||||
! is_network_admin() &&
|
||||
is_super_admin( $this->store->get_selectedUser()->ID ) &&
|
||||
$this->store->get_userSettings( 'disable_super_admin' )
|
||||
) {
|
||||
$this->disable_super_admin();
|
||||
}
|
||||
|
||||
$done = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the current user's WP_User instance with the current view capabilities.
|
||||
*
|
||||
* @since 1.6.3
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function modify_user() {
|
||||
|
||||
// Can be the current or selected WP_User object (depending on the user view).
|
||||
$user = $this->store->get_selectedUser();
|
||||
|
||||
/**
|
||||
* Allow other modules to hook after the initial changes to the current user.
|
||||
*
|
||||
* @since 1.6.3
|
||||
* @since 1.6.4 Changed name (was: `vaa_view_admin_as_modify_current_user`).
|
||||
* @param \WP_User $user The modified user object.
|
||||
*/
|
||||
do_action( 'vaa_view_admin_as_modify_user', $user );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent some updates to the current user like roles and capabilities.
|
||||
* to prevent problems when making changes within a view.
|
||||
*
|
||||
* IMPORTANT! This filter should ONLY be used when a view is selected!
|
||||
*
|
||||
* @since 1.6.3
|
||||
* @access public
|
||||
* @see init_current_user_modifications()
|
||||
*
|
||||
* @see 'update_user_metadata' filter
|
||||
* @link https://codex.wordpress.org/Plugin_API/Filter_Reference/update_(meta_type)_metadata
|
||||
* @link http://hookr.io/filters/update_user_metadata/
|
||||
*
|
||||
* @global \wpdb $wpdb
|
||||
* @param null $null Whether to allow updating metadata for the given type.
|
||||
* @param int $object_id Object ID.
|
||||
* @param string $meta_key Meta key.
|
||||
* @return mixed
|
||||
*/
|
||||
public function filter_prevent_update_user_metadata( $null, $object_id, $meta_key ) {
|
||||
global $wpdb;
|
||||
$user = $this->store->get_selectedUser();
|
||||
|
||||
// Check if the object being updated is the current user.
|
||||
if ( (int) $user->ID === (int) $object_id ) {
|
||||
|
||||
// Capabilities meta key check.
|
||||
if ( empty( $user->cap_key ) ) {
|
||||
$user->cap_key = $wpdb->get_blog_prefix() . 'capabilities';
|
||||
}
|
||||
|
||||
// Do not update the current user capabilities or user level while in a view.
|
||||
if ( in_array( $meta_key, array(
|
||||
$user->cap_key,
|
||||
$wpdb->get_blog_prefix() . 'capabilities',
|
||||
$wpdb->get_blog_prefix() . 'user_level',
|
||||
), true ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return $null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return view roles when getting the current user data to prevent reloading current user data within a view.
|
||||
*
|
||||
* IMPORTANT! This filter should ONLY be used when a view is selected!
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @access public
|
||||
* @see init_current_user_modifications()
|
||||
*
|
||||
* @see 'get_user_metadata' filter
|
||||
* @link https://codex.wordpress.org/Plugin_API/Filter_Reference/get_(meta_type)_metadata
|
||||
*
|
||||
* @global \wpdb $wpdb
|
||||
* @param null $null The value update_metadata() should return.
|
||||
* @param int $object_id Object ID.
|
||||
* @param string $meta_key Meta key.
|
||||
* @return mixed
|
||||
*/
|
||||
public function filter_overrule_get_user_metadata( $null, $object_id, $meta_key ) {
|
||||
global $wpdb;
|
||||
$user = $this->store->get_selectedUser();
|
||||
|
||||
// Check if the object being updated is the current user.
|
||||
if ( (int) $user->ID === (int) $object_id ) {
|
||||
|
||||
// Return the current user capabilities or user level while in a view.
|
||||
// Always return an array to fix $single usage.
|
||||
|
||||
// Current user cap key should be equal to the meta_key for capabilities.
|
||||
if ( ! empty( $user->cap_key ) && $meta_key === $user->cap_key ) {
|
||||
return array( $user->caps );
|
||||
}
|
||||
// Fallback if cap_key doesn't exists.
|
||||
if ( $meta_key === $wpdb->get_blog_prefix() . 'capabilities' ) {
|
||||
return array( $user->caps );
|
||||
}
|
||||
if ( $meta_key === $wpdb->get_blog_prefix() . 'user_level' ) {
|
||||
if ( ! isset( $user->user_level ) ) {
|
||||
// Make sure the key exists. Result will be filtered in `filter_prevent_update_user_metadata()`.
|
||||
$user->update_user_level_from_caps();
|
||||
}
|
||||
return array( $user->user_level );
|
||||
}
|
||||
}
|
||||
return $null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change capabilities when the user has selected a view.
|
||||
* If the capability isn't in the chosen view, then make the value for this capability empty and add "do_not_allow".
|
||||
*
|
||||
* @since 0.1
|
||||
* @since 1.5 Changed function name to map_meta_cap (was change_caps).
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.6.2 Use logic from current_view_can().
|
||||
* @since 1.6.3 Prefix function name with `filter_`.
|
||||
* @since 1.7.2 Use the `user_has_cap` filter for compatibility enhancements.
|
||||
* @access public
|
||||
*
|
||||
* @param array $caps The actual (mapped) cap names, if the caps are not mapped this returns the requested cap.
|
||||
* @param string $cap The capability that was requested.
|
||||
* @param int $user_id The ID of the user.
|
||||
* @param array $args Adds the context to the cap. Typically the object ID (not used).
|
||||
* @return array $caps
|
||||
*/
|
||||
public function filter_map_meta_cap( $caps, $cap, $user_id, $args = array() ) {
|
||||
|
||||
if ( (int) $this->store->get_selectedUser()->ID !== (int) $user_id ) {
|
||||
return $caps;
|
||||
}
|
||||
|
||||
$filter_caps = (array) $this->store->get_selectedCaps();
|
||||
|
||||
if ( ! $this->store->get_view( 'caps' ) ) {
|
||||
/**
|
||||
* Apply user_has_cap filters to make sure we are compatible with modifications from other plugins.
|
||||
*
|
||||
* Issues found:
|
||||
* - Restrict User Access - Overwrites our filtered capabilities. (fixed since RUA 0.15.x).
|
||||
* - Groups - Overwrites our filtered capabilities. (fixed in Groups module).
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @see \WP_User::has_cap()
|
||||
*/
|
||||
$filter_caps = apply_filters(
|
||||
'user_has_cap',
|
||||
$filter_caps,
|
||||
$caps,
|
||||
// Replicate arguments for `user_has_cap`.
|
||||
array_merge( array( $cap, $user_id ), (array) $args ),
|
||||
$this->store->get_selectedUser()
|
||||
);
|
||||
}
|
||||
|
||||
foreach ( (array) $caps as $actual_cap ) {
|
||||
if ( ! $this->current_view_can( $actual_cap, $filter_caps ) ) {
|
||||
// Regular users. Assuming this capability never exists..
|
||||
$caps['vaa_do_not_allow'] = 'vaa_do_not_allow';
|
||||
// Network admins.
|
||||
$caps['do_not_allow'] = 'do_not_allow';
|
||||
}
|
||||
}
|
||||
|
||||
return $caps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite the user's capabilities.
|
||||
*
|
||||
* @since 1.6.3
|
||||
* @access public
|
||||
*
|
||||
* @param array $allcaps All the capabilities of the user.
|
||||
* @param array $caps Actual capabilities for meta capability.
|
||||
* @param array $args [0] Requested capability.
|
||||
* [1] User ID.
|
||||
* [2] Associated object ID.
|
||||
* @param \WP_User $user (WP 3.7+) The user object.
|
||||
* @return array
|
||||
*/
|
||||
public function filter_user_has_cap( $allcaps, $caps, $args, $user = null ) {
|
||||
$user_id = ( $user ) ? $user->ID : $args[1];
|
||||
if ( is_numeric( $user_id ) && (int) $user_id === (int) $this->store->get_selectedUser()->ID ) {
|
||||
return (array) $this->store->get_selectedCaps();
|
||||
}
|
||||
return $allcaps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the current user from the list of super admins.
|
||||
* This sets/changes the global $super_admins variable which overwrites the site option.
|
||||
*
|
||||
* @since 1.7.3
|
||||
* @access public
|
||||
* @see grant_super_admin() >> wp-includes/capabilities.php
|
||||
* @see revoke_super_admin() >> wp-includes/capabilities.php
|
||||
* @see get_super_admins() >> wp-includes/capabilities.php
|
||||
* @see is_super_admin() >> wp-includes/capabilities.php
|
||||
* @link https://developer.wordpress.org/reference/functions/is_super_admin/
|
||||
*
|
||||
* @global array $super_admins
|
||||
* @param \WP_User|int|string $user (optional) A user to remove. Both a user object or a user field is accepted.
|
||||
* @param string $field (optional) A user field key to get the user data by.
|
||||
*/
|
||||
public function disable_super_admin( $user = null, $field = 'id' ) {
|
||||
global $super_admins;
|
||||
|
||||
if ( ! isset( $super_admins ) ) {
|
||||
$super_admins = get_super_admins();
|
||||
}
|
||||
|
||||
$user = ( null !== $user ) ? $user : $this->store->get_selectedUser();
|
||||
if ( ! $user instanceof WP_User ) {
|
||||
$user = get_user_by( $field, $user );
|
||||
}
|
||||
|
||||
// Remove current user from the super admins array.
|
||||
// Effectively disables functions grant_super_admin() and revoke_super_admin().
|
||||
if ( ! empty( $user->user_login ) && is_array( $super_admins ) ) {
|
||||
$key = array_search( $user->user_login, $super_admins, true );
|
||||
if ( false !== $key ) {
|
||||
unset( $super_admins[ $key ] );
|
||||
$GLOBALS['super_admins'] = $super_admins;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar function to current_user_can().
|
||||
*
|
||||
* @since 1.6.2
|
||||
* @since 1.8 Check for non-scalar types being passed as first parameter.
|
||||
* @access public
|
||||
*
|
||||
* @param string $cap The capability.
|
||||
* @param array $caps (optional) Capabilities to compare to.
|
||||
* Defaults to the selected caps for the current view.
|
||||
* @return bool
|
||||
*/
|
||||
public function current_view_can( $cap, $caps = array() ) {
|
||||
|
||||
if ( empty( $caps ) ) {
|
||||
$caps = $this->store->get_selectedCaps();
|
||||
}
|
||||
|
||||
if ( ! is_scalar( $cap ) ) {
|
||||
$cap = (array) $cap;
|
||||
foreach ( $cap as $capability ) {
|
||||
if ( ! $this->current_view_can( $capability, $caps ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
$cap = (string) $cap;
|
||||
|
||||
if ( is_array( $caps ) &&
|
||||
! empty( $caps[ $cap ] ) &&
|
||||
'do_not_allow' !== $cap &&
|
||||
'do_not_allow' !== $caps[ $cap ]
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the current user modified?
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function is_user_modified() {
|
||||
return (bool) $this->is_user_modified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the locale for the current view.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @access public
|
||||
* @return bool Will return false when used with older WP versions.
|
||||
*/
|
||||
public function freeze_locale() {
|
||||
if ( function_exists( 'get_user_locale' ) && function_exists( 'switch_to_locale' ) ) {
|
||||
$locale = get_user_locale( $this->store->get_curUser()->ID );
|
||||
if ( get_locale() !== $locale ) {
|
||||
switch_to_locale( $locale );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Instance.
|
||||
*
|
||||
* Ensures only one instance of this class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @static
|
||||
* @param \VAA_View_Admin_As $caller The referrer class.
|
||||
* @return \VAA_View_Admin_As_View $this
|
||||
*/
|
||||
public static function get_instance( $caller = null ) {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self( $caller );
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_View.
|
||||
2
backend/wordpress/wp-content/plugins/view-admin-as/includes/index.php
Executable file
2
backend/wordpress/wp-content/plugins/view-admin-as/includes/index.php
Executable file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
//Nothing to see here
|
||||
2
backend/wordpress/wp-content/plugins/view-admin-as/index.php
Executable file
2
backend/wordpress/wp-content/plugins/view-admin-as/index.php
Executable file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
//Nothing to see here
|
||||
280
backend/wordpress/wp-content/plugins/view-admin-as/license.txt
Executable file
280
backend/wordpress/wp-content/plugins/view-admin-as/license.txt
Executable file
@@ -0,0 +1,280 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
497
backend/wordpress/wp-content/plugins/view-admin-as/modules/class-caps.php
Executable file
497
backend/wordpress/wp-content/plugins/view-admin-as/modules/class-caps.php
Executable file
@@ -0,0 +1,497 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - User switcher
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* User switcher view type.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.3 View type existed in core.
|
||||
* @since 1.8 Created this class.
|
||||
* @version 1.8
|
||||
* @uses \VAA_View_Admin_As_Type Extends class
|
||||
*/
|
||||
class VAA_View_Admin_As_Caps extends VAA_View_Admin_As_Type
|
||||
{
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @since 1.8
|
||||
* @static
|
||||
* @var \VAA_View_Admin_As_Caps
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* @since 1.8
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'caps';
|
||||
|
||||
/**
|
||||
* The icon for this view type.
|
||||
*
|
||||
* @since 1.8
|
||||
* @var string
|
||||
*/
|
||||
protected $icon = 'dashicons-forms';
|
||||
|
||||
/**
|
||||
* Populate the instance.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access protected
|
||||
* @param \VAA_View_Admin_As $vaa The main VAA object.
|
||||
*/
|
||||
protected function __construct( $vaa ) {
|
||||
self::$_instance = $this;
|
||||
parent::__construct( $vaa );
|
||||
|
||||
if ( ! $this->has_access() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->priorities = array(
|
||||
'toolbar' => 10,
|
||||
'view_title' => 80,
|
||||
'validate_view_data' => 10,
|
||||
'update_view' => 10,
|
||||
'do_view' => 8,
|
||||
);
|
||||
|
||||
$this->label = __( 'Capabilities', VIEW_ADMIN_AS_DOMAIN );
|
||||
$this->label_singular = __( 'Capability', VIEW_ADMIN_AS_DOMAIN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the user view.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
*/
|
||||
public function do_view() {
|
||||
|
||||
if ( parent::do_view() ) {
|
||||
|
||||
$this->add_action( 'vaa_view_admin_as_modify_user', array( $this, 'modify_user' ), 2, 2 );
|
||||
$this->init_user_modifications();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the current user object.
|
||||
*
|
||||
* @since 1.3
|
||||
* @param \WP_User $user The modified user object.
|
||||
*/
|
||||
public function modify_user( $user ) {
|
||||
|
||||
$view_data = $this->store->get_view( $this->type );
|
||||
|
||||
if ( is_array( $view_data ) ) {
|
||||
// @since 1.6.3 Set the current user's caps (roles) to the current view.
|
||||
$user->allcaps = array_merge(
|
||||
(array) array_filter( $view_data ),
|
||||
(array) $user->caps // Contains the current user roles.
|
||||
);
|
||||
// Set the selected capabilities.
|
||||
$this->store->set_selectedCaps( $user->allcaps );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the VAA admin bar menu title.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param array $titles The current title(s).
|
||||
* @return array
|
||||
*/
|
||||
public function view_title( $titles = array() ) {
|
||||
if ( $this->selected ) {
|
||||
$titles[] = $this->label;
|
||||
}
|
||||
return $titles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate data for this view type
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.8 Moved from VAA_View_Admin_As_Controller
|
||||
* @access public
|
||||
* @param null $null Default return (invalid)
|
||||
* @param mixed $data The view data
|
||||
* @return mixed
|
||||
*/
|
||||
public function validate_view_data( $null, $data = null ) {
|
||||
// Caps data must be an array
|
||||
if ( is_array( $data ) ) {
|
||||
|
||||
// The data is an array, most likely from the database.
|
||||
$data = array_map( 'absint', $data );
|
||||
// Sort the new caps the same way we sort the existing caps.
|
||||
ksort( $data );
|
||||
|
||||
// Only allow assigned capabilities if it isn't a super admin.
|
||||
if ( ! VAA_API::is_super_admin() ) {
|
||||
$data = array_intersect_key( $data, $this->store->get_caps() );
|
||||
}
|
||||
|
||||
// @since 1.7.4 Forbidden capabilities.
|
||||
unset( $data['do_not_allow'] );
|
||||
unset( $data['vaa_do_not_allow'] );
|
||||
|
||||
return $data;
|
||||
}
|
||||
return $null;
|
||||
}
|
||||
|
||||
/**
|
||||
* View update handler (Ajax probably), called from main handler.
|
||||
*
|
||||
* @since 1.8 Renamed from `ajax_handler`
|
||||
* @access public
|
||||
* @param null $null Null.
|
||||
* @param array $data The ajax data for this module.
|
||||
* @param string $type The view type.
|
||||
* @return bool
|
||||
*/
|
||||
public function update_view( $null, $data, $type = null ) {
|
||||
$success = $null;
|
||||
if ( ! is_array( $data ) || $this->type !== $type ) {
|
||||
return $success;
|
||||
}
|
||||
|
||||
// Check if the selected caps are equal to the default caps.
|
||||
if ( VAA_API::array_equal( $this->store->get_curUser()->allcaps, $data ) ) {
|
||||
// The selected caps are equal to the current user default caps so we can reset the view.
|
||||
$this->vaa->controller()->reset_view();
|
||||
if ( $this->selected ) {
|
||||
// The user was in a custom caps view.
|
||||
$success = true; // and continue.
|
||||
} else {
|
||||
// The user was in his default view, notify the user.
|
||||
$success = array(
|
||||
'success' => false,
|
||||
'data' => array(
|
||||
'type' => 'message',
|
||||
'text' => esc_html__( 'These are your default capabilities!', VIEW_ADMIN_AS_DOMAIN ),
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Store the selected caps.
|
||||
$new_caps = array_map( 'absint', $data );
|
||||
|
||||
// Check if the new caps selection is different.
|
||||
if ( VAA_API::array_equal( $this->selected, $new_caps ) ) {
|
||||
$success = array(
|
||||
'success' => false,
|
||||
'data' => array(
|
||||
'type' => 'message',
|
||||
'text' => esc_html__( 'This view is already selected!', VIEW_ADMIN_AS_DOMAIN ),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
$this->store->set_view( $data, $type, true );
|
||||
$success = true;
|
||||
}
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the admin bar items.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.8 Moved from VAA_View_Admin_As_Admin_Bar.
|
||||
* @access public
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The root item.
|
||||
*/
|
||||
public function admin_bar_menu( $admin_bar, $root ) {
|
||||
static $done;
|
||||
if ( $done ) return;
|
||||
|
||||
/**
|
||||
* Make sure we have the latest added capabilities.
|
||||
* It can be that a plugin/theme adds a capability after the initial call to store_caps (hook: 'plugins_loaded').
|
||||
*
|
||||
* @see \VAA_View_Admin_As::run()
|
||||
* @since 1.4.1
|
||||
*/
|
||||
$this->store_data();
|
||||
|
||||
if ( ! $this->get_data() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the capability manager should be loaded as a submenu from the title element or as a separate node below the title.
|
||||
* Default: true.
|
||||
* Useful if you have a plugin that adds another sub-node below the capability title.
|
||||
*
|
||||
* @since 1.7.5
|
||||
* @return bool
|
||||
*/
|
||||
$title_submenu = (bool) apply_filters( 'vaa_admin_bar_caps_do_title_submenu', true );
|
||||
|
||||
$main_root = $root;
|
||||
$root = $main_root . '-caps';
|
||||
|
||||
$admin_bar->add_group( array(
|
||||
'id' => $root,
|
||||
'parent' => $main_root,
|
||||
'meta' => array(
|
||||
'class' => 'ab-sub-secondary',
|
||||
),
|
||||
) );
|
||||
|
||||
$title_class = '';
|
||||
if ( $title_submenu ) {
|
||||
$title_class .= ( $this->selected ) ? ' current' : '';
|
||||
} else {
|
||||
$title_class .= ' ab-vaa-toggle active';
|
||||
}
|
||||
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-title',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_icon( $this->icon ) . $this->label,
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'vaa-has-icon ab-vaa-title' . $title_class,
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
|
||||
/**
|
||||
* Add items at the beginning of the caps group.
|
||||
*
|
||||
* @since 1.5
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @param string $main_root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_caps_before', $admin_bar, $root, $main_root );
|
||||
|
||||
if ( $title_submenu ) {
|
||||
$admin_bar->add_group( array(
|
||||
'id' => $root . '-manager',
|
||||
'parent' => $root . '-title',
|
||||
) );
|
||||
} else {
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-manager',
|
||||
'parent' => $root,
|
||||
'title' => __( 'Manager', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => ( $this->selected ) ? 'current' : '',
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
}
|
||||
|
||||
// Capabilities submenu.
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-applycaps',
|
||||
'parent' => $root . '-manager',
|
||||
'title' => VAA_View_Admin_As_Form::do_button( array(
|
||||
'name' => 'apply-caps-view',
|
||||
'label' => __( 'Apply', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'class' => 'button-primary',
|
||||
) )
|
||||
. VAA_View_Admin_As_Form::do_button( array(
|
||||
'name' => 'close-caps-popup',
|
||||
'label' => VAA_View_Admin_As_Form::do_icon( 'dashicons-editor-contract' ),
|
||||
'class' => 'button-secondary vaa-icon vaa-hide-responsive',
|
||||
'element' => 'a',
|
||||
) )
|
||||
. VAA_View_Admin_As_Form::do_button( array(
|
||||
'name' => 'open-caps-popup',
|
||||
'label' => VAA_View_Admin_As_Form::do_icon( 'dashicons-editor-expand' ),
|
||||
'class' => 'button-secondary vaa-icon vaa-hide-responsive',
|
||||
'element' => 'a',
|
||||
) ),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'vaa-button-container',
|
||||
),
|
||||
) );
|
||||
|
||||
/**
|
||||
* Add items at the before of the caps selection options.
|
||||
*
|
||||
* @since 1.7
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item. ($root.'-manager')
|
||||
* @param string $main_root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_caps_manager_before', $admin_bar, $root . '-manager', $main_root );
|
||||
|
||||
$admin_bar->add_group( array(
|
||||
'id' => $root . '-select',
|
||||
'parent' => $root . '-manager',
|
||||
) );
|
||||
|
||||
// Used in templates
|
||||
$parent = $root . '-select';
|
||||
|
||||
/**
|
||||
* Add items at the before of the caps actions.
|
||||
*
|
||||
* @since 1.7
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $parent The current root item.
|
||||
* @param string $main_root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_caps_actions_before', $admin_bar, $parent, $main_root );
|
||||
|
||||
// Add caps actions.
|
||||
include VIEW_ADMIN_AS_DIR . 'ui/templates/adminbar-caps-actions.php';
|
||||
|
||||
/**
|
||||
* Add items at the after of the caps actions.
|
||||
*
|
||||
* @since 1.7
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $parent The current root item.
|
||||
* @param string $main_root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_caps_actions_after', $admin_bar, $parent, $main_root );
|
||||
|
||||
// Add the caps.
|
||||
include VIEW_ADMIN_AS_DIR . 'ui/templates/adminbar-caps-items.php';
|
||||
|
||||
/**
|
||||
* Add items at the end of the caps group.
|
||||
*
|
||||
* @since 1.5
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @param string $main_root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_caps_after', $admin_bar, $root, $main_root );
|
||||
|
||||
$done = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store available capabilities.
|
||||
*
|
||||
* @since 1.4.1
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.8 Moved from VAA_View_Admin_As_Store.
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function store_data() {
|
||||
|
||||
// Get current user capabilities.
|
||||
$caps = $this->store->get_originalUserData( 'allcaps' );
|
||||
if ( empty( $caps ) ) {
|
||||
// Fallback.
|
||||
$caps = $this->store->get_curUser()->allcaps;
|
||||
}
|
||||
|
||||
// Only allow to add capabilities for an admin (or super admin).
|
||||
if ( VAA_API::is_super_admin() ) {
|
||||
|
||||
/**
|
||||
* Add compatibility for other cap managers.
|
||||
*
|
||||
* @since 1.5
|
||||
* @see \VAA_View_Admin_As_Compat->init()
|
||||
* @param array $caps An empty array, waiting to be filled with capabilities.
|
||||
* @return array
|
||||
*/
|
||||
$all_caps = apply_filters( 'view_admin_as_get_capabilities', array() );
|
||||
|
||||
$add_caps = array();
|
||||
// Add new capabilities to the capability array as disabled.
|
||||
foreach ( $all_caps as $cap_key => $cap_val ) {
|
||||
if ( is_numeric( $cap_key ) ) {
|
||||
// Try to convert numeric (faulty) keys.
|
||||
$add_caps[ (string) $cap_val ] = 0;
|
||||
} else {
|
||||
$add_caps[ (string) $cap_key ] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$caps = array_merge( $add_caps, $caps );
|
||||
|
||||
} // End if().
|
||||
|
||||
// Remove role names.
|
||||
$caps = array_diff_key( $caps, $this->store->get_roles() );
|
||||
// And sort alphabetical.
|
||||
ksort( $caps );
|
||||
|
||||
$this->set_data( $caps );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the view type data.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param mixed $val
|
||||
* @param string $key (optional) The data key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
*/
|
||||
public function set_data( $val, $key = null, $append = true ) {
|
||||
$this->store->set_caps( $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view type data.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param string $key (optional) The data key.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_data( $key = null ) {
|
||||
return $this->store->get_caps( $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Instance.
|
||||
*
|
||||
* Ensures only one instance of this class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @static
|
||||
* @param \VAA_View_Admin_As $caller The referrer class.
|
||||
* @return \VAA_View_Admin_As_Caps $this
|
||||
*/
|
||||
public static function get_instance( $caller = null ) {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self( $caller );
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_Caps.
|
||||
663
backend/wordpress/wp-content/plugins/view-admin-as/modules/class-groups.php
Executable file
663
backend/wordpress/wp-content/plugins/view-admin-as/modules/class-groups.php
Executable file
@@ -0,0 +1,663 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Groups plugin
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compatibility class for the Groups plugin
|
||||
*
|
||||
* Tested from Groups version: 2.1.2
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.7.2
|
||||
* @version 1.8
|
||||
* @uses \VAA_View_Admin_As_Type Extends class
|
||||
*/
|
||||
final class VAA_View_Admin_As_Groups extends VAA_View_Admin_As_Type
|
||||
{
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @static
|
||||
* @var \VAA_View_Admin_As_Groups
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* @since 1.7.2
|
||||
* @since 1.8 Renamed from $viewKey.
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'groups';
|
||||
|
||||
/**
|
||||
* The view icon.
|
||||
*
|
||||
* @todo Check for `dashicons-itthinx-groups`: https://github.com/itthinx/groups/pull/61
|
||||
*
|
||||
* @since 1.7.6
|
||||
* @var string
|
||||
*/
|
||||
protected $icon = 'dashicons-image-filter';
|
||||
|
||||
/**
|
||||
* @since 1.7.2
|
||||
* @since 1.8 Renamed from $selectedGroup.
|
||||
* @see \Groups_Group >> groups/lib/core/class-groups-group.php
|
||||
* @var \Groups_Group
|
||||
*/
|
||||
protected $selected;
|
||||
|
||||
/**
|
||||
* @since 1.7.4
|
||||
* @var string
|
||||
*/
|
||||
protected $groupsScreen = 'groups-admin';
|
||||
|
||||
/**
|
||||
* Populate the instance and validate Groups plugin.
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @access protected
|
||||
* @param \VAA_View_Admin_As $vaa The main VAA object.
|
||||
*/
|
||||
protected function __construct( $vaa ) {
|
||||
self::$_instance = $this;
|
||||
|
||||
if ( is_network_admin() || ! VAA_API::exists_callable( array( 'Groups_Group', 'get_groups' ), 'debug' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->cap = ( defined( 'GROUPS_ADMINISTER_GROUPS' ) ) ? GROUPS_ADMINISTER_GROUPS : 'manage_options';
|
||||
|
||||
parent::__construct( $vaa );
|
||||
|
||||
if ( ! $this->has_access() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->priorities['toolbar'] = 40;
|
||||
|
||||
$this->label = $this->translate_remote( 'Groups' );
|
||||
$this->label_singular = $this->translate_remote( 'Group' );
|
||||
$this->description = __( 'Plugin' ) . ': ' . $this->label;
|
||||
|
||||
// Add groups capabilities.
|
||||
$this->capabilities[] = $this->cap;
|
||||
if ( defined( 'GROUPS_ACCESS_GROUPS' ) ) {
|
||||
$this->capabilities[] = GROUPS_ACCESS_GROUPS;
|
||||
}
|
||||
if ( defined( 'GROUPS_ADMINISTER_OPTIONS' ) ) {
|
||||
$this->capabilities[] = GROUPS_ADMINISTER_OPTIONS;
|
||||
}
|
||||
if ( defined( 'GROUPS_RESTRICT_ACCESS' ) ) {
|
||||
$this->capabilities[] = GROUPS_RESTRICT_ACCESS;
|
||||
}
|
||||
// Do not add to VAA capabilities.
|
||||
$this->add_filter( 'members_get_capabilities', array( $this, 'add_capabilities' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup module and hooks.
|
||||
*
|
||||
* @since 1.7.4
|
||||
* @access private
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
if ( parent::init() ) {
|
||||
|
||||
if ( defined( 'GROUPS_PLUGIN_URL' ) ) {
|
||||
$this->icon = GROUPS_PLUGIN_URL . '/images/groups.png';
|
||||
}
|
||||
} else {
|
||||
// Add this anyway.
|
||||
$this->add_action( 'vaa_view_admin_as_do_view', array( $this, 'do_view' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the Groups module.
|
||||
* @since 1.7.2
|
||||
* @access public
|
||||
*/
|
||||
public function do_view() {
|
||||
|
||||
if ( parent::do_view() ) {
|
||||
|
||||
$this->selected = new Groups_Group( $this->store->get_view( $this->type ) );
|
||||
|
||||
$this->reset_groups_user();
|
||||
|
||||
$this->vaa->view()->init_user_modifications();
|
||||
$this->add_action( 'vaa_view_admin_as_modify_user', array( $this, 'modify_user' ), 10, 2 );
|
||||
|
||||
$this->add_filter( 'groups_post_access_user_can_read_post', array( $this, 'groups_post_access_user_can_read_post' ), 99, 3 );
|
||||
|
||||
/**
|
||||
* Replicate 404 page when the selected user has no access to read.
|
||||
* I use this since I can't hook into the `posts_where` filter from Groups.
|
||||
* @see VAA_View_Admin_As_Groups::groups_post_access_user_can_read_post()
|
||||
*/
|
||||
$this->add_action( 'wp', array( $this, 'post_access_404' ) );
|
||||
//$this->add_filter( 'groups_post_access_posts_where_apply', '__return_false' );
|
||||
|
||||
remove_shortcode( 'groups_member' );
|
||||
remove_shortcode( 'groups_non_member' );
|
||||
add_shortcode( 'groups_member', array( $this, 'shortcode_groups_member' ) );
|
||||
add_shortcode( 'groups_non_member', array( $this, 'shortcode_groups_non_member' ) );
|
||||
|
||||
// Filter user-group relationships.
|
||||
//$this->add_filter( 'groups_user_is_member', array( $this, 'groups_user_is_member' ), 20, 3 );
|
||||
}
|
||||
|
||||
// Filter group capabilities.
|
||||
if ( VAA_API::is_user_modified() ) {
|
||||
$this->add_filter( 'groups_group_can', array( $this, 'groups_group_can' ), 20, 3 );
|
||||
$this->add_filter( 'groups_user_can', array( $this, 'groups_user_can' ), 20, 3 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset Groups_User data for the selected user.
|
||||
*
|
||||
* @see \Groups_Cache
|
||||
* @see \Groups_User
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @access public
|
||||
* @param int $user_id
|
||||
*/
|
||||
public function reset_groups_user( $user_id = null ) {
|
||||
if ( ! VAA_API::exists_callable( array( 'Groups_User', 'clear_cache' ), 'debug' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! $user_id ) {
|
||||
$user_id = $this->store->get_selectedUser()->ID;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Groups_User::clear_cache( $user_id );
|
||||
|
||||
$capabilities_base = array();
|
||||
$capability_ids_base = array();
|
||||
$groups_ids_base = array( $this->selected->group_id );
|
||||
$groups_base = array( $this->selected );
|
||||
$capabilities = null;
|
||||
$capability_ids = null;
|
||||
$groups_ids = null;
|
||||
$groups = null;
|
||||
|
||||
Groups_Cache::set( Groups_User::CAPABILITIES_BASE . $user_id, $capabilities_base, Groups_User::CACHE_GROUP );
|
||||
Groups_Cache::set( Groups_User::CAPABILITY_IDS_BASE . $user_id, $capability_ids_base, Groups_User::CACHE_GROUP );
|
||||
Groups_Cache::set( Groups_User::GROUP_IDS_BASE . $user_id, $groups_ids_base, Groups_User::CACHE_GROUP );
|
||||
Groups_Cache::set( Groups_User::GROUPS_BASE . $user_id, $groups_base, Groups_User::CACHE_GROUP );
|
||||
//Groups_Cache::set( Groups_User::CAPABILITIES . $user_id, $capabilities, Groups_User::CACHE_GROUP );
|
||||
//Groups_Cache::set( Groups_User::CAPABILITY_IDS . $user_id, $capability_ids, Groups_User::CACHE_GROUP );
|
||||
//Groups_Cache::set( Groups_User::GROUP_IDS . $user_id, $groups_ids, Groups_User::CACHE_GROUP );
|
||||
//Groups_Cache::set( Groups_User::GROUPS . $user_id, $groups, Groups_User::CACHE_GROUP );
|
||||
|
||||
} catch ( Exception $e ) {
|
||||
|
||||
$this->vaa->add_error_notice( __METHOD__, array(
|
||||
'message' => $e->getMessage(),
|
||||
) );
|
||||
|
||||
} // End try().
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the current user's WP_User instance with the current view data.
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @access public
|
||||
* @param \WP_User $user User object.
|
||||
*/
|
||||
public function modify_user( $user ) {
|
||||
|
||||
$caps = array();
|
||||
if ( $this->selected ) {
|
||||
|
||||
// Merge the caps with the current selected caps, overwrite existing.
|
||||
$group_caps = (array) $this->selected->capabilities_deep;
|
||||
foreach ( $group_caps as $group_cap ) {
|
||||
/**
|
||||
* @see \Groups_Capability::create()
|
||||
* @see \Groups_Capability::__get()
|
||||
* @param int $capability_id
|
||||
* @param string $capability
|
||||
* @param string $class
|
||||
* @param string $object
|
||||
* @param string $name
|
||||
* @param string $description
|
||||
* @param array $group_ids
|
||||
*/
|
||||
if ( isset( $group_cap->capability ) && is_string( $group_cap->capability ) ) {
|
||||
$caps[ $group_cap->capability ] = 1;
|
||||
} elseif ( isset( $group_cap->capability->capability ) ) {
|
||||
$caps[ $group_cap->capability->capability ] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$caps = array_merge( $this->store->get_selectedCaps(), $caps );
|
||||
|
||||
$this->store->set_selectedCaps( $caps );
|
||||
|
||||
// Merge the caps with the current user caps, overwrite existing.
|
||||
$user->allcaps = array_merge( $user->caps, $caps );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the user-group relation.
|
||||
*
|
||||
* @todo https://github.com/itthinx/groups/pull/59
|
||||
* @see \Groups_User_Group::read() >> groups/lib/core/class-groups-user-group.php
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @access public
|
||||
* @param bool $result Current result.
|
||||
* @param int $user_id User ID.
|
||||
* @param int $group_id Group ID.
|
||||
* @return bool|object
|
||||
*/
|
||||
public function groups_user_is_member( $result, $user_id, $group_id ) {
|
||||
if ( (int) $user_id === (int) $this->store->get_curUser()->ID
|
||||
&& $this->selected
|
||||
&& (int) $group_id === (int) $this->selected->group->group_id
|
||||
) {
|
||||
$result = $this->selected->group;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter for the current view.
|
||||
*
|
||||
* @see \Groups_User::can() >> groups/lib/core/class-groups-user.php
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @access public
|
||||
* @param bool $result Current result.
|
||||
* @param \Groups_Group $object (not used) Group object.
|
||||
* @param string $cap Capability.
|
||||
* @return bool
|
||||
*/
|
||||
public function groups_user_can( $result, $object = null, $cap = '' ) {
|
||||
|
||||
/**
|
||||
* Fallback PHP < 5.4 due to apply_filters_ref_array
|
||||
* @see https://codex.wordpress.org/Function_Reference/apply_filters_ref_array
|
||||
*/
|
||||
if ( is_array( $result ) ) {
|
||||
$cap = $result[2];
|
||||
//$object = $result[1];
|
||||
$result = $result[0];
|
||||
}
|
||||
|
||||
if ( ! $this->store->get_view() ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( $this->selected &&
|
||||
is_callable( array( $this->selected, 'can' ) ) &&
|
||||
! $this->selected->can( $cap )
|
||||
) {
|
||||
$result = false;
|
||||
} else {
|
||||
// For other view types.
|
||||
$result = VAA_API::current_view_can( $cap );
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter for the current view.
|
||||
*
|
||||
* @see \Groups_Group::can() >> groups/lib/core/class-groups-group.php
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @access public
|
||||
* @param bool $result Current result.
|
||||
* @param \Groups_Group $object Group object.
|
||||
* @param string $cap Capability.
|
||||
* @return bool
|
||||
*/
|
||||
public function groups_group_can( $result, $object = null, $cap = '' ) {
|
||||
// Prevent loop on `groups_user_can` filter.
|
||||
if ( $this->selected && $this->selected->group_id === $object->group_id ) {
|
||||
return $result;
|
||||
}
|
||||
return $this->groups_user_can( $result, $object, $cap );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter whether the user can do something with a post.
|
||||
*
|
||||
* @see \Groups_Post_Access::user_can_read_post()
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @access public
|
||||
* @param bool $result
|
||||
* @param int $post_id
|
||||
* @param int $user_id
|
||||
* @return bool
|
||||
*/
|
||||
public function groups_post_access_user_can_read_post( $result, $post_id, $user_id ) {
|
||||
if ( $this->store->get_selectedUser()->ID !== $user_id || ! $this->selected ) {
|
||||
return $result;
|
||||
}
|
||||
if ( ! VAA_API::exists_callable( array( 'Groups_Post_Access', 'get_read_group_ids' ), 'debug' ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$post_access = Groups_Post_Access::get_read_group_ids( $post_id );
|
||||
$result = true;
|
||||
if ( ! empty( $post_access ) && ! in_array( $this->selected->group_id, $post_access, true ) ) {
|
||||
$result = false;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replicate 404 page when the selected user has no access to read.
|
||||
* I use this since I can't hook into the `posts_where` filter from Groups.
|
||||
*
|
||||
* @hook `wp`
|
||||
* @see \VAA_View_Admin_As_Groups::groups_post_access_user_can_read_post()
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @access public
|
||||
*/
|
||||
public function post_access_404() {
|
||||
global $post;
|
||||
if ( isset( $post->ID ) && ! $this->groups_post_access_user_can_read_post( true, $post->ID, $this->store->get_selectedUser()->ID ) ) {
|
||||
global $wp_query;
|
||||
$wp_query->set_404();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Our own implementation for the groups_member shortcode.
|
||||
*
|
||||
* @see \Groups_Access_Shortcodes::groups_member()
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @param array $atts
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
public function shortcode_groups_member( $atts, $content ) {
|
||||
return $this->shortcode_member( $atts, $content, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Our own implementation for the groups_non_member shortcode.
|
||||
*
|
||||
* @see \Groups_Access_Shortcodes::groups_non_member()
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @param array $atts
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
public function shortcode_groups_non_member( $atts, $content ) {
|
||||
return ! $this->shortcode_member( $atts, $content, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Our own implementation for the Groups member shortcodes.
|
||||
*
|
||||
* @see \VAA_View_Admin_As_Groups::shortcode_groups_member()
|
||||
* @see \VAA_View_Admin_As_Groups::shortcode_groups_non_member()
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @param array $atts
|
||||
* @param string $content
|
||||
* @param bool $reverse
|
||||
* @return string
|
||||
*/
|
||||
public function shortcode_member( $atts, $content, $reverse = false ) {
|
||||
$output = '';
|
||||
$shortcode = ( $reverse ) ? 'groups_non_member' : 'groups_member';
|
||||
$options = shortcode_atts( array( 'group' => '' ), $atts ); //, $shortcode
|
||||
$show_content = false;
|
||||
if ( null !== $content ) {
|
||||
$groups = explode( ',', $options['group'] );
|
||||
foreach ( $groups as $group ) {
|
||||
$group = trim( $group );
|
||||
$selected_group = $this->selected;
|
||||
$current_group = Groups_Group::read( $group );
|
||||
if ( ! $current_group ) {
|
||||
$current_group = Groups_Group::read_by_name( $group );
|
||||
}
|
||||
if ( $current_group && $current_group->group_id === $selected_group->group_id ) {
|
||||
$show_content = ! $reverse;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( $show_content ) {
|
||||
remove_shortcode( $shortcode );
|
||||
$content = do_shortcode( $content );
|
||||
add_shortcode( $shortcode, array( $this, 'shortcode_' . $shortcode ) );
|
||||
$output = $content;
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate data for this view type
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @param null $null Default return (invalid)
|
||||
* @param mixed $data The view data
|
||||
* @return mixed
|
||||
*/
|
||||
public function validate_view_data( $null, $data = null ) {
|
||||
if ( is_numeric( $data ) && $this->get_groups( (int) $data ) ) {
|
||||
return (int) $data;
|
||||
}
|
||||
return $null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the VAA admin bar menu title.
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @since 1.7.5 Renamed from vaa_viewing_as_title().
|
||||
* @access public
|
||||
* @param array $titles The current title(s).
|
||||
* @return array
|
||||
*/
|
||||
public function view_title( $titles = array() ) {
|
||||
if ( $this->selected ) {
|
||||
$titles[ $this->label_singular ] = $this->selected->name;
|
||||
}
|
||||
return $titles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the Groups admin bar items.
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @access public
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The root item.
|
||||
*/
|
||||
public function admin_bar_menu( $admin_bar, $root ) {
|
||||
|
||||
if ( ! $this->get_groups() || ! count( $this->get_groups() ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$admin_bar->add_group( array(
|
||||
'id' => $root . '-groups',
|
||||
'parent' => $root,
|
||||
'meta' => array(
|
||||
'class' => 'ab-sub-secondary',
|
||||
),
|
||||
) );
|
||||
|
||||
$root = $root . '-groups';
|
||||
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-title',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_icon( $this->icon ) . $this->label,
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'vaa-has-icon ab-vaa-title ab-vaa-toggle active',
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-admin',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_description(
|
||||
VAA_View_Admin_As_Form::do_icon( 'dashicons-admin-links' )
|
||||
. __( 'Plugin' ) . ': ' . $this->label
|
||||
),
|
||||
'href' => menu_page_url( $this->groupsScreen, false ),
|
||||
'meta' => array(
|
||||
'class' => 'auto-height',
|
||||
),
|
||||
) );
|
||||
|
||||
/**
|
||||
* Add items at the beginning of the groups group.
|
||||
*
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_groups_before', $admin_bar, $root );
|
||||
|
||||
// Add the groups.
|
||||
foreach ( $this->get_groups() as $group_key => $group ) {
|
||||
$view_value = $group->group_id;
|
||||
$view_data = array( $this->type => $view_value );
|
||||
$href = VAA_API::get_vaa_action_link( $view_data, $this->store->get_nonce( true ) );
|
||||
$class = 'vaa-' . $this->type . '-item';
|
||||
$title = VAA_View_Admin_As_Form::do_view_title( $group->name, $this, $view_value );
|
||||
// Check if this group is the current view.
|
||||
if ( $this->store->get_view( $this->type ) ) {
|
||||
if ( (int) $this->store->get_view( $this->type ) === (int) $group->group_id ) {
|
||||
$class .= ' current';
|
||||
$href = false;
|
||||
} else {
|
||||
$selected = $this->get_groups( $this->store->get_view( $this->type ) );
|
||||
if ( (int) $selected->parent_id === (int) $group->group_id ) {
|
||||
$class .= ' current-parent';
|
||||
}
|
||||
}
|
||||
}
|
||||
$parent = $root;
|
||||
if ( ! empty( $group->parent_id ) ) {
|
||||
$parent = $root . '-' . $this->type . '-' . (int) $group->parent_id;
|
||||
}
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-' . $this->type . '-' . (int) $group->group_id,
|
||||
'parent' => $parent,
|
||||
'title' => $title,
|
||||
'href' => $href,
|
||||
'meta' => array(
|
||||
// Translators: %s stands for the view type name.
|
||||
'title' => sprintf( __( 'View as %s', VIEW_ADMIN_AS_DOMAIN ), $group->name ),
|
||||
'class' => $class,
|
||||
),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add items at the end of the groups group.
|
||||
*
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_groups_after', $admin_bar, $root );
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the available groups.
|
||||
* @since 1.7.2
|
||||
* @since 1.8 Renamed from store_groups().
|
||||
* @access private
|
||||
*/
|
||||
public function store_data() {
|
||||
$groups = Groups_Group::get_groups();
|
||||
|
||||
$data = array();
|
||||
if ( ! empty( $groups ) ) {
|
||||
foreach ( $groups as $group ) {
|
||||
$data[ $group->group_id ] = $group;
|
||||
}
|
||||
}
|
||||
$this->set_data( $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a group by ID.
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @access public
|
||||
* @param string $key The group key.
|
||||
* @return \Groups_Group[]|\Groups_Group|bool
|
||||
*/
|
||||
public function get_groups( $key = '-1' ) {
|
||||
if ( ! is_numeric( $key ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( '-1' === $key ) {
|
||||
$key = null;
|
||||
}
|
||||
return $this->get_data( $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate with another domain.
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @param string $string The string.
|
||||
* @return string
|
||||
*/
|
||||
public function translate_remote( $string ) {
|
||||
$domain = ( defined( 'GROUPS_PLUGIN_DOMAIN' ) ) ? GROUPS_PLUGIN_DOMAIN : 'groups';
|
||||
// @codingStandardsIgnoreLine >> Prevent groups translation from getting parsed by translate.wordpress.org
|
||||
return __( $string, $domain );
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Instance.
|
||||
*
|
||||
* Ensures only one instance of this class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @access public
|
||||
* @static
|
||||
* @param \VAA_View_Admin_As $caller The referrer class.
|
||||
* @return \VAA_View_Admin_As_Groups $this
|
||||
*/
|
||||
public static function get_instance( $caller = null ) {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self( $caller );
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_Groups.
|
||||
370
backend/wordpress/wp-content/plugins/view-admin-as/modules/class-languages.php
Executable file
370
backend/wordpress/wp-content/plugins/view-admin-as/modules/class-languages.php
Executable file
@@ -0,0 +1,370 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Language switcher
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Language switcher add-on.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.7.5
|
||||
* @version 1.8
|
||||
* @uses \VAA_View_Admin_As_Type Extends class
|
||||
*/
|
||||
class VAA_View_Admin_As_Languages extends VAA_View_Admin_As_Type
|
||||
{
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @since 1.7.5
|
||||
* @static
|
||||
* @var \VAA_View_Admin_As_Languages
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* Option key.
|
||||
*
|
||||
* @since 1.7.5
|
||||
* @var string
|
||||
*/
|
||||
protected $optionKey = 'languages';
|
||||
|
||||
/**
|
||||
* @since 1.7.5
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'locale';
|
||||
|
||||
/**
|
||||
* The icon for this view type.
|
||||
*
|
||||
* @since 1.8
|
||||
* @var string
|
||||
*/
|
||||
protected $icon = 'dashicons-translation';
|
||||
|
||||
/**
|
||||
* Populate the instance.
|
||||
*
|
||||
* @since 1.7.5
|
||||
* @access protected
|
||||
* @param \VAA_View_Admin_As $vaa The main VAA object.
|
||||
*/
|
||||
protected function __construct( $vaa ) {
|
||||
self::$_instance = $this;
|
||||
parent::__construct( $vaa );
|
||||
|
||||
if ( ! $this->has_access() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->priorities = array(
|
||||
'toolbar' => 9,
|
||||
'view_title' => 90,
|
||||
'validate_view_data' => 10,
|
||||
'update_view' => 10,
|
||||
'do_view' => 10,
|
||||
);
|
||||
|
||||
$this->label = __( 'Languages', VIEW_ADMIN_AS_DOMAIN );
|
||||
$this->label_singular = __( 'Language', VIEW_ADMIN_AS_DOMAIN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the language view.
|
||||
*
|
||||
* @since 1.7.5
|
||||
* @access public
|
||||
*/
|
||||
public function do_view() {
|
||||
|
||||
if ( parent::do_view() ) {
|
||||
|
||||
$this->add_filter( 'locale', array( $this, 'filter_locale' ) );
|
||||
$this->add_action( 'after_setup_theme', array( $this, 'action_switch_to_locale' ), 0 );
|
||||
|
||||
// Overwrite user setting for freeze locale.
|
||||
$this->add_filter( 'view_admin_as_freeze_locale', '__return_false', 99 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the site language.
|
||||
*
|
||||
* @since 1.7.5
|
||||
* @access public
|
||||
* param string $locale
|
||||
* @return string
|
||||
*/
|
||||
public function filter_locale() {
|
||||
return $this->selected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the site language.
|
||||
*
|
||||
* @since 1.7.5
|
||||
* @access public
|
||||
*/
|
||||
public function action_switch_to_locale() {
|
||||
if ( function_exists( 'switch_to_locale' ) ) {
|
||||
switch_to_locale( $this->selected );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate data for this view type
|
||||
*
|
||||
* @since 1.7.5
|
||||
* @param null $null Default return (invalid)
|
||||
* @param mixed $data The view data
|
||||
* @return mixed
|
||||
*/
|
||||
public function validate_view_data( $null, $data = null ) {
|
||||
if ( is_string( $data ) && $this->get_data( $data ) ) {
|
||||
return $data;
|
||||
}
|
||||
return $null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the VAA admin bar menu title.
|
||||
*
|
||||
* @since 1.7.5
|
||||
* @since 1.8 Renamed from vaa_admin_bar_view_titles().
|
||||
* @access public
|
||||
* @param array $titles The current title(s).
|
||||
* @return array
|
||||
*/
|
||||
public function view_title( $titles = array() ) {
|
||||
$language = $this->get_data( $this->selected );
|
||||
if ( $language ) {
|
||||
$titles[ /* No need for view type key. */ ] = $this->get_view_title( $this->selected );
|
||||
}
|
||||
return $titles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view title.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param string $locale The locale.
|
||||
* @return string
|
||||
*/
|
||||
public function get_view_title( $locale ) {
|
||||
$title = $this->get_data( $locale );
|
||||
|
||||
/**
|
||||
* Change the display title for language nodes.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param string $title Language (native).
|
||||
* @param string $locale The locale.
|
||||
* @return string
|
||||
*/
|
||||
$title = apply_filters( 'vaa_admin_bar_view_title_' . $this->type, $title, $locale );
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the admin bar items.
|
||||
*
|
||||
* @since 1.7.5
|
||||
* @access public
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The root item.
|
||||
*/
|
||||
public function admin_bar_menu( $admin_bar, $root ) {
|
||||
static $done;
|
||||
if ( $done ) return;
|
||||
|
||||
$main_root = $root;
|
||||
$root = $main_root . '-locale';
|
||||
|
||||
$admin_bar->add_group( array(
|
||||
'id' => $root,
|
||||
'parent' => $main_root,
|
||||
'meta' => array(
|
||||
'class' => 'ab-sub-secondary',
|
||||
),
|
||||
) );
|
||||
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-title',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_icon( $this->icon ) . $this->label,
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'vaa-has-icon ab-vaa-title' . ( ( $this->store->get_view( $this->type ) ) ? ' current' : '' ),
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
|
||||
$admin_bar->add_group( array(
|
||||
'id' => $root . '-languages',
|
||||
'parent' => $root . '-title',
|
||||
'meta' => array(
|
||||
'class' => 'vaa-auto-max-height',
|
||||
),
|
||||
) );
|
||||
|
||||
/**
|
||||
* Add items at the beginning of the rua group.
|
||||
*
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_languages_before', $admin_bar, $root );
|
||||
|
||||
// Add the levels.
|
||||
include VIEW_ADMIN_AS_DIR . 'ui/templates/adminbar-language-items.php';
|
||||
|
||||
/**
|
||||
* Add items at the end of the rua group.
|
||||
*
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_languages_after', $admin_bar, $root );
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the available languages.
|
||||
*
|
||||
* @since 1.7.5
|
||||
* @since 1.8 Renamed from store_languages().
|
||||
* @access public
|
||||
*/
|
||||
public function store_data() {
|
||||
|
||||
$installed = get_available_languages();
|
||||
|
||||
if ( ! $installed || ( 1 === count( $installed ) && 'en_US' === reset( $installed ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$existing = (array) $this->store->get_optionData( $this->optionKey );
|
||||
$languages = $existing;
|
||||
|
||||
if ( array_diff_key( array_flip( $installed ), $existing ) ) {
|
||||
// New languages detected. Call the WP API to get language info.
|
||||
$languages = $this->get_wp_languages( $languages );
|
||||
}
|
||||
|
||||
$data_languages['en_US'] = 'English';
|
||||
|
||||
// Same order as WordPress.
|
||||
sort( $installed );
|
||||
|
||||
foreach ( $installed as $locale ) {
|
||||
if ( array_key_exists( $locale, $languages ) ) {
|
||||
$data_languages[ $locale ] = $languages[ $locale ];
|
||||
}
|
||||
}
|
||||
|
||||
if ( $languages !== $existing ) {
|
||||
$this->store->update_optionData( $data_languages, $this->optionKey, true );
|
||||
}
|
||||
|
||||
$this->set_data( $data_languages );
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the WP API to get language info.
|
||||
*
|
||||
* @since 1.7.5
|
||||
* @param array $languages Existing languages.
|
||||
* @return array
|
||||
*/
|
||||
private function get_wp_languages( $languages ) {
|
||||
if ( ! file_exists( ABSPATH . 'wp-admin/includes/translation-install.php' ) ) {
|
||||
// @todo Notice on debug.
|
||||
return $languages;
|
||||
}
|
||||
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
|
||||
|
||||
if ( ! function_exists( 'wp_get_available_translations' ) ) {
|
||||
return $languages;
|
||||
}
|
||||
$wp_languages = wp_get_available_translations();
|
||||
|
||||
if ( ! $wp_languages ) {
|
||||
return $languages;
|
||||
}
|
||||
|
||||
foreach ( $wp_languages as $locale => $language_info ) {
|
||||
$name = $locale;
|
||||
if ( isset( $language_info['native_name'] ) ) {
|
||||
$name = $language_info['native_name'];
|
||||
}
|
||||
$languages[ $locale ] = $name;
|
||||
}
|
||||
|
||||
return $languages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the view type data.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param mixed $val
|
||||
* @param string $key (optional) The data key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
*/
|
||||
public function set_data( $val, $key = null, $append = true ) {
|
||||
$this->store->set_languages( $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a language by locale.
|
||||
*
|
||||
* @since 1.7.5
|
||||
* @since 1.8 Renamed from get_languages().
|
||||
* @access public
|
||||
* @param string $key (optional) The language locale.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_data( $key = '-1' ) {
|
||||
if ( ! is_string( $key ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( '-1' === $key ) {
|
||||
$key = null;
|
||||
}
|
||||
return $this->store->get_languages( $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Instance.
|
||||
*
|
||||
* Ensures only one instance of this class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.7.5
|
||||
* @access public
|
||||
* @static
|
||||
* @param \VAA_View_Admin_As $caller The referrer class.
|
||||
* @return \VAA_View_Admin_As_Languages $this
|
||||
*/
|
||||
public static function get_instance( $caller = null ) {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self( $caller );
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_Languages.
|
||||
@@ -0,0 +1,588 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Restrict User Access plugin
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compatibility class for the Restrict User Access plugin.
|
||||
*
|
||||
* Tested from RUA version: 0.12.4
|
||||
* Official RUA compat release: 0.13 (https://github.com/intoxstudio/restrict-user-access/pull/8)
|
||||
* Required since v1.7.2: 0.15.1 (https://github.com/intoxstudio/restrict-user-access/pull/11)
|
||||
* Checked version: 1.0
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.6.4
|
||||
* @version 1.8
|
||||
* @uses \VAA_View_Admin_As_Type Extends class
|
||||
*/
|
||||
final class VAA_View_Admin_As_RUA extends VAA_View_Admin_As_Type
|
||||
{
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @static
|
||||
* @var \VAA_View_Admin_As_RUA
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* @since 1.6.4
|
||||
* @since 1.8 Renamed from $viewKey.
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'rua_level';
|
||||
|
||||
/**
|
||||
* The view icon.
|
||||
*
|
||||
* @since 1.7.6
|
||||
* @var string
|
||||
*/
|
||||
protected $icon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgdmlld0JveD0iMCAwIDIwIDIwIj48ZyBmaWxsPSIjYTBhNWFhIj48cGF0aCBkPSJNMTAuMDEyIDE0LjYyNUw1Ljc4IDEyLjI3Yy0xLjkwNi42NjQtMy42MDUgMS43Ni00Ljk4IDMuMTc4IDIuMTA1IDIuNzcgNS40MzYgNC41NiA5LjE4NSA0LjU2IDMuNzY2IDAgNy4xMTItMS44MDIgOS4yMTUtNC41OTMtMS4zOC0xLjQwNC0zLjA3LTIuNDk2LTQuOTctMy4xNTRsLTQuMjE4IDIuMzY3em0tLjAwNS0xNC42M0M3LjQxMi0uMDA1IDUuMzEgMS45MSA1LjMxIDQuMjhoOS4zOTNjMC0yLjM3LTIuMS00LjI4Ni00LjY5Ni00LjI4NnptNi4xMjYgMTAuNzFjLjE1OC0uMDMyLjY0LS4yMzIuNjMtLjMzMy0uMDI1LS4yNC0uNjg2LTUuNTg0LS42ODYtNS41ODRzLS40MjItLjI3LS42ODYtLjI5M2MuMDI0LjIxLjY5IDUuNzYuNzQ1IDYuMjF6bS0xMi4yNTMgMGMtLjE1OC0uMDMyLS42NC0uMjMyLS42My0uMzMzLjAyNS0uMjQuNjg2LTUuNTg0LjY4Ni01LjU4NHMuNDItLjI3LjY4Ni0uMjkzYy0uMDIuMjEtLjY5IDUuNzYtLjc0MiA2LjIxeiIvPjxwYXRoIGQ9Ik0xMCAxMy45NjdoLjAyM2wuOTc1LS41NXYtNC4yMWMuNzgtLjM3NyAxLjMxNC0xLjE3MyAxLjMxNC0yLjA5NyAwLTEuMjg1LTEuMDM1LTIuMzIzLTIuMzItMi4zMjNTNy42NyA1LjgyNSA3LjY3IDcuMTFjMCAuOTIzLjUzNSAxLjcyIDEuMzE1IDIuMDkzVjEzLjRsMS4wMTYuNTY3em0tMS43NjQtLjk4NXYtLjAzNWMwLTMuNjEtMS4zNS02LjU4My0zLjA4My02Ljk2bC0uMDMuMy0uNTIgNC42NyAzLjYzMyAyLjAyNXptMy41Ni0uMDM1YzAgLjAxNCAwIC4wMTguMDAzLjAyM2wzLjYxLTIuMDI1LS41My00LjY4LS4wMjgtLjI3M2MtMS43MjMuNC0zLjA1NyAzLjM2Mi0zLjA1NyA2Ljk1NXoiLz48L2c+PC9zdmc+';
|
||||
|
||||
/**
|
||||
* @since 1.6.4
|
||||
* @since 1.8 Renamed from $selectedLevel.
|
||||
* @var int WP_Post ID (RUA access level post type).
|
||||
*/
|
||||
protected $selected;
|
||||
|
||||
/**
|
||||
* @since 1.6.4
|
||||
* @since 1.8 Renamed from $selectedLevelCaps.
|
||||
* @var array The caps set for this level.
|
||||
*/
|
||||
protected $selectedCaps = array();
|
||||
|
||||
/**
|
||||
* @since 1.6.4
|
||||
* @var \WP_Post_Type The post type object of the level types.
|
||||
*/
|
||||
protected $levelPostType;
|
||||
|
||||
/**
|
||||
* @since 1.6.4
|
||||
* @var \RUA_App
|
||||
*/
|
||||
protected $ruaApp;
|
||||
|
||||
/**
|
||||
* @since 1.7.2
|
||||
* @var \RUA_Level_Manager
|
||||
*/
|
||||
protected $ruaLevelManager;
|
||||
|
||||
/**
|
||||
* @since 1.6.4
|
||||
* @var string
|
||||
*/
|
||||
protected $ruaMetaPrefix;
|
||||
|
||||
/**
|
||||
* @since 1.6.4
|
||||
* @var string
|
||||
*/
|
||||
protected $ruaTypeRestrict;
|
||||
|
||||
/**
|
||||
* @since 1.7.4
|
||||
* @var string
|
||||
*/
|
||||
protected $ruaScreen;
|
||||
|
||||
/**
|
||||
* Populate the instance and validate RUA plugin is active.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @access protected
|
||||
* @param \VAA_View_Admin_As $vaa The main VAA object.
|
||||
*/
|
||||
protected function __construct( $vaa ) {
|
||||
self::$_instance = $this;
|
||||
|
||||
if ( is_network_admin() || ! VAA_API::exists_callable( array( 'RUA_App', 'instance' ), 'debug' ) ) {
|
||||
return;
|
||||
}
|
||||
$this->ruaApp = RUA_App::instance();
|
||||
|
||||
if ( ! is_object( $this->ruaApp->level_manager ) ) {
|
||||
return;
|
||||
}
|
||||
$this->ruaLevelManager = $this->ruaApp->level_manager;
|
||||
|
||||
$this->ruaMetaPrefix = ( defined( 'RUA_App::META_PREFIX' ) ) ? RUA_App::META_PREFIX : '_ca_';
|
||||
$this->ruaTypeRestrict = ( defined( 'RUA_App::TYPE_RESTRICT' ) ) ? RUA_App::TYPE_RESTRICT : 'restriction';
|
||||
$this->ruaScreen = ( defined( 'RUA_App::BASE_SCREEN' ) ) ? RUA_App::BASE_SCREEN : 'wprua';
|
||||
$this->cap = ( defined( 'RUA_App::CAPABILITY' ) ) ? RUA_App::CAPABILITY : 'manage_options';
|
||||
|
||||
parent::__construct( $vaa );
|
||||
|
||||
if ( ! $this->has_access() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->priorities['toolbar'] = 40;
|
||||
|
||||
$this->label = 'Access Levels';
|
||||
$this->label_singular = 'Access Level';
|
||||
$this->description = __( 'Plugin' ) . ': ' . $this->translate_remote( 'Restrict User Access' );
|
||||
|
||||
$this->add_action( 'init', array( $this, 'set_labels' ), 99999 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type labels.
|
||||
* @since 1.8
|
||||
*/
|
||||
public function set_labels() {
|
||||
$this->levelPostType = get_post_type_object( $this->ruaTypeRestrict );
|
||||
if ( ! empty( $this->levelPostType->labels->singular_name ) ) {
|
||||
$this->label_singular = $this->levelPostType->labels->singular_name;
|
||||
}
|
||||
if ( isset( $this->levelPostType->label ) ) {
|
||||
$this->label = $this->levelPostType->label;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup module and hooks.
|
||||
*
|
||||
* @since 1.7.4
|
||||
* @access private
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
if ( parent::init() ) {
|
||||
$this->add_action( 'vaa_admin_bar_roles_after', array( $this, 'admin_bar_roles_after' ), 10, 2 );
|
||||
} else {
|
||||
// Add this anyway to reset user level caps.
|
||||
$this->add_action( 'vaa_view_admin_as_do_view', array( $this, 'do_view' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the RUA module.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @access public
|
||||
*/
|
||||
public function do_view() {
|
||||
|
||||
if ( parent::do_view() ) {
|
||||
|
||||
if ( ! VAA_API::exists_callable( array( 'WPCALoader', 'load' ), 'debug' ) ) {
|
||||
return;
|
||||
}
|
||||
WPCALoader::load();
|
||||
|
||||
//$this->selected = $this->store->get_view( $this->type );
|
||||
$this->selectedCaps = $this->get_level_caps( $this->selected, true );
|
||||
|
||||
$this->vaa->view()->init_user_modifications();
|
||||
$this->add_action( 'vaa_view_admin_as_modify_user', array( $this, 'modify_user' ), 10, 2 );
|
||||
|
||||
$this->add_filter( 'get_user_metadata', array( $this, 'get_user_metadata' ), 10, 3 );
|
||||
|
||||
// Administrators can see all restricted content in RUA.
|
||||
if ( $this->store->get_view() && ! $this->store->get_selectedCaps( 'administrator' ) ) {
|
||||
// Not a view with administrator capability == no global access.
|
||||
$this->add_filter( 'rua/user/global-access', '__return_false' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( VAA_API::is_user_modified() && is_object( $this->ruaLevelManager ) ) {
|
||||
|
||||
if ( is_callable( array( $this->ruaLevelManager, 'reset_user_levels_caps' ) ) ) {
|
||||
/**
|
||||
* Reset the user levels caps.
|
||||
* @since 1.7.2
|
||||
* @link https://github.com/JoryHogeveen/view-admin-as/issues/56#issuecomment-299077527
|
||||
* @link https://github.com/intoxstudio/restrict-user-access/pull/11
|
||||
* @see \RUA_Level_Manager::add_filters()
|
||||
*/
|
||||
$this->ruaLevelManager->reset_user_levels_caps( $this->store->get_selectedUser()->ID );
|
||||
}
|
||||
|
||||
if ( $this->store->get_view( 'caps' ) ) {
|
||||
/**
|
||||
* Remove the whole filter when the caps view is selected.
|
||||
* @since 1.7.2
|
||||
* @link https://github.com/JoryHogeveen/view-admin-as/issues/56#issuecomment-299077527
|
||||
* @see \RUA_Level_Manager::add_filters()
|
||||
*/
|
||||
remove_filter( 'user_has_cap', array( $this->ruaLevelManager, 'user_level_has_cap' ), 9 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the current user's WP_User instance with the current view data.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @param \WP_User $user User object.
|
||||
*/
|
||||
public function modify_user( $user ) {
|
||||
|
||||
$caps = (array) $this->selectedCaps;
|
||||
|
||||
// Merge the caps with the current selected caps, overwrite existing.
|
||||
$caps = array_merge( $this->store->get_selectedCaps(), $caps );
|
||||
|
||||
$this->store->set_selectedCaps( $caps );
|
||||
|
||||
// Merge the caps with the current user caps, overwrite existing.
|
||||
$user->allcaps = array_merge( $user->caps, $caps );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the return metadata for the RUA levels.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @param null $null The value get_metadata() should return.
|
||||
* @param int $user_id User/Object ID.
|
||||
* @param string $meta_key Meta key.
|
||||
* @return array
|
||||
*/
|
||||
public function get_user_metadata( $null, $user_id, $meta_key ) {
|
||||
if ( (int) $user_id === (int) $this->store->get_selectedUser()->ID
|
||||
&& $this->get_levels( $this->selected )
|
||||
) {
|
||||
// @todo Check for future API updates in RUA plugin
|
||||
if ( $this->ruaMetaPrefix . 'level' === $meta_key ) {
|
||||
return array( $this->selected );
|
||||
}
|
||||
if ( $this->ruaMetaPrefix . 'level_' . $this->selected === $meta_key ) {
|
||||
// Return current time + 120 seconds to make sure this level won't be set as expired.
|
||||
return array( time() + 120 );
|
||||
}
|
||||
}
|
||||
return $null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate data for this view type
|
||||
*
|
||||
* @since 1.7
|
||||
* @param null $null Default return (invalid)
|
||||
* @param mixed $data The view data
|
||||
* @return mixed
|
||||
*/
|
||||
public function validate_view_data( $null, $data = null ) {
|
||||
if ( is_numeric( $data ) && $this->get_levels( (int) $data ) ) {
|
||||
return (int) $data;
|
||||
}
|
||||
return $null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the VAA admin bar menu title.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @since 1.7.5 Renamed from vaa_viewing_as_title().
|
||||
* @since 1.8 Renamed from vaa_admin_bar_view_titles().
|
||||
* @access public
|
||||
* @param array $titles The current title(s).
|
||||
* @return array
|
||||
*/
|
||||
public function view_title( $titles = array() ) {
|
||||
|
||||
$current = $this->get_levels( $this->selected );
|
||||
if ( $current ) {
|
||||
|
||||
$titles[ $this->label_singular ] = $current->post_title;
|
||||
}
|
||||
return $titles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the RUA admin bar items.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @access public
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The root item.
|
||||
* @param string $role (optional) Role name.
|
||||
* @param \WP_Role $role_obj (optional) Role object.
|
||||
*/
|
||||
public function admin_bar_menu( $admin_bar, $root, $role = null, $role_obj = null ) {
|
||||
|
||||
if ( ! $this->get_levels() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! $role ) {
|
||||
|
||||
$admin_bar->add_group( array(
|
||||
'id' => $root . '-rua-levels',
|
||||
'parent' => $root,
|
||||
'meta' => array(
|
||||
'class' => 'ab-sub-secondary',
|
||||
),
|
||||
) );
|
||||
|
||||
$root = $root . '-rua-levels';
|
||||
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-title',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_icon( $this->icon ) . $this->label,
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'vaa-has-icon ab-vaa-title ab-vaa-toggle active',
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-admin',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_description(
|
||||
VAA_View_Admin_As_Form::do_icon( 'dashicons-admin-links' )
|
||||
. __( 'Plugin' ) . ': ' . $this->translate_remote( 'Restrict User Access' )
|
||||
),
|
||||
'href' => menu_page_url( $this->ruaScreen, false ),
|
||||
'meta' => array(
|
||||
'class' => 'auto-height',
|
||||
),
|
||||
) );
|
||||
|
||||
} else {
|
||||
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-rua-levels',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_icon( $this->icon ) . $this->label,
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'vaa-has-icon',
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
|
||||
$root = $root . '-rua-levels';
|
||||
|
||||
} // End if().
|
||||
|
||||
/**
|
||||
* Add items at the beginning of the rua group.
|
||||
*
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_rua_levels_before', $admin_bar, $root );
|
||||
|
||||
// Add the levels.
|
||||
foreach ( $this->get_levels() as $level ) {
|
||||
$view_value = $level->ID;
|
||||
$view_data = array( $this->type => $view_value );
|
||||
if ( $role ) {
|
||||
$view_data['role'] = $role;
|
||||
}
|
||||
$href = VAA_API::get_vaa_action_link( $view_data, $this->store->get_nonce( true ) );
|
||||
$class = 'vaa-' . $this->type . '-item';
|
||||
$title = VAA_View_Admin_As_Form::do_view_title( $level->post_title, $this, ( $role ) ? wp_json_encode( $view_data ) : $view_value );
|
||||
// Check if this level is the current view.
|
||||
if ( $this->store->get_view( $this->type ) ) {
|
||||
if ( VAA_API::is_current_view( $view_value, $this->type ) ) {
|
||||
$class .= ' current';
|
||||
if ( 1 === count( $this->store->get_view() ) && empty( $role ) ) {
|
||||
// The node item is the only view and is not related to a role.
|
||||
$href = false;
|
||||
} elseif ( ! empty( $role ) && $role === $this->store->get_view( 'role' ) ) {
|
||||
// The node item is related to a role and that role is the current view.
|
||||
$href = false;
|
||||
}
|
||||
} else {
|
||||
$selected = $this->get_levels( $this->selected );
|
||||
if ( $selected && (int) $selected->post_parent === (int) $view_value ) {
|
||||
$class .= ' current-parent';
|
||||
}
|
||||
}
|
||||
}
|
||||
$parent = $root;
|
||||
if ( ! empty( $level->post_parent ) ) {
|
||||
$parent = $root . '-' . $this->type . '-' . (int) $level->post_parent;
|
||||
}
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-' . $this->type . '-' . $view_value,
|
||||
'parent' => $parent,
|
||||
'title' => $title,
|
||||
'href' => $href,
|
||||
'meta' => array(
|
||||
// Translators: %s stands for the view type name.
|
||||
'title' => sprintf( __( 'View as %s', VIEW_ADMIN_AS_DOMAIN ), $level->post_title )
|
||||
. ( ( $role ) ? ' (' . $this->store->get_rolenames( $role_obj->name ) . ')' : '' ),
|
||||
'class' => $class,
|
||||
),
|
||||
) );
|
||||
} // End foreach().
|
||||
|
||||
/**
|
||||
* Add items at the end of the rua group.
|
||||
*
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_rua_levels_after', $admin_bar, $root );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add levels under roles.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @access public
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The root item.
|
||||
*/
|
||||
public function admin_bar_roles_after( $admin_bar, $root ) {
|
||||
|
||||
$roles = $this->store->get_roles();
|
||||
if ( ! $roles ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $roles as $role_key => $role ) {
|
||||
|
||||
// Admins always have full access in RUA.
|
||||
if ( 'administrator' === $role_key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$role_root = $root . '-role-' . $role_key;
|
||||
|
||||
$this->admin_bar_menu( $admin_bar, $role_root, $role_key, $role );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the available access levels.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @since 1.8 Renamed from store_levels().
|
||||
* @access private
|
||||
*/
|
||||
public function store_data() {
|
||||
if ( is_callable( array( $this->ruaApp, 'get_levels' ) ) ) {
|
||||
$levels = $this->ruaApp->get_levels();
|
||||
} else {
|
||||
// Fallback @todo Keep this updated on changes in RUA plugin.
|
||||
$levels = get_posts( array(
|
||||
'numberposts' => -1,
|
||||
'post_type' => $this->ruaTypeRestrict,
|
||||
'post_status' => array( 'publish', 'private', 'future' ),
|
||||
) );
|
||||
}
|
||||
|
||||
$data = array();
|
||||
if ( ! empty( $levels ) ) {
|
||||
foreach ( $levels as $level ) {
|
||||
$data[ $level->ID ] = $level;
|
||||
}
|
||||
}
|
||||
$this->set_data( $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an access level by ID.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @see \RUA_App::get_levels()
|
||||
* @access public
|
||||
* @param string $key (optional) The level key.
|
||||
* @return \WP_Post[]|\WP_Post Array of WP_Post objects (RUA access level post type)
|
||||
*/
|
||||
public function get_levels( $key = '-1' ) {
|
||||
if ( ! is_numeric( $key ) ) {
|
||||
return null;
|
||||
}
|
||||
if ( '-1' === $key ) {
|
||||
$key = null;
|
||||
}
|
||||
return $this->get_data( $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all caps of a level.
|
||||
* Also able to get all caps based on level hierarchy (default).
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @param int $level_id The level ID.
|
||||
* @param bool $hierarchical Add parent level caps?
|
||||
* @return array
|
||||
*/
|
||||
public function get_level_caps( $level_id, $hierarchical = true ) {
|
||||
|
||||
// @see https://github.com/intoxstudio/restrict-user-access/pull/8.
|
||||
if ( function_exists( 'rua_get_level_caps' ) ) {
|
||||
return (array) rua_get_level_caps( $level_id, $hierarchical );
|
||||
}
|
||||
|
||||
$levels = array( $level_id );
|
||||
if ( $hierarchical ) {
|
||||
$levels = array_merge( $levels, get_post_ancestors( (int) $level_id ) );
|
||||
$levels = array_reverse( (array) $levels );
|
||||
}
|
||||
|
||||
$caps = array();
|
||||
foreach ( $levels as $level ) {
|
||||
// Just use the regular get_post_meta to prevent any errors in future or old versions of RUA.
|
||||
// @todo Check for future API updates in RUA plugin.
|
||||
// $level_caps = $this->ruaApp->level_manager->metadata()->get( "caps" )->get_data( $level );
|
||||
$level_caps = get_post_meta( $level, $this->ruaMetaPrefix . 'caps', true );
|
||||
if ( ! empty( $level_caps ) && is_array( $level_caps ) ) {
|
||||
foreach ( $level_caps as $key => $level_cap ) {
|
||||
$caps[ $key ] = (bool) $level_cap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $caps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate with another domain.
|
||||
*
|
||||
* @since 1.7.4
|
||||
* @param string $string The string.
|
||||
* @return string
|
||||
*/
|
||||
public function translate_remote( $string ) {
|
||||
$domain = ( defined( 'RUA_App::DOMAIN' ) ) ? RUA_App::DOMAIN : 'restrict-user-access';
|
||||
// @codingStandardsIgnoreLine >> Prevent groups translation from getting parsed by translate.wordpress.org
|
||||
return __( $string, $domain );
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Instance.
|
||||
*
|
||||
* Ensures only one instance of this class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @access public
|
||||
* @static
|
||||
* @param \VAA_View_Admin_As $caller The referrer class.
|
||||
* @return \VAA_View_Admin_As_RUA $this
|
||||
*/
|
||||
public static function get_instance( $caller = null ) {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self( $caller );
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_RUA.
|
||||
1884
backend/wordpress/wp-content/plugins/view-admin-as/modules/class-role-defaults.php
Executable file
1884
backend/wordpress/wp-content/plugins/view-admin-as/modules/class-role-defaults.php
Executable file
File diff suppressed because it is too large
Load Diff
1578
backend/wordpress/wp-content/plugins/view-admin-as/modules/class-role-manager.php
Executable file
1578
backend/wordpress/wp-content/plugins/view-admin-as/modules/class-role-manager.php
Executable file
File diff suppressed because it is too large
Load Diff
352
backend/wordpress/wp-content/plugins/view-admin-as/modules/class-roles.php
Executable file
352
backend/wordpress/wp-content/plugins/view-admin-as/modules/class-roles.php
Executable file
@@ -0,0 +1,352 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - User switcher
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* User switcher view type.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 0.1 View type existed in core.
|
||||
* @since 1.8 Created this class.
|
||||
* @version 1.8
|
||||
* @uses \VAA_View_Admin_As_Type Extends class
|
||||
*/
|
||||
class VAA_View_Admin_As_Roles extends VAA_View_Admin_As_Type
|
||||
{
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @since 1.8
|
||||
* @static
|
||||
* @var \VAA_View_Admin_As_Roles
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* @since 1.8
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'role';
|
||||
|
||||
/**
|
||||
* The icon for this view type.
|
||||
*
|
||||
* @since 1.8
|
||||
* @var string
|
||||
*/
|
||||
protected $icon = 'dashicons-groups';
|
||||
|
||||
/**
|
||||
* Populate the instance.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access protected
|
||||
* @param \VAA_View_Admin_As $vaa The main VAA object.
|
||||
*/
|
||||
protected function __construct( $vaa ) {
|
||||
self::$_instance = $this;
|
||||
|
||||
if ( is_network_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
parent::__construct( $vaa );
|
||||
|
||||
// Roles should always be stored because of dependencies.
|
||||
if ( ! $this->is_enabled() ) {
|
||||
$this->store_data();
|
||||
}
|
||||
|
||||
if ( ! $this->has_access() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->priorities = array(
|
||||
'toolbar' => 20,
|
||||
'view_title' => 8,
|
||||
'validate_view_data' => 10,
|
||||
'update_view' => 10,
|
||||
'do_view' => 5,
|
||||
);
|
||||
|
||||
$this->label = __( 'Roles', VIEW_ADMIN_AS_DOMAIN );
|
||||
$this->label_singular = __( 'Role', VIEW_ADMIN_AS_DOMAIN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the user view.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
*/
|
||||
public function do_view() {
|
||||
|
||||
if ( parent::do_view() ) {
|
||||
|
||||
$this->add_action( 'vaa_view_admin_as_modify_user', array( $this, 'modify_user' ), 2, 2 );
|
||||
$this->init_user_modifications();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the current user object.
|
||||
*
|
||||
* @param \WP_User $user The modified user object.
|
||||
*/
|
||||
public function modify_user( $user ) {
|
||||
|
||||
if ( $this->get_data( $this->selected ) instanceof WP_Role ) {
|
||||
// @since 1.6.3 Set the current user's role to the current view.
|
||||
$user->caps = array( $this->selected => 1 );
|
||||
// Sets the `allcaps` and `roles` properties correct.
|
||||
$user->get_role_caps();
|
||||
// Set the selected capabilities.
|
||||
$this->store->set_selectedCaps( $user->allcaps );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the VAA admin bar menu title.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param array $titles The current title(s).
|
||||
* @return array
|
||||
*/
|
||||
public function view_title( $titles = array() ) {
|
||||
$current = $this->get_data( $this->selected );
|
||||
if ( $current ) {
|
||||
$titles[ $this->label_singular ] = $this->get_view_title( $current );
|
||||
}
|
||||
return $titles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view title.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param \WP_Role $role
|
||||
* @return string
|
||||
*/
|
||||
public function get_view_title( $role ) {
|
||||
$title = $this->store->get_rolenames( $role->name );
|
||||
|
||||
/**
|
||||
* Change the display title for role nodes.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param string $title Role name (translated).
|
||||
* @param \WP_Role $role The role object.
|
||||
* @return string
|
||||
*/
|
||||
$title = apply_filters( 'vaa_admin_bar_view_title_' . $this->type, $title, $role );
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate data for this view type
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.8 Moved from VAA_View_Admin_As_Controller
|
||||
* @access public
|
||||
* @param null $null Default return (invalid)
|
||||
* @param mixed $data The view data
|
||||
* @return mixed
|
||||
*/
|
||||
public function validate_view_data( $null, $data = null ) {
|
||||
// User data must be a number and exists in the loaded array of user id's.
|
||||
if ( is_string( $data ) && array_key_exists( $data, $this->get_data() ) ) {
|
||||
return $data;
|
||||
}
|
||||
return $null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the admin bar items.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.8 Moved from VAA_View_Admin_As_Admin_Bar.
|
||||
* @access public
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The root item.
|
||||
*/
|
||||
public function admin_bar_menu( $admin_bar, $root ) {
|
||||
static $done;
|
||||
if ( $done ) return;
|
||||
|
||||
/**
|
||||
* Make sure we have the latest added roles.
|
||||
* It can be that a plugin/theme adds a role after the initial call to store_roles (hook: 'plugins_loaded').
|
||||
*
|
||||
* @see \VAA_View_Admin_As::run()
|
||||
* @since 1.6.3
|
||||
*/
|
||||
$this->store_data();
|
||||
|
||||
if ( ! $this->get_data() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$main_root = $root;
|
||||
$root = $main_root . '-roles';
|
||||
|
||||
$admin_bar->add_group( array(
|
||||
'id' => $root,
|
||||
'parent' => $main_root,
|
||||
'meta' => array(
|
||||
'class' => 'ab-sub-secondary',
|
||||
),
|
||||
) );
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-title',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_icon( $this->icon ) . $this->label,
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'vaa-has-icon ab-vaa-title ab-vaa-toggle active',
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
|
||||
/**
|
||||
* Add items at the beginning of the roles group.
|
||||
*
|
||||
* @since 1.5
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @param string $main_root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_roles_before', $admin_bar, $main_root );
|
||||
|
||||
// Add the roles.
|
||||
include VIEW_ADMIN_AS_DIR . 'ui/templates/adminbar-role-items.php';
|
||||
|
||||
/**
|
||||
* Add items at the end of the roles group.
|
||||
*
|
||||
* @since 1.5
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @param string $main_root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_roles_after', $admin_bar, $root, $main_root );
|
||||
|
||||
$done = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store available roles.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.5.2 Get role objects instead of arrays.
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.8 Moved from VAA_View_Admin_As_Store.
|
||||
* @access public
|
||||
* @global \WP_Roles $wp_roles
|
||||
* @return void
|
||||
*/
|
||||
public function store_data() {
|
||||
|
||||
// @since 1.6.3 Check for the wp_roles() function in WP 4.3+.
|
||||
if ( function_exists( 'wp_roles' ) ) {
|
||||
$wp_roles = wp_roles();
|
||||
} else {
|
||||
global $wp_roles;
|
||||
}
|
||||
|
||||
// Store available roles (role_objects for objects, roles for arrays).
|
||||
$roles = $wp_roles->role_objects;
|
||||
|
||||
if ( ! VAA_API::is_super_admin() ) {
|
||||
|
||||
// The current user is not a super admin (or regular admin in single installations).
|
||||
unset( $roles['administrator'] );
|
||||
|
||||
// @see https://codex.wordpress.org/Plugin_API/Filter_Reference/editable_roles.
|
||||
$editable_roles = apply_filters( 'editable_roles', $wp_roles->roles );
|
||||
|
||||
// Current user has the view_admin_as capability, otherwise this functions would'nt be called.
|
||||
foreach ( $roles as $role_key => $role ) {
|
||||
if ( ! array_key_exists( $role_key, $editable_roles ) ) {
|
||||
// Remove roles that this user isn't allowed to edit.
|
||||
unset( $roles[ $role_key ] );
|
||||
}
|
||||
elseif ( $role instanceof WP_Role && $role->has_cap( 'view_admin_as' ) ) {
|
||||
// Remove roles that have the view_admin_as capability.
|
||||
unset( $roles[ $role_key ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @since 1.6.4 Set role names.
|
||||
$role_names = array();
|
||||
foreach ( $roles as $role_key => $role ) {
|
||||
if ( isset( $wp_roles->role_names[ $role_key ] ) ) {
|
||||
$role_names[ $role_key ] = $wp_roles->role_names[ $role_key ];
|
||||
} else {
|
||||
$role_names[ $role_key ] = $role->name;
|
||||
}
|
||||
}
|
||||
|
||||
$this->store->set_rolenames( $role_names );
|
||||
$this->set_data( $roles );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the view type data.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param mixed $val
|
||||
* @param string $key (optional) The data key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
*/
|
||||
public function set_data( $val, $key = null, $append = true ) {
|
||||
$this->store->set_roles( $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view type data.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param string $key (optional) The data key.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_data( $key = null ) {
|
||||
return $this->store->get_roles( $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Instance.
|
||||
*
|
||||
* Ensures only one instance of this class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @static
|
||||
* @param \VAA_View_Admin_As $caller The referrer class.
|
||||
* @return \VAA_View_Admin_As_Roles $this
|
||||
*/
|
||||
public static function get_instance( $caller = null ) {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self( $caller );
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_Roles.
|
||||
944
backend/wordpress/wp-content/plugins/view-admin-as/modules/class-users.php
Executable file
944
backend/wordpress/wp-content/plugins/view-admin-as/modules/class-users.php
Executable file
@@ -0,0 +1,944 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - User switcher
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* User switcher view type.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 0.1 View type existed in core.
|
||||
* @since 1.8 Created this class.
|
||||
* @version 1.8
|
||||
* @uses \VAA_View_Admin_As_Type Extends class
|
||||
*/
|
||||
class VAA_View_Admin_As_Users extends VAA_View_Admin_As_Type
|
||||
{
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @since 1.8
|
||||
* @static
|
||||
* @var \VAA_View_Admin_As_Users
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* @since 1.8
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'user';
|
||||
|
||||
/**
|
||||
* The icon for this view type.
|
||||
*
|
||||
* @since 1.8
|
||||
* @var string
|
||||
*/
|
||||
protected $icon = 'dashicons-admin-users';
|
||||
|
||||
/**
|
||||
* Provide ajax search instead of loading all users at once?
|
||||
*
|
||||
* @since 1.8 Ajax search UI not available yet.
|
||||
* @var bool
|
||||
*/
|
||||
protected $ajax_search = false;
|
||||
|
||||
/**
|
||||
* Populate the instance.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access protected
|
||||
* @param \VAA_View_Admin_As $vaa The main VAA object.
|
||||
*/
|
||||
protected function __construct( $vaa ) {
|
||||
self::$_instance = $this;
|
||||
parent::__construct( $vaa );
|
||||
|
||||
if ( ! $this->has_access() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->priorities = array(
|
||||
'toolbar' => 30,
|
||||
'view_title' => 5,
|
||||
'validate_view_data' => 10,
|
||||
'update_view' => 10,
|
||||
'do_view' => 2,
|
||||
);
|
||||
|
||||
$this->label = __( 'Users', VIEW_ADMIN_AS_DOMAIN );
|
||||
$this->label_singular = __( 'User', VIEW_ADMIN_AS_DOMAIN );
|
||||
|
||||
$this->init_hooks();
|
||||
|
||||
if ( $this->is_enabled() ) {
|
||||
$this->add_action( 'vaa_admin_bar_settings_after', array( $this, 'admin_bar_menu_settings' ), 10, 2 );
|
||||
}
|
||||
|
||||
// Users can also be switched from the user list page.
|
||||
if ( 'browse' === $this->store->get_userSettings( 'view_mode' ) ) {
|
||||
$this->add_filter( 'user_row_actions', array( $this, 'filter_user_row_actions' ), 10, 2 );
|
||||
}
|
||||
|
||||
if ( VAA_API::is_ajax_request( 'view_admin_as_search_users' ) ) {
|
||||
$this->ajax_search_users();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the user view.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
*/
|
||||
public function do_view() {
|
||||
|
||||
if ( $this->selected && ( ! $this->is_enabled() || $this->ajax_search ) ) {
|
||||
// Store the single selected user.
|
||||
$this->validate_target_user( $this->selected );
|
||||
}
|
||||
|
||||
if ( parent::do_view() ) {
|
||||
|
||||
/**
|
||||
* Change current user object so changes can be made on various screen settings.
|
||||
* wp_set_current_user() returns the new user object.
|
||||
*/
|
||||
$this->store->set_selectedUser( wp_set_current_user( (int) $this->selected ) );
|
||||
|
||||
// @since 1.6.2 Set the caps for this view (user view).
|
||||
if ( isset( $this->store->get_selectedUser()->allcaps ) ) {
|
||||
$this->store->set_selectedCaps( $this->store->get_selectedUser()->allcaps );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the VAA admin bar menu title.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param array $titles The current title(s).
|
||||
* @return array
|
||||
*/
|
||||
public function view_title( $titles = array() ) {
|
||||
$current = $this->validate_target_user( $this->selected );
|
||||
if ( $current ) {
|
||||
|
||||
$type = $this->label_singular;
|
||||
$user = $this->store->get_selectedUser();
|
||||
$titles[ $type ] = $this->get_view_title( $user );
|
||||
|
||||
/**
|
||||
* Filter documented in /templates/adminbar-user-items.php
|
||||
*/
|
||||
if ( ! $this->store->get_view( 'role' ) && apply_filters( 'vaa_admin_bar_view_title_' . $this->type . '_show_roles', true, $user ) ) {
|
||||
$user_roles = array();
|
||||
foreach ( (array) $user->roles as $role ) {
|
||||
$user_roles[] = $this->store->get_rolenames( $role );
|
||||
}
|
||||
$titles[ $type ] .= ' <span class="user-role">(' . implode( ', ', $user_roles ) . ')</span>';
|
||||
}
|
||||
}
|
||||
return $titles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view title.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param \WP_User $user
|
||||
* @return string
|
||||
*/
|
||||
public function get_view_title( $user ) {
|
||||
$title = $user->display_name;
|
||||
if ( ! $title ) {
|
||||
$title = $user->nickname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the display title for user nodes.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param string $title User display name.
|
||||
* @param \WP_User $user The user object.
|
||||
* @return string
|
||||
*/
|
||||
$title = apply_filters( 'vaa_admin_bar_view_title_' . $this->type, $title, $user );
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* View update handler (Ajax probably), called from main handler.
|
||||
*
|
||||
* @since 1.8 Renamed from `ajax_handler`
|
||||
* @access public
|
||||
* @param null $null Null.
|
||||
* @param mixed $data The ajax data for this module.
|
||||
* @param string $type The view type.
|
||||
* @return bool
|
||||
*/
|
||||
public function update_view( $null, $data, $type = null ) {
|
||||
|
||||
if ( $type !== $this->type ) {
|
||||
return $null;
|
||||
}
|
||||
|
||||
if ( $this->validate_view_data( null, $data ) ) {
|
||||
$this->store->set_view( $data, $this->type, true );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate data for this view type
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.8 Moved from VAA_View_Admin_As_Controller
|
||||
* @access public
|
||||
* @param null $null Default return (invalid)
|
||||
* @param mixed $data The view data
|
||||
* @return mixed
|
||||
*/
|
||||
public function validate_view_data( $null, $data = null ) {
|
||||
// User data must be a number and exists in the loaded array of user id's.
|
||||
if ( is_numeric( $data ) && $this->validate_target_user( $data ) ) {
|
||||
return $data;
|
||||
}
|
||||
return $null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the admin bar items.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.8 Moved from VAA_View_Admin_As_Admin_Bar.
|
||||
* @access public
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The root item.
|
||||
*/
|
||||
public function admin_bar_menu( $admin_bar, $root ) {
|
||||
static $done;
|
||||
if ( $done ) return;
|
||||
|
||||
if ( ! $this->is_enabled() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$main_root = $root;
|
||||
$root = $main_root . '-users';
|
||||
$title_submenu = false;
|
||||
|
||||
$admin_bar->add_group( array(
|
||||
'id' => $root,
|
||||
'parent' => $main_root,
|
||||
'meta' => array(
|
||||
'class' => 'ab-sub-secondary',
|
||||
),
|
||||
) );
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-title',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_icon( $this->icon ) . $this->label,
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'vaa-has-icon ab-vaa-title ab-vaa-toggle active',
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
|
||||
if ( ! $this->group_user_roles() && 15 < count( $this->get_data() ) ) {
|
||||
$admin_bar->add_group( array(
|
||||
'id' => $root . '-all',
|
||||
'parent' => $root . '-title',
|
||||
'meta' => array(
|
||||
'class' => 'vaa-auto-max-height',
|
||||
),
|
||||
) );
|
||||
|
||||
$title_submenu = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add items at the beginning of the users group.
|
||||
*
|
||||
* @since 1.5
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @param string $main_root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_users_before', $admin_bar, $root, $main_root );
|
||||
|
||||
include VIEW_ADMIN_AS_DIR . 'ui/templates/adminbar-user-actions.php';
|
||||
|
||||
if ( $this->get_data() ) {
|
||||
if ( $title_submenu ) {
|
||||
$parent = $root . '-all';
|
||||
}
|
||||
// Add the users.
|
||||
include VIEW_ADMIN_AS_DIR . 'ui/templates/adminbar-user-items.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add items at the end of the users group.
|
||||
*
|
||||
* @since 1.5
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @param string $main_root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_users_after', $admin_bar, $root, $main_root );
|
||||
|
||||
$done = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* User view type settings.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The root item.
|
||||
*/
|
||||
public function admin_bar_menu_settings( $admin_bar, $root ) {
|
||||
|
||||
/**
|
||||
* force_group_users setting.
|
||||
*
|
||||
* @since 1.5.2
|
||||
* @since 1.8 Moved to this class & enhance checks whether to show this setting or not.
|
||||
*/
|
||||
if ( ! $this->ajax_search &&
|
||||
VAA_API::is_view_type_enabled( 'role' ) &&
|
||||
$this->store->get_roles() &&
|
||||
(
|
||||
! $this->group_user_roles() ||
|
||||
15 >= ( count( (array) $this->get_data() ) + count( (array) $this->store->get_roles() ) )
|
||||
)
|
||||
) {
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-force-group-users',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_checkbox(
|
||||
array(
|
||||
'name' => $root . '-force-group-users',
|
||||
'value' => $this->store->get_userSettings( 'force_group_users' ),
|
||||
'compare' => true,
|
||||
'label' => __( 'Group users', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Group users under their assigned roles', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'help' => true,
|
||||
'auto_js' => array(
|
||||
'setting' => 'user_setting',
|
||||
'key' => 'force_group_users',
|
||||
'refresh' => true,
|
||||
),
|
||||
'auto_showhide' => true,
|
||||
)
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'auto-height',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Group the users under their roles?
|
||||
*
|
||||
* @since 1.5 As a parameter in VAA_View_Admin_As_Admin_Bar.
|
||||
* @since 1.8 Moved from VAA_View_Admin_As_Admin_Bar and changed to a function.
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function group_user_roles() {
|
||||
static $check;
|
||||
if ( is_bool( $check ) ) return $check;
|
||||
|
||||
$check = false;
|
||||
|
||||
if ( $this->ajax_search ) {
|
||||
return $check;
|
||||
}
|
||||
|
||||
$roles = $this->store->get_roles();
|
||||
|
||||
if ( ! $roles || ! VAA_API::is_view_type_enabled( 'role' ) ) {
|
||||
return $check;
|
||||
}
|
||||
|
||||
$force = $this->store->get_userSettings( 'force_group_users' );
|
||||
|
||||
// If the amount of items (roles and users combined) is more than 15 users, group them under their roles.
|
||||
// There are no roles to group users on network pages.
|
||||
if ( ! is_network_admin() &&
|
||||
( $force || 15 < ( count( (array) $this->get_data() ) + count( (array) $roles ) ) )
|
||||
) {
|
||||
$check = true;
|
||||
}
|
||||
|
||||
return $check;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the original user can access a user (view as).
|
||||
* Also checks the current store.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param int|\WP_User $user
|
||||
* @return \WP_User
|
||||
*/
|
||||
public function validate_target_user( $user ) {
|
||||
$user_id = ( $user instanceof WP_User ) ? $user->ID : $user;
|
||||
|
||||
$check = $this->get_data( $user_id );
|
||||
if ( $check ) {
|
||||
return $check;
|
||||
}
|
||||
|
||||
$check = $this->filter_users_by_access( array( $user ) );
|
||||
if ( ! empty( $check[ $user_id ] ) ) {
|
||||
$user = $check[ $user_id ];
|
||||
$this->set_data( $user, $user->ID, true );
|
||||
return $user;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search users with AJAX.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
public function ajax_search_users() {
|
||||
$args = VAA_API::get_ajax_request( $this->store->get_nonce(), 'view_admin_as_search_users' );
|
||||
if ( ! $args ) {
|
||||
wp_send_json_error( __( 'Cheatin uh?', VIEW_ADMIN_AS_DOMAIN ) );
|
||||
die();
|
||||
}
|
||||
|
||||
if ( ! is_array( $args ) ) {
|
||||
$args = array(
|
||||
'search' => $args,
|
||||
);
|
||||
}
|
||||
|
||||
$users = $this->search_users( $args );
|
||||
|
||||
if ( ! $users ) {
|
||||
wp_send_json_error();
|
||||
die();
|
||||
}
|
||||
|
||||
$return = '';
|
||||
foreach ( $users as $user ) {
|
||||
$href = VAA_API::get_vaa_action_link( array( $this->type => $user->ID ), $this->store->get_nonce( true ) );
|
||||
$class = 'vaa-' . $this->type . '-item';
|
||||
$title = $this->get_view_title( $user );
|
||||
|
||||
$view_title = VAA_View_Admin_As_Form::do_view_title( $title, $this, $user->ID );
|
||||
|
||||
/**
|
||||
* Filter documented in /templates/adminbar-user-items.php
|
||||
*/
|
||||
if ( ! $this->store->get_view( 'role' ) && apply_filters( 'vaa_admin_bar_view_title_' . $this->type . '_show_roles', true, $user ) ) {
|
||||
$selected_user_roles = array();
|
||||
foreach ( (array) $user->roles as $role ) {
|
||||
$selected_user_roles[] = $this->store->get_rolenames( $role );
|
||||
}
|
||||
$view_title .= ' <span class="user-role">(' . implode( ', ', $selected_user_roles ) . ')</span>';
|
||||
}
|
||||
|
||||
$attr = array(
|
||||
'href' => $href,
|
||||
'class' => 'ab-item',
|
||||
// Translators: %s stands for the user display name.
|
||||
'title' => sprintf( __( 'View as %s', VIEW_ADMIN_AS_DOMAIN ), $title ),
|
||||
);
|
||||
|
||||
$item = '<a ' . VAA_View_Admin_As_Form::parse_to_html_attr( $attr ) . '>' . $view_title . '</a>';
|
||||
$return .= '<li class="' . $class . '">' . $item . '</a>';
|
||||
}
|
||||
|
||||
wp_send_json_success( $return );
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Search users.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param array $args Function arguments.
|
||||
* @return \WP_User[]
|
||||
*/
|
||||
public function search_users( $args = array() ) {
|
||||
$this->store_data( $args );
|
||||
return $this->get_data();
|
||||
}
|
||||
|
||||
/**
|
||||
* Store available users.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.6.2 Reduce user queries to 1 for non-network pages with custom query handling.
|
||||
* @since 1.8 Moved from VAA_View_Admin_As_Store.
|
||||
* @access public
|
||||
* @global \wpdb $wpdb
|
||||
* @param array $args Function arguments.
|
||||
* @return void
|
||||
*/
|
||||
public function store_data( $args = array() ) {
|
||||
global $wpdb;
|
||||
|
||||
$args = wp_parse_args( $args, array(
|
||||
/**
|
||||
* Change the limit for querying users.
|
||||
* @since 1.8
|
||||
* @param int $limit Default: 100.
|
||||
* @return int
|
||||
*/
|
||||
'limit' => apply_filters( 'view_admin_as_user_query_limit', 100 ),
|
||||
'search' => '',
|
||||
'search_by' => 'display_name', // @todo: display_name|user_login|user_email
|
||||
) );
|
||||
|
||||
$limit = (int) $args['limit'];
|
||||
|
||||
$super_admins = get_super_admins();
|
||||
// Load the superior admins.
|
||||
$superior_admins = VAA_API::get_superior_admins();
|
||||
|
||||
// Is the current user a super admin?
|
||||
$is_super_admin = VAA_API::is_super_admin();
|
||||
// Is it also one of the manually configured superior admins?
|
||||
$is_superior_admin = VAA_API::is_superior_admin();
|
||||
|
||||
/**
|
||||
* Base user query.
|
||||
* Also gets the roles from the user meta table.
|
||||
* Reduces queries to 1 when getting the available users.
|
||||
*
|
||||
* @since 1.6.2
|
||||
* @todo Use it for network pages as well?
|
||||
* @todo Check options https://github.com/JoryHogeveen/view-admin-as/issues/24.
|
||||
*/
|
||||
$user_query = array(
|
||||
'select' => "SELECT users.*, usermeta.meta_value AS roles",
|
||||
'from' => "FROM {$wpdb->users} users",
|
||||
'join' => "INNER JOIN {$wpdb->usermeta} usermeta ON ( users.ID = usermeta.user_id )",
|
||||
'where' => "WHERE ( usermeta.meta_key = '{$wpdb->get_blog_prefix()}capabilities' )",
|
||||
'order_by' => "ORDER BY users.display_name ASC",
|
||||
'limit' => 'LIMIT ' . $limit,
|
||||
);
|
||||
|
||||
/**
|
||||
* Search for users.
|
||||
* @since 1.8
|
||||
* @link https://developer.wordpress.org/reference/classes/wp_user_query/prepare_query/
|
||||
* @link https://developer.wordpress.org/reference/classes/wp_user_query/get_search_sql/
|
||||
*/
|
||||
if ( ! empty( $args['search'] ) ) {
|
||||
if ( ! in_array( $args['search_by'], array( 'display_name', 'user_login', 'user_email' ), true ) ) {
|
||||
$args['search_by'] = 'display_name';
|
||||
}
|
||||
$args['search'] = esc_sql( $args['search'] );
|
||||
$user_query['where'] .= " AND users.{$args['search_by']} LIKE '%{$args['search']}%'";
|
||||
}
|
||||
|
||||
if ( is_network_admin() ) {
|
||||
|
||||
/**
|
||||
* Super admins are only available for superior admins.
|
||||
* (short circuit return for performance).
|
||||
* @since 1.6.3
|
||||
*/
|
||||
if ( ! $is_superior_admin ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get super admins (returns login's).
|
||||
$users = $super_admins;
|
||||
// Remove current user.
|
||||
if ( in_array( $this->store->get_curUser()->user_login, $users, true ) ) {
|
||||
unset( $users[ array_search( $this->store->get_curUser()->user_login, $users, true ) ] );
|
||||
}
|
||||
|
||||
// Convert login to WP_User objects and filter them for superior admins.
|
||||
foreach ( $users as $key => $user_login ) {
|
||||
$user = get_user_by( 'login', $user_login );
|
||||
// Compare user ID with superior admins array.
|
||||
if ( isset( $user->ID ) && ! in_array( (int) $user->ID, $superior_admins, true ) ) {
|
||||
$users[ $key ] = $user;
|
||||
} else {
|
||||
unset( $users[ $key ] );
|
||||
}
|
||||
}
|
||||
|
||||
// @todo Maybe build network super admins where clause for SQL instead of `get_user_by`.
|
||||
|
||||
/*
|
||||
if ( ! empty( $users ) && $include = implode( ',', array_map( 'strval', $users ) ) ) {
|
||||
$user_query['where'] .= " AND users.user_login IN ({$include})";
|
||||
}
|
||||
*/
|
||||
|
||||
} else {
|
||||
|
||||
/**
|
||||
* Exclude current user and superior admins (values are user ID's).
|
||||
*
|
||||
* @since 1.5.2 Exclude the current user.
|
||||
* @since 1.6.2 Exclude in SQL format.
|
||||
*/
|
||||
$exclude = implode( ',',
|
||||
array_unique(
|
||||
array_map( 'absint',
|
||||
array_merge( $superior_admins, array( $this->store->get_curUser()->ID ) )
|
||||
)
|
||||
)
|
||||
);
|
||||
$user_query['where'] .= " AND users.ID NOT IN ({$exclude})";
|
||||
|
||||
/**
|
||||
* Do not get regular admins for normal installs.
|
||||
*
|
||||
* @since 1.5.2 WP 4.4+ only >> ( 'role__not_in' => 'administrator' ).
|
||||
* @since 1.6.2 Exclude in SQL format (Not WP dependent).
|
||||
*/
|
||||
if ( ! is_multisite() && ! $is_superior_admin ) {
|
||||
$user_query['where'] .= " AND usermeta.meta_value NOT LIKE '%administrator%'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not get super admins for network installs (values are usernames).
|
||||
* These we're filtered after query in previous versions.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*/
|
||||
if ( is_multisite() && ! $is_superior_admin && ! empty( $super_admins[0] ) ) {
|
||||
// Escape usernames just to be sure.
|
||||
$super_admins = array_filter( $super_admins, 'validate_username' );
|
||||
// Pre WP 4.4 - Remove empty usernames since these return true before WP 4.4.
|
||||
$super_admins = array_filter( $super_admins );
|
||||
|
||||
$exclude_siblings = "'" . implode( "','", $super_admins ) . "'";
|
||||
$user_query['where'] .= " AND users.user_login NOT IN ({$exclude_siblings})";
|
||||
}
|
||||
|
||||
// Run query (OBJECT_K to set the user ID as key).
|
||||
// @codingStandardsIgnoreLine >> $wpdb->prepare() not needed
|
||||
$users_results = $wpdb->get_results( implode( ' ', $user_query ), OBJECT_K );
|
||||
|
||||
if ( $users_results ) {
|
||||
|
||||
$users = array();
|
||||
// Temp set users.
|
||||
$this->set_data( $users_results );
|
||||
// @hack Short circuit the meta queries (not needed).
|
||||
add_filter( 'get_user_metadata', array( $this, '_filter_get_user_capabilities' ), 10, 3 );
|
||||
|
||||
// Turn query results into WP_User objects.
|
||||
foreach ( $users_results as $user ) {
|
||||
$user->roles = maybe_unserialize( $user->roles );
|
||||
$users[ $user->ID ] = new WP_User( $user );
|
||||
}
|
||||
|
||||
// @hack Restore the default meta queries.
|
||||
remove_filter( 'get_user_metadata', array( $this, '_filter_get_user_capabilities' ) );
|
||||
// Clear temp users.
|
||||
$this->set_data( array() );
|
||||
|
||||
} else {
|
||||
|
||||
// @todo Notice on debug? If so, check if the query gave an error before doing so...
|
||||
|
||||
// Fallback to WP native functions.
|
||||
$user_args = array(
|
||||
'orderby' => 'display_name',
|
||||
// @since 1.5.2 Exclude the current user.
|
||||
'exclude' => array_merge( $superior_admins, array( $this->store->get_curUser()->ID ) ),
|
||||
// @since 1.8 Limit the number of users to return.
|
||||
'number' => $limit,
|
||||
);
|
||||
// @since 1.5.2 Do not get regular admins for normal installs (WP 4.4+).
|
||||
if ( ! is_multisite() && ! $is_superior_admin ) {
|
||||
$user_args['role__not_in'] = 'administrator';
|
||||
}
|
||||
// @since 1.8 Search for users.
|
||||
if ( ! empty( $args['search'] ) ) {
|
||||
$user_args['search'] = $args['search'];
|
||||
$user_args['search_columns'] = (array) $args['search_by'];
|
||||
}
|
||||
|
||||
$users = get_users( $user_args );
|
||||
}
|
||||
|
||||
// @since 1.8 Switch to ajax search because of load time.
|
||||
if ( $limit <= count( $users ) ) {
|
||||
$this->ajax_search = true;
|
||||
if ( ! VAA_API::is_ajax_request( 'view_admin_as_search_users' ) ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Sort users by role and filter them on available roles.
|
||||
$users = $this->filter_sort_users_by_role( $users );
|
||||
} // End if().
|
||||
|
||||
$users = $this->filter_users_by_access( $users );
|
||||
|
||||
$this->set_data( $users );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the WP_User object construction to short circuit the extra meta queries.
|
||||
*
|
||||
* FOR INTERNAL USE ONLY!!!
|
||||
* @hack
|
||||
* @internal
|
||||
*
|
||||
* @since 1.6.2
|
||||
* @since 1.8 Moved to this class from VAA_View_Admin_As_Store
|
||||
* @see \WP_User::for_site() ( prev: \WP_User::_init_caps() ) >> wp-includes/class-wp-user.php
|
||||
* @see get_metadata() >> `get_user_metadata` filter
|
||||
* @link https://developer.wordpress.org/reference/functions/get_metadata/
|
||||
*
|
||||
* @global \wpdb $wpdb
|
||||
* @param null $null The value get_metadata() should return.
|
||||
* @param int $user_id Object ID.
|
||||
* @param string $meta_key Meta key.
|
||||
* @return mixed
|
||||
*/
|
||||
public function _filter_get_user_capabilities( $null, $user_id, $meta_key ) {
|
||||
global $wpdb;
|
||||
if ( $wpdb->get_blog_prefix() . 'capabilities' === $meta_key && array_key_exists( $user_id, $this->get_data() ) ) {
|
||||
|
||||
$roles = $this->get_data( $user_id )->roles;
|
||||
if ( is_string( $roles ) ) {
|
||||
// It is still raw DB data, unserialize it.
|
||||
$roles = maybe_unserialize( $roles );
|
||||
}
|
||||
|
||||
// Always return an array format due to $single handling (unused 4th parameter).
|
||||
return array( $roles );
|
||||
}
|
||||
return $null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter users and remove those who the selected user can't access.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param \WP_User[]|\WP_User $users
|
||||
* @param null|int|\WP_User $user_id
|
||||
* @return array
|
||||
*/
|
||||
public function filter_users_by_access( $users, $user_id = null ) {
|
||||
|
||||
if ( ! is_array( $users ) ) {
|
||||
$users = array( $users );
|
||||
}
|
||||
|
||||
$super_admins = get_super_admins();
|
||||
// Load the superior admins.
|
||||
$superior_admins = VAA_API::get_superior_admins();
|
||||
|
||||
// Is the user a super admin?
|
||||
$is_super_admin = VAA_API::is_super_admin( $user_id );
|
||||
// Is it also one of the manually configured superior admins?
|
||||
$is_superior_admin = VAA_API::is_superior_admin( $user_id );
|
||||
|
||||
foreach ( $users as $user_key => $user ) {
|
||||
|
||||
if ( ! $user instanceof WP_User ) {
|
||||
$user = get_user_by( 'ID', $user );
|
||||
unset( $users[ $user_key ] );
|
||||
if ( ! $user instanceof WP_User ) {
|
||||
continue;
|
||||
}
|
||||
$user_key = $user->ID;
|
||||
$users[ $user_key ] = $user;
|
||||
}
|
||||
|
||||
// If the current user is not a superior admin, run the user filters.
|
||||
if ( true !== $is_superior_admin ) {
|
||||
|
||||
/**
|
||||
* Implement in_array() on get_super_admins() check instead of is_super_admin().
|
||||
* Reduces the amount of queries while the end result is the same.
|
||||
*
|
||||
* @since 1.5.2
|
||||
* @see get_super_admins() >> wp-includes/capabilities.php
|
||||
* @see is_super_admin() >> wp-includes/capabilities.php
|
||||
* @link https://developer.wordpress.org/reference/functions/is_super_admin/
|
||||
*/
|
||||
if ( // Remove super admins for multisites.
|
||||
( is_multisite() && in_array( $user->user_login, (array) $super_admins, true ) ) ||
|
||||
// Remove regular admins for normal installs.
|
||||
( ! is_multisite() && $user->has_cap( 'administrator' ) ) ||
|
||||
// Remove users who can access this plugin for non-admin users with the view_admin_as capability.
|
||||
( ! $is_super_admin && $user->has_cap( 'view_admin_as' ) )
|
||||
) {
|
||||
unset( $users[ $user_key ] );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// @since 1.7.6 Remove users who are not allowed to be edited by this user.
|
||||
if ( ! current_user_can( 'edit_user', $user->ID ) ) {
|
||||
unset( $users[ $user_key ] );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort users by role.
|
||||
* Only done if roles are stored (role type enabled and initialized before the user type).
|
||||
*
|
||||
* @since 1.1
|
||||
* @since 1.6 Moved to this class from main class.
|
||||
* @since 1.7.1 User ID as array key.
|
||||
* @access public
|
||||
*
|
||||
* @see store_users()
|
||||
*
|
||||
* @param \WP_User[] $users Array of user objects (WP_User).
|
||||
* @return \WP_User[] $users
|
||||
*/
|
||||
public function filter_sort_users_by_role( $users ) {
|
||||
$roles = $this->store->get_roles();
|
||||
if ( ! $roles ) {
|
||||
return $users;
|
||||
}
|
||||
$tmp_users = array();
|
||||
foreach ( $roles as $role => $role_data ) {
|
||||
foreach ( $users as $user ) {
|
||||
// Reset the array to make sure we find a key.
|
||||
// Only one key is needed to add the user to the list of available users.
|
||||
reset( $user->roles );
|
||||
if ( current( $user->roles ) === $role ) {
|
||||
$tmp_users[ $user->ID ] = $user;
|
||||
}
|
||||
}
|
||||
}
|
||||
$users = $tmp_users;
|
||||
return $users;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter function to add view-as links on user rows in users.php.
|
||||
*
|
||||
* @since 1.6
|
||||
* @since 1.6.3 Check whether to place link + reset link for current user.
|
||||
* @since 1.8 Moved to this class from VAA_View_Admin_As_UI.
|
||||
* @access public
|
||||
* @param array $actions The existing actions.
|
||||
* @param \WP_User $user The user object.
|
||||
* @return array
|
||||
*/
|
||||
public function filter_user_row_actions( $actions, $user ) {
|
||||
|
||||
if ( is_network_admin() ) {
|
||||
$link = network_admin_url();
|
||||
} else {
|
||||
$link = admin_url();
|
||||
}
|
||||
|
||||
if ( $user->ID === $this->store->get_curUser()->ID ) {
|
||||
// Add reset link if it is the current user and a view is selected.
|
||||
if ( $this->store->get_view() ) {
|
||||
$link = VAA_API::get_reset_link( $link );
|
||||
} else {
|
||||
$link = false;
|
||||
}
|
||||
}
|
||||
elseif ( $this->store->get_users( $user->ID ) || $this->filter_users_by_access( array( $user ) ) ) {
|
||||
$link = VAA_API::get_vaa_action_link( array( $this->type => $user->ID ), $this->store->get_nonce( true ), $link );
|
||||
} else {
|
||||
$link = false;
|
||||
}
|
||||
|
||||
if ( $link ) {
|
||||
$icon = 'dashicons-visibility';
|
||||
$icon_attr = array(
|
||||
'style' => array(
|
||||
'font-size: inherit;',
|
||||
'line-height: inherit;',
|
||||
'display: inline;',
|
||||
'vertical-align: text-top;',
|
||||
),
|
||||
);
|
||||
$title = VAA_View_Admin_As_Form::do_icon( $icon, $icon_attr ) . ' ' . esc_html__( 'View as', VIEW_ADMIN_AS_DOMAIN );
|
||||
$actions['vaa_view'] = '<a href="' . $link . '">' . $title . '</a>';
|
||||
}
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the view type data.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param mixed $val
|
||||
* @param string $key (optional) The data key.
|
||||
* @param bool $append (optional) Append if it doesn't exist?
|
||||
*/
|
||||
public function set_data( $val, $key = null, $append = true ) {
|
||||
$this->store->set_users( $val, $key, $append );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view type data.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @param string $key (optional) The data key.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_data( $key = null ) {
|
||||
return $this->store->get_users( $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Instance.
|
||||
*
|
||||
* Ensures only one instance of this class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @static
|
||||
* @param \VAA_View_Admin_As $caller The referrer class.
|
||||
* @return \VAA_View_Admin_As_Users $this
|
||||
*/
|
||||
public static function get_instance( $caller = null ) {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self( $caller );
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_Users.
|
||||
2
backend/wordpress/wp-content/plugins/view-admin-as/modules/index.php
Executable file
2
backend/wordpress/wp-content/plugins/view-admin-as/modules/index.php
Executable file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
//Nothing to see here
|
||||
371
backend/wordpress/wp-content/plugins/view-admin-as/readme.txt
Executable file
371
backend/wordpress/wp-content/plugins/view-admin-as/readme.txt
Executable file
@@ -0,0 +1,371 @@
|
||||
=== View Admin As ===
|
||||
Contributors: keraweb
|
||||
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=YGPLMLU7XQ9E8&lc=US&item_name=View%20Admin%20As&item_number=JWPP%2dVAA¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest
|
||||
Tags: admin, view, roles, users, switch, user switching, role switching, capabilities, caps, screen settings, defaults, visitor
|
||||
Requires at least: 4.1
|
||||
Tested up to: 4.9
|
||||
Requires PHP: 5.2.4
|
||||
Stable tag: 1.8
|
||||
|
||||
View the WordPress admin as a different role or visitor, switch between users, temporarily change your capabilities, set screen settings for roles.
|
||||
|
||||
== Description ==
|
||||
|
||||
= The ultimate User switcher and Role manager =
|
||||
|
||||
This plugin will add a menu item to your admin bar where you can change your view in the WordPress admin without the need to login with a user that has this role!
|
||||
|
||||
If you've selected a user, you can also change this user's preferences; like screen settings on various admin pages. You can also switch to a role or temporarily change your own capabilities.
|
||||
|
||||
With the "Role defaults" module you can set default screen settings for roles and apply them on users through various bulk actions.
|
||||
|
||||
It also features a "Role manager" module to add, edit or remove roles and grant or deny them capabilities.
|
||||
|
||||
= Overview / Features =
|
||||
|
||||
* Switch between user accounts
|
||||
* Edit this user's screen preferences and settings
|
||||
* Switch between roles
|
||||
* Temporarily change your own capabilities (non-destructively)
|
||||
* View your site as an unregistered visitor
|
||||
* Switch language/locale on backend and frontend
|
||||
* Make combinations of the above view types
|
||||
* Easily switch back anytime
|
||||
* Completely secure (see *Security* below)
|
||||
* Do all the above without logging out!
|
||||
|
||||
= Module: Role defaults (screen settings) =
|
||||
|
||||
* Set default screen settings for roles
|
||||
* Apply defaults to a user
|
||||
* Apply defaults to all users of a role
|
||||
* Apply defaults when registering a new user (in a multisite this is done when a user is added to its first blog)
|
||||
* Copy defaults from one role to another (or multiple)
|
||||
* Import/Export role defaults, can also download (and upload) setting files
|
||||
* Disable the "screen settings" option and/or lock the meta boxes for all users that don't have access to this plugin
|
||||
|
||||
= Module: Role manager (role editor) =
|
||||
|
||||
*Note: Changes made with the Role Manager are permanent!*
|
||||
|
||||
* Add, edit or delete roles
|
||||
* Grant and/or add capabilities to roles
|
||||
* Rename roles
|
||||
* Clone roles
|
||||
* Import/Export roles, can also download (and upload) setting files
|
||||
* Update role capabilities from current view
|
||||
* Automatically migrate users to another role after deleting a role
|
||||
|
||||
= Compatibility & Integrations =
|
||||
|
||||
This plugin will work with most other plugins but these are tested:
|
||||
|
||||
* **Advanced Access Manager** *(Pro version not verified)*
|
||||
* **bbPress**
|
||||
* **BuddyPress**
|
||||
* **Genesis Framework** *(and probably other theme frameworks)*
|
||||
* **Gravity Forms**
|
||||
* **Groups 2.1+** *(Custom integration: adds a view type for groups. Pro version not tested)*
|
||||
* **Pods Framework 2.0+**
|
||||
* **Members**
|
||||
* **Restrict User Access 0.13+** *(Custom integration: adds a view type for access levels)*
|
||||
* **User Roles and Capabilities**
|
||||
* **User Role Editor** *(Pro version not verified)*
|
||||
* **User Switching** *(Not sure why you'd want this but yes, switch-ception is possible!)*
|
||||
* **WPFront User Role Editor**
|
||||
* **WP Admin UI Customize 1.5.11+**
|
||||
* **Yoast SEO**
|
||||
|
||||
Full list of tested plugins and details: [Compatibility & Integrations](https://github.com/JoryHogeveen/view-admin-as/wiki/Compatibility-&-Integrations)
|
||||
|
||||
= I can't switch back! =
|
||||
|
||||
See item **3** at [FAQ](https://wordpress.org/plugins/view-admin-as/faq/).
|
||||
|
||||
= It's not working! / I found a bug! =
|
||||
|
||||
Please let me know through the support and add a plugins and themes list! :)
|
||||
|
||||
= Security =
|
||||
|
||||
This plugin is completely safe and will keep your users, passwords and data secure.
|
||||
For more info see item **7** at [FAQ](https://wordpress.org/plugins/view-admin-as/faq/)!
|
||||
|
||||
= Developer notes =
|
||||
|
||||
This plugin will only be useful for admins (network super admins or regular admins). It will not add functionalities for other roles unless you specifically apply custom capabilities for those users.
|
||||
Also keep in mind that switching to users that have equal roles is disabled. (regular admins to regular admins + super admins to super admins)
|
||||
|
||||
I've created this at first for myself since I'm a developer and often need to see the outcome on roles which my clients use.
|
||||
|
||||
So, when you are developing a plugin or theme that does anything with roles or capabilities you can use this plugin to easily check if everything works.
|
||||
No more hassle of creating test users and constantly logging out and in anymore!
|
||||
|
||||
This plugin is also useful to support your clients and/or users. For example; make screen display presets of the edit and overview pages before you let them log in.
|
||||
|
||||
== Installation ==
|
||||
|
||||
Installation of this plugin works like any other plugin out there. Either:
|
||||
|
||||
1. Upload and unpack the zip file to the '/wp-content/plugins/' directory
|
||||
2. Activate the plugin through the 'Plugins' menu in WordPress
|
||||
|
||||
Or search for "View Admin As" via your plugins menu.
|
||||
|
||||
= Minimum Requirements =
|
||||
|
||||
* WordPress 4.1 or greater (Though I always recommend to update to the latest version!)
|
||||
|
||||
= Install as a must-use plugin =
|
||||
Move the `view-admin-as.php` file into the root of your mu-plugins directory, not in the `view-admin-as` subdirectory.
|
||||
This is a limitation of WordPress and probably won't change soon.
|
||||
|
||||
**Example:**
|
||||
All files dir: `/wp-content/mu-plugins/view-admin-as/...`
|
||||
Main file dir: `/wp-content/mu-plugins/view-admin-as.php`
|
||||
|
||||
== Frequently Asked Questions ==
|
||||
|
||||
= 1. How do I switch to a user, role or visitor? =
|
||||
Just click on the link in the toolbar!
|
||||
|
||||
If the amount of users and roles combined is more than 15 you can find the users under their roles or you can search for them.
|
||||
|
||||
If the amount of users is more than 100 the plugin will switch to AJAX search and won't load users in advance for performance.
|
||||
This limit can be changed through the filter: [`view_admin_as_user_query_limit`](https://github.com/JoryHogeveen/view-admin-as/wiki/Filters#view_admin_as_user_query_limit)
|
||||
|
||||
= 2. How does the capability system work? =
|
||||
Only the capabilities that are allowed for your user are shown.
|
||||
You can deselect the capabilities by clicking on them. When you would like to see the results just click the apply button on the upper left.
|
||||
|
||||
*Please note that as an administrator you don't have all capabilities marked as enabled by default. This is because WP overrules some capability checks for super admins. **This does not happen when you are in a view!***
|
||||
|
||||
You can also filter the roles by name or select/deselect all capabilities.
|
||||
Note: When you select/deselect capabilities while you've filtered them only the capabilities shown by your filter are affected!
|
||||
|
||||
When you disable a capability that prevents you from viewing a screen, you can reset the view, see next item.
|
||||
|
||||
= 3. I can't switch back! =
|
||||
When a view is selected there is a reset button available on the dropdown.
|
||||
If you get a 403 page of WordPress you can return with the link that this plugin will add to those pages.
|
||||
And if even that doesn't work just add "?reset-view" in the address bar and you're good to go! This will work on all pages as long as you are logged in.
|
||||
|
||||
Example: http://www.your.domain/wp-admin/?reset-view
|
||||
|
||||
= 4. What data is stored for role defaults and how can I change this? =
|
||||
Please see the `view_admin_as_role_defaults_meta` filter at [Wiki: Filters](https://github.com/JoryHogeveen/view-admin-as/wiki/Filters#view_admin_as_role_defaults_meta)!
|
||||
|
||||
The meta manager (since 1.6.3) provides a UI to edit the meta keys.
|
||||
Please follow these guidelines:
|
||||
|
||||
* `%%` stands for a wildcard which could be anything.
|
||||
* Avoid special characters. Spaces, quotes etc. are forbidden.
|
||||
* Default meta keys cannot be removed, only disabled.
|
||||
|
||||
= 5. I can't find a user! =
|
||||
Could it be that this user is an equal user to your's? Example: you are both Admins?
|
||||
If so, these are filtered. Viewing Admins can only be done when you are a Super Admin within a network installation.
|
||||
|
||||
Why? To protect your fellow admin! You have no power over equal users..
|
||||
*Unless you are a superior admin... [Read more](https://github.com/JoryHogeveen/view-admin-as/wiki/Filters#view_admin_as_superior_admins)*
|
||||
|
||||
If this is not the case, please make sure you aren't overlooking something.
|
||||
If that is not the case, please contact me! See next item.
|
||||
|
||||
= 6. It's not working! / I found a bug! =
|
||||
Please let me know through the support and add a plugins and themes list! :)
|
||||
|
||||
= 7. Is this plugin safe? Even for production websites? =
|
||||
You have nothing to worry about.
|
||||
All the plugin functionality is only run if the user is logged in AND is allowed to use this plugin (website admin or custom capabilities).
|
||||
**This plugin will do absolutely nothing if the above requirements are not met.**
|
||||
|
||||
* Your view is stored separately so your user will keep the normal roles and capabilities.
|
||||
* All settings, views, capabilities, etc. are verified before applied.
|
||||
* Passwords are not (and cannot be) revealed.
|
||||
* Fully written with the WordPress coding and security standards.
|
||||
* Full support for SSL (https).
|
||||
|
||||
So basically if your admin users are safe, this plugin will be safe.
|
||||
Note: if your admin users aren't safe, this plugin is the last one to worry about ;)
|
||||
|
||||
= 8. Does this plugin work as a must-use plugin (mu-plugin)? =
|
||||
Yes, see *Install as a must-use plugin* on the *Installation* tab.
|
||||
|
||||
== Screenshots ==
|
||||
|
||||
1. Default dropdown
|
||||
2. Dropdown with grouped users
|
||||
3. Search users
|
||||
4. Quickly (de)select capabilities
|
||||
5. Large popup for better overview of capabilities
|
||||
6. Admin bar when a view is selected + the reset button location
|
||||
7. Settings window
|
||||
8. Module Role defaults window (tabs are normally closed)
|
||||
9. Module Role manager main window (tabs are normally closed)
|
||||
10. Module Role manager capability window (tabs is normally closed)
|
||||
11. View combinations
|
||||
12. Access levels taken from the "Restrict User Access" plugin
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 1.8 =
|
||||
|
||||
* **Feature:** View combinations UI. [#18](https://github.com/JoryHogeveen/view-admin-as/issues/18)
|
||||
* **Feature/Enhancement:** Limit user query to max 100 users for performance. Switch to AJAX search if there are more users than this limit. [#19](https://github.com/JoryHogeveen/view-admin-as/issues/19)
|
||||
* **Accessibility:** New filter: `view_admin_as_user_query_limit` to change the limit used to query users.
|
||||
* **Accessibility:** New filters: `vaa_admin_bar_view_title_role` & `vaa_admin_bar_view_title_user` & `vaa_admin_bar_view_title_locale` to change the titles for role, users and languages.
|
||||
* **Accessibility:** New filter: `vaa_admin_bar_view_title_user_show_roles` to remove the roles from user nodes.
|
||||
* **Accessibility:** New filter: `view_admin_as_full_access_capabilities` for single site installations to change the capabilities required to gain full access to this plugin.
|
||||
* **Enhancement:** Use a class autoloader.
|
||||
* **Enhancement:** Stop using the `rel` attribute for view type data.
|
||||
* **Enhancement:** Access validation logic.
|
||||
* **Compatibility:** Patch Yoast SEO compatibility. [Yoast SEO #9365](https://github.com/Yoast/wordpress-seo/pull/9365)
|
||||
* **Refactoring:** Action/Filter hook manager class. [#77](https://github.com/JoryHogeveen/view-admin-as/issues/77)
|
||||
* **Refactoring:** Refactor all view types as separate modules. [#84](https://github.com/JoryHogeveen/view-admin-as/issues/84)
|
||||
* **Fix:** Use `prop` instead of `attr` for `checked` attributes in checkbox inputs.
|
||||
* **Updated/Added:** Screenshots.
|
||||
|
||||
Detailed info: [PR on GitHub](https://github.com/JoryHogeveen/view-admin-as/pull/78)
|
||||
|
||||
= 1.7.6.1 =
|
||||
|
||||
* **Compatibility:** Improve customizer compatibility. [#88](https://github.com/JoryHogeveen/view-admin-as/issues/88)
|
||||
* **Compatibility/Fix:** Frontend error with Yoast SEO. [Yoast SEO #9285](https://github.com/Yoast/wordpress-seo/pull/9285)
|
||||
|
||||
Detailed info: [PR on GitHub](https://github.com/JoryHogeveen/view-admin-as/pull/90)
|
||||
|
||||
= 1.7.6 =
|
||||
|
||||
* **Feature:** Role manager: Option to migrate users to another role after deleting a role. [#86](https://github.com/JoryHogeveen/view-admin-as/issues/86)
|
||||
* **Enhancement:** Enhance user full access validation for single installations. Not only check for super admin but also the capabilities `edit_users` and `delete_plugins`.
|
||||
* **Enhancement:** Add customizer support and a new setting to disable this. [#26](https://github.com/JoryHogeveen/view-admin-as/issues/26)
|
||||
* **Enhancement:** Compatibility with `$_SERVER['ORIG_REQUEST_URI']` for removable query args on front end. [#87](https://github.com/JoryHogeveen/view-admin-as/issues/87)
|
||||
* **UI:** Support SVG and file icons + Base64 encoded strings.
|
||||
|
||||
Detailed info: [PR on GitHub](https://github.com/JoryHogeveen/view-admin-as/pull/85)
|
||||
|
||||
= 1.7.5 =
|
||||
|
||||
* **Feature:** Language switcher. [#81](https://github.com/JoryHogeveen/view-admin-as/issues/81)
|
||||
* **Enhancement:** Store options network wide instead of per blog/site if network/multisite is enabled.
|
||||
* **Enhancement:** Action links (no-JS) on frontend.
|
||||
* **Enhancement:** Add filter `view_admin_as_freeze_locale` to overwrite user setting.
|
||||
* **Fix:** JavaScript init on frontend.
|
||||
* **UI:** Various minor enhancements.
|
||||
|
||||
Detailed info: [PR on GitHub](https://github.com/JoryHogeveen/view-admin-as/pull/82)
|
||||
|
||||
= 1.7.4 =
|
||||
|
||||
* **Feature:** Role defaults / Role manager: download export data as file + import from file. [#73](https://github.com/JoryHogeveen/view-admin-as/issues/73)
|
||||
* **Enhancement:** Refresh page instead of redirect to home when switching to a site visitor on the frontend. [#76](https://github.com/JoryHogeveen/view-admin-as/issues/76)
|
||||
* **Enhancement:** Role Manager: Refresh the page if a role is updated while active in the current view.
|
||||
* **Enhancement:** jQuery selector performance.
|
||||
* **Compatibility:** [WP 4.9 capabilities](https://make.wordpress.org/core/2017/10/15/improvements-for-roles-and-capabilities-in-4-9/).
|
||||
* **Compatibility:** WP Admin UI Customize admin bar editor. [#40](https://github.com/JoryHogeveen/view-admin-as/issues/40) & [WAUC/#1](https://github.com/gqevu6bsiz/WP-Admin-UI-Customize-test/pull/1) & [WAUC/#2](https://github.com/gqevu6bsiz/WP-Admin-UI-Customize-test/pull/2)
|
||||
* **Compatibility:** Fix issue with Restrict User Access. [RUA/#15](https://github.com/intoxstudio/restrict-user-access/issues/15)
|
||||
* **Compatibility:** Fetch all capabilities from Yoast SEO (5.5+).
|
||||
* **Compatibility:** Must-use plugin loader scripts.
|
||||
* **UI:** The almighty View Admin As loader icon.
|
||||
* **UI:** Full opacity when semi-transparent group nodes are opened.
|
||||
* **UI:** Admin page links for Groups and Restrict User Access modules.
|
||||
* **UI:** Resizable checkbox wrappers.
|
||||
|
||||
Detailed info: [PR on GitHub](https://github.com/JoryHogeveen/view-admin-as/pull/75)
|
||||
|
||||
= 1.7.3 =
|
||||
|
||||
* **Feature:** Role Manager: Import/Export roles. [#51](https://github.com/JoryHogeveen/view-admin-as/issues/51) & [PR #62](https://github.com/JoryHogeveen/view-admin-as/pull/62)
|
||||
* **Feature/Enhancement:** Option to disable super admin status when a view is active and modifies the current user. [#53](https://github.com/JoryHogeveen/view-admin-as/issues/53) & [PR #61](https://github.com/JoryHogeveen/view-admin-as/pull/61)
|
||||
* **Enhancement:** Role Manager: Show custom capabilities that are not yet stored but used in an active caps view. [#70](https://github.com/JoryHogeveen/view-admin-as/issues/70)
|
||||
* **Enhancement:** Prevent duplicate names when fetching capabilities from WP objects.
|
||||
* **Enhancement:** Allow this plugin to be installed as a must-use plugin. [#71](https://github.com/JoryHogeveen/view-admin-as/issues/71)
|
||||
* More info: [Docs: Install as a must-use plugin](https://github.com/JoryHogeveen/view-admin-as#install-as-a-must-use-plugin) & [WP codex: mu-plugins](https://codex.wordpress.org/Must_Use_Plugins)
|
||||
* **Enhancement:** Role Defaults: Enhance meta key comparison.
|
||||
* **UI:** Option tooltips. [#67](https://github.com/JoryHogeveen/view-admin-as/issues/67)
|
||||
* **UI:** Enhance full popup caps view.
|
||||
* **Refactoring:** Fix base class name.
|
||||
|
||||
Detailed info: [PR on GitHub](https://github.com/JoryHogeveen/view-admin-as/pull/68)
|
||||
|
||||
= 1.7.2 =
|
||||
|
||||
* **Feature:** Integration with the "Groups" plugin. Introduces a new view type `groups` when this plugin is activated. [#11](https://github.com/JoryHogeveen/view-admin-as/issues/11)
|
||||
* **Fix:** auto max height didn't work on frontend. [#55](https://github.com/JoryHogeveen/view-admin-as/issues/55)
|
||||
* **Fix:** Role Manager used `boolval()` which is only available in PHP 5.5+. [#63](https://github.com/JoryHogeveen/view-admin-as/issues/63)
|
||||
* **Fix:** `view_admin_as_superior_admins` filter was not working for single installations. [#65](https://github.com/JoryHogeveen/view-admin-as/issues/65)
|
||||
* **Compatibility:** Allow other plugins to overwrite our `user_has_cap` filter by setting it's priority as first (large negative number). [#56](https://github.com/JoryHogeveen/view-admin-as/issues/56). Thanks to [@pbiron](https://github.com/pbiron) for the report.
|
||||
* **Compatibility:** Run the `user_has_cap` filter in your `map_meta_cap` filter. [#56](https://github.com/JoryHogeveen/view-admin-as/issues/56)
|
||||
* **Compatibility:** Add new network capabilities (WP 4.8) to the list. [#64](https://github.com/JoryHogeveen/view-admin-as/issues/64)
|
||||
* **Enhancement:** Automatic JS handling for simple and more advanced options. [#60](https://github.com/JoryHogeveen/view-admin-as/issues/60)
|
||||
* **Enhancement:** Role defaults: Rename `all` wildcard to `__all__` to prevent a possible conflict with custom roles.
|
||||
* **Enhancement:** Role defaults: Add recording indicator icon to the top level node when a role view is active.
|
||||
* **Refactoring:** Move form logic to separate class and extend it (admin bar)
|
||||
|
||||
Detailed info: [PR on GitHub](https://github.com/JoryHogeveen/view-admin-as/pull/54) & [Groups integration PR on GitHub](https://github.com/JoryHogeveen/view-admin-as/pull/59)
|
||||
|
||||
= 1.7.1 =
|
||||
|
||||
* **Feature:** Module Role Manager: Rename roles. [#47](https://github.com/JoryHogeveen/view-admin-as/issues/47)
|
||||
* **Enhancement:** Improve fetching available capabilities for a super admin. It now also checks for registered custom post type and taxonomy capabilities and more other plugins.
|
||||
* **Compatibility:** Also use the `user_has_cap` filter besides `map_meta_cap` to further improve capability and role view compatibility.
|
||||
* **UI:** Add submenu scrollbar when there are too much users under a role. [#49](https://github.com/JoryHogeveen/view-admin-as/issues/49)
|
||||
* **UI:** Module Role Manager: Show original role name for reference.
|
||||
* **Accessibility:** Fix tabindex for some nodes that have form elements.
|
||||
* **Updated:** Screenshots.
|
||||
|
||||
Detailed info: [PR on GitHub](https://github.com/JoryHogeveen/view-admin-as/pull/48)
|
||||
|
||||
= 1.7 =
|
||||
|
||||
* **Feature:** New module Role manager. Add, edit and/or remove roles and grant or deny them capabilities. [#43](https://github.com/JoryHogeveen/view-admin-as/issues/43)
|
||||
* **Feature:** Module Role Defaults: Added the option to copy defaults from one role to another (or multiple). [#44](https://github.com/JoryHogeveen/view-admin-as/issues/44)
|
||||
* **Enhancement/UI:** Enable and Improve responsive styles/a11y. [#16](https://github.com/JoryHogeveen/view-admin-as/issues/16)
|
||||
* **Enhancement/UI:** Improved the autoHeight calculation (submenu and popup).
|
||||
* **Enhancement:** View combinations now working in code (No UI). [#18](https://github.com/JoryHogeveen/view-admin-as/issues/18)
|
||||
* **Enhancement:** Major code refactoring for better standards en easier development.
|
||||
* **Maintenance:** Validated compatibility with "Restrict User Access" (RUA) plugin v0.14. [#31](https://github.com/JoryHogeveen/view-admin-as/issues/31)
|
||||
* **Compatibility:** Tested with WordPress 4.8 (alpha) and requires WordPress 4.1 or higher (was 3.5).
|
||||
* **Fix:** Fixed all major [CodeClimate](https://codeclimate.com/github/JoryHogeveen/view-admin-as) issues. All green now!
|
||||
* **Updated:** [Wiki (documentation)](https://github.com/JoryHogeveen/view-admin-as/wiki).
|
||||
* **Updated/Added:** Screenshots & Banners.
|
||||
|
||||
Detailed info: [PR on GitHub](https://github.com/JoryHogeveen/view-admin-as/pull/42)
|
||||
|
||||
= Older versions =
|
||||
|
||||
[Complete changelog](https://github.com/JoryHogeveen/view-admin-as/wiki/Changelog)
|
||||
|
||||
== Other Notes ==
|
||||
|
||||
= You can find me here: =
|
||||
|
||||
* [Keraweb](http://www.keraweb.nl/)
|
||||
* [GitHub](https://github.com/JoryHogeveen/view-admin-as/)
|
||||
* [LinkedIn](https://nl.linkedin.com/in/joryhogeveen)
|
||||
|
||||
= Translations =
|
||||
|
||||
Please help translating this plugin on [translate.wordpress.org](https://translate.wordpress.org/projects/wp-plugins/view-admin-as)!
|
||||
|
||||
= Actions & Filters =
|
||||
|
||||
* [Click here for Action documentation](https://github.com/JoryHogeveen/view-admin-as/wiki/Actions)
|
||||
* [Click here for Filter documentation](https://github.com/JoryHogeveen/view-admin-as/wiki/Filters)
|
||||
|
||||
= Plugin capabilities =
|
||||
|
||||
[Click here for documentation](https://github.com/JoryHogeveen/view-admin-as/wiki/Custom-capabilities)
|
||||
|
||||
= Ideas? =
|
||||
|
||||
Please let me know on [GitHub](https://github.com/JoryHogeveen/view-admin-as/issues/new)!
|
||||
|
||||
== Upgrade Notice ==
|
||||
|
||||
= 1.7 =
|
||||
Version 1.7 introduces some radical code changes to the plugin and requires WordPress 4.1 or higher. Please clear your cache after updating.
|
||||
|
||||
= 1.5 =
|
||||
Version 1.5 introduces some radical code changes to the plugin. Please clear your cache after updating.
|
||||
713
backend/wordpress/wp-content/plugins/view-admin-as/ui/class-admin-bar.php
Executable file
713
backend/wordpress/wp-content/plugins/view-admin-as/ui/class-admin-bar.php
Executable file
@@ -0,0 +1,713 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Admin Bar UI
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin Bar UI for View Admin As.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.5
|
||||
* @version 1.8
|
||||
* @uses \VAA_View_Admin_As_Base Extends class
|
||||
*/
|
||||
final class VAA_View_Admin_As_Admin_Bar extends VAA_View_Admin_As_Base
|
||||
{
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @since 1.5
|
||||
* @static
|
||||
* @var \VAA_View_Admin_As_Admin_Bar
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* Admin bar root item ID.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @static
|
||||
* @var string
|
||||
*/
|
||||
public static $root = 'vaa';
|
||||
|
||||
/**
|
||||
* Admin bar parent item ID.
|
||||
*
|
||||
* @since 1.7.4
|
||||
* @static
|
||||
* @var string
|
||||
*/
|
||||
public static $parent = 'top-secondary';
|
||||
|
||||
/**
|
||||
* Construct function.
|
||||
* Protected to make sure it isn't declared elsewhere.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.6.1 $vaa param
|
||||
* @access protected
|
||||
* @param \VAA_View_Admin_As $vaa The main VAA object.
|
||||
*/
|
||||
protected function __construct( $vaa ) {
|
||||
self::$_instance = $this;
|
||||
parent::__construct( $vaa );
|
||||
|
||||
if ( $this->is_vaa_enabled() ) {
|
||||
$this->add_action( 'vaa_view_admin_as_init', array( $this, 'vaa_init' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* init function to store data from the main class and enable functionality based on the current view.
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @see 'vaa_view_admin_as_init' action
|
||||
* @return void
|
||||
*/
|
||||
public function vaa_init() {
|
||||
|
||||
$priority = 10;
|
||||
$location = $this->store->get_userSettings( 'admin_menu_location' );
|
||||
if ( $location && in_array( $location, $this->store->get_allowedUserSettings( 'admin_menu_location' ), true ) ) {
|
||||
self::$parent = $location;
|
||||
if ( 'my-account' === $location ) {
|
||||
$priority = -10;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Set the priority in which the adminbar root node is added.
|
||||
* @since 1.7.4
|
||||
* @param int $priority
|
||||
* @param string $parent The main VAA node parent.
|
||||
* @return int
|
||||
*/
|
||||
$priority = (int) apply_filters( 'vaa_admin_bar_priority', $priority, self::$parent );
|
||||
|
||||
// Add the default nodes to the WP admin bar.
|
||||
$this->add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), $priority );
|
||||
$this->add_action( 'vaa_toolbar_menu', array( $this, 'admin_bar_menu' ), 10, 2 );
|
||||
|
||||
// Add the global nodes to the admin bar.
|
||||
$this->add_action( 'vaa_admin_bar_menu', array( $this, 'admin_bar_menu_info' ), 1 );
|
||||
$this->add_action( 'vaa_admin_bar_menu', array( $this, 'admin_bar_menu_settings' ), 2 );
|
||||
$this->add_action( 'vaa_admin_bar_settings_after', array( $this, 'admin_bar_menu_view_types' ), 1, 2 );
|
||||
$this->add_action( 'vaa_admin_bar_settings_after', array( $this, 'admin_bar_menu_modules' ), 2, 2 );
|
||||
|
||||
if ( ! is_network_admin() ) {
|
||||
|
||||
if ( $this->current_user_can( 'view_admin_as_combinations' ) ) {
|
||||
// View combinations.
|
||||
$this->add_action( 'vaa_admin_bar_menu', array( $this, 'admin_bar_menu_combine' ), 8, 2 );
|
||||
}
|
||||
|
||||
// There are no outside visitors on network pages.
|
||||
// Add the visitor view nodes under roles with a fallback to users.
|
||||
$this->add_action( 'vaa_admin_bar_roles_after', array( $this, 'admin_bar_menu_visitor' ), 10, 2 );
|
||||
$this->add_action( 'vaa_admin_bar_users_before', array( $this, 'admin_bar_menu_visitor' ), 10, 2 );
|
||||
// Fallback action for when there are no roles or users available.
|
||||
$this->add_action( 'vaa_admin_bar_menu', array( $this, 'admin_bar_menu_visitor' ), 31 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the toolbar title for the main VAA node.
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @access private
|
||||
* @see \VAA_View_Admin_As_Admin_Bar::admin_bar_menu()
|
||||
* @return string
|
||||
*/
|
||||
private function get_admin_bar_menu_title() {
|
||||
if ( ! $this->store->get_view() ) {
|
||||
return __( 'Default view (Off)', VIEW_ADMIN_AS_DOMAIN );
|
||||
}
|
||||
|
||||
$titles = array();
|
||||
|
||||
if ( $this->store->get_view( 'visitor' ) ) {
|
||||
$titles[] = __( 'Site visitor', VIEW_ADMIN_AS_DOMAIN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter what to show when a view is applied.
|
||||
*
|
||||
* @hooked
|
||||
* 5: user
|
||||
* 8: role
|
||||
* 10: group (Groups)
|
||||
* 10: rua_level (Restrict User Access)
|
||||
* 80: caps
|
||||
* 90: locale
|
||||
* 999: role defaults (appends an icon)
|
||||
*
|
||||
* @since 1.7.5
|
||||
*
|
||||
* @param array $titles The current title(s).
|
||||
* @param array $view The view data.
|
||||
*
|
||||
* @return array|string
|
||||
*/
|
||||
$titles = apply_filters( 'vaa_admin_bar_view_titles', $titles, (array) $this->store->get_view() );
|
||||
|
||||
if ( is_array( $titles ) ) {
|
||||
if ( 1 < count( $titles ) ) {
|
||||
// @todo Help icon for view info?
|
||||
// Translators: Context is a list of view types. Not the verb.
|
||||
$title = __( 'View', VIEW_ADMIN_AS_DOMAIN ) . ': ' . implode( ', ', $titles );
|
||||
} else {
|
||||
$type = key( $titles );
|
||||
$name = reset( $titles );
|
||||
$title = __( 'Viewing as', VIEW_ADMIN_AS_DOMAIN );
|
||||
if ( $type ) {
|
||||
$title .= ' ' . $type;
|
||||
}
|
||||
$title .= ': ';
|
||||
if ( $name ) {
|
||||
$title .= $name;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$title = (string) $titles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter what to show when a view is applied.
|
||||
* This filter is hooked after the initial parsing of view titles.
|
||||
*
|
||||
* @since 1.6
|
||||
* @since 1.7.5 Renamed from `vaa_admin_bar_viewing_as_title`.
|
||||
* @param string $title The current title.
|
||||
* @param string $view The view data.
|
||||
* @return string
|
||||
*/
|
||||
$title = apply_filters( 'vaa_admin_bar_title', $title, (array) $this->store->get_view() );
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin bar menu items.
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The root item ID/Name. If set it will overwrite the user setting.
|
||||
* @return void
|
||||
*/
|
||||
public function admin_bar_menu( $admin_bar, $root = '' ) {
|
||||
|
||||
$icon = 'dashicons-hidden';
|
||||
$tooltip = __( 'View Admin As', VIEW_ADMIN_AS_DOMAIN );
|
||||
|
||||
if ( $this->store->get_view() ) {
|
||||
$icon = 'dashicons-visibility';
|
||||
$tooltip .= ' - ' . __( 'View active', VIEW_ADMIN_AS_DOMAIN );
|
||||
}
|
||||
|
||||
$title = $this->get_admin_bar_menu_title();
|
||||
|
||||
if ( empty( $root ) ) {
|
||||
$root = self::$parent;
|
||||
}
|
||||
|
||||
// Add menu item.
|
||||
$admin_bar->add_node( array(
|
||||
'id' => self::$root,
|
||||
'parent' => $root,
|
||||
'title' => '<span class="ab-label">' . $title . '</span>' . VAA_View_Admin_As_Form::do_icon(
|
||||
$icon,
|
||||
array( 'class' => 'alignright' )
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'title' => $tooltip,
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
|
||||
/**
|
||||
* Add items as first.
|
||||
*
|
||||
* @since 1.5
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string self::$root The current root item.
|
||||
* @param string self::$root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_menu_before', $admin_bar, self::$root, self::$root );
|
||||
|
||||
// Add reset button.
|
||||
if ( $this->store->get_view() ) {
|
||||
$name = 'reset-view';
|
||||
if ( 'single' === $this->store->get_userSettings( 'view_mode' ) ) {
|
||||
$name = 'reload';
|
||||
}
|
||||
$admin_bar->add_node( array(
|
||||
'id' => self::$root . '-reset',
|
||||
'parent' => self::$root,
|
||||
'title' => VAA_View_Admin_As_Form::do_button( array(
|
||||
'name' => self::$root . '-' . $name,
|
||||
'label' => __( 'Reset to default', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'class' => 'button-secondary',
|
||||
) ),
|
||||
'href' => VAA_API::get_reset_link(),
|
||||
'meta' => array(
|
||||
'title' => esc_attr__( 'Reset to default', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'class' => 'vaa-reset-item vaa-button-container',
|
||||
),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add items.
|
||||
*
|
||||
* @since 1.5
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string self::$root The current root item.
|
||||
* @param string self::$root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_menu', $admin_bar, self::$root, self::$root );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin bar menu info items.
|
||||
*
|
||||
* @hooked
|
||||
* 1: Info
|
||||
* 2: Settings
|
||||
* 5: Role Defaults module
|
||||
* 6: Role Manager module
|
||||
* 8: View combinations
|
||||
* 9: Languages view
|
||||
* 10: Capabilities view
|
||||
* 20: Roles view
|
||||
* 30: Users view
|
||||
* 31: Visitor view
|
||||
* 40: RUA & Groups view modules
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @see 'vaa_admin_bar_menu' action
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @return void
|
||||
*/
|
||||
public function admin_bar_menu_info( $admin_bar ) {
|
||||
|
||||
$root = self::$root . '-info';
|
||||
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root,
|
||||
'parent' => self::$root,
|
||||
'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-info' ) . __( 'Info', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'vaa-has-icon',
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
|
||||
$admin_bar->add_group( array(
|
||||
'id' => $root . '-about',
|
||||
'parent' => $root,
|
||||
'meta' => array(
|
||||
'class' => 'ab-sub-secondary',
|
||||
),
|
||||
) );
|
||||
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'parent' => $root . '-about',
|
||||
'id' => $root . '-about-version',
|
||||
'title' => __( 'Version', VIEW_ADMIN_AS_DOMAIN ) . ': ' . VIEW_ADMIN_AS_VERSION,
|
||||
'href' => false,
|
||||
)
|
||||
);
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'parent' => $root . '-about',
|
||||
'id' => $root . '-about-author',
|
||||
'title' => 'Keraweb • Jory Hogeveen',
|
||||
'href' => 'https://profiles.wordpress.org/keraweb/',
|
||||
'meta' => array(
|
||||
'target' => '_blank',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Add items at the beginning of the info group.
|
||||
*
|
||||
* @since 1.6
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @param string self::$root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_info_before', $admin_bar, $root, self::$root );
|
||||
|
||||
// Add the general admin links.
|
||||
if ( VAA_API::exists_callable( array( $this->vaa->get_ui( 'ui' ), 'get_links' ), true ) ) {
|
||||
$info_links = $this->vaa->get_ui( 'ui' )->get_links();
|
||||
|
||||
$admin_bar->add_group( array(
|
||||
'id' => $root . '-links',
|
||||
'parent' => $root,
|
||||
) );
|
||||
|
||||
foreach ( $info_links as $id => $link ) {
|
||||
$admin_bar->add_node( array(
|
||||
'parent' => $root . '-links',
|
||||
'id' => $root . '-' . $id,
|
||||
'title' => VAA_View_Admin_As_Form::do_icon( $link['icon'] ) . $link['description'],
|
||||
'href' => esc_url( $link['url'] ),
|
||||
'meta' => array(
|
||||
'class' => 'auto-height vaa-has-icon',
|
||||
'target' => '_blank',
|
||||
),
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add items at the end of the info group.
|
||||
*
|
||||
* @since 1.6
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @param string self::$root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_info_after', $admin_bar, $root, self::$root );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin bar menu settings items.
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @see 'vaa_admin_bar_menu' action
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @return void
|
||||
*/
|
||||
public function admin_bar_menu_settings( $admin_bar ) {
|
||||
|
||||
$root = self::$root . '-settings';
|
||||
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root,
|
||||
'parent' => self::$root,
|
||||
'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-admin-settings' ) . __( 'Settings', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'vaa-has-icon',
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
|
||||
/**
|
||||
* Add items at the beginning of the settings group.
|
||||
*
|
||||
* @since 1.5
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @param string self::$root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_settings_before', $admin_bar, $root, self::$root );
|
||||
|
||||
// Add user setting nodes.
|
||||
include VIEW_ADMIN_AS_DIR . 'ui/templates/adminbar-settings-user.php';
|
||||
|
||||
/**
|
||||
* Add items at the end of the settings group.
|
||||
*
|
||||
* @since 1.5
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @param string self::$root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_settings_after', $admin_bar, $root, self::$root );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin bar menu view type items.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @see 'vaa_admin_bar_menu' action
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @return void
|
||||
*/
|
||||
public function admin_bar_menu_view_types( $admin_bar, $root ) {
|
||||
|
||||
if ( ! VAA_API::is_super_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$view_types = $this->vaa->get_view_types();
|
||||
|
||||
// Do not render the view_types group if there are no view types to show.
|
||||
if ( ! $view_types ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$admin_bar->add_group( array(
|
||||
'id' => self::$root . '-view_types',
|
||||
'parent' => $root,
|
||||
'meta' => array(
|
||||
'class' => 'ab-sub-secondary',
|
||||
),
|
||||
) );
|
||||
|
||||
$root = self::$root . '-view_types';
|
||||
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-title',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-visibility' ) . __( 'View types', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'vaa-has-icon ab-vaa-title ab-vaa-toggle active',
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
|
||||
$parent = $root;// . '-title';
|
||||
|
||||
$view_type_nodes = array();
|
||||
|
||||
foreach ( $view_types as $type ) {
|
||||
|
||||
$view_type_node = array(
|
||||
'name' => $root . '-' . $type->get_type(),
|
||||
'value' => $type->is_enabled(),
|
||||
'compare' => true,
|
||||
'label' => $type->get_label(),
|
||||
'auto_js' => array(
|
||||
'setting' => 'setting',
|
||||
'key' => 'view_types',
|
||||
'values' => array(
|
||||
$type->get_type() => array(
|
||||
'values' => array(
|
||||
'enabled' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
'refresh' => true,
|
||||
),
|
||||
'auto_showhide' => true,
|
||||
);
|
||||
|
||||
if ( $type->get_description() ) {
|
||||
$view_type_node['description'] = $type->get_description();
|
||||
$view_type_node['help'] = true;
|
||||
}
|
||||
|
||||
$view_type_nodes[ $type->get_priority() ][] = array(
|
||||
'id' => $root . '-' . $type->get_type(),
|
||||
'parent' => $parent,
|
||||
'title' => VAA_View_Admin_As_Form::do_checkbox( $view_type_node ),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'auto-height',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
ksort( $view_type_nodes );
|
||||
foreach ( $view_type_nodes as $nodes ) {
|
||||
foreach ( $nodes as $node ) {
|
||||
$admin_bar->add_node( $node );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add items to the view_types group.
|
||||
*
|
||||
* @since 1.7.1
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @param string self::$root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_view_types', $admin_bar, $root, self::$root );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin bar menu modules items.
|
||||
*
|
||||
* @since 1.7.1
|
||||
* @access public
|
||||
* @see 'vaa_admin_bar_menu' action
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @return void
|
||||
*/
|
||||
public function admin_bar_menu_modules( $admin_bar, $root ) {
|
||||
|
||||
// Do not render the modules group if there are no modules to show.
|
||||
if ( ! has_action( 'vaa_admin_bar_modules' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$admin_bar->add_group( array(
|
||||
'id' => self::$root . '-modules',
|
||||
'parent' => $root,
|
||||
'meta' => array(
|
||||
'class' => 'ab-sub-secondary',
|
||||
),
|
||||
) );
|
||||
|
||||
$root = self::$root . '-modules';
|
||||
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-title',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-admin-plugins' ) . __( 'Modules', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'vaa-has-icon ab-vaa-title ab-vaa-toggle active',
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
|
||||
/**
|
||||
* Add items to the modules group.
|
||||
*
|
||||
* @since 1.7.1
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @param string self::$root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_modules', $admin_bar, $root, self::$root );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin bar menu visitor view.
|
||||
*
|
||||
* @since 1.6.2
|
||||
* @access public
|
||||
* @see 'vaa_admin_bar_menu' action
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root (optional) The root item.
|
||||
* @return void
|
||||
*/
|
||||
public function admin_bar_menu_visitor( $admin_bar, $root = '' ) {
|
||||
static $done;
|
||||
if ( $done ) return;
|
||||
|
||||
$main_root = self::$root;
|
||||
$class = 'vaa-visitor-item vaa-has-icon';
|
||||
|
||||
if ( empty( $root ) || $root === $main_root ) {
|
||||
|
||||
$admin_bar->add_group( array(
|
||||
'id' => $main_root . '-visitor',
|
||||
'parent' => $main_root,
|
||||
'meta' => array(
|
||||
'class' => 'ab-sub-secondary',
|
||||
),
|
||||
) );
|
||||
|
||||
$root = $main_root . '-visitor';
|
||||
$class .= ' ab-vaa-title';
|
||||
} else {
|
||||
$class .= ' vaa-menupop';
|
||||
}
|
||||
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $main_root . '-visitor-view',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-universal-access' )
|
||||
. VAA_View_Admin_As_Form::do_view_title( __( 'Site visitor', VIEW_ADMIN_AS_DOMAIN ), 'visitor', true ),
|
||||
'href' => '#',
|
||||
'meta' => array(
|
||||
'title' => esc_attr__( 'View as site visitor', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'class' => $class,
|
||||
),
|
||||
) );
|
||||
|
||||
$done = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin bar menu for view combinations.
|
||||
* Combine views node as last item in the default group.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @see 'vaa_admin_bar_menu' action
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root (optional) The root item.
|
||||
* @return void
|
||||
*/
|
||||
public function admin_bar_menu_combine( $admin_bar, $root = '' ) {
|
||||
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-combine-views',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_checkbox( array(
|
||||
'name' => $root . '-combine-views',
|
||||
'label' => __( 'Combine views', VIEW_ADMIN_AS_DOMAIN ),
|
||||
) ) . VAA_View_Admin_As_Form::do_button( array(
|
||||
'name' => $root . '-combine-views-apply',
|
||||
'label' => __( 'Apply', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'class' => 'button-primary ab-vaa-conditional vaa-alignright',
|
||||
'attr' => array(
|
||||
'vaa-condition-target' => '#' . $root . '-combine-views',
|
||||
),
|
||||
) ) . '<ul id="vaa-combine-views-selection" class="ab-sub-secondary ab-vaa-results" style="display: none;"></ul>',
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'title' => esc_attr__( 'Make view combinations', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'class' => 'vaa-button-container',
|
||||
),
|
||||
) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Instance.
|
||||
*
|
||||
* Ensures only one instance of this class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @static
|
||||
* @param \VAA_View_Admin_As $caller The referrer class
|
||||
* @return \VAA_View_Admin_As_Admin_Bar $this
|
||||
*/
|
||||
public static function get_instance( $caller = null ) {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self( $caller );
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_Admin_Bar.
|
||||
166
backend/wordpress/wp-content/plugins/view-admin-as/ui/class-toolbar.php
Executable file
166
backend/wordpress/wp-content/plugins/view-admin-as/ui/class-toolbar.php
Executable file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Toolbar UI
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WP_Admin_Bar' ) && file_exists( ABSPATH . WPINC . '/class-wp-admin-bar.php' ) ) {
|
||||
require_once ABSPATH . WPINC . '/class-wp-admin-bar.php';
|
||||
}
|
||||
|
||||
if ( class_exists( 'WP_Admin_Bar' ) ) {
|
||||
|
||||
/**
|
||||
* Toolbar UI for View Admin As.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.6
|
||||
* @version 1.8
|
||||
* @see wp-includes/class-wp-admin-bar.php
|
||||
* @uses \WP_Admin_Bar Extends class
|
||||
*/
|
||||
final class VAA_View_Admin_As_Toolbar extends WP_Admin_Bar
|
||||
{
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @since 1.6
|
||||
* @static
|
||||
* @var \VAA_View_Admin_As_Toolbar
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* Is this toolbar being rendered?
|
||||
*
|
||||
* @since 1.6
|
||||
* @static
|
||||
* @var bool
|
||||
*/
|
||||
public static $showing = false;
|
||||
|
||||
/**
|
||||
* View Admin As store.
|
||||
*
|
||||
* @since 1.6
|
||||
* @var \VAA_View_Admin_As_Store
|
||||
*/
|
||||
private $vaa_store = null;
|
||||
|
||||
/**
|
||||
* Construct function.
|
||||
* Protected to make sure it isn't declared elsewhere.
|
||||
*
|
||||
* @since 1.6
|
||||
* @since 1.6.1 $vaa param
|
||||
* @access protected
|
||||
* @param \VAA_View_Admin_As $vaa The main VAA object.
|
||||
*/
|
||||
protected function __construct( $vaa ) {
|
||||
self::$_instance = $this;
|
||||
$this->vaa_store = view_admin_as()->store();
|
||||
|
||||
view_admin_as()->hooks()->add_action( 'vaa_view_admin_as_init', array( $this, 'vaa_init' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Init function that initializes this plugin after the main VAA class is loaded.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @see 'vaa_view_admin_as_init' action
|
||||
* @return void
|
||||
*/
|
||||
public function vaa_init() {
|
||||
// @since 1.7.6 Changed hook from `init` to `wp_loaded` (later).
|
||||
view_admin_as()->hooks()->add_action( 'wp_loaded', array( $this, 'vaa_toolbar_init' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Init function for the toolbar.
|
||||
*
|
||||
* @since 1.6
|
||||
* @since 1.6.2 Check for customizer preview.
|
||||
* @since 1.7.6 Add customizer support by only enabling it in the container, not the preview window.
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function vaa_toolbar_init() {
|
||||
// Stop if the admin bar is already showing or we're in the customizer preview window.
|
||||
if ( is_admin_bar_showing() || ( ! is_admin() && is_customize_preview() ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ( is_customize_preview() && ! $this->vaa_store->get_userSettings( 'hide_customizer' ) ) ||
|
||||
( ! is_admin() && ! $this->vaa_store->get_userSettings( 'hide_front' ) ) ||
|
||||
$this->vaa_store->get_view()
|
||||
) {
|
||||
|
||||
self::$showing = true;
|
||||
|
||||
view_admin_as()->hooks()->add_action( 'wp_footer', array( $this, 'vaa_toolbar_render' ), 100 );
|
||||
view_admin_as()->hooks()->add_action( 'customize_controls_print_footer_scripts', array( $this, 'vaa_toolbar_render' ), 100 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render our toolbar using the render function from WP_Admin_bar.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function vaa_toolbar_render() {
|
||||
|
||||
$this->add_group( array(
|
||||
'id' => 'top-secondary',
|
||||
'meta' => array(
|
||||
'class' => 'ab-top-secondary',
|
||||
),
|
||||
) );
|
||||
|
||||
// Load our admin bar nodes and force the location.
|
||||
do_action( 'vaa_toolbar_menu', $this, 'top-secondary' );
|
||||
|
||||
/**
|
||||
* Add classes to the toolbar menu (front only).
|
||||
* @since 1.6
|
||||
* @param array $array Empty array.
|
||||
* @return array
|
||||
*/
|
||||
$toolbar_classes = apply_filters( 'view_admin_as_toolbar_classes', array() );
|
||||
echo '<div id="vaa_toolbar" class="' . esc_attr( implode( ' ', $toolbar_classes ) ) . '">';
|
||||
|
||||
$this->render();
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Instance.
|
||||
*
|
||||
* Ensures only one instance of this class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @static
|
||||
* @param \VAA_View_Admin_As $caller The referrer class.
|
||||
* @return \VAA_View_Admin_As_Toolbar $this
|
||||
*/
|
||||
public static function get_instance( $caller = null ) {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self( $caller );
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_Toolbar.
|
||||
|
||||
} // End if().
|
||||
398
backend/wordpress/wp-content/plugins/view-admin-as/ui/class-ui.php
Executable file
398
backend/wordpress/wp-content/plugins/view-admin-as/ui/class-ui.php
Executable file
@@ -0,0 +1,398 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Main UI class
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* UI hooks for View Admin As.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.6
|
||||
* @since 1.7 Renamed from VAA_View_Admin_As_Admin
|
||||
* @version 1.8
|
||||
* @uses \VAA_View_Admin_As_Base Extends class
|
||||
*/
|
||||
final class VAA_View_Admin_As_UI extends VAA_View_Admin_As_Base
|
||||
{
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @since 1.6
|
||||
* @static
|
||||
* @var \VAA_View_Admin_As_UI
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* Plugin links.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @var array[]
|
||||
*/
|
||||
private $links = array();
|
||||
|
||||
/**
|
||||
* Construct function.
|
||||
*
|
||||
* @since 1.6
|
||||
* @since 1.6.1 $vaa param
|
||||
* @access protected
|
||||
* @param \VAA_View_Admin_As $vaa The main VAA object.
|
||||
*/
|
||||
protected function __construct( $vaa ) {
|
||||
self::$_instance = $this;
|
||||
parent::__construct( $vaa );
|
||||
|
||||
$this->add_action( 'wp_meta', array( $this, 'action_wp_meta' ) );
|
||||
$this->add_action( 'plugin_row_meta', array( $this, 'action_plugin_row_meta' ), 10, 2 );
|
||||
$this->add_filter( 'removable_query_args', array( $this, 'filter_removable_query_args' ) );
|
||||
|
||||
$this->add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
$this->add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
// @since 1.7.6.1 Add scripts to the customizer container hook.
|
||||
$this->add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
|
||||
$this->add_filter( 'wp_die_handler', array( $this, 'filter_wp_die_handler' ) );
|
||||
|
||||
/**
|
||||
* Compat with front and WP version lower than 4.2.0.
|
||||
* @since 1.6.4
|
||||
* @link https://developer.wordpress.org/reference/functions/wp_admin_canonical_url/
|
||||
*/
|
||||
if ( ! is_admin() || ! VAA_API::validate_wp_version( '4.2' ) ) {
|
||||
$this->add_action( 'wp_head', array( $this, 'remove_query_args' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a 'View Admin As: Reset view' link to the Meta sidebar widget if the admin bar is hidden.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @access public
|
||||
*/
|
||||
public function action_wp_meta() {
|
||||
if ( ! VAA_API::is_toolbar_showing() && $this->store->get_view() ) {
|
||||
$link = __( 'View Admin As', VIEW_ADMIN_AS_DOMAIN ) . ': ' . __( 'Reset view', VIEW_ADMIN_AS_DOMAIN );
|
||||
$url = VAA_API::get_reset_link();
|
||||
echo '<li id="vaa_reset_view"><a href="' . esc_url( $url ) . '">' . esc_html( $link ) . '</a></li>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show row meta on the plugin screen.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @see \WP_Plugins_List_Table::single_row()
|
||||
* @param array[] $links The existing links.
|
||||
* @param string $file The plugin file.
|
||||
* @return array
|
||||
*/
|
||||
public function action_plugin_row_meta( $links, $file ) {
|
||||
if ( VIEW_ADMIN_AS_BASENAME === $file ) {
|
||||
$icon_attr = array(
|
||||
'style' => array(
|
||||
'font-size: inherit;',
|
||||
'line-height: inherit;',
|
||||
'display: inline;',
|
||||
'vertical-align: text-top;',
|
||||
),
|
||||
);
|
||||
foreach ( $this->get_links() as $id => $link ) {
|
||||
$title = VAA_View_Admin_As_Form::do_icon( $link['icon'], $icon_attr ) . ' ' . esc_html( $link['title'] );
|
||||
$links[ $id ] = '<a href="' . esc_url( $link['url'] ) . '" target="_blank">' . $title . '</a>';
|
||||
}
|
||||
}
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin links.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @since 1.6.2 Added Slack channel link
|
||||
* @return array[]
|
||||
*/
|
||||
public function get_links() {
|
||||
if ( ! empty( $this->links ) ) {
|
||||
return $this->links;
|
||||
}
|
||||
|
||||
$this->links = array(
|
||||
'support' => array(
|
||||
'title' => __( 'Support', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Need support?', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'icon' => 'dashicons-sos',
|
||||
'url' => 'https://wordpress.org/support/plugin/view-admin-as/',
|
||||
),
|
||||
'slack' => array(
|
||||
'title' => __( 'Slack', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Quick help via Slack', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'icon' => 'dashicons-format-chat',
|
||||
'url' => 'https://keraweb.slack.com/messages/plugin-vaa/',
|
||||
),
|
||||
'review' => array(
|
||||
'title' => __( 'Review', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Give 5 stars on WordPress.org!', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'icon' => 'dashicons-star-filled',
|
||||
'url' => 'https://wordpress.org/support/plugin/view-admin-as/reviews/',
|
||||
),
|
||||
'translate' => array(
|
||||
'title' => __( 'Translate', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Help translating this plugin!', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'icon' => 'dashicons-translation',
|
||||
'url' => 'https://translate.wordpress.org/projects/wp-plugins/view-admin-as',
|
||||
),
|
||||
'issue' => array(
|
||||
'title' => __( 'Report issue', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Have ideas or a bug report?', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'icon' => 'dashicons-lightbulb',
|
||||
'url' => 'https://github.com/JoryHogeveen/view-admin-as/issues',
|
||||
),
|
||||
'docs' => array(
|
||||
'title' => __( 'Documentation', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Documentation', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'icon' => 'dashicons-book-alt',
|
||||
'url' => 'https://github.com/JoryHogeveen/view-admin-as/wiki',
|
||||
),
|
||||
'github' => array(
|
||||
'title' => __( 'GitHub', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Follow development on GitHub', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'icon' => 'dashicons-editor-code',
|
||||
'url' => 'https://github.com/JoryHogeveen/view-admin-as/tree/dev',
|
||||
),
|
||||
'donate' => array(
|
||||
'title' => __( 'Donate', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Buy me a coffee!', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'icon' => 'dashicons-smiley',
|
||||
'url' => 'https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=YGPLMLU7XQ9E8&lc=US&item_name=View%20Admin%20As&item_number=JWPP%2dVAA¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest',
|
||||
),
|
||||
'plugins' => array(
|
||||
'title' => __( 'Plugins', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Check out my other plugins', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'icon' => 'dashicons-admin-plugins',
|
||||
'url' => 'https://profiles.wordpress.org/keraweb/#content-plugins',
|
||||
),
|
||||
);
|
||||
|
||||
return $this->links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the list of query arguments which get removed from admin area URLs in WordPress.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @access public
|
||||
* @link https://core.trac.wordpress.org/ticket/23367
|
||||
*
|
||||
* @param array $args List of removable query arguments.
|
||||
* @return array Updated list of removable query arguments.
|
||||
*/
|
||||
public function filter_removable_query_args( $args ) {
|
||||
return array_merge( $args, array(
|
||||
'reset-view',
|
||||
'reset-all-views',
|
||||
'view_admin_as',
|
||||
'_vaa_nonce',
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove query arguments from the url.
|
||||
* Same logic as WP uses since v4.2.0.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @see wp_admin_canonical_url()
|
||||
* @return void
|
||||
*/
|
||||
public function remove_query_args() {
|
||||
$removable_query_args = $this->filter_removable_query_args( array() );
|
||||
|
||||
if ( empty( $removable_query_args ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$request_uri = $_SERVER['REQUEST_URI'];
|
||||
// @since 1.7.6 Some plugins overwrite `REQUEST_URI` and set it to `ORIG_REQUEST_URI`.
|
||||
if ( ! empty( $_SERVER['ORIG_REQUEST_URI'] ) ) {
|
||||
$request_uri = $_SERVER['ORIG_REQUEST_URI'];
|
||||
}
|
||||
|
||||
// Ensure we're using an absolute URL.
|
||||
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $request_uri );
|
||||
$filtered_url = remove_query_arg( $removable_query_args, $current_url );
|
||||
?>
|
||||
<link id="wp-vaa-canonical" rel="canonical" href="<?php echo esc_url( $filtered_url ); ?>" />
|
||||
<script>
|
||||
if ( window.history.replaceState ) {
|
||||
window.history.replaceState( null, null, document.getElementById( 'wp-vaa-canonical' ).href + window.location.hash );
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Add necessary scripts and styles.
|
||||
*
|
||||
* @since 0.1
|
||||
* @since 1.7 Moved to this class from main class.
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function enqueue_scripts() {
|
||||
// Only enqueue scripts if the admin bar is enabled otherwise they have no use.
|
||||
if ( ! VAA_API::is_toolbar_showing() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Use non-minified versions.
|
||||
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
|
||||
// Prevent browser cache.
|
||||
$version = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? time() : $this->store->get_version();
|
||||
|
||||
wp_enqueue_style(
|
||||
'vaa_view_admin_as_style',
|
||||
VIEW_ADMIN_AS_URL . 'assets/css/view-admin-as' . $suffix . '.css',
|
||||
array( 'admin-bar' ),
|
||||
$version
|
||||
);
|
||||
wp_enqueue_script(
|
||||
'vaa_view_admin_as_script',
|
||||
VIEW_ADMIN_AS_URL . 'assets/js/view-admin-as' . $suffix . '.js',
|
||||
array( 'jquery', 'admin-bar' ),
|
||||
$version,
|
||||
true // load in footer.
|
||||
);
|
||||
|
||||
/**
|
||||
* Add data to the VAA script localization.
|
||||
* @since 1.7
|
||||
* @param array $array Empty array (Will be overwritten with VAA core data so use unique keys).
|
||||
* @return array
|
||||
*/
|
||||
$script_localization = array_merge(
|
||||
(array) apply_filters( 'view_admin_as_script_localization', array() ),
|
||||
array(
|
||||
// Data.
|
||||
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
||||
'siteurl' => get_site_url(),
|
||||
'settings' => $this->store->get_settings(),
|
||||
'settings_user' => $this->store->get_userSettings(),
|
||||
'view' => $this->store->get_view(),
|
||||
'view_types' => $this->vaa->controller()->get_view_types(),
|
||||
// Other.
|
||||
'_loader_icon' => VIEW_ADMIN_AS_URL . 'assets/img/loader.gif',
|
||||
'_debug' => ( defined( 'WP_DEBUG' ) ) ? (bool) WP_DEBUG : false,
|
||||
'_vaa_nonce' => $this->store->get_nonce( true ),
|
||||
// i18n.
|
||||
'__no_users_found' => esc_html__( 'No users found.', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'__key_already_exists' => esc_html__( 'Key already exists.', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'__success' => esc_html__( 'Success', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'__confirm' => esc_html__( 'Are you sure?', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'__download' => esc_html__( 'Download', VIEW_ADMIN_AS_DOMAIN ),
|
||||
)
|
||||
);
|
||||
|
||||
wp_localize_script( 'vaa_view_admin_as_script', 'VAA_View_Admin_As', $script_localization );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add options to the access denied page when the user has selected a view and did something this view is not allowed.
|
||||
*
|
||||
* @since 1.3
|
||||
* @since 1.5.1 Check for SSL (Moved to VAA_API).
|
||||
* @since 1.6 More options and better description.
|
||||
* @since 1.7 Moved to this class from main class.
|
||||
* @since 1.8 Renamed from die_handler().
|
||||
* @access public
|
||||
* @see wp_die()
|
||||
*
|
||||
* @param callable $callback WP die callback.
|
||||
* @return callable $callback WP die callback.
|
||||
*/
|
||||
public function filter_wp_die_handler( $callback ) {
|
||||
|
||||
// Only do something if a view is selected.
|
||||
if ( ! $this->store->get_view() ) {
|
||||
return $callback;
|
||||
}
|
||||
|
||||
$options = array();
|
||||
|
||||
if ( is_network_admin() ) {
|
||||
$options[] = array(
|
||||
'text' => __( 'Go to network dashboard', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'url' => network_admin_url(),
|
||||
);
|
||||
} else {
|
||||
$options[] = array(
|
||||
'text' => __( 'Go to dashboard', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'url' => admin_url(),
|
||||
);
|
||||
$options[] = array(
|
||||
'text' => __( 'Go to homepage', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'url' => get_bloginfo( 'url' ),
|
||||
);
|
||||
}
|
||||
|
||||
// Reset url.
|
||||
$options[] = array(
|
||||
'text' => __( 'Reset the view', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'url' => VAA_API::get_reset_link(),
|
||||
);
|
||||
|
||||
/**
|
||||
* Add or remove options to the die/error handler pages.
|
||||
*
|
||||
* @since 1.6.2
|
||||
* @param array $options {
|
||||
* Required array of arrays.
|
||||
* @type array {
|
||||
* @type string $text The text to show.
|
||||
* @type string $url The link.
|
||||
* }
|
||||
* }
|
||||
* @return array[]
|
||||
*/
|
||||
$options = apply_filters( 'view_admin_as_error_page_options', $options );
|
||||
?>
|
||||
<div>
|
||||
<h3><?php esc_html_e( 'View Admin As', VIEW_ADMIN_AS_DOMAIN ); ?>:</h3>
|
||||
<?php esc_html_e( 'The view you have selected is not permitted to access this page, please choose one of the options below.', VIEW_ADMIN_AS_DOMAIN ); ?>
|
||||
<ul>
|
||||
<?php foreach ( $options as $option ) { ?>
|
||||
<li><a href="<?php echo $option['url']; ?>"><?php echo $option['text']; ?></a></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</div>
|
||||
<hr>
|
||||
<?php
|
||||
return $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Instance.
|
||||
*
|
||||
* Ensures only one instance of this class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @static
|
||||
* @param \VAA_View_Admin_As $caller The referrer class.
|
||||
* @return \VAA_View_Admin_As_UI $this
|
||||
*/
|
||||
public static function get_instance( $caller = null ) {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self( $caller );
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_UI.
|
||||
2
backend/wordpress/wp-content/plugins/view-admin-as/ui/index.php
Executable file
2
backend/wordpress/wp-content/plugins/view-admin-as/ui/index.php
Executable file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
//Nothing to see here
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* Add caps actions.
|
||||
*
|
||||
* @since 1.7
|
||||
* @version 1.7.4
|
||||
*
|
||||
* @var \VAA_View_Admin_As_Caps $this
|
||||
* @var \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @var string $root The current root item.
|
||||
* @var string $main_root The main VAA root item.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
if ( isset( $admin_bar ) && $admin_bar instanceof WP_Admin_Bar && isset( $root ) ) {
|
||||
|
||||
if ( ! isset( $main_root ) ) {
|
||||
$main_root = $root;
|
||||
}
|
||||
if ( ! isset( $parent ) ) {
|
||||
$parent = $root;
|
||||
}
|
||||
|
||||
// Text filter
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-filtercaps',
|
||||
'parent' => $parent,
|
||||
'title' => VAA_View_Admin_As_Form::do_input(
|
||||
array(
|
||||
'name' => $root . '-filtercaps',
|
||||
'placeholder' => esc_attr__( 'Filter', VIEW_ADMIN_AS_DOMAIN ),
|
||||
)
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'ab-vaa-input ab-vaa-filter filter-caps vaa-column-one-half vaa-column-first',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// Select filter
|
||||
$role_select_options = array(
|
||||
array(
|
||||
'value' => 'default',
|
||||
'label' => __( 'Default', VIEW_ADMIN_AS_DOMAIN ),
|
||||
),
|
||||
);
|
||||
// View filter
|
||||
if ( $this->store->get_view() ) {
|
||||
$data_caps = wp_json_encode( $this->store->get_selectedCaps() );
|
||||
$role_select_options[] = array(
|
||||
'compare' => 'vaa',
|
||||
'label' => '= ' . __( 'Current view', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'attr' => array(
|
||||
'data-caps' => $data_caps,
|
||||
),
|
||||
);
|
||||
$role_select_options[] = array(
|
||||
'compare' => 'reversed-vaa',
|
||||
'label' => '≠ ' . __( 'Current view', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'attr' => array(
|
||||
'data-caps' => $data_caps,
|
||||
'data-reverse' => '1',
|
||||
),
|
||||
);
|
||||
}
|
||||
// Role filters
|
||||
foreach ( $this->store->get_roles() as $role_key => $role ) {
|
||||
$data_caps = wp_json_encode( $role->capabilities );
|
||||
$role_select_options[] = array(
|
||||
'compare' => esc_attr( $role_key ),
|
||||
'label' => '= ' . $this->store->get_rolenames( $role_key ),
|
||||
'attr' => array(
|
||||
'data-caps' => $data_caps,
|
||||
),
|
||||
);
|
||||
$role_select_options[] = array(
|
||||
'compare' => 'reversed-' . esc_attr( $role_key ),
|
||||
'label' => '≠ ' . $this->store->get_rolenames( $role_key ),
|
||||
'attr' => array(
|
||||
'data-caps' => $data_caps,
|
||||
'data-reverse' => '1',
|
||||
),
|
||||
);
|
||||
}
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-selectrolecaps',
|
||||
'parent' => $parent,
|
||||
'title' => VAA_View_Admin_As_Form::do_select(
|
||||
array(
|
||||
'name' => $root . '-selectrolecaps',
|
||||
'values' => $role_select_options,
|
||||
)
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'ab-vaa-select select-role-caps vaa-column-one-half vaa-column-last',
|
||||
'html' => '',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// Select/deselect
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-bulkselectcaps',
|
||||
'parent' => $parent,
|
||||
'title' => VAA_View_Admin_As_Form::do_button(
|
||||
array(
|
||||
'name' => 'select-all-caps',
|
||||
'label' => __( 'Select', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'classes' => 'button-secondary',
|
||||
)
|
||||
) . ' ' . VAA_View_Admin_As_Form::do_button(
|
||||
array(
|
||||
'name' => 'deselect-all-caps',
|
||||
'label' => __( 'Deselect', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'classes' => 'button-secondary',
|
||||
)
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'ab-vaa-input vaa-button-container vaa-clear-float',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
} else {
|
||||
_doing_it_wrong( __FILE__, esc_html__( 'No toolbar resources found.', VIEW_ADMIN_AS_DOMAIN ), '1.7' );
|
||||
} // End if().
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* Add caps items.
|
||||
*
|
||||
* @since 1.7
|
||||
* @version 1.8
|
||||
*
|
||||
* @var \VAA_View_Admin_As_Caps $this
|
||||
* @var \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @var string $root The current root item.
|
||||
* @var string $main_root The main VAA root item.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
if ( isset( $admin_bar ) && $admin_bar instanceof WP_Admin_Bar && isset( $root ) ) {
|
||||
|
||||
if ( ! isset( $main_root ) ) {
|
||||
$main_root = $root;
|
||||
}
|
||||
if ( ! isset( $parent ) ) {
|
||||
$parent = $root;
|
||||
}
|
||||
|
||||
$caps_items = '';
|
||||
foreach ( $this->store->get_caps() as $cap => $granted ) {
|
||||
$class = 'vaa-cap-item';
|
||||
$checked = (bool) $granted;
|
||||
// check if we've selected a capability view and we've changed some capabilities.
|
||||
$selected_caps = $this->store->get_view( $this->type );
|
||||
if ( isset( $selected_caps[ $cap ] ) ) {
|
||||
$checked = (bool) $selected_caps[ $cap ];
|
||||
}
|
||||
// Check for this capability in any view set.
|
||||
if ( $this->vaa->view()->current_view_can( $cap ) ) {
|
||||
$class .= ' current';
|
||||
}
|
||||
// The list of capabilities.
|
||||
$caps_items .=
|
||||
'<div class="ab-item ' . $class . '">'
|
||||
. VAA_View_Admin_As_Form::do_checkbox(
|
||||
array(
|
||||
'name' => 'vaa_cap_' . esc_attr( $cap ),
|
||||
'value' => $checked,
|
||||
'compare' => true,
|
||||
'checkbox_value' => esc_attr( $cap ),
|
||||
'label' => $cap,
|
||||
)
|
||||
)
|
||||
. '</div>';
|
||||
}
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-select-options',
|
||||
'parent' => $parent,
|
||||
'title' => $caps_items,
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'ab-vaa-multipleselect vaa-auto-max-height',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
} else {
|
||||
_doing_it_wrong( __FILE__, esc_html__( 'No toolbar resources found.', VIEW_ADMIN_AS_DOMAIN ), '1.7' );
|
||||
} // End if().
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* Add role items.
|
||||
*
|
||||
* @since 1.8
|
||||
* @version 1.8
|
||||
*
|
||||
* @var \VAA_View_Admin_As_Languages $this
|
||||
* @var \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @var string $root The current root item.
|
||||
* @var string $main_root The main VAA root item.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
if ( isset( $admin_bar ) && $admin_bar instanceof WP_Admin_Bar && isset( $root ) ) {
|
||||
|
||||
if ( ! isset( $main_root ) ) {
|
||||
$main_root = $root;
|
||||
}
|
||||
|
||||
$parent = $root . '-languages';
|
||||
|
||||
foreach ( $this->store->get_languages() as $locale => $language ) {
|
||||
$href = VAA_API::get_vaa_action_link( array( $this->type => $locale ), $this->store->get_nonce( true ) );
|
||||
$class = 'vaa-' . $this->type . '-item';
|
||||
$title = $this->get_view_title( $locale );
|
||||
|
||||
$view_title = ( $locale !== $title ) ? '<code>' . $locale . '</code> | ' . $language : $locale;
|
||||
|
||||
$view_title = VAA_View_Admin_As_Form::do_view_title( $view_title, $this, $locale );
|
||||
|
||||
// Check if this role is the current view.
|
||||
if ( VAA_API::is_current_view( $locale, $this->type ) ) {
|
||||
$class .= ' current';
|
||||
if ( 1 === count( $this->store->get_view() ) ) {
|
||||
$href = false;
|
||||
}
|
||||
}
|
||||
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-' . $this->type . '-' . $locale,
|
||||
'parent' => $parent,
|
||||
'title' => $view_title,
|
||||
'href' => $href,
|
||||
'meta' => array(
|
||||
// Translators: %s stands for the translated role name.
|
||||
'title' => sprintf( __( 'View as %s', VIEW_ADMIN_AS_DOMAIN ), $title ),
|
||||
'class' => $class,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
} // End foreach().
|
||||
|
||||
} else {
|
||||
_doing_it_wrong( __FILE__, esc_html__( 'No toolbar resources found.', VIEW_ADMIN_AS_DOMAIN ), '1.7' );
|
||||
} // End if().
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* Add role items.
|
||||
*
|
||||
* @since 1.7
|
||||
* @version 1.8
|
||||
*
|
||||
* @var \VAA_View_Admin_As_Roles $this
|
||||
* @var \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @var string $root The current root item.
|
||||
* @var string $main_root The main VAA root item.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
if ( isset( $admin_bar ) && $admin_bar instanceof WP_Admin_Bar && isset( $root ) ) {
|
||||
|
||||
if ( ! isset( $main_root ) ) {
|
||||
$main_root = $root;
|
||||
}
|
||||
if ( ! isset( $parent ) ) {
|
||||
$parent = $root;
|
||||
}
|
||||
|
||||
foreach ( $this->store->get_roles() as $role_key => $role ) {
|
||||
$href = VAA_API::get_vaa_action_link( array( $this->type => $role_key ), $this->store->get_nonce( true ) );
|
||||
$class = 'vaa-' . $this->type . '-item';
|
||||
$title = $this->get_view_title( $role );
|
||||
|
||||
$view_title = VAA_View_Admin_As_Form::do_view_title( $title, $this, $role_key );
|
||||
|
||||
/**
|
||||
* Check if the users need to be grouped under their roles.
|
||||
* @var \VAA_View_Admin_As_Users $user_view_type
|
||||
*/
|
||||
$user_view_type = view_admin_as()->get_view_types( 'user' );
|
||||
if ( $user_view_type instanceof VAA_View_Admin_As_Users && $user_view_type->group_user_roles() ) {
|
||||
// Used to align items properly when some roles don't have users.
|
||||
$class .= ' vaa-menupop';
|
||||
// Check if the current view is a user with this role.
|
||||
if ( $this->store->get_view( 'user' ) &&
|
||||
in_array( $role_key, $this->store->get_selectedUser()->roles, true )
|
||||
) {
|
||||
$class .= ' current-parent';
|
||||
}
|
||||
// If there are users with this role, add a counter.
|
||||
$user_count = 0;
|
||||
foreach ( $this->store->get_users() as $user ) {
|
||||
if ( in_array( $role_key, $user->roles, true ) ) {
|
||||
$user_count ++;
|
||||
}
|
||||
}
|
||||
if ( 0 < $user_count ) {
|
||||
$view_title = $view_title . ' <span class="user-count ab-italic">(' . $user_count . ')</span>';
|
||||
}
|
||||
}
|
||||
|
||||
// Check if this role is the current view.
|
||||
if ( VAA_API::is_current_view( $role_key, $this->type ) ) {
|
||||
$class .= ' current';
|
||||
if ( 1 === count( $this->store->get_view() ) ) {
|
||||
$href = false;
|
||||
}
|
||||
}
|
||||
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-' . $this->type . '-' . $role_key,
|
||||
'parent' => $parent,
|
||||
'title' => $view_title,
|
||||
'href' => $href,
|
||||
'meta' => array(
|
||||
// Translators: %s stands for the translated role name.
|
||||
'title' => sprintf( __( 'View as %s', VIEW_ADMIN_AS_DOMAIN ), $title ),
|
||||
'class' => $class,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
} // End foreach().
|
||||
|
||||
} else {
|
||||
_doing_it_wrong( __FILE__, esc_html__( 'No toolbar resources found.', VIEW_ADMIN_AS_DOMAIN ), '1.7' );
|
||||
} // End if().
|
||||
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
/**
|
||||
* Add user setting items.
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @version 1.8
|
||||
*
|
||||
* @var \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @var string $root The current root item.
|
||||
* @var string $main_root The main VAA root item.
|
||||
*
|
||||
* Settings order:
|
||||
* - admin_menu_location
|
||||
* - view_mode
|
||||
* - disable_super_admin
|
||||
* - hide_front
|
||||
* - freeze_locale
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
if ( isset( $this ) &&
|
||||
isset( $this->store ) &&
|
||||
isset( $admin_bar ) && $admin_bar instanceof WP_Admin_Bar &&
|
||||
isset( $root )
|
||||
) {
|
||||
|
||||
/**
|
||||
* admin_menu_location setting.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-admin-menu-location',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_select(
|
||||
array(
|
||||
'name' => $root . '-admin-menu-location',
|
||||
'value' => $this->store->get_userSettings( 'admin_menu_location' ),
|
||||
'label' => __( 'Location', VIEW_ADMIN_AS_DOMAIN ) . ': ',
|
||||
'description' => __( 'Change the location of this menu node', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'help' => true,
|
||||
'values' => array(
|
||||
array(
|
||||
'compare' => 'top-secondary',
|
||||
'label' => __( 'Default', VIEW_ADMIN_AS_DOMAIN ),
|
||||
),
|
||||
array(
|
||||
'compare' => 'my-account',
|
||||
'label' => __( 'My account', VIEW_ADMIN_AS_DOMAIN ),
|
||||
),
|
||||
),
|
||||
'auto_js' => array(
|
||||
'setting' => 'user_setting',
|
||||
'key' => 'admin_menu_location',
|
||||
'refresh' => true,
|
||||
),
|
||||
'auto_showhide' => true,
|
||||
)
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'auto-height',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* view_mode setting.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-view-mode',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_radio(
|
||||
array(
|
||||
'name' => $root . '-view-mode',
|
||||
'value' => $this->store->get_userSettings( 'view_mode' ),
|
||||
'values' => array(
|
||||
array(
|
||||
'compare' => 'browse',
|
||||
'label' => __( 'Browse mode', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Store view and use WordPress with this view', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'help' => true,
|
||||
),
|
||||
array(
|
||||
'compare' => 'single',
|
||||
'label' => __( 'Single switch mode', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Choose view on every pageload. This setting doesn\'t store views', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'help' => true,
|
||||
),
|
||||
),
|
||||
'auto_js' => array(
|
||||
'setting' => 'user_setting',
|
||||
'key' => 'view_mode',
|
||||
'refresh' => false,
|
||||
),
|
||||
'auto_showhide' => true,
|
||||
)
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'auto-height',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Disable super admin checks while switched.
|
||||
*
|
||||
* @since 1.7.3
|
||||
* @since 1.8 Don't use VAA_API since users that are super admins but don't have full access could
|
||||
* still want to use this setting.
|
||||
* Also check if the installation is a network.
|
||||
*/
|
||||
if ( is_multisite() && is_super_admin( view_admin_as()->store()->get_curUser()->ID ) ) {
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-disable-super-admin',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_checkbox(
|
||||
array(
|
||||
'name' => $root . '-disable-super-admin',
|
||||
'value' => $this->store->get_userSettings( 'disable_super_admin' ),
|
||||
'compare' => true,
|
||||
'label' => __( 'Disable super admin', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Disable super admin status while switched to another view', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'help' => true,
|
||||
'auto_js' => array(
|
||||
'setting' => 'user_setting',
|
||||
'key' => 'disable_super_admin',
|
||||
'refresh' => ( $this->store->get_view() ) ? true : false,
|
||||
),
|
||||
'auto_showhide' => true,
|
||||
)
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'auto-height',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* hide_front setting.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-hide-front',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_checkbox(
|
||||
array(
|
||||
'name' => $root . '-hide-front',
|
||||
'value' => $this->store->get_userSettings( 'hide_front' ),
|
||||
'compare' => true,
|
||||
'label' => __( 'Hide on frontend', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Hide on frontend when no view is selected and the admin bar is not shown', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'help' => true,
|
||||
'auto_js' => array(
|
||||
'setting' => 'user_setting',
|
||||
'key' => 'hide_front',
|
||||
'refresh' => false,
|
||||
),
|
||||
'auto_showhide' => true,
|
||||
)
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'auto-height',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* hide_customizer setting.
|
||||
*
|
||||
* @since 1.7.6
|
||||
*/
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-hide-customizer',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_checkbox(
|
||||
array(
|
||||
'name' => $root . '-hide-customizer',
|
||||
'value' => $this->store->get_userSettings( 'hide_customizer' ),
|
||||
'compare' => true,
|
||||
'label' => __( 'Hide on customizer', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Hide on customizer when no view is selected', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'help' => true,
|
||||
'auto_js' => array(
|
||||
'setting' => 'user_setting',
|
||||
'key' => 'hide_customizer',
|
||||
'refresh' => VAA_API::is_customizer_admin(),
|
||||
),
|
||||
'auto_showhide' => true,
|
||||
)
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'auto-height',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* freeze_locale setting.
|
||||
* Force own locale on view, WP 4.7+ only.
|
||||
*
|
||||
* @see https://github.com/JoryHogeveen/view-admin-as/issues/21
|
||||
* @since 1.6.1
|
||||
*/
|
||||
if ( VAA_API::validate_wp_version( '4.7' ) ) {
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-freeze-locale',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_checkbox(
|
||||
array(
|
||||
'name' => $root . '-freeze-locale',
|
||||
'value' => $this->store->get_userSettings( 'freeze_locale' ),
|
||||
'compare' => true,
|
||||
'label' => __( 'Freeze locale', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Force your own locale setting to the current view', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'help' => true,
|
||||
'auto_js' => array(
|
||||
'setting' => 'user_setting',
|
||||
'key' => 'freeze_locale',
|
||||
'refresh' => ( $this->store->get_view( 'user' ) ) ? true : false,
|
||||
),
|
||||
'auto_showhide' => true,
|
||||
)
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'auto-height',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
} // End if().
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Add user actions.
|
||||
*
|
||||
* @since 1.8
|
||||
* @version 1.8
|
||||
*
|
||||
* @var \VAA_View_Admin_As_Users $this
|
||||
* @var \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @var string $root The current root item.
|
||||
* @var string $main_root The main VAA root item.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
if ( isset( $admin_bar ) && $admin_bar instanceof WP_Admin_Bar && isset( $root ) ) {
|
||||
|
||||
if ( ! isset( $main_root ) ) {
|
||||
$main_root = $root;
|
||||
}
|
||||
if ( ! isset( $parent ) ) {
|
||||
$parent = $root;
|
||||
}
|
||||
|
||||
if ( ! isset( $title_submenu ) ) {
|
||||
$title_submenu = false;
|
||||
}
|
||||
|
||||
if ( $title_submenu || $this->ajax_search || $this->group_user_roles() ) {
|
||||
|
||||
$title = '';
|
||||
if ( $this->group_user_roles() ) {
|
||||
$title = VAA_View_Admin_As_Form::do_description( __( 'Users are grouped under their roles', VIEW_ADMIN_AS_DOMAIN ) );
|
||||
}
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-searchusers',
|
||||
'parent' => $root,
|
||||
'title' => $title . VAA_View_Admin_As_Form::do_input( array(
|
||||
'name' => $root . '-searchusers',
|
||||
'placeholder' => __( 'Search', VIEW_ADMIN_AS_DOMAIN ),
|
||||
) ),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'ab-vaa-search search-users' . ( ( $this->ajax_search ) ? ' search-ajax' : '' ),
|
||||
'html' => '<ul id="vaa-searchuser-results" class="ab-sub-secondary vaa-auto-max-height ab-submenu ab-vaa-results"></ul>',
|
||||
),
|
||||
) );
|
||||
}
|
||||
|
||||
} else {
|
||||
_doing_it_wrong( __FILE__, esc_html__( 'No toolbar resources found.', VIEW_ADMIN_AS_DOMAIN ), '1.7' );
|
||||
} // End if().
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* Add user items.
|
||||
*
|
||||
* @since 1.7
|
||||
* @version 1.8
|
||||
*
|
||||
* @var \VAA_View_Admin_As_Users $this
|
||||
* @var \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @var string $root The current root item.
|
||||
* @var string $main_root The main VAA root item.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
if ( isset( $admin_bar ) && $admin_bar instanceof WP_Admin_Bar && isset( $root ) ) {
|
||||
|
||||
if ( ! isset( $main_root ) ) {
|
||||
$main_root = $root;
|
||||
}
|
||||
if ( ! isset( $parent ) ) {
|
||||
$parent = $root;
|
||||
}
|
||||
|
||||
if ( ! isset( $title_submenu ) ) {
|
||||
$title_submenu = false;
|
||||
}
|
||||
|
||||
foreach ( $this->store->get_users() as $user ) {
|
||||
// Reset parent for each loop due to groupUserRoles.
|
||||
$item_parent = $parent;
|
||||
$href = VAA_API::get_vaa_action_link( array( $this->type => $user->ID ), $this->store->get_nonce( true ) );
|
||||
$class = 'vaa-' . $this->type . '-item';
|
||||
$title = $this->get_view_title( $user );
|
||||
|
||||
$view_title = VAA_View_Admin_As_Form::do_view_title( $title, $this, $user->ID );
|
||||
|
||||
/**
|
||||
* Add the user roles to the user title?
|
||||
* Only available if users are not grouped under their roles.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param bool $true True by default.
|
||||
* @param \WP_User $user The user object.
|
||||
* @return bool
|
||||
*/
|
||||
if ( ! $this->group_user_roles() && apply_filters( 'vaa_admin_bar_view_title_' . $this->type . '_show_roles', true, $user ) ) {
|
||||
// Users displayed as normal.
|
||||
$user_roles = array();
|
||||
// Add the roles of this user in the name.
|
||||
foreach ( $user->roles as $role ) {
|
||||
$user_roles[] = $this->store->get_rolenames( $role );
|
||||
}
|
||||
$view_title = $view_title . ' <span class="user-role ab-italic">(' . implode( ', ', $user_roles ) . ')</span>';
|
||||
}
|
||||
|
||||
// Check if this user is the current view.
|
||||
if ( VAA_API::is_current_view( $user->ID, $this->type ) ) {
|
||||
$class .= ' current';
|
||||
if ( 1 === count( $this->store->get_view() ) ) {
|
||||
$href = false;
|
||||
}
|
||||
}
|
||||
|
||||
$user_node = array(
|
||||
'id' => $root . '-' . $this->type . '-' . $user->ID,
|
||||
'parent' => $item_parent,
|
||||
'title' => $view_title,
|
||||
'href' => $href,
|
||||
'meta' => array(
|
||||
// Translators: %s stands for the user display name.
|
||||
'title' => sprintf( __( 'View as %s', VIEW_ADMIN_AS_DOMAIN ), $title ),
|
||||
'class' => $class,
|
||||
),
|
||||
);
|
||||
|
||||
if ( $this->group_user_roles() ) {
|
||||
// Users grouped under roles.
|
||||
foreach ( $user->roles as $role ) {
|
||||
$user_role_node = $user_node;
|
||||
$item_parent = $main_root . '-roles-role-' . $role;
|
||||
$group = $item_parent . '-users';
|
||||
if ( ! $admin_bar->get_node( $group ) ) {
|
||||
$admin_bar->add_group( array(
|
||||
'id' => $group,
|
||||
'parent' => $item_parent,
|
||||
'meta' => array(
|
||||
'class' => 'vaa-auto-max-height',
|
||||
),
|
||||
) );
|
||||
}
|
||||
$user_role_node['id'] .= '-' . $role;
|
||||
$user_role_node['parent'] = $group;
|
||||
$admin_bar->add_node( $user_role_node );
|
||||
}
|
||||
} else {
|
||||
$admin_bar->add_node( $user_node );
|
||||
}
|
||||
|
||||
} // End foreach().
|
||||
|
||||
} else {
|
||||
_doing_it_wrong( __FILE__, esc_html__( 'No toolbar resources found.', VIEW_ADMIN_AS_DOMAIN ), '1.7' );
|
||||
} // End if().
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
//Nothing to see here
|
||||
72
backend/wordpress/wp-content/plugins/view-admin-as/uninstall.php
Executable file
72
backend/wordpress/wp-content/plugins/view-admin-as/uninstall.php
Executable file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Uninstaller
|
||||
*
|
||||
* Remove plugin data from the database
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package view-admin-as
|
||||
* @since 1.3.4
|
||||
* @version 1.7
|
||||
*/
|
||||
|
||||
//if uninstall not called from WordPress exit
|
||||
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
vaa_uninstall();
|
||||
|
||||
if ( is_multisite() ) {
|
||||
global $wp_version;
|
||||
if ( version_compare( $wp_version, '4.5.999', '<' ) ) {
|
||||
// @codingStandardsIgnoreLine >> Backwards compat (Sadly does not work for large networks -> return false).
|
||||
$blogs = wp_get_sites();
|
||||
} else {
|
||||
$blogs = get_sites();
|
||||
}
|
||||
if ( $blogs ) {
|
||||
foreach ( $blogs as $blog ) {
|
||||
$blog = (array) $blog;
|
||||
vaa_uninstall( intval( $blog['blog_id'] ) );
|
||||
}
|
||||
vaa_uninstall( 'site' );
|
||||
}
|
||||
}
|
||||
function vaa_uninstall( $blog_id = false ) {
|
||||
|
||||
// Delete all View Admin As options
|
||||
$option_keys = array( 'vaa_view_admin_as', 'vaa_role_defaults', 'vaa_role_manager' );
|
||||
|
||||
if ( $blog_id ) {
|
||||
|
||||
if ( 'site' === $blog_id ) {
|
||||
foreach ( $option_keys as $option_key ) {
|
||||
delete_site_option( $option_key );
|
||||
}
|
||||
} else {
|
||||
foreach ( $option_keys as $option_key ) {
|
||||
delete_blog_option( $blog_id, $option_key );
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
foreach ( $option_keys as $option_key ) {
|
||||
delete_option( $option_key );
|
||||
}
|
||||
|
||||
// Delete all View Admin As user metadata
|
||||
$user_meta_keys = array( 'vaa-view-admin-as' );
|
||||
// Older (not used anymore) keys
|
||||
$user_meta_keys[] = 'view-admin-as';
|
||||
|
||||
global $wpdb;
|
||||
foreach ( $user_meta_keys as $user_meta_key ) {
|
||||
$wpdb->delete(
|
||||
$wpdb->usermeta,
|
||||
array( 'meta_key' => $user_meta_key )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
126
backend/wordpress/wp-content/plugins/view-admin-as/view-admin-as.php
Executable file
126
backend/wordpress/wp-content/plugins/view-admin-as/view-admin-as.php
Executable file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 0.1
|
||||
* @version 1.8
|
||||
* @licence GPL-2.0+
|
||||
* @link https://github.com/JoryHogeveen/view-admin-as
|
||||
*
|
||||
* @wordpress-plugin
|
||||
* Plugin Name: View Admin As
|
||||
* Plugin URI: https://wordpress.org/plugins/view-admin-as/
|
||||
* Description: View the WordPress admin as a different role or visitor, switch between users, temporarily change your capabilities, set default screen settings for roles.
|
||||
* Version: 1.8
|
||||
* Author: Jory Hogeveen
|
||||
* Author URI: https://www.keraweb.nl
|
||||
* Text Domain: view-admin-as
|
||||
* Domain Path: /languages/
|
||||
* License: GPL-2.0+
|
||||
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
* GitHub Plugin URI: https://github.com/JoryHogeveen/view-admin-as
|
||||
*
|
||||
* @copyright 2015-2017 Jory Hogeveen
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* ( at your option ) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'VAA_View_Admin_As' ) && ! function_exists( 'view_admin_as' ) ) {
|
||||
|
||||
define( 'VIEW_ADMIN_AS_VERSION', '1.8' );
|
||||
define( 'VIEW_ADMIN_AS_DB_VERSION', '1.8' );
|
||||
define( 'VIEW_ADMIN_AS_DOMAIN', 'view-admin-as' );
|
||||
define( 'VIEW_ADMIN_AS_FILE', __FILE__ );
|
||||
define( 'VIEW_ADMIN_AS_BASENAME', plugin_basename( VIEW_ADMIN_AS_FILE ) );
|
||||
|
||||
/**
|
||||
* Added must-use (mu-plugins) compatibility.
|
||||
*
|
||||
* @since 1.7.3
|
||||
* Move this file into the root of your mu-plugins directory, not in the `view-admin-as` subdirectory.
|
||||
* This is a limitation of WordPress and probably won't change soon.
|
||||
* @example
|
||||
* Plugins dir: /wp-content/mu-plugins/view-admin-as/...
|
||||
* This file dir: /wp-content/mu-plugins/view-admin-as.php
|
||||
*
|
||||
* @since 1.7.4 Compatibility with mu-plugin loader scripts.
|
||||
* @example https://gist.github.com/JoryHogeveen/b91d144c9916df430c821fcd834a9667
|
||||
*/
|
||||
if ( 0 === strpos( VIEW_ADMIN_AS_FILE, WPMU_PLUGIN_DIR ) ) {
|
||||
define( 'VIEW_ADMIN_AS_MU', true );
|
||||
if ( basename( VIEW_ADMIN_AS_FILE ) === VIEW_ADMIN_AS_BASENAME ) {
|
||||
// This file is in the mu root folder.
|
||||
define( 'VIEW_ADMIN_AS_DIR', plugin_dir_path( VIEW_ADMIN_AS_FILE ) . trailingslashit( 'view-admin-as' ) );
|
||||
define( 'VIEW_ADMIN_AS_URL', plugin_dir_url( VIEW_ADMIN_AS_FILE ) . trailingslashit( 'view-admin-as' ) );
|
||||
} else {
|
||||
// This file is in the VAA folder, probably loaded using a mu-plugin loader.
|
||||
define( 'VIEW_ADMIN_AS_DIR', plugin_dir_path( VIEW_ADMIN_AS_FILE ) );
|
||||
define( 'VIEW_ADMIN_AS_URL', plugin_dir_url( VIEW_ADMIN_AS_FILE ) );
|
||||
}
|
||||
} else {
|
||||
define( 'VIEW_ADMIN_AS_MU', false );
|
||||
define( 'VIEW_ADMIN_AS_DIR', plugin_dir_path( VIEW_ADMIN_AS_FILE ) );
|
||||
define( 'VIEW_ADMIN_AS_URL', plugin_dir_url( VIEW_ADMIN_AS_FILE ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP 5.5+ function.
|
||||
* @see boolval()
|
||||
* @todo Move to a separate file?
|
||||
*/
|
||||
if ( ! function_exists( 'boolval' ) ) {
|
||||
function boolval( $val ) {
|
||||
return (bool) $val;
|
||||
}
|
||||
}
|
||||
|
||||
// Include main init class file.
|
||||
require_once VIEW_ADMIN_AS_DIR . 'includes/class-vaa.php';
|
||||
|
||||
/**
|
||||
* Main instance of View Admin As.
|
||||
* Returns the main instance of VAA_View_Admin_As to prevent the need to use globals.
|
||||
*
|
||||
* @since 1.4.1
|
||||
* @since 1.6.4 Changed to lowercase (style fix).
|
||||
* @return \VAA_View_Admin_As
|
||||
*/
|
||||
function view_admin_as() {
|
||||
return VAA_View_Admin_As::get_instance();
|
||||
}
|
||||
|
||||
// Instantiate View Admin As.
|
||||
view_admin_as();
|
||||
|
||||
// end if class_exists.
|
||||
} else {
|
||||
|
||||
// @since 1.5.1 added notice on class name conflict.
|
||||
add_action( 'admin_notices', 'view_admin_as_conflict_admin_notice' );
|
||||
function view_admin_as_conflict_admin_notice() {
|
||||
echo '<div class="notice-error notice is-dismissible"><p><strong>' . esc_html__( 'View Admin As', 'view-admin-as' ) . ':</strong> '
|
||||
. esc_html__( 'Plugin not activated because of a conflict with an other plugin or theme', 'view-admin-as' )
|
||||
// Translators: %s stands for the class name.
|
||||
. ' <code>(' . sprintf( esc_html__( 'Class %s already exists', 'view-admin-as' ), 'VAA_View_Admin_As' ) . ')</code></p></div>';
|
||||
}
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
deactivate_plugins( plugin_basename( __FILE__ ) );
|
||||
|
||||
} // End if().
|
||||
Reference in New Issue
Block a user