diff --git a/README.md b/README.md index 7dff71d5..f615e336 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ This plugin will work with most other plugins but these are tested: * **BuddyPress** * **Genesis Framework** *(and probably other theme frameworks)* * **Gravity Forms** +* **Groups 2.1+** *(Custom integration: adds a view type for groups. Pro version not tested)* * **Pods Framework 2.0+** * **Members** * **Restrict User Access 0.13+** *(Custom integration: adds a view type for access levels)* diff --git a/assets/css/view-admin-as.css b/assets/css/view-admin-as.css index 6e5bc6be..76d2b788 100644 --- a/assets/css/view-admin-as.css +++ b/assets/css/view-admin-as.css @@ -5,7 +5,7 @@ * @author Jory Hogeveen * @package View_Admin_As * @since 1.1 - * @version 1.7.1 + * @version 1.7.2 * @preserve */ @@ -91,7 +91,7 @@ * Icon fixes */ #wpadminbar #wp-admin-bar-vaa > .ab-item > .ab-label {float: left;} /* IE fix */ -#wpadminbar #wp-admin-bar-vaa > .ab-item > .ab-icon {float: right; margin-right: 0; margin-left: 6px; top: 2px;} +#wpadminbar #wp-admin-bar-vaa > .ab-item .ab-icon {float: right; 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; line-height: 16px; vertical-align: text-bottom; font-weight: normal !important; 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;} diff --git a/assets/css/view-admin-as.min.css b/assets/css/view-admin-as.min.css index a59dbee9..db5e0438 100644 --- a/assets/css/view-admin-as.min.css +++ b/assets/css/view-admin-as.min.css @@ -5,7 +5,7 @@ * @author Jory Hogeveen * @package View_Admin_As * @since 1.1 - * @version 1.7.1 + * @version 1.7.2 * @preserve */ -.vaa-loader-icon{width:40px;height:40px;background:transparent url('../../../../../wp-includes/images/spinner-2x.gif') center center no-repeat;background-size:contain}#vaa-overlay{position:fixed;top:0;left:0;height:100%;width:100%;background:rgba(255,255,255,0.85);display:none;z-index:999999999}#vaa-overlay .vaa-loader-icon{position:fixed;top:50%;left:50%;margin:-20px 0 0 -20px;display:block}#vaa-overlay .vaa-overlay-container{max-width:75%;min-width:50%;max-height:50%;min-height:20px;margin:0 25%;top:10%;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;cursor:pointer}#vaa-overlay .vaa-overlay-container .vaa-response-data{overflow:hidden;overflow-y:auto}#vaa-overlay .vaa-overlay-container .vaa-response-data ul li{margin-left:20px;list-style:disc outside}#vaa-overlay .vaa-overlay-container.vaa-message{border:2px solid #0075b3}#vaa-overlay .vaa-overlay-container.vaa-warning{border:2px solid #c8730c}#vaa-overlay .vaa-overlay-container.vaa-error{border:2px solid #dc3232}#vaa-overlay .vaa-overlay-container.vaa-success{border:2px solid #46b450}#wpadminbar .vaa-notice{display:inline-block;padding:0 5px 0 10px;background:#fff}#wpadminbar .vaa-notice.vaa-message,#wpadminbar .vaa-notice.vaa-message .ab-icon:before{color:#0075b3 !important}#wpadminbar .vaa-notice.vaa-warning,#wpadminbar .vaa-notice.vaa-warning .ab-icon:before{color:#c8730c !important}#wpadminbar .vaa-notice.vaa-error,#wpadminbar .vaa-notice.vaa-error .ab-icon:before{color:#dc3232 !important}#wpadminbar .vaa-notice.vaa-success,#wpadminbar .vaa-notice.vaa-success .ab-icon:before{color:#46b450 !important}#wpadminbar #wp-admin-bar-vaa .vaa-notice{display:block;clear:both;margin-bottom:3px}#wpadminbar #wp-admin-bar-vaa .vaa-notice button{vertical-align:baseline;margin:0 0 0 -5px;padding:1px 10px}#wpadminbar .vaa-notice .remove,#wpadminbar #wp-admin-bar-vaa .remove{cursor:pointer;top:2px;float:right;margin-right:0;margin-left:6px}#wpadminbar #wp-admin-bar-vaa ul li,#wpadminbar #wp-admin-bar-vaa .ab-item{clear:both}#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper .ab-item>span{line-height:26px}#wpadminbar #wp-admin-bar-vaa .ab-item>span.remove{font-size:16px;line-height:16px;top:1px}#wpadminbar #wp-admin-bar-vaa .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:.5;transition:opacity .2s}#wpadminbar #wp-admin-bar-vaa .vaa-sub-transparent:hover>*{opacity:1}#wpadminbar #wp-admin-bar-vaa .ab-vaa-results{margin:6px 0;padding:0}#wpadminbar #wp-admin-bar-vaa .ab-vaa-results:empty{display:none}#wpadminbar #wp-admin-bar-vaa .ab-vaa-spacing-top,#wpadminbar #wp-admin-bar-vaa>div>ul.ab-sub-secondary+ul.ab-sub-secondary{margin-top:3px}#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper .ab-sub-wrapper ul.ab-sub-secondary+ul.ab-sub-secondary{padding-top:0}#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:.8em;font-style:italic;margin-bottom:7px;white-space:normal}#wpadminbar #wp-admin-bar-vaa .ab-item .description:first-child{margin-bottom:0}#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>.ab-item .vaa-view-data,#wpadminbar #wp-admin-bar-vaa .current>input:checked+label,#wpadminbar #wp-admin-bar-vaa .current-parent>.ab-item,#wpadminbar #wp-admin-bar-vaa .current-parent>.ab-item .vaa-view-data,#wpadminbar #wp-admin-bar-vaa .current-parent>label{font-weight:bold}#wpadminbar #wp-admin-bar-vaa .current>.ab-item::after,#wpadminbar #wp-admin-bar-vaa .current>label::after{content:'\f177';font-family:'dashicons';margin:0 5px;font-size:17px;vertical-align:middle;font-weight:normal}#wpadminbar #wp-admin-bar-vaa>.ab-item>.ab-label{float:left}#wpadminbar #wp-admin-bar-vaa>.ab-item>.ab-icon{float:right;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;line-height:16px;vertical-align:text-bottom;font-weight:normal !important;padding:0}#wpadminbar #wp-admin-bar-vaa .vaa-has-icon>.ab-item::before{display:none}#wpadminbar #wp-admin-bar-vaa .vaa-has-icon.menupop>.ab-item{padding-left:10px;padding-right:10px}#wpadminbar #wp-admin-bar-vaa .vaa-has-icon.ab-vaa-title>.ab-item>.ab-icon{font-size:18px;line-height:20px;margin:0 5px 0 -1px}#wpadminbar .ab-top-secondary .menupop .vaa-menupop>.ab-item{padding-left:2em;padding-right:1em}#wpadminbar .ab-top-secondary .menupop .vaa-menupop>.ab-item .ab-icon{margin-left:-20px;margin-right:4px}#wpadminbar #wp-admin-bar-vaa.menupop ul.ab-sub-secondary{position:static}#wpadminbar #wp-admin-bar-vaa.menupop .menupop>.ab-item:before{top:1px}#wpadminbar #wp-admin-bar-vaa button>.ab-icon{margin:0 5px 0 -5px;padding:0;top:0}#wpadminbar #wp-admin-bar-vaa .ab-item>label+button{margin:0 0 0 12px;vertical-align:baseline}#wpadminbar #wp-admin-bar-vaa .vaa-button-container>.ab-item{overflow:hidden;height:auto}#wpadminbar #wp-admin-bar-vaa button{float:none;text-decoration:none;font-size:13px;line-height:20px;height:20px;margin:3px 0;padding:0 10px 1px;vertical-align:middle;cursor:pointer}#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 .vaa-auto-max-height{min-height:26px;overflow-y:auto;transition:max-height .3s}#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect .ab-item,#wpadminbar #wp-admin-bar-vaa .ab-vaa-input .ab-item,#wpadminbar #wp-admin-bar-vaa .ab-vaa-search .ab-item,#wpadminbar #wp-admin-bar-vaa .ab-vaa-filter .ab-item,#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item{height:auto;clear:both}#wpadminbar #wp-admin-bar-vaa .ab-vaa-input .ab-item input,#wpadminbar #wp-admin-bar-vaa .ab-vaa-search .ab-item input,#wpadminbar #wp-admin-bar-vaa .ab-vaa-filter .ab-item input,#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item select{display:inline-block;background:#fff;color:#555;margin:5px 0;padding:3px;border:0;line-height:normal;height:auto;width:100%;box-sizing:border-box}#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item select{padding:2px 3px}#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item label+input,#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item label+select{margin-top:0}#wpadminbar #wp-admin-bar-vaa .ab-vaa-textarea .ab-item{height:auto;line-height:normal}#wpadminbar #wp-admin-bar-vaa .ab-vaa-textarea .ab-item textarea{width:100%;padding:5px;margin-top:5px;box-sizing:border-box;line-height:normal}#wpadminbar #wp-admin-bar-vaa .ab-item select+button.input-overlay,#wpadminbar #wp-admin-bar-vaa .ab-item input+button.input-overlay{position:absolute;right:10px;margin:5px 0}#wpadminbar #wp-admin-bar-vaa input.checkbox,#wpadminbar #wp-admin-bar-vaa input.radio{display:inline-block;height:16px;width:16px;vertical-align:text-bottom;box-sizing:border-box;cursor:pointer}#wpadminbar #wp-admin-bar-vaa .ab-item input.checkbox,#wpadminbar #wp-admin-bar-vaa .ab-item input.radio{margin:0 5px 0 0}#wpadminbar #wp-admin-bar-vaa .ab-item input.checkbox+label,#wpadminbar #wp-admin-bar-vaa .ab-item input.checkbox+label *,#wpadminbar #wp-admin-bar-vaa .ab-item input.radio+label,#wpadminbar #wp-admin-bar-vaa .ab-item input.radio+label *{line-height:18px;vertical-align:text-top;display:inline}#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 6px 0 0}#wpadminbar #wp-admin-bar-vaa .ab-item input.radio{border-radius:100%}#wpadminbar #wp-admin-bar-vaa .ab-item input.radio+label+br{line-height:0}#wpadminbar #wp-admin-bar-vaa input.checkbox.vaa-right,#wpadminbar #wp-admin-bar-vaa input.radio.vaa-right{position:absolute;top:5px;right:1em;z-index:99}#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect{max-height:400px;min-width:250px;overflow:hidden;overflow-y:auto;margin:6px 0;padding:0;border:solid transparent;border-width:0 10px}#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect .ab-empty-item{height:auto;overflow:hidden;margin:0;padding:5px 10px;background-color:#fff}#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect .ab-empty-item .ab-item{color:#333}#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect.vaa-small{max-height:100px}#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect .remove:before{color:#333}#wpadminbar #wp-admin-bar-vaa .vaa-column-one-half{width:50%;display:block;float:left;clear:none}#wpadminbar #wp-admin-bar-vaa .vaa-column-one-half .ab-item{min-width:0}#wpadminbar #wp-admin-bar-vaa .vaa-column-one-half.vaa-column-first .ab-item{padding-right:1px}#wpadminbar #wp-admin-bar-vaa .vaa-column-one-half.vaa-column-last .ab-item{padding-left:1px}#wpadminbar #wp-admin-bar-vaa .vaa-clear-float{clear:both}#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle .ab-item{padding-right:34px}#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle .ab-item:hover{cursor:pointer}#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle .ab-item::after{content:"\f140";font-family:'dashicons';position:absolute;right:10px;margin:0;font-size:20px;font-weight:normal}#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle.active .ab-item::after{content:"\f142"}#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 #wp-admin-bar-vaa-caps #apply-caps-view{float:left;margin-right:5px}#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #reset-caps-view,#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #open-caps-popup,#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #close-caps-popup{float:right;margin-left:5px;height:auto}#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #close-caps-popup{display:none}#wpadminbar #wp-admin-bar-vaa.fullPopupActive #wp-admin-bar-vaa-caps .ab-sub-wrapper.fullPopup #close-caps-popup{display:block}#wpadminbar #wp-admin-bar-vaa.fullPopupActive #wp-admin-bar-vaa-caps .ab-sub-wrapper.fullPopup #open-caps-popup{display:none}#wpadminbar #wp-admin-bar-vaa.fullPopupActive #wp-admin-bar-vaa-caps .ab-sub-wrapper.fullPopup #wp-admin-bar-vaa-caps-select-options .vaa-cap-item{width:250px;float:left;clear:none}#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps-popup:hover{cursor:pointer}#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>.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}@media screen and (max-width:782px){#wpadminbar #wp-admin-bar-vaa{display:block;position:static}#wpadminbar #wp-admin-bar-vaa>.ab-item>.ab-icon{margin-left:0}#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper{width:100%}#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper .ab-sub-wrapper{position:static;top:auto;margin:0;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}#wpadminbar #wp-admin-bar-vaa.menupop .menupop>.ab-item:before{content:''}#wpadminbar #wp-admin-bar-vaa .ab-item .vaa-hide-responsive{display:none}#wpadminbar #wp-admin-bar-vaa .vaa-notice{line-height:42px;font-size:16px}#wpadminbar #wp-admin-bar-vaa .vaa-notice .ab-icon{height:auto}#wpadminbar #wp-admin-bar-vaa>div>ul,#wpadminbar #wp-admin-bar-vaa .menupop>.ab-sub-wrapper .ab-submenu{padding:5px 0}#wpadminbar #wp-admin-bar-vaa .menupop>.ab-sub-wrapper .ab-item{padding:8px 44px;white-space:normal;height:auto}#wpadminbar #wp-admin-bar-vaa .menupop>.ab-sub-wrapper .ab-item>.ab-item{padding:8px 0}#wpadminbar #wp-admin-bar-vaa .menupop>.ab-sub-wrapper:last-child .ab-item.description{margin-bottom:0}#wpadminbar #wp-admin-bar-vaa .ab-item>span.remove,#wpadminbar #wp-admin-bar-vaa .vaa-has-icon .ab-item .ab-icon{width:auto;height:auto;font-size:22px !important;margin-right:10px;vertical-align:text-top}#wpadminbar #wp-admin-bar-vaa .ab-vaa-title.vaa-has-icon>.ab-item>.ab-icon{font-size:30px !important;margin-left:-6px;margin-top:-1px;vertical-align:top}#wpadminbar #wp-admin-bar-vaa .vaa-has-icon.menupop>.ab-item{padding-left:12px;padding-right:12px}#wpadminbar #wp-admin-bar-vaa .vaa-menupop div li{margin-left:12px}#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper .vaa-role-item.menupop>.ab-item{padding-left:15px}#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle .ab-item::after,#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper .vaa-menupop.menupop>.ab-item:after{content:"\f140";font-family:'dashicons';position:absolute;right:10px;top:8px;margin:0;font-size:30px;font-weight:normal}#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle.active .ab-item::after,#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper .vaa-menupop.menupop.active>.ab-item:after{content:"\f142"}#wpadminbar #wp-admin-bar-vaa button{font-size:16px;padding:5px 15px}#wpadminbar #wp-admin-bar-vaa .ab-vaa-input .ab-item input,#wpadminbar #wp-admin-bar-vaa .ab-vaa-search .ab-item input,#wpadminbar #wp-admin-bar-vaa .ab-vaa-filter .ab-item input{padding:8px 12px}#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item select{padding:7px 12px}#wpadminbar #wp-admin-bar-vaa .ab-item select+button.input-overlay,#wpadminbar #wp-admin-bar-vaa .ab-item input+button.input-overlay{right:44px;padding:6px 10px 7px;font-size:14px}#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect{border-width:0 44px;max-height:300px !important}#wpadminbar #wp-admin-bar-vaa .menupop>.ab-sub-wrapper .ab-vaa-multipleselect>.ab-item{padding:8px 16px}#wpadminbar #wp-admin-bar-vaa input.checkbox,#wpadminbar #wp-admin-bar-vaa input.radio{width:24px;height:24px}#wpadminbar #wp-admin-bar-vaa input.checkbox.vaa-right,#wpadminbar #wp-admin-bar-vaa input.radio.vaa-right{top:9px;right:11px}} \ No newline at end of file +.vaa-loader-icon{width:40px;height:40px;background:transparent url('../../../../../wp-includes/images/spinner-2x.gif') center center no-repeat;background-size:contain}#vaa-overlay{position:fixed;top:0;left:0;height:100%;width:100%;background:rgba(255,255,255,0.85);display:none;z-index:999999999}#vaa-overlay .vaa-loader-icon{position:fixed;top:50%;left:50%;margin:-20px 0 0 -20px;display:block}#vaa-overlay .vaa-overlay-container{max-width:75%;min-width:50%;max-height:50%;min-height:20px;margin:0 25%;top:10%;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;cursor:pointer}#vaa-overlay .vaa-overlay-container .vaa-response-data{overflow:hidden;overflow-y:auto}#vaa-overlay .vaa-overlay-container .vaa-response-data ul li{margin-left:20px;list-style:disc outside}#vaa-overlay .vaa-overlay-container.vaa-message{border:2px solid #0075b3}#vaa-overlay .vaa-overlay-container.vaa-warning{border:2px solid #c8730c}#vaa-overlay .vaa-overlay-container.vaa-error{border:2px solid #dc3232}#vaa-overlay .vaa-overlay-container.vaa-success{border:2px solid #46b450}#wpadminbar .vaa-notice{display:inline-block;padding:0 5px 0 10px;background:#fff}#wpadminbar .vaa-notice.vaa-message,#wpadminbar .vaa-notice.vaa-message .ab-icon:before{color:#0075b3 !important}#wpadminbar .vaa-notice.vaa-warning,#wpadminbar .vaa-notice.vaa-warning .ab-icon:before{color:#c8730c !important}#wpadminbar .vaa-notice.vaa-error,#wpadminbar .vaa-notice.vaa-error .ab-icon:before{color:#dc3232 !important}#wpadminbar .vaa-notice.vaa-success,#wpadminbar .vaa-notice.vaa-success .ab-icon:before{color:#46b450 !important}#wpadminbar #wp-admin-bar-vaa .vaa-notice{display:block;clear:both;margin-bottom:3px}#wpadminbar #wp-admin-bar-vaa .vaa-notice button{vertical-align:baseline;margin:0 0 0 -5px;padding:1px 10px}#wpadminbar .vaa-notice .remove,#wpadminbar #wp-admin-bar-vaa .remove{cursor:pointer;top:2px;float:right;margin-right:0;margin-left:6px}#wpadminbar #wp-admin-bar-vaa ul li,#wpadminbar #wp-admin-bar-vaa .ab-item{clear:both}#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper .ab-item>span{line-height:26px}#wpadminbar #wp-admin-bar-vaa .ab-item>span.remove{font-size:16px;line-height:16px;top:1px}#wpadminbar #wp-admin-bar-vaa .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:.5;transition:opacity .2s}#wpadminbar #wp-admin-bar-vaa .vaa-sub-transparent:hover>*{opacity:1}#wpadminbar #wp-admin-bar-vaa .ab-vaa-results{margin:6px 0;padding:0}#wpadminbar #wp-admin-bar-vaa .ab-vaa-results:empty{display:none}#wpadminbar #wp-admin-bar-vaa .ab-vaa-spacing-top,#wpadminbar #wp-admin-bar-vaa>div>ul.ab-sub-secondary+ul.ab-sub-secondary{margin-top:3px}#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper .ab-sub-wrapper ul.ab-sub-secondary+ul.ab-sub-secondary{padding-top:0}#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:.8em;font-style:italic;margin-bottom:7px;white-space:normal}#wpadminbar #wp-admin-bar-vaa .ab-item .description:first-child{margin-bottom:0}#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>.ab-item .vaa-view-data,#wpadminbar #wp-admin-bar-vaa .current>input:checked+label,#wpadminbar #wp-admin-bar-vaa .current-parent>.ab-item,#wpadminbar #wp-admin-bar-vaa .current-parent>.ab-item .vaa-view-data,#wpadminbar #wp-admin-bar-vaa .current-parent>label{font-weight:bold}#wpadminbar #wp-admin-bar-vaa .current>.ab-item::after,#wpadminbar #wp-admin-bar-vaa .current>label::after{content:'\f177';font-family:'dashicons';margin:0 5px;font-size:17px;vertical-align:middle;font-weight:normal}#wpadminbar #wp-admin-bar-vaa>.ab-item>.ab-label{float:left}#wpadminbar #wp-admin-bar-vaa>.ab-item .ab-icon{float:right;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;line-height:16px;vertical-align:text-bottom;font-weight:normal !important;padding:0}#wpadminbar #wp-admin-bar-vaa .vaa-has-icon>.ab-item::before{display:none}#wpadminbar #wp-admin-bar-vaa .vaa-has-icon.menupop>.ab-item{padding-left:10px;padding-right:10px}#wpadminbar #wp-admin-bar-vaa .vaa-has-icon.ab-vaa-title>.ab-item>.ab-icon{font-size:18px;line-height:20px;margin:0 5px 0 -1px}#wpadminbar .ab-top-secondary .menupop .vaa-menupop>.ab-item{padding-left:2em;padding-right:1em}#wpadminbar .ab-top-secondary .menupop .vaa-menupop>.ab-item .ab-icon{margin-left:-20px;margin-right:4px}#wpadminbar #wp-admin-bar-vaa.menupop ul.ab-sub-secondary{position:static}#wpadminbar #wp-admin-bar-vaa.menupop .menupop>.ab-item:before{top:1px}#wpadminbar #wp-admin-bar-vaa button>.ab-icon{margin:0 5px 0 -5px;padding:0;top:0}#wpadminbar #wp-admin-bar-vaa .ab-item>label+button{margin:0 0 0 12px;vertical-align:baseline}#wpadminbar #wp-admin-bar-vaa .vaa-button-container>.ab-item{overflow:hidden;height:auto}#wpadminbar #wp-admin-bar-vaa button{float:none;text-decoration:none;font-size:13px;line-height:20px;height:20px;margin:3px 0;padding:0 10px 1px;vertical-align:middle;cursor:pointer}#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 .vaa-auto-max-height{min-height:26px;overflow-y:auto;transition:max-height .3s}#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect .ab-item,#wpadminbar #wp-admin-bar-vaa .ab-vaa-input .ab-item,#wpadminbar #wp-admin-bar-vaa .ab-vaa-search .ab-item,#wpadminbar #wp-admin-bar-vaa .ab-vaa-filter .ab-item,#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item{height:auto;clear:both}#wpadminbar #wp-admin-bar-vaa .ab-vaa-input .ab-item input,#wpadminbar #wp-admin-bar-vaa .ab-vaa-search .ab-item input,#wpadminbar #wp-admin-bar-vaa .ab-vaa-filter .ab-item input,#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item select{display:inline-block;background:#fff;color:#555;margin:5px 0;padding:3px;border:0;line-height:normal;height:auto;width:100%;box-sizing:border-box}#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item select{padding:2px 3px}#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item label+input,#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item label+select{margin-top:0}#wpadminbar #wp-admin-bar-vaa .ab-vaa-textarea .ab-item{height:auto;line-height:normal}#wpadminbar #wp-admin-bar-vaa .ab-vaa-textarea .ab-item textarea{width:100%;padding:5px;margin-top:5px;box-sizing:border-box;line-height:normal}#wpadminbar #wp-admin-bar-vaa .ab-item select+button.input-overlay,#wpadminbar #wp-admin-bar-vaa .ab-item input+button.input-overlay{position:absolute;right:10px;margin:5px 0}#wpadminbar #wp-admin-bar-vaa input.checkbox,#wpadminbar #wp-admin-bar-vaa input.radio{display:inline-block;height:16px;width:16px;vertical-align:text-bottom;box-sizing:border-box;cursor:pointer}#wpadminbar #wp-admin-bar-vaa .ab-item input.checkbox,#wpadminbar #wp-admin-bar-vaa .ab-item input.radio{margin:0 5px 0 0}#wpadminbar #wp-admin-bar-vaa .ab-item input.checkbox+label,#wpadminbar #wp-admin-bar-vaa .ab-item input.checkbox+label *,#wpadminbar #wp-admin-bar-vaa .ab-item input.radio+label,#wpadminbar #wp-admin-bar-vaa .ab-item input.radio+label *{line-height:18px;vertical-align:text-top;display:inline}#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 6px 0 0}#wpadminbar #wp-admin-bar-vaa .ab-item input.radio{border-radius:100%}#wpadminbar #wp-admin-bar-vaa .ab-item input.radio+label+br{line-height:0}#wpadminbar #wp-admin-bar-vaa input.checkbox.vaa-right,#wpadminbar #wp-admin-bar-vaa input.radio.vaa-right{position:absolute;top:5px;right:1em;z-index:99}#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect{max-height:400px;min-width:250px;overflow:hidden;overflow-y:auto;margin:6px 0;padding:0;border:solid transparent;border-width:0 10px}#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect .ab-empty-item{height:auto;overflow:hidden;margin:0;padding:5px 10px;background-color:#fff}#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect .ab-empty-item .ab-item{color:#333}#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect.vaa-small{max-height:100px}#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect .remove:before{color:#333}#wpadminbar #wp-admin-bar-vaa .vaa-column-one-half{width:50%;display:block;float:left;clear:none}#wpadminbar #wp-admin-bar-vaa .vaa-column-one-half .ab-item{min-width:0}#wpadminbar #wp-admin-bar-vaa .vaa-column-one-half.vaa-column-first .ab-item{padding-right:1px}#wpadminbar #wp-admin-bar-vaa .vaa-column-one-half.vaa-column-last .ab-item{padding-left:1px}#wpadminbar #wp-admin-bar-vaa .vaa-clear-float{clear:both}#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle .ab-item{padding-right:34px}#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle .ab-item:hover{cursor:pointer}#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle .ab-item::after{content:"\f140";font-family:'dashicons';position:absolute;right:10px;margin:0;font-size:20px;font-weight:normal}#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle.active .ab-item::after{content:"\f142"}#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 #wp-admin-bar-vaa-caps #apply-caps-view{float:left;margin-right:5px}#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #reset-caps-view,#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #open-caps-popup,#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #close-caps-popup{float:right;margin-left:5px;height:auto}#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps #close-caps-popup{display:none}#wpadminbar #wp-admin-bar-vaa.fullPopupActive #wp-admin-bar-vaa-caps .ab-sub-wrapper.fullPopup #close-caps-popup{display:block}#wpadminbar #wp-admin-bar-vaa.fullPopupActive #wp-admin-bar-vaa-caps .ab-sub-wrapper.fullPopup #open-caps-popup{display:none}#wpadminbar #wp-admin-bar-vaa.fullPopupActive #wp-admin-bar-vaa-caps .ab-sub-wrapper.fullPopup #wp-admin-bar-vaa-caps-select-options .vaa-cap-item{width:250px;float:left;clear:none}#wpadminbar #wp-admin-bar-vaa #wp-admin-bar-vaa-caps-popup:hover{cursor:pointer}#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>.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}@media screen and (max-width:782px){#wpadminbar #wp-admin-bar-vaa{display:block;position:static}#wpadminbar #wp-admin-bar-vaa>.ab-item>.ab-icon{margin-left:0}#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper{width:100%}#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper .ab-sub-wrapper{position:static;top:auto;margin:0;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}#wpadminbar #wp-admin-bar-vaa.menupop .menupop>.ab-item:before{content:''}#wpadminbar #wp-admin-bar-vaa .ab-item .vaa-hide-responsive{display:none}#wpadminbar #wp-admin-bar-vaa .vaa-notice{line-height:42px;font-size:16px}#wpadminbar #wp-admin-bar-vaa .vaa-notice .ab-icon{height:auto}#wpadminbar #wp-admin-bar-vaa>div>ul,#wpadminbar #wp-admin-bar-vaa .menupop>.ab-sub-wrapper .ab-submenu{padding:5px 0}#wpadminbar #wp-admin-bar-vaa .menupop>.ab-sub-wrapper .ab-item{padding:8px 44px;white-space:normal;height:auto}#wpadminbar #wp-admin-bar-vaa .menupop>.ab-sub-wrapper .ab-item>.ab-item{padding:8px 0}#wpadminbar #wp-admin-bar-vaa .menupop>.ab-sub-wrapper:last-child .ab-item.description{margin-bottom:0}#wpadminbar #wp-admin-bar-vaa .ab-item>span.remove,#wpadminbar #wp-admin-bar-vaa .vaa-has-icon .ab-item .ab-icon{width:auto;height:auto;font-size:22px !important;margin-right:10px;vertical-align:text-top}#wpadminbar #wp-admin-bar-vaa .ab-vaa-title.vaa-has-icon>.ab-item>.ab-icon{font-size:30px !important;margin-left:-6px;margin-top:-1px;vertical-align:top}#wpadminbar #wp-admin-bar-vaa .vaa-has-icon.menupop>.ab-item{padding-left:12px;padding-right:12px}#wpadminbar #wp-admin-bar-vaa .vaa-menupop div li{margin-left:12px}#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper .vaa-role-item.menupop>.ab-item{padding-left:15px}#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle .ab-item::after,#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper .vaa-menupop.menupop>.ab-item:after{content:"\f140";font-family:'dashicons';position:absolute;right:10px;top:8px;margin:0;font-size:30px;font-weight:normal}#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle.active .ab-item::after,#wpadminbar #wp-admin-bar-vaa .ab-sub-wrapper .vaa-menupop.menupop.active>.ab-item:after{content:"\f142"}#wpadminbar #wp-admin-bar-vaa button{font-size:16px;padding:5px 15px}#wpadminbar #wp-admin-bar-vaa .ab-vaa-input .ab-item input,#wpadminbar #wp-admin-bar-vaa .ab-vaa-search .ab-item input,#wpadminbar #wp-admin-bar-vaa .ab-vaa-filter .ab-item input{padding:8px 12px}#wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item select{padding:7px 12px}#wpadminbar #wp-admin-bar-vaa .ab-item select+button.input-overlay,#wpadminbar #wp-admin-bar-vaa .ab-item input+button.input-overlay{right:44px;padding:6px 10px 7px;font-size:14px}#wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect{border-width:0 44px;max-height:300px !important}#wpadminbar #wp-admin-bar-vaa .menupop>.ab-sub-wrapper .ab-vaa-multipleselect>.ab-item{padding:8px 16px}#wpadminbar #wp-admin-bar-vaa input.checkbox,#wpadminbar #wp-admin-bar-vaa input.radio{width:24px;height:24px}#wpadminbar #wp-admin-bar-vaa input.checkbox.vaa-right,#wpadminbar #wp-admin-bar-vaa input.radio.vaa-right{top:9px;right:11px}} \ No newline at end of file diff --git a/assets/js/view-admin-as.js b/assets/js/view-admin-as.js index bf848b0d..c47e8c6e 100644 --- a/assets/js/view-admin-as.js +++ b/assets/js/view-admin-as.js @@ -6,7 +6,7 @@ * @author Jory Hogeveen * @package View_Admin_As * @since 0.1 - * @version 1.7.1 + * @version 1.7.2 * @preserve */ /* eslint-enable no-extra-semi */ @@ -42,7 +42,7 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { VAA_View_Admin_As.prefix = '#wpadminbar #wp-admin-bar-vaa '; VAA_View_Admin_As.root = '#wp-admin-bar-vaa'; - VAA_View_Admin_As.maxHeightListenerElements = $( VAA_View_Admin_As.prefix + '.vaa-auto-max-height' ); + VAA_View_Admin_As.maxHeightListenerElements = null; VAA_View_Admin_As._mobile = false; if ( ! VAA_View_Admin_As.hasOwnProperty( '_debug' ) ) { @@ -89,38 +89,43 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { VAA_View_Admin_As.init_caps(); VAA_View_Admin_As.init_users(); - VAA_View_Admin_As.init_settings(); VAA_View_Admin_As.init_module_role_defaults(); VAA_View_Admin_As.init_module_role_manager(); // Functionality that require the document to be fully loaded. $window.on( 'load', function() { + VAA_View_Admin_As.init_auto_js(); + + // Load autoMaxHeight elements. + VAA_View_Admin_As.maxHeightListenerElements = $( VAA_View_Admin_As.prefix + '.vaa-auto-max-height' ); + // Toggle content with title. $( VAA_View_Admin_As.prefix + '.ab-vaa-toggle' ).each( function() { - var toggleContent = $(this).parent().children().not('.ab-vaa-toggle'); - if ( ! $(this).hasClass('active') ) { - toggleContent.hide(); + var $this = $(this), + $toggle = $this.parent().children().not('.ab-vaa-toggle'); + if ( ! $this.hasClass('active') ) { + $toggle.hide(); } - $(this).on( 'click touchend', function( e ) { + $this.on( 'click touchend', function( e ) { e.preventDefault(); e.stopPropagation(); if ( true === VAA_View_Admin_As._touchmove ) { return; } if ( $(this).hasClass('active') ) { - toggleContent.slideUp('fast'); + $toggle.slideUp('fast'); $(this).removeClass('active'); } else { - toggleContent.slideDown('fast'); + $toggle.slideDown('fast'); $(this).addClass('active'); } VAA_View_Admin_As.autoMaxHeight(); } ); // @since 1.6.1 Keyboard a11y. - $(this).on( 'keyup', function( e ) { + $this.on( 'keyup', function( e ) { e.preventDefault(); /** * @see https://api.jquery.com/keyup/ @@ -131,10 +136,10 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { */ var key = parseInt( e.which, 10 ); if ( $(this).hasClass('active') && ( 13 === key || 32 === key || 38 === key ) ) { - toggleContent.slideUp('fast'); + $toggle.slideUp('fast'); $(this).removeClass('active'); } else if ( 13 === key || 32 === key || 40 === key ) { - toggleContent.slideDown('fast'); + $toggle.slideDown('fast'); $(this).addClass('active'); } VAA_View_Admin_As.autoMaxHeight(); @@ -142,30 +147,45 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { } ); // @since 1.6.3 Toggle items on hover. - $( VAA_View_Admin_As.prefix + '.ab-vaa-showhide[data-showhide]' ).each( function() { - $( $(this).attr('data-showhide') ).hide(); + $( VAA_View_Admin_As.prefix + '[vaa-showhide]' ).each( function() { + $( $(this).attr('vaa-showhide') ).hide(); $(this).on( 'mouseenter', function() { - $( $(this).attr('data-showhide') ).slideDown('fast'); + $( $(this).attr('vaa-showhide') ).slideDown('fast'); }).on( 'mouseleave', function() { - $( $(this).attr('data-showhide') ).slideUp('fast'); + $( $(this).attr('vaa-showhide') ).slideUp('fast'); } ); } ); // @since 1.7 Conditional items. - $( VAA_View_Admin_As.prefix + '.ab-vaa-conditional[data-condition-target]' ).each( function() { - var $this = $( this ), - $target = $( $this.attr( 'data-condition-target' ) ), - compare = $this.attr( 'data-condition' ), - checkbox = $target.is(':checkbox'); - $this.hide(); - $target.on( 'change', function() { + $( VAA_View_Admin_As.prefix + '[vaa-condition-target]' ).each( function() { + var $this = $(this), + $target = $( $this.attr( 'vaa-condition-target' ) ), + checkbox = ( 'checkbox' === $target.attr('type') ), + compare = $this.attr( 'vaa-condition' ); + if ( checkbox ) { + if ( 'undefined' !== typeof compare ) { + compare = Boolean( compare ); + } else { + compare = true; + } + } + function check_conditional() { if ( checkbox && $target.is(':checked') ) { - $this.slideDown('fast'); + if ( compare ) { + $this.slideDown('fast'); + } else { + $this.slideUp('fast'); + } } else if ( ! checkbox && compare === $target.val() ) { $this.slideDown('fast'); } else { $this.slideUp('fast'); } + } + $this.hide(); + check_conditional(); + $target.on( 'change', function() { + check_conditional(); VAA_View_Admin_As.autoMaxHeight(); } ); } ); @@ -217,7 +237,7 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { var view_data = {}, val = $this.attr('rel'); if ( ! val ) { - val = $this.find('.vaa-view-data').attr('data-view-value'); + val = $this.find('.vaa-view-data').attr('vaa-view-value'); } view_data[ type ] = VAA_View_Admin_As.json_decode( val ); view_data = ( 'object' === typeof view_data[ type ] ) ? view_data[ type ] : view_data; @@ -400,11 +420,7 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { } if ( ! data.hasOwnProperty( 'type' ) ) { - if ( success ) { - data.type = 'success'; - } else { - data.type = 'error'; - } + data.type = ( success ) ? 'success' : 'error'; } if ( 'popup' === display ) { @@ -469,7 +485,7 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { $( 'html, body' ).animate( { scrollTop: '0' } ); // Remove it after # seconds. if ( timeout ) { - setTimeout( function () { $( root ).slideUp( 'fast', function () { $( this ).remove(); } ); }, timeout ); + setTimeout( function () { $( root ).slideUp( 'fast', function () { $(this).remove(); } ); }, timeout ); } } else { // Notice in top level admin bar. @@ -478,7 +494,7 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { $( root + ' .remove' ).click( function() { $(this).parent().remove(); } ); // Remove it after # seconds. if ( timeout ) { - setTimeout( function () { $( root ).fadeOut( 'fast', function () { $( this ).remove(); } ); }, timeout ); + setTimeout( function () { $( root ).fadeOut( 'fast', function () { $(this).remove(); } ); }, timeout ); } } }; @@ -578,8 +594,8 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { */ var root = 'body #vaa-overlay', $overlay = $( root ), - $overlayContainer = $( root + ' .vaa-overlay-container' ), - $popupResponse = $( root + ' .vaa-response-data' ); + $overlay_container = $( root + ' .vaa-overlay-container' ), + $popup_response = $( root + ' .vaa-response-data' ); // Remove overlay. $( root + ' .vaa-overlay-container .remove' ).click( function() { @@ -595,7 +611,7 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { } ); } ); - var textarea = $( 'textarea', $popupResponse ); + var textarea = $( 'textarea', $popup_response ); if ( textarea.length ) { // Select full text on click. textarea.on( 'click', function() { $(this).select(); } ); @@ -604,13 +620,13 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { var popupMaxHeight = function() { if ( textarea.length ) { textarea.each( function() { - $( this ).css( { 'height': 'auto', 'overflow-y': 'hidden' } ).height( this.scrollHeight ); + $(this).css( { 'height': 'auto', 'overflow-y': 'hidden' } ).height( this.scrollHeight ); }); } // 80% of screen height - padding + border; - var maxHeight = ( $overlay.height() * .8 ) - 24; - $overlayContainer.css( 'max-height', maxHeight ); - $popupResponse.css( 'max-height', maxHeight ); + var max_height = ( $overlay.height() * .8 ) - 24; + $overlay_container.css( 'max-height', max_height ); + $popup_response.css( 'max-height', max_height ); }; popupMaxHeight(); $window.on( 'resize', function() { @@ -619,69 +635,251 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { }; /** - * SETTINGS. - * @since 1.5 + * Automatic option handling. + * @since 1.7.2 * @return {null} Nothing. */ - VAA_View_Admin_As.init_settings = function() { - - var root = VAA_View_Admin_As.root + '-settings', - prefix = 'vaa-settings', - root_prefix = VAA_View_Admin_As.prefix + root; + VAA_View_Admin_As.init_auto_js = function() { - // @since 1.5 Location. - $document.on( 'change', root_prefix + '-admin-menu-location select#' + prefix + '-admin-menu-location', function( e ) { - e.preventDefault(); - var val = $(this).val(); - if ( val && '' !== val ) { - var view_data = { user_setting : { admin_menu_location : val } }; - VAA_View_Admin_As.ajax( view_data, true ); + $( VAA_View_Admin_As.root + ' [vaa-auto-js]' ).each( function() { + var $this = $(this), + data = VAA_View_Admin_As.json_decode( $this.attr('vaa-auto-js') ); + if ( 'object' !== typeof data ) { + return; } + if ( ! data.hasOwnProperty('event') ) { + data.event = 'change'; + } + if ( 'click' === data.event ) { + data.event = 'click touchend'; + } + $this.on( data.event, function( e ) { + if ( 'change' !== data.event && true === VAA_View_Admin_As._touchmove ) { + return; + } + e.preventDefault(); + VAA_View_Admin_As.do_auto_js( data, this ); + return false; + } ); } ); - // @since 1.5 View mode. - $document.on( 'change', root_prefix + '-view-mode input.radio.' + prefix + '-view-mode', function( e ) { - e.preventDefault(); - var val = $(this).val(); - if ( val && '' !== val ) { - var view_data = { user_setting : { view_mode : val } }; - VAA_View_Admin_As.ajax( view_data, false ); + /** + * Get the values of the option data. + * @since 1.7.2 + * @param {object} data { + * The option data. + * @type {string} setting The setting key. + * @type {boolean} confirm Confirm before sending ajax? + * @type {boolean} refresh Refresh after sending ajax? + * @type {object} values { + * A object of multiple values as option_key => data (see below parameters). + * Can also contain another values parameter to build the option data recursive. + * @type {boolean} required Whether this option is required or not (default: true). + * @type {mixed} element The option element (overwrites the second elem parameter). + * @type {string} parser The value parser. + * @type {string} attr Get an attribute value instead of using .val()? + * OR + * @type {object} values An object of multiple values as option_key => data (see above parameters). + * } + * } + * @param {mixed} elem The element (runs through $() function). + * @return {object} Nothing. + */ + VAA_View_Admin_As.do_auto_js = function( data, elem ) { + if ( 'object' !== typeof data ) { + return null; } - } ); + var $elem = $( elem ), + setting = ( data.hasOwnProperty( 'setting' ) ) ? String( data.setting ) : null, + confirm = ( data.hasOwnProperty( 'confirm' ) ) ? Boolean( data.confirm ) : false, + refresh = ( data.hasOwnProperty( 'refresh' ) ) ? Boolean( data.refresh ) : false; + + var val = VAA_View_Admin_As.get_auto_js_values_recursive( data, elem ); + + if ( null !== val ) { + var view_data = {}; + view_data[ setting ] = val; + + if ( confirm ) { + confirm = VAA_View_Admin_As.item_confirm( $elem.parent(), VAA_View_Admin_As.__confirm ); + $( confirm ).on( 'click', function() { + VAA_View_Admin_As.ajax( view_data, refresh ); + } ); + } else { + VAA_View_Admin_As.ajax( view_data, refresh ); + } + } else { + // @todo Notifications etc. + } + }; - // @since 1.5.2 Force group users. - $document.on( 'change', root_prefix + '-force-group-users input#' + prefix + '-force-group-users', function( e ) { - e.preventDefault(); - var view_data = { user_setting : { force_group_users : "no" } }; - if ( this.checked ) { - view_data = { user_setting : { force_group_users : "yes" } }; + /** + * Get the values of the option data. + * @since 1.7.2 + * @param {object} data { + * The option data. + * @type {boolean} required Whether this option is required or not (default: true). + * @type {mixed} element The option element (overwrites the second elem parameter). + * @type {string} parser The value parser. + * @type {string} attr Get an attribute value instead of using .val()? + * OR + * @type {object} values An object of multiple values as option_key => data (see above parameters). + * } + * @param {mixed} elem The element (runs through $() function). + * @return {object} Value data. + */ + VAA_View_Admin_As.get_auto_js_values_recursive = function( data, elem ) { + if ( 'object' !== typeof data ) { + return null; } - VAA_View_Admin_As.ajax( view_data, true ); - } ); + var stop = false, + val = null; + if ( data.hasOwnProperty( 'values' ) ) { + val = {}; + $.each( data.values, function( val_key, auto_js ) { + if ( 'object' !== typeof auto_js || null === auto_js ) { + auto_js = {}; + } + auto_js.required = ( auto_js.hasOwnProperty( 'required' ) ) ? Boolean( auto_js.required ) : true; - // @since 1.6 Enable hide front. - $document.on( 'change', root_prefix + '-hide-front input#' + prefix + '-hide-front', function( e ) { - e.preventDefault(); - var view_data = { user_setting : { hide_front : "no" } }; - if ( this.checked ) { - view_data = { user_setting : { hide_front : "yes" } }; + var val_val = VAA_View_Admin_As.get_auto_js_values_recursive( auto_js, elem ); + + if ( null !== val_val ) { + val[ val_key ] = val_val; + } else if ( auto_js.required ) { + val = null; + stop = true; + return false; + } + } ); + + if ( stop ) { + return null; + } + + } else { + val = VAA_View_Admin_As.parse_auto_js_value( data, elem ); } - VAA_View_Admin_As.ajax( view_data, false ); - } ); + return val; + }; - // @since 1.6.1 Enable freeze locale. - $document.on( 'change', root_prefix + '-freeze-locale input#' + prefix + '-freeze-locale', function( e ) { - e.preventDefault(); - var view_data = { user_setting : { freeze_locale : "no" } }; - if ( this.checked ) { - view_data = { user_setting : { freeze_locale : "yes" } }; + /** + * Get the value of an option through various parsers. + * @since 1.7.2 + * @param {object} data { + * The option data. + * @type {mixed} element The option element (overwrites the second elem parameter). + * @type {string} parser The value parser. + * @type {string} attr Get an attribute value instead of using .val()? + * @type {boolean} attr Parse as JSON? + * } + * @param {mixed} elem The element (runs through $() function). + * @return {*} Value. + */ + VAA_View_Admin_As.parse_auto_js_value = function( data, elem ) { + if ( 'object' !== typeof data ) { + return null; } - var reload = false; - if ( 'object' === typeof VAA_View_Admin_As.view && 'undefined' !== typeof VAA_View_Admin_As.view.user ) { - reload = true; + var $elem = ( data.hasOwnProperty( 'element' ) ) ? $( data.element ) : $( elem ), + parser = ( data.hasOwnProperty( 'parser' ) ) ? String( data.parser ) : '', + val = null; + + switch ( parser ) { + + case 'multiple': + case 'multi': + val = {}; + $elem.each( function() { + var $this = $(this), + value; + if ( 'checkbox' === $this.attr( 'type' ) ) { + // JSON not supported and always a boolean value. + value = ( data.hasOwnProperty( 'attr' ) ) ? $this.attr( data.attr ) : $this.val(); + val[ value ] = this.checked; + } else { + value = VAA_View_Admin_As.get_auto_js_value( this, data ); + val[ $this.attr('name') ] = value; + } + } ); + break; + + case 'selected': + val = []; + $elem.each( function() { + var $this = $(this), + value; + if ( 'checkbox' === $this.attr( 'type' ) ) { + // JSON not supported. + value = ( data.hasOwnProperty( 'attr' ) ) ? $this.attr( data.attr ) : $this.val(); + if ( this.checked && value ) { + val.push( value ); + } + } else { + value = VAA_View_Admin_As.get_auto_js_value( this, data ); + if ( value ) { + val.push( value ); + } + } + } ); + break; + + default: + val = VAA_View_Admin_As.get_auto_js_value( $elem, data ); + break; + } - VAA_View_Admin_As.ajax( view_data, reload ); - } ); + + return val; + }; + + /** + * Get the value of an option through various parsers. + * @since 1.7.2 + * @param {mixed} elem Required. The element (runs through $() function). + * @param {object} data { + * The option data. + * @type {string} attr Optional. Get an attribute value instead of using .val()? + * @type {boolean} json Optional. Parse as JSON? + * } + * @return {*} Value. + */ + VAA_View_Admin_As.get_auto_js_value = function( elem, data ) { + if ( 'object' !== typeof data ) { + data = {}; + } + var $elem = $( elem ), + val = null, + attr = ( data.hasOwnProperty( 'attr' ) ) ? String( data.attr ) : false, + json = ( data.hasOwnProperty( 'json' ) ) ? Boolean( data.json ) : false, + value = ( attr ) ? $elem.attr( attr ) : $elem.val(); + + if ( 'checkbox' === $elem.attr( 'type' ) ) { + var checked = $elem.is(':checked'); + if ( attr ) { + if ( checked && value ) { + val = value; + } + } else { + val = checked; + } + } else { + if ( value ) { + val = value; + } + } + + if ( json ) { + try { + val = JSON.parse( val ); + } catch ( err ) { + val = null; + // @todo Improve error message. + VAA_View_Admin_As.popup( '
' + err + '
', 'error' ); + } + } + + return val; + } }; /** @@ -698,11 +896,11 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { // Search users. $document.on( 'keyup', root_prefix + ' .ab-vaa-search.search-users input', function() { $( VAA_View_Admin_As.prefix + ' .ab-vaa-search .ab-vaa-results' ).empty(); - if ( 1 <= $(this).val().length ) { - var inputText = $(this).val(); + var input_text = $(this).val(); + if ( 1 <= input_text.length ) { $( VAA_View_Admin_As.prefix + '.vaa-user-item' ).each( function() { var name = $( '.ab-item', this ).text(); - if ( -1 < name.toLowerCase().indexOf( inputText.toLowerCase() ) ) { + if ( -1 < name.toLowerCase().indexOf( input_text.toLowerCase() ) ) { var exists = false; $( VAA_View_Admin_As.prefix + '.ab-vaa-search .ab-vaa-results .vaa-user-item .ab-item' ).each(function() { if ( -1 < $(this).text().indexOf(name) ) { @@ -779,11 +977,7 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { $( root_prefix + '-select-options .vaa-cap-item input' ).each( function() { var val = $(this).attr('value'); if ( 'undefined' === typeof capabilities[ val ] ) { - if ( $(this).is(':checked') ) { - capabilities[ val ] = 1; - } else { - capabilities[ val ] = 0; - } + capabilities[ val ] = $(this).is(':checked'); } } ); return capabilities; @@ -792,14 +986,15 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { // Since 1.7 Set the selected capabilities. VAA_View_Admin_As.set_selected_capabilities = function( capabilities ) { $( root_prefix + '-select-options .vaa-cap-item input' ).each( function() { - if ( capabilities.hasOwnProperty( $(this).attr('value') ) ) { - if ( capabilities[ $(this).attr('value') ] ) { - $( this ).attr('checked','checked'); + var $this = $(this); + if ( capabilities.hasOwnProperty( $this.attr('value') ) ) { + if ( capabilities[ $this.attr('value') ] ) { + $this.attr( 'checked', 'checked' ); } else { - $( this ).attr( 'checked', false ); + $this.attr( 'checked', false ); } } else { - $( this ).attr( 'checked', false ); + $this.attr( 'checked', false ); } } ); }; @@ -807,13 +1002,13 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { // Enlarge caps. $document.on( 'click', root_prefix + ' #open-caps-popup', function() { $( VAA_View_Admin_As.prefix ).addClass('fullPopupActive'); - $( root_prefix + '-manager > .ab-sub-wrapper').addClass('fullPopup'); + $( root_prefix + '-manager > .ab-sub-wrapper' ).addClass('fullPopup'); VAA_View_Admin_As.autoMaxHeight(); } ); // Undo enlarge caps. $document.on( 'click', root_prefix + ' #close-caps-popup', function() { $( VAA_View_Admin_As.prefix ).removeClass('fullPopupActive'); - $( root_prefix + '-manager > .ab-sub-wrapper').removeClass('fullPopup'); + $( root_prefix + '-manager > .ab-sub-wrapper' ).removeClass('fullPopup'); VAA_View_Admin_As.autoMaxHeight(); } ); @@ -872,8 +1067,8 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { return; } e.preventDefault(); - var newCaps = VAA_View_Admin_As.get_selected_capabilities(); - VAA_View_Admin_As.ajax( { caps : newCaps }, true ); + var new_caps = VAA_View_Admin_As.get_selected_capabilities(); + VAA_View_Admin_As.ajax( { caps : new_caps }, true ); return false; } ); }; @@ -885,54 +1080,10 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { */ VAA_View_Admin_As.init_module_role_defaults = function() { - var root = VAA_View_Admin_As.root + '-modules', - prefix = 'vaa-modules', + var root = VAA_View_Admin_As.root + '-role-defaults', + prefix = 'vaa-role-defaults', root_prefix = VAA_View_Admin_As.prefix + root; - // Enable module. - $document.on( 'change', root_prefix + '-role-defaults-enable input#' + prefix + '-role-defaults-enable', function( e ) { - e.preventDefault(); - var view_data = { role_defaults : { enable : 0 } }; - if ( this.checked ) { - view_data = { role_defaults : { enable : true } }; - } - VAA_View_Admin_As.ajax( view_data, true ); - } ); - - root = VAA_View_Admin_As.root + '-role-defaults'; - prefix = 'vaa-role-defaults'; - root_prefix = VAA_View_Admin_As.prefix + root; - - // @since 1.4 Enable apply defaults on register. - $document.on( 'change', root_prefix + '-setting-register-enable input#' + prefix + '-setting-register-enable', function( e ) { - e.preventDefault(); - var view_data = { role_defaults : { apply_defaults_on_register : 0 } }; - if ( this.checked ) { - view_data = { role_defaults : { apply_defaults_on_register : true } }; - } - VAA_View_Admin_As.ajax( view_data, false ); - } ); - - // @since 1.5.3 Disable screen settings for users who can't access this plugin. - $document.on( 'change', root_prefix + '-setting-disable-user-screen-options input#' + prefix + '-setting-disable-user-screen-options', function( e ) { - e.preventDefault(); - var view_data = { role_defaults : { disable_user_screen_options : 0 } }; - if ( this.checked ) { - view_data = { role_defaults : { disable_user_screen_options : true } }; - } - VAA_View_Admin_As.ajax( view_data, false ); - } ); - - // @since 1.6 Lock meta box order and locations for users who can't access this plugin. - $document.on( 'change', root_prefix + '-setting-lock-meta-boxes input#' + prefix + '-setting-lock-meta-boxes', function( e ) { - e.preventDefault(); - var view_data = { role_defaults : { lock_meta_boxes : 0 } }; - if ( this.checked ) { - view_data = { role_defaults : { lock_meta_boxes : true } }; - } - VAA_View_Admin_As.ajax( view_data, false ); - } ); - // @since 1.6.3 Add new meta. $document.on( 'click touchend', root_prefix + '-meta-add button#' + prefix + '-meta-add', function( e ) { if ( true === VAA_View_Admin_As._touchmove ) { @@ -950,31 +1101,14 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { } } ); - // @since 1.6.3 Update meta. - $document.on( 'click touchend', root_prefix + '-meta-apply button#' + prefix + '-meta-apply', function( e ) { - if ( true === VAA_View_Admin_As._touchmove ) { - return; - } - e.preventDefault(); - var val = {}; - $( root_prefix + '-meta-select .ab-item.vaa-item input' ).each( function() { - val[ $(this).val() ] = ( $(this).is(':checked') ); - } ); - if ( val ) { - var view_data = { role_defaults : { update_meta : val } }; - VAA_View_Admin_As.ajax( view_data, false ); - } - return false; - } ); - // @since 1.4 Filter users. $document.on( 'keyup', root_prefix + '-bulk-users-filter input#' + prefix + '-bulk-users-filter', function( e ) { e.preventDefault(); if ( 1 <= $(this).val().length ) { - var inputText = $(this).val(); + var input_text = $(this).val(); $( root_prefix + '-bulk-users-select .ab-item.vaa-item' ).each( function() { var name = $('.user-name', this).text(); - if ( -1 < name.toLowerCase().indexOf( inputText.toLowerCase() ) ) { + if ( -1 < name.toLowerCase().indexOf( input_text.toLowerCase() ) ) { $(this).show(); } else { $(this).hide(); @@ -986,119 +1120,6 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { } ); } } ); - - // @since 1.4 Apply defaults to users. - $document.on( 'click touchend', root_prefix + '-bulk-users-apply button#' + prefix + '-bulk-users-apply', function( e ) { - if ( true === VAA_View_Admin_As._touchmove ) { - return; - } - e.preventDefault(); - var val = []; - $( root_prefix + '-bulk-users-select .ab-item.vaa-item input' ).each( function() { - if ( $(this).is(':checked') ) { - val.push( $(this).val() ); - } - } ); - if ( val ) { - var view_data = { role_defaults : { apply_defaults_to_users : val } }; - VAA_View_Admin_As.ajax( view_data, false ); - } - return false; - } ); - - // @since 1.4 Apply defaults to users by role. - $document.on( 'click touchend', root_prefix + '-bulk-roles-apply button#' + prefix + '-bulk-roles-apply', function( e ) { - if ( true === VAA_View_Admin_As._touchmove ) { - return; - } - e.preventDefault(); - var val = $( root_prefix + '-bulk-roles-select select#' + prefix + '-bulk-roles-select' ).val(); - if ( val && '' !== val ) { - var view_data = { role_defaults : { apply_defaults_to_users_by_role : val } }; - VAA_View_Admin_As.ajax( view_data, false ); - } - return false; - } ); - - // @since 1.7 Copy role defaults. - $document.on( 'click touchend', root_prefix + '-copy-roles-copy button.vaa-copy-role-defaults', function( e ) { - if ( true === VAA_View_Admin_As._touchmove ) { - return; - } - e.preventDefault(); - var val = []; - $( root_prefix + '-copy-roles-to .ab-item.vaa-item input' ).each( function() { - if ( $(this).is(':checked') ) { - val.push( $(this).val() ); - } - } ); - var data = { - from: $( root_prefix + '-copy-roles-from select#' + prefix + '-copy-roles-from' ).val(), - to: val - }; - if ( data.from && data.to.length ) { - var view_data = { role_defaults : { copy_role_defaults : data } }; - if ( $(this).attr('data-method') ) { - view_data.role_defaults.copy_role_defaults_method = String( $(this).attr('data-method') ); - } - VAA_View_Admin_As.ajax( view_data, false ); - } - return false; - } ); - - // @since 1.5 Export role defaults. - $document.on( 'click touchend', root_prefix + '-export-roles-export button#' + prefix + '-export-roles-export', function( e ) { - if ( true === VAA_View_Admin_As._touchmove ) { - return; - } - e.preventDefault(); - var val = $( root_prefix + '-export-roles-select select#' + prefix + '-export-roles-select' ).val(); - if ( val && '' !== val ) { - var view_data = { role_defaults : { export_role_defaults : val } }; - VAA_View_Admin_As.ajax( view_data, false ); - } - return false; - } ); - - // @since 1.5 Import role defaults. - $document.on( 'click touchend', root_prefix + '-import-roles-import button.vaa-import-role-defaults', function( e ) { - if ( true === VAA_View_Admin_As._touchmove ) { - return; - } - e.preventDefault(); - var val = $( root_prefix + '-import-roles-input textarea#' + prefix + '-import-roles-input' ).val(); - if ( val && '' !== val ) { - try { - val = JSON.parse( val ); - var view_data = { role_defaults : { import_role_defaults : val } }; - if ( $(this).attr('data-method') ) { - view_data.role_defaults.import_role_defaults_method = String( $(this).attr('data-method') ); - } - VAA_View_Admin_As.ajax( view_data, false ); - } catch ( err ) { - // @todo Improve error message. - VAA_View_Admin_As.popup( '
' + err + '
', 'error' ); - } - } - return false; - } ); - - // @since 1.4 Clear role defaults. - $document.on( 'click touchend', root_prefix + '-clear-roles-apply button#' + prefix + '-clear-roles-apply', function( e ) { - if ( true === VAA_View_Admin_As._touchmove ) { - return; - } - e.preventDefault(); - var val = $( root_prefix + '-clear-roles-select select#' + prefix + '-clear-roles-select' ).val(); - if ( val && '' !== val ) { - var view_data = { role_defaults : { clear_role_defaults : val } }, - confirm = VAA_View_Admin_As.item_confirm( $(this).parent(), VAA_View_Admin_As.__confirm ); - $( confirm ).on( 'click', function() { - VAA_View_Admin_As.ajax( view_data, false ); - } ); - } - return false; - } ); }; /** @@ -1108,101 +1129,21 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { */ VAA_View_Admin_As.init_module_role_manager = function() { - var root = VAA_View_Admin_As.root + '-modules', - prefix = 'vaa-modules', - root_prefix = VAA_View_Admin_As.prefix + root; - - // Enable module. - $document.on( 'change', root_prefix + '-role-manager-enable input#' + prefix + '-role-manager-enable', function( e ) { - e.preventDefault(); - var view_data = { role_manager : { enable : 0 } }; - if ( this.checked ) { - view_data = { role_manager : { enable : true } }; - } - VAA_View_Admin_As.ajax( view_data, true ); - } ); - - root = VAA_View_Admin_As.root + '-role-manager'; - prefix = 'vaa-role-manager'; - root_prefix = VAA_View_Admin_As.prefix + root; - - // @since 1.7 Apply current view capabilities to role. - $document.on( 'click touchend', root_prefix + '-apply-view-apply button#' + prefix + '-apply-view-apply', function( e ) { - if ( true === VAA_View_Admin_As._touchmove ) { - return; - } - e.preventDefault(); - var role = $( root_prefix + '-apply-view-select select#' + prefix + '-apply-view-select' ).val(); - var capabilities = JSON.parse( $(this).attr('data-view-caps') ); - if ( role && '' !== role && capabilities ) { - var view_data = { role_manager : { apply_view_to_role : { role: role, capabilities: capabilities } } }; - VAA_View_Admin_As.ajax( view_data, true ); - } - return false; - } ); - - // @since 1.7.1 Rename role. - $document.on( 'click touchend', root_prefix + '-rename-apply button#' + prefix + '-rename-apply', function( e ) { - if ( true === VAA_View_Admin_As._touchmove ) { - return; - } - e.preventDefault(); - var role = $( root_prefix + '-rename-select select#' + prefix + '-rename-select' ).val(); - var new_name = $( root_prefix + '-rename-input input#' + prefix + '-rename-input' ).val(); - if ( role && '' !== role && new_name && '' !== new_name ) { - var view_data = { role_manager : { rename_role : { role : role, new_name : new_name } } }; - VAA_View_Admin_As.ajax( view_data, true ); - } - return false; - } ); - - // @since 1.7 Clone role. - $document.on( 'click touchend', root_prefix + '-clone-apply button#' + prefix + '-clone-apply', function( e ) { - if ( true === VAA_View_Admin_As._touchmove ) { - return; - } - e.preventDefault(); - var role = $( root_prefix + '-clone-select select#' + prefix + '-clone-select' ).val(); - var new_role = $( root_prefix + '-clone-input input#' + prefix + '-clone-input' ).val(); - if ( role && '' !== role && new_role && '' !== new_role ) { - var view_data = { role_manager : { clone_role : { role : role, new_role : new_role } } }; - VAA_View_Admin_As.ajax( view_data, true ); - } - return false; - } ); - - // @since 1.7 Delete role. - $document.on( 'click touchend', root_prefix + '-delete-apply button#' + prefix + '-delete-apply', function( e ) { - if ( true === VAA_View_Admin_As._touchmove ) { - return; - } - e.preventDefault(); - var val = $( root_prefix + '-delete-select select#' + prefix + '-delete-select' ).val(); - if ( val && '' !== val ) { - var view_data = { role_manager : { delete_role : val } }, - confirm = VAA_View_Admin_As.item_confirm( $(this).parent(), VAA_View_Admin_As.__confirm ); - $( confirm ).on( 'click', function() { - VAA_View_Admin_As.ajax( view_data, true ); - } ); - } - return false; - } ); - /** * Capability functions. */ - var caps_root = VAA_View_Admin_As.root + '-caps-manager-role-manager', - caps_prefix = 'vaa-caps-manager-role-manager', - caps_root_prefix = VAA_View_Admin_As.prefix + caps_root; + var root = VAA_View_Admin_As.root + '-caps-manager-role-manager', + prefix = 'vaa-caps-manager-role-manager', + root_prefix = VAA_View_Admin_As.prefix + root; // @since 1.7 Update capabilities when selecting a role. - $document.on( 'change', caps_root_prefix + ' select#' + caps_prefix + '-edit-role', function() { + $document.on( 'change', root_prefix + ' select#' + prefix + '-edit-role', function() { var $this = $(this), role = $this.val(), caps = {}, - selectedRoleElement = $( caps_root_prefix + ' select#' + caps_prefix + '-edit-role option[value="' + role + '"]' ); - if ( selectedRoleElement.attr('data-caps') ) { - caps = JSON.parse( selectedRoleElement.attr('data-caps') ); + $selected_role = $( root_prefix + ' select#' + prefix + '-edit-role option[value="' + role + '"]' ); + if ( $selected_role.attr('data-caps') ) { + caps = JSON.parse( $selected_role.attr('data-caps') ); } // Reset role filters. @@ -1215,18 +1156,18 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { } ); // @since 1.7 Add/Modify roles. - $document.on( 'click touchend', caps_root_prefix + ' button#' + caps_prefix + '-save-role', function( e ) { + $document.on( 'click touchend', root_prefix + ' button#' + prefix + '-save-role', function( e ) { if ( true === VAA_View_Admin_As._touchmove ) { return; } e.preventDefault(); - var role = $( caps_root_prefix + ' select#' + caps_prefix + '-edit-role' ).val(), + var role = $( root_prefix + ' select#' + prefix + '-edit-role' ).val(), refresh = false; if ( ! role ) { return false; } if ( '__new__' === role ) { - role = $( caps_root_prefix + ' input#' + caps_prefix + '-new-role' ).val(); + role = $( root_prefix + ' input#' + prefix + '-new-role' ).val(); refresh = true; } var data = { @@ -1238,14 +1179,14 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { } ); // @since 1.7 Add new capabilities. - $document.on( 'click touchend', caps_root_prefix + '-new-cap button#' + caps_prefix + '-add-cap', function( e ) { + $document.on( 'click touchend', root_prefix + '-new-cap button#' + prefix + '-add-cap', function( e ) { if ( true === VAA_View_Admin_As._touchmove ) { return; } e.preventDefault(); var existing = VAA_View_Admin_As.get_selected_capabilities(); - var val = $( caps_root_prefix + '-new-cap input#' + caps_prefix + '-new-cap' ).val(); - var item = $( caps_root_prefix + '-new-cap #' + caps_prefix + '-cap-template' ).html().toString(); + var val = $( root_prefix + '-new-cap input#' + prefix + '-new-cap' ).val(); + var item = $( root_prefix + '-new-cap #' + prefix + '-cap-template' ).html().toString(); val = val.replace( / /g, '_' ); item = item.replace( /vaa_new_item/g, val ); if ( 'undefined' !== typeof existing[ val ] ) { @@ -1262,21 +1203,24 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { * @return {null} Nothing. */ VAA_View_Admin_As.autoMaxHeight = function() { + if ( ! VAA_View_Admin_As.maxHeightListenerElements ) { + return null; + } setTimeout( function() { // @link http://stackoverflow.com/questions/11193453/find-the-vertical-position-of-scrollbar-without-jquery - var scrollTop = ( 'undefined' !== typeof window.pageYOffset ) ? window.pageYOffset : ( document.documentElement || document.body.parentNode || document.body ).scrollTop; + var scroll_top = ( 'undefined' !== typeof window.pageYOffset ) ? window.pageYOffset : ( document.documentElement || document.body.parentNode || document.body ).scrollTop; VAA_View_Admin_As.maxHeightListenerElements.each( function() { var $element = $(this), count = 0, wait = setInterval( function() { - var offset = $element.offset(), - offsetTop = ( offset.top - scrollTop ); - if ( $element.is(':visible') && 0 < offsetTop ) { + var offset = $element.offset(), + offset_top = ( offset.top - scroll_top ); + if ( $element.is(':visible') && 0 < offset_top ) { clearInterval( wait ); - var maxHeight = $window.height() - offsetTop - 100; - maxHeight = ( 100 < maxHeight ) ? maxHeight : 100; - $element.css( { 'max-height': maxHeight + 'px' } ); + var max_height = $window.height() - offset_top - 100; + max_height = ( 100 < max_height ) ? max_height : 100; + $element.css( { 'max-height': max_height + 'px' } ); } count++; if ( 5 < count ) { diff --git a/assets/js/view-admin-as.min.js b/assets/js/view-admin-as.min.js index 1d7fba23..d9eea903 100644 --- a/assets/js/view-admin-as.min.js +++ b/assets/js/view-admin-as.min.js @@ -5,7 +5,7 @@ * @author Jory Hogeveen * @package View_Admin_As * @since 0.1 - * @version 1.7.1 + * @version 1.7.2 * @preserve */ -if("undefined"===typeof VAA_View_Admin_As){var VAA_View_Admin_As={}}(function($){var $document=$(document),$window=$(window),$body=$("body");VAA_View_Admin_As.prefix="#wpadminbar #wp-admin-bar-vaa ";VAA_View_Admin_As.root="#wp-admin-bar-vaa";VAA_View_Admin_As.maxHeightListenerElements=$(VAA_View_Admin_As.prefix+".vaa-auto-max-height");VAA_View_Admin_As._mobile=false;if(!VAA_View_Admin_As.hasOwnProperty("_debug")){VAA_View_Admin_As._debug=false}VAA_View_Admin_As._debug=Boolean(parseInt(VAA_View_Admin_As._debug,10));if(!VAA_View_Admin_As.hasOwnProperty("ajaxurl")&&"undefined"!==typeof ajaxurl){VAA_View_Admin_As.ajaxurl=ajaxurl}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});VAA_View_Admin_As.json_decode=function(val){if(0===val.indexOf("{")){try{val=JSON.parse(val)}catch(err){}}return val};VAA_View_Admin_As.init=function(){VAA_View_Admin_As.init_caps();VAA_View_Admin_As.init_users();VAA_View_Admin_As.init_settings();VAA_View_Admin_As.init_module_role_defaults();VAA_View_Admin_As.init_module_role_manager();$window.on("load",function(){$(VAA_View_Admin_As.prefix+".ab-vaa-toggle").each(function(){var toggleContent=$(this).parent().children().not(".ab-vaa-toggle");if(!$(this).hasClass("active")){toggleContent.hide()}$(this).on("click touchend",function(e){e.preventDefault();e.stopPropagation();if(true===VAA_View_Admin_As._touchmove){return}if($(this).hasClass("active")){toggleContent.slideUp("fast");$(this).removeClass("active")}else{toggleContent.slideDown("fast");$(this).addClass("active")}VAA_View_Admin_As.autoMaxHeight()});$(this).on("keyup",function(e){e.preventDefault();var key=parseInt(e.which,10);if($(this).hasClass("active")&&(13===key||32===key||38===key)){toggleContent.slideUp("fast");$(this).removeClass("active")}else if(13===key||32===key||40===key){toggleContent.slideDown("fast");$(this).addClass("active")}VAA_View_Admin_As.autoMaxHeight()})});$(VAA_View_Admin_As.prefix+".ab-vaa-showhide[data-showhide]").each(function(){$($(this).attr("data-showhide")).hide();$(this).on("mouseenter",function(){$($(this).attr("data-showhide")).slideDown("fast")}).on("mouseleave",function(){$($(this).attr("data-showhide")).slideUp("fast")})});$(VAA_View_Admin_As.prefix+".ab-vaa-conditional[data-condition-target]").each(function(){var $this=$(this),$target=$($this.attr("data-condition-target")),compare=$this.attr("data-condition"),checkbox=$target.is(":checkbox");$this.hide();$target.on("change",function(){if(checkbox&&$target.is(":checked")){$this.slideDown("fast")}else if(!checkbox&&compare===$target.val()){$this.slideDown("fast")}else{$this.slideUp("fast")}VAA_View_Admin_As.autoMaxHeight()})});if($body.hasClass("mobile")||783>$body.innerWidth()){$body.addClass("vaa-mobile");VAA_View_Admin_As._mobile=true;VAA_View_Admin_As.mobile()}VAA_View_Admin_As.maxHeightListenerElements.each(function(){$(this).parents(".menupop").on("mouseenter",function(){VAA_View_Admin_As.autoMaxHeight()})})});$document.on("click touchend",VAA_View_Admin_As.prefix+".vaa-reset-item > .ab-item",function(e){e.preventDefault();if(true===VAA_View_Admin_As._touchmove){return}if("vaa_reload"===$("button",this).attr("name")){window.location.reload()}else{VAA_View_Admin_As.ajax({reset:true},true);return false}});$.each(VAA_View_Admin_As.view_types,function(index,type){$document.on("click touchend",VAA_View_Admin_As.prefix+".vaa-"+type+"-item > a.ab-item",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();var $this=$(this);if(VAA_View_Admin_As._mobile&&$this.parent().hasClass("menupop")&&!$this.next().is(":visible")){$this.next().show().parent().addClass("active");return}if(!$this.parent().hasClass("not-a-view")){var view_data={},val=$this.attr("rel");if(!val){val=$this.find(".vaa-view-data").attr("data-view-value")}view_data[type]=VAA_View_Admin_As.json_decode(val);view_data="object"===typeof view_data[type]?view_data[type]:view_data;VAA_View_Admin_As.ajax(view_data,true);return false}})});$document.on("click touchend",VAA_View_Admin_As.prefix+".remove",function(e){e.preventDefault();if(true===VAA_View_Admin_As._touchmove){return}$(this).parent().slideUp("fast",function(){$(this).remove()})})};VAA_View_Admin_As.mobile=function(){var prefix=".vaa-mobile "+VAA_View_Admin_As.prefix;$document.on("click touchend",prefix+" > .ab-sub-wrapper .ab-item",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();e.stopPropagation();var $sub=$(this).parent(".menupop").children(".ab-sub-wrapper");if($sub.length){if($sub.hasClass("active")){$sub.slideUp("fast");$sub.removeClass("active")}else{$sub.slideDown("fast");$sub.addClass("active")}}});$document.on("click touchend",prefix+"input, "+prefix+"textarea, "+prefix+"select",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.stopPropagation();var $this=$(this);if($this.is('[type="checkbox"]')){e.preventDefault();if($this.is(":checked")){$this.prop("checked",false)}else{$this.prop("checked",true)}$this.trigger("change");return false}else if($this.is('[type="radio"]')){e.preventDefault();$('input[name="'+$this.attr["name"]+'"]').removeAttr("checked");$this.prop("checked",true);$this.trigger("change");return false}return true});$document.on("click touchend",prefix+"label",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();e.stopPropagation();$("#"+$(this).attr("for")).trigger(e.type);return false})};VAA_View_Admin_As.overlay=function(html){var $overlay=$("#vaa-overlay");if(!$overlay.length){html='
'+html+"
";$body.append(html);$overlay=$("body #vaa-overlay")}else if(html.length){$overlay.html(html)}$overlay.fadeIn("fast")};VAA_View_Admin_As.ajax=function(data,refresh){$(".vaa-notice","#wpadminbar").remove();var loader_icon=VAA_View_Admin_As.siteurl+"/wp-includes/images/spinner-2x.gif";VAA_View_Admin_As.overlay('');var post_data={action:"view_admin_as",_vaa_nonce:VAA_View_Admin_As._vaa_nonce,view_admin_as:JSON.stringify(data)};var isView=false;$.each(VAA_View_Admin_As.view_types,function(index,type){if("undefined"!==typeof data[type]){isView=true;return true}});if($(VAA_View_Admin_As.prefix+"#vaa-settings-view-mode-single").is(":checked")&&isView){$body.append('');var form=$("#vaa_single_mode_form");form.append('');form.append('');form.append('');form.find("#data").val(post_data.view_admin_as);form.submit()}else{$.post(VAA_View_Admin_As.ajaxurl,post_data,function(response){var success=response.hasOwnProperty("success")&&true===response.success,data={},display=false;if(true===VAA_View_Admin_As._debug){console.log(response)}if(response.hasOwnProperty("data")){if("object"===typeof response.data){data=response.data;if(data.hasOwnProperty("display")){display=data.display}}}if(success){if(refresh){VAA_View_Admin_As.refresh(data);return}else{if(!data.hasOwnProperty("text")){data.text=VAA_View_Admin_As.__success}}}if(!data.hasOwnProperty("type")){if(success){data.type="success"}else{data.type="error"}}if("popup"===display){VAA_View_Admin_As.popup(data,data.type)}else{if(!data.hasOwnProperty("text")){data.text=response.data}VAA_View_Admin_As.notice(String(data.text),data.type,5e3);$("body #vaa-overlay").addClass(data.type).fadeOut("fast",function(){$(this).remove()})}})}};VAA_View_Admin_As.refresh=function(data){if(data.hasOwnProperty("redirect")){window.location.replace(String(data.redirect))}else{window.location.hash="";window.location.reload()}};VAA_View_Admin_As.notice=function(notice,type,timeout){var root="#wpadminbar .vaa-notice",html=notice+'';type="undefined"===typeof type?"notice":type;timeout="undefined"===typeof timeout?5e3:timeout;if(VAA_View_Admin_As._mobile){html='";$(VAA_View_Admin_As.prefix+"> .ab-sub-wrapper").prepend(html).children(".vaa-notice").slideDown("fast");$("html, body").animate({scrollTop:"0"});if(timeout){setTimeout(function(){$(root).slideUp("fast",function(){$(this).remove()})},timeout)}}else{html='
  • '+html+"
  • ";$("#wp-admin-bar-top-secondary").append(html);$(root+" .remove").click(function(){$(this).parent().remove()});if(timeout){setTimeout(function(){$(root).fadeOut("fast",function(){$(this).remove()})},timeout)}}};VAA_View_Admin_As.item_notice=function(parent,notice,type,timeout){var root=".vaa-notice",html=notice+'',$element=$(parent);type="undefined"===typeof type?"notice":type;timeout="undefined"===typeof timeout?5e3:timeout;html='";$element.append(html).children(".vaa-notice").slideDown("fast");if(timeout){setTimeout(function(){$(root,$element).slideUp("fast",function(){$(this).remove()})},timeout)}};VAA_View_Admin_As.item_confirm=function(parent,text){$(parent).find(".vaa-notice").slideUp("fast",function(){$(this).remove()});text='";VAA_View_Admin_As.item_notice(parent,text,"warning",0);return $(parent).find(".vaa-confirm")};VAA_View_Admin_As.popup=function(data,type){type="undefined"===typeof type?"notice":type;var html="";html+='
    ';html+='';html+='
    ';if("object"!==typeof data){data={text:data}}if(data.hasOwnProperty("text")){html+="

    "+String(data.text)+"

    "}if(data.hasOwnProperty("list")){html+="
      ";data.list.forEach(function(item){html+="
    • "+String(item)+"
    • "});html+="
    "}if(data.hasOwnProperty("textarea")){html+='"}html+="
    ";VAA_View_Admin_As.overlay(html);var root="body #vaa-overlay",$overlay=$(root),$overlayContainer=$(root+" .vaa-overlay-container"),$popupResponse=$(root+" .vaa-response-data");$(root+" .vaa-overlay-container .remove").click(function(){$overlay.fadeOut("fast",function(){$(this).remove()})});$document.on("mouseup",function(e){$(root+" .vaa-overlay-container").each(function(){if(!$(this).is(e.target)&&0===$(this).has(e.target).length){$overlay.fadeOut("fast",function(){$(this).remove()})}})});var textarea=$("textarea",$popupResponse);if(textarea.length){textarea.on("click",function(){$(this).select()})}var popupMaxHeight=function(){if(textarea.length){textarea.each(function(){$(this).css({height:"auto","overflow-y":"hidden"}).height(this.scrollHeight)})}var maxHeight=$overlay.height()*.8-24;$overlayContainer.css("max-height",maxHeight);$popupResponse.css("max-height",maxHeight)};popupMaxHeight();$window.on("resize",function(){popupMaxHeight()})};VAA_View_Admin_As.init_settings=function(){var root=VAA_View_Admin_As.root+"-settings",prefix="vaa-settings",root_prefix=VAA_View_Admin_As.prefix+root;$document.on("change",root_prefix+"-admin-menu-location select#"+prefix+"-admin-menu-location",function(e){e.preventDefault();var val=$(this).val();if(val&&""!==val){var view_data={user_setting:{admin_menu_location:val}};VAA_View_Admin_As.ajax(view_data,true)}});$document.on("change",root_prefix+"-view-mode input.radio."+prefix+"-view-mode",function(e){e.preventDefault();var val=$(this).val();if(val&&""!==val){var view_data={user_setting:{view_mode:val}};VAA_View_Admin_As.ajax(view_data,false)}});$document.on("change",root_prefix+"-force-group-users input#"+prefix+"-force-group-users",function(e){e.preventDefault();var view_data={user_setting:{force_group_users:"no"}};if(this.checked){view_data={user_setting:{force_group_users:"yes"}}}VAA_View_Admin_As.ajax(view_data,true)});$document.on("change",root_prefix+"-hide-front input#"+prefix+"-hide-front",function(e){e.preventDefault();var view_data={user_setting:{hide_front:"no"}};if(this.checked){view_data={user_setting:{hide_front:"yes"}}}VAA_View_Admin_As.ajax(view_data,false)});$document.on("change",root_prefix+"-freeze-locale input#"+prefix+"-freeze-locale",function(e){e.preventDefault();var view_data={user_setting:{freeze_locale:"no"}};if(this.checked){view_data={user_setting:{freeze_locale:"yes"}}}var reload=false;if("object"===typeof VAA_View_Admin_As.view&&"undefined"!==typeof VAA_View_Admin_As.view.user){reload=true}VAA_View_Admin_As.ajax(view_data,reload)})};VAA_View_Admin_As.init_users=function(){var root=VAA_View_Admin_As.root+"-users",root_prefix=VAA_View_Admin_As.prefix+root;$document.on("keyup",root_prefix+" .ab-vaa-search.search-users input",function(){$(VAA_View_Admin_As.prefix+" .ab-vaa-search .ab-vaa-results").empty();if(1<=$(this).val().length){var inputText=$(this).val();$(VAA_View_Admin_As.prefix+".vaa-user-item").each(function(){var name=$(".ab-item",this).text();if(-1('+role+")")}}});if(""===$.trim($(VAA_View_Admin_As.prefix+".ab-vaa-search .ab-vaa-results").html())){$(VAA_View_Admin_As.prefix+".ab-vaa-search .ab-vaa-results").append('
    '+VAA_View_Admin_As.__no_users_found+"
    ")}}})};VAA_View_Admin_As.init_caps=function(){var root=VAA_View_Admin_As.root+"-caps",root_prefix=VAA_View_Admin_As.prefix+root;VAA_View_Admin_As.caps_filter_settings={selectedRole:"default",selectedRoleCaps:{},selectedRoleReverse:false,filterString:""};VAA_View_Admin_As.filter_capabilities=function(){var reverse=true===VAA_View_Admin_As.caps_filter_settings.selectedRoleReverse,isDefault="default"===VAA_View_Admin_As.caps_filter_settings.selectedRole,filterString=VAA_View_Admin_As.caps_filter_settings.filterString;$(root_prefix+"-select-options .vaa-cap-item").each(function(){var $this=$(this),exists=$("input",this).attr("value")in VAA_View_Admin_As.caps_filter_settings.selectedRoleCaps,name;$this.hide();if(reverse||exists||isDefault){if(1<=filterString.length){name=$this.text();if(-1 .ab-sub-wrapper").addClass("fullPopup");VAA_View_Admin_As.autoMaxHeight()});$document.on("click",root_prefix+" #close-caps-popup",function(){$(VAA_View_Admin_As.prefix).removeClass("fullPopupActive");$(root_prefix+"-manager > .ab-sub-wrapper").removeClass("fullPopup");VAA_View_Admin_As.autoMaxHeight()});$document.on("change",root_prefix+" .ab-vaa-select.select-role-caps select",function(){VAA_View_Admin_As.caps_filter_settings.selectedRole=$(this).val();if("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=false}else{var selectedRoleElement=$(root_prefix+'-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"));VAA_View_Admin_As.caps_filter_settings.selectedRoleReverse=1===parseInt(selectedRoleElement.attr("data-reverse"),10)}VAA_View_Admin_As.filter_capabilities()});$document.on("keyup",root_prefix+" .ab-vaa-filter input",function(){VAA_View_Admin_As.caps_filter_settings.filterString=$(this).val();VAA_View_Admin_As.filter_capabilities()});$document.on("click touchend",root_prefix+" button#select-all-caps",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();$(root_prefix+"-select-options .vaa-cap-item").each(function(){if($(this).is(":visible")){$("input",this).prop("checked",true)}});return false});$document.on("click touchend",root_prefix+" button#deselect-all-caps",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();$(root_prefix+"-select-options .vaa-cap-item").each(function(){if($(this).is(":visible")){$("input",this).prop("checked",false)}});return false});$document.on("click touchend",root_prefix+" button#apply-caps-view",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();var newCaps=VAA_View_Admin_As.get_selected_capabilities();VAA_View_Admin_As.ajax({caps:newCaps},true);return false})};VAA_View_Admin_As.init_module_role_defaults=function(){var root=VAA_View_Admin_As.root+"-modules",prefix="vaa-modules",root_prefix=VAA_View_Admin_As.prefix+root;$document.on("change",root_prefix+"-role-defaults-enable input#"+prefix+"-role-defaults-enable",function(e){e.preventDefault();var view_data={role_defaults:{enable:0}};if(this.checked){view_data={role_defaults:{enable:true}}}VAA_View_Admin_As.ajax(view_data,true)});root=VAA_View_Admin_As.root+"-role-defaults";prefix="vaa-role-defaults";root_prefix=VAA_View_Admin_As.prefix+root;$document.on("change",root_prefix+"-setting-register-enable input#"+prefix+"-setting-register-enable",function(e){e.preventDefault();var view_data={role_defaults:{apply_defaults_on_register:0}};if(this.checked){view_data={role_defaults:{apply_defaults_on_register:true}}}VAA_View_Admin_As.ajax(view_data,false)});$document.on("change",root_prefix+"-setting-disable-user-screen-options input#"+prefix+"-setting-disable-user-screen-options",function(e){e.preventDefault();var view_data={role_defaults:{disable_user_screen_options:0}};if(this.checked){view_data={role_defaults:{disable_user_screen_options:true}}}VAA_View_Admin_As.ajax(view_data,false)});$document.on("change",root_prefix+"-setting-lock-meta-boxes input#"+prefix+"-setting-lock-meta-boxes",function(e){e.preventDefault();var view_data={role_defaults:{lock_meta_boxes:0}};if(this.checked){view_data={role_defaults:{lock_meta_boxes:true}}}VAA_View_Admin_As.ajax(view_data,false)});$document.on("click touchend",root_prefix+"-meta-add button#"+prefix+"-meta-add",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();var val=$(root_prefix+"-meta-add input#"+prefix+"-meta-new").val();var item=$(root_prefix+"-meta-add #"+prefix+"-meta-template").html().toString();val=val.replace(/ /g,"_");item=item.replace(/vaa_new_item/g,val);if($(root_prefix+'-meta-select input[value="'+val+'"]').length){VAA_View_Admin_As.item_notice($(this).parent(),VAA_View_Admin_As.__key_already_exists,"error",2e3)}else{$(root_prefix+"-meta-select > .ab-item").prepend(item)}});$document.on("click touchend",root_prefix+"-meta-apply button#"+prefix+"-meta-apply",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();var val={};$(root_prefix+"-meta-select .ab-item.vaa-item input").each(function(){val[$(this).val()]=$(this).is(":checked")});if(val){var view_data={role_defaults:{update_meta:val}};VAA_View_Admin_As.ajax(view_data,false)}return false});$document.on("keyup",root_prefix+"-bulk-users-filter input#"+prefix+"-bulk-users-filter",function(e){e.preventDefault();if(1<=$(this).val().length){var inputText=$(this).val();$(root_prefix+"-bulk-users-select .ab-item.vaa-item").each(function(){var name=$(".user-name",this).text();if(-1"+err+"","error")}}return false});$document.on("click touchend",root_prefix+"-clear-roles-apply button#"+prefix+"-clear-roles-apply",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();var val=$(root_prefix+"-clear-roles-select select#"+prefix+"-clear-roles-select").val();if(val&&""!==val){var view_data={role_defaults:{clear_role_defaults:val}},confirm=VAA_View_Admin_As.item_confirm($(this).parent(),VAA_View_Admin_As.__confirm);$(confirm).on("click",function(){VAA_View_Admin_As.ajax(view_data,false)})}return false})};VAA_View_Admin_As.init_module_role_manager=function(){var root=VAA_View_Admin_As.root+"-modules",prefix="vaa-modules",root_prefix=VAA_View_Admin_As.prefix+root;$document.on("change",root_prefix+"-role-manager-enable input#"+prefix+"-role-manager-enable",function(e){e.preventDefault();var view_data={role_manager:{enable:0}};if(this.checked){view_data={role_manager:{enable:true}}}VAA_View_Admin_As.ajax(view_data,true)});root=VAA_View_Admin_As.root+"-role-manager";prefix="vaa-role-manager";root_prefix=VAA_View_Admin_As.prefix+root;$document.on("click touchend",root_prefix+"-apply-view-apply button#"+prefix+"-apply-view-apply",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();var role=$(root_prefix+"-apply-view-select select#"+prefix+"-apply-view-select").val();var capabilities=JSON.parse($(this).attr("data-view-caps"));if(role&&""!==role&&capabilities){var view_data={role_manager:{apply_view_to_role:{role:role,capabilities:capabilities}}};VAA_View_Admin_As.ajax(view_data,true)}return false});$document.on("click touchend",root_prefix+"-rename-apply button#"+prefix+"-rename-apply",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();var role=$(root_prefix+"-rename-select select#"+prefix+"-rename-select").val();var new_name=$(root_prefix+"-rename-input input#"+prefix+"-rename-input").val();if(role&&""!==role&&new_name&&""!==new_name){var view_data={role_manager:{rename_role:{role:role,new_name:new_name}}};VAA_View_Admin_As.ajax(view_data,true)}return false});$document.on("click touchend",root_prefix+"-clone-apply button#"+prefix+"-clone-apply",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();var role=$(root_prefix+"-clone-select select#"+prefix+"-clone-select").val();var new_role=$(root_prefix+"-clone-input input#"+prefix+"-clone-input").val();if(role&&""!==role&&new_role&&""!==new_role){var view_data={role_manager:{clone_role:{role:role,new_role:new_role}}};VAA_View_Admin_As.ajax(view_data,true)}return false});$document.on("click touchend",root_prefix+"-delete-apply button#"+prefix+"-delete-apply",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();var val=$(root_prefix+"-delete-select select#"+prefix+"-delete-select").val();if(val&&""!==val){var view_data={role_manager:{delete_role:val}},confirm=VAA_View_Admin_As.item_confirm($(this).parent(),VAA_View_Admin_As.__confirm);$(confirm).on("click",function(){VAA_View_Admin_As.ajax(view_data,true)})}return false});var caps_root=VAA_View_Admin_As.root+"-caps-manager-role-manager",caps_prefix="vaa-caps-manager-role-manager",caps_root_prefix=VAA_View_Admin_As.prefix+caps_root;$document.on("change",caps_root_prefix+" select#"+caps_prefix+"-edit-role",function(){var $this=$(this),role=$this.val(),caps={},selectedRoleElement=$(caps_root_prefix+" select#"+caps_prefix+'-edit-role option[value="'+role+'"]');if(selectedRoleElement.attr("data-caps")){caps=JSON.parse(selectedRoleElement.attr("data-caps"))}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;VAA_View_Admin_As.filter_capabilities();VAA_View_Admin_As.set_selected_capabilities(caps)});$document.on("click touchend",caps_root_prefix+" button#"+caps_prefix+"-save-role",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();var role=$(caps_root_prefix+" select#"+caps_prefix+"-edit-role").val(),refresh=false;if(!role){return false}if("__new__"===role){role=$(caps_root_prefix+" input#"+caps_prefix+"-new-role").val();refresh=true}var data={role:role,capabilities:VAA_View_Admin_As.get_selected_capabilities()};VAA_View_Admin_As.ajax({role_manager:{save_role:data}},refresh);return false});$document.on("click touchend",caps_root_prefix+"-new-cap button#"+caps_prefix+"-add-cap",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();var existing=VAA_View_Admin_As.get_selected_capabilities();var val=$(caps_root_prefix+"-new-cap input#"+caps_prefix+"-new-cap").val();var item=$(caps_root_prefix+"-new-cap #"+caps_prefix+"-cap-template").html().toString();val=val.replace(/ /g,"_");item=item.replace(/vaa_new_item/g,val);if("undefined"!==typeof existing[val]){VAA_View_Admin_As.item_notice($(this).parent(),VAA_View_Admin_As.__key_already_exists,"error",2e3)}else{$(VAA_View_Admin_As.root+"-caps-select-options > .ab-item").prepend(item)}})};VAA_View_Admin_As.autoMaxHeight=function(){setTimeout(function(){var scrollTop="undefined"!==typeof window.pageYOffset?window.pageYOffset:(document.documentElement||document.body.parentNode||document.body).scrollTop;VAA_View_Admin_As.maxHeightListenerElements.each(function(){var $element=$(this),count=0,wait=setInterval(function(){var offset=$element.offset(),offsetTop=offset.top-scrollTop;if($element.is(":visible")&&0$body.innerWidth()){$body.addClass("vaa-mobile");VAA_View_Admin_As._mobile=true;VAA_View_Admin_As.mobile()}VAA_View_Admin_As.maxHeightListenerElements.each(function(){$(this).parents(".menupop").on("mouseenter",function(){VAA_View_Admin_As.autoMaxHeight()})})});$document.on("click touchend",VAA_View_Admin_As.prefix+".vaa-reset-item > .ab-item",function(e){e.preventDefault();if(true===VAA_View_Admin_As._touchmove){return}if("vaa_reload"===$("button",this).attr("name")){window.location.reload()}else{VAA_View_Admin_As.ajax({reset:true},true);return false}});$.each(VAA_View_Admin_As.view_types,function(index,type){$document.on("click touchend",VAA_View_Admin_As.prefix+".vaa-"+type+"-item > a.ab-item",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();var $this=$(this);if(VAA_View_Admin_As._mobile&&$this.parent().hasClass("menupop")&&!$this.next().is(":visible")){$this.next().show().parent().addClass("active");return}if(!$this.parent().hasClass("not-a-view")){var view_data={},val=$this.attr("rel");if(!val){val=$this.find(".vaa-view-data").attr("vaa-view-value")}view_data[type]=VAA_View_Admin_As.json_decode(val);view_data="object"===typeof view_data[type]?view_data[type]:view_data;VAA_View_Admin_As.ajax(view_data,true);return false}})});$document.on("click touchend",VAA_View_Admin_As.prefix+".remove",function(e){e.preventDefault();if(true===VAA_View_Admin_As._touchmove){return}$(this).parent().slideUp("fast",function(){$(this).remove()})})};VAA_View_Admin_As.mobile=function(){var prefix=".vaa-mobile "+VAA_View_Admin_As.prefix;$document.on("click touchend",prefix+" > .ab-sub-wrapper .ab-item",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();e.stopPropagation();var $sub=$(this).parent(".menupop").children(".ab-sub-wrapper");if($sub.length){if($sub.hasClass("active")){$sub.slideUp("fast");$sub.removeClass("active")}else{$sub.slideDown("fast");$sub.addClass("active")}}});$document.on("click touchend",prefix+"input, "+prefix+"textarea, "+prefix+"select",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.stopPropagation();var $this=$(this);if($this.is('[type="checkbox"]')){e.preventDefault();if($this.is(":checked")){$this.prop("checked",false)}else{$this.prop("checked",true)}$this.trigger("change");return false}else if($this.is('[type="radio"]')){e.preventDefault();$('input[name="'+$this.attr["name"]+'"]').removeAttr("checked");$this.prop("checked",true);$this.trigger("change");return false}return true});$document.on("click touchend",prefix+"label",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();e.stopPropagation();$("#"+$(this).attr("for")).trigger(e.type);return false})};VAA_View_Admin_As.overlay=function(html){var $overlay=$("#vaa-overlay");if(!$overlay.length){html='
    '+html+"
    ";$body.append(html);$overlay=$("body #vaa-overlay")}else if(html.length){$overlay.html(html)}$overlay.fadeIn("fast")};VAA_View_Admin_As.ajax=function(data,refresh){$(".vaa-notice","#wpadminbar").remove();var loader_icon=VAA_View_Admin_As.siteurl+"/wp-includes/images/spinner-2x.gif";VAA_View_Admin_As.overlay('');var post_data={action:"view_admin_as",_vaa_nonce:VAA_View_Admin_As._vaa_nonce,view_admin_as:JSON.stringify(data)};var isView=false;$.each(VAA_View_Admin_As.view_types,function(index,type){if("undefined"!==typeof data[type]){isView=true;return true}});if($(VAA_View_Admin_As.prefix+"#vaa-settings-view-mode-single").is(":checked")&&isView){$body.append('');var form=$("#vaa_single_mode_form");form.append('');form.append('');form.append('');form.find("#data").val(post_data.view_admin_as);form.submit()}else{$.post(VAA_View_Admin_As.ajaxurl,post_data,function(response){var success=response.hasOwnProperty("success")&&true===response.success,data={},display=false;if(true===VAA_View_Admin_As._debug){console.log(response)}if(response.hasOwnProperty("data")){if("object"===typeof response.data){data=response.data;if(data.hasOwnProperty("display")){display=data.display}}}if(success){if(refresh){VAA_View_Admin_As.refresh(data);return}else{if(!data.hasOwnProperty("text")){data.text=VAA_View_Admin_As.__success}}}if(!data.hasOwnProperty("type")){data.type=success?"success":"error"}if("popup"===display){VAA_View_Admin_As.popup(data,data.type)}else{if(!data.hasOwnProperty("text")){data.text=response.data}VAA_View_Admin_As.notice(String(data.text),data.type,5e3);$("body #vaa-overlay").addClass(data.type).fadeOut("fast",function(){$(this).remove()})}})}};VAA_View_Admin_As.refresh=function(data){if(data.hasOwnProperty("redirect")){window.location.replace(String(data.redirect))}else{window.location.hash="";window.location.reload()}};VAA_View_Admin_As.notice=function(notice,type,timeout){var root="#wpadminbar .vaa-notice",html=notice+'';type="undefined"===typeof type?"notice":type;timeout="undefined"===typeof timeout?5e3:timeout;if(VAA_View_Admin_As._mobile){html='";$(VAA_View_Admin_As.prefix+"> .ab-sub-wrapper").prepend(html).children(".vaa-notice").slideDown("fast");$("html, body").animate({scrollTop:"0"});if(timeout){setTimeout(function(){$(root).slideUp("fast",function(){$(this).remove()})},timeout)}}else{html='
  • '+html+"
  • ";$("#wp-admin-bar-top-secondary").append(html);$(root+" .remove").click(function(){$(this).parent().remove()});if(timeout){setTimeout(function(){$(root).fadeOut("fast",function(){$(this).remove()})},timeout)}}};VAA_View_Admin_As.item_notice=function(parent,notice,type,timeout){var root=".vaa-notice",html=notice+'',$element=$(parent);type="undefined"===typeof type?"notice":type;timeout="undefined"===typeof timeout?5e3:timeout;html='";$element.append(html).children(".vaa-notice").slideDown("fast");if(timeout){setTimeout(function(){$(root,$element).slideUp("fast",function(){$(this).remove()})},timeout)}};VAA_View_Admin_As.item_confirm=function(parent,text){$(parent).find(".vaa-notice").slideUp("fast",function(){$(this).remove()});text='";VAA_View_Admin_As.item_notice(parent,text,"warning",0);return $(parent).find(".vaa-confirm")};VAA_View_Admin_As.popup=function(data,type){type="undefined"===typeof type?"notice":type;var html="";html+='
    ';html+='';html+='
    ';if("object"!==typeof data){data={text:data}}if(data.hasOwnProperty("text")){html+="

    "+String(data.text)+"

    "}if(data.hasOwnProperty("list")){html+="
      ";data.list.forEach(function(item){html+="
    • "+String(item)+"
    • "});html+="
    "}if(data.hasOwnProperty("textarea")){html+='"}html+="
    ";VAA_View_Admin_As.overlay(html);var root="body #vaa-overlay",$overlay=$(root),$overlay_container=$(root+" .vaa-overlay-container"),$popup_response=$(root+" .vaa-response-data");$(root+" .vaa-overlay-container .remove").click(function(){$overlay.fadeOut("fast",function(){$(this).remove()})});$document.on("mouseup",function(e){$(root+" .vaa-overlay-container").each(function(){if(!$(this).is(e.target)&&0===$(this).has(e.target).length){$overlay.fadeOut("fast",function(){$(this).remove()})}})});var textarea=$("textarea",$popup_response);if(textarea.length){textarea.on("click",function(){$(this).select()})}var popupMaxHeight=function(){if(textarea.length){textarea.each(function(){$(this).css({height:"auto","overflow-y":"hidden"}).height(this.scrollHeight)})}var max_height=$overlay.height()*.8-24;$overlay_container.css("max-height",max_height);$popup_response.css("max-height",max_height)};popupMaxHeight();$window.on("resize",function(){popupMaxHeight()})};VAA_View_Admin_As.init_auto_js=function(){$(VAA_View_Admin_As.root+" [vaa-auto-js]").each(function(){var $this=$(this),data=VAA_View_Admin_As.json_decode($this.attr("vaa-auto-js"));if("object"!==typeof data){return}if(!data.hasOwnProperty("event")){data.event="change"}if("click"===data.event){data.event="click touchend"}$this.on(data.event,function(e){if("change"!==data.event&&true===VAA_View_Admin_As._touchmove){return}e.preventDefault();VAA_View_Admin_As.do_auto_js(data,this);return false})});VAA_View_Admin_As.do_auto_js=function(data,elem){if("object"!==typeof data){return null}var $elem=$(elem),setting=data.hasOwnProperty("setting")?String(data.setting):null,confirm=data.hasOwnProperty("confirm")?Boolean(data.confirm):false,refresh=data.hasOwnProperty("refresh")?Boolean(data.refresh):false;var val=VAA_View_Admin_As.get_auto_js_values_recursive(data,elem);if(null!==val){var view_data={};view_data[setting]=val;if(confirm){confirm=VAA_View_Admin_As.item_confirm($elem.parent(),VAA_View_Admin_As.__confirm);$(confirm).on("click",function(){VAA_View_Admin_As.ajax(view_data,refresh)})}else{VAA_View_Admin_As.ajax(view_data,refresh)}}else{}};VAA_View_Admin_As.get_auto_js_values_recursive=function(data,elem){if("object"!==typeof data){return null}var stop=false,val=null;if(data.hasOwnProperty("values")){val={};$.each(data.values,function(val_key,auto_js){if("object"!==typeof auto_js||null===auto_js){auto_js={}}auto_js.required=auto_js.hasOwnProperty("required")?Boolean(auto_js.required):true;var val_val=VAA_View_Admin_As.get_auto_js_values_recursive(auto_js,elem);if(null!==val_val){val[val_key]=val_val}else if(auto_js.required){val=null;stop=true;return false}});if(stop){return null}}else{val=VAA_View_Admin_As.parse_auto_js_value(data,elem)}return val};VAA_View_Admin_As.parse_auto_js_value=function(data,elem){if("object"!==typeof data){return null}var $elem=data.hasOwnProperty("element")?$(data.element):$(elem),parser=data.hasOwnProperty("parser")?String(data.parser):"",val=null;switch(parser){case"multiple":case"multi":val={};$elem.each(function(){var $this=$(this),value;if("checkbox"===$this.attr("type")){value=data.hasOwnProperty("attr")?$this.attr(data.attr):$this.val();val[value]=this.checked}else{value=VAA_View_Admin_As.get_auto_js_value(this,data);val[$this.attr("name")]=value}});break;case"selected":val=[];$elem.each(function(){var $this=$(this),value;if("checkbox"===$this.attr("type")){value=data.hasOwnProperty("attr")?$this.attr(data.attr):$this.val();if(this.checked&&value){val.push(value)}}else{value=VAA_View_Admin_As.get_auto_js_value(this,data);if(value){val.push(value)}}});break;default:val=VAA_View_Admin_As.get_auto_js_value($elem,data);break}return val};VAA_View_Admin_As.get_auto_js_value=function(elem,data){if("object"!==typeof data){data={}}var $elem=$(elem),val=null,attr=data.hasOwnProperty("attr")?String(data.attr):false,json=data.hasOwnProperty("json")?Boolean(data.json):false,value=attr?$elem.attr(attr):$elem.val();if("checkbox"===$elem.attr("type")){var checked=$elem.is(":checked");if(attr){if(checked&&value){val=value}}else{val=checked}}else{if(value){val=value}}if(json){try{val=JSON.parse(val)}catch(err){val=null;VAA_View_Admin_As.popup("
    "+err+"
    ","error")}}return val}};VAA_View_Admin_As.init_users=function(){var root=VAA_View_Admin_As.root+"-users",root_prefix=VAA_View_Admin_As.prefix+root;$document.on("keyup",root_prefix+" .ab-vaa-search.search-users input",function(){$(VAA_View_Admin_As.prefix+" .ab-vaa-search .ab-vaa-results").empty();var input_text=$(this).val();if(1<=input_text.length){$(VAA_View_Admin_As.prefix+".vaa-user-item").each(function(){var name=$(".ab-item",this).text();if(-1('+role+")")}}});if(""===$.trim($(VAA_View_Admin_As.prefix+".ab-vaa-search .ab-vaa-results").html())){$(VAA_View_Admin_As.prefix+".ab-vaa-search .ab-vaa-results").append('
    '+VAA_View_Admin_As.__no_users_found+"
    ")}}})};VAA_View_Admin_As.init_caps=function(){var root=VAA_View_Admin_As.root+"-caps",root_prefix=VAA_View_Admin_As.prefix+root;VAA_View_Admin_As.caps_filter_settings={selectedRole:"default",selectedRoleCaps:{},selectedRoleReverse:false,filterString:""};VAA_View_Admin_As.filter_capabilities=function(){var reverse=true===VAA_View_Admin_As.caps_filter_settings.selectedRoleReverse,isDefault="default"===VAA_View_Admin_As.caps_filter_settings.selectedRole,filterString=VAA_View_Admin_As.caps_filter_settings.filterString;$(root_prefix+"-select-options .vaa-cap-item").each(function(){var $this=$(this),exists=$("input",this).attr("value")in VAA_View_Admin_As.caps_filter_settings.selectedRoleCaps,name;$this.hide();if(reverse||exists||isDefault){if(1<=filterString.length){name=$this.text();if(-1 .ab-sub-wrapper").addClass("fullPopup");VAA_View_Admin_As.autoMaxHeight()});$document.on("click",root_prefix+" #close-caps-popup",function(){$(VAA_View_Admin_As.prefix).removeClass("fullPopupActive");$(root_prefix+"-manager > .ab-sub-wrapper").removeClass("fullPopup");VAA_View_Admin_As.autoMaxHeight()});$document.on("change",root_prefix+" .ab-vaa-select.select-role-caps select",function(){VAA_View_Admin_As.caps_filter_settings.selectedRole=$(this).val();if("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=false}else{var selectedRoleElement=$(root_prefix+'-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"));VAA_View_Admin_As.caps_filter_settings.selectedRoleReverse=1===parseInt(selectedRoleElement.attr("data-reverse"),10)}VAA_View_Admin_As.filter_capabilities()});$document.on("keyup",root_prefix+" .ab-vaa-filter input",function(){VAA_View_Admin_As.caps_filter_settings.filterString=$(this).val();VAA_View_Admin_As.filter_capabilities()});$document.on("click touchend",root_prefix+" button#select-all-caps",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();$(root_prefix+"-select-options .vaa-cap-item").each(function(){if($(this).is(":visible")){$("input",this).prop("checked",true)}});return false});$document.on("click touchend",root_prefix+" button#deselect-all-caps",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();$(root_prefix+"-select-options .vaa-cap-item").each(function(){if($(this).is(":visible")){$("input",this).prop("checked",false)}});return false});$document.on("click touchend",root_prefix+" button#apply-caps-view",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();var new_caps=VAA_View_Admin_As.get_selected_capabilities();VAA_View_Admin_As.ajax({caps:new_caps},true);return false})};VAA_View_Admin_As.init_module_role_defaults=function(){var root=VAA_View_Admin_As.root+"-role-defaults",prefix="vaa-role-defaults",root_prefix=VAA_View_Admin_As.prefix+root;$document.on("click touchend",root_prefix+"-meta-add button#"+prefix+"-meta-add",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();var val=$(root_prefix+"-meta-add input#"+prefix+"-meta-new").val();var item=$(root_prefix+"-meta-add #"+prefix+"-meta-template").html().toString();val=val.replace(/ /g,"_");item=item.replace(/vaa_new_item/g,val);if($(root_prefix+'-meta-select input[value="'+val+'"]').length){VAA_View_Admin_As.item_notice($(this).parent(),VAA_View_Admin_As.__key_already_exists,"error",2e3)}else{$(root_prefix+"-meta-select > .ab-item").prepend(item)}});$document.on("keyup",root_prefix+"-bulk-users-filter input#"+prefix+"-bulk-users-filter",function(e){e.preventDefault();if(1<=$(this).val().length){var input_text=$(this).val();$(root_prefix+"-bulk-users-select .ab-item.vaa-item").each(function(){var name=$(".user-name",this).text();if(-1 .ab-item").prepend(item)}})};VAA_View_Admin_As.autoMaxHeight=function(){if(!VAA_View_Admin_As.maxHeightListenerElements){return null}setTimeout(function(){var scroll_top="undefined"!==typeof window.pageYOffset?window.pageYOffset:(document.documentElement||document.body.parentNode||document.body).scrollTop;VAA_View_Admin_As.maxHeightListenerElements.each(function(){var $element=$(this),count=0,wait=setInterval(function(){var offset=$element.offset(),offset_top=offset.top-scroll_top;if($element.is(":visible")&&0 * @package View_Admin_As * @since 1.6 - * @version 1.7.1 + * @version 1.7.2 */ final class VAA_API { @@ -55,6 +55,10 @@ public static function is_superior_admin( $user_id = null ) { ( null !== $user_id && (int) get_current_user_id() === (int) $user_id ) ? null : $user_id ); + if ( null === $user_id ) { + $user_id = VAA_View_Admin_As_Store::get_originalUserData( 'ID' ); + } + // Is it a super admin and is it one of the manually configured superior admins? return (bool) ( true === $is_super_admin && in_array( (int) $user_id, self::get_superior_admins(), true ) ); } @@ -93,9 +97,15 @@ public static function get_superior_admins() { * Check if the provided data is the same as the current view. * * @since 1.7.1 + * @access public + * @static + * @api + * * @param array $data * @param bool $type Only compare a single view type instead of all view data? * If set, the data value should be the single view type data. + * If data is `null` then it will return true if that view type is active. + * If data is `false` then it will return true if this is the only active view type. * @return bool */ public static function is_current_view( $data, $type = null ) { @@ -106,6 +116,45 @@ public static function is_current_view( $data, $type = null ) { return false; } + /** + * Similar function to current_user_can(). + * + * @since 1.7.2 + * @access public + * @static + * @api + * + * @param string $cap The capability. + * @param array $caps (optional) Capabilities to compare to. + * Defaults to the selected caps for the current view. + * @return bool + */ + public static function current_view_can( $cap, $caps = array() ) { + $view = view_admin_as()->view(); + if ( $view ) { + return $view->current_view_can( $cap, $caps ); + } + return false; + } + + /** + * Is the current user modified? + * + * @since 1.7.2 + * @access public + * @static + * @api + * + * @return bool + */ + public static function is_user_modified() { + $view = view_admin_as()->view(); + if ( $view ) { + return $view->is_user_modified(); + } + return false; + } + /** * Is any toolbar showing? * Do not use this before the `init` hook. @@ -162,17 +211,13 @@ public static function get_vaa_action_link( $data, $nonce, $url = null ) { $params = array( 'action' => 'view_admin_as', 'view_admin_as' => $data, // wp_json_encode( array( $type, $data ) ), - '_vaa_nonce' => (string) $nonce, + '_vaa_nonce' => (string) $nonce, ); // @todo fix WP referrer/nonce checks and allow switching on any page without ajax. // @see https://codex.wordpress.org/Function_Reference/check_admin_referer if ( empty( $url ) ) { - if ( is_network_admin() ) { - $url = network_admin_url(); - } else { - $url = admin_url(); - } + $url = is_network_admin() ? network_admin_url() : admin_url(); } $url = add_query_arg( $params, ( $url ) ? $url : false ); @@ -385,20 +430,28 @@ public static function ends_with( $haystack, $needle ) { * Returns true when it's the provided version or newer. * * @since 1.6.4 + * @since 1.7.2 Only check full version numbers by default. * @access public * @static * @api * - * @global string $wp_version WordPress version. - * @param int|string $version The WP version to check. + * @global string $wp_version WordPress version. + * @param int|string $version The WP version to check. + * @param bool $only_full_versions Only validate full versions without dev notes (RC1, dev, etc). * @return bool */ - public static function validate_wp_version( $version ) { + public static function validate_wp_version( $version, $only_full_versions = true ) { global $wp_version; - if ( version_compare( $wp_version, $version, '<' ) ) { - return false; + $version = strtolower( $version ); + $compare = strtolower( $wp_version ); + if ( $only_full_versions ) { + // Only leave the version numbers. + $version = explode( '-', $version ); + $version = $version[0]; + $compare = explode( '-', $compare ); + $compare = $compare[0]; } - return true; + return (bool) version_compare( $version, $compare, '<=' ); } /** diff --git a/includes/class-compat.php b/includes/class-compat.php index 835202a3..128be087 100644 --- a/includes/class-compat.php +++ b/includes/class-compat.php @@ -168,6 +168,8 @@ public function get_wordpress_capabilities( $caps = array() ) { /** * Network capabilities. * @since 1.5.3 + * @since 1.7.2 Added new WP 4.8 caps. + * https://make.wordpress.org/core/2017/05/22/multisite-focused-changes-in-4-8/ * @see https://codex.wordpress.org/Roles_and_Capabilities */ if ( is_multisite() ) { @@ -179,6 +181,10 @@ public function get_wordpress_capabilities( $caps = array() ) { 'manage_network_themes', 'manage_network_options', ); + if ( VAA_API::validate_wp_version( '4.8' ) ) { + $network_caps[] = 'upgrade_network'; + $network_caps[] = 'setup_network'; + } $caps = array_merge( $network_caps, $caps ); } diff --git a/includes/class-controller.php b/includes/class-controller.php index c3d0add9..9033b3c6 100644 --- a/includes/class-controller.php +++ b/includes/class-controller.php @@ -16,7 +16,7 @@ * @author Jory Hogeveen * @package View_Admin_As * @since 1.7 - * @version 1.7.1 + * @version 1.7.2 * @uses VAA_View_Admin_As_Class_Base Extends class */ final class VAA_View_Admin_As_Controller extends VAA_View_Admin_As_Class_Base @@ -340,9 +340,12 @@ public function filter_update_view_caps( $null, $data, $type ) { * Check if the provided data is the same as the current view. * * @since 1.7 - * @param array $data + * @since 1.7.2 Data options: `null` for active view & `false` for only/single view. + * @param mixed $data The view data to compare with. * @param bool $type Only compare a single view type instead of all view data? - * If set, the data value should be the single view type data. + * If set, the data value should be the single view type data or `null`. + * If data is `null` then it will return true if that view type is active. + * If data is `false` then it will return true if this is the only active view type. * @return bool */ public function is_current_view( $data, $type = null ) { @@ -354,6 +357,12 @@ public function is_current_view( $data, $type = null ) { if ( is_array( $data ) ) { return VAA_API::array_equal( $data, $current ); } + if ( null === $data ) { + return true; + } + if ( false === $data ) { + return ( 1 === count( $this->store->get_view() ) ); + } return ( (string) $data === (string) $current ); } return VAA_API::array_equal( $data, $this->store->get_view() ); diff --git a/includes/class-settings.php b/includes/class-settings.php index 08e0a842..ac8b78b3 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -18,7 +18,7 @@ * @author Jory Hogeveen * @package View_Admin_As * @since 1.7 - * @version 1.7 + * @version 1.7.2 * @uses VAA_View_Admin_As_Class_Base Extends class */ class VAA_View_Admin_As_Settings extends VAA_View_Admin_As_Class_Base { @@ -157,16 +157,16 @@ protected function __construct( $id ) { $default_user = array( 'admin_menu_location' => 'top-secondary', - 'force_group_users' => 'no', - 'freeze_locale' => 'no', - 'hide_front' => 'no', + 'force_group_users' => false, + 'freeze_locale' => false, + 'hide_front' => false, 'view_mode' => 'browse', ); $allowed_user = array( 'admin_menu_location' => array( 'top-secondary', 'my-account' ), - 'force_group_users' => array( 'yes', 'no' ), - 'freeze_locale' => array( 'yes', 'no' ), - 'hide_front' => array( 'yes', 'no' ), + 'force_group_users' => array( true, false ), + 'freeze_locale' => array( true, false ), + 'hide_front' => array( true, false ), 'view_mode' => array( 'browse', 'single' ), ); diff --git a/includes/class-update.php b/includes/class-update.php index fcb59b3f..5cdc4672 100644 --- a/includes/class-update.php +++ b/includes/class-update.php @@ -16,7 +16,7 @@ * @author Jory Hogeveen * @package View_Admin_As * @since 1.6 - * @version 1.7 + * @version 1.7.2 * @uses VAA_View_Admin_As_Class_Base Extends class */ final class VAA_View_Admin_As_Update extends VAA_View_Admin_As_Class_Base @@ -96,6 +96,10 @@ private function db_update() { $this->store->set_userMeta( false ); } + if ( version_compare( $current_db_version, '1.7.2', '<' ) ) { + $this->update_1_7_2(); + } + // Update version, append if needed. $this->store->set_optionData( $this->store->get_dbVersion(), 'db_version', true ); // Update option data. @@ -105,6 +109,41 @@ private function db_update() { do_action( 'vaa_view_admin_as_db_update' ); } + /** + * Update to version 1.7.2. + * Changes yes/no options to boolean types. + * + * @since 1.7.2 + * @global wpdb $wpdb + * @access private + * @return void + */ + private function update_1_7_2() { + global $wpdb; + + $sql = 'SELECT * FROM ' . $wpdb->usermeta . ' WHERE meta_key = %s'; + // @codingStandardsIgnoreLine >> $wpdb->prepare(), check returning false error. + $results = (array) $wpdb->get_results( $wpdb->prepare( $sql, 'vaa-view-admin-as' ) ); + + foreach ( $results as $meta ) { + if ( ! empty( $meta->meta_value ) ) { + // @codingStandardsIgnoreLine >> unserialize() required since WP stores it this way. + $value = unserialize( $meta->meta_value ); + if ( ! empty( $value['settings'] ) ) { + foreach ( $value['settings'] as $key => $val ) { + if ( in_array( $key, array( 'force_group_users', 'freeze_locale', 'hide_front' ), true ) ) { + $value['settings'][ $key ] = ( 'yes' === $val ) ? true : false; + } + } + update_user_meta( $meta->user_id, 'vaa-view-admin-as', $value ); + } + } + } + + // Re-init VAA store. + $this->store->init( true ); + } + /** * Main Instance. * diff --git a/includes/class-vaa.php b/includes/class-vaa.php index b93be929..e3e69f49 100644 --- a/includes/class-vaa.php +++ b/includes/class-vaa.php @@ -16,7 +16,7 @@ * @author Jory Hogeveen * @package View_Admin_As * @since 0.1 - * @version 1.7.1 + * @version 1.7.2 */ final class VAA_View_Admin_As { @@ -216,8 +216,7 @@ private function run() { $this->store->init( true ); - // Sets enabled. - $this->validate_user(); + $this->set_enabled(); $this->load_modules(); @@ -253,9 +252,31 @@ private function run() { } } + /** + * Try to enable plugin functionality. + * + * @since 1.7.2 + * @access public + * @return bool + */ + public function set_enabled() { + $this->enable = $this->validate_user(); + return $this->enable; + } + + /** + * Is enabled? + * + * @since 1.5 + * @access public + * @return bool + */ + public function is_enabled() { + return (bool) $this->enable; + } + /** * Validate if the current user has access to the functionalities. - * Sets enabled if user passes validation. * * @since 0.1 Check if the current user had administrator rights (is_super_admin). * Disable plugin functions for network admin pages. @@ -270,17 +291,17 @@ private function run() { * @return bool */ public function validate_user() { - $this->enable = false; + $valid = false; if ( ( VAA_API::is_super_admin() || ( current_user_can( 'view_admin_as' ) && current_user_can( 'edit_users' ) ) ) && ( ! is_network_admin() || VAA_API::is_superior_admin( $this->store->get_curUser()->ID ) ) && $this->store->get_curUserSession() ) { - $this->enable = true; + $valid = true; } - return $this->enable; + return $valid; } /** @@ -308,10 +329,9 @@ public function include_file( $file, $class = '' ) { if ( empty( $class ) || ! class_exists( $class ) ) { include_once( $file ); } else { - $this->add_notice( 'class-error-' . $class, array( + $this->add_error_notice( __METHOD__ . ' - ' . $class, array( 'type' => 'notice-error', - 'message' => '' . __( 'View Admin As', VIEW_ADMIN_AS_DOMAIN ) . ': ' - . __( 'Plugin not fully loaded because of a conflict with an other plugin or theme', VIEW_ADMIN_AS_DOMAIN ) + 'message' => __( 'Plugin not fully loaded because of a conflict with an other plugin or theme', VIEW_ADMIN_AS_DOMAIN ) // Translators: %s stands for the class name. . ' (' . sprintf( __( 'Class %s already exists', VIEW_ADMIN_AS_DOMAIN ), $class ) . ')', ) ); @@ -370,6 +390,10 @@ public function load_files( $includes, &$group = null ) { private function load_ui() { $includes = array( + 'form' => array( + 'file' => 'ui/class-form.php', + 'class' => 'VAA_View_Admin_As_Form', + ), 'ui' => array( 'file' => 'ui/class-ui.php', 'class' => 'VAA_View_Admin_As_UI', @@ -415,6 +439,13 @@ private function load_modules() { ); } + if ( is_callable( array( 'Groups_Group', 'get_groups' ) ) ) { + $includes['groups'] = array( + 'file' => 'modules/class-groups.php', + 'class' => 'VAA_View_Admin_As_Groups', + ); + } + // Run include code but do not register modules yet (leave that to the modules). $this->load_files( $includes ); @@ -458,17 +489,6 @@ public function load_textdomain() { } } - /** - * Is enabled? - * - * @since 1.5 - * @access public - * @return bool - */ - public function is_enabled() { - return (bool) $this->enable; - } - /** * Get the store class. * @@ -567,6 +587,42 @@ public function welcome_notice() { ) ); } + /** + * Add error notices to generate. + * Automatically generated a bug report link at the end of the notice. + * + * @since 1.7.2 + * @access public + * + * @param string $id + * @param array $notice { + * Required array. + * @type string $message The notice message. + * @type string $type (optional) The WP notice type class(es). + * } + * @return void + */ + public function add_error_notice( $id, $notice ) { + if ( ! empty( $notice['message'] ) ) { + $notice['type'] = ( ! empty( $notice['type'] ) ) ? $notice['type'] : 'notice-error'; + + // @todo Add debug_backtrace to body? + $report = array( + 'title' => __( 'Error', VIEW_ADMIN_AS_DOMAIN ) . ': ' . $id, + 'body' => $notice['message'], + ); + $report_link = add_query_arg( $report, 'https://github.com/JoryHogeveen/view-admin-as/issues/new' ); + + $notice['message'] = '' . __( 'View Admin As', VIEW_ADMIN_AS_DOMAIN ) . ': ' + . $notice['message'] + . ' ' + . __( 'Click here to report this error!', VIEW_ADMIN_AS_DOMAIN ) + . ''; + + $this->add_notice( $id, $notice ); + } + } + /** * Add notices to generate. * @@ -576,13 +632,14 @@ public function welcome_notice() { * @param string $id * @param array $notice { * Required array. - * @type string $type The WP notice type class(es). * @type string $message The notice message. + * @type string $type (optional) The WP notice type class(es). * } * @return void */ public function add_notice( $id, $notice ) { - if ( isset( $notice['type'] ) && ! empty( $notice['message'] ) ) { + if ( ! empty( $notice['message'] ) ) { + $notice['type'] = ( ! empty( $notice['type'] ) ) ? $notice['type'] : ''; $this->notices[ $id ] = array( 'type' => $notice['type'], 'message' => $notice['message'], diff --git a/includes/class-view.php b/includes/class-view.php index 082d692b..bf485af3 100644 --- a/includes/class-view.php +++ b/includes/class-view.php @@ -17,7 +17,7 @@ * @package View_Admin_As * @since 1.6 * @since 1.7 Class got split up: data handling/updating is now in VAA_View_Admin_As_Controller. - * @version 1.7.1 + * @version 1.7.2 * @uses VAA_View_Admin_As_Class_Base Extends class */ final class VAA_View_Admin_As_View extends VAA_View_Admin_As_Class_Base @@ -31,6 +31,14 @@ final class VAA_View_Admin_As_View extends VAA_View_Admin_As_Class_Base */ private static $_instance = null; + /** + * Is the current user modified? + * + * @since 1.7.2 + * @var bool + */ + private $is_user_modified = false; + /** * VAA_View_Admin_As_View constructor. * @@ -119,7 +127,7 @@ private function do_view() { * Force own locale on view. * @since 1.6.1 */ - if ( 'yes' === $this->store->get_userSettings( 'freeze_locale' ) + if ( $this->store->get_userSettings( 'freeze_locale' ) && (int) $this->store->get_curUser()->ID !== (int) $this->store->get_selectedUser()->ID ) { add_action( 'init', array( $this, 'freeze_locale' ), 0 ); @@ -138,6 +146,8 @@ public function init_user_modifications() { static $done; if ( $done ) return; + $this->is_user_modified = true; + add_action( 'vaa_view_admin_as_do_view', array( $this, 'modify_user' ), 99 ); /** @@ -159,17 +169,39 @@ public function init_user_modifications() { */ add_filter( 'get_user_metadata' , array( $this, 'filter_overrule_get_user_metadata' ), 999999999, 3 ); + // `user_has_cap` priority. + $priority = -999999999; + if ( $this->store->get_view( 'caps' ) ) { + // Overwrite everything when the capability view is active. + remove_all_filters( 'user_has_cap' ); + $priority = 999999999; + } /** - * Map the capabilities (map_meta_cap is used for compatibility with network admins). - * @since 0.1 + * The priority value of the VAA `user_has_cap` filter. + * Runs as first by default. + * + * @since 1.7.2 + * @param int $priority + * @return int */ - add_filter( 'map_meta_cap', array( $this, 'filter_map_meta_cap' ), 999999999, 3 ); //4 + $priority = (int) apply_filters( 'view_admin_as_user_has_cap_priority', $priority ); /** * Change the capabilities. + * * @since 1.7.1 + * @since 1.7.2 Changed priority to set is at the beginning instead of as last + * to allow other plugins to filter based on the modified user. */ - add_filter( 'user_has_cap', array( $this, 'filter_user_has_cap' ), 999999999, 4 ); + add_filter( 'user_has_cap', array( $this, 'filter_user_has_cap' ), $priority, 4 ); + + /** + * Map the capabilities (map_meta_cap is used for compatibility with network admins). + * Filter as last to check other plugin changes as well. + * + * @since 0.1 + */ + add_filter( 'map_meta_cap', array( $this, 'filter_map_meta_cap' ), 999999999, 4 ); $done = true; } @@ -352,15 +384,16 @@ public function filter_overrule_get_user_metadata( $null, $object_id, $meta_key * @since 1.6 Moved to this class from main class. * @since 1.6.2 Use logic from current_view_can(). * @since 1.6.3 Prefix function name with `filter_`. + * @since 1.7.2 Use the `user_has_cap` filter for compatibility enhancements. * @access public * * @param array $caps The actual (mapped) cap names, if the caps are not mapped this returns the requested cap. * @param string $cap The capability that was requested. * @param int $user_id The ID of the user. - * param array $args Adds the context to the cap. Typically the object ID (not used). + * @param array $args Adds the context to the cap. Typically the object ID (not used). * @return array $caps */ - public function filter_map_meta_cap( $caps, $cap, $user_id ) { + public function filter_map_meta_cap( $caps, $cap, $user_id, $args = array() ) { if ( (int) $this->store->get_selectedUser()->ID !== (int) $user_id ) { return $caps; @@ -368,12 +401,33 @@ public function filter_map_meta_cap( $caps, $cap, $user_id ) { $filter_caps = (array) $this->store->get_selectedCaps(); + if ( ! $this->store->get_view( 'caps' ) ) { + /** + * Apply user_has_cap filters to make sure we are compatible with modifications from other plugins. + * + * Issues found: + * - Restrict User Access - Overwrites our filtered capabilities. (fixed since RUA 0.15.x). + * - Groups - Overwrites our filtered capabilities. (fixed in Groups module). + * + * @since 1.7.2 + * @see WP_User::has_cap() + */ + $filter_caps = apply_filters( + 'user_has_cap', + $filter_caps, + $caps, + // Replicate arguments for `user_has_cap`. + array_merge( array( $cap, $user_id ), (array) $args ), + $this->store->get_selectedUser() + ); + } + foreach ( (array) $caps as $actual_cap ) { if ( ! $this->current_view_can( $actual_cap, $filter_caps ) ) { - // Regular users. - $caps[ $cap ] = 0; + // Regular users. Assuming this capability never exists.. + $caps['vaa_do_not_allow'] = 'vaa_do_not_allow'; // Network admins. - $caps[] = 'do_not_allow'; + $caps['do_not_allow'] = 'do_not_allow'; } } @@ -419,16 +473,28 @@ public function current_view_can( $cap, $caps = array() ) { $caps = $this->store->get_selectedCaps(); } - if ( is_array( $caps ) - && array_key_exists( $cap, $caps ) - && 1 === (int) $caps[ $cap ] - && 'do_not_allow' !== $caps[ $cap ] + if ( is_array( $caps ) && + array_key_exists( $cap, $caps ) && + 1 === (int) $caps[ $cap ] && + 'do_not_allow' !== $cap && + 'do_not_allow' !== $caps[ $cap ] ) { return true; } return false; } + /** + * Is the current user modified? + * + * @since 1.7.2 + * @access public + * @return bool + */ + public function is_user_modified() { + return (bool) $this->is_user_modified; + } + /** * Set the locale for the current view. * diff --git a/modules/class-groups.php b/modules/class-groups.php new file mode 100644 index 00000000..6a3c6015 --- /dev/null +++ b/modules/class-groups.php @@ -0,0 +1,654 @@ + + * @package View_Admin_As + */ + +if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) { + die(); +} + +add_action( 'vaa_view_admin_as_modules_loaded', array( 'VAA_View_Admin_As_Groups', 'get_instance' ) ); + +/** + * Compatibility class for the Groups plugin + * + * Tested from Groups version: 2.1.2 + * + * @author Jory Hogeveen + * @package View_Admin_As + * @since 1.7.2 + * @version 1.7.2 + * @uses VAA_View_Admin_As_Class_Base Extends class + */ +final class VAA_View_Admin_As_Groups extends VAA_View_Admin_As_Class_Base +{ + /** + * The single instance of the class. + * + * @since 1.7.2 + * @static + * @var VAA_View_Admin_As_Groups + */ + private static $_instance = null; + + /** + * The existing groups. + * + * @since 1.7.2 + * @see Groups_Group >> groups/lib/core/class-groups-group.php + * @var array of objects: Groups_Group + */ + private $groups; + + /** + * @since 1.7.2 + * @see Groups_Group >> groups/lib/core/class-groups-group.php + * @var Groups_Group + */ + private $selectedGroup; + + /** + * @since 1.7.2 + * @var string + */ + private $viewKey = 'groups'; + + /** + * Populate the instance and validate Groups plugin. + * + * @since 1.7.2 + * @access protected + * @param VAA_View_Admin_As $vaa The main VAA object. + */ + protected function __construct( $vaa ) { + self::$_instance = $this; + parent::__construct( $vaa ); + + if ( ! $this->vaa->is_enabled() ) { + return; + } + + if ( is_callable( array( 'Groups_Group', 'get_groups' ) ) && + defined( 'GROUPS_ADMINISTER_GROUPS' ) && + current_user_can( GROUPS_ADMINISTER_GROUPS ) && + ! is_network_admin() + ) { + + $this->vaa->register_module( array( + 'id' => $this->viewKey, + 'instance' => self::$_instance, + ) ); + + $this->store_groups(); + + add_action( 'vaa_admin_bar_menu', array( $this, 'admin_bar_menu' ), 40, 2 ); + add_filter( 'view_admin_as_view_types', array( $this, 'add_view_type' ) ); + + add_filter( 'view_admin_as_validate_view_data_' . $this->viewKey, array( $this, 'validate_view_data' ), 10, 2 ); + add_filter( 'view_admin_as_update_view_' . $this->viewKey, array( $this, 'update_view' ), 10, 3 ); + } + + add_action( 'vaa_view_admin_as_do_view', array( $this, 'do_view' ) ); + } + + /** + * Initialize the Groups module. + * @since 1.7.2 + * @access public + */ + public function do_view() { + + if ( $this->get_groups( $this->store->get_view( $this->viewKey ) ) ) { + + $this->selectedGroup = new Groups_Group( $this->store->get_view( $this->viewKey ) ); + + $this->reset_groups_user(); + + add_filter( 'vaa_admin_bar_viewing_as_title', array( $this, 'vaa_viewing_as_title' ) ); + + $this->vaa->view()->init_user_modifications(); + add_action( 'vaa_view_admin_as_modify_user', array( $this, 'modify_user' ), 10, 2 ); + + add_filter( 'groups_post_access_user_can_read_post', array( $this, 'groups_post_access_user_can_read_post' ), 99, 3 ); + + /** + * Replicate 404 page when the selected user has no access to read. + * I use this since I can't hook into the `posts_where` filter from Groups. + * @see VAA_View_Admin_As_Groups::groups_post_access_user_can_read_post() + */ + add_action( 'wp', array( $this, 'post_access_404' ) ); + //add_filter( 'groups_post_access_posts_where_apply', '__return_false' ); + + remove_shortcode( 'groups_member' ); + remove_shortcode( 'groups_non_member' ); + add_shortcode( 'groups_member', array( $this, 'shortcode_groups_member' ) ); + add_shortcode( 'groups_non_member', array( $this, 'shortcode_groups_non_member' ) ); + + // Filter user-group relationships. + //add_filter( 'groups_user_is_member', array( $this, 'groups_user_is_member' ), 20, 3 ); + } + + // Filter group capabilities. + if ( VAA_API::is_user_modified() ) { + add_filter( 'groups_group_can', array( $this, 'groups_group_can' ), 20, 3 ); + add_filter( 'groups_user_can', array( $this, 'groups_user_can' ), 20, 3 ); + } + } + + /** + * Reset Groups_User data for the selected user. + * + * @since 1.7.2 + * @access public + * @param int $user_id + */ + public function reset_groups_user( $user_id = null ) { + if ( ! is_callable( array( 'Groups_User', 'clear_cache' ) ) ) { + return; + } + + if ( ! $user_id ) { + $user_id = $this->store->get_selectedUser()->ID; + } + + try { + + Groups_User::clear_cache( $user_id ); + + $capabilities_base = array(); + $capability_ids_base = array(); + $groups_ids_base = array( $this->selectedGroup->group_id ); + $groups_base = array( $this->selectedGroup ); + $capabilities = null; + $capability_ids = null; + $groups_ids = null; + $groups = null; + + Groups_Cache::set( Groups_User::CAPABILITIES_BASE . $user_id, $capabilities_base, Groups_User::CACHE_GROUP ); + Groups_Cache::set( Groups_User::CAPABILITY_IDS_BASE . $user_id, $capability_ids_base, Groups_User::CACHE_GROUP ); + Groups_Cache::set( Groups_User::GROUP_IDS_BASE . $user_id, $groups_ids_base, Groups_User::CACHE_GROUP ); + Groups_Cache::set( Groups_User::GROUPS_BASE . $user_id, $groups_base, Groups_User::CACHE_GROUP ); + //Groups_Cache::set( Groups_User::CAPABILITIES . $user_id, $capabilities, Groups_User::CACHE_GROUP ); + //Groups_Cache::set( Groups_User::CAPABILITY_IDS . $user_id, $capability_ids, Groups_User::CACHE_GROUP ); + //Groups_Cache::set( Groups_User::GROUP_IDS . $user_id, $groups_ids, Groups_User::CACHE_GROUP ); + //Groups_Cache::set( Groups_User::GROUPS . $user_id, $groups, Groups_User::CACHE_GROUP ); + + } catch ( Exception $e ) { + + $this->vaa->add_error_notice( __METHOD__, array( + 'message' => $e->getMessage(), + ) ); + + } // End try(). + } + + /** + * Update the current user's WP_User instance with the current view data. + * + * @since 1.7.2 + * @access public + * @param WP_User $user User object. + * @param bool $accessible Are the WP_User properties accessible? + */ + public function modify_user( $user, $accessible ) { + + $caps = array(); + if ( $this->selectedGroup ) { + $group_caps = (array) $this->selectedGroup->capabilities_deep; + foreach ( $group_caps as $group_cap ) { + /** + * @see Groups_Capability::create() + * @see Groups_Capability::__get() + * @param int $capability_id + * @param string $capability + * @param string $class + * @param string $object + * @param string $name + * @param string $description + * @param array $group_ids + */ + if ( isset( $group_cap->capability ) && is_string( $group_cap->capability ) ) { + $caps[ $group_cap->capability ] = 1; + } elseif ( isset( $group_cap->capability->capability ) ) { + $caps[ $group_cap->capability->capability ] = 1; + } + } + } + + $caps = array_merge( $this->store->get_selectedCaps(), $caps ); + + $this->store->set_selectedCaps( $caps ); + + if ( $accessible ) { + // Merge the caps with the current user caps, overwrite existing. + $user->allcaps = array_merge( $user->caps, $caps ); + } + } + + /** + * Filter the user-group relation. + * + * @todo https://github.com/itthinx/groups/pull/59 + * @see Groups_User_Group::read() >> groups/lib/core/class-groups-user-group.php + * + * @since 1.7.2 + * @access public + * @param bool $result Current result. + * @param int $user_id User ID. + * @param int $group_id Group ID. + * @return bool|object + */ + public function groups_user_is_member( $result, $user_id, $group_id ) { + if ( (int) $user_id === (int) $this->store->get_curUser()->ID + && $this->selectedGroup + && (int) $group_id === (int) $this->selectedGroup->group->group_id + ) { + $result = $this->selectedGroup->group; + } + return $result; + } + + /** + * Filter for the current view. + * + * @see Groups_User::can() >> groups/lib/core/class-groups-user.php + * + * @since 1.7.2 + * @access public + * @param bool $result Current result. + * @param Groups_Group $object (not used) Group object. + * @param string $cap Capability. + * @return bool + */ + public function groups_user_can( $result, $object = null, $cap = '' ) { + + /** + * Fallback PHP < 5.4 due to apply_filters_ref_array + * @see https://codex.wordpress.org/Function_Reference/apply_filters_ref_array + */ + if ( is_array( $result ) ) { + $cap = $result[2]; + //$object = $result[1]; + $result = $result[0]; + } + + if ( ! $this->store->get_view() ) { + return $result; + } + + if ( $this->selectedGroup && + is_callable( array( $this->selectedGroup, 'can' ) ) && + ! $this->selectedGroup->can( $cap ) + ) { + $result = false; + } else { + // For other view types. + $result = VAA_API::current_view_can( $cap ); + } + return $result; + } + + /** + * Filter for the current view. + * + * @see Groups_Group::can() >> groups/lib/core/class-groups-group.php + * + * @since 1.7.2 + * @access public + * @param bool $result Current result. + * @param Groups_Group $object Group object. + * @param string $cap Capability. + * @return bool + */ + public function groups_group_can( $result, $object = null, $cap = '' ) { + // Prevent loop on `groups_user_can` filter. + if ( $this->selectedGroup && $this->selectedGroup->group_id === $object->group_id ) { + return $result; + } + return $this->groups_user_can( $result, $object, $cap ); + } + + /** + * Filter whether the user can do something with a post. + * + * @see Groups_Post_Access::user_can_read_post() + * + * @since 1.7.2 + * @access public + * @param bool $result + * @param int $post_id + * @param int $user_id + * @return bool + */ + public function groups_post_access_user_can_read_post( $result, $post_id, $user_id ) { + if ( $this->store->get_selectedUser()->ID !== $user_id || ! $this->selectedGroup ) { + return $result; + } + if ( ! is_callable( 'Groups_Post_Access', 'get_read_group_ids' ) ) { + return $result; + } + + $post_access = Groups_Post_Access::get_read_group_ids( $post_id ); + $result = true; + if ( ! empty( $post_access ) && ! in_array( $this->selectedGroup->group_id, $post_access, true ) ) { + $result = false; + } + return $result; + } + + /** + * Replicate 404 page when the selected user has no access to read. + * I use this since I can't hook into the `posts_where` filter from Groups. + * + * @hook `wp` + * @see VAA_View_Admin_As_Groups::groups_post_access_user_can_read_post() + * + * @since 1.7.2 + * @access public + */ + public function post_access_404() { + global $post; + if ( isset( $post->ID ) && ! $this->groups_post_access_user_can_read_post( true, $post->ID, $this->store->get_selectedUser()->ID ) ) { + global $wp_query; + $wp_query->set_404(); + } + } + + /** + * Our own implementation for the groups_member shortcode. + * + * @see Groups_Access_Shortcodes::groups_member() + * + * @since 1.7.2 + * @param array $atts + * @param string $content + * @return string + */ + public function shortcode_groups_member( $atts, $content ) { + return $this->shortcode_member( $atts, $content, false ); + } + + /** + * Our own implementation for the groups_non_member shortcode. + * + * @see Groups_Access_Shortcodes::groups_non_member() + * + * @since 1.7.2 + * @param array $atts + * @param string $content + * @return string + */ + public function shortcode_groups_non_member( $atts, $content ) { + return ! $this->shortcode_member( $atts, $content, true ); + } + + /** + * Our own implementation for the Groups member shortcodes. + * + * @see VAA_View_Admin_As_Groups::shortcode_groups_member() + * @see VAA_View_Admin_As_Groups::shortcode_groups_non_member() + * + * @since 1.7.2 + * @param array $atts + * @param string $content + * @param bool $reverse + * @return string + */ + public function shortcode_member( $atts, $content, $reverse = false ) { + $output = ''; + $shortcode = ( $reverse ) ? 'groups_non_member' : 'groups_member'; + $options = shortcode_atts( array( 'group' => '' ), $atts ); //, $shortcode + $show_content = false; + if ( null !== $content ) { + $groups = explode( ',', $options['group'] ); + foreach ( $groups as $group ) { + $group = trim( $group ); + $selected_group = $this->selectedGroup; + $current_group = Groups_Group::read( $group ); + if ( ! $current_group ) { + $current_group = Groups_Group::read_by_name( $group ); + } + if ( $current_group && $current_group->group_id === $selected_group->group_id ) { + $show_content = ( $reverse ) ? false : true; + break; + } + } + if ( $show_content ) { + remove_shortcode( $shortcode ); + $content = do_shortcode( $content ); + add_shortcode( $shortcode, array( $this, 'shortcode_' . $shortcode ) ); + $output = $content; + } + } + return $output; + } + + /** + * Add view type. + * + * @since 1.7.2 + * @param array $types Existing view types. + * @return array + */ + public function add_view_type( $types ) { + $types[] = $this->viewKey; + return $types; + } + + /** + * Validate data for this view type + * + * @since 1.7.2 + * @param null $null Default return (invalid) + * @param mixed $data The view data + * @return mixed + */ + public function validate_view_data( $null, $data ) { + if ( is_numeric( $data ) && $this->get_groups( (int) $data ) ) { + return $data; + } + return $null; + } + + /** + * View update handler (Ajax probably), called from main handler. + * + * @since 1.7.2 + * @access public + * @param null $null Null. + * @param array $data The ajax data for this module. + * @param string $type The view type. + * @return bool + */ + public function update_view( $null, $data, $type ) { + + if ( ! $this->is_valid_ajax() || $type !== $this->viewKey ) { + return $null; + } + + if ( is_numeric( $data ) && $this->get_groups( (int) $data ) ) { + $this->store->set_view( (int) $data, $this->viewKey, true ); + return true; + } + return false; + } + + /** + * Change the VAA admin bar menu title. + * + * @since 1.7.2 + * @access public + * @param string $title The current title. + * @return string + */ + public function vaa_viewing_as_title( $title ) { + if ( $this->get_groups( $this->store->get_view( $this->viewKey ) ) ) { + // Translators: %s stands for "Group" (translated with the Groups domain). + $title = sprintf( __( 'Viewing as %s', VIEW_ADMIN_AS_DOMAIN ), $this->translate_groups( 'Group' ) ) . ': ' + . $this->get_groups( $this->store->get_view( $this->viewKey ) )->name; + } + return $title; + } + + /** + * Add the Groups admin bar items. + * + * @since 1.7.2 + * @access public + * @param WP_Admin_Bar $admin_bar The toolbar object. + * @param string $root The root item. + */ + public function admin_bar_menu( $admin_bar, $root ) { + + if ( ! $this->get_groups() || ! count( $this->get_groups() ) ) { + return; + } + + $admin_bar->add_group( array( + 'id' => $root . '-groups', + 'parent' => $root, + 'meta' => array( + 'class' => 'ab-sub-secondary', + ), + ) ); + + $root = $root . '-groups'; + + $admin_bar->add_node( array( + 'id' => $root . '-title', + 'parent' => $root, + 'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-image-filter dashicons-itthinx-groups' ) + . $this->translate_groups( 'Groups' ), + 'href' => false, + 'meta' => array( + 'class' => 'vaa-has-icon ab-vaa-title ab-vaa-toggle active', + 'tabindex' => '0', + ), + ) ); + + /** + * Add items at the beginning of the groups group. + * + * @see 'admin_bar_menu' action + * @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar + * @param WP_Admin_Bar $admin_bar The toolbar object. + * @param string $root The current root item. + */ + do_action( 'vaa_admin_bar_groups_before', $admin_bar, $root ); + + // Add the groups. + foreach ( $this->get_groups() as $group_key => $group ) { + $view_value = $group->name; + $view_data = array( $this->viewKey => $view_value ); + $href = VAA_API::get_vaa_action_link( $view_data, $this->store->get_nonce( true ) ); + $class = 'vaa-' . $this->viewKey . '-item'; + $title = VAA_View_Admin_As_Form::do_view_title( $group->name, $this->viewKey, $view_value ); + // Check if this group is the current view. + if ( $this->store->get_view( $this->viewKey ) ) { + if ( (int) $this->store->get_view( $this->viewKey ) === (int) $group->group_id ) { + $class .= ' current'; + $href = false; + } else { + $selected = $this->get_groups( $this->store->get_view( $this->viewKey ) ); + if ( (int) $selected->parent_id === (int) $group->group_id ) { + $class .= ' current-parent'; + } + } + } + $parent = $root; + if ( ! empty( $group->parent_id ) ) { + $parent = $root . '-' . $this->viewKey . '-' . (int) $group->parent_id; + } + $admin_bar->add_node( array( + 'id' => $root . '-' . $this->viewKey . '-' . (int) $group->group_id, + 'parent' => $parent, + 'title' => $title, + 'href' => $href, + 'meta' => array( + // Translators: %s stands for the view type name. + 'title' => sprintf( __( 'View as %s', VIEW_ADMIN_AS_DOMAIN ), $view_value ), + 'class' => $class, + 'rel' => $group->group_id, + ), + ) ); + } + + /** + * Add items at the end of the groups group. + * + * @see 'admin_bar_menu' action + * @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar + * @param WP_Admin_Bar $admin_bar The toolbar object. + * @param string $root The current root item. + */ + do_action( 'vaa_admin_bar_groups_after', $admin_bar, $root ); + } + + /** + * Store the available groups. + * @since 1.7.2 + * @access private + */ + private function store_groups() { + $groups = Groups_Group::get_groups(); + + if ( ! empty( $groups ) ) { + foreach ( $groups as $group ) { + $this->groups[ $group->group_id ] = $group; + } + } + } + + /** + * Get a group by ID. + * + * @since 1.7.2 + * @access public + * @param string $key The group key. + * @return mixed + */ + public function get_groups( $key = '-1' ) { + if ( ! is_numeric( $key ) ) { + return false; + } + if ( '-1' === $key ) { + $key = null; + } + return VAA_API::get_array_data( $this->groups, $key ); + } + + /** + * Translate with another domain. + * + * @since 1.7.2 + * @param string $string The string. + * @return string + */ + public function translate_groups( $string ) { + $domain = ( defined( 'GROUPS_PLUGIN_DOMAIN' ) ) ? GROUPS_PLUGIN_DOMAIN : 'groups'; + // @codingStandardsIgnoreLine >> Prevent groups translation from getting parsed by translate.wordpress.org + return __( $string, $domain ); + } + + /** + * Main Instance. + * + * Ensures only one instance of this class is loaded or can be loaded. + * + * @since 1.7.2 + * @access public + * @static + * @param VAA_View_Admin_As $caller The referrer class. + * @return VAA_View_Admin_As_Groups + */ + public static function get_instance( $caller = null ) { + if ( is_null( self::$_instance ) ) { + self::$_instance = new self( $caller ); + } + return self::$_instance; + } + +} // End class VAA_View_Admin_As_Groups. diff --git a/modules/class-restrict-user-access.php b/modules/class-restrict-user-access.php index c019b479..cd9d22d7 100644 --- a/modules/class-restrict-user-access.php +++ b/modules/class-restrict-user-access.php @@ -15,12 +15,13 @@ * * Tested from RUA version: 0.12.4 * Official RUA compat release: 0.13 (https://github.com/intoxstudio/restrict-user-access/pull/8) - * Checked version: 0.14 + * Required since v1.7.2: 0.15.1 (https://github.com/intoxstudio/restrict-user-access/pull/11) + * Checked version: 0.15.1 * * @author Jory Hogeveen * @package View_Admin_As * @since 1.6.4 - * @version 1.7.1 + * @version 1.7.2 * @uses VAA_View_Admin_As_Class_Base Extends class */ final class VAA_View_Admin_As_RUA extends VAA_View_Admin_As_Class_Base @@ -73,6 +74,12 @@ final class VAA_View_Admin_As_RUA extends VAA_View_Admin_As_Class_Base */ private $ruaApp; + /** + * @since 1.7.2 + * @var RUA_Level_Manager + */ + private $ruaLevelManager; + /** * @since 1.6.4 * @var string @@ -93,20 +100,27 @@ final class VAA_View_Admin_As_RUA extends VAA_View_Admin_As_Class_Base * @param VAA_View_Admin_As $vaa The main VAA object. */ protected function __construct( $vaa ) { + self::$_instance = $this; + parent::__construct( $vaa ); + + if ( ! $this->vaa->is_enabled() ) { + return; + } if ( ! is_callable( array( 'RUA_App', 'instance' ) ) ) { return; } - self::$_instance = $this; $this->ruaApp = RUA_App::instance(); + if ( isset( $this->ruaApp->level_manager ) ) { + $this->ruaLevelManager = $this->ruaApp->level_manager; + } $access_cap = ( defined( RUA_App::CAPABILITY ) ) ? RUA_App::CAPABILITY : 'edit_users'; $this->ruaMetaPrefix = ( defined( RUA_App::META_PREFIX ) ) ? RUA_App::META_PREFIX : '_ca_'; $this->ruaTypeRestrict = ( defined( RUA_App::TYPE_RESTRICT ) ) ? RUA_App::TYPE_RESTRICT : 'restriction'; - if ( $vaa->is_enabled() && current_user_can( $access_cap ) && ! is_network_admin() ) { - parent::__construct( $vaa ); + if ( current_user_can( $access_cap ) && ! is_network_admin() ) { $this->vaa->register_module( array( 'id' => $this->viewKey, @@ -120,11 +134,11 @@ protected function __construct( $vaa ) { add_action( 'vaa_admin_bar_menu', array( $this, 'admin_bar_menu' ), 40, 2 ); add_action( 'vaa_admin_bar_roles_after', array( $this, 'admin_bar_roles_after' ), 10, 2 ); - add_action( 'vaa_view_admin_as_do_view', array( $this, 'do_view' ) ); - add_filter( 'view_admin_as_validate_view_data_' . $this->viewKey, array( $this, 'validate_view_data' ), 10, 2 ); add_filter( 'view_admin_as_update_view_' . $this->viewKey, array( $this, 'update_view' ), 10, 3 ); } + + add_action( 'vaa_view_admin_as_do_view', array( $this, 'do_view' ) ); } /** @@ -153,6 +167,30 @@ public function do_view() { add_filter( 'rua/user/global-access', '__return_false' ); } } + + if ( VAA_API::is_user_modified() && isset( $this->ruaLevelManager ) ) { + + if ( is_callable( array( $this->ruaLevelManager, 'reset_user_levels_caps' ) ) ) { + /** + * Reset the user levels caps. + * @since 1.7.2 + * @link https://github.com/JoryHogeveen/view-admin-as/issues/56#issuecomment-299077527 + * @link https://github.com/intoxstudio/restrict-user-access/pull/11 + * @see RUA_Level_Manager::add_filters() + */ + $this->ruaLevelManager->reset_user_levels_caps( $this->store->get_selectedUser()->ID ); + } + + if ( $this->store->get_view( 'caps' ) ) { + /** + * Remove the whole filter when the caps view is selected. + * @since 1.7.2 + * @link https://github.com/JoryHogeveen/view-admin-as/issues/56#issuecomment-299077527 + * @see RUA_Level_Manager::add_filters() + */ + remove_filter( 'user_has_cap', array( $this->ruaLevelManager, 'user_level_has_cap' ), 9 ); + } + } } /** @@ -208,7 +246,7 @@ public function get_user_metadata( $null, $user_id, $meta_key ) { } /** - * Add groups view type. + * Add view type. * * @since 1.6.4 * @param array $types Existing view types. @@ -369,16 +407,17 @@ public function admin_bar_menu( $admin_bar, $root, $role = null, $role_obj = nul // Add the levels. foreach ( $this->get_levels() as $level ) { - $view_data = array( $this->viewKey => $level->ID ); + $view_value = $level->ID; + $view_data = array( $this->viewKey => $view_value ); if ( $role ) { $view_data['role'] = $role; } $href = VAA_API::get_vaa_action_link( $view_data, $this->store->get_nonce( true ) ); $class = 'vaa-' . $this->viewKey . '-item'; - $title = VAA_View_Admin_As_Admin_Bar::do_view_title( $level->post_title, $this->viewKey, ( $role ) ? wp_json_encode( $view_data ) : $level->ID ); + $title = VAA_View_Admin_As_Form::do_view_title( $level->post_title, $this->viewKey, ( $role ) ? wp_json_encode( $view_data ) : $view_value ); // Check if this level is the current view. if ( $this->store->get_view( $this->viewKey ) ) { - if ( VAA_API::is_current_view( $level->ID, $this->viewKey ) ) { + if ( VAA_API::is_current_view( $view_value, $this->viewKey ) ) { // @todo Use is_current_view() from vaa controller? if ( 1 === count( $this->store->get_view() ) && empty( $role ) ) { $class .= ' current'; @@ -387,28 +426,28 @@ public function admin_bar_menu( $admin_bar, $root, $role = null, $role_obj = nul $class .= ' current'; $href = false; } - } - elseif ( $current_parent = $this->get_levels( $this->selectedLevel ) ) { - if ( (int) $current_parent->post_parent === (int) $level->ID ) { + } else { + $selected = $this->get_levels( $this->selectedLevel ); + if ( $selected && (int) $selected->post_parent === (int) $view_value ) { $class .= ' current-parent'; } } } $parent = $root; if ( ! empty( $level->post_parent ) ) { - $parent = $root . '-' . $this->viewKey . '-' . $level->post_parent; + $parent = $root . '-' . $this->viewKey . '-' . (int) $level->post_parent; } $admin_bar->add_node( array( - 'id' => $root . '-' . $this->viewKey . '-' . $level->ID, + 'id' => $root . '-' . $this->viewKey . '-' . $view_value, 'parent' => $parent, 'title' => $title, 'href' => $href, 'meta' => array( // Translators: %s stands for the view type name. - 'title' => sprintf( esc_attr__( 'View as %s', VIEW_ADMIN_AS_DOMAIN ), $level->post_title ) + 'title' => sprintf( __( 'View as %s', VIEW_ADMIN_AS_DOMAIN ), $level->post_title ) . ( ( $role ) ? ' (' . $this->store->get_rolenames( $role_obj->name ) . ')' : '' ), 'class' => $class, - 'rel' => ( $role ) ? wp_json_encode( $view_data ) : $level->ID, + 'rel' => ( $role ) ? wp_json_encode( $view_data ) : $view_value, ), ) ); } // End foreach(). diff --git a/modules/class-role-defaults.php b/modules/class-role-defaults.php index 28479ce4..145158d1 100644 --- a/modules/class-role-defaults.php +++ b/modules/class-role-defaults.php @@ -21,7 +21,7 @@ * @author Jory Hogeveen * @package View_Admin_As * @since 1.4 - * @version 1.7.1 + * @version 1.7.2 * @uses VAA_View_Admin_As_Module Extends class */ final class VAA_View_Admin_As_Role_Defaults extends VAA_View_Admin_As_Module @@ -35,6 +35,14 @@ final class VAA_View_Admin_As_Role_Defaults extends VAA_View_Admin_As_Module */ private static $_instance = null; + /** + * Module key. + * + * @since 1.7.2 + * @var string + */ + protected $moduleKey = 'role_defaults'; + /** * Option key. * @@ -104,7 +112,7 @@ protected function __construct( $vaa ) { // Add this class to the modules in the main class. $this->vaa->register_module( array( - 'id' => 'role_defaults', + 'id' => $this->moduleKey, 'instance' => self::$_instance, ) ); @@ -139,7 +147,7 @@ protected function __construct( $vaa ) { */ if ( ! is_network_admin() && $this->current_user_can( 'view_admin_as_role_defaults' ) ) { add_action( 'vaa_view_admin_as_init', array( $this, 'vaa_init' ) ); - add_filter( 'view_admin_as_handle_ajax_role_defaults', array( $this, 'ajax_handler' ), 10, 2 ); + add_filter( 'view_admin_as_handle_ajax_' . $this->moduleKey, array( $this, 'ajax_handler' ), 10, 2 ); } } @@ -452,20 +460,23 @@ public function ajax_handler( $null, $data ) { // @since 1.5 Import if ( VAA_API::array_has( $data, 'import_role_defaults', array( 'validation' => 'is_array' ) ) ) { - $method = ( ! empty( $data['import_role_defaults_method'] ) ) ? (string) $data['import_role_defaults_method'] : ''; - // $content format: array( 'text' => **text**, 'errors' => **error array** ). - $content = $this->import_role_defaults( $data['import_role_defaults'], $method ); - if ( true === $content ) { - $success = true; - } else { - $success = $this->ajax_data_popup( false, (array) $content, 'error' ); + $success = false; + if ( ! empty( $data['import_role_defaults']['data'] ) ) { + $method = ( ! empty( $data['import_role_defaults']['method'] ) ) ? (string) $data['import_role_defaults']['method'] : ''; + // $content format: array( 'text' => **text**, 'errors' => **error array** ). + $content = $this->import_role_defaults( $data['import_role_defaults']['data'], $method ); + if ( true === $content ) { + $success = true; + } else { + $success = $this->ajax_data_popup( false, (array) $content, 'error' ); + } } } // @since 1.7 Copy if ( VAA_API::array_has( $data, 'copy_role_defaults', array( 'validation' => 'is_array' ) ) ) { if ( isset( $data['copy_role_defaults']['from'] ) && isset( $data['copy_role_defaults']['to'] ) ) { - $method = ( ! empty( $data['copy_role_defaults_method'] ) ) ? (string) $data['copy_role_defaults_method'] : ''; + $method = ( ! empty( $data['copy_role_defaults']['method'] ) ) ? (string) $data['copy_role_defaults']['method'] : ''; // $content format: array( 'text' => **text**, 'errors' => **error array** ). $content = $this->copy_role_defaults( $data['copy_role_defaults']['from'], @@ -553,14 +564,15 @@ public function update_user_with_role_defaults_multisite_register( $user_id, $ro * Apply default settings to all users of a role. * * @since 1.4 + * @since 1.7.2 Renamed "all" wildcard to "__all__" * @access private - * @param string|array $role The role name. + * @param string|array $role Role name, an array of role names or just "__all__" for all roles. * @return bool */ private function apply_defaults_to_users_by_role( $role ) { $success = true; $roles = array(); - if ( 'all' === $role ) { + if ( '__all__' === $role ) { $roles = array_keys( (array) $this->store->get_roles() ); } else { foreach ( (array) $role as $role_name ) { @@ -597,9 +609,27 @@ private function init_store_role_defaults() { if ( $this->store->get_view( 'role' ) && $this->is_enabled() ) { add_filter( 'get_user_metadata' , array( $this, 'filter_get_user_metadata' ), 10, 4 ); add_filter( 'update_user_metadata' , array( $this, 'filter_update_user_metadata' ), 10, 5 ); + add_filter( 'vaa_admin_bar_viewing_as_title', array( $this, 'vaa_title_recording_role_defaults' ), 999 ); } } + /** + * Add a role defaults icon to indicate screen changes are being recorded to role defaults. + * + * @since 1.7.2 + * @access public + * @param string $title The current title. + * @return string + */ + public function vaa_title_recording_role_defaults( $title ) { + $role = $this->store->get_view( 'role' ); + $title .= VAA_View_Admin_As_Form::do_icon( 'dashicons-welcome-view-site', array( + 'title' => __( 'Recording screen changes for role defaults', VIEW_ADMIN_AS_DOMAIN ) + . ': ' . $this->store->get_rolenames( $role ), + ) ); + return $title; + } + /** * 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. @@ -692,7 +722,7 @@ public function get_role_defaults( $role = null, $meta_key = null ) { * @since 1.7 * @access private * @param array $new_defaults New role defaults (requires a full array of roles with data). - * @param string $method Method to be used (overwrite, append or default) + * @param string $method Method to be used. (merge, append, default). */ private function set_role_defaults( $new_defaults, $method = '' ) { if ( empty( $new_defaults ) ) { @@ -705,8 +735,8 @@ private function set_role_defaults( $new_defaults, $method = '' ) { } // @since 1.6.2 Multiple import methods. switch ( $method ) { - case 'overwrite': - // Overwrite the existing data, keep data that don't exist in the import. + case 'merge': + // Merge and the existing data (keep data that doesn't exist in the import data). $role_defaults[ $role ] = array_merge( $role_defaults[ $role ], $role_data ); break; case 'append': @@ -786,14 +816,15 @@ private function copy_role_defaults( $from_role, $to_role, $method = '' ) { * Remove defaults of a role. * * @since 1.4 + * @since 1.7.2 Renamed "all" wildcard to "__all__" * @access private - * @param string|array $role Role name or array of role names or just "all" for all roles. + * @param string|array $role Role name, an array of role names or just "__all__" for all roles. * @return bool */ private function clear_role_defaults( $role ) { $role_defaults = $this->get_role_defaults(); if ( ! is_array( $role ) ) { - if ( isset( $role_defaults ) && 'all' === $role ) { + if ( isset( $role_defaults ) && '__all__' === $role ) { $role_defaults = array(); } else { $roles = array( $role ); @@ -818,16 +849,17 @@ private function clear_role_defaults( $role ) { * Export role defaults. * * @since 1.5 + * @since 1.7.2 Renamed "all" wildcard to "__all__" * @access private - * @param string $role Role name or "all" for all roles. + * @param string $role Role name or "__all__" for all roles. * @return mixed */ - private function export_role_defaults( $role = 'all' ) { + private function export_role_defaults( $role = '__all__' ) { $role_defaults = $this->get_role_defaults(); - if ( 'all' !== $role && isset( $role_defaults[ $role ] ) ) { + if ( '__all__' !== $role && isset( $role_defaults[ $role ] ) ) { $data = $role_defaults[ $role ]; $data = array( $role => $data ); - } elseif ( 'all' === $role && ! empty( $role_defaults ) ) { + } elseif ( '__all__' === $role && ! empty( $role_defaults ) ) { $data = $role_defaults; } else { $data = esc_attr__( 'No valid data found', VIEW_ADMIN_AS_DOMAIN ); @@ -943,12 +975,17 @@ public function admin_bar_menu_modules( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root_prefix . '-enable', 'parent' => $root, - 'title' => VAA_View_Admin_As_Admin_Bar::do_checkbox( array( + 'title' => VAA_View_Admin_As_Form::do_checkbox( array( 'name' => $root_prefix . '-enable', 'value' => $this->get_optionData( 'enable' ), 'compare' => true, 'label' => __( 'Enable role defaults', VIEW_ADMIN_AS_DOMAIN ), 'description' => __( 'Set default screen settings for roles and apply them on users through various bulk and automatic actions', VIEW_ADMIN_AS_DOMAIN ), + 'auto-js' => array( + 'setting' => $this->moduleKey, + 'key' => 'enable', + 'refresh' => true, + ), ) ), 'href' => false, 'meta' => array( @@ -979,7 +1016,7 @@ public function admin_bar_menu( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-role-defaults', 'parent' => $root, - 'title' => VAA_View_Admin_As_Admin_Bar::do_icon( 'dashicons-welcome-view-site' ) . __( 'Role defaults', VIEW_ADMIN_AS_DOMAIN ), + 'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-welcome-view-site' ) . __( 'Role defaults', VIEW_ADMIN_AS_DOMAIN ), 'href' => false, 'meta' => array( 'class' => 'vaa-has-icon', @@ -989,44 +1026,62 @@ public function admin_bar_menu( $admin_bar, $root ) { $root = $root . '-role-defaults'; + // @since 1.4 Enable apply defaults on register. $admin_bar->add_node( array( 'id' => $root . '-setting-register-enable', 'parent' => $root, - 'title' => VAA_View_Admin_As_Admin_Bar::do_checkbox( array( + 'title' => VAA_View_Admin_As_Form::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_DOMAIN ), + 'auto-js' => array( + 'setting' => $this->moduleKey, + 'key' => 'apply_defaults_on_register', + 'refresh' => false, + ), ) ), 'href' => false, 'meta' => array( 'class' => 'auto-height', ), ) ); + // @since 1.5.3 Disable screen settings for users who can't access this plugin. $admin_bar->add_node( array( 'id' => $root . '-setting-disable-user-screen-options', 'parent' => $root, - 'title' => VAA_View_Admin_As_Admin_Bar::do_checkbox( array( + 'title' => VAA_View_Admin_As_Form::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_DOMAIN ), 'description' => __( "Hide the screen options for all users who can't access role defaults", VIEW_ADMIN_AS_DOMAIN ), + 'auto-js' => array( + 'setting' => $this->moduleKey, + 'key' => 'disable_user_screen_options', + 'refresh' => false, + ), ) ), 'href' => false, 'meta' => array( 'class' => 'auto-height', ), ) ); + // @since 1.6 Lock meta box order and locations for users who can't access this plugin. $admin_bar->add_node( array( 'id' => $root . '-setting-lock-meta-boxes', 'parent' => $root, - 'title' => VAA_View_Admin_As_Admin_Bar::do_checkbox( array( + 'title' => VAA_View_Admin_As_Form::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_DOMAIN ), 'description' => __( "Lock meta box order and locations for all users who can't access role defaults", VIEW_ADMIN_AS_DOMAIN ), + 'auto-js' => array( + 'setting' => $this->moduleKey, + 'key' => 'lock_meta_boxes', + 'refresh' => false, + ), ) ), 'href' => false, 'meta' => array( @@ -1049,7 +1104,7 @@ public function admin_bar_menu( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-meta-title', 'parent' => $root . '-meta', - 'title' => VAA_View_Admin_As_Admin_Bar::do_icon( 'dashicons-admin-tools' ) . __( 'Manage meta sync', VIEW_ADMIN_AS_DOMAIN ), + 'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-admin-tools' ) . __( 'Manage meta sync', VIEW_ADMIN_AS_DOMAIN ), 'href' => false, 'meta' => array( 'class' => 'ab-bold vaa-has-icon ab-vaa-toggle', @@ -1059,7 +1114,7 @@ public function admin_bar_menu( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-meta-docs', 'parent' => $root . '-meta', - 'title' => VAA_View_Admin_As_Admin_Bar::do_icon( 'dashicons-info' ) . __( 'Documentation', VIEW_ADMIN_AS_DOMAIN ), + 'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-info' ) . __( 'Documentation', VIEW_ADMIN_AS_DOMAIN ), 'href' => 'https://github.com/JoryHogeveen/view-admin-as/wiki/FAQ#4-what-data-is-stored-for-role-defaults-and-how-can-i-change-this', 'meta' => array( 'class' => 'auto-height vaa-has-icon', @@ -1069,16 +1124,16 @@ public function admin_bar_menu( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-meta-add', 'parent' => $root . '-meta', - 'title' => VAA_View_Admin_As_Admin_Bar::do_input( array( + 'title' => VAA_View_Admin_As_Form::do_input( array( 'name' => $root . '-meta-new', 'placeholder' => esc_attr__( 'Add meta key', VIEW_ADMIN_AS_DOMAIN ), - ) ) . VAA_View_Admin_As_Admin_Bar::do_button( array( - 'name' => $root . '-meta-add', - 'label' => __( 'Add', VIEW_ADMIN_AS_DOMAIN ), - 'class' => 'button-primary input-overlay', + ) ) . VAA_View_Admin_As_Form::do_button( array( + 'name' => $root . '-meta-add', + 'label' => __( 'Add', VIEW_ADMIN_AS_DOMAIN ), + 'class' => 'button-primary input-overlay', ) ) . '', 'href' => false, 'meta' => array( - 'class' => 'ab-vaa-input', + 'class' => 'ab-vaa-input', ), ) ); $meta_select_content = ''; foreach ( $this->get_meta() as $metakey => $value ) { $meta_select_content .= '
    ' - . VAA_View_Admin_As_Admin_Bar::do_checkbox( array( + . VAA_View_Admin_As_Form::do_checkbox( array( 'name' => 'role-defaults-meta-select[]', 'id' => $root . '-meta-select-' . $metakey, 'value' => $value, @@ -1119,10 +1174,19 @@ public function admin_bar_menu( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-meta-apply', 'parent' => $root . '-meta', - 'title' => VAA_View_Admin_As_Admin_Bar::do_button( array( - 'name' => $root . '-meta-apply', - 'label' => __( 'Apply', VIEW_ADMIN_AS_DOMAIN ), - 'class' => 'button-primary', + 'title' => VAA_View_Admin_As_Form::do_button( array( + 'name' => $root . '-meta-apply', + 'label' => __( 'Apply', VIEW_ADMIN_AS_DOMAIN ), + 'class' => 'button-primary', + 'auto-js' => array( + 'setting' => $this->moduleKey, + 'key' => 'update_meta', + 'refresh' => false, + 'value' => array( + 'element' => '#wp-admin-bar-' . $root . '-meta-select .ab-item.vaa-item input', + 'parser' => 'multi', + ), + ), ) ), 'href' => false, 'meta' => array( @@ -1156,8 +1220,8 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { '' => array( 'label' => ' --- ', ), - 'all' => array( - 'value' => 'all', + '__all__' => array( + 'value' => '__all__', 'label' => ' - ' . __( 'All roles', VIEW_ADMIN_AS_DOMAIN ) . ' - ', ), ); @@ -1169,7 +1233,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { ); $role_check_content[ $role_key ] = '
    ' - . VAA_View_Admin_As_Admin_Bar::do_checkbox( array( + . VAA_View_Admin_As_Form::do_checkbox( array( 'name' => 'role-defaults-bulk-roles-select[]', 'id' => $root . '-bulk-roles-select-' . esc_attr( $role_key ), 'checkbox_value' => esc_attr( $role_key ), @@ -1186,7 +1250,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $role_name = $this->store->get_rolenames( $role ); $users_check_content[] = '
    ' - . VAA_View_Admin_As_Admin_Bar::do_checkbox( array( + . VAA_View_Admin_As_Form::do_checkbox( array( 'name' => 'role-defaults-bulk-users-select[]', 'id' => $root . '-bulk-users-select-' . $user->ID, 'checkbox_value' => $user->ID . '|' . $role, @@ -1207,7 +1271,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { if ( $users ) { /** - * Apply defaults to users + * @since 1.4 Apply defaults to users */ $admin_bar->add_group( array( 'id' => $root . '-bulk-users', @@ -1219,7 +1283,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-bulk-users-title', 'parent' => $root . '-bulk-users', - 'title' => VAA_View_Admin_As_Admin_Bar::do_icon( 'dashicons-admin-users' ) + 'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-admin-users' ) . __( 'Apply defaults to users', VIEW_ADMIN_AS_DOMAIN ), 'href' => false, 'meta' => array( @@ -1230,7 +1294,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-bulk-users-filter', 'parent' => $root . '-bulk-users', - 'title' => VAA_View_Admin_As_Admin_Bar::do_input( array( + 'title' => VAA_View_Admin_As_Form::do_input( array( 'name' => $root . '-bulk-users-filter', 'placeholder' => esc_attr__( 'Filter', VIEW_ADMIN_AS_DOMAIN ) . ' (' . strtolower( __( 'Username' ) ) . ')', ) ), @@ -1251,10 +1315,19 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( '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_DOMAIN ), - 'class' => 'button-primary', + 'title' => VAA_View_Admin_As_Form::do_button( array( + 'name' => $root . '-bulk-users-apply', + 'label' => __( 'Apply', VIEW_ADMIN_AS_DOMAIN ), + 'class' => 'button-primary', + 'auto-js' => array( + 'setting' => $this->moduleKey, + 'key' => 'apply_defaults_to_users', + 'refresh' => false, + 'value' => array( + 'element' => '#wp-admin-bar-' . $root . '-bulk-users-select .ab-item.vaa-item input', + 'parser' => 'selected', + ), + ), ) ), 'href' => false, 'meta' => array( @@ -1266,7 +1339,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { if ( $roles ) { /** - * Apply defaults to all users for a role + * @since 1.4 Apply defaults to all users for a role */ $admin_bar->add_group( array( 'id' => $root . '-bulk-roles', @@ -1278,7 +1351,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-bulk-roles-title', 'parent' => $root . '-bulk-roles', - 'title' => VAA_View_Admin_As_Admin_Bar::do_icon( 'dashicons-groups' ) + 'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-groups' ) . __( 'Apply defaults to users by role', VIEW_ADMIN_AS_DOMAIN ), 'href' => false, 'meta' => array( @@ -1289,7 +1362,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-bulk-roles-select', 'parent' => $root . '-bulk-roles', - 'title' => VAA_View_Admin_As_Admin_Bar::do_select( array( + 'title' => VAA_View_Admin_As_Form::do_select( array( 'name' => $root . '-bulk-roles-select', 'values' => $role_select_options, ) ), @@ -1301,10 +1374,19 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( '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_DOMAIN ), - 'class' => 'button-primary', + 'title' => VAA_View_Admin_As_Form::do_button( array( + 'name' => $root . '-bulk-roles-apply', + 'label' => __( 'Apply', VIEW_ADMIN_AS_DOMAIN ), + 'class' => 'button-primary', + 'auto-js' => array( + 'setting' => $this->moduleKey, + 'key' => 'apply_defaults_to_users_by_role', + 'refresh' => false, + 'value' => array( + 'element' => '#wp-admin-bar-' . $root . '-bulk-roles-select select#' . $root . '-bulk-roles-select', + 'parser' => '', // Default. + ), + ), ) ), 'href' => false, 'meta' => array( @@ -1319,13 +1401,13 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { */ if ( $roles ) { - /* - * Copy actions. + /** + * @since 1.7 Copy actions. */ $role_copy_options = $role_select_options; $role_copy_options['']['label'] = '- ' . __( 'Select role source', VIEW_ADMIN_AS_DOMAIN ) . ' -'; - // Remove 'all' option from copy list. - unset( $role_copy_options['all'] ); + // Remove '__all__' option from copy list. + unset( $role_copy_options['__all__'] ); $admin_bar->add_group( array( 'id' => $root . '-copy', @@ -1337,18 +1419,18 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-copy-roles', 'parent' => $root . '-copy', - 'title' => VAA_View_Admin_As_Admin_Bar::do_icon( 'dashicons-pressthis' ) + 'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-pressthis' ) . __( 'Copy defaults to role', VIEW_ADMIN_AS_DOMAIN ), 'href' => false, 'meta' => array( - 'class' => 'ab-bold vaa-has-icon ab-vaa-toggle', + 'class' => 'ab-bold vaa-has-icon ab-vaa-toggle', 'tabindex' => '0', ), ) ); $admin_bar->add_node( array( 'id' => $root . '-copy-roles-from', 'parent' => $root . '-copy', - 'title' => VAA_View_Admin_As_Admin_Bar::do_select( array( + 'title' => VAA_View_Admin_As_Form::do_select( array( 'name' => $root . '-copy-roles-from', 'values' => $role_copy_options, ) ), @@ -1366,45 +1448,67 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { 'class' => 'ab-vaa-multipleselect vaa-small', ), ) ); + + $auto_js = array( + 'setting' => $this->moduleKey, + 'key' => 'copy_role_defaults', + 'refresh' => false, + 'values' => array( + 'from' => array( + 'element' => '#wp-admin-bar-' . $root . '-copy-roles-from select#' . $root . '-copy-roles-from', + 'parser' => '', // Default. + ), + 'to' => array( + 'element' => '#wp-admin-bar-' . $root . '-copy-roles-to .ab-item.vaa-item input', + 'parser' => 'selected', + ), + 'method' => array( + 'attr' => 'vaa-method', + ), + ), + ); $admin_bar->add_node( array( 'id' => $root . '-copy-roles-copy', 'parent' => $root . '-copy', - 'title' => VAA_View_Admin_As_Admin_Bar::do_button( array( + 'title' => VAA_View_Admin_As_Form::do_button( array( 'name' => $root . '-copy-roles-copy', 'label' => __( 'Copy', VIEW_ADMIN_AS_DOMAIN ), 'class' => 'button-secondary ab-vaa-showhide vaa-copy-role-defaults', 'attr' => array( - 'data-method' => 'copy', - 'data-showhide' => 'p.vaa-copy-role-defaults-desc', + 'vaa-method' => 'copy', + 'vaa-showhide' => 'p.vaa-copy-role-defaults-desc', ), + 'auto-js' => $auto_js, ) ) . ' ' - . VAA_View_Admin_As_Admin_Bar::do_button( array( - 'name' => $root . '-copy-roles-copy-overwrite', - 'label' => __( 'Overwrite', VIEW_ADMIN_AS_DOMAIN ), + . VAA_View_Admin_As_Form::do_button( array( + 'name' => $root . '-copy-roles-copy-merge', + 'label' => __( 'Merge', VIEW_ADMIN_AS_DOMAIN ), 'class' => 'button-secondary ab-vaa-showhide vaa-copy-role-defaults', 'attr' => array( - 'data-method' => 'overwrite', - 'data-showhide' => 'p.vaa-copy-role-defaults-overwrite-desc', + 'vaa-method' => 'merge', + 'vaa-showhide' => 'p.vaa-copy-role-defaults-merge-desc', ), + 'auto-js' => $auto_js, ) ) . ' ' - . VAA_View_Admin_As_Admin_Bar::do_button( array( + . VAA_View_Admin_As_Form::do_button( array( 'name' => $root . '-copy-roles-copy-append', 'label' => __( 'Append', VIEW_ADMIN_AS_DOMAIN ), 'class' => 'button-secondary ab-vaa-showhide vaa-copy-role-defaults', 'attr' => array( - 'data-method' => 'append', - 'data-showhide' => 'p.vaa-copy-role-defaults-append-desc', + 'vaa-method' => 'append', + 'vaa-showhide' => 'p.vaa-copy-role-defaults-append-desc', ), + 'auto-js' => $auto_js, ) ) - . VAA_View_Admin_As_Admin_Bar::do_description( + . VAA_View_Admin_As_Form::do_description( __( 'Fully overwrite data', VIEW_ADMIN_AS_DOMAIN ), array( 'class' => 'vaa-copy-role-defaults-desc' ) ) - . VAA_View_Admin_As_Admin_Bar::do_description( - __( 'Overwrite and keep existing data that is not overwritten', VIEW_ADMIN_AS_DOMAIN ), - array( 'class' => 'vaa-copy-role-defaults-overwrite-desc' ) + . VAA_View_Admin_As_Form::do_description( + __( 'Merge and overwrite existing data', VIEW_ADMIN_AS_DOMAIN ), + array( 'class' => 'vaa-copy-role-defaults-merge-desc' ) ) - . VAA_View_Admin_As_Admin_Bar::do_description( + . VAA_View_Admin_As_Form::do_description( __( 'Append without overwriting the existing data', VIEW_ADMIN_AS_DOMAIN ), array( 'class' => 'vaa-copy-role-defaults-append-desc' ) ), @@ -1414,8 +1518,8 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { ), ) ); - /* - * Export actions. + /** + * @since 1.5 Export actions. */ $admin_bar->add_group( array( 'id' => $root . '-export', @@ -1427,7 +1531,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-export-roles', 'parent' => $root . '-export', - 'title' => VAA_View_Admin_As_Admin_Bar::do_icon( 'dashicons-upload' ) + 'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-upload' ) . __( 'Export defaults for role', VIEW_ADMIN_AS_DOMAIN ), 'href' => false, 'meta' => array( @@ -1438,7 +1542,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-export-roles-select', 'parent' => $root . '-export', - 'title' => VAA_View_Admin_As_Admin_Bar::do_select( array( + 'title' => VAA_View_Admin_As_Form::do_select( array( 'name' => $root . '-export-roles-select', 'values' => $role_select_options, ) ), @@ -1450,10 +1554,19 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( '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_DOMAIN ), - 'class' => 'button-secondary', + 'title' => VAA_View_Admin_As_Form::do_button( array( + 'name' => $root . '-export-roles-export', + 'label' => __( 'Export', VIEW_ADMIN_AS_DOMAIN ), + 'class' => 'button-secondary', + 'auto-js' => array( + 'setting' => $this->moduleKey, + 'key' => 'export_role_defaults', + 'refresh' => false, + 'value' => array( + 'element' => '#wp-admin-bar-' . $root . '-export-roles-select select#' . $root . '-export-roles-select', + 'parser' => '', // Default. + ), + ), ) ), 'href' => false, 'meta' => array( @@ -1461,8 +1574,8 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { ), ) ); - /* - * Import actions. + /** + * @since 1.5 Import actions. */ $admin_bar->add_group( array( 'id' => $root . '-import', @@ -1474,7 +1587,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-import-roles', 'parent' => $root . '-import', - 'title' => VAA_View_Admin_As_Admin_Bar::do_icon( 'dashicons-download' ) + 'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-download' ) . __( 'Import defaults for role', VIEW_ADMIN_AS_DOMAIN ), 'href' => false, 'meta' => array( @@ -1492,45 +1605,64 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { 'class' => 'ab-vaa-textarea input-role', // vaa-column-one-half vaa-column-last . ), ) ); + + $auto_js = array( + 'setting' => $this->moduleKey, + 'key' => 'import_role_defaults', + 'refresh' => false, + 'values' => array( + 'data' => array( + 'element' => '#wp-admin-bar-' . $root . '-import-roles-input textarea#' . $root . '-import-roles-input', + 'parser' => '', // Default. + 'json' => true, + ), + 'method' => array( + 'attr' => 'vaa-method', + ), + ), + ); $admin_bar->add_node( array( 'id' => $root . '-import-roles-import', 'parent' => $root . '-import', - 'title' => VAA_View_Admin_As_Admin_Bar::do_button( array( + 'title' => VAA_View_Admin_As_Form::do_button( array( 'name' => $root . '-import-roles-import', 'label' => __( 'Import', VIEW_ADMIN_AS_DOMAIN ), 'class' => 'button-secondary ab-vaa-showhide vaa-import-role-defaults', 'attr' => array( - 'data-method' => 'import', - 'data-showhide' => 'p.vaa-import-role-defaults-desc', + 'vaa-method' => 'import', + 'vaa-showhide' => 'p.vaa-import-role-defaults-desc', ), + 'auto-js' => $auto_js, ) ) . ' ' - . VAA_View_Admin_As_Admin_Bar::do_button( array( - 'name' => $root . '-import-roles-import-overwrite', - 'label' => __( 'Overwrite', VIEW_ADMIN_AS_DOMAIN ), + . VAA_View_Admin_As_Form::do_button( array( + 'name' => $root . '-import-roles-import-merge', + 'label' => __( 'Merge', VIEW_ADMIN_AS_DOMAIN ), 'class' => 'button-secondary ab-vaa-showhide vaa-import-role-defaults', 'attr' => array( - 'data-method' => 'overwrite', - 'data-showhide' => 'p.vaa-import-role-defaults-overwrite-desc', + 'vaa-method' => 'merge', + 'vaa-showhide' => 'p.vaa-import-role-defaults-merge-desc', ), + 'auto-js' => $auto_js, ) ) . ' ' - . VAA_View_Admin_As_Admin_Bar::do_button( array( + . VAA_View_Admin_As_Form::do_button( array( 'name' => $root . '-import-roles-import-append', 'label' => __( 'Append', VIEW_ADMIN_AS_DOMAIN ), 'class' => 'button-secondary ab-vaa-showhide vaa-import-role-defaults', 'attr' => array( - 'data-method' => 'append', - 'data-showhide' => 'p.vaa-import-role-defaults-append-desc', + 'vaa-method' => 'append', + 'vaa-showhide' => 'p.vaa-import-role-defaults-append-desc', ), + 'auto-js' => $auto_js, ) ) - . VAA_View_Admin_As_Admin_Bar::do_description( + . VAA_View_Admin_As_Form::do_description( __( 'Fully overwrite data', VIEW_ADMIN_AS_DOMAIN ), array( 'class' => 'vaa-import-role-defaults-desc' ) ) - . VAA_View_Admin_As_Admin_Bar::do_description( - __( 'Overwrite and keep existing data that is not overwritten', VIEW_ADMIN_AS_DOMAIN ), - array( 'class' => 'vaa-import-role-defaults-overwrite-desc' ) + . VAA_View_Admin_As_Form::do_description( + __( 'Merge and overwrite existing data', VIEW_ADMIN_AS_DOMAIN ), + array( 'class' => 'vaa-import-role-defaults-merge-desc' ) ) - . VAA_View_Admin_As_Admin_Bar::do_description( + . VAA_View_Admin_As_Form::do_description( __( 'Append without overwriting the existing data', VIEW_ADMIN_AS_DOMAIN ), array( 'class' => 'vaa-import-role-defaults-append-desc' ) ), @@ -1542,8 +1674,8 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { } // End if(). - /* - * Clear actions + /** + * @since 1.4 Clear actions */ /** @@ -1558,7 +1690,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { 'label' => ' --- ', ), array( - 'value' => 'all', + 'value' => '__all__', 'label' => ' - ' . __( 'All roles', VIEW_ADMIN_AS_DOMAIN ) . ' - ', ), ); @@ -1584,7 +1716,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-clear-roles', 'parent' => $root . '-clear', - 'title' => VAA_View_Admin_As_Admin_Bar::do_icon( 'dashicons-trash' ) + 'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-trash' ) . __( 'Remove defaults for role', VIEW_ADMIN_AS_DOMAIN ), 'href' => false, 'meta' => array( @@ -1595,8 +1727,8 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-clear-roles-select', 'parent' => $root . '-clear', - 'title' => VAA_View_Admin_As_Admin_Bar::do_select( array( - 'name' => $root . '-clear-roles-select', + 'title' => VAA_View_Admin_As_Form::do_select( array( + 'name' => $root . '-clear-roles-select', 'values' => $role_clear_options, ) ), 'href' => false, @@ -1607,10 +1739,20 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( '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_DOMAIN ), - 'class' => 'button-secondary', + 'title' => VAA_View_Admin_As_Form::do_button( array( + 'name' => $root . '-clear-roles-apply', + 'label' => __( 'Apply', VIEW_ADMIN_AS_DOMAIN ), + 'class' => 'button-secondary', + 'auto-js' => array( + 'setting' => $this->moduleKey, + 'key' => 'clear_role_defaults', + 'confirm' => true, + 'refresh' => false, + 'value' => array( + 'element' => '#wp-admin-bar-' . $root . '-clear-roles-select select#' . $root . '-clear-roles-select', + 'parser' => '', // Default. + ), + ), ) ), 'href' => false, 'meta' => array( diff --git a/modules/class-role-manager.php b/modules/class-role-manager.php index 4b99c138..22fe883a 100644 --- a/modules/class-role-manager.php +++ b/modules/class-role-manager.php @@ -16,7 +16,7 @@ * @author Jory Hogeveen * @package View_Admin_As * @since 1.7 - * @version 1.7.1 + * @version 1.7.2 * @uses VAA_View_Admin_As_Module Extends class */ final class VAA_View_Admin_As_Role_Manager extends VAA_View_Admin_As_Module @@ -30,6 +30,14 @@ final class VAA_View_Admin_As_Role_Manager extends VAA_View_Admin_As_Module */ private static $_instance = null; + /** + * Module key. + * + * @since 1.7.2 + * @var string + */ + protected $moduleKey = 'role_manager'; + /** * Option key. * @@ -78,7 +86,7 @@ protected function __construct( $vaa ) { // Add this class to the modules in the main class. $this->vaa->register_module( array( - 'id' => 'role_manager', + 'id' => $this->moduleKey, 'instance' => self::$_instance, ) ); @@ -96,7 +104,7 @@ protected function __construct( $vaa ) { } add_action( 'vaa_view_admin_as_init', array( $this, 'vaa_init' ) ); - add_filter( 'view_admin_as_handle_ajax_role_manager', array( $this, 'ajax_handler' ), 10, 2 ); + add_filter( 'view_admin_as_handle_ajax_' . $this->moduleKey, array( $this, 'ajax_handler' ), 10, 2 ); } /** @@ -271,9 +279,16 @@ public function save_role( $role, $capabilities ) { // @see wp-includes/capabilities.php $existing_role = get_role( $role ); // Build role name. (Only used for adding a new role). - $role_name = ucfirst( strip_tags( $role ) ); - // Sanitize capabilities. - $capabilities = array_map( 'boolval', $capabilities ); + $role_name = self::sanitize_role_name( $role ); + /** + * Sanitize capabilities. + * @since 1.7 + * @since 1.7.2 Use foreach loop. boolval() is PHP 5.5+. + * @example $capabilities = array_map( 'boolval', $capabilities ); + */ + foreach ( $capabilities as $cap => $grant ) { + $capabilities[ $cap ] = (bool) $grant; + } if ( ! $existing_role ) { // Sanitize role slug/key. @@ -365,7 +380,7 @@ public function rename_role( $role, $new_name ) { $role = $this->store->get_roles( $role ); if ( $role ) { // @todo Check https://core.trac.wordpress.org/ticket/40320. - $new_name = ucfirst( strip_tags( $new_name ) ); + $new_name = self::sanitize_role_name( $new_name ); $this->wp_roles->role_objects[ $slug ]->name = $new_name; $this->wp_roles->role_names[ $slug ] = $new_name; @@ -397,6 +412,25 @@ public function delete_role( $role ) { return __( 'Role not found', VIEW_ADMIN_AS_DOMAIN ); } + /** + * Convert role slug into a role name. + * Formats the name by default (capitalize and convert underscores to spaces). + * + * @since 1.7.2 + * @access public + * @param string $role_name The role ID/slug. + * @param bool $format Apply string formatting. + * @return string + */ + public static function sanitize_role_name( $role_name, $format = true ) { + $role_name = strip_tags( $role_name ); + if ( $format ) { + $role_name = str_replace( array( '_' ), ' ', $role_name ); + $role_name = ucwords( $role_name ); + } + return trim( $role_name ); + } + /** * Convert role name/label into a role slug. * Similar to sanitize_key but it converts spaces and dashed to underscores. @@ -431,12 +465,17 @@ public function admin_bar_menu_modules( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root_prefix . '-enable', 'parent' => $root, - 'title' => VAA_View_Admin_As_Admin_Bar::do_checkbox( array( + 'title' => VAA_View_Admin_As_Form::do_checkbox( array( 'name' => $root_prefix . '-enable', 'value' => $this->get_optionData( 'enable' ), 'compare' => true, 'label' => __( 'Enable role manager', VIEW_ADMIN_AS_DOMAIN ), 'description' => __( 'Add or remove roles and grant or deny them capabilities', VIEW_ADMIN_AS_DOMAIN ), + 'auto-js' => array( + 'setting' => $this->moduleKey, + 'key' => 'enable', + 'refresh' => true, + ), ) ), 'href' => false, 'meta' => array( @@ -462,7 +501,7 @@ public function admin_bar_menu( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-role-manager', 'parent' => $root, - 'title' => VAA_View_Admin_As_Admin_Bar::do_icon( 'dashicons-id-alt' ) . __( 'Role manager', VIEW_ADMIN_AS_DOMAIN ), + 'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-id-alt' ) . __( 'Role manager', VIEW_ADMIN_AS_DOMAIN ), 'href' => false, 'meta' => array( 'class' => 'vaa-has-icon', @@ -527,8 +566,8 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { ); } - /* - * Apply current view capabilities to role. + /** + * @since 1.7 Apply current view capabilities to role. */ $icon = 'dashicons-hidden'; if ( $this->store->get_view() ) { @@ -544,7 +583,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-apply-view-title', 'parent' => $root . '-apply-view', - 'title' => VAA_View_Admin_As_Admin_Bar::do_icon( $icon ) . __( 'Apply current view capabilities to role', VIEW_ADMIN_AS_DOMAIN ), + 'title' => VAA_View_Admin_As_Form::do_icon( $icon ) . __( 'Apply current view capabilities to role', VIEW_ADMIN_AS_DOMAIN ), 'href' => false, 'meta' => array( 'class' => 'ab-bold vaa-has-icon ab-vaa-toggle', @@ -556,7 +595,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-apply-view-select', 'parent' => $root . '-apply-view', - 'title' => VAA_View_Admin_As_Admin_Bar::do_select( + 'title' => VAA_View_Admin_As_Form::do_select( array( 'name' => $root . '-apply-view-select', 'values' => $role_select_options, @@ -564,18 +603,34 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { ), 'href' => false, 'meta' => array( - 'class' => 'ab-vaa-select select-role', + 'class' => 'ab-vaa-select select-role', ), ) ); + // @todo Find a way to get the current view server-side (view capabilities aren't available yet in ajax handling). $admin_bar->add_node( array( 'id' => $root . '-apply-view-apply', 'parent' => $root . '-apply-view', - 'title' => VAA_View_Admin_As_Admin_Bar::do_button( array( + 'title' => VAA_View_Admin_As_Form::do_button( array( 'name' => $root . '-apply-view-apply', 'label' => __( 'Apply', VIEW_ADMIN_AS_DOMAIN ), 'class' => 'button-primary', 'attr' => array( - 'data-view-caps' => wp_json_encode( $this->store->get_selectedCaps() ), + 'vaa-view-caps' => wp_json_encode( $this->store->get_selectedCaps() ), + ), + 'auto-js' => array( + 'setting' => $this->moduleKey, + 'key' => 'apply_view_to_role', + 'refresh' => false, + 'values' => array( + 'role' => array( + 'element' => '#wp-admin-bar-' . $root . '-apply-view-select select#' . $root . '-apply-view-select', + 'parser' => '', // Default. + ), + 'capabilities' => array( + 'attr' => 'vaa-view-caps', + 'json' => true, + ), + ), ), ) ), 'href' => false, @@ -592,8 +647,8 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { ) ); } // End if(). - /* - * Rename role. + /** + * @since 1.7.1 Rename role. */ $admin_bar->add_group( array( 'id' => $root . '-rename', @@ -605,7 +660,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-rename-title', 'parent' => $root . '-rename', - 'title' => VAA_View_Admin_As_Admin_Bar::do_icon( 'dashicons-edit' ) . __( 'Rename role', VIEW_ADMIN_AS_DOMAIN ), + 'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-edit' ) . __( 'Rename role', VIEW_ADMIN_AS_DOMAIN ), 'href' => false, 'meta' => array( 'class' => 'ab-bold vaa-has-icon ab-vaa-toggle', @@ -615,7 +670,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-rename-select', 'parent' => $root . '-rename', - 'title' => VAA_View_Admin_As_Admin_Bar::do_select( + 'title' => VAA_View_Admin_As_Form::do_select( array( 'name' => $root . '-rename-select', 'values' => $role_select_options, @@ -623,39 +678,54 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { ), 'href' => false, 'meta' => array( - 'class' => 'ab-vaa-select select-role', + 'class' => 'ab-vaa-select select-role', ), ) ); $admin_bar->add_node( array( 'id' => $root . '-rename-input', 'parent' => $root . '-rename', - 'title' => VAA_View_Admin_As_Admin_Bar::do_input( + 'title' => VAA_View_Admin_As_Form::do_input( array( - 'name' => $root . '-rename-input', + 'name' => $root . '-rename-input', 'placeholder' => __( 'New role name', VIEW_ADMIN_AS_DOMAIN ), ) ), 'href' => false, 'meta' => array( - 'class' => 'ab-vaa-input rename-role', + 'class' => 'ab-vaa-input rename-role', ), ) ); $admin_bar->add_node( array( 'id' => $root . '-rename-apply', 'parent' => $root . '-rename', - 'title' => VAA_View_Admin_As_Admin_Bar::do_button( array( - 'name' => $root . '-rename-apply', - 'label' => __( 'Apply', VIEW_ADMIN_AS_DOMAIN ), - 'class' => 'button-primary', + 'title' => VAA_View_Admin_As_Form::do_button( array( + 'name' => $root . '-rename-apply', + 'label' => __( 'Apply', VIEW_ADMIN_AS_DOMAIN ), + 'class' => 'button-primary', + 'auto-js' => array( + 'setting' => $this->moduleKey, + 'key' => 'rename_role', + 'refresh' => true, + 'values' => array( + 'role' => array( + 'element' => '#wp-admin-bar-' . $root . '-rename-select select#' . $root . '-rename-select', + 'parser' => '', // Default. + ), + 'new_name' => array( + 'element' => '#wp-admin-bar-' . $root . '-rename-input input#' . $root . '-rename-input', + 'parser' => '', + ), + ), + ), ) ), 'href' => false, - 'meta' => array( + 'meta' => array( 'class' => 'vaa-button-container', ), ) ); - /* - * Clone role. + /** + * @since 1.7 Clone role. */ $admin_bar->add_group( array( 'id' => $root . '-clone', @@ -667,7 +737,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-clone-title', 'parent' => $root . '-clone', - 'title' => VAA_View_Admin_As_Admin_Bar::do_icon( 'dashicons-pressthis' ) . __( 'Clone role', VIEW_ADMIN_AS_DOMAIN ), + 'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-pressthis' ) . __( 'Clone role', VIEW_ADMIN_AS_DOMAIN ), 'href' => false, 'meta' => array( 'class' => 'ab-bold vaa-has-icon ab-vaa-toggle', @@ -677,7 +747,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-clone-select', 'parent' => $root . '-clone', - 'title' => VAA_View_Admin_As_Admin_Bar::do_select( + 'title' => VAA_View_Admin_As_Form::do_select( array( 'name' => $root . '-clone-select', 'values' => $role_select_options, @@ -685,30 +755,45 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { ), 'href' => false, 'meta' => array( - 'class' => 'ab-vaa-select select-role', + 'class' => 'ab-vaa-select select-role', ), ) ); $admin_bar->add_node( array( 'id' => $root . '-clone-input', 'parent' => $root . '-clone', - 'title' => VAA_View_Admin_As_Admin_Bar::do_input( + 'title' => VAA_View_Admin_As_Form::do_input( array( - 'name' => $root . '-clone-input', + 'name' => $root . '-clone-input', 'placeholder' => __( 'New role name', VIEW_ADMIN_AS_DOMAIN ), ) ), 'href' => false, 'meta' => array( - 'class' => 'ab-vaa-input clone-role', + 'class' => 'ab-vaa-input clone-role', ), ) ); $admin_bar->add_node( array( 'id' => $root . '-clone-apply', 'parent' => $root . '-clone', - 'title' => VAA_View_Admin_As_Admin_Bar::do_button( array( - 'name' => $root . '-clone-apply', - 'label' => __( 'Apply', VIEW_ADMIN_AS_DOMAIN ), - 'class' => 'button-primary', + 'title' => VAA_View_Admin_As_Form::do_button( array( + 'name' => $root . '-clone-apply', + 'label' => __( 'Apply', VIEW_ADMIN_AS_DOMAIN ), + 'class' => 'button-primary', + 'auto-js' => array( + 'setting' => $this->moduleKey, + 'key' => 'clone_role', + 'refresh' => true, + 'values' => array( + 'role' => array( + 'element' => '#wp-admin-bar-' . $root . '-clone-select select#' . $root . '-clone-select', + 'parser' => '', // Default. + ), + 'new_role' => array( + 'element' => '#wp-admin-bar-' . $root . '-clone-input input#' . $root . '-clone-input', + 'parser' => '', + ), + ), + ), ) ), 'href' => false, 'meta' => array( @@ -716,8 +801,8 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { ), ) ); - /* - * Delete role. + /** + * @since 1.7 Delete role. */ $role_select_options = array_diff_key( $role_select_options, $this->protected_roles ); $admin_bar->add_group( array( @@ -730,7 +815,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-delete-title', 'parent' => $root . '-delete', - 'title' => VAA_View_Admin_As_Admin_Bar::do_icon( 'dashicons-trash' ) . __( 'Delete role', VIEW_ADMIN_AS_DOMAIN ), + 'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-trash' ) . __( 'Delete role', VIEW_ADMIN_AS_DOMAIN ), 'href' => false, 'meta' => array( 'class' => 'ab-bold vaa-has-icon ab-vaa-toggle', @@ -740,7 +825,7 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-delete-select', 'parent' => $root . '-delete', - 'title' => VAA_View_Admin_As_Admin_Bar::do_select( + 'title' => VAA_View_Admin_As_Form::do_select( array( 'name' => $root . '-delete-select', 'values' => $role_select_options, @@ -748,16 +833,26 @@ private function admin_bar_menu_bulk_actions( $admin_bar, $root ) { ), 'href' => false, 'meta' => array( - 'class' => 'ab-vaa-select select-role', + 'class' => 'ab-vaa-select select-role', ), ) ); $admin_bar->add_node( array( 'id' => $root . '-delete-apply', 'parent' => $root . '-delete', - 'title' => VAA_View_Admin_As_Admin_Bar::do_button( array( - 'name' => $root . '-delete-apply', - 'label' => __( 'Delete', VIEW_ADMIN_AS_DOMAIN ), - 'class' => 'button-primary', + 'title' => VAA_View_Admin_As_Form::do_button( array( + 'name' => $root . '-delete-apply', + 'label' => __( 'Delete', VIEW_ADMIN_AS_DOMAIN ), + 'class' => 'button-primary', + 'auto-js' => array( + 'setting' => $this->moduleKey, + 'key' => 'delete_role', + 'confirm' => true, + 'refresh' => true, + 'value' => array( + 'element' => '#wp-admin-bar-' . $root . '-delete-select select#' . $root . '-delete-select', + 'parser' => '', // Default. + ), + ), ) ), 'href' => false, 'meta' => array( @@ -798,7 +893,7 @@ public function admin_bar_menu_caps( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-roles-title', 'parent' => $root, - 'title' => VAA_View_Admin_As_Admin_Bar::do_icon( 'dashicons-id-alt' ) . __( 'Role manager', VIEW_ADMIN_AS_DOMAIN ), + 'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-id-alt' ) . __( 'Role manager', VIEW_ADMIN_AS_DOMAIN ), 'href' => false, 'meta' => array( 'class' => 'ab-bold vaa-has-icon ab-vaa-toggle', @@ -836,16 +931,16 @@ public function admin_bar_menu_caps( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-edit-role', 'parent' => $root, - 'title' => VAA_View_Admin_As_Admin_Bar::do_select( + 'title' => VAA_View_Admin_As_Form::do_select( array( 'name' => $root . '-edit-role', 'values' => $role_select_options, ) - ) . VAA_View_Admin_As_Admin_Bar::do_button( + ) . VAA_View_Admin_As_Form::do_button( array( 'name' => $root . '-save-role', 'label' => __( 'Save role', VIEW_ADMIN_AS_DOMAIN ), - 'class' => 'button-primary input-overlay', + 'class' => 'button-primary input-overlay', ) ), 'href' => false, @@ -857,14 +952,14 @@ public function admin_bar_menu_caps( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-new-role', 'parent' => $root, - 'title' => VAA_View_Admin_As_Admin_Bar::do_input( + 'title' => VAA_View_Admin_As_Form::do_input( array( 'name' => $root . '-new-role', 'placeholder' => __( 'New role name', VIEW_ADMIN_AS_DOMAIN ), 'class' => 'ab-vaa-conditional', 'attr' => array( - 'data-condition' => '__new__', - 'data-condition-target' => '#' . $root . '-edit-role', + 'vaa-condition' => '__new__', + 'vaa-condition-target' => '#' . $root . '-edit-role', ), ) ), @@ -877,16 +972,16 @@ public function admin_bar_menu_caps( $admin_bar, $root ) { $admin_bar->add_node( array( 'id' => $root . '-new-cap', 'parent' => $root, - 'title' => VAA_View_Admin_As_Admin_Bar::do_input( array( + 'title' => VAA_View_Admin_As_Form::do_input( array( 'name' => $root . '-new-cap', 'placeholder' => esc_attr__( 'Add new capability', VIEW_ADMIN_AS_DOMAIN ), - ) ) . VAA_View_Admin_As_Admin_Bar::do_button( array( + ) ) . VAA_View_Admin_As_Form::do_button( array( 'name' => $root . '-add-cap', 'label' => __( 'Add', VIEW_ADMIN_AS_DOMAIN ), 'class' => 'button-primary input-overlay', ) ) . '