diff --git a/assets/css/view-admin-as.css b/assets/css/view-admin-as.css index e9f5712f..151d6ab9 100644 --- a/assets/css/view-admin-as.css +++ b/assets/css/view-admin-as.css @@ -4,7 +4,7 @@ * * @author Jory Hogeveen * @package view-admin-as - * @version 1.6 + * @version 1.6.1 */ #vaa-overlay {position: fixed; top: 0; left: 0; height: 100%; width: 100%; background: rgba(255,255,255,0.85); display: none; z-index: 999999999;} @@ -19,130 +19,130 @@ #vaa-overlay.error {background-color: rgba(220, 50, 50, 0.85);} #vaa-overlay.success {background-color: rgba(70, 180, 80, 0.85);} */ - -#wpadminbar #wp-admin-bar-view-as ul li, -#wpadminbar #wp-admin-bar-view-as .ab-item {clear: both;} - -#wpadminbar #wp-admin-bar-view-as > .ab-item > .ab-label {float: left;} /* IE fix */ -#wpadminbar #wp-admin-bar-view-as > .ab-item > .ab-icon {float: right !important; margin-right: 0; margin-left: 6px; top: 2px;} -#wpadminbar #wp-admin-bar-view-as .vaa-has-icon > .ab-item > .ab-icon {float: none; font-size: 16px; vertical-align: text-bottom; font-weight: normal; padding: 0;} -#wpadminbar #wp-admin-bar-view-as .vaa-has-icon > .ab-item::before {display: none;} -#wpadminbar #wp-admin-bar-view-as .vaa-has-icon.menupop > .ab-item {padding-left: 10px; padding-right: 10px;} -#wpadminbar #wp-admin-bar-view-as .vaa-has-icon.ab-vaa-title > .ab-item > .ab-icon {font-size: 18px; margin: 0 5px 0 -1px;} - #wpadminbar .vaa-update.vaa-error {display: inline-block; color: #dc3232; background: #fff; padding: 0 10px;} #wpadminbar .vaa-update.vaa-error .ab-icon:before {color: #dc3232;} #wpadminbar .vaa-update.vaa-success {display: inline-block; color: #46b450; background: #fff; padding: 0 10px;} #wpadminbar .vaa-update.vaa-success .ab-icon:before {color: #46b450;} -#wpadminbar #wp-admin-bar-view-as.menupop ul.ab-sub-secondary {position: static;} -#wpadminbar #wp-admin-bar-view-as.menupop .menupop > .ab-item:before {top: 1px;} +#wpadminbar #wp-admin-bar-vaa ul li, +#wpadminbar #wp-admin-bar-vaa .ab-item {clear: both;} -#wpadminbar #wp-admin-bar-view-as > div > ul.ab-sub-secondary + ul.ab-sub-secondary {margin-top: 3px;} +#wpadminbar #wp-admin-bar-vaa > .ab-item > .ab-label {float: left;} /* IE fix */ +#wpadminbar #wp-admin-bar-vaa > .ab-item > .ab-icon {float: right !important; margin-right: 0; margin-left: 6px; top: 2px;} +#wpadminbar #wp-admin-bar-vaa .vaa-has-icon > .ab-item > .ab-icon {float: none; font-size: 16px; vertical-align: text-bottom; font-weight: normal; 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; margin: 0 5px 0 -1px;} -#wpadminbar #wp-admin-bar-view-as .auto-height > .ab-item {height: auto;} -#wpadminbar #wp-admin-bar-view-as .ab-item .description {height: auto; line-height: 1.2; font-size: 0.9em; font-style: italic; margin-bottom: 7px; white-space: normal;} +#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 #wp-admin-bar-view-as.menupop .ab-vaa-title .ab-item {font-weight: bold; line-height: 26px; font-size: 1.1em; text-transform: uppercase;} -#wpadminbar #wp-admin-bar-view-as .current > .ab-item, -#wpadminbar #wp-admin-bar-view-as .current-parent > .ab-item {font-weight: bold;} -#wpadminbar #wp-admin-bar-view-as .current > .ab-item::after {content: '\f177'; font-family: 'dashicons'; margin: 0 5px; font-size: 17px; vertical-align: middle; font-weight: normal;} +#wpadminbar #wp-admin-bar-vaa > div > ul.ab-sub-secondary + ul.ab-sub-secondary {margin-top: 3px;} -#wpadminbar .ab-top-secondary .menupop .vaa-menupop > .ab-item {padding-left: 2em; padding-right: 1em;} +#wpadminbar #wp-admin-bar-vaa .auto-height > .ab-item {height: auto;} +#wpadminbar #wp-admin-bar-vaa .ab-item .description {height: auto; line-height: 1.2; font-size: 0.9em; font-style: italic; margin-bottom: 7px; white-space: normal;} + +#wpadminbar #wp-admin-bar-vaa.menupop .ab-vaa-title .ab-item {font-weight: bold; line-height: 26px; font-size: 1.1em; text-transform: uppercase;} +#wpadminbar #wp-admin-bar-vaa .current > .ab-item, +#wpadminbar #wp-admin-bar-vaa .current-parent > .ab-item {font-weight: bold;} +#wpadminbar #wp-admin-bar-vaa .current > .ab-item::after {content: '\f177'; font-family: 'dashicons'; margin: 0 5px; font-size: 17px; vertical-align: middle; font-weight: normal;} -#wpadminbar #wp-admin-bar-view-as .ab-bold > .ab-item, -#wpadminbar #wp-admin-bar-view-as .ab-bold > .ab-item * {font-weight: bold !important;} -#wpadminbar #wp-admin-bar-view-as .ab-italic > .ab-item, -#wpadminbar #wp-admin-bar-view-as .ab-italic > .ab-item * {font-style: italic !important;} - -#wpadminbar #wp-admin-bar-view-as .vaa-sub-transparent > * {opacity: 0.5; transition: opacity 0.2s;} -#wpadminbar #wp-admin-bar-view-as .vaa-sub-transparent:hover > * {opacity: 1;} - -#wpadminbar #wp-admin-bar-view-as .ab-item .user-role, -#wpadminbar #wp-admin-bar-view-as .ab-item .user-count {font-style: italic; line-height: 26px; font-weight: normal;} - -#wpadminbar #wp-admin-bar-view-as .ab-vaa-multipleselect .ab-item, -#wpadminbar #wp-admin-bar-view-as .ab-vaa-search .ab-item, -#wpadminbar #wp-admin-bar-view-as .ab-vaa-filter .ab-item, -#wpadminbar #wp-admin-bar-view-as .ab-vaa-select .ab-item {height: auto; clear: both;} -#wpadminbar #wp-admin-bar-view-as .ab-vaa-search .ab-item input, -#wpadminbar #wp-admin-bar-view-as .ab-vaa-filter .ab-item input, -#wpadminbar #wp-admin-bar-view-as .ab-vaa-select .ab-item select {display: inline-block; background: #fff; color: #555; padding: 3px; border: 0; line-height: normal; height: auto; margin: 5px 0; width: 100%; box-sizing: border-box;} -#wpadminbar #wp-admin-bar-view-as .ab-vaa-select .ab-item select {padding: 2px 3px;} -#wpadminbar #wp-admin-bar-view-as .ab-vaa-textarea .ab-item {height: auto; line-height: normal;} -#wpadminbar #wp-admin-bar-view-as .ab-vaa-textarea .ab-item textarea {width: 100%; padding: 5px; box-sizing: border-box; line-height: normal;} - -/*#wpadminbar #wp-admin-bar-view-as .ab-vaa-select .ab-item select {border: 0; margin-top: 6px;}*/ - -#wpadminbar #wp-admin-bar-view-as .ab-vaa-multipleselect .ab-empty-item {height: auto; overflow: hidden;} -#wpadminbar #wp-admin-bar-view-as .ab-vaa-multipleselect.max-height .ab-empty-item {max-height: 100px; overflow-y: scroll; background: #fff; margin: 0 10px 5px; padding: 5px 10px;} -#wpadminbar #wp-admin-bar-view-as .ab-vaa-multipleselect.max-height .ab-empty-item .ab-item {color: #333;} -#wpadminbar #wp-admin-bar-view-as .ab-vaa-multipleselect.auto-height .ab-empty-item {max-height: none; margin: 0;} - -#wpadminbar #wp-admin-bar-view-as ul li.vaa-column-one-half {width: 50%; display: block; float: left; clear: none;} -#wpadminbar #wp-admin-bar-view-as ul li.vaa-column-one-half .ab-item {min-width: 0;} -#wpadminbar #wp-admin-bar-view-as ul li.vaa-column-one-half.vaa-column-first .ab-item {padding-right: 1px;} -#wpadminbar #wp-admin-bar-view-as ul li.vaa-column-one-half.vaa-column-last .ab-item {padding-left: 1px;} -#wpadminbar #wp-admin-bar-view-as ul li.vaa-clear-float {clear: both;} - -#wpadminbar #wp-admin-bar-view-as .ab-item input.checkbox, -#wpadminbar #wp-admin-bar-view-as .ab-item input.radio {display: inline-block; height: 16px; width: 16px; margin: 0 5px 0 0; vertical-align: text-bottom; box-sizing: border-box;} -#wpadminbar #wp-admin-bar-view-as .ab-item input.checkbox + label, -#wpadminbar #wp-admin-bar-view-as .ab-item input.checkbox + label *, -#wpadminbar #wp-admin-bar-view-as .ab-item input.radio + label, -#wpadminbar #wp-admin-bar-view-as .ab-item input.radio + label * {line-height: 18px; vertical-align: text-top;} -#wpadminbar #wp-admin-bar-view-as .ab-item input.checkbox + label:hover, -#wpadminbar #wp-admin-bar-view-as .ab-item input.radio + label:hover {cursor: pointer;} -#wpadminbar #wp-admin-bar-view-as .ab-item input.checkbox:first-child, -#wpadminbar #wp-admin-bar-view-as .ab-item input.radio:first-child {margin: 0 5px 0 0;} -#wpadminbar #wp-admin-bar-view-as .ab-item input.radio {border-radius: 100%;} - -#wpadminbar #wp-admin-bar-view-as .ab-vaa-search #vaa-searchuser-results {margin: 0; padding: 0;} - -#wpadminbar #wp-admin-bar-view-as #wp-admin-bar-caps #wp-admin-bar-caps-quickselect-options {max-height: 400px; min-width: 250px; overflow: hidden; overflow-y: auto; margin: 5px 0; padding: 0; border: solid transparent; border-width: 0 10px 0 0;} - -#wpadminbar #wp-admin-bar-view-as .vaa-button-container > .ab-item {overflow: hidden; height: auto;} -#wpadminbar #wp-admin-bar-view-as button {float: none; text-decoration: none; font-size: 13px; line-height: 20px; height: 20px; margin: 3px 0; padding: 0 10px 1px; vertical-align: middle;} -#wpadminbar #wp-admin-bar-view-as .vaa-icon {padding: 0 2px 1px;} -#wpadminbar #wp-admin-bar-view-as .vaa-icon .ab-icon {margin: 0;} -#wpadminbar #wp-admin-bar-view-as button.vaa-icon .ab-icon {padding: 0;} -#wpadminbar #wp-admin-bar-view-as button#reset-view {margin: 0 0 5px;} -#wpadminbar #wp-admin-bar-view-as #wp-admin-bar-caps #apply-caps-view {float: left; margin-right: 5px;} -#wpadminbar #wp-admin-bar-view-as #wp-admin-bar-caps #reset-caps-view, -#wpadminbar #wp-admin-bar-view-as #wp-admin-bar-caps #open-caps-popup, -#wpadminbar #wp-admin-bar-view-as #wp-admin-bar-caps #close-caps-popup {float: right; margin-left: 5px;} -#wpadminbar #wp-admin-bar-view-as #wp-admin-bar-caps #close-caps-popup {display: none;} -/*#wpadminbar #wp-admin-bar-view-as #wp-admin-bar-caps #wp-admin-bar-filtercaps {clear: both;}*/ - -#wpadminbar #wp-admin-bar-view-as .ab-vaa-toggle .ab-item:hover {cursor: pointer;} -#wpadminbar #wp-admin-bar-view-as .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-view-as .ab-vaa-toggle.active .ab-item::after {content: "\f142";} - -#wpadminbar #wp-admin-bar-view-as.fullPopupActive .ab-sub-wrapper, -#wpadminbar #wp-admin-bar-view-as.fullPopupActive .ab-sub-wrapper .ab-item {display: none;} -#wpadminbar #wp-admin-bar-view-as.fullPopupActive > .ab-sub-wrapper {display: block;} -#wpadminbar #wp-admin-bar-view-as.fullPopupActive > .ab-sub-wrapper > .ab-submenu {padding: 0;} -#wpadminbar #wp-admin-bar-view-as.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-view-as.fullPopupActive .ab-sub-wrapper.fullPopup .ab-item {display: block;} -#wpadminbar #wp-admin-bar-view-as.fullPopupActive #wp-admin-bar-caps .ab-sub-wrapper.fullPopup #close-caps-popup {display: block;} -#wpadminbar #wp-admin-bar-view-as.fullPopupActive #wp-admin-bar-caps .ab-sub-wrapper.fullPopup #open-caps-popup {display: none;} -#wpadminbar #wp-admin-bar-view-as.fullPopupActive #wp-admin-bar-caps .ab-sub-wrapper.fullPopup #wp-admin-bar-caps-quickselect-options .vaa-cap-item {width: 250px; float: left; clear: none;} - -#wpadminbar #wp-admin-bar-view-as #wp-admin-bar-caps-popup:hover {cursor: pointer;} +#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 .ab-bold > .ab-item, +#wpadminbar #wp-admin-bar-vaa .ab-bold > .ab-item * {font-weight: bold !important;} +#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 .vaa-sub-transparent > * {opacity: 0.5; transition: opacity 0.2s;} +#wpadminbar #wp-admin-bar-vaa .vaa-sub-transparent:hover > * {opacity: 1;} + +#wpadminbar #wp-admin-bar-vaa .ab-item .user-role, +#wpadminbar #wp-admin-bar-vaa .ab-item .user-count {font-style: italic; line-height: 26px; font-weight: normal;} + +#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect .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-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; padding: 3px; border: 0; line-height: normal; height: auto; margin: 5px 0; 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-textarea .ab-item {height: auto; line-height: normal;} +#wpadminbar #wp-admin-bar-vaa .ab-vaa-textarea .ab-item textarea {width: 100%; padding: 5px; box-sizing: border-box; line-height: normal;} + +/*#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item select {border: 0; margin-top: 6px;}*/ + +#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect .ab-empty-item {height: auto; overflow: hidden;} +#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect.max-height .ab-empty-item {max-height: 100px; overflow-y: scroll; background: #fff; margin: 0 10px 5px; padding: 5px 10px;} +#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect.max-height .ab-empty-item .ab-item {color: #333;} +#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect.auto-height .ab-empty-item {max-height: none; margin: 0;} + +#wpadminbar #wp-admin-bar-vaa ul li.vaa-column-one-half {width: 50%; display: block; float: left; clear: none;} +#wpadminbar #wp-admin-bar-vaa ul li.vaa-column-one-half .ab-item {min-width: 0;} +#wpadminbar #wp-admin-bar-vaa ul li.vaa-column-one-half.vaa-column-first .ab-item {padding-right: 1px;} +#wpadminbar #wp-admin-bar-vaa ul li.vaa-column-one-half.vaa-column-last .ab-item {padding-left: 1px;} +#wpadminbar #wp-admin-bar-vaa ul li.vaa-clear-float {clear: both;} + +#wpadminbar #wp-admin-bar-vaa .ab-item input.checkbox, +#wpadminbar #wp-admin-bar-vaa .ab-item input.radio {display: inline-block; height: 16px; width: 16px; margin: 0 5px 0 0; vertical-align: text-bottom; box-sizing: border-box;} +#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;} +#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.checkbox:first-child, +#wpadminbar #wp-admin-bar-vaa .ab-item input.radio:first-child {margin: 0 5px 0 0;} +#wpadminbar #wp-admin-bar-vaa .ab-item input.radio {border-radius: 100%;} + +#wpadminbar #wp-admin-bar-vaa .ab-vaa-search #vaa-searchuser-results {margin: 0; padding: 0;} + +#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #wp-admin-bar-vaa-caps-quickselect-options {max-height: 400px; min-width: 250px; overflow: hidden; overflow-y: auto; margin: 5px 0; padding: 0; border: solid transparent; border-width: 0 10px 0 0;} + +#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;} +#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;} +#wpadminbar #wp-admin-bar-vaa button#reset-view {margin: 0 0 5px;} +#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;} +#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #close-caps-popup {display: none;} +/*#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #wp-admin-bar-filtercaps {clear: both;}*/ + +#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";} + +#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 #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-quickselect-options .vaa-cap-item {width: 250px; float: left; clear: none;} + +#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps-popup:hover {cursor: pointer;} /** * Location: My Account; */ -#wpadminbar #wp-admin-bar-my-account #wp-admin-bar-view-as > .ab-item > .ab-label {line-height: 26px;} -#wpadminbar #wp-admin-bar-my-account #wp-admin-bar-view-as > .ab-item > .ab-icon {top: 0;} +#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;} /** * Our custom frontend 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-view-as > .ab-item .ab-icon {margin-left: 0;} -#vaa_toolbar #wpadminbar #wp-admin-bar-view-as > .ab-item .ab-label {display: none;} -#vaa_toolbar #wpadminbar #wp-admin-bar-view-as:hover > .ab-item .ab-icon {margin-left: 6px;} -#vaa_toolbar #wpadminbar #wp-admin-bar-view-as:hover > .ab-item .ab-label {display: inline-block;} +#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;} diff --git a/assets/css/view-admin-as.min.css b/assets/css/view-admin-as.min.css index b0803156..b62240e0 100644 --- a/assets/css/view-admin-as.min.css +++ b/assets/css/view-admin-as.min.css @@ -4,7 +4,7 @@ * * @author Jory Hogeveen * @package view-admin-as - * @version 1.6 + * @version 1.6.1 */ -#vaa-overlay .vaa-overlay-container>.remove:hover,#wpadminbar #wp-admin-bar-view-as #wp-admin-bar-caps-popup:hover,#wpadminbar #wp-admin-bar-view-as .ab-item input.checkbox+label:hover,#wpadminbar #wp-admin-bar-view-as .ab-item input.radio+label:hover,#wpadminbar #wp-admin-bar-view-as .ab-vaa-toggle .ab-item:hover{cursor:pointer}#vaa-overlay{position:fixed;top:0;left:0;height:100%;width:100%;background:rgba(255,255,255,.85);display:none;z-index:999999999}#vaa-overlay .vaa-loader-icon{position:fixed;width:40px;height:40px;top:50%;left:50%;margin:-20px 0 0 -20px;display:block}#vaa-overlay .vaa-overlay-container{max-width:75%;min-width:50%;max-height:50%;min-height:20px;margin:5% 25%;background:#fff;box-shadow:0 0 5px #aaa;padding:10px;border-radius:3px;position:relative}#vaa-overlay .vaa-overlay-container>.remove{position:absolute;right:-10px;top:-10px;background:#FFF;width:20px;height:20px}#vaa-overlay.inner,#vaa-overlay.inner .vaa-loader-icon{position:absolute}#wpadminbar #wp-admin-bar-view-as .ab-item,#wpadminbar #wp-admin-bar-view-as ul li{clear:both}#wpadminbar #wp-admin-bar-view-as>.ab-item>.ab-label{float: left;}#wpadminbar #wp-admin-bar-view-as>.ab-item>.ab-icon{float:right!important;margin-right:0;margin-left:6px;top:2px}#wpadminbar #wp-admin-bar-view-as .vaa-has-icon>.ab-item>.ab-icon{float:none;font-size:16px;vertical-align:text-bottom;font-weight:400;padding:0}#wpadminbar #wp-admin-bar-view-as .vaa-has-icon>.ab-item::before{display:none}#wpadminbar #wp-admin-bar-view-as .vaa-has-icon.menupop>.ab-item{padding-left:10px;padding-right:10px}#wpadminbar #wp-admin-bar-view-as .vaa-has-icon.ab-vaa-title>.ab-item>.ab-icon{font-size:18px;margin:0 5px 0 -1px}#wpadminbar .vaa-update.vaa-error{display:inline-block;color:#dc3232;background:#fff;padding:0 10px}#wpadminbar .vaa-update.vaa-error .ab-icon:before{color:#dc3232}#wpadminbar .vaa-update.vaa-success{display:inline-block;color:#46b450;background:#fff;padding:0 10px}#wpadminbar .vaa-update.vaa-success .ab-icon:before{color:#46b450}#wpadminbar #wp-admin-bar-view-as.menupop ul.ab-sub-secondary{position:static}#wpadminbar #wp-admin-bar-view-as.menupop .menupop>.ab-item:before{top:1px}#wpadminbar #wp-admin-bar-view-as>div>ul.ab-sub-secondary+ul.ab-sub-secondary{margin-top:3px}#wpadminbar #wp-admin-bar-view-as .auto-height>.ab-item{height:auto}#wpadminbar #wp-admin-bar-view-as .ab-item .description{height:auto;line-height:1.2;font-size:.9em;font-style:italic;margin-bottom:7px;white-space:normal}#wpadminbar #wp-admin-bar-view-as.menupop .ab-vaa-title .ab-item{font-weight:700;line-height:26px;font-size:1.1em;text-transform:uppercase}#wpadminbar #wp-admin-bar-view-as .current-parent>.ab-item,#wpadminbar #wp-admin-bar-view-as .current>.ab-item{font-weight:700}#wpadminbar #wp-admin-bar-view-as .current>.ab-item::after{content:'\f177';font-family:dashicons;margin:0 5px;font-size:17px;vertical-align:middle;font-weight:400}#wpadminbar .ab-top-secondary .menupop .vaa-menupop>.ab-item{padding-left:2em;padding-right:1em}#wpadminbar #wp-admin-bar-view-as .ab-bold>.ab-item,#wpadminbar #wp-admin-bar-view-as .ab-bold>.ab-item *{font-weight:700!important}#wpadminbar #wp-admin-bar-view-as .ab-italic>.ab-item,#wpadminbar #wp-admin-bar-view-as .ab-italic>.ab-item *{font-style:italic!important}#wpadminbar #wp-admin-bar-view-as .vaa-sub-transparent>*{opacity:.5;transition:opacity .2s}#wpadminbar #wp-admin-bar-view-as .vaa-sub-transparent:hover>*{opacity:1}#wpadminbar #wp-admin-bar-view-as .ab-item .user-count,#wpadminbar #wp-admin-bar-view-as .ab-item .user-role{font-style:italic;line-height:26px;font-weight:400}#wpadminbar #wp-admin-bar-view-as .ab-vaa-filter .ab-item,#wpadminbar #wp-admin-bar-view-as .ab-vaa-multipleselect .ab-item,#wpadminbar #wp-admin-bar-view-as .ab-vaa-search .ab-item,#wpadminbar #wp-admin-bar-view-as .ab-vaa-select .ab-item{height:auto;clear:both}#wpadminbar #wp-admin-bar-view-as .ab-vaa-filter .ab-item input,#wpadminbar #wp-admin-bar-view-as .ab-vaa-search .ab-item input,#wpadminbar #wp-admin-bar-view-as .ab-vaa-select .ab-item select{display:inline-block;background:#fff;color:#555;padding:3px;border:0;line-height:normal;height:auto;margin:5px 0;width:100%;box-sizing:border-box}#wpadminbar #wp-admin-bar-view-as .ab-vaa-select .ab-item select{padding:2px 3px}#wpadminbar #wp-admin-bar-view-as .ab-vaa-textarea .ab-item{height:auto;line-height:normal}#wpadminbar #wp-admin-bar-view-as .ab-vaa-textarea .ab-item textarea{width:100%;padding:5px;box-sizing:border-box;line-height:normal}#wpadminbar #wp-admin-bar-view-as .ab-vaa-multipleselect .ab-empty-item{height:auto;overflow:hidden}#wpadminbar #wp-admin-bar-view-as .ab-vaa-multipleselect.max-height .ab-empty-item{max-height:100px;overflow-y:scroll;background:#fff;margin:0 10px 5px;padding:5px 10px}#wpadminbar #wp-admin-bar-view-as .ab-vaa-multipleselect.max-height .ab-empty-item .ab-item{color:#333}#wpadminbar #wp-admin-bar-view-as .ab-vaa-multipleselect.auto-height .ab-empty-item{max-height:none;margin:0}#wpadminbar #wp-admin-bar-view-as ul li.vaa-column-one-half{width:50%;display:block;float:left;clear:none}#wpadminbar #wp-admin-bar-view-as ul li.vaa-column-one-half .ab-item{min-width:0}#wpadminbar #wp-admin-bar-view-as ul li.vaa-column-one-half.vaa-column-first .ab-item{padding-right:1px}#wpadminbar #wp-admin-bar-view-as ul li.vaa-column-one-half.vaa-column-last .ab-item{padding-left:1px}#wpadminbar #wp-admin-bar-view-as ul li.vaa-clear-float{clear:both}#wpadminbar #wp-admin-bar-view-as .ab-item input.checkbox,#wpadminbar #wp-admin-bar-view-as .ab-item input.radio{display:inline-block;height:16px;width:16px;margin:0 5px 0 0;vertical-align:text-bottom;box-sizing:border-box}#wpadminbar #wp-admin-bar-view-as #wp-admin-bar-caps #close-caps-popup,#wpadminbar #wp-admin-bar-view-as.fullPopupActive .ab-sub-wrapper,#wpadminbar #wp-admin-bar-view-as.fullPopupActive .ab-sub-wrapper .ab-item{display:none}#wpadminbar #wp-admin-bar-view-as .ab-item input.checkbox+label,#wpadminbar #wp-admin-bar-view-as .ab-item input.checkbox+label *,#wpadminbar #wp-admin-bar-view-as .ab-item input.radio+label,#wpadminbar #wp-admin-bar-view-as .ab-item input.radio+label *{line-height:18px;vertical-align:text-top}#wpadminbar #wp-admin-bar-view-as .ab-item input.checkbox:first-child,#wpadminbar #wp-admin-bar-view-as .ab-item input.radio:first-child{margin:0 5px 0 0}#wpadminbar #wp-admin-bar-view-as .ab-item input.radio{border-radius:100%}#wpadminbar #wp-admin-bar-view-as .ab-vaa-search #vaa-searchuser-results{margin:0;padding:0}#wpadminbar #wp-admin-bar-view-as #wp-admin-bar-caps #wp-admin-bar-caps-quickselect-options{max-height:400px;min-width:250px;overflow:hidden;overflow-y:auto;margin:5px 0;padding:0;border:solid transparent;border-width:0 10px 0 0}#wpadminbar #wp-admin-bar-view-as .vaa-button-container>.ab-item{overflow:hidden;height:auto}#wpadminbar #wp-admin-bar-view-as button{float:none;text-decoration:none;font-size:13px;line-height:20px;height:20px;margin:3px 0;padding:0 10px 1px;vertical-align:middle}#wpadminbar #wp-admin-bar-view-as .vaa-icon{padding:0 2px 1px}#wpadminbar #wp-admin-bar-view-as button.vaa-icon .ab-icon,#wpadminbar #wp-admin-bar-view-as.fullPopupActive>.ab-sub-wrapper>.ab-submenu{padding:0}#wpadminbar #wp-admin-bar-view-as .vaa-icon .ab-icon{margin:0}#wpadminbar #wp-admin-bar-view-as button#reset-view{margin:0 0 5px}#wpadminbar #wp-admin-bar-view-as #wp-admin-bar-caps #apply-caps-view{float:left;margin-right:5px}#wpadminbar #wp-admin-bar-view-as #wp-admin-bar-caps #close-caps-popup,#wpadminbar #wp-admin-bar-view-as #wp-admin-bar-caps #open-caps-popup,#wpadminbar #wp-admin-bar-view-as #wp-admin-bar-caps #reset-caps-view{float:right;margin-left:5px}#wpadminbar #wp-admin-bar-view-as .ab-vaa-toggle .ab-item::after{content:"\f140";font-family:dashicons;position:absolute;right:10px;margin:0;font-size:20px;font-weight:400}#wpadminbar #wp-admin-bar-view-as .ab-vaa-toggle.active .ab-item::after{content:"\f142"}#wpadminbar #wp-admin-bar-view-as.fullPopupActive #wp-admin-bar-caps .ab-sub-wrapper.fullPopup #close-caps-popup,#wpadminbar #wp-admin-bar-view-as.fullPopupActive .ab-sub-wrapper.fullPopup .ab-item,#wpadminbar #wp-admin-bar-view-as.fullPopupActive>.ab-sub-wrapper{display:block}#wpadminbar #wp-admin-bar-view-as.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,.3)}#vaa_toolbar #wpadminbar #wp-admin-bar-view-as>.ab-item .ab-label,#wpadminbar #wp-admin-bar-view-as.fullPopupActive #wp-admin-bar-caps .ab-sub-wrapper.fullPopup #open-caps-popup{display:none}#wpadminbar #wp-admin-bar-view-as.fullPopupActive #wp-admin-bar-caps .ab-sub-wrapper.fullPopup #wp-admin-bar-caps-quickselect-options .vaa-cap-item{width:250px;float:left;clear:none}#wpadminbar #wp-admin-bar-my-account #wp-admin-bar-view-as>.ab-item>.ab-label{line-height:26px;}#wpadminbar #wp-admin-bar-my-account #wp-admin-bar-view-as>.ab-item>.ab-icon{top:0}#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-view-as>.ab-item .ab-icon{margin-left:0}#vaa_toolbar #wpadminbar #wp-admin-bar-view-as:hover>.ab-item .ab-icon{margin-left:6px}#vaa_toolbar #wpadminbar #wp-admin-bar-view-as:hover>.ab-item .ab-label{display:inline-block} \ No newline at end of file +#vaa-overlay .vaa-overlay-container>.remove:hover,#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps-popup:hover,#wpadminbar #wp-admin-bar-vaa .ab-item input.checkbox+label:hover,#wpadminbar #wp-admin-bar-vaa .ab-item input.radio+label:hover,#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle .ab-item:hover{cursor:pointer}#vaa-overlay{position:fixed;top:0;left:0;height:100%;width:100%;background:rgba(255,255,255,.85);display:none;z-index:999999999}#vaa-overlay .vaa-loader-icon{position:fixed;width:40px;height:40px;top:50%;left:50%;margin:-20px 0 0 -20px;display:block}#vaa-overlay .vaa-overlay-container{max-width:75%;min-width:50%;max-height:50%;min-height:20px;margin:5% 25%;background:#fff;box-shadow:0 0 5px #aaa;padding:10px;border-radius:3px;position:relative}#vaa-overlay .vaa-overlay-container>.remove{position:absolute;right:-10px;top:-10px;background:#FFF;width:20px;height:20px}#vaa-overlay.inner,#vaa-overlay.inner .vaa-loader-icon{position:absolute}#wpadminbar .vaa-update.vaa-error{display:inline-block;color:#dc3232;background:#fff;padding:0 10px}#wpadminbar .vaa-update.vaa-error .ab-icon:before{color:#dc3232}#wpadminbar .vaa-update.vaa-success{display:inline-block;color:#46b450;background:#fff;padding:0 10px}#wpadminbar .vaa-update.vaa-success .ab-icon:before{color:#46b450}#wpadminbar #wp-admin-bar-vaa .ab-item,#wpadminbar #wp-admin-bar-vaa ul li{clear:both}#wpadminbar #wp-admin-bar-vaa>.ab-item>.ab-label{float:left}#wpadminbar #wp-admin-bar-vaa>.ab-item>.ab-icon{float:right!important;margin-right:0;margin-left:6px;top:2px}#wpadminbar #wp-admin-bar-vaa .vaa-has-icon>.ab-item>.ab-icon{float:none;font-size:16px;vertical-align:text-bottom;font-weight:400;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;margin:0 5px 0 -1px}#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 #wp-admin-bar-vaa>div>ul.ab-sub-secondary+ul.ab-sub-secondary{margin-top:3px}#wpadminbar #wp-admin-bar-vaa .auto-height>.ab-item{height:auto}#wpadminbar #wp-admin-bar-vaa .ab-item .description{height:auto;line-height:1.2;font-size:.9em;font-style:italic;margin-bottom:7px;white-space:normal}#wpadminbar #wp-admin-bar-vaa.menupop .ab-vaa-title .ab-item{font-weight:700;line-height:26px;font-size:1.1em;text-transform:uppercase}#wpadminbar #wp-admin-bar-vaa .current-parent>.ab-item,#wpadminbar #wp-admin-bar-vaa .current>.ab-item{font-weight:700}#wpadminbar #wp-admin-bar-vaa .current>.ab-item::after{content:'\f177';font-family:dashicons;margin:0 5px;font-size:17px;vertical-align:middle;font-weight:400}#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 .ab-bold>.ab-item,#wpadminbar #wp-admin-bar-vaa .ab-bold>.ab-item *{font-weight:700!important}#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 .vaa-sub-transparent>*{opacity:.5;transition:opacity .2s}#wpadminbar #wp-admin-bar-vaa .vaa-sub-transparent:hover>*{opacity:1}#wpadminbar #wp-admin-bar-vaa .ab-item .user-count,#wpadminbar #wp-admin-bar-vaa .ab-item .user-role{font-style:italic;line-height:26px;font-weight:400}#wpadminbar #wp-admin-bar-vaa .ab-vaa-filter .ab-item,#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect .ab-item,#wpadminbar #wp-admin-bar-vaa .ab-vaa-search .ab-item,#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item{height:auto;clear:both}#wpadminbar #wp-admin-bar-vaa .ab-vaa-filter .ab-item input,#wpadminbar #wp-admin-bar-vaa .ab-vaa-search .ab-item input,#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item select{display:inline-block;background:#fff;color:#555;padding:3px;border:0;line-height:normal;height:auto;margin:5px 0;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-textarea .ab-item{height:auto;line-height:normal}#wpadminbar #wp-admin-bar-vaa .ab-vaa-textarea .ab-item textarea{width:100%;padding:5px;box-sizing:border-box;line-height:normal}#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect .ab-empty-item{height:auto;overflow:hidden}#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect.max-height .ab-empty-item{max-height:100px;overflow-y:scroll;background:#fff;margin:0 10px 5px;padding:5px 10px}#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect.max-height .ab-empty-item .ab-item{color:#333}#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect.auto-height .ab-empty-item{max-height:none;margin:0}#wpadminbar #wp-admin-bar-vaa ul li.vaa-column-one-half{width:50%;display:block;float:left;clear:none}#wpadminbar #wp-admin-bar-vaa ul li.vaa-column-one-half .ab-item{min-width:0}#wpadminbar #wp-admin-bar-vaa ul li.vaa-column-one-half.vaa-column-first .ab-item{padding-right:1px}#wpadminbar #wp-admin-bar-vaa ul li.vaa-column-one-half.vaa-column-last .ab-item{padding-left:1px}#wpadminbar #wp-admin-bar-vaa ul li.vaa-clear-float{clear:both}#wpadminbar #wp-admin-bar-vaa .ab-item input.checkbox,#wpadminbar #wp-admin-bar-vaa .ab-item input.radio{display:inline-block;height:16px;width:16px;margin:0 5px 0 0;vertical-align:text-bottom;box-sizing:border-box}#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #close-caps-popup,#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 .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}#wpadminbar #wp-admin-bar-vaa .ab-item input.checkbox:first-child,#wpadminbar #wp-admin-bar-vaa .ab-item input.radio:first-child{margin:0 5px 0 0}#wpadminbar #wp-admin-bar-vaa .ab-item input.radio{border-radius:100%}#wpadminbar #wp-admin-bar-vaa .ab-vaa-search #vaa-searchuser-results{margin:0;padding:0}#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #wp-admin-bar-vaa-caps-quickselect-options{max-height:400px;min-width:250px;overflow:hidden;overflow-y:auto;margin:5px 0;padding:0;border:solid transparent;border-width:0 10px 0 0}#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;}#wpadminbar #wp-admin-bar-vaa .vaa-icon{padding:0 2px 1px}#wpadminbar #wp-admin-bar-vaa button.vaa-icon .ab-icon,#wpadminbar #wp-admin-bar-vaa.fullPopupActive>.ab-sub-wrapper>.ab-submenu{padding:0}#wpadminbar #wp-admin-bar-vaa .vaa-icon .ab-icon{margin:0}#wpadminbar #wp-admin-bar-vaa button#reset-view{margin:0 0 5px}#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 #close-caps-popup,#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #open-caps-popup,#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #reset-caps-view{float:right;margin-left:5px}#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:400}#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle.active .ab-item::after{content:"\f142"}#wpadminbar #wp-admin-bar-vaa.fullPopupActive #wp-admin-bar-vaa-caps .ab-sub-wrapper.fullPopup #close-caps-popup,#wpadminbar #wp-admin-bar-vaa.fullPopupActive .ab-sub-wrapper.fullPopup .ab-item,#wpadminbar #wp-admin-bar-vaa.fullPopupActive>.ab-sub-wrapper{display:block}#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,.3)}#vaa_toolbar #wpadminbar #wp-admin-bar-vaa>.ab-item .ab-label,#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-quickselect-options .vaa-cap-item{width:250px;float:left;clear:none}#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}#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:hover>.ab-item .ab-icon{margin-left:6px}#vaa_toolbar #wpadminbar #wp-admin-bar-vaa:hover>.ab-item .ab-label{display:inline-block} \ No newline at end of file diff --git a/assets/js/view-admin-as.js b/assets/js/view-admin-as.js index 6b75f46c..1c4f0c72 100644 --- a/assets/js/view-admin-as.js +++ b/assets/js/view-admin-as.js @@ -4,24 +4,26 @@ * * @author Jory Hogeveen * @package view-admin-as - * @version 1.6 + * @version 1.6.1 */ if ( 'undefined' == typeof VAA_View_Admin_As ) { var VAA_View_Admin_As = { - 'ajaxurl': null, - 'siteurl': '', - '_debug': false, - '_vaa_nonce': '', - '__no_users_found': 'No users found.', - '__success': 'Success', - '__confirm': 'Are you sure?' + ajaxurl: null, + siteurl: '', + view_as: false, + _debug: false, + _vaa_nonce: '', + __no_users_found: 'No users found.', + __success: 'Success', + __confirm: 'Are you sure?' }; } -(function($) { +( function( $ ) { - VAA_View_Admin_As.prefix = '#wpadminbar #wp-admin-bar-view-as '; + VAA_View_Admin_As.prefix = '#wpadminbar #wp-admin-bar-vaa '; + VAA_View_Admin_As.root = '#wp-admin-bar-vaa'; if ( 'undefined' == typeof VAA_View_Admin_As._debug ) { VAA_View_Admin_As._debug = 0; @@ -33,6 +35,14 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { VAA_View_Admin_As.ajaxurl = ajaxurl; } + // @since 1.6.1 Prevent swipe events to be seen as a click (bug in some browsers) + VAA_View_Admin_As._touchmove = false; + $( document ).on( 'touchmove', function() { + VAA_View_Admin_As._touchmove = true; + } ); + $( document ).on( 'touchstart', function() { + VAA_View_Admin_As._touchmove = false; + } ); /** * BASE INIT @@ -52,7 +62,8 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { if ( ! $(this).hasClass('active') ) { toggleContent.hide(); } - $(this).click( function( e ) { + + $(this).on( 'click', function( e ) { e.preventDefault(); if ( $(this).hasClass('active') ) { toggleContent.slideUp('fast'); @@ -62,17 +73,39 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { $(this).addClass('active'); } }); + + // @since 1.6.1 Keyboard A11y + $(this).on( 'keyup', function( e ) { + e.preventDefault(); + /** + * @see https://api.jquery.com/keyup/ + * 13 = enter + * 32 = space + * 38 = arrow up + * 40 = arrow down + */ + var key = e.which; + if ( $(this).hasClass('active') && ( key == 13 || key == 32 || key == 38 ) ) { + toggleContent.slideUp('fast'); + $(this).removeClass('active'); + } else if ( key == 13 || key == 32 || key == 40 ) { + toggleContent.slideDown('fast'); + $(this).addClass('active'); + } + }); }); }); // Process reset - $(document).on('click', VAA_View_Admin_As.prefix+'.vaa-reset-item > .ab-item', function( e ) { + $(document).on('click touchend', VAA_View_Admin_As.prefix+'.vaa-reset-item > .ab-item', function( e ) { e.preventDefault(); - if ( $('button', this).attr('name') == 'reload' ) { + if ( true === VAA_View_Admin_As._touchmove ) { + return; + } + if ( $('button', this).attr('name') == 'vaa_reload' ) { window.location.reload(); } else { - viewAs = { reset : true }; - VAA_View_Admin_As.ajax( viewAs, true ); + VAA_View_Admin_As.ajax( { reset : true }, true ); return false; } }); @@ -107,7 +140,11 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { 'view_admin_as': viewAs }; - if ( $(VAA_View_Admin_As.prefix+'#vaa_settings_view_mode_single').is(':checked') && ( typeof viewAs.caps !== 'undefined' || typeof viewAs.role !== 'undefined' || typeof viewAs.user !== 'undefined' ) ) { + /** + * @since 1.5 Check view mode + * @todo improve if statement and form creation + */ + if ( $(VAA_View_Admin_As.prefix+'#vaa-settings-view-mode-single').is(':checked') && ( typeof viewAs.caps !== 'undefined' || typeof viewAs.role !== 'undefined' || typeof viewAs.user !== 'undefined' ) ) { body.append(''); var form = $('#vaa_single_mode_form'); @@ -140,8 +177,12 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { /** * Reload the page * Currently I use "replace" since no history seems necessary. Other option would be "assign" which enables history. + * @since 1.6.1 Fix issue with anchors */ - window.location.replace( window.location.href.replace('?reset-view', '').replace('&reset-view', '') ); + window.location.hash = ''; + window.location.replace( + window.location.href.replace('#', '').replace('?reset-view', '').replace('&reset-view', '').replace('?reset-all-views', '').replace('&reset-all-views', '') + ); } } else { $('body #vaa-overlay').addClass('error').fadeOut( 'fast', function() { $(this).remove(); } ); @@ -186,13 +227,16 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { * @param {string} type */ VAA_View_Admin_As.overlay = function( data, type ) { - $('body #vaa-overlay').html('
'); + + var root = 'body #vaa-overlay'; + + $( root ).html('
'); if ( type == 'textarea' ) { if ( typeof data.text != 'undefined' ) { - $('body #vaa-overlay .vaa-response-data').append('

' + data.text + '

'); + $(root+' .vaa-response-data').append('

' + data.text + '

'); } if ( typeof data.textareacontent != 'undefined' ) { - $('body #vaa-overlay .vaa-response-data').append(''); + $(root+' .vaa-response-data').append(''); // Auto height /*$('body #vaa-overlay .vaa-response-data textarea').each(function(){ var maxTextareaHeight = $('body #vaa-overlay .vaa-response-data').height(); @@ -200,30 +244,30 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { $(this).css({'height': 'auto', 'max-height': maxTextareaHeight}).height( fullTextareaHeight ); });*/ // Select full text on click - $('body #vaa-overlay .vaa-response-data textarea').click( function() { $(this).select(); } ); + $(root+' .vaa-response-data textarea').click( function() { $(this).select(); } ); } } else if ( type == 'errorlist' ) { if ( typeof data.text != 'undefined' ) { - $('body #vaa-overlay .vaa-response-data').append('

'+data.text+'

'); + $(root+' .vaa-response-data').append('

'+data.text+'

'); } if ( typeof data.errors != 'undefined' ) { - $('body #vaa-overlay .vaa-response-data').append('
    '); + $(root+' .vaa-response-data').append('
      '); data.errors.forEach(function(error) { - $('body #vaa-overlay .vaa-response-data .errorlist').append('
    • '+error+'
    • '); + $(root+' .vaa-response-data .errorlist').append('
    • '+error+'
    • '); }); } } else { - $('body #vaa-overlay .vaa-response-data').append('
      '+data+'
      '); + $(root+' .vaa-response-data').append('
      '+data+'
      '); } - $('#vaa-overlay .vaa-overlay-container .remove').click( function() { - $('body #vaa-overlay').fadeOut( 'fast', function() { $(this).remove(); } ); + $(root+' .vaa-overlay-container .remove').click( function() { + $( root ).fadeOut( 'fast', function() { $(this).remove(); } ); }); // Remove overlay on click outside of container $(document).mouseup( function( e ){ - $('body #vaa-overlay .vaa-overlay-container').each( function(){ + $(root+' .vaa-overlay-container').each( function(){ if ( ! $(this).is(e.target) && 0 === $(this).has(e.target).length ) { - $('body #vaa-overlay').fadeOut( 'fast', function() { $(this).remove(); } ); + $( root ).fadeOut( 'fast', function() { $(this).remove(); } ); } }); }); @@ -232,11 +276,15 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { /** * SETTINGS - **/ + * @since 1.5 + */ VAA_View_Admin_As.init_settings = function() { - // Location - $(document).on('change', VAA_View_Admin_As.prefix+'#wp-admin-bar-settings-admin-menu-location select#vaa_settings_admin_menu_location', function( e ) { + var root = VAA_View_Admin_As.root + '-settings', + prefix = 'vaa-settings'; + + // @since 1.5 Location + $(document).on('change', VAA_View_Admin_As.prefix+root+'-admin-menu-location select#' + prefix + '-admin-menu-location', function( e ) { e.preventDefault(); var val = $(this).val(); if ( val && '' !== val ) { @@ -245,8 +293,8 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { } }); - // View mode - $(document).on('change', VAA_View_Admin_As.prefix+'#wp-admin-bar-settings-view-mode input.radio.vaa_settings_view_mode', function( e ) { + // @since 1.5 View mode + $(document).on('change', VAA_View_Admin_As.prefix+root+'-view-mode input.radio.' + prefix + '-view-mode', function( e ) { e.preventDefault(); var val = $(this).val(); if ( val && '' !== val ) { @@ -255,8 +303,8 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { } }); - // Force group users - $(document).on('change', VAA_View_Admin_As.prefix+'#wp-admin-bar-settings-force-group-users input#vaa_settings_force_group_users', function( e ) { + // @since 1.5.2 Force group users + $(document).on('change', VAA_View_Admin_As.prefix+root+'-force-group-users input#' + prefix + '-force-group-users', function( e ) { e.preventDefault(); var viewAs = { user_setting : { force_group_users : "no" } }; if ( this.checked ) { @@ -265,8 +313,8 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { VAA_View_Admin_As.ajax( viewAs, true ); }); - // Enable hide front - $(document).on('change', VAA_View_Admin_As.prefix+'#wp-admin-bar-settings-hide-front input#vaa_settings_hide_front', function( e ) { + // @since 1.6 Enable hide front + $(document).on('change', VAA_View_Admin_As.prefix+root+'-hide-front input#' + prefix + '-hide-front', function( e ) { e.preventDefault(); var viewAs = { user_setting : { hide_front : "no" } }; if ( this.checked ) { @@ -274,6 +322,20 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { } VAA_View_Admin_As.ajax( viewAs, false ); }); + + // @since 1.6.1 Enable freeze locale + $(document).on('change', VAA_View_Admin_As.prefix+root+'-freeze-locale input#' + prefix + '-freeze-locale', function( e ) { + e.preventDefault(); + var viewAs = { user_setting : { freeze_locale : "no" } }; + if ( this.checked ) { + viewAs = { user_setting : { freeze_locale : "yes" } }; + } + var reload = false; + if ( typeof VAA_View_Admin_As.view_as == 'object' && typeof VAA_View_Admin_As.view_as.user != 'undefined' ) { + reload = true; + } + VAA_View_Admin_As.ajax( viewAs, reload ); + }); }; @@ -283,7 +345,10 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { VAA_View_Admin_As.init_roles = function() { // Process role views - $(document).on('click', VAA_View_Admin_As.prefix+'.vaa-role-item > a.ab-item', function( e ) { + $(document).on('click touchend', VAA_View_Admin_As.prefix+'.vaa-role-item > a.ab-item', function( e ) { + if ( true === VAA_View_Admin_As._touchmove ) { + return; + } e.preventDefault(); if ( ! $(this).parent().hasClass('not-a-view') ) { var viewAs = { role : String( $(this).attr('rel') ) }; @@ -299,8 +364,13 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { **/ VAA_View_Admin_As.init_users = function() { + var root = VAA_View_Admin_As.root + '-users'; + // Process user views - $(document).on('click', VAA_View_Admin_As.prefix+'.vaa-user-item > a.ab-item', function( e ) { + $(document).on('click touchend', VAA_View_Admin_As.prefix+'.vaa-user-item > a.ab-item', function( e ) { + if ( true === VAA_View_Admin_As._touchmove ) { + return; + } e.preventDefault(); if ( ! $(this).parent().hasClass('not-a-view') ) { var viewAs = { user : parseInt( $(this).attr('rel') ) }; @@ -310,7 +380,7 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { }); // Search users - $(document).on('keyup', VAA_View_Admin_As.prefix+'#wp-admin-bar-users .ab-vaa-search.search-users input', function() { + $(document).on('keyup', VAA_View_Admin_As.prefix+root+' .ab-vaa-search.search-users input', function() { $(VAA_View_Admin_As.prefix+' .ab-vaa-search #vaa-searchuser-results').empty(); if ( 1 <= $(this).val().length ) { var inputText = $(this).val(); @@ -341,9 +411,12 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { /** * CAPABILITIES + * @since 1.3 **/ VAA_View_Admin_As.init_caps = function() { + var root = VAA_View_Admin_As.root + '-caps'; + VAA_View_Admin_As.caps_filter_settings = { selectedRole : 'default', selectedRoleCaps : {}, @@ -354,7 +427,7 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { // Filter capability handler VAA_View_Admin_As.filter_capabilities = function() { //VAA_View_Admin_As.caps_filter_settings; - $(VAA_View_Admin_As.prefix+' #wp-admin-bar-caps-quickselect-options .vaa-cap-item').each( function() { + $(VAA_View_Admin_As.prefix+root+'-quickselect-options .vaa-cap-item').each( function() { var name; if ( true === VAA_View_Admin_As.caps_filter_settings.selectedRoleReverse ) { $(this).hide(); @@ -386,29 +459,29 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { }; // Set max height of the caps submenu - $(document).on('mouseenter', VAA_View_Admin_As.prefix+'#wp-admin-bar-caps-quickselect', function() { - $(VAA_View_Admin_As.prefix+'#wp-admin-bar-caps-quickselect-options').css( { 'max-height': ( $(window).height() - 350 )+'px' } ); + $(document).on('mouseenter', VAA_View_Admin_As.prefix+root+'-quickselect', function() { + $(VAA_View_Admin_As.prefix+root+'-quickselect-options').css( { 'max-height': ( $(window).height() - 350 )+'px' } ); }); // Enlarge caps - $(document).on('click', VAA_View_Admin_As.prefix+'#wp-admin-bar-caps #open-caps-popup', function() { + $(document).on('click', VAA_View_Admin_As.prefix+root+' #open-caps-popup', function() { $(VAA_View_Admin_As.prefix).addClass('fullPopupActive'); - $(VAA_View_Admin_As.prefix+'#wp-admin-bar-caps-quickselect > .ab-sub-wrapper').addClass('fullPopup'); + $(VAA_View_Admin_As.prefix+root+'-quickselect > .ab-sub-wrapper').addClass('fullPopup'); }); // Undo enlarge caps - $(document).on('click', VAA_View_Admin_As.prefix+'#wp-admin-bar-caps #close-caps-popup', function() { + $(document).on('click', VAA_View_Admin_As.prefix+root+' #close-caps-popup', function() { $(VAA_View_Admin_As.prefix).removeClass('fullPopupActive'); - $(VAA_View_Admin_As.prefix+'#wp-admin-bar-caps-quickselect > .ab-sub-wrapper').removeClass('fullPopup'); + $(VAA_View_Admin_As.prefix+root+'-quickselect > .ab-sub-wrapper').removeClass('fullPopup'); }); // Select role capabilities - $(document).on('change', VAA_View_Admin_As.prefix+'#wp-admin-bar-caps .ab-vaa-select.select-role-caps select', function() { + $(document).on('change', VAA_View_Admin_As.prefix+root+' .ab-vaa-select.select-role-caps select', function() { VAA_View_Admin_As.caps_filter_settings.selectedRole = $(this).val(); if ( VAA_View_Admin_As.caps_filter_settings.selectedRole == 'default' ) { VAA_View_Admin_As.caps_filter_settings.selectedRoleCaps = {}; VAA_View_Admin_As.caps_filter_settings.selectedRoleReverse = false; } else { - var selectedRoleElement = $(VAA_View_Admin_As.prefix+' #wp-admin-bar-selectrolecaps #select-role-caps option[value="' + VAA_View_Admin_As.caps_filter_settings.selectedRole + '"]'); + var selectedRoleElement = $(VAA_View_Admin_As.prefix+root+'-selectrolecaps #vaa-caps-selectrolecaps option[value="' + VAA_View_Admin_As.caps_filter_settings.selectedRole + '"]'); VAA_View_Admin_As.caps_filter_settings.selectedRoleCaps = JSON.parse( selectedRoleElement.attr('data-caps') ); if ( '1' == selectedRoleElement.attr('data-reverse') ) { VAA_View_Admin_As.caps_filter_settings.selectedRoleReverse = true; @@ -420,7 +493,7 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { }); // Filter capabilities with text input - $(document).on('keyup', VAA_View_Admin_As.prefix+'#wp-admin-bar-caps .ab-vaa-filter input', function() { + $(document).on('keyup', VAA_View_Admin_As.prefix+root+' .ab-vaa-filter input', function() { //VAA_View_Admin_As.caps_filter_settings; if ( 1 <= $(this).val().length ) { VAA_View_Admin_As.caps_filter_settings.filterString = $(this).val(); @@ -432,9 +505,12 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { // Select all capabilities - $(document).on('click', VAA_View_Admin_As.prefix+'#wp-admin-bar-caps button#select-all-caps', function( e ) { + $(document).on('click touchend', VAA_View_Admin_As.prefix+root+' button#select-all-caps', function( e ) { + if ( true === VAA_View_Admin_As._touchmove ) { + return; + } e.preventDefault(); - $(VAA_View_Admin_As.prefix+'#wp-admin-bar-caps-quickselect-options .vaa-cap-item').each( function() { + $(VAA_View_Admin_As.prefix+root+'-quickselect-options .vaa-cap-item').each( function() { if ( $(this).is(':visible') ){ $('input', this).prop( "checked", true ); } @@ -442,9 +518,12 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { return false; }); // Deselect all capabilities - $(document).on('click', VAA_View_Admin_As.prefix+'#wp-admin-bar-caps button#deselect-all-caps', function( e ) { + $(document).on('click touchend', VAA_View_Admin_As.prefix+root+' button#deselect-all-caps', function( e ) { + if ( true === VAA_View_Admin_As._touchmove ) { + return; + } e.preventDefault(); - $(VAA_View_Admin_As.prefix+'#wp-admin-bar-caps-quickselect-options .vaa-cap-item').each( function() { + $(VAA_View_Admin_As.prefix+root+'-quickselect-options .vaa-cap-item').each( function() { if ( $(this).is(':visible') ){ $('input', this).prop( "checked", false ); } @@ -453,10 +532,13 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { }); // Process view: capabilities - $(document).on('click', VAA_View_Admin_As.prefix+'#wp-admin-bar-caps button#apply-caps-view', function( e ) { + $(document).on('click touchend', VAA_View_Admin_As.prefix+root+' button#apply-caps-view', function( e ) { + if ( true === VAA_View_Admin_As._touchmove ) { + return; + } e.preventDefault(); var newCaps = ''; - $(VAA_View_Admin_As.prefix+'#wp-admin-bar-caps-quickselect-options .vaa-cap-item input').each( function() { + $(VAA_View_Admin_As.prefix+root+'-quickselect-options .vaa-cap-item input').each( function() { if ( $(this).is(':checked') ) { newCaps += $(this).attr('value') + ':' + 1 + ','; } else { @@ -471,11 +553,15 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { /** * MODULE: Role Defaults + * @since 1.4 */ VAA_View_Admin_As.init_module_role_defaults = function() { + var root = VAA_View_Admin_As.root + '-settings', + prefix = 'vaa-settings'; + // Enable module - $(document).on('change', VAA_View_Admin_As.prefix+'#wp-admin-bar-settings-role-defaults-enable input#vaa_role_defaults_enable', function( e ) { + $(document).on('change', VAA_View_Admin_As.prefix+root+'-role-defaults-enable input#' + prefix + '-role-defaults-enable', function( e ) { e.preventDefault(); var viewAs = { role_defaults : { enable : 0 } }; if ( this.checked ) { @@ -484,8 +570,11 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { VAA_View_Admin_As.ajax( viewAs, true ); }); - // Enable apply defaults on register - $(document).on('change', VAA_View_Admin_As.prefix+'#wp-admin-bar-role-defaults-setting-register-enable input#vaa_role_defaults_register_enable', function( e ) { + root = VAA_View_Admin_As.root + '-role-defaults'; + prefix = 'vaa-role-defaults'; + + // @since 1.4 Enable apply defaults on register + $(document).on('change', VAA_View_Admin_As.prefix+root+'-setting-register-enable input#' + prefix + '-setting-register-enable', function( e ) { e.preventDefault(); var viewAs = { role_defaults : { apply_defaults_on_register : 0 } }; if ( this.checked ) { @@ -494,8 +583,8 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { VAA_View_Admin_As.ajax( viewAs, false ); }); - // Disable screen settings for users who can't access this plugin - $(document).on('change', VAA_View_Admin_As.prefix+'#wp-admin-bar-role-defaults-setting-disable-user-screen-options input#vaa_role_defaults_disable_user_screen_options', function( e ) { + // @since 1.5.3 Disable screen settings for users who can't access this plugin + $(document).on('change', VAA_View_Admin_As.prefix+root+'-setting-disable-user-screen-options input#' + prefix + '-setting-disable-user-screen-options', function( e ) { e.preventDefault(); var viewAs = { role_defaults : { disable_user_screen_options : 0 } }; if ( this.checked ) { @@ -504,8 +593,8 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { VAA_View_Admin_As.ajax( viewAs, false ); }); - // Lock meta box order and locations for users who can't access this plugin - $(document).on('change', VAA_View_Admin_As.prefix+'#wp-admin-bar-role-defaults-setting-lock-meta-boxes input#vaa_role_defaults_lock_meta_boxes', function( e ) { + // @since 1.6 Lock meta box order and locations for users who can't access this plugin + $(document).on('change', VAA_View_Admin_As.prefix+root+'-setting-lock-meta-boxes input#' + prefix + '-setting-lock-meta-boxes', function( e ) { e.preventDefault(); var viewAs = { role_defaults : { lock_meta_boxes : 0 } }; if ( this.checked ) { @@ -514,12 +603,12 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { VAA_View_Admin_As.ajax( viewAs, false ); }); - // Filter users - $(document).on('keyup', VAA_View_Admin_As.prefix+'#wp-admin-bar-role-defaults-bulk-users-filter input#role-defaults-bulk-users-filter', function( e ) { + // @since 1.4 Filter users + $(document).on('keyup', VAA_View_Admin_As.prefix+root+'-bulk-users-filter input#' + prefix + '-bulk-users-filter', function( e ) { e.preventDefault(); if ( $(this).val().length >= 1 ) { var inputText = $(this).val(); - $(VAA_View_Admin_As.prefix+'#wp-admin-bar-role-defaults-bulk-users-select .ab-item.vaa-item').each( function() { + $(VAA_View_Admin_As.prefix+root+'-bulk-users-select .ab-item.vaa-item').each( function() { var name = $('.user-name', this).text(); if ( name.toLowerCase().indexOf( inputText.toLowerCase() ) > -1 ) { $(this).show(); @@ -528,17 +617,20 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { } }); } else { - $(VAA_View_Admin_As.prefix+'#wp-admin-bar-role-defaults-bulk-users-select .ab-item.vaa-item').each( function() { + $(VAA_View_Admin_As.prefix+root+'-bulk-users-select .ab-item.vaa-item').each( function() { $(this).show(); }); } }); - // Apply defaults to users - $(document).on('click', VAA_View_Admin_As.prefix+'#wp-admin-bar-role-defaults-bulk-users-apply button#role-defaults-bulk-users-apply', function( e ) { + // @since 1.4 Apply defaults to users + $(document).on('click touchend', VAA_View_Admin_As.prefix+root+'-bulk-users-apply button#' + prefix + '-bulk-users-apply', function( e ) { + if ( true === VAA_View_Admin_As._touchmove ) { + return; + } e.preventDefault(); var val = []; - $(VAA_View_Admin_As.prefix+'#wp-admin-bar-role-defaults-bulk-users-select .ab-item.vaa-item input').each( function() { + $(VAA_View_Admin_As.prefix+root+'-bulk-users-select .ab-item.vaa-item input').each( function() { if ( $(this).is(':checked') ) { val.push( $(this).val() ); } @@ -550,10 +642,13 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { return false; }); - // Apply defaults to users by role - $(document).on('click', VAA_View_Admin_As.prefix+'#wp-admin-bar-role-defaults-bulk-roles-apply button#role-defaults-bulk-roles-apply', function( e ) { + // @since 1.4 Apply defaults to users by role + $(document).on('click touchend', VAA_View_Admin_As.prefix+root+'-bulk-roles-apply button#' + prefix + '-bulk-roles-apply', function( e ) { + if ( true === VAA_View_Admin_As._touchmove ) { + return; + } e.preventDefault(); - var val = $(VAA_View_Admin_As.prefix+'#wp-admin-bar-role-defaults-bulk-roles-select select#role-defaults-bulk-roles-select').val(); + var val = $(VAA_View_Admin_As.prefix+root+'-bulk-roles-select select#' + prefix + '-bulk-roles-select').val(); if ( val && '' !== val ) { var viewAs = { role_defaults : { apply_defaults_to_users_by_role : val } }; VAA_View_Admin_As.ajax( viewAs, false ); @@ -561,10 +656,13 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { return false; }); - // Clear role defaults - $(document).on('click', VAA_View_Admin_As.prefix+'#wp-admin-bar-role-defaults-clear-roles-apply button#role-defaults-clear-roles-apply', function( e ) { + // @since 1.4 Clear role defaults + $(document).on('click touchend', VAA_View_Admin_As.prefix+root+'-clear-roles-apply button#' + prefix + '-clear-roles-apply', function( e ) { + if ( true === VAA_View_Admin_As._touchmove ) { + return; + } e.preventDefault(); - var val = $(VAA_View_Admin_As.prefix+'#wp-admin-bar-role-defaults-clear-roles-select select#role-defaults-clear-roles-select').val(); + var val = $(VAA_View_Admin_As.prefix+root+'-clear-roles-select select#' + prefix + '-clear-roles-select').val(); if ( val && '' !== val ) { var viewAs = { role_defaults : { clear_role_defaults : val } }; if ( confirm( VAA_View_Admin_As.__confirm ) ) { @@ -574,10 +672,13 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { return false; }); - // Export role defaults - $(document).on('click', VAA_View_Admin_As.prefix+'#wp-admin-bar-role-defaults-export-roles-export button#role-defaults-export-roles-export', function( e ) { + // @since 1.5 Export role defaults + $(document).on('click touchend', VAA_View_Admin_As.prefix+root+'-export-roles-export button#' + prefix + '-export-roles-export', function( e ) { + if ( true === VAA_View_Admin_As._touchmove ) { + return; + } e.preventDefault(); - var val = $(VAA_View_Admin_As.prefix+'#wp-admin-bar-role-defaults-export-roles-select select#role-defaults-export-roles-select').val(); + var val = $(VAA_View_Admin_As.prefix+root+'-export-roles-select select#' + prefix + '-export-roles-select').val(); if ( val && '' !== val ) { var viewAs = { role_defaults : { export_role_defaults : val } }; VAA_View_Admin_As.ajax( viewAs, false ); @@ -585,10 +686,13 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { return false; }); - // Import role defaults - $(document).on('click', VAA_View_Admin_As.prefix+'#wp-admin-bar-role-defaults-import-roles-import button#role-defaults-import-roles-import', function( e ) { + // @since 1.5 Import role defaults + $(document).on('click touchend', VAA_View_Admin_As.prefix+root+'-import-roles-import button#' + prefix + '-import-roles-import', function( e ) { + if ( true === VAA_View_Admin_As._touchmove ) { + return; + } e.preventDefault(); - var val = $(VAA_View_Admin_As.prefix+'#wp-admin-bar-role-defaults-import-roles-input textarea#role-defaults-import-roles-input').val(); + var val = $(VAA_View_Admin_As.prefix+root+'-import-roles-input textarea#' + prefix + '-import-roles-input').val(); if ( val && '' !== val ) { var viewAs = { role_defaults : { import_role_defaults : val } }; VAA_View_Admin_As.ajax( viewAs, false ); @@ -604,4 +708,4 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) { } -})( jQuery ); \ No newline at end of file +} )( jQuery ); \ No newline at end of file diff --git a/assets/js/view-admin-as.min.js b/assets/js/view-admin-as.min.js index 20e0b620..2fa77d81 100644 --- a/assets/js/view-admin-as.min.js +++ b/assets/js/view-admin-as.min.js @@ -4,7 +4,7 @@ * * @author Jory Hogeveen * @package view-admin-as - * @version 1.6 + * @version 1.6.1 */ -if("undefined"==typeof VAA_View_Admin_As)var VAA_View_Admin_As={ajaxurl:null,siteurl:"",_debug:!1,_vaa_nonce:"",__no_users_found:"No users found.",__success:"Success",__confirm:"Are you sure?"};!function(e){VAA_View_Admin_As.prefix="#wpadminbar #wp-admin-bar-view-as ","undefined"==typeof VAA_View_Admin_As._debug?VAA_View_Admin_As._debug=0:VAA_View_Admin_As._debug=parseInt(VAA_View_Admin_As._debug),"undefined"==typeof VAA_View_Admin_As.ajaxurl&&"undefined"!=typeof ajaxurl&&(VAA_View_Admin_As.ajaxurl=ajaxurl),VAA_View_Admin_As.init=function(){VAA_View_Admin_As.init_caps(),VAA_View_Admin_As.init_roles(),VAA_View_Admin_As.init_users(),VAA_View_Admin_As.init_settings(),VAA_View_Admin_As.init_module_role_defaults(),e(window).load(function(){e(VAA_View_Admin_As.prefix+".ab-vaa-toggle").each(function(){var i=e(this).parent().children().not(".ab-vaa-toggle");e(this).hasClass("active")||i.hide(),e(this).click(function(a){a.preventDefault(),e(this).hasClass("active")?(i.slideUp("fast"),e(this).removeClass("active")):(i.slideDown("fast"),e(this).addClass("active"))})})}),e(document).on("click",VAA_View_Admin_As.prefix+".vaa-reset-item > .ab-item",function(i){return i.preventDefault(),"reload"!=e("button",this).attr("name")?(viewAs={reset:!0},VAA_View_Admin_As.ajax(viewAs,!0),!1):void window.location.reload()})},VAA_View_Admin_As.ajax=function(i,a){var t=e("body");e("#wpadminbar .vaa-update").remove(),t.append('
      "),e("body #vaa-overlay").fadeIn("fast");var s=!1;e(VAA_View_Admin_As.prefix).hasClass("fullPopupActive")&&(s=!0,e(VAA_View_Admin_As.prefix).removeClass("fullPopupActive"));var n={action:"view_admin_as",_vaa_nonce:VAA_View_Admin_As._vaa_nonce,view_admin_as:i};if(!e(VAA_View_Admin_As.prefix+"#vaa_settings_view_mode_single").is(":checked")||"undefined"==typeof i.caps&&"undefined"==typeof i.role&&"undefined"==typeof i.user)e.post(VAA_View_Admin_As.ajaxurl,n,function(i){1===VAA_View_Admin_As._debug&&console.log(i),"undefined"!=typeof i.success&&!0===i.success?!1===a?"undefined"!=typeof i.data&&"undefined"!=typeof i.data.content?("undefined"==typeof i.data.type&&(i.data.type="default"),"object"!=typeof i.data.content&&(i.data.content=String(i.data.content)),VAA_View_Admin_As.overlay(i.data.content,String(i.data.type))):(e("body #vaa-overlay").addClass("success").fadeOut("fast",function(){e(this).remove()}),VAA_View_Admin_As.notice(VAA_View_Admin_As.__success,"success")):window.location.replace(window.location.href.replace("?reset-view","").replace("&reset-view","")):(e("body #vaa-overlay").addClass("error").fadeOut("fast",function(){e(this).remove()}),!0===s&&e(VAA_View_Admin_As.prefix).addClass("fullPopupActive"),"undefined"!=typeof i.data&&("undefined"!=typeof i.data.content?("undefined"==typeof i.data.type&&(i.data.type="error"),VAA_View_Admin_As.notice(i.data.content,i.data.type)):VAA_View_Admin_As.notice(i.data,"error")))});else{t.append('');var _=e("#vaa_single_mode_form");_.append(''),_.append(''),_.append(''),_.find("#data").val(JSON.stringify(n.view_admin_as)),_.submit()}},VAA_View_Admin_As.notice=function(i,a){e("#wp-admin-bar-top-secondary").append('
    • '+i+"
    • "),e("#wpadminbar .vaa-update .remove").click(function(){e(this).parent().remove()}),setTimeout(function(){e("#wpadminbar .vaa-update").fadeOut("fast",function(){e(this).remove()})},5e3)},VAA_View_Admin_As.overlay=function(i,a){e("body #vaa-overlay").html('
      '),"textarea"==a?("undefined"!=typeof i.text&&e("body #vaa-overlay .vaa-response-data").append("

      "+i.text+"

      "),"undefined"!=typeof i.textareacontent&&(e("body #vaa-overlay .vaa-response-data").append('"),e("body #vaa-overlay .vaa-response-data textarea").click(function(){e(this).select()}))):"errorlist"==a?("undefined"!=typeof i.text&&e("body #vaa-overlay .vaa-response-data").append("

      "+i.text+"

      "),"undefined"!=typeof i.errors&&(e("body #vaa-overlay .vaa-response-data").append('
        '),i.errors.forEach(function(i){e("body #vaa-overlay .vaa-response-data .errorlist").append("
      • "+i+"
      • ")}))):e("body #vaa-overlay .vaa-response-data").append("
        "+i+"
        "),e("#vaa-overlay .vaa-overlay-container .remove").click(function(){e("body #vaa-overlay").fadeOut("fast",function(){e(this).remove()})}),e(document).mouseup(function(i){e("body #vaa-overlay .vaa-overlay-container").each(function(){e(this).is(i.target)||0!==e(this).has(i.target).length||e("body #vaa-overlay").fadeOut("fast",function(){e(this).remove()})})})},VAA_View_Admin_As.init_settings=function(){e(document).on("change",VAA_View_Admin_As.prefix+"#wp-admin-bar-settings-admin-menu-location select#vaa_settings_admin_menu_location",function(i){i.preventDefault();var a=e(this).val();if(a&&""!==a){var t={user_setting:{admin_menu_location:a}};VAA_View_Admin_As.ajax(t,!0)}}),e(document).on("change",VAA_View_Admin_As.prefix+"#wp-admin-bar-settings-view-mode input.radio.vaa_settings_view_mode",function(i){i.preventDefault();var a=e(this).val();if(a&&""!==a){var t={user_setting:{view_mode:a}};VAA_View_Admin_As.ajax(t,!1)}}),e(document).on("change",VAA_View_Admin_As.prefix+"#wp-admin-bar-settings-force-group-users input#vaa_settings_force_group_users",function(e){e.preventDefault();var i={user_setting:{force_group_users:"no"}};this.checked&&(i={user_setting:{force_group_users:"yes"}}),VAA_View_Admin_As.ajax(i,!0)}),e(document).on("change",VAA_View_Admin_As.prefix+"#wp-admin-bar-settings-hide-front input#vaa_settings_hide_front",function(e){e.preventDefault();var i={user_setting:{hide_front:"no"}};this.checked&&(i={user_setting:{hide_front:"yes"}}),VAA_View_Admin_As.ajax(i,!1)})},VAA_View_Admin_As.init_roles=function(){e(document).on("click",VAA_View_Admin_As.prefix+".vaa-role-item > a.ab-item",function(i){if(i.preventDefault(),!e(this).parent().hasClass("not-a-view")){var a={role:String(e(this).attr("rel"))};return VAA_View_Admin_As.ajax(a,!0),!1}})},VAA_View_Admin_As.init_users=function(){e(document).on("click",VAA_View_Admin_As.prefix+".vaa-user-item > a.ab-item",function(i){if(i.preventDefault(),!e(this).parent().hasClass("not-a-view")){var a={user:parseInt(e(this).attr("rel"))};return VAA_View_Admin_As.ajax(a,!0),!1}}),e(document).on("keyup",VAA_View_Admin_As.prefix+"#wp-admin-bar-users .ab-vaa-search.search-users input",function(){if(e(VAA_View_Admin_As.prefix+" .ab-vaa-search #vaa-searchuser-results").empty(),1<=e(this).val().length){var i=e(this).val();e(VAA_View_Admin_As.prefix+".vaa-user-item").each(function(){var a=e(".ab-item",this).text();if(-1-1&&(t=e(this))});var s=e(this).parents(".vaa-role-item").children(".ab-item").attr("rel");!1!==t&&t.length?t.find(".user-role").text(t.find(".user-role").text().replace(")",", "+s+")")):e(this).clone().appendTo(VAA_View_Admin_As.prefix+".ab-vaa-search #vaa-searchuser-results").children(".ab-item").append('   ('+s+")")}}),""===e.trim(e(VAA_View_Admin_As.prefix+".ab-vaa-search #vaa-searchuser-results").html())&&e(VAA_View_Admin_As.prefix+".ab-vaa-search #vaa-searchuser-results").append('
        '+VAA_View_Admin_As.__no_users_found+"
        ")}})},VAA_View_Admin_As.init_caps=function(){VAA_View_Admin_As.caps_filter_settings={selectedRole:"default",selectedRoleCaps:{},selectedRoleReverse:!1,filterString:""},VAA_View_Admin_As.filter_capabilities=function(){e(VAA_View_Admin_As.prefix+" #wp-admin-bar-caps-quickselect-options .vaa-cap-item").each(function(){var i;!0===VAA_View_Admin_As.caps_filter_settings.selectedRoleReverse?(e(this).hide(),1<=VAA_View_Admin_As.caps_filter_settings.filterString.length?(i=e(this).text(),-1 .ab-sub-wrapper").addClass("fullPopup")}),e(document).on("click",VAA_View_Admin_As.prefix+"#wp-admin-bar-caps #close-caps-popup",function(){e(VAA_View_Admin_As.prefix).removeClass("fullPopupActive"),e(VAA_View_Admin_As.prefix+"#wp-admin-bar-caps-quickselect > .ab-sub-wrapper").removeClass("fullPopup")}),e(document).on("change",VAA_View_Admin_As.prefix+"#wp-admin-bar-caps .ab-vaa-select.select-role-caps select",function(){if(VAA_View_Admin_As.caps_filter_settings.selectedRole=e(this).val(),"default"==VAA_View_Admin_As.caps_filter_settings.selectedRole)VAA_View_Admin_As.caps_filter_settings.selectedRoleCaps={},VAA_View_Admin_As.caps_filter_settings.selectedRoleReverse=!1;else{var i=e(VAA_View_Admin_As.prefix+' #wp-admin-bar-selectrolecaps #select-role-caps option[value="'+VAA_View_Admin_As.caps_filter_settings.selectedRole+'"]');VAA_View_Admin_As.caps_filter_settings.selectedRoleCaps=JSON.parse(i.attr("data-caps")),"1"==i.attr("data-reverse")?VAA_View_Admin_As.caps_filter_settings.selectedRoleReverse=!0:VAA_View_Admin_As.caps_filter_settings.selectedRoleReverse=!1}VAA_View_Admin_As.filter_capabilities()}),e(document).on("keyup",VAA_View_Admin_As.prefix+"#wp-admin-bar-caps .ab-vaa-filter input",function(){1<=e(this).val().length?VAA_View_Admin_As.caps_filter_settings.filterString=e(this).val():VAA_View_Admin_As.caps_filter_settings.filterString="",VAA_View_Admin_As.filter_capabilities()}),e(document).on("click",VAA_View_Admin_As.prefix+"#wp-admin-bar-caps button#select-all-caps",function(i){return i.preventDefault(),e(VAA_View_Admin_As.prefix+"#wp-admin-bar-caps-quickselect-options .vaa-cap-item").each(function(){e(this).is(":visible")&&e("input",this).prop("checked",!0)}),!1}),e(document).on("click",VAA_View_Admin_As.prefix+"#wp-admin-bar-caps button#deselect-all-caps",function(i){return i.preventDefault(),e(VAA_View_Admin_As.prefix+"#wp-admin-bar-caps-quickselect-options .vaa-cap-item").each(function(){e(this).is(":visible")&&e("input",this).prop("checked",!1)}),!1}),e(document).on("click",VAA_View_Admin_As.prefix+"#wp-admin-bar-caps button#apply-caps-view",function(i){i.preventDefault();var a="";return e(VAA_View_Admin_As.prefix+"#wp-admin-bar-caps-quickselect-options .vaa-cap-item input").each(function(){a+=e(this).is(":checked")?e(this).attr("value")+":1,":e(this).attr("value")+":0,"}),VAA_View_Admin_As.ajax({caps:a},!0),!1})},VAA_View_Admin_As.init_module_role_defaults=function(){e(document).on("change",VAA_View_Admin_As.prefix+"#wp-admin-bar-settings-role-defaults-enable input#vaa_role_defaults_enable",function(e){e.preventDefault();var i={role_defaults:{enable:0}};this.checked&&(i={role_defaults:{enable:!0}}),VAA_View_Admin_As.ajax(i,!0)}),e(document).on("change",VAA_View_Admin_As.prefix+"#wp-admin-bar-role-defaults-setting-register-enable input#vaa_role_defaults_register_enable",function(e){e.preventDefault();var i={role_defaults:{apply_defaults_on_register:0}};this.checked&&(i={role_defaults:{apply_defaults_on_register:!0}}),VAA_View_Admin_As.ajax(i,!1)}),e(document).on("change",VAA_View_Admin_As.prefix+"#wp-admin-bar-role-defaults-setting-disable-user-screen-options input#vaa_role_defaults_disable_user_screen_options",function(e){e.preventDefault();var i={role_defaults:{disable_user_screen_options:0}};this.checked&&(i={role_defaults:{disable_user_screen_options:!0}}),VAA_View_Admin_As.ajax(i,!1)}),e(document).on("change",VAA_View_Admin_As.prefix+"#wp-admin-bar-role-defaults-setting-lock-meta-boxes input#vaa_role_defaults_lock_meta_boxes",function(e){e.preventDefault();var i={role_defaults:{lock_meta_boxes:0}};this.checked&&(i={role_defaults:{lock_meta_boxes:!0}}),VAA_View_Admin_As.ajax(i,!1)}),e(document).on("keyup",VAA_View_Admin_As.prefix+"#wp-admin-bar-role-defaults-bulk-users-filter input#role-defaults-bulk-users-filter",function(i){if(i.preventDefault(),e(this).val().length>=1){var a=e(this).val();e(VAA_View_Admin_As.prefix+"#wp-admin-bar-role-defaults-bulk-users-select .ab-item.vaa-item").each(function(){var i=e(".user-name",this).text();i.toLowerCase().indexOf(a.toLowerCase())>-1?e(this).show():e(this).hide()})}else e(VAA_View_Admin_As.prefix+"#wp-admin-bar-role-defaults-bulk-users-select .ab-item.vaa-item").each(function(){e(this).show()})}),e(document).on("click",VAA_View_Admin_As.prefix+"#wp-admin-bar-role-defaults-bulk-users-apply button#role-defaults-bulk-users-apply",function(i){i.preventDefault();var a=[];if(e(VAA_View_Admin_As.prefix+"#wp-admin-bar-role-defaults-bulk-users-select .ab-item.vaa-item input").each(function(){e(this).is(":checked")&&a.push(e(this).val())}),a){var t={role_defaults:{apply_defaults_to_users:a}};VAA_View_Admin_As.ajax(t,!1)}return!1}),e(document).on("click",VAA_View_Admin_As.prefix+"#wp-admin-bar-role-defaults-bulk-roles-apply button#role-defaults-bulk-roles-apply",function(i){i.preventDefault();var a=e(VAA_View_Admin_As.prefix+"#wp-admin-bar-role-defaults-bulk-roles-select select#role-defaults-bulk-roles-select").val();if(a&&""!==a){var t={role_defaults:{apply_defaults_to_users_by_role:a}};VAA_View_Admin_As.ajax(t,!1)}return!1}),e(document).on("click",VAA_View_Admin_As.prefix+"#wp-admin-bar-role-defaults-clear-roles-apply button#role-defaults-clear-roles-apply",function(i){i.preventDefault();var a=e(VAA_View_Admin_As.prefix+"#wp-admin-bar-role-defaults-clear-roles-select select#role-defaults-clear-roles-select").val();if(a&&""!==a){var t={role_defaults:{clear_role_defaults:a}};confirm(VAA_View_Admin_As.__confirm)&&VAA_View_Admin_As.ajax(t,!1)}return!1}),e(document).on("click",VAA_View_Admin_As.prefix+"#wp-admin-bar-role-defaults-export-roles-export button#role-defaults-export-roles-export",function(i){i.preventDefault();var a=e(VAA_View_Admin_As.prefix+"#wp-admin-bar-role-defaults-export-roles-select select#role-defaults-export-roles-select").val();if(a&&""!==a){var t={role_defaults:{export_role_defaults:a}};VAA_View_Admin_As.ajax(t,!1)}return!1}),e(document).on("click",VAA_View_Admin_As.prefix+"#wp-admin-bar-role-defaults-import-roles-import button#role-defaults-import-roles-import",function(i){i.preventDefault();var a=e(VAA_View_Admin_As.prefix+"#wp-admin-bar-role-defaults-import-roles-input textarea#role-defaults-import-roles-input").val();if(a&&""!==a){var t={role_defaults:{import_role_defaults:a}};VAA_View_Admin_As.ajax(t,!1)}return!1})},"undefined"!=typeof VAA_View_Admin_As._vaa_nonce&&VAA_View_Admin_As.init()}(jQuery); \ No newline at end of file +if("undefined"==typeof VAA_View_Admin_As)var VAA_View_Admin_As={ajaxurl:null,siteurl:"",_debug:!1,_vaa_nonce:"",__no_users_found:"No users found.",__success:"Success",__confirm:"Are you sure?",view_as:!1};!function(e){VAA_View_Admin_As.prefix="#wpadminbar #wp-admin-bar-vaa ",VAA_View_Admin_As.root="#wp-admin-bar-vaa","undefined"==typeof VAA_View_Admin_As._debug?VAA_View_Admin_As._debug=0:VAA_View_Admin_As._debug=parseInt(VAA_View_Admin_As._debug),"undefined"==typeof VAA_View_Admin_As.ajaxurl&&"undefined"!=typeof ajaxurl&&(VAA_View_Admin_As.ajaxurl=ajaxurl),VAA_View_Admin_As._touchmove=!1,e(document).on("touchmove",function(){VAA_View_Admin_As._touchmove=!0}),e(document).on("touchstart",function(){VAA_View_Admin_As._touchmove=!1}),VAA_View_Admin_As.init=function(){VAA_View_Admin_As.init_caps(),VAA_View_Admin_As.init_roles(),VAA_View_Admin_As.init_users(),VAA_View_Admin_As.init_settings(),VAA_View_Admin_As.init_module_role_defaults(),e(window).load(function(){e(VAA_View_Admin_As.prefix+".ab-vaa-toggle").each(function(){var i=e(this).parent().children().not(".ab-vaa-toggle");e(this).hasClass("active")||i.hide(),e(this).on("click",function(t){t.preventDefault(),e(this).hasClass("active")?(i.slideUp("fast"),e(this).removeClass("active")):(i.slideDown("fast"),e(this).addClass("active"))}),e(this).on("keyup",function(t){t.preventDefault();var s=t.which;!e(this).hasClass("active")||13!=s&&32!=s&&38!=s?13!=s&&32!=s&&40!=s||(i.slideDown("fast"),e(this).addClass("active")):(i.slideUp("fast"),e(this).removeClass("active"))})})}),e(document).on("click touchend",VAA_View_Admin_As.prefix+".vaa-reset-item > .ab-item",function(i){return i.preventDefault(),!0!==VAA_View_Admin_As._touchmove?"vaa_reload"!=e("button",this).attr("name")?(VAA_View_Admin_As.ajax({reset:!0},!0),!1):void window.location.reload():void 0})},VAA_View_Admin_As.ajax=function(i,t){var s=e("body");e("#wpadminbar .vaa-update").remove(),s.append('
        "),e("body #vaa-overlay").fadeIn("fast");var n=!1;e(VAA_View_Admin_As.prefix).hasClass("fullPopupActive")&&(n=!0,e(VAA_View_Admin_As.prefix).removeClass("fullPopupActive"));var a={action:"view_admin_as",_vaa_nonce:VAA_View_Admin_As._vaa_nonce,view_admin_as:i};if(!e(VAA_View_Admin_As.prefix+"#vaa-settings-view-mode-single").is(":checked")||"undefined"==typeof i.caps&&"undefined"==typeof i.role&&"undefined"==typeof i.user)e.post(VAA_View_Admin_As.ajaxurl,a,function(i){1===VAA_View_Admin_As._debug&&console.log(i),"undefined"!=typeof i.success&&!0===i.success?!1===t?"undefined"!=typeof i.data&&"undefined"!=typeof i.data.content?("undefined"==typeof i.data.type&&(i.data.type="default"),"object"!=typeof i.data.content&&(i.data.content=String(i.data.content)),VAA_View_Admin_As.overlay(i.data.content,String(i.data.type))):(e("body #vaa-overlay").addClass("success").fadeOut("fast",function(){e(this).remove()}),VAA_View_Admin_As.notice(VAA_View_Admin_As.__success,"success")):(window.location.hash="",window.location.replace(window.location.href.replace("#","").replace("?reset-view","").replace("&reset-view","").replace("?reset-all-views","").replace("&reset-all-views",""))):(e("body #vaa-overlay").addClass("error").fadeOut("fast",function(){e(this).remove()}),!0===n&&e(VAA_View_Admin_As.prefix).addClass("fullPopupActive"),"undefined"!=typeof i.data&&("undefined"!=typeof i.data.content?("undefined"==typeof i.data.type&&(i.data.type="error"),VAA_View_Admin_As.notice(i.data.content,i.data.type)):VAA_View_Admin_As.notice(i.data,"error")))});else{s.append('');var _=e("#vaa_single_mode_form");_.append(''),_.append(''),_.append(''),_.find("#data").val(JSON.stringify(a.view_admin_as)),_.submit()}},VAA_View_Admin_As.notice=function(i,t){e("#wp-admin-bar-top-secondary").append('
      • '+i+"
      • "),e("#wpadminbar .vaa-update .remove").click(function(){e(this).parent().remove()}),setTimeout(function(){e("#wpadminbar .vaa-update").fadeOut("fast",function(){e(this).remove()})},5e3)},VAA_View_Admin_As.overlay=function(i,t){var s="body #vaa-overlay";e(s).html('
        '),"textarea"==t?("undefined"!=typeof i.text&&e(s+" .vaa-response-data").append("

        "+i.text+"

        "),"undefined"!=typeof i.textareacontent&&(e(s+" .vaa-response-data").append('"),e(s+" .vaa-response-data textarea").click(function(){e(this).select()}))):"errorlist"==t?("undefined"!=typeof i.text&&e(s+" .vaa-response-data").append("

        "+i.text+"

        "),"undefined"!=typeof i.errors&&(e(s+" .vaa-response-data").append('
          '),i.errors.forEach(function(i){e(s+" .vaa-response-data .errorlist").append("
        • "+i+"
        • ")}))):e(s+" .vaa-response-data").append("
          "+i+"
          "),e(s+" .vaa-overlay-container .remove").click(function(){e(s).fadeOut("fast",function(){e(this).remove()})}),e(document).mouseup(function(i){e(s+" .vaa-overlay-container").each(function(){e(this).is(i.target)||0!==e(this).has(i.target).length||e(s).fadeOut("fast",function(){e(this).remove()})})})},VAA_View_Admin_As.init_settings=function(){var i=VAA_View_Admin_As.root+"-settings",t="vaa-settings";e(document).on("change",VAA_View_Admin_As.prefix+i+"-admin-menu-location select#"+t+"-admin-menu-location",function(i){i.preventDefault();var t=e(this).val();if(t&&""!==t){var s={user_setting:{admin_menu_location:t}};VAA_View_Admin_As.ajax(s,!0)}}),e(document).on("change",VAA_View_Admin_As.prefix+i+"-view-mode input.radio."+t+"-view-mode",function(i){i.preventDefault();var t=e(this).val();if(t&&""!==t){var s={user_setting:{view_mode:t}};VAA_View_Admin_As.ajax(s,!1)}}),e(document).on("change",VAA_View_Admin_As.prefix+i+"-force-group-users input#"+t+"-force-group-users",function(e){e.preventDefault();var i={user_setting:{force_group_users:"no"}};this.checked&&(i={user_setting:{force_group_users:"yes"}}),VAA_View_Admin_As.ajax(i,!0)}),e(document).on("change",VAA_View_Admin_As.prefix+i+"-hide-front input#"+t+"-hide-front",function(e){e.preventDefault();var i={user_setting:{hide_front:"no"}};this.checked&&(i={user_setting:{hide_front:"yes"}}),VAA_View_Admin_As.ajax(i,!1)}),e(document).on("change",VAA_View_Admin_As.prefix+i+"-freeze-locale input#"+t+"-freeze-locale",function(e){e.preventDefault();var i={user_setting:{freeze_locale:"no"}};this.checked&&(i={user_setting:{freeze_locale:"yes"}});var t=!1;"object"==typeof VAA_View_Admin_As.view_as&&"undefined"!=typeof VAA_View_Admin_As.view_as.user&&(t=!0),VAA_View_Admin_As.ajax(i,t)})},VAA_View_Admin_As.init_roles=function(){e(document).on("click touchend",VAA_View_Admin_As.prefix+".vaa-role-item > a.ab-item",function(i){if(!0!==VAA_View_Admin_As._touchmove&&(i.preventDefault(),!e(this).parent().hasClass("not-a-view"))){var t={role:String(e(this).attr("rel"))};return VAA_View_Admin_As.ajax(t,!0),!1}})},VAA_View_Admin_As.init_users=function(){var i=VAA_View_Admin_As.root+"-users";e(document).on("click touchend",VAA_View_Admin_As.prefix+".vaa-user-item > a.ab-item",function(i){if(!0!==VAA_View_Admin_As._touchmove&&(i.preventDefault(),!e(this).parent().hasClass("not-a-view"))){var t={user:parseInt(e(this).attr("rel"))};return VAA_View_Admin_As.ajax(t,!0),!1}}),e(document).on("keyup",VAA_View_Admin_As.prefix+i+" .ab-vaa-search.search-users input",function(){if(e(VAA_View_Admin_As.prefix+" .ab-vaa-search #vaa-searchuser-results").empty(),1<=e(this).val().length){var i=e(this).val();e(VAA_View_Admin_As.prefix+".vaa-user-item").each(function(){var t=e(".ab-item",this).text();if(-1-1&&(s=e(this))});var n=e(this).parents(".vaa-role-item").children(".ab-item").attr("rel");!1!==s&&s.length?s.find(".user-role").text(s.find(".user-role").text().replace(")",", "+n+")")):e(this).clone().appendTo(VAA_View_Admin_As.prefix+".ab-vaa-search #vaa-searchuser-results").children(".ab-item").append('   ('+n+")")}}),""===e.trim(e(VAA_View_Admin_As.prefix+".ab-vaa-search #vaa-searchuser-results").html())&&e(VAA_View_Admin_As.prefix+".ab-vaa-search #vaa-searchuser-results").append('
          '+VAA_View_Admin_As.__no_users_found+"
          ")}})},VAA_View_Admin_As.init_caps=function(){var i=VAA_View_Admin_As.root+"-caps";VAA_View_Admin_As.caps_filter_settings={selectedRole:"default",selectedRoleCaps:{},selectedRoleReverse:!1,filterString:""},VAA_View_Admin_As.filter_capabilities=function(){e(VAA_View_Admin_As.prefix+i+"-quickselect-options .vaa-cap-item").each(function(){var i;!0===VAA_View_Admin_As.caps_filter_settings.selectedRoleReverse?(e(this).hide(),1<=VAA_View_Admin_As.caps_filter_settings.filterString.length?(i=e(this).text(),-1 .ab-sub-wrapper").addClass("fullPopup")}),e(document).on("click",VAA_View_Admin_As.prefix+i+" #close-caps-popup",function(){e(VAA_View_Admin_As.prefix).removeClass("fullPopupActive"),e(VAA_View_Admin_As.prefix+i+"-quickselect > .ab-sub-wrapper").removeClass("fullPopup")}),e(document).on("change",VAA_View_Admin_As.prefix+i+" .ab-vaa-select.select-role-caps select",function(){if(VAA_View_Admin_As.caps_filter_settings.selectedRole=e(this).val(),"default"==VAA_View_Admin_As.caps_filter_settings.selectedRole)VAA_View_Admin_As.caps_filter_settings.selectedRoleCaps={},VAA_View_Admin_As.caps_filter_settings.selectedRoleReverse=!1;else{var t=e(VAA_View_Admin_As.prefix+i+'-selectrolecaps #vaa-caps-selectrolecaps option[value="'+VAA_View_Admin_As.caps_filter_settings.selectedRole+'"]');VAA_View_Admin_As.caps_filter_settings.selectedRoleCaps=JSON.parse(t.attr("data-caps")),"1"==t.attr("data-reverse")?VAA_View_Admin_As.caps_filter_settings.selectedRoleReverse=!0:VAA_View_Admin_As.caps_filter_settings.selectedRoleReverse=!1}VAA_View_Admin_As.filter_capabilities()}),e(document).on("keyup",VAA_View_Admin_As.prefix+i+" .ab-vaa-filter input",function(){1<=e(this).val().length?VAA_View_Admin_As.caps_filter_settings.filterString=e(this).val():VAA_View_Admin_As.caps_filter_settings.filterString="",VAA_View_Admin_As.filter_capabilities()}),e(document).on("click touchend",VAA_View_Admin_As.prefix+i+" button#select-all-caps",function(t){return!0!==VAA_View_Admin_As._touchmove?(t.preventDefault(),e(VAA_View_Admin_As.prefix+i+"-quickselect-options .vaa-cap-item").each(function(){e(this).is(":visible")&&e("input",this).prop("checked",!0)}),!1):void 0}),e(document).on("click touchend",VAA_View_Admin_As.prefix+i+" button#deselect-all-caps",function(t){return!0!==VAA_View_Admin_As._touchmove?(t.preventDefault(),e(VAA_View_Admin_As.prefix+i+"-quickselect-options .vaa-cap-item").each(function(){e(this).is(":visible")&&e("input",this).prop("checked",!1)}),!1):void 0}),e(document).on("click touchend",VAA_View_Admin_As.prefix+i+" button#apply-caps-view",function(t){if(!0!==VAA_View_Admin_As._touchmove){t.preventDefault();var s="";return e(VAA_View_Admin_As.prefix+i+"-quickselect-options .vaa-cap-item input").each(function(){s+=e(this).is(":checked")?e(this).attr("value")+":1,":e(this).attr("value")+":0,"}),VAA_View_Admin_As.ajax({caps:s},!0),!1}})},VAA_View_Admin_As.init_module_role_defaults=function(){var i=VAA_View_Admin_As.root+"-settings",t="vaa-settings";e(document).on("change",VAA_View_Admin_As.prefix+i+"-role-defaults-enable input#"+t+"-role-defaults-enable",function(e){e.preventDefault();var i={role_defaults:{enable:0}};this.checked&&(i={role_defaults:{enable:!0}}),VAA_View_Admin_As.ajax(i,!0)}),i=VAA_View_Admin_As.root+"-role-defaults",t="vaa-role-defaults",e(document).on("change",VAA_View_Admin_As.prefix+i+"-setting-register-enable input#"+t+"-setting-register-enable",function(e){e.preventDefault();var i={role_defaults:{apply_defaults_on_register:0}};this.checked&&(i={role_defaults:{apply_defaults_on_register:!0}}),VAA_View_Admin_As.ajax(i,!1)}),e(document).on("change",VAA_View_Admin_As.prefix+i+"-setting-disable-user-screen-options input#"+t+"-setting-disable-user-screen-options",function(e){e.preventDefault();var i={role_defaults:{disable_user_screen_options:0}};this.checked&&(i={role_defaults:{disable_user_screen_options:!0}}),VAA_View_Admin_As.ajax(i,!1)}),e(document).on("change",VAA_View_Admin_As.prefix+i+"-setting-lock-meta-boxes input#"+t+"-setting-lock-meta-boxes",function(e){e.preventDefault();var i={role_defaults:{lock_meta_boxes:0}};this.checked&&(i={role_defaults:{lock_meta_boxes:!0}}),VAA_View_Admin_As.ajax(i,!1)}),e(document).on("keyup",VAA_View_Admin_As.prefix+i+"-bulk-users-filter input#"+t+"-bulk-users-filter",function(t){if(t.preventDefault(),e(this).val().length>=1){var s=e(this).val();e(VAA_View_Admin_As.prefix+i+"-bulk-users-select .ab-item.vaa-item").each(function(){var i=e(".user-name",this).text();i.toLowerCase().indexOf(s.toLowerCase())>-1?e(this).show():e(this).hide()})}else e(VAA_View_Admin_As.prefix+i+"-bulk-users-select .ab-item.vaa-item").each(function(){e(this).show()})}),e(document).on("click touchend",VAA_View_Admin_As.prefix+i+"-bulk-users-apply button#"+t+"-bulk-users-apply",function(t){if(!0!==VAA_View_Admin_As._touchmove){t.preventDefault();var s=[];if(e(VAA_View_Admin_As.prefix+i+"-bulk-users-select .ab-item.vaa-item input").each(function(){e(this).is(":checked")&&s.push(e(this).val())}),s){var n={role_defaults:{apply_defaults_to_users:s}};VAA_View_Admin_As.ajax(n,!1)}return!1}}),e(document).on("click touchend",VAA_View_Admin_As.prefix+i+"-bulk-roles-apply button#"+t+"-bulk-roles-apply",function(s){if(!0!==VAA_View_Admin_As._touchmove){s.preventDefault();var n=e(VAA_View_Admin_As.prefix+i+"-bulk-roles-select select#"+t+"-bulk-roles-select").val();if(n&&""!==n){var a={role_defaults:{apply_defaults_to_users_by_role:n}};VAA_View_Admin_As.ajax(a,!1)}return!1}}),e(document).on("click touchend",VAA_View_Admin_As.prefix+i+"-clear-roles-apply button#"+t+"-clear-roles-apply",function(s){if(!0!==VAA_View_Admin_As._touchmove){s.preventDefault();var n=e(VAA_View_Admin_As.prefix+i+"-clear-roles-select select#"+t+"-clear-roles-select").val();if(n&&""!==n){var a={role_defaults:{clear_role_defaults:n}};confirm(VAA_View_Admin_As.__confirm)&&VAA_View_Admin_As.ajax(a,!1)}return!1}}),e(document).on("click touchend",VAA_View_Admin_As.prefix+i+"-export-roles-export button#"+t+"-export-roles-export",function(s){if(!0!==VAA_View_Admin_As._touchmove){s.preventDefault();var n=e(VAA_View_Admin_As.prefix+i+"-export-roles-select select#"+t+"-export-roles-select").val();if(n&&""!==n){var a={role_defaults:{export_role_defaults:n}};VAA_View_Admin_As.ajax(a,!1)}return!1}}),e(document).on("click touchend",VAA_View_Admin_As.prefix+i+"-import-roles-import button#"+t+"-import-roles-import",function(s){if(!0!==VAA_View_Admin_As._touchmove){s.preventDefault();var n=e(VAA_View_Admin_As.prefix+i+"-import-roles-input textarea#"+t+"-import-roles-input").val();if(n&&""!==n){var a={role_defaults:{import_role_defaults:n}};VAA_View_Admin_As.ajax(a,!1)}return!1}})},"undefined"!=typeof VAA_View_Admin_As._vaa_nonce&&VAA_View_Admin_As.init()}(jQuery); \ No newline at end of file diff --git a/includes/class-api.php b/includes/class-api.php index 3d7be444..89ea80c4 100644 --- a/includes/class-api.php +++ b/includes/class-api.php @@ -7,7 +7,7 @@ * @author Jory Hogeveen * @package view-admin-as * @since 1.6 - * @version 1.6 + * @version 1.6.1 */ ! defined( 'VIEW_ADMIN_AS_DIR' ) and die( 'You shall not pass!' ); @@ -17,9 +17,9 @@ final class VAA_API /** * Check if the user is a superior admin * - * @since 1.5.3 - * @since 1.6 Moved to this class from main class - * @access public + * @since 1.5.3 + * @since 1.6 Moved to this class from main class + * @access public * @static * @api * @@ -34,9 +34,9 @@ public static function is_superior_admin( $user_id ) { /** * 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 + * @since 1.5.3 + * @since 1.6 Moved to this class from main class + * @access public * @static * @api * @@ -121,12 +121,12 @@ final public static function set_array_data( $array, $var, $key = false, $append /** * Is our custom toolbar showing? * - * @since 1.6 - * @access public + * @since 1.6 + * @access public * @static * @api * - * @return bool + * @return bool */ public static function is_vaa_toolbar_showing() { @@ -139,25 +139,26 @@ public static function is_vaa_toolbar_showing() { /** * Appends the "reset-view" parameter to the current URL * - * @since 1.6 - * @access public + * @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 + * @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 = '', $all = false ) { if ( empty( $url ) ) { $url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; - // Check for existing query vars - $url_comp = parse_url( $url ); // Check protocol $url = ( ( is_ssl() ) ? 'https://' : 'http://' ) . $url; } + // Check for existing query vars + $url_comp = parse_url( $url ); + $reset = 'reset-view'; if ( $all ) { $reset = 'reset-all-views'; @@ -169,13 +170,13 @@ public static function get_reset_link( $url = '', $all = false ) { /** * Removes the "reset-view" or "reset-all-views" parameter to the current URL * - * @since 1.6 - * @access public + * @since 1.6 + * @access public * @static * @api * - * @param string $url (optional) Use a defined url to remove the reset link - * @return string + * @param string $url (optional) Use a defined url to remove the reset link + * @return string */ public static function remove_reset_link( $url = '' ) { diff --git a/includes/class-base.php b/includes/class-base.php index c2f3a526..c0f6fa8e 100644 --- a/includes/class-base.php +++ b/includes/class-base.php @@ -75,8 +75,9 @@ abstract class VAA_View_Admin_As_Class_Base * Protected to make sure it isn't declared elsewhere * * @since 1.5.3 - * @param object $vaa (optional) Pass VAA object + * @since 1.6 $vaa param * @access protected + * @param VAA_View_Admin_As $vaa (optional) Pass VAA object */ protected function __construct( $vaa = null ) { // Load resources @@ -87,12 +88,14 @@ protected function __construct( $vaa = null ) { * 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 + * @param VAA_View_Admin_As $vaa (optional) Pass VAA object * @return void */ - final public function load_vaa( $vaa ) { + final public function load_vaa( $vaa = null ) { $this->vaa = $vaa; - if ( null == $vaa ) { + if ( ! is_object( $vaa ) || 'VAA_View_Admin_As' != get_class( $vaa ) ) { $this->vaa = View_Admin_As( $this ); } $this->store = $this->vaa->store(); diff --git a/includes/class-compat.php b/includes/class-compat.php index 9e3aeae6..746cb451 100644 --- a/includes/class-compat.php +++ b/includes/class-compat.php @@ -7,7 +7,7 @@ * @author Jory Hogeveen * @package view-admin-as * @since 1.6 - * @version 1.6 + * @version 1.6.1 */ ! defined( 'VIEW_ADMIN_AS_DIR' ) and die( 'You shall not pass!' ); @@ -17,18 +17,22 @@ final class VAA_View_Admin_As_Compat extends VAA_View_Admin_As_Class_Base /** * The single instance of the class. * - * @since 1.6 - * @var VAA_View_Admin_As_Compat + * @since 1.6 + * @static + * @var VAA_View_Admin_As_Compat */ private static $_instance = null; /** * Populate the instance - * @since 1.6 + * @since 1.6 + * @since 1.6.1 $vaa param + * @access protected + * @param VAA_View_Admin_As $vaa */ - protected function __construct() { + protected function __construct( $vaa ) { self::$_instance = $this; - parent::__construct(); + parent::__construct( $vaa ); } /** @@ -41,28 +45,44 @@ protected function __construct() { */ public function init() { - if ( false !== $this->store->get_viewAs() ) { - // WooCommerce - remove_filter( 'show_admin_bar', 'wc_disable_admin_bar', 10 ); - } - - // Pods 2.x (only needed for the role selector) - if ( $this->store->get_viewAs('role') ) { - add_filter( 'pods_is_admin', array( $this, 'pods_caps_check' ), 10, 3 ); - } + add_action( 'vaa_view_admin_as_init', array( $this, 'init_after' ) ); /** * Add our caps to the members plugin - * @since 1.6 + * @since 1.6 */ add_filter( 'members_get_capabilities', array( $this, 'add_capabilities' ) ); add_action( 'members_register_cap_groups', array( $this, 'members_register_cap_group' ) ); - // Get caps from other plugins + /** + * Get caps from other plugins + * @since 1.5 + */ add_filter( 'view_admin_as_get_capabilities', array( $this, 'get_capabilities' ) ); } + /** + * 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 ( false !== $this->store->get_viewAs() ) { + // WooCommerce + remove_filter( 'show_admin_bar', 'wc_disable_admin_bar', 10 ); + }*/ + + if ( $this->store->get_viewAs('role') ) { + // Pods 2.x (only needed for the role selector) + add_filter( 'pods_is_admin', array( $this, 'pods_caps_check' ), 10, 3 ); + } + } + /** * Get's current capabilities and merges with capabilities from other plugins * @@ -125,9 +145,10 @@ public function pods_caps_check( $bool, $cap, $capability ) { } $role_caps = $this->store->get_roles( $this->store->get_viewAs('role') )->capabilities; - if ( ! array_key_exists( $cap, $role_caps ) || ( 1 != $role_caps[$cap] ) ) { + if ( ! array_key_exists( $cap, $role_caps ) || ( 1 != $role_caps[ $cap ] ) ) { return false; } + return true; } @@ -138,7 +159,7 @@ public function pods_caps_check( $bool, $cap, $capability ) { * @access public * @see init() */ - public function members_register_cap_group () { + public function members_register_cap_group() { if ( function_exists( 'members_register_cap_group' ) ) { // Register the vaa group. @@ -161,17 +182,17 @@ public function members_register_cap_group () { * @since 1.6 * @access public * @static - * @param object|bool $caller The referrer class - * @return VAA_View_Admin_As_Compat|bool + * @param VAA_View_Admin_As $caller The referrer class + * @return VAA_View_Admin_As_Compat */ - public static function get_instance( $caller = false ) { + public static function get_instance( $caller = null ) { if ( is_object( $caller ) && 'VAA_View_Admin_As' == get_class( $caller ) ) { if ( is_null( self::$_instance ) ) { - self::$_instance = new self(); + self::$_instance = new self( $caller ); } return self::$_instance; } - return false; + return null; } } // end class \ No newline at end of file diff --git a/includes/class-store.php b/includes/class-store.php index d07ceb52..0c6b668f 100644 --- a/includes/class-store.php +++ b/includes/class-store.php @@ -7,7 +7,7 @@ * @author Jory Hogeveen * @package view-admin-as * @since 1.6 - * @version 1.6 + * @version 1.6.1 */ ! defined( 'VIEW_ADMIN_AS_DIR' ) and die( 'You shall not pass!' ); @@ -17,8 +17,9 @@ final class VAA_View_Admin_As_Store /** * The single instance of the class. * - * @since 1.6 - * @var VAA_View_Admin_As_Store + * @since 1.6 + * @static + * @var VAA_View_Admin_As_Store */ private static $_instance = null; @@ -75,13 +76,15 @@ final class VAA_View_Admin_As_Store * @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 * @var array */ private $defaultUserSettings = array( - 'view_mode' => 'browse', 'admin_menu_location' => 'top-secondary', - 'force_group_users' => 'no', - 'hide_front' => 'no', + 'force_group_users' => 'no', + 'freeze_locale' => 'no', + 'hide_front' => 'no', + 'view_mode' => 'browse', ); /** @@ -91,13 +94,15 @@ final class VAA_View_Admin_As_Store * @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 * @var array */ private $allowedUserSettings = array( - 'view_mode' => array( 'browse', 'single' ), 'admin_menu_location' => array( 'top-secondary', 'my-account' ), - 'force_group_users' => array( 'yes', 'no' ), - 'hide_front' => array( 'yes', 'no' ), + 'force_group_users' => array( 'yes', 'no' ), + 'freeze_locale' => array( 'yes', 'no' ), + 'hide_front' => array( 'yes', 'no' ), + 'view_mode' => array( 'browse', 'single' ), ); /** @@ -128,7 +133,7 @@ final class VAA_View_Admin_As_Store * @since 1.6 Moved to this class from main class * @var array */ - private $caps; + private $caps = array(); /** * Array of available roles @@ -137,7 +142,7 @@ final class VAA_View_Admin_As_Store * @since 1.6 Moved to this class from main class * @var array */ - private $roles; + private $roles = array(); /** * Array of available user objects @@ -146,7 +151,7 @@ final class VAA_View_Admin_As_Store * @since 1.6 Moved to this class from main class * @var array */ - private $users; + private $users = array(); /** * Expiration time for view data @@ -193,7 +198,7 @@ final class VAA_View_Admin_As_Store * @since 1.6 Moved to this class from main class * @var array */ - private $usernames; + private $usernames = array(); /** * Array of available user ID's (key) and display names (value) @@ -202,7 +207,7 @@ final class VAA_View_Admin_As_Store * @since 1.6 Moved to this class from main class * @var array */ - private $userids; + private $userids = array(); /** * The selected user object (if the user view is selected) @@ -248,7 +253,8 @@ public function store_roles() { } } } - // @since 1.5.2.1 Merge role names with the role objects + + // @since 1.5.2.1 Merge role names with the role objects foreach ( $roles as $role_key => $role ) { if ( isset( $role_names[ $role_key ] ) ) { $roles[ $role_key ]->name = $role_names[ $role_key ]; @@ -268,6 +274,9 @@ public function store_roles() { */ public function store_users() { + // Load the superior admins + $superior_admins = VAA_API::get_superior_admins(); + // Is the current user a super admin? $is_super_admin = is_super_admin( $this->get_curUser()->ID ); // Is it also one of the manually configured superior admins? @@ -275,17 +284,17 @@ public function store_users() { if ( is_network_admin() ) { - // Get super admins (returns logins) + // Get super admins (returns login's) $users = get_super_admins(); // Remove current user if ( in_array( $this->get_curUser()->user_login, $users ) ) { unset( $users[ array_search( $this->get_curUser()->user_login, $users ) ] ); } - // Convert logins to WP_User objects and filter them for superior admins + // 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 ); - if ( $user && ! in_array( $user->user_login, VAA_API::get_superior_admins() ) ) { - $users[ $key ] = get_user_by( 'login', $user_login ); + if ( $user && ! in_array( $user->user_login, $superior_admins ) ) { + $users[ $key ] = $user; } else { unset( $users[ $key ] ); } @@ -296,7 +305,7 @@ public function store_users() { $user_args = array( 'orderby' => 'display_name', // @since 1.5.2 Exclude the current user - 'exclude' => array_merge( VAA_API::get_superior_admins(), array( $this->get_curUser()->ID ) ), + 'exclude' => array_merge( $superior_admins, array( $this->get_curUser()->ID ) ), ); // Do not get regular admins for normal installs (WP 4.4+) if ( ! is_multisite() && ! $is_superior_admin ) { @@ -308,14 +317,14 @@ public function store_users() { $userids = array(); $usernames = array(); - // Loop though all users + foreach ( $users as $user_key => $user ) { // If the current user is not a superior admin, run the user filters if ( true !== $is_superior_admin ) { /** - * Implement checks instead of is_super_admin() because it adds a lot unnecessary queries + * Implement checks instead of is_super_admin() because it adds a lot of unnecessary queries * * @since 1.5.2 * @See is_super_admin() @@ -356,8 +365,8 @@ public function store_users() { * * @see store_users() * - * @param array $users - * @return array $users + * @param array $users + * @return array $users */ public function filter_sort_users_by_role( $users ) { if ( ! $this->get_roles() ) { @@ -511,7 +520,7 @@ public function store_settings( $settings, $type ) { * * @param array $settings * @param string $type global / user - * @return array|bool $settings + * @return array|bool $settings / false */ public function validate_settings( $settings, $type ) { if ( $type == 'global' ) { @@ -545,7 +554,7 @@ public function validate_settings( $settings, $type ) { * * @param int|bool $user_id ID of the user being deleted/removed * @param object|bool $user User object provided by the wp_login hook - * @param bool $reset_only Only reset (not delet) the user meta + * @param bool $reset_only Only reset (not delete) the user meta * @return bool */ public function delete_user_meta( $user_id = false, $user = false, $reset_only = true ) { @@ -657,17 +666,17 @@ public function update_userMeta( $var, $key = false, $append = false ) { * @since 1.6 * @access public * @static - * @param object|bool $caller The referrer class - * @return VAA_View_Admin_As_Store|bool + * @param VAA_View_Admin_As $caller The referrer class + * @return VAA_View_Admin_As_Store */ - public static function get_instance( $caller = false ) { + public static function get_instance( $caller = null ) { if ( is_object( $caller ) && 'VAA_View_Admin_As' == get_class( $caller ) ) { if ( is_null( self::$_instance ) ) { - self::$_instance = new self(); + self::$_instance = new self( $caller ); } return self::$_instance; } - return false; + return null; } /** diff --git a/includes/class-update.php b/includes/class-update.php index 72962312..d6146a4a 100644 --- a/includes/class-update.php +++ b/includes/class-update.php @@ -7,7 +7,7 @@ * @author Jory Hogeveen * @package view-admin-as * @since 1.6 - * @version 1.6 + * @version 1.6.1 */ ! defined( 'VIEW_ADMIN_AS_DIR' ) and die( 'You shall not pass!' ); @@ -17,18 +17,22 @@ final class VAA_View_Admin_As_Update extends VAA_View_Admin_As_Class_Base /** * The single instance of the class. * - * @since 1.6 - * @var VAA_View_Admin_As_Update + * @since 1.6 + * @static + * @var VAA_View_Admin_As_Update */ private static $_instance = null; /** * Populate the instance - * @since 1.6 + * @since 1.6 + * @since 1.6.1 $vaa param + * @access protected + * @param VAA_View_Admin_As $vaa */ - protected function __construct() { + protected function __construct( $vaa ) { self::$_instance = $this; - parent::__construct(); + parent::__construct( $vaa ); } /** @@ -90,16 +94,16 @@ public function maybe_db_update() { * @since 1.6 * @access public * @static - * @param object|bool $caller The referrer class - * @return VAA_View_Admin_As_Update|bool + * @param VAA_View_Admin_As $caller The referrer class + * @return VAA_View_Admin_As_Update */ - public static function get_instance( $caller = false ) { + public static function get_instance( $caller = null ) { if ( is_object( $caller ) && 'VAA_View_Admin_As' == get_class( $caller ) ) { if ( is_null( self::$_instance ) ) { - self::$_instance = new self(); + self::$_instance = new self( $caller ); } return self::$_instance; } - return false; + return null; } } \ No newline at end of file diff --git a/includes/class-vaa.php b/includes/class-vaa.php index 9df2a19f..99108e70 100644 --- a/includes/class-vaa.php +++ b/includes/class-vaa.php @@ -7,7 +7,7 @@ * @author Jory Hogeveen * @package view-admin-as * @since 0.1 - * @version 1.6 + * @version 1.6.1 */ ! defined( 'VIEW_ADMIN_AS_DIR' ) and die( 'You shall not pass!' ); @@ -18,6 +18,7 @@ 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; @@ -25,9 +26,9 @@ final class VAA_View_Admin_As /** * Classes that are allowed to use this class * - * @see get_instance() - * * @since 1.6 + * @static + * @see get_instance() * @var array */ private static $vaa_class_names = array(); @@ -52,7 +53,7 @@ final class VAA_View_Admin_As * VAA Store * * @since 1.6 - * @var array + * @var VAA_View_Admin_As_Store */ private $store = null; @@ -60,7 +61,7 @@ final class VAA_View_Admin_As * VAA View handler * * @since 1.6 - * @var array + * @var VAA_View_Admin_As_View */ private $view = null; @@ -68,7 +69,8 @@ final class VAA_View_Admin_As * VAA UI classes that are loaded * * @since 1.5 - * @var array + * @see load_ui() + * @var array of objects */ private $ui = array(); @@ -76,7 +78,9 @@ final class VAA_View_Admin_As * Other VAA modules that are loaded * * @since 1.4 - * @var array + * @see load_modules() + * @see register_module() + * @var array of objects */ private $modules = array(); @@ -98,8 +102,8 @@ private function __construct() { add_action( 'admin_notices', array( $this, 'do_admin_notices' ) ); - // Returns true on conflict - if ( (boolean) $this->validate_versions() ) { + // Returns false on conflict + if ( ! (boolean) $this->validate_versions() ) { return; } @@ -113,7 +117,7 @@ private function __construct() { } else { - $this->add_notice('class-error-base', array( + $this->add_notice('class-error-core', array( 'type' => 'notice-error', 'message' => '' . __('View Admin As', 'view-admin-as') . ': ' . __('Plugin not loaded because of a conflict with an other plugin or theme', 'view-admin-as') @@ -127,8 +131,8 @@ private function __construct() { * Load required classes and files * Returns false on conflict * - * @since 1.6 - * @return bool + * @since 1.6 + * @return bool */ private function load() { @@ -163,8 +167,8 @@ private function load() { /** * Instantiate function that checks if the plugin is already loaded * - * @since 1.6 - * @access public + * @since 1.6 + * @access public */ public function init() { static $loaded = false; @@ -177,7 +181,7 @@ public function init() { /** * Run the plugin! - * Check current user, load nessesary data and register all used hooks + * Check current user, load necessary data and register all used hooks * * @since 0.1 * @access private @@ -190,6 +194,7 @@ private function run() { //add_action( 'wpmu_delete_user', array( $this->store, 'delete_user_meta' ) ); //add_action( 'wp_delete_user', array( $this->store, 'delete_user_meta' ) ); + // We can't do this check before `plugins_loaded` hook if ( is_user_logged_in() ) { $this->store->set_nonce( 'view-admin-as' ); @@ -215,7 +220,7 @@ private function run() { * 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 nedwork admin pages + * 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) @@ -223,8 +228,8 @@ private function run() { */ if ( ( is_super_admin( $this->store->get_curUser()->ID ) || ( 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() != '' + && ( ! is_network_admin() || VAA_API::is_superior_admin( $this->store->get_curUser()->ID ) ) + && $this->store->get_curUserSession() != '' ) { $this->enable = true; } @@ -268,7 +273,7 @@ private function run() { } else { // Extra security check for non-admins who did something naughty or we're demoted to a lesser role // If they have settings etc. we'll keep them in case they get promoted again - add_action( 'wp_login', array( $this, 'reset_all_views' ), 10, 2 ); + add_action( 'wp_login', array( $this->view, 'reset_all_views' ), 10, 2 ); } } } @@ -284,6 +289,20 @@ private function run() { */ private function load_ui() { + // WP admin modifications + if ( ! class_exists('VAA_View_Admin_As_Admin') ) { + require( VIEW_ADMIN_AS_DIR . 'ui/class-admin.php' ); + self::$vaa_class_names[] = 'VAA_View_Admin_As_Admin'; + $this->ui['admin'] = VAA_View_Admin_As_Admin::get_instance( $this ); + } else { + $this->add_notice('class-error-admin', array( + 'type' => 'notice-error', + 'message' => '' . __('View Admin As', 'view-admin-as') . ': ' + . __('Plugin not fully loaded because of a conflict with an other plugin or theme', 'view-admin-as') + . ' (' . sprintf( __('Class %s already exists', 'view-admin-as'), 'VAA_View_Admin_As_Admin' ) . ')', + ) ); + } + // The default admin bar ui if ( ! class_exists('VAA_View_Admin_As_Admin_Bar') ) { require( VIEW_ADMIN_AS_DIR . 'ui/class-admin-bar.php' ); @@ -293,7 +312,7 @@ private function load_ui() { $this->add_notice('class-error-admin-bar', array( 'type' => 'notice-error', 'message' => '' . __('View Admin As', 'view-admin-as') . ': ' - . __('Plugin not loaded because of a conflict with an other plugin or theme', 'view-admin-as') + . __('Plugin not fully loaded because of a conflict with an other plugin or theme', 'view-admin-as') . ' (' . sprintf( __('Class %s already exists', 'view-admin-as'), 'VAA_View_Admin_As_Admin_Bar' ) . ')', ) ); } @@ -307,24 +326,10 @@ private function load_ui() { $this->add_notice('class-error-toolbar', array( 'type' => 'notice-error', 'message' => '' . __('View Admin As', 'view-admin-as') . ': ' - . __('Plugin not loaded because of a conflict with an other plugin or theme', 'view-admin-as') + . __('Plugin not fully loaded because of a conflict with an other plugin or theme', 'view-admin-as') . ' (' . sprintf( __('Class %s already exists', 'view-admin-as'), 'VAA_View_Admin_As_Toolbar' ) . ')', ) ); } - - // WP admin modifications - if ( ! class_exists('VAA_View_Admin_As_Admin') ) { - require( VIEW_ADMIN_AS_DIR . 'ui/class-admin.php' ); - self::$vaa_class_names[] = 'VAA_View_Admin_As_Admin'; - $this->ui['static_actions'] = VAA_View_Admin_As_Admin::get_instance( $this ); - } else { - $this->add_notice('class-error-admin', array( - 'type' => 'notice-error', - 'message' => '' . __('View Admin As', 'view-admin-as') . ': ' - . __('Plugin not loaded because of a conflict with an other plugin or theme', 'view-admin-as') - . ' (' . sprintf( __('Class %s already exists', 'view-admin-as'), 'VAA_View_Admin_As_Admin' ) . ')', - ) ); - } } /** @@ -395,7 +400,7 @@ public function die_handler( $function_name ) { ?>

          :

          - +
          • @@ -418,25 +423,45 @@ public function die_handler( $function_name ) { public function enqueue_scripts() { // Only enqueue scripts if the admin bar is enabled otherwise they have no use if ( ( is_admin_bar_showing() || VAA_API::is_vaa_toolbar_showing() ) && $this->is_enabled() ) { - $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; // Use non-minified versions - $version = defined('WP_DEBUG') && WP_DEBUG ? time() : $this->store->get_version(); // Prevent browser cache - wp_enqueue_style( 'vaa_view_admin_as_style', VIEW_ADMIN_AS_URL . 'assets/css/view-admin-as' . $suffix . '.css', array(), $version ); - wp_enqueue_script( 'vaa_view_admin_as_script', VIEW_ADMIN_AS_URL . 'assets/js/view-admin-as' . $suffix . '.js', array( 'jquery' ), $version, true ); + // 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(), + $version + ); + wp_enqueue_script( + 'vaa_view_admin_as_script', + VIEW_ADMIN_AS_URL . 'assets/js/view-admin-as' . $suffix . '.js', + array( 'jquery' ), + $version, + true // load in footer + ); $script_localization = array( - 'ajaxurl' => admin_url( 'admin-ajax.php' ), - 'siteurl' => get_site_url(), - '_debug' => ( defined('WP_DEBUG') && WP_DEBUG ) ? (bool) WP_DEBUG : false, + // Data + 'ajaxurl' => admin_url( 'admin-ajax.php' ), + 'siteurl' => get_site_url(), + 'settings' => $this->store->get_settings(), + 'settings_user' => $this->store->get_userSettings(), + 'view_as' => $this->store->get_viewAs(), + // Other + '_debug' => ( defined('WP_DEBUG') && 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' ), - '__success' => esc_html__( 'Success', 'view-admin-as' ), - '__confirm' => esc_html__( 'Are you sure?', 'view-admin-as' ), - 'settings' => $this->store->get_settings(), - 'settings_user' => $this->store->get_userSettings() + '__success' => esc_html__( 'Success', 'view-admin-as' ), + '__confirm' => esc_html__( 'Are you sure?', 'view-admin-as' ) ); foreach ( $this->get_modules() as $name => $module ) { - $script_localization[ 'settings_' . $name ] = $module->get_scriptLocalization(); + if ( is_callable( array( $module, 'get_scriptLocalization' ) ) ) { + $script_localization[ 'settings_' . $name ] = $module->get_scriptLocalization(); + } } wp_localize_script( 'vaa_view_admin_as_script', 'VAA_View_Admin_As', $script_localization ); @@ -456,7 +481,8 @@ public function load_textdomain() { if ( $this->is_enabled() ) { /** - * Keep the third parameter pointing to the languages folder within this plugin to enable support for custom .mo files + * Keep the third parameter pointing to the languages folder within this plugin + * to enable support for custom .mo files * * @todo look into 4.6 changes Maybe the same can be done in an other way * @see https://make.wordpress.org/core/2016/07/06/i18n-improvements-in-4-6/ @@ -490,7 +516,7 @@ public function is_enabled() { * * @since 1.6 * @access public - * @return null|VAA_View_Admin_As_Store + * @return VAA_View_Admin_As_Store */ public function store() { return $this->store; @@ -501,25 +527,57 @@ public function store() { * * @since 1.6 * @access public - * @return null|VAA_View_Admin_As_View + * @return VAA_View_Admin_As_View */ public function view() { return $this->view; } + /** + * Get UI classes + * If a key is provided it will only a single UI object + * + * @since 1.6.1 + * @access public + * @param string|bool $key (optional) UI class name + * @return array|object + */ + public function get_ui( $key ) { + return VAA_API::get_array_data( $this->ui, $key ); + } + /** * Get current modules * If a key is provided it will only return that module * * @since 1.5 * @access public - * @param string|bool $key The module key + * @param string|bool $key (optional) The module key * @return array|object */ public function get_modules( $key = false ) { 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 object $instance The module class reference/instance + * } + * @return bool + */ + public function register_module( $data ) { + if ( ! empty( $data['id'] ) && ! empty( $data['instance'] ) && is_object( $data['instance'] ) ) { + $this->modules[ (string) $data['id'] ] = $data['instance']; + return true; + } + return false; + } + /** * Add notices to generate * @@ -567,7 +625,7 @@ public function do_admin_notices() { */ private function validate_versions() { global $wp_version; - $conflict = false; + $valid = true; // Validate PHP /*if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { @@ -577,6 +635,7 @@ private function validate_versions() { ) ); require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); deactivate_plugins( VIEW_ADMIN_AS_BASENAME ); + $valid = false; }*/ // Validate WP @@ -587,13 +646,13 @@ private function validate_versions() { ) ); require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); deactivate_plugins( VIEW_ADMIN_AS_BASENAME ); - $conflict = true; + $valid = false; } - return $conflict; + return $valid; } /** - * Main View Admin As Instance. + * Main View Admin As instance. * * Ensures only one instance of View Admin As is loaded or can be loaded. * @@ -605,8 +664,8 @@ private function validate_versions() { * @param object $caller * @return VAA_View_Admin_As */ - public static function get_instance( $caller ) { - if ( in_array( get_class( $caller ), self::$vaa_class_names ) ) { + public static function get_instance( $caller = null ) { + if ( is_object( $caller ) && in_array( get_class( $caller ), self::$vaa_class_names ) ) { return self::$_instance; } return null; diff --git a/includes/class-view.php b/includes/class-view.php index 9497b044..aa25106c 100644 --- a/includes/class-view.php +++ b/includes/class-view.php @@ -7,7 +7,7 @@ * @author Jory Hogeveen * @package view-admin-as * @since 1.6 - * @version 1.6 + * @version 1.6.1 */ ! defined( 'VIEW_ADMIN_AS_DIR' ) and die( 'You shall not pass!' ); @@ -17,19 +17,23 @@ final class VAA_View_Admin_As_View extends VAA_View_Admin_As_Class_Base /** * The single instance of the class. * - * @since 1.6 - * @var VAA_View_Admin_As_View + * @since 1.6 + * @static + * @var VAA_View_Admin_As_View */ private static $_instance = null; /** * VAA_View_Admin_As_View constructor. * - * @since 1.6 + * @since 1.6 + * @since 1.6.1 $vaa param + * @access protected + * @param VAA_View_Admin_As $vaa */ - protected function __construct() { + protected function __construct( $vaa ) { self::$_instance = $this; - parent::__construct(); + parent::__construct( $vaa ); // When a user logs in or out, reset the view to default add_action( 'wp_login', array( $this, 'cleanup_views' ), 10, 2 ); @@ -57,7 +61,7 @@ public function init() { // Admin selector ajax return add_action( 'wp_ajax_view_admin_as', array( $this, 'ajax_view_admin_as' ) ); - //add_action( 'wp_ajax_nopriv_update_view_as', array( $this, 'ajax_update_view_as' ) ); + //add_action( 'wp_ajax_nopriv_view_admin_as', array( $this, 'ajax_view_admin_as' ) ); // Get the current view (returns false if not found) $this->store->set_viewAs( $this->get_view() ); @@ -74,6 +78,11 @@ public function init() { // Change the capabilities (map_meta_cap is better for compatibility with network admins) add_filter( 'map_meta_cap', array( $this, 'map_meta_cap' ), 999999999, 4 ); } + + // @since 1.6.1 Force own locale on view + if ( 'yes' == $this->store->get_userSettings('freeze_locale') ) { + add_action( 'init', array( $this, 'freeze_locale' ) ); + } } } @@ -87,10 +96,10 @@ public function init() { * @since 1.6 Moved to this class from main class * @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 (not used) - * @param array $args Adds the context to the cap. Typically the object ID (not used) + * @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 (not used) + * @param array $args Adds the context to the cap. Typically the object ID (not used) * @return array $caps */ public function map_meta_cap( $caps, $cap, $user_id, $args ) { @@ -104,7 +113,9 @@ public function map_meta_cap( $caps, $cap, $user_id, $args ) { $filter_caps = $this->store->get_viewAs('caps'); } - if ( false != $filter_caps ) { + if ( false !== $filter_caps ) { + // Cast to an array + $filter_caps = (array) $filter_caps; foreach ( $caps as $actual_cap ) { if ( ! array_key_exists( $actual_cap, $filter_caps ) || ( 1 != (int) $filter_caps[ $actual_cap ] ) ) { // Regular @@ -136,11 +147,11 @@ public function map_meta_cap( $caps, $cap, $user_id, $args ) { public function ajax_view_admin_as() { if ( ! defined('DOING_AJAX') - || ! DOING_AJAX - || ! $this->is_vaa_enabled() - || ! isset( $_POST['view_admin_as'] ) - || ! isset( $_POST['_vaa_nonce'] ) - || ! wp_verify_nonce( $_POST['_vaa_nonce'], $this->store->get_nonce() ) + || ! DOING_AJAX + || ! $this->is_vaa_enabled() + || ! isset( $_POST['view_admin_as'] ) + || ! isset( $_POST['_vaa_nonce'] ) + || ! wp_verify_nonce( $_POST['_vaa_nonce'], $this->store->get_nonce() ) ) { wp_send_json_error( __('Cheatin uh?', 'view-admin-as') ); die(); @@ -207,7 +218,7 @@ public function ajax_view_admin_as() { foreach ( $view_as as $key => $data ) { if ( array_key_exists( $key, $this->get_modules() ) ) { $module = $this->get_modules( $key ); - if ( method_exists( $module, 'ajax_handler' ) ) { + if ( is_callable( array( $module, 'ajax_handler' ) ) ) { $success = $module->ajax_handler( $data ); if ( is_string( $success ) && ! empty( $success ) ) { wp_send_json_error( $success ); @@ -269,10 +280,7 @@ public function get_view() { // Browse mode if ( $this->store->get_userSettings('view_mode') == 'browse' ) { $meta = $this->store->get_userMeta('views'); - if ( is_array( $meta ) - && isset( $meta[ $this->store->get_curUserSession() ] ) - && isset( $meta[ $this->store->get_curUserSession() ]['view'] ) - ) { + if ( isset( $meta[ $this->store->get_curUserSession() ]['view'] ) ) { return $this->validate_view_as_data( $meta[ $this->store->get_curUserSession() ]['view'] ); } } @@ -285,21 +293,21 @@ public function get_view() { * * @since 1.3.4 * @since 1.6 Moved to this class from main class - * @access private + * @access public * - * @param array|bool $data + * @param array|bool $data * @return bool */ - private function update_view( $data = false ) { - if ( false != $data ) { + public function update_view( $data = false ) { + if ( false != $data && $data = $this->validate_view_as_data( $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 ( ! $meta || ! is_array( $meta ) ) { + if ( ! is_array( $meta ) ) { $meta = array(); } // Add the new view metadata and expiration date $meta[ $this->store->get_curUserSession() ] = array( - 'view' => $this->validate_view_as_data( $data ), + 'view' => $data, 'expire' => ( time() + $this->store->get_metaExpiration() ), ); // Update metadata (returns: true on success, false on failure) @@ -330,7 +338,7 @@ public function reset_view( $user_login = false, $user = false ) { if ( isset( $user->ID ) ) { $meta = get_user_meta( $user->ID, $this->store->get_userMetaKey(), true ); // Check if this user session has metadata - if ( isset( $meta['views'] ) && isset( $meta['views'][ $this->store->get_curUserSession() ] ) ) { + 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 @@ -367,7 +375,10 @@ public function cleanup_views( $user_login = false, $user = false ) { if ( isset( $user->ID ) ) { $meta = get_user_meta( $user->ID, $this->store->get_userMetaKey(), true ); // If meta exists, loop it - if ( isset( $meta['views'] ) && 0 < count( $meta['views'] ) ) { + if ( isset( $meta['views'] ) ) { + if ( ! is_array( $meta['views'] ) ) { + $meta['views'] = array(); + } foreach ( $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() > $meta['views'][ $key ]['expire'] ) { @@ -505,6 +516,23 @@ public function validate_view_as_data( $view_as ) { return false; } + /** + * Set the locale for the current view + * + * @since 1.6.1 + * @access public + */ + 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 ( $locale != get_locale() ) { + switch_to_locale( $locale ); + } + return true; + } + return false; + } + /** * Main Instance. * @@ -513,17 +541,17 @@ public function validate_view_as_data( $view_as ) { * @since 1.6 * @access public * @static - * @param object|bool $caller The referrer class - * @return VAA_View_Admin_As_View|bool + * @param VAA_View_Admin_As $caller The referrer class + * @return VAA_View_Admin_As_View */ - public static function get_instance( $caller = false ) { + public static function get_instance( $caller = null ) { if ( is_object( $caller ) && 'VAA_View_Admin_As' == get_class( $caller ) ) { if ( is_null( self::$_instance ) ) { - self::$_instance = new self(); + self::$_instance = new self( $caller ); } return self::$_instance; } - return false; + return null; } } // end class \ No newline at end of file diff --git a/modules/class-role-defaults.php b/modules/class-role-defaults.php index 3a169aba..8e20d7ea 100644 --- a/modules/class-role-defaults.php +++ b/modules/class-role-defaults.php @@ -4,10 +4,10 @@ * * Set default screen settings for roles and apply them on users through various bulk actions. * - * @author Jory Hogeveen + * @author Jory Hogeveen * @package view-admin-as * @since 1.4 - * @version 1.6 + * @version 1.6.1 */ ! defined( 'VIEW_ADMIN_AS_DIR' ) and die( 'You shall not pass!' ); @@ -17,8 +17,9 @@ final class VAA_View_Admin_As_Role_Defaults extends VAA_View_Admin_As_Class_Base /** * The single instance of the class. * - * @since 1.5 - * @var VAA_View_Admin_As_Role_Defaults + * @since 1.5 + * @static + * @var VAA_View_Admin_As_Role_Defaults */ private static $_instance = null; @@ -35,7 +36,7 @@ final class VAA_View_Admin_As_Role_Defaults extends VAA_View_Admin_As_Class_Base * %% stands for a wildcard and can be anything * * @since 1.4 - * @since 1.5.2 Set both values and keys to fix problem with unsetting a key through the filter + * @since 1.5.2 Set both values and keys to fix problem with unsetting a key through the filter * @var array */ private $meta = array( @@ -72,11 +73,13 @@ final class VAA_View_Admin_As_Role_Defaults extends VAA_View_Admin_As_Class_Base * Protected to make sure it isn't declared elsewhere * * @since 1.4 + * @since 1.6.1 $vaa param * @access protected + * @param VAA_View_Admin_As $vaa */ - protected function __construct() { + protected function __construct( $vaa ) { self::$_instance = $this; - parent::__construct(); + parent::__construct( $vaa ); // Load data $this->set_optionData( get_option( $this->get_optionKey() ) ); @@ -93,7 +96,7 @@ protected function __construct() { } /** - * Only allow settings for admin users or users with the correct apabilities + * Only allow settings for admin users or users with the correct capabilities * * @since 1.5.2 Validate custom capability view_admin_as_role_defaults * @since 1.5.2.1 Validate is_super_admin (bug in 1.5.2) @@ -161,7 +164,7 @@ private function init() { /** * Print script in the admin header * Also handles the lock_meta_boxes setting - * @since 1.6 + * @since 1.6 */ add_action( 'admin_print_scripts', array( $this, 'admin_print_scripts' ), 100 ); } @@ -180,7 +183,7 @@ public function vaa_init() { if ( is_super_admin( $this->get_curUser()->ID ) ) { // Add adminbar menu items in settings section - add_action( 'vaa_admin_bar_settings_after', array( $this, 'admin_bar_menu_settings' ) ); + add_action( 'vaa_admin_bar_settings_after', array( $this, 'admin_bar_menu_settings' ), 10, 2 ); } // Add adminbar menu items in role section @@ -190,7 +193,7 @@ public function vaa_init() { $this->init_store_role_defaults(); // Show the admin bar node - add_action( 'vaa_admin_bar_settings_after', array( $this, 'admin_bar_menu' ) ); + add_action( 'vaa_admin_bar_menu', array( $this, 'admin_bar_menu' ), 5, 2 ); } } @@ -204,7 +207,6 @@ public function admin_print_scripts() { /** * Setting: Lock meta box order and locations for all users who can't access role defaults - * * @since 1.6 */ if ( true == $this->get_optionData('lock_meta_boxes') @@ -216,7 +218,7 @@ public function admin_print_scripts() { /** * Lock meta boxes in position by disabling sorting. * - * Credits go to Chris Van Patten: + * Credits - Chris Van Patten: * http://wordpress.stackexchange.com/a/44539 */ $('.meta-box-sortables').sortable( { disabled: true } ); @@ -252,7 +254,7 @@ private function set_meta( $var ) { } /** - * Validates meta keys in case forbitten or invalid meta keys are added + * Validates meta keys in case forbidden or invalid meta keys are added * * @since 1.5.2 * @access private @@ -261,7 +263,7 @@ private function set_meta( $var ) { */ private function validate_meta( $metas ) { if ( is_array( $metas ) ) { - foreach( $metas as $key => $meta_key ) { + foreach ( $metas as $key => $meta_key ) { // Remove forbidden or invalid meta keys if ( in_array( $meta_key, $this->meta_forbidden ) || strpos( $meta_key, ' ' ) !== false @@ -276,7 +278,7 @@ private function validate_meta( $metas ) { } /** - * Ajax handler, called from main plugin + * Ajax handler, called from main ajax handler * * @since 1.4 * @access public @@ -458,7 +460,7 @@ private function apply_defaults_to_users_by_role( $role ) { $success = true; $roles = array(); if ( is_array( $role ) ) { - foreach( $role as $role_name ) { + foreach ( $role as $role_name ) { if ( array_key_exists( $role_name, $this->get_roles() ) ) { $roles[] = $role_name; } @@ -467,7 +469,7 @@ private function apply_defaults_to_users_by_role( $role ) { if ( array_key_exists( $role, $this->get_roles() ) ) { $roles[] = $role; } elseif ( $role == 'all' ) { - foreach( $this->get_roles() as $role_name => $val ) { + foreach ( $this->get_roles() as $role_name => $val ) { $roles[] = $role_name; } } @@ -486,8 +488,8 @@ private function apply_defaults_to_users_by_role( $role ) { } /** - * Initialize the sync funcionality (store defaults) - * Init function/action to load nessesary data and register all used hooks + * Initialize the sync functionality (store defaults) + * Init function/action to load necessary data and register all used hooks * IMPORTANT! This function should ONLY be used when a role view is selected! * * @since 1.4 @@ -503,7 +505,7 @@ private function init_store_role_defaults() { } /** - * Check if the meta_key maches one of the predefined metakeys in the role defaults + * Check if the meta_key matches one of the predefined metakeys in the role defaults * If there is a match and the role default value is set, return this value instead of the current user value. * * IMPORTANT! This filter should ONLY be used when a role view is selected! @@ -533,7 +535,7 @@ public function filter_get_user_metadata( $null, $object_id, $meta_key, $single } /** - * Check if the meta_key maches one of the predefined metakeys to store as defaults. + * Check if the meta_key matches one of the predefined metakeys to store as defaults. * If there is a match, store the update to the defaults and cancel the update for the current user. * * IMPORTANT! This filter should ONLY be used when a role view is selected! @@ -604,10 +606,10 @@ private function update_role_defaults( $role, $meta_key, $meta_value ) { * * @since 1.4 * @access private - * @param string $role + * @param string|array $role Role name or array of role names or just "all" for all roles * @return bool */ - private function clear_role_defaults( $role ) { // option to set $role to "all" or pass an array of multiple roles + private function clear_role_defaults( $role ) { $role_defaults = $this->get_optionData( 'roles' ); if ( ! is_array( $role ) ) { if ( isset( $role_defaults ) && $role == 'all' ) { @@ -647,7 +649,7 @@ private function export_role_defaults( $role = 'all' ) { $data = array( $role => $data ); } elseif ( 'all' == $role && ! empty( $role_defaults ) ) { $data = $role_defaults; - } else { + } else { $data = esc_attr__('No valid data found', 'view-admin-as'); } return $data; @@ -663,7 +665,7 @@ private function export_role_defaults( $role = 'all' ) { */ private function import_role_defaults( $data ) { $new_defaults = array(); - $error_list = array(); + $error_list = array(); if ( empty( $data ) || ! is_array( $data ) ) { return array( 'text' => esc_attr__('No valid data found', 'view-admin-as') ); } @@ -694,12 +696,18 @@ private function import_role_defaults( $data ) { $this->update_optionData( $role_defaults, 'roles', true ); if ( ! empty( $error_list ) ) { // Close enough! - return array( 'text' => esc_attr__('Data imported but there were some errors', 'view-admin-as') . ':', 'errors' => $error_list); + return array( + 'text' => esc_attr__( 'Data imported but there were some errors', 'view-admin-as' ) . ':', + 'errors' => $error_list + ); } return true; // Yay! } // Nope.. - return array( 'text' => esc_attr__('No valid data found', 'view-admin-as') . ':', 'errors' => $error_list ); + return array( + 'text' => esc_attr__( 'No valid data found', 'view-admin-as' ) . ':', + 'errors' => $error_list + ); } /** @@ -714,7 +722,7 @@ private function import_role_defaults( $data ) { private function compare_metakey( $meta_key_compare ) { $meta_keys = $this->get_meta(); if ( is_array( $meta_keys ) ) { - foreach( $meta_keys as $key => $meta_key ) { + foreach ( $meta_keys as $key => $meta_key ) { if ( empty( $meta_key ) || ! is_string( $meta_key ) ) { continue; } else { @@ -753,28 +761,36 @@ private function endsWith( $haystack, $needle ) { * @since 1.5 * @access public * @see 'vaa_admin_bar_settings_after' action + * * @param object $admin_bar + * @param string $root The root item (vaa-settings) * @return void */ - public function admin_bar_menu_settings( $admin_bar ) { + public function admin_bar_menu_settings( $admin_bar, $root ) { $admin_bar->add_group( array( - 'id' => 'settings-role-defaults', - 'parent' => 'settings', - 'meta' => array( - 'class' => 'ab-sub-secondary', + 'id' => $root . '-role-defaults', + 'parent' => $root, + 'meta' => array( + 'class' => 'ab-sub-secondary', ), ) ); + $root = $root . '-role-defaults'; + $admin_bar->add_node( array( - 'id' => 'settings-role-defaults-enable', - 'parent' => 'settings-role-defaults', - 'title' => 'get_optionData( 'enable' ), true, false ) . '> - -

            ' . __('Set default screen settings for roles and apply them on users through various bulk and automatic actions', 'view-admin-as') . '

            ', - 'href' => false, - 'meta' => array( - 'class' => 'auto-height', + 'id' => $root . '-enable', + 'parent' => $root, + 'title' => VAA_View_Admin_As_Admin_Bar::do_checkbox( array( + 'name' => $root . '-enable', + 'value' => $this->get_optionData( 'enable' ), + 'compare' => true, + 'label' => __('Enable role defaults', 'view-admin-as'), + 'description' => __('Set default screen settings for roles and apply them on users through various bulk and automatic actions', 'view-admin-as') + ) ), + 'href' => false, + 'meta' => array( + 'class' => 'auto-height', ), ) ); @@ -783,62 +799,77 @@ public function admin_bar_menu_settings( $admin_bar ) { /** * Add admin bar menu's * - * * @since 1.4 * @since 1.5.2 Changed hook to vaa_admin_bar_settings_after (previous: 'vaa_admin_bar_roles_before') * @access public - * @see 'vaa_admin_bar_settings_after' action + * @see 'vaa_admin_bar_menu' action * * @param object $admin_bar + * @param string $root The root item (vaa) * @return void */ - public function admin_bar_menu( $admin_bar ) { + public function admin_bar_menu( $admin_bar, $root ) { $admin_bar->add_node( array( - 'id' => 'role-defaults', - 'parent' => 'view-as', - 'title' => VAA_View_Admin_As_Admin_Bar::do_icon( 'dashicons-id-alt' ) . __('Role defaults', 'view-admin-as'), - 'href' => false, - 'meta' => array( - 'class' => 'vaa-has-icon', + 'id' => $root . '-role-defaults', + 'parent' => $root, + 'title' => VAA_View_Admin_As_Admin_Bar::do_icon( 'dashicons-id-alt' ) . __( 'Role defaults', 'view-admin-as' ), + 'href' => false, + 'meta' => array( + 'class' => 'vaa-has-icon', + 'tabindex' => '0' ), ) ); + $root = $root . '-role-defaults'; + $role_select_options = ''; foreach ( $this->get_roles() as $role_key => $role ) { $role_select_options .= ''; } $admin_bar->add_node( array( - 'id' => 'role-defaults-setting-register-enable', - 'parent' => 'role-defaults', - 'title' => 'get_optionData( 'apply_defaults_on_register' ), true, false ) . '> - ', - 'href' => false, - 'meta' => array( - 'class' => 'auto-height', + 'id' => $root . '-setting-register-enable', + 'parent' => $root, + 'title' => VAA_View_Admin_As_Admin_Bar::do_checkbox( array( + 'name' => $root . '-setting-register-enable', + 'value' => $this->get_optionData( 'apply_defaults_on_register' ), + 'compare' => true, + 'label' => __('Automatically apply defaults to new users', 'view-admin-as'), + ) ), + 'href' => false, + 'meta' => array( + 'class' => 'auto-height', ), ) ); $admin_bar->add_node( array( - 'id' => 'role-defaults-setting-disable-user-screen-options', - 'parent' => 'role-defaults', - 'title' => 'get_optionData( 'disable_user_screen_options' ), true, false ) . '> - -

            ' . __("Hide the screen options for all users who can't access role defaults", 'view-admin-as') . '

            ', - 'href' => false, - 'meta' => array( - 'class' => 'auto-height', + 'id' => $root . '-setting-disable-user-screen-options', + 'parent' => $root, + 'title' => VAA_View_Admin_As_Admin_Bar::do_checkbox( array( + 'name' => $root . '-setting-disable-user-screen-options', + 'value' => $this->get_optionData( 'disable_user_screen_options' ), + 'compare' => true, + 'label' => __('Disable screen options', 'view-admin-as'), + 'description' => __("Hide the screen options for all users who can't access role defaults", 'view-admin-as') + ) ), + 'href' => false, + 'meta' => array( + 'class' => 'auto-height', ), ) ); $admin_bar->add_node( array( - 'id' => 'role-defaults-setting-lock-meta-boxes', - 'parent' => 'role-defaults', - 'title' => 'get_optionData( 'lock_meta_boxes' ), true, false ) . '> - -

            ' . __("Lock meta box order and locations for all users who can't access role defaults", 'view-admin-as') . '

            ', - 'href' => false, - 'meta' => array( - 'class' => 'auto-height', + 'id' => $root . '-setting-lock-meta-boxes', + 'parent' => $root, + 'title' => VAA_View_Admin_As_Admin_Bar::do_checkbox( array( + 'name' => $root . '-setting-lock-meta-boxes', + 'value' => $this->get_optionData( 'lock_meta_boxes' ), + 'compare' => true, + 'label' => __('Lock meta boxes', 'view-admin-as'), + 'description' => __("Lock meta box order and locations for all users who can't access role defaults", 'view-admin-as') + ) ), + 'href' => false, + 'meta' => array( + 'class' => 'auto-height', ), ) ); @@ -849,28 +880,32 @@ public function admin_bar_menu( $admin_bar ) { if ( $this->get_users() ) { // Users select $admin_bar->add_group( array( - 'id' => 'role-defaults-bulk-users', - 'parent' => 'role-defaults', - 'meta' => array( - 'class' => 'ab-sub-secondary', + 'id' => $root . '-bulk-users', + 'parent' => $root, + 'meta' => array( + 'class' => 'ab-sub-secondary', ), ) ); $admin_bar->add_node( array( - 'id' => 'role-defaults-bulk-users-title', - 'parent' => 'role-defaults-bulk-users', - 'title' => __('Apply defaults to users', 'view-admin-as'), - 'href' => false, - 'meta' => array( - 'class' => 'ab-bold ab-vaa-toggle', + 'id' => $root . '-bulk-users-title', + 'parent' => $root . '-bulk-users', + 'title' => __('Apply defaults to users', 'view-admin-as'), + 'href' => false, + 'meta' => array( + 'class' => 'ab-bold ab-vaa-toggle', + 'tabindex' => '0' ), ) ); $admin_bar->add_node( array( - 'id' => 'role-defaults-bulk-users-filter', - 'parent' => 'role-defaults-bulk-users', - 'title' => '', - 'href' => false, - 'meta' => array( - 'class' => 'ab-vaa-filter', + 'id' => $root . '-bulk-users-filter', + 'parent' => $root . '-bulk-users', + 'title' => VAA_View_Admin_As_Admin_Bar::do_input( array( + 'name' => $root . '-bulk-users-filter', + 'placeholder' => esc_attr__('Filter', 'view-admin-as') . ' (' . strtolower( __('Username') ) . ')' + ) ), + 'href' => false, + 'meta' => array( + 'class' => 'ab-vaa-filter', ), ) ); $bulk_users_select_content = ''; @@ -880,29 +915,32 @@ public function admin_bar_menu( $admin_bar ) { $role_name = translate_user_role( $role_data->name ); $bulk_users_select_content .= '
            - - + +
            '; } } } $admin_bar->add_node( array( - 'id' => 'role-defaults-bulk-users-select', - 'parent' => 'role-defaults-bulk-users', - 'title' => $bulk_users_select_content, - 'href' => false, - 'meta' => array( - 'class' => 'ab-vaa-multipleselect max-height', + 'id' => $root . '-bulk-users-select', + 'parent' => $root . '-bulk-users', + 'title' => $bulk_users_select_content, + 'href' => false, + 'meta' => array( + 'class' => 'ab-vaa-multipleselect max-height', ), ) ); $admin_bar->add_node( array( - 'id' => 'role-defaults-bulk-users-apply', - 'parent' => 'role-defaults-bulk-users', - 'title' => '', - 'href' => false, - 'meta' => array( - 'class' => 'vaa-button-container', - 'html' => '', + 'id' => $root . '-bulk-users-apply', + 'parent' => $root . '-bulk-users', + 'title' => VAA_View_Admin_As_Admin_Bar::do_button( array( + 'name' => $root . '-bulk-users-apply', + 'label' => __('Apply', 'view-admin-as'), + 'classes' => 'button-primary' + ) ), + 'href' => false, + 'meta' => array( + 'class' => 'vaa-button-container', ), ) ); } @@ -910,40 +948,43 @@ public function admin_bar_menu( $admin_bar ) { if ( $this->get_users() && $this->get_roles() ) { // Roles select $admin_bar->add_group( array( - 'id' => 'role-defaults-bulk-roles', - 'parent' => 'role-defaults', - 'meta' => array( - 'class' => 'ab-sub-secondary', + 'id' => $root . '-bulk-roles', + 'parent' => $root, + 'meta' => array( + 'class' => 'ab-sub-secondary', ), ) ); $admin_bar->add_node( array( - 'id' => 'role-defaults-bulk-roles-title', - 'parent' => 'role-defaults-bulk-roles', - 'title' => __('Apply defaults to users by role', 'view-admin-as'), - 'href' => false, - 'meta' => array( - 'class' => 'ab-bold ab-vaa-toggle', + 'id' => $root . '-bulk-roles-title', + 'parent' => $root . '-bulk-roles', + 'title' => __('Apply defaults to users by role', 'view-admin-as'), + 'href' => false, + 'meta' => array( + 'class' => 'ab-bold ab-vaa-toggle', + 'tabindex' => '0' ), ) ); $admin_bar->add_node( array( - 'id' => 'role-defaults-bulk-roles-select', - 'parent' => 'role-defaults-bulk-roles', - 'title' => '', - 'href' => false, - 'meta' => array( - 'class' => 'ab-vaa-select select-role', // vaa-column-one-half vaa-column-last - 'html' => '', + 'id' => $root . '-bulk-roles-select', + 'parent' => $root . '-bulk-roles', + 'title' => '', + 'href' => false, + 'meta' => array( + 'class' => 'ab-vaa-select select-role', // vaa-column-one-half vaa-column-last ), ) ); $admin_bar->add_node( array( - 'id' => 'role-defaults-bulk-roles-apply', - 'parent' => 'role-defaults-bulk-roles', - 'title' => '', - 'href' => false, - 'meta' => array( - 'class' => 'vaa-button-container', - 'html' => '', + 'id' => $root . '-bulk-roles-apply', + 'parent' => $root . '-bulk-roles', + 'title' => VAA_View_Admin_As_Admin_Bar::do_button( array( + 'name' => $root . '-bulk-roles-apply', + 'label' => __('Apply', 'view-admin-as'), + 'classes' => 'button-primary' + ) ), + 'href' => false, + 'meta' => array( + 'class' => 'vaa-button-container', ), ) ); } @@ -952,117 +993,126 @@ public function admin_bar_menu( $admin_bar ) { /* Export actions */ $admin_bar->add_group( array( - 'id' => 'role-defaults-export', - 'parent' => 'role-defaults', - 'meta' => array( - 'class' => 'ab-sub-secondary', + 'id' => $root . '-export', + 'parent' => $root, + 'meta' => array( + 'class' => 'ab-sub-secondary', ), ) ); $admin_bar->add_node( array( - 'id' => 'role-defaults-export-roles', - 'parent' => 'role-defaults-export', - 'title' => __('Export defaults for role', 'view-admin-as'), - 'href' => false, - 'meta' => array( - 'class' => 'ab-bold ab-vaa-toggle', + 'id' => $root . '-export-roles', + 'parent' => $root . '-export', + 'title' => __('Export defaults for role', 'view-admin-as'), + 'href' => false, + 'meta' => array( + 'class' => 'ab-bold ab-vaa-toggle', + 'tabindex' => '0' ), ) ); $admin_bar->add_node( array( - 'id' => 'role-defaults-export-roles-select', - 'parent' => 'role-defaults-export', - 'title' => '', - 'href' => false, - 'meta' => array( - 'class' => 'ab-vaa-select select-role', // vaa-column-one-half vaa-column-last - 'html' => '', + 'id' => $root . '-export-roles-select', + 'parent' => $root . '-export', + 'title' => '', + 'href' => false, + 'meta' => array( + 'class' => 'ab-vaa-select select-role', // vaa-column-one-half vaa-column-last ), ) ); $admin_bar->add_node( array( - 'id' => 'role-defaults-export-roles-export', - 'parent' => 'role-defaults-export', - 'title' => '', - 'href' => false, - 'meta' => array( - 'class' => 'vaa-button-container', - 'html' => '', + 'id' => $root . '-export-roles-export', + 'parent' => $root . '-export', + 'title' => VAA_View_Admin_As_Admin_Bar::do_button( array( + 'name' => $root . '-export-roles-export', + 'label' => __('Export', 'view-admin-as'), + 'classes' => 'button-secondary' + ) ), + 'href' => false, + 'meta' => array( + 'class' => 'vaa-button-container', ), ) ); /* Import actions */ $admin_bar->add_group( array( - 'id' => 'role-defaults-import', - 'parent' => 'role-defaults', - 'meta' => array( - 'class' => 'ab-sub-secondary', + 'id' => $root . '-import', + 'parent' => $root, + 'meta' => array( + 'class' => 'ab-sub-secondary', ), ) ); $admin_bar->add_node( array( - 'id' => 'role-defaults-import-roles', - 'parent' => 'role-defaults-import', - 'title' => __('Import defaults for role', 'view-admin-as'), - 'href' => false, - 'meta' => array( - 'class' => 'ab-bold ab-vaa-toggle', + 'id' => $root . '-import-roles', + 'parent' => $root . '-import', + 'title' => __('Import defaults for role', 'view-admin-as'), + 'href' => false, + 'meta' => array( + 'class' => 'ab-bold ab-vaa-toggle', + 'tabindex' => '0' ), ) ); $admin_bar->add_node( array( - 'id' => 'role-defaults-import-roles-input', - 'parent' => 'role-defaults-import', - 'title' => '', - 'href' => false, - 'meta' => array( - 'class' => 'ab-vaa-textarea input-role', // vaa-column-one-half vaa-column-last - 'html' => '', + 'id' => $root . '-import-roles-input', + 'parent' => $root . '-import', + 'title' => '', + 'href' => false, + 'meta' => array( + 'class' => 'ab-vaa-textarea input-role', // vaa-column-one-half vaa-column-last ), ) ); $admin_bar->add_node( array( - 'id' => 'role-defaults-import-roles-import', - 'parent' => 'role-defaults-import', - 'title' => '', - 'href' => false, - 'meta' => array( - 'class' => 'vaa-button-container', - 'html' => '', + 'id' => $root . '-import-roles-import', + 'parent' => $root . '-import', + 'title' => VAA_View_Admin_As_Admin_Bar::do_button( array( + 'name' => $root . '-import-roles-import', + 'label' => __('Import', 'view-admin-as'), + 'classes' => 'button-secondary' + ) ), + 'href' => false, + 'meta' => array( + 'class' => 'vaa-button-container', ), ) ); /* Clear actions */ $admin_bar->add_group( array( - 'id' => 'role-defaults-clear', - 'parent' => 'role-defaults', - 'meta' => array( - 'class' => 'ab-sub-secondary vaa-sub-transparent', + 'id' => $root . '-clear', + 'parent' => $root, + 'meta' => array( + 'class' => 'ab-sub-secondary vaa-sub-transparent', ), ) ); $admin_bar->add_node( array( - 'id' => 'role-defaults-clear-roles', - 'parent' => 'role-defaults-clear', - 'title' => __('Remove defaults for role', 'view-admin-as'), - 'href' => false, - 'meta' => array( - 'class' => 'ab-bold ab-vaa-toggle', + 'id' => $root . '-clear-roles', + 'parent' => $root . '-clear', + 'title' => __('Remove defaults for role', 'view-admin-as'), + 'href' => false, + 'meta' => array( + 'class' => 'ab-bold ab-vaa-toggle', + 'tabindex' => '0' ), ) ); $admin_bar->add_node( array( - 'id' => 'role-defaults-clear-roles-select', - 'parent' => 'role-defaults-clear', - 'title' => '', - 'href' => false, - 'meta' => array( - 'class' => 'ab-vaa-select select-role', // vaa-column-one-half vaa-column-last - 'html' => '', + 'id' => $root . '-clear-roles-select', + 'parent' => $root . '-clear', + 'title' => '', + 'href' => false, + 'meta' => array( + 'class' => 'ab-vaa-select select-role', // vaa-column-one-half vaa-column-last ), ) ); $admin_bar->add_node( array( - 'id' => 'role-defaults-clear-roles-apply', - 'parent' => 'role-defaults-clear', - 'title' => '', - 'href' => false, - 'meta' => array( - 'class' => 'vaa-button-container', - 'html' => '', + 'id' => $root . '-clear-roles-apply', + 'parent' => $root . '-clear', + 'title' => VAA_View_Admin_As_Admin_Bar::do_button( array( + 'name' => $root . '-clear-roles-apply', + 'label' => __('Apply', 'view-admin-as'), + 'classes' => 'button-secondary' + ) ), + 'href' => false, + 'meta' => array( + 'class' => 'vaa-button-container', ), ) ); } @@ -1076,17 +1126,17 @@ public function admin_bar_menu( $admin_bar ) { * @since 1.5 * @access public * @static - * @param object|bool $caller The referrer class - * @return VAA_View_Admin_As_Role_Defaults|bool + * @param VAA_View_Admin_As $caller The referrer class + * @return VAA_View_Admin_As_Role_Defaults */ - public static function get_instance( $caller = false ) { + public static function get_instance( $caller = null ) { if ( is_object( $caller ) && 'VAA_View_Admin_As' == get_class( $caller ) ) { if ( is_null( self::$_instance ) ) { - self::$_instance = new self(); + self::$_instance = new self( $caller ); } return self::$_instance; } - return false; + return null; } } // end class diff --git a/readme.txt b/readme.txt index c61a055c..58329cde 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=YGPLM Tags: admin, view, roles, users, switch, user switching, role switching, capabilities, caps, screen settings, defaults Requires at least: 3.5 Tested up to: 4.7 -Stable tag: 1.6 +Stable tag: 1.6.1 View the WordPress admin as a different role, switch between users, temporarily change your capabilities, set default screen settings for roles. @@ -162,6 +162,15 @@ This plugin is also useful to support your clients and/or users. For example; ma == Changelog == += 1.6.1 = + +* Feature: Freeze locale, force your own locale setting over that of a selected view. (Requires WP 4.7) [#21](https://github.com/JoryHogeveen/view-admin-as/issues/21) +* Enhancement: Added a11y keyboard tab indexes +* Fix: Reloading when anchor tags are set in the url [#17](https://github.com/JoryHogeveen/view-admin-as/issues/17) +* Other minor fixes + +Detailed info: [PR on GitHub](https://github.com/JoryHogeveen/view-admin-as/pull/20) + = 1.6 = * Feature: Lock meta boxes [#9](https://github.com/JoryHogeveen/view-admin-as/issues/9) @@ -174,59 +183,7 @@ This plugin is also useful to support your clients and/or users. For example; ma * Fix: occasional issues with enabling the Role Defaults module * Refactor whole backend into multiple classes for more flexibility in future development -= 1.5.3 = - -* Feature: Switch between super admins on network pages (currently only available for superior admins, see `view_admin_as_superior_admins` filter) -* Improvement: Better handling of role defaults for new users -* Improvement: Also hide the screen options for all users who can access this plugin default functionalities but can't access the role defaults module -* UX: Confirm before deleting role defaults -* UI: Translate user roles in front end (WP issue workaround) -* UI: Fix icon sizes across browsers -* Tested for WordPress 4.6 - -= 1.5.2.1 = - -* Fix: minor bug with displaying role names -* Fix: minor bug with displaying role defaults menu item - -= 1.5.2 = - -* Feature: Added the `view_admin_as_superior_admins` filter. Grant admins the capability to view other admins. There is no UI for this! -* Improvement: (Module Role Defaults) Added forbidden meta keys to make sure user entered keys (filter) are ok to use. -* Improvement: (Settings tab) Add the option to group users under their roles. This option is only available when there are less than 15 users and roles, otherwise this is default -* Improvement: `view_admin_as_role_defaults` capability for access to the "Role Defaults" module when a user isn't a super admin -* Performance: Less queries for user validation -* Fix: (Module Role Defaults) Problem solved with un-setting meta keys -* Fix: Problem solved with anchor tags preventing javascript from reloading -* Fix: Problem solved with reset button on single switch mode -* UI: Move "Role Defaults" to the top -* UI: Remove the reset button when no view is selected -* UI: Added some of those pretty dashicons -* UI: Allow titles to toggle content -* Resource: Started with [viewadminas.wordpress.com](https://viewadminas.wordpress.com/ "viewadminas.wordpress.com") - -= 1.5.1 = - -* Feature: `view_admin_as` capability for non-admin users to enable limited access to this plugin (they won't be able to view or edit equal or admin users and roles). This capability requires the `edit_users` capability (+ `manage_network_users` for multisite installations) -* Feature: Ability to disable the "screen settings" option for all users that don't have access to this plugin -* Fix: die_handler for https -* Fix: Reset currently loaded metadata as well when resetting a view (refresh is no longer needed, minor bug in 1.5) -* Added notices on compatibility errors - -= 1.5 = - -* Upgrade notice: The plugin code changed a lot, please clear your cache after updating -* Feature: Import and export functions for module "Role defaults" -* Feature: (Settings tab) View mode "browse" and "single" -* Feature: (Settings tab) Change location of this plugin menu -* Improvement: Better capability filter (used for changing capabilities and roles) -* Improvement: Added some actions for extension purposes -* Improvement: Better version compare -* Improvement: Better code standards and data validation -* Compatibility: Backwards compatibility until WP 3.5+ (3.8+ is highly recommended, 4.0+ is best!) -* Security: Better data validation and usage of a nonce (although in this case I don't think it made any difference for actual security, it's still good to implement proper security!) -* i18n: All translations are now managed with translate.wordpress.org -* Screenshots updated +Detailed info: [PR on GitHub](https://github.com/JoryHogeveen/view-admin-as/pull/8) = Older versions = diff --git a/ui/class-admin-bar.php b/ui/class-admin-bar.php index b4226860..60a4d213 100644 --- a/ui/class-admin-bar.php +++ b/ui/class-admin-bar.php @@ -4,10 +4,10 @@ * * Admin Bar UI for View Admin As * - * @author Jory Hogeveen + * @author Jory Hogeveen * @package view-admin-as * @since 1.5 - * @version 1.6 + * @version 1.6.1 */ ! defined( 'VIEW_ADMIN_AS_DIR' ) and die( 'You shall not pass!' ); @@ -17,11 +17,21 @@ final class VAA_View_Admin_As_Admin_Bar extends VAA_View_Admin_As_Class_Base /** * The single instance of the class. * - * @since 1.5 - * @var VAA_View_Admin_As_Admin_Bar + * @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'; + /** * Database option key * @@ -51,18 +61,20 @@ final class VAA_View_Admin_As_Admin_Bar extends VAA_View_Admin_As_Class_Base * 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 */ - protected function __construct() { + protected function __construct( $vaa ) { self::$_instance = $this; - parent::__construct(); + parent::__construct( $vaa ); if ( $this->is_vaa_enabled() ) { add_action( 'vaa_view_admin_as_init', array( $this, 'vaa_init' ) ); } // Load data - $this->set_optionData( get_option( $this->get_optionKey() ) ); + //$this->set_optionData( get_option( $this->get_optionKey() ) ); } /** @@ -161,21 +173,23 @@ public function admin_bar_menu( $admin_bar, $root = '' ) { // Add menu item $admin_bar->add_node( array( - 'id' => 'view-as', + 'id' => self::$root, 'parent' => $root, 'title' => '' . $title . '', 'href' => false, 'meta' => array( - 'title' => __('View Admin As', 'view-admin-as'), + 'title' => __('View Admin As', 'view-admin-as'), + 'tabindex' => '0' ), ) ); /** - * Add items at the beginning + * Add items as first + * @since 1.5 * @see 'admin_bar_menu' action * @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar */ - do_action( 'vaa_admin_bar_menu_before', $admin_bar ); + do_action( 'vaa_admin_bar_menu_before', $admin_bar, self::$root ); // Add reset button if ( $this->get_viewAs() ) { @@ -186,24 +200,29 @@ public function admin_bar_menu( $admin_bar, $root = '' ) { $name = 'reload'; } $admin_bar->add_node( array( - 'id' => 'reset', - 'parent' => 'view-as', - 'title' => '', // __('Default', 'view-admin-as') + 'id' => self::$root . '-reset', + 'parent' => self::$root, + 'title' => self::do_button( array( + 'name' => self::$root . '-' . $name, + 'label' => __('Reset to default', 'view-admin-as'), + 'classes' => 'button-secondary' + ) ), 'href' => false, 'meta' => array( - 'title' => esc_attr__('Reset to default', 'view-admin-as'), - 'class' => 'vaa-reset-item', - 'rel' => $rel, + 'title' => esc_attr__('Reset to default', 'view-admin-as'), + 'class' => 'vaa-reset-item vaa-button-container', + 'rel' => $rel ), ) ); } /** * Add items + * @since 1.5 * @see 'admin_bar_menu' action * @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar */ - do_action( 'vaa_admin_bar_menu', $admin_bar ); + do_action( 'vaa_admin_bar_menu', $admin_bar, self::$root ); } @@ -218,75 +237,80 @@ public function admin_bar_menu( $admin_bar, $root = '' ) { */ public function admin_bar_menu_info( $admin_bar ) { + $root = self::$root . '-info'; + $admin_bar->add_node( array( - 'id' => 'info', - 'parent' => 'view-as', + 'id' => $root, + 'parent' => self::$root, 'title' => self::do_icon( 'dashicons-info' ) . __('Info', 'view-admin-as'), 'href' => false, 'meta' => array( - 'class' => 'vaa-has-icon', + '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' ) . ': ' . 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 */ - do_action( 'vaa_admin_bar_info_before', $admin_bar ); + do_action( 'vaa_admin_bar_info_before', $admin_bar, $root, self::$root ); - $info_links = array( - array( - 'id' => 'info-support', - 'title' => self::do_icon( 'dashicons-testimonial' ) . __( 'Need support?', 'view-admin-as' ), - 'href' => 'https://wordpress.org/support/plugin/view-admin-as/', - ), - array( - 'id' => 'info-review', - 'title' => self::do_icon( 'dashicons-star-filled' ) . __( 'Give 5 stars on WordPress.org!', 'view-admin-as' ), - 'href' => 'https://wordpress.org/support/plugin/view-admin-as/reviews/', - ), - array( - 'id' => 'info-issue', - 'title' => self::do_icon( 'dashicons-lightbulb' ) . __( 'Have ideas or a bug report?', 'view-admin-as' ), - 'href' => 'https://github.com/JoryHogeveen/view-admin-as/issues', - ), - array( - 'id' => 'info-translate', - 'title' => self::do_icon( 'dashicons-translation' ) . __( 'Help translating this plugin!', 'view-admin-as' ), - 'href' => 'https://translate.wordpress.org/projects/wp-plugins/view-admin-as', - ), - array( - 'id' => 'info-docs', - 'title' => self::do_icon( 'dashicons-book-alt' ) . __( 'Documentation', 'view-admin-as' ), - 'href' => 'https://github.com/JoryHogeveen/view-admin-as/wiki', - ), - array( - 'id' => 'info-github', - 'title' => self::do_icon( 'dashicons-editor-code' ) . __( 'Follow development on GitHub', 'view-admin-as' ), - 'href' => 'https://github.com/JoryHogeveen/view-admin-as/tree/dev', - ) - ); + // Add the general admin links + if ( is_callable( array( $this->vaa->get_ui('admin'), 'get_links' ) ) ) { + $info_links = $this->vaa->get_ui('admin')->get_links(); - foreach ( $info_links as $link ) { - $admin_bar->add_node( array( - 'parent' => 'info', - 'id' => $link['id'], - 'title' => $link['title'], - 'href' => $link['href'], - 'meta' => array( - 'class' => 'auto-height vaa-has-icon', - 'target' => '_blank' - ), - ) ); + foreach ( $info_links as $id => $link ) { + $admin_bar->add_node( array( + 'parent' => $root, + 'id' => $root . '-' . $id, + 'title' => self::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 */ - do_action( 'vaa_admin_bar_info_after', $admin_bar ); + do_action( 'vaa_admin_bar_info_after', $admin_bar, $root, self::$root ); } @@ -301,88 +325,146 @@ public function admin_bar_menu_info( $admin_bar ) { */ public function admin_bar_menu_settings( $admin_bar ) { + $root = self::$root . '-settings'; + $admin_bar->add_node( array( - 'id' => 'settings', - 'parent' => 'view-as', + 'id' => $root, + 'parent' => self::$root, 'title' => self::do_icon( 'dashicons-admin-settings' ) . __('Settings', 'view-admin-as'), 'href' => false, 'meta' => array( - 'class' => 'vaa-has-icon', + '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 */ - do_action( 'vaa_admin_bar_settings_before', $admin_bar ); + do_action( 'vaa_admin_bar_settings_before', $admin_bar, $root, self::$root ); $admin_bar->add_node( array( - 'id' => 'settings-admin-menu-location', - 'parent' => 'settings', - 'title' => ' - -

            ' . __('Change the location of this menu node', 'view-admin-as') . '

            ', + 'id' => $root . '-admin-menu-location', + 'parent' => $root, + 'title' => self::do_select( array( + 'name' => $root . '-admin-menu-location', + 'value' => $this->get_userSettings('admin_menu_location'), + 'label' => __('Location', 'view-admin-as') . ':   ', + 'description' => __('Change the location of this menu node', 'view-admin-as'), + 'values' => array( + array( + 'compare' => 'top-secondary', + 'label' => __( 'Default', 'view-admin-as' ) + ), + array( + 'compare' => 'my-account', + 'label' => __( 'My account', 'view-admin-as' ) + ) + ) + ) ), 'href' => false, 'meta' => array( - 'class' => 'auto-height', + 'class' => 'auto-height', ), ) ); $admin_bar->add_node( array( - 'id' => 'settings-view-mode', - 'parent' => 'settings', - 'title' => //'

            ' . __('View mode', 'view-admin-as') . '

            - 'get_userSettings('view_mode'), 'browse', false ) . '> -

            ' . __('Store view and use WordPress with this view', 'view-admin-as') . ' (' . __('default', 'view-admin-as') . ')

            - get_userSettings('view_mode'), 'single', false ) . '> -

            ' . __('Choose view on every pageload. This setting doesn\'t store views', 'view-admin-as') . '

            ', + 'id' => $root . '-view-mode', + 'parent' => $root, + 'title' => self::do_radio( array( + 'name' => $root . '-view-mode', + 'value' => $this->get_userSettings('view_mode'), + 'values' => array( + array( + 'compare' => 'browse', + 'label' => __('Browse mode', 'view-admin-as'), + 'description' => __('Store view and use WordPress with this view', 'view-admin-as') + ), + array( + 'compare' => 'single', + 'label' => __('Single switch mode', 'view-admin-as'), + 'description' => __('Choose view on every pageload. This setting doesn\'t store views', 'view-admin-as') + ) + ) + ) ), 'href' => false, 'meta' => array( - 'class' => 'auto-height', + 'class' => 'auto-height', ), ) ); $admin_bar->add_node( array( - 'id' => 'settings-hide-front', - 'parent' => 'settings', - 'title' => 'get_userSettings('hide_front'), 'yes', false ) . '> - -

            ' . __('Hide on frontend when no view is selected and the admin bar is not shown', 'view-admin-as') . '

            ', + 'id' => $root . '-hide-front', + 'parent' => $root, + 'title' => self::do_checkbox( array( + 'name' => $root . '-hide-front', + 'value' => $this->get_userSettings('hide_front'), + 'compare' => 'yes', + 'label' => __('Hide on frontend', 'view-admin-as'), + 'description' => __('Hide on frontend when no view is selected and the admin bar is not shown', 'view-admin-as') + ) ), 'href' => false, 'meta' => array( - 'class' => 'auto-height', + 'class' => 'auto-height', ), ) ); + /** + * Force own locale on view, WP 4.7+ only + * @see https://github.com/JoryHogeveen/view-admin-as/issues/21 + * @since 1.6.1 + */ + if ( function_exists( 'get_user_locale' ) && function_exists( 'switch_to_locale' ) ) { + $admin_bar->add_node( array( + 'id' => $root . '-freeze-locale', + 'parent' => $root, + 'title' => self::do_checkbox( array( + 'name' => $root . '-freeze-locale', + 'value' => $this->get_userSettings('freeze_locale'), + 'compare' => 'yes', + 'label' => __('Freeze locale', 'view-admin-as'), + 'description' => __('Force your own locale setting to the current view', 'view-admin-as') + ) ), + 'href' => false, + 'meta' => array( + 'class' => 'auto-height', + ), + ) ); + } + /** * force_group_users setting * @since 1.5.2 */ if ( true !== $this->groupUserRoles || 15 >= ( count( $this->get_users() ) + count( $this->get_roles() ) ) ) { $admin_bar->add_node( array( - 'id' => 'settings-force-group-users', - 'parent' => 'settings', - 'title' => 'get_userSettings('force_group_users'), "yes", false ) . '> - -

            ' . __('Group users under their assigned roles', 'view-admin-as') . '

            ', + 'id' => $root . '-force-group-users', + 'parent' => $root, + 'title' => self::do_checkbox( array( + 'name' => $root . '-force-group-users', + 'value' => $this->get_userSettings('force_group_users'), + 'compare' => 'yes', + 'label' => __('Group users', 'view-admin-as'), + 'description' => __('Group users under their assigned roles', 'view-admin-as') + ) ), 'href' => false, 'meta' => array( - 'class' => 'auto-height', + 'class' => 'auto-height', + 'tabindex' => '0' ), ) ); } /** * 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 */ - do_action( 'vaa_admin_bar_settings_after', $admin_bar ); + do_action( 'vaa_admin_bar_settings_after', $admin_bar, $root, self::$root ); } /** @@ -401,127 +483,172 @@ public function admin_bar_menu_caps( $admin_bar ) { // Add capabilities group if ( $this->get_caps() && 0 < count( $this->get_caps() ) ) { + $root = self::$root . '-caps'; + $admin_bar->add_group( array( - 'id' => 'caps', - 'parent' => 'view-as', + 'id' => $root, + 'parent' => self::$root, 'meta' => array( 'class' => 'ab-sub-secondary', ), ) ); $admin_bar->add_node( array( - 'id' => 'caps-title', - 'parent' => 'caps', + 'id' => $root . '-title', + 'parent' => $root, 'title' => self::do_icon( 'dashicons-admin-generic' ) . __('Capabilities', 'view-admin-as'), 'href' => false, 'meta' => array( - 'class' => 'vaa-has-icon ab-vaa-title ab-vaa-toggle active', + 'class' => 'vaa-has-icon ab-vaa-title ab-vaa-toggle active', + '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 */ - do_action( 'vaa_admin_bar_caps_before', $admin_bar ); + do_action( 'vaa_admin_bar_caps_before', $admin_bar, $root, self::$root ); $caps_quickselect_class = ''; if ( $this->get_viewAs('caps') ) { $caps_quickselect_class .= ' current'; } $admin_bar->add_node( array( - 'id' => 'caps-quickselect', - 'parent' => 'caps', + 'id' => $root . '-quickselect', + 'parent' => $root, 'title' => __('Select', 'view-admin-as'), 'href' => false, 'meta' => array( - 'class' => $caps_quickselect_class, + 'class' => $caps_quickselect_class, + 'tabindex' => '0' ), ) ); // Capabilities submenu - $admin_bar->add_node( array( - 'id' => 'applycaps', - 'parent' => 'caps-quickselect', - 'title' => ' - - ', - 'href' => false, - 'meta' => array( - 'class' => 'vaa-button-container', - ), - ) ); - $admin_bar->add_node( array( - 'id' => 'filtercaps', - 'parent' => 'caps-quickselect', - 'title' => '', - 'href' => false, - 'meta' => array( - 'class' => 'ab-vaa-filter filter-caps vaa-column-one-half vaa-column-first', - ), - ) ); - $role_select_options = ''; - foreach ( $this->get_roles() as $role_key => $role ) { - $role_select_options .= ''; - $role_select_options .= ''; - } - $admin_bar->add_node( array( - 'id' => 'selectrolecaps', - 'parent' => 'caps-quickselect', - 'title' => '', - 'href' => false, - 'meta' => array( - 'class' => 'ab-vaa-select select-role-caps vaa-column-one-half vaa-column-last', - 'html' => '', - ), - ) ); - $admin_bar->add_node( array( - 'id' => 'bulkselectcaps', - 'parent' => 'caps-quickselect', - 'title' => '' . __('All', 'view-admin-as') . ':   - - ', - 'href' => false, - 'meta' => array( - 'class' => 'vaa-button-container vaa-clear-float', - ), - ) ); - $caps_quickselect_content = ''; - foreach ( $this->get_caps() as $cap_name => $cap_val ) { - $class = 'vaa-cap-item'; - $checked = ''; - // check if we've selected a capability view and we've changed some capabilities - $selected_caps = $this->get_viewAs('caps'); - if ( isset( $selected_caps[ $cap_name ] ) ) { - if ( 1 == $selected_caps[ $cap_name ] ) { - $checked = ' checked="checked"'; - } - } elseif ( 1 == $cap_val ) { - $checked = ' checked="checked"'; + $admin_bar->add_node( array( + 'id' => $root . '-applycaps', + 'parent' => $root . '-quickselect', + 'title' => ' + + ', + 'href' => false, + 'meta' => array( + 'class' => 'vaa-button-container', + ), + ) ); + + $admin_bar->add_node( array( + 'id' => $root . '-filtercaps', + 'parent' => $root . '-quickselect', + 'title' => VAA_View_Admin_As_Admin_Bar::do_input( array( + 'name' => $root . '-filtercaps', + 'placeholder' => esc_attr__('Filter', 'view-admin-as') + ) ), + 'href' => false, + 'meta' => array( + 'class' => 'ab-vaa-filter filter-caps vaa-column-one-half vaa-column-first', + ), + ) ); + + $role_select_options = array( + array( + 'value' => 'default', + 'label' => __('Default', 'view-admin-as') + ) + ); + foreach ( $this->get_roles() as $role_key => $role ) { + $role_select_options[] = array( + 'compare' => esc_attr( $role_key ), + 'label' => '= ' . translate_user_role( $role->name ), + 'attr' => array( + 'data-caps' => json_encode( $role->capabilities ), + ) + ); + $role_select_options[] = array( + 'compare' => 'reversed-' . esc_attr( $role_key ), + 'label' => '≠ ' . translate_user_role( $role->name ), + 'attr' => array( + 'data-caps' => json_encode( $role->capabilities ), + 'data-reverse' => '1' + ) + ); + } + $admin_bar->add_node( array( + 'id' => $root . '-selectrolecaps', + 'parent' => $root . '-quickselect', + 'title' => self::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' => '', + ), + ) ); + + $admin_bar->add_node( array( + 'id' => $root . '-bulkselectcaps', + 'parent' => $root . '-quickselect', + 'title' => self::do_button( array( + 'name' => 'select-all-caps', + 'label' => __('Select', 'view-admin-as'), + 'classes' => 'button-secondary' + ) ) . ' ' . self::do_button( array( + 'name' => 'deselect-all-caps', + 'label' => __('Deselect', 'view-admin-as'), + 'classes' => 'button-secondary' + ) ), + 'href' => false, + 'meta' => array( + 'class' => 'vaa-button-container vaa-clear-float', + ), + ) ); + + $caps_quickselect_content = ''; + foreach ( $this->get_caps() as $cap_name => $cap_val ) { + $class = 'vaa-cap-item'; + $checked = false; + // check if we've selected a capability view and we've changed some capabilities + $selected_caps = $this->get_viewAs('caps'); + if ( isset( $selected_caps[ $cap_name ] ) ) { + if ( 1 == $selected_caps[ $cap_name ] ) { + $checked = true; } - // The list of capabilities - $caps_quickselect_content .= - '
            - - -
            '; + } elseif ( 1 == $cap_val ) { + $checked = true; } - $admin_bar->add_node( array( - 'id' => 'caps-quickselect-options', - 'parent' => 'caps-quickselect', - 'title' => $caps_quickselect_content, - 'href' => false, - 'meta' => array( - 'class' => 'ab-vaa-multipleselect auto-height', - ), - ) ); + // The list of capabilities + $caps_quickselect_content .= + '
            ' + . self::do_checkbox( array( + 'name' => 'vaa_cap_' . esc_attr( $cap_name ), + 'value' => $checked, + 'compare' => true, + 'checkbox_value' => esc_attr( $cap_name ), + 'label' => str_replace( '_', ' ', $cap_name ) + ) ) + . '
            '; + } + $admin_bar->add_node( array( + 'id' => $root . '-quickselect-options', + 'parent' => $root . '-quickselect', + 'title' => $caps_quickselect_content, + 'href' => false, + 'meta' => array( + 'class' => 'ab-vaa-multipleselect auto-height', + ), + ) ); /** * 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 */ - do_action( 'vaa_admin_bar_caps_after', $admin_bar ); + do_action( 'vaa_admin_bar_caps_after', $admin_bar, $root, self::$root ); } } @@ -538,34 +665,40 @@ public function admin_bar_menu_roles( $admin_bar ) { if ( $this->get_roles() && 0 < count( $this->get_roles() ) ) { + $root = self::$root . '-roles'; + $admin_bar->add_group( array( - 'id' => 'roles', - 'parent' => 'view-as', + 'id' => $root, + 'parent' => self::$root, 'meta' => array( 'class' => 'ab-sub-secondary', ), ) ); $admin_bar->add_node( array( - 'id' => 'roles-title', - 'parent' => 'roles', + 'id' => $root . '-title', + 'parent' => $root, 'title' => self::do_icon( 'dashicons-groups' ) . __('Roles', 'view-admin-as'), 'href' => false, 'meta' => array( - 'class' => 'vaa-has-icon ab-vaa-title ab-vaa-toggle active', + '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 */ - do_action( 'vaa_admin_bar_roles_before', $admin_bar ); + do_action( 'vaa_admin_bar_roles_before', $admin_bar, self::$root ); // Add the roles - foreach( $this->get_roles() as $role_key => $role ) { + foreach ( $this->get_roles() as $role_key => $role ) { + $parent = $root; $href = '#'; $class = 'vaa-role-item'; + $has_icon = false; $title = translate_user_role( $role->name ); // Check if the users need to be grouped under their roles if ( true === $this->groupUserRoles ) { @@ -585,30 +718,34 @@ public function admin_bar_menu_roles( $admin_bar ) { $title = $title . ' (' . $user_count . ')'; } } + if ( $has_icon ) { + $class .= ' vaa-has-icon'; + } // Check if this role is the current view if ( $this->get_viewAs('role') && $this->get_viewAs('role') == strtolower( $role->name ) ) { $class .= ' current'; $href = false; } $admin_bar->add_node( array( - 'id' => 'role-' . $role_key, - 'parent' => 'roles', + 'id' => $root . '-role-' . $role_key, + 'parent' => $parent, 'title' => $title, 'href' => $href, 'meta' => array( 'title' => esc_attr__('View as', 'view-admin-as') . ' ' . translate_user_role( $role->name ), 'class' => $class, - 'rel' => $role_key, + 'rel' => $role_key ), ) ); } /** * 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 */ - do_action( 'vaa_admin_bar_roles_after', $admin_bar ); + do_action( 'vaa_admin_bar_roles_after', $admin_bar, $root, self::$root ); } } @@ -625,35 +762,42 @@ public function admin_bar_menu_users( $admin_bar ) { if ( $this->get_users() && 0 < count( $this->get_users() ) ) { + $root = self::$root . '-users'; + $admin_bar->add_group( array( - 'id' => 'users', - 'parent' => 'view-as', + 'id' => $root, + 'parent' => self::$root, 'meta' => array( 'class' => 'ab-sub-secondary', ), ) ); $admin_bar->add_node( array( - 'id' => 'users-title', - 'parent' => 'users', + 'id' => $root . '-title', + 'parent' => $root, 'title' => self::do_icon( 'dashicons-admin-users' ) . __('Users', 'view-admin-as'), 'href' => false, 'meta' => array( - 'class' => 'vaa-has-icon ab-vaa-title ab-vaa-toggle active', + 'class' => 'vaa-has-icon ab-vaa-title ab-vaa-toggle active', + 'tabindex' => '0' ), ) ); /** * 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 */ - do_action( 'vaa_admin_bar_users_before', $admin_bar ); + do_action( 'vaa_admin_bar_users_before', $admin_bar, $root, self::$root ); if ( true === $this->searchUsers ) { $admin_bar->add_node( array( - 'id' => 'searchuser', - 'parent' => 'users', - 'title' => '', + 'id' => $root . '-searchusers', + 'parent' => $root, + 'title' => self::do_input( array( + 'name' => $root . '-searchusers', + 'placeholder' => esc_attr__('Search', 'view-admin-as') . ' (' . strtolower( __('Username', 'view-admin-as') ) . ')' + ) ), 'href' => false, 'meta' => array( 'class' => 'ab-vaa-search search-users', @@ -662,7 +806,8 @@ public function admin_bar_menu_users( $admin_bar ) { ) ); } // Add the users - foreach( $this->get_users() as $user_key => $user ) { + foreach ( $this->get_users() as $user_key => $user ) { + $parent = $root; $href = '#'; $title = $user->data->display_name; $class = 'vaa-user-item'; @@ -671,14 +816,12 @@ public function admin_bar_menu_users( $admin_bar ) { $class .= ' current'; $href = false; } - $parent = 'users'; - if ( true === $this->groupUserRoles ) { // Users grouped under roles foreach ( $user->roles as $role ) { - $parent = 'role-' . $role; + $parent = self::$root . '-roles-role-' . $role; $admin_bar->add_node( array( - 'id' => 'user-' . $user->data->ID . '-' . $role, + 'id' => $root . '-user-' . $user->data->ID . '-' . $role, 'parent' => $parent, 'title' => $title, 'href' => $href, @@ -699,7 +842,7 @@ public function admin_bar_menu_users( $admin_bar ) { } $title = $title.'   (' . implode( ', ', $user_roles ) . ')'; $admin_bar->add_node( array( - 'id' => 'user-' . $user->data->ID, + 'id' => $root . '-user-' . $user->data->ID, 'parent' => $parent, 'title' => $title, 'href' => $href, @@ -714,21 +857,298 @@ public function admin_bar_menu_users( $admin_bar ) { /** * 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 */ - do_action( 'vaa_admin_bar_users_after', $admin_bar ); + do_action( 'vaa_admin_bar_users_after', $admin_bar, $root, self::$root ); + } + } + + /** + * Generate button HTML for node + * + * @since 1.6.1 + * @access public + * @static + * @param array $args { + * Required. An array of field arguments + * @type string $name Required + * @type string $label Optional + * @type string $classes Optional + * @type array $attr Optional + * } + * @return string + */ + public static function do_button( $args ) { + $id = esc_attr( $args['name'] ); + $name = str_replace( '-', '_', $id ); + $label = esc_attr( ( ! empty( $args['label'] ) ) ? $args['label'] : $args['value'] ); + $classes = ' classes="button' . ( ( ! empty( $args['classes'] ) ) ? ' ' . $args['classes'] : '' ) . '"'; + $attr = ( ! empty( $args['attr'] ) ) ? self::parse_attr_to_html( $args['attr'] ) : ''; + return ''; + } + + /** + * Generate text input HTML for node + * + * @since 1.6.1 + * @access public + * @static + * @param array $args { + * Required. An array of field arguments + * @type string $name Required + * @type string $placeholder Optional + * @type string $default Optional + * @type string $value Optional + * @type string $label Optional + * @type string $description Optional + * @type string $classes Optional + * @type array $attr Optional + * } + * @return string + */ + public static function do_input( $args ) { + + $html = ''; + + $id = esc_attr( $args['name'] ); + $name = str_replace( '-', '_', $id ); + $default = ( ! empty( $args['default'] ) ) ? $args['default'] : ''; + $value = ( ! empty( $args['value'] ) ) ? $args['value'] : $default; + $placeholder = ( ! empty( $args['placeholder'] ) ) ? ' placeholder="' . $args['placeholder'] . '"' : ''; + $classes = ( ! empty( $args['classes'] ) ) ? ' classes="' . $args['classes'] . '"' : ''; + $attr = ( ! empty( $args['attr'] ) ) ? self::parse_attr_to_html( $args['attr'] ) : ''; + + if ( ! empty( $args['label'] ) ) { + $html .= self::do_label( $args['label'], $id ); + } + $html .= ''; + if ( ! empty( $args['description'] ) ) { + $html .= self::do_description( $args['description'] ); + } + return $html; + } + + /** + * Generate checkbox HTML for node + * + * @since 1.6.1 + * @access public + * @static + * @param array $args { + * Required. An array of field arguments + * @type string $name Required + * @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 $classes Optional + * @type array $attr Optional + * } + * @return string + */ + public static function do_checkbox( $args ) { + + $html = ''; + + $id = esc_attr( $args['name'] ); + $name = str_replace( '-', '_', $id ); + + if ( empty( $args['value'] ) ) { + $args['value'] = null; + } + if ( empty( $args['compare'] ) ) { + $args['compare'] = 1; + } + $checked = checked( $args['value'], $args['compare'], false ); + $classes = ( ! empty( $args['classes'] ) ) ? ' ' . $args['classes'] : ''; + $attr = ( ! empty( $args['attr'] ) ) ? self::parse_attr_to_html( $args['attr'] ) : ''; + $value = ( ! empty( $args['checkbox_value'] ) ) ? $args['checkbox_value'] : '1'; + + $html .= ''; + if ( ! empty( $args['label'] ) ) { + $html .= self::do_label( $args['label'], $id ); + } + if ( ! empty( $args['description'] ) ) { + $html .= self::do_description( $args['description'] ); } + return $html; + } + + /** + * Generate radio HTML for node + * + * @since 1.6.1 + * @access public + * @static + * @param array $data { + * Required. An array of arrays with field arguments + * @type string $name Required + * @type string $value Optional + * @type string $description Optional + * @type array $values { + * @type array $args { + * @type string $compare Required + * @type string $label Optional + * @type string $description Optional + * @type string $classes Optional + * @type array $attr Optional + * } + * } + * } + * @return string + */ + public static function do_radio( $data ) { + + $html = ''; + + if ( is_array( $data ) && ! empty( $data['values'] ) ) { + foreach ( $data['values'] as $args ) { + + $id = esc_attr( $data['name'] . '-' . $args['compare'] ); + $name = str_replace( '-', '_', esc_attr( $data['name'] ) ); + + if ( empty( $data['value'] ) ) { + $data['value'] = null; + } + $checked = checked( $data['value'], $args['compare'], false ); + $classes = ( ! empty( $args['classes'] ) ) ? ' ' . $args['classes'] : ''; + $classes .= ' ' . esc_attr( $data['name'] ); + $attr = ( ! empty( $args['attr'] ) ) ? self::parse_attr_to_html( $args['attr'] ) : ''; + + $html .= ''; + if ( ! empty( $args['label'] ) ) { + $html .= self::do_label( $args['label'], $id ); + } + if ( ! empty( $args['description'] ) ) { + $html .= self::do_description( $args['description'] ); + } + } + if ( ! empty( $data['description'] ) ) { + $html .= self::do_description( $data['description'] ); + } + } + return $html; + } + + /** + * Generate selectbox HTML for node + * + * @since 1.6.1 + * @access public + * @static + * @param array $data { + * Required. An array of arrays with field arguments + * @type string $name Required + * @type string $value Optional + * @type string $label Optional + * @type string $description Optional + * @type string $classes Optional + * @type array $attr Optional + * @type array $values { + * @type array $args { + * @type string $compare Required + * @type string $value Optional (Alias for compare) + * @type string $label Optional + * @type string $classes Optional + * @type array $attr Optional + * } + * } + * } + * @return string + */ + public static function do_select( $data ) { + + $html = ''; + + if ( is_array( $data ) && ! empty( $data['values'] ) ) { + $id = esc_attr( $data['name'] ); + $name = str_replace( '-', '_', $id ); + + if ( ! empty( $data['label'] ) ) { + $html .= self::do_label( $data['label'], $id ); + } + + if ( empty( $data['value'] ) ) { + $data['value'] = null; + } + $classes = ( ! empty( $data['classes'] ) ) ? ' ' . $data['classes'] : ''; + $attr = ( ! empty( $data['attr'] ) ) ? self::parse_attr_to_html( $data['attr'] ) : ''; + $html .= ''; + + if ( ! empty( $data['description'] ) ) { + $html .= self::do_description( $data['description'] ); + } + } + return $html; } /** * Returns icon html for WP admin bar - * @since 1.6 + * @since 1.6.1 + * @static * @param string $icon * @return string */ public static function do_icon( $icon ) { - return ''; + return ''; + } + + /** + * Returns label html for WP admin bar + * @since 1.6.1 + * @static + * @param string $label + * @param string $for + * @return string + */ + public static function do_label( $label, $for = '' ) { + $for = ( ! empty( $for ) ) ? ' for="' . $for . '"' : ''; + return '' . $label . ''; + } + + /** + * Returns description html for WP admin bar + * @since 1.6.1 + * @static + * @param string $text + * @return string + */ + public static function do_description( $text ) { + return '

            ' . $text . '

            '; + } + + /** + * Converts an array of attributes to a HTML string format starting with a space + * @since 1.6.1 + * @static + * @param array $array + * @return string + */ + public static function parse_attr_to_html( $array ) { + $str = ''; + if ( is_array( $array ) && ! empty( $array ) ) { + foreach ( $array as $attr => $value ) { + $array[ $attr ] = esc_attr( $attr ) . '="' . esc_attr( $value ) . '"'; + } + $str = ' ' . implode( ' ', $array ); + } + return $str; } /** @@ -739,17 +1159,17 @@ public static function do_icon( $icon ) { * @since 1.5 * @access public * @static - * @param object|bool $caller The referrer class - * @return VAA_View_Admin_As_Admin_Bar|bool + * @param VAA_View_Admin_As $caller The referrer class + * @return VAA_View_Admin_As_Admin_Bar */ - public static function get_instance( $caller = false ) { + public static function get_instance( $caller = null ) { if ( is_object( $caller ) && 'VAA_View_Admin_As' == get_class( $caller ) ) { if ( is_null( self::$_instance ) ) { - self::$_instance = new self(); + self::$_instance = new self( $caller ); } return self::$_instance; } - return false; + return null; } } // end class diff --git a/ui/class-admin.php b/ui/class-admin.php index b7beb12c..a96e55df 100644 --- a/ui/class-admin.php +++ b/ui/class-admin.php @@ -4,11 +4,10 @@ * * Admin UI hooks for View Admin As * - * @author Jory Hogeveen + * @author Jory Hogeveen * @package view-admin-as * @since 1.6 - * @version 1.6 - * @see wp-includes/class-wp-admin-bar.php + * @version 1.6.1 */ ! defined( 'VIEW_ADMIN_AS_DIR' ) and die( 'You shall not pass!' ); @@ -17,11 +16,20 @@ final class VAA_View_Admin_As_Admin extends VAA_View_Admin_As_Class_Base { + /** + * Plugin links + * + * @since 1.6.1 + * @var array + */ + private $links = array(); + /** * The single instance of the class. * - * @since 1.6 - * @var VAA_View_Admin_As_Admin_Bar + * @since 1.6 + * @static + * @var VAA_View_Admin_As_Admin */ private static $_instance = null; @@ -29,16 +37,19 @@ final class VAA_View_Admin_As_Admin extends VAA_View_Admin_As_Class_Base * Construct function * * @since 1.6 + * @since 1.6.1 $vaa param * @access protected + * @param VAA_View_Admin_As $vaa */ - protected function __construct() { + protected function __construct( $vaa ) { self::$_instance = $this; - parent::__construct(); + parent::__construct( $vaa ); if ( $this->store->get_userSettings('view_mode') == 'browse' ) { add_filter( 'user_row_actions', array( $this, 'filter_user_row_actions' ), 10, 2 ); } - //add_action( 'wp_meta', array( $this, 'action_wp_meta' ) ); + add_action( 'wp_meta', array( $this, 'action_wp_meta' ) ); + add_action( 'plugin_row_meta', array( $this, 'action_plugin_row_meta' ), 10, 2 ); } /** @@ -58,7 +69,12 @@ public function filter_user_row_actions( $actions, $user ) { } else { $link = admin_url(); } - $link .= '?action=view_admin_as&view_admin_as=' . htmlentities( json_encode( $data ) ) . '&_vaa_nonce=' . $this->store->get_nonce( true ); + $params = array( + 'action' => 'view_admin_as', + 'view_admin_as' => htmlentities( json_encode( $data ) ), + '_vaa_nonce' => $this->store->get_nonce( true ) + ); + $link .= '?' . http_build_query( $params ); $actions['vaa_view'] = '' . __( 'View as', 'view-admin-as' ) . ''; return $actions; @@ -67,7 +83,7 @@ public function filter_user_row_actions( $actions, $user ) { /** * Adds a 'View Admin As: Reset view' link to the Meta sidebar widget if the admin bar is hidden * - * @since 1.6 + * @since 1.6.1 * @access public */ public function action_wp_meta() { @@ -79,6 +95,80 @@ public function action_wp_meta() { } } + /** + * Show row meta on the plugin screen + * + * @since 1.6.1 + * @param array $links + * @param string $file + * @return array + */ + public function action_plugin_row_meta( $links, $file ) { + if ( $file == VIEW_ADMIN_AS_BASENAME ) { + foreach ( $this->get_links() as $id => $link ) { + $links[ $id ] = '' . esc_html( $link['title'] ) . ''; + } + } + return $links; + } + + /** + * Plugin links + * + * @since 1.6.1 + * @return array + */ + public function get_links() { + if ( empty( $this->links ) ) { + $this->links = array( + 'support' => array( + 'title' => __( 'Support', 'view-admin-as' ), + 'description' => __( 'Need support?', 'view-admin-as' ), + 'icon' => 'dashicons-testimonial', + 'url' => 'https://wordpress.org/support/plugin/view-admin-as/', + ), + 'review' => array( + 'title' => __( 'Review', 'view-admin-as' ), + 'description' => __( 'Give 5 stars on WordPress.org!', 'view-admin-as' ), + 'icon' => 'dashicons-star-filled', + 'url' => 'https://wordpress.org/support/plugin/view-admin-as/reviews/', + ), + 'translate' => array( + 'title' => __( 'Translate', 'view-admin-as' ), + 'description' => __( 'Help translating this plugin!', 'view-admin-as' ), + 'icon' => 'dashicons-translation', + 'url' => 'https://translate.wordpress.org/projects/wp-plugins/view-admin-as', + ), + 'issue' => array( + 'title' => __( 'Report issue', 'view-admin-as' ), + 'description' => __( 'Have ideas or a bug report?', 'view-admin-as' ), + 'icon' => 'dashicons-lightbulb', + 'url' => 'https://github.com/JoryHogeveen/view-admin-as/issues', + ), + 'docs' => array( + 'title' => __( 'Documentation', 'view-admin-as' ), + 'description' => __( 'Documentation', 'view-admin-as' ), + 'icon' => 'dashicons-book-alt', + 'url' => 'https://github.com/JoryHogeveen/view-admin-as/wiki', + ), + 'github' => array( + 'title' => __( 'GitHub', 'view-admin-as' ), + 'description' => __( 'Follow development on GitHub', 'view-admin-as' ), + 'icon' => 'dashicons-editor-code', + 'url' => 'https://github.com/JoryHogeveen/view-admin-as/tree/dev', + ), + 'donate' => array( + 'title' => __( 'Donate', 'view-admin-as' ), + 'description' => __( 'Buy me a coffee!', 'view-admin-as' ), + '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', + ) + ); + } + + return $this->links; + } + /** * Main Instance. * @@ -87,17 +177,17 @@ public function action_wp_meta() { * @since 1.6 * @access public * @static - * @param object|bool $caller The referrer class - * @return VAA_View_Admin_As_Admin_Bar|bool + * @param VAA_View_Admin_As $caller The referrer class + * @return VAA_View_Admin_As_Admin */ - public static function get_instance( $caller = false ) { + public static function get_instance( $caller = null ) { if ( is_object( $caller ) && 'VAA_View_Admin_As' == get_class( $caller ) ) { if ( is_null( self::$_instance ) ) { - self::$_instance = new self(); + self::$_instance = new self( $caller ); } return self::$_instance; } - return false; + return null; } } // end class diff --git a/ui/class-toolbar.php b/ui/class-toolbar.php index ef58efed..ef25ce16 100644 --- a/ui/class-toolbar.php +++ b/ui/class-toolbar.php @@ -4,11 +4,11 @@ * * Toolbar UI for View Admin As * - * @author Jory Hogeveen + * @author Jory Hogeveen * @package view-admin-as * @since 1.6 - * @version 1.6 - * @see wp-includes/class-wp-admin-bar.php + * @version 1.6.1 + * @see wp-includes/class-wp-admin-bar.php */ ! defined( 'VIEW_ADMIN_AS_DIR' ) and die( 'You shall not pass!' ); @@ -24,37 +24,41 @@ final class VAA_View_Admin_As_Toolbar extends WP_Admin_Bar /** * The single instance of the class. * - * @since 1.6 - * @var VAA_View_Admin_As_Admin_Bar + * @since 1.6 + * @static + * @var VAA_View_Admin_As_Toolbar */ private static $_instance = null; /** * Is this toolbar being rendered? * - * @since 1.6 - * @var bool + * @since 1.6 + * @static + * @var bool */ public static $showing = false; /** * View Admin As store * - * @since 1.6 - * @var object|bool + * @since 1.6 + * @var object */ - private $vaa_store = false; + 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 */ - protected function __construct() { + protected function __construct( $vaa ) { self::$_instance = $this; - $this->vaa_store = View_Admin_As( $this )->store(); + $this->vaa_store = $vaa->store(); if ( ! is_admin() ) { add_action( 'vaa_view_admin_as_init', array( $this, 'vaa_init' ) ); @@ -128,17 +132,17 @@ public function vaa_toolbar_render() { * @since 1.6 * @access public * @static - * @param object|bool $caller The referrer class - * @return VAA_View_Admin_As_Admin_Bar|bool + * @param object $caller The referrer class + * @return VAA_View_Admin_As_Toolbar */ - public static function get_instance( $caller = false ) { + public static function get_instance( $caller = null ) { if ( is_object( $caller ) && 'VAA_View_Admin_As' == get_class( $caller ) ) { if ( is_null( self::$_instance ) ) { - self::$_instance = new self(); + self::$_instance = new self( $caller ); } return self::$_instance; } - return false; + return null; } } // end class diff --git a/view-admin-as.php b/view-admin-as.php index 905a01c9..2761dcb2 100644 --- a/view-admin-as.php +++ b/view-admin-as.php @@ -3,7 +3,7 @@ * Plugin Name: View Admin As * Description: View the WordPress admin as a specific role, switch between users and temporarily change your capabilities. * Plugin URI: https://wordpress.org/plugins/view-admin-as/ - * Version: 1.6 + * Version: 1.6.1 * Author: Jory Hogeveen * Author URI: https://www.keraweb.nl * Text Domain: view-admin-as @@ -13,7 +13,7 @@ * @author Jory Hogeveen * @package view-admin-as * @since 0.1 - * @version 1.6 + * @version 1.6.1 */ /* @@ -40,12 +40,12 @@ if ( ! class_exists( 'VAA_View_Admin_As' ) ) { - define( 'VIEW_ADMIN_AS_VERSION', '1.6' ); + define( 'VIEW_ADMIN_AS_VERSION', '1.6.1' ); define( 'VIEW_ADMIN_AS_DB_VERSION', '1.6' ); - define( 'VIEW_ADMIN_AS_FILE', __FILE__ ); - define( 'VIEW_ADMIN_AS_BASENAME', plugin_basename( VIEW_ADMIN_AS_FILE ) ); - define( 'VIEW_ADMIN_AS_DIR', plugin_dir_path( VIEW_ADMIN_AS_FILE ) ); - define( 'VIEW_ADMIN_AS_URL', plugin_dir_url( VIEW_ADMIN_AS_FILE ) ); + define( 'VIEW_ADMIN_AS_FILE', __FILE__ ); + define( 'VIEW_ADMIN_AS_BASENAME', plugin_basename( VIEW_ADMIN_AS_FILE ) ); + define( 'VIEW_ADMIN_AS_DIR', plugin_dir_path( VIEW_ADMIN_AS_FILE ) ); + define( 'VIEW_ADMIN_AS_URL', plugin_dir_url( VIEW_ADMIN_AS_FILE ) ); // Include main init class file require_once( VIEW_ADMIN_AS_DIR . 'includes/class-vaa.php' ); @@ -54,6 +54,7 @@ * Main instance of View Admin As. * * Returns the main instance of VAA_View_Admin_As to prevent the need to use globals. + * Only for internal use. If the $caller parameter passes an unknown object it will return null. * * @since 1.4.1 * @since 1.6 $caller parameter @@ -77,6 +78,7 @@ function view_admin_as_conflict_admin_notice() { . __('Plugin not activated because of a conflict with an other plugin or theme', 'view-admin-as') . ' (' . sprintf( __( 'Class %s already exists', 'view-admin-as' ), 'VAA_View_Admin_As' ) . ')' . '

          '; } + require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); deactivate_plugins( plugin_basename( __FILE__ ) ); }