diff --git a/assets/js/view-admin-as.js b/assets/js/view-admin-as.js index 3e2329fc..a3220f16 100644 --- a/assets/js/view-admin-as.js +++ b/assets/js/view-admin-as.js @@ -244,7 +244,7 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) { // @since 1.8.2 Enhance height calc + provide trigger for content changes $( '.vaa-resizable', $vaa ).each( function() { var $this = $(this), - maxHeight = parseInt( $this.css( 'max-heights' ), 10 ), + maxHeight = parseInt( $this.css( 'max-height' ), 10 ), height, innerHeight, newHeight; // Check for empty containers. diff --git a/assets/js/view-admin-as.min.js b/assets/js/view-admin-as.min.js index e57df90c..be3264f9 100644 --- a/assets/js/view-admin-as.min.js +++ b/assets/js/view-admin-as.min.js @@ -8,4 +8,4 @@ * @version 1.8.2 * @preserve */ -if("undefined"===typeof VAA_View_Admin_As){var VAA_View_Admin_As={}}(function($){VAA_View_Admin_As.prefix="#wpadminbar #wp-admin-bar-vaa ";VAA_View_Admin_As.root="#wp-admin-bar-vaa";var $document=$(document),$window=$(window),$body=$("body"),$vaa=$(VAA_View_Admin_As.prefix);VAA_View_Admin_As.maxHeightListenerElements=null;VAA_View_Admin_As._mobile=false;if(!VAA_View_Admin_As.hasOwnProperty("_debug")){VAA_View_Admin_As._debug=false}if(!VAA_View_Admin_As.hasOwnProperty("ajaxurl")){if("undefined"===typeof ajaxurl){var ajaxurl=window.location.origin+"/wp-admin/admin-ajax.php"}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.maybe_json_decode=function(val){if(0===val.indexOf("{")||0===val.indexOf("[")){try{val=JSON.parse(val)}catch(err){}}return val};VAA_View_Admin_As.init=function(){if(!$vaa.length){$vaa=$(VAA_View_Admin_As.prefix)}if(VAA_View_Admin_As._loader_icon){var loader_icon=new Image;loader_icon.src=VAA_View_Admin_As._loader_icon}VAA_View_Admin_As.maxHeightListenerElements=$(VAA_View_Admin_As.prefix+".vaa-auto-max-height");VAA_View_Admin_As.init_caps();VAA_View_Admin_As.init_users();VAA_View_Admin_As.init_combine_views();VAA_View_Admin_As.init_module_role_defaults();VAA_View_Admin_As.init_module_role_manager();VAA_View_Admin_As.init_auto_js();$(".ab-vaa-toggle",$vaa).each(function(){var $this=$(this),$toggle=$this.parent().children().not(".ab-vaa-toggle");if(!$this.hasClass("active")){$toggle.hide()}$this.on("click touchend",function(e){e.preventDefault();e.stopPropagation();if(true===VAA_View_Admin_As._touchmove){return}if($(this).hasClass("active")){$toggle.slideUp("fast");$(this).removeClass("active")}else{$toggle.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)){$toggle.slideUp("fast");$(this).removeClass("active")}else if(13===key||32===key||40===key){$toggle.slideDown("fast");$(this).addClass("active")}VAA_View_Admin_As.autoMaxHeight()})});$("[vaa-showhide]",$vaa).each(function(){var $this=$(this),args=VAA_View_Admin_As.maybe_json_decode($this.attr("vaa-showhide")),delay=200;if("object"!==typeof args){args={0:{target:args,delay:delay}}}$.each(args,function(key,data){var timeout=null,$target=$(data.target);if(!data.hasOwnProperty("delay")){data.delay=delay}$target.hide();$this.on("mouseenter",function(){timeout=setTimeout(function(){$target.slideDown("fast")},data.delay)}).on("mouseleave",function(){if(timeout){clearTimeout(timeout)}$target.slideUp("fast")})})});$("[vaa-condition-target]",$vaa).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}}$this.hide();$target.on("change.vaa",function(){if(checkbox&&$target.is(":checked")){if(compare){$this.slideDown("fast")}else{$this.slideUp("fast")}}else if(!checkbox&&compare===$target.val()){$this.slideDown("fast")}else{$this.slideUp("fast")}VAA_View_Admin_As.autoMaxHeight()}).trigger("change.vaa")});if($body.hasClass("mobile")||783>$body.innerWidth()){$body.addClass("vaa-mobile");VAA_View_Admin_As._mobile=true;VAA_View_Admin_As.init_touch()}VAA_View_Admin_As.maxHeightListenerElements.each(function(){$(this).parents(".menupop").on("mouseenter",VAA_View_Admin_As.autoMaxHeight)});$(".vaa-resizable",$vaa).each(function(){var $this=$(this),maxHeight=parseInt($this.css("max-heights"),10),height,innerHeight,newHeight;$this.find(".ab-empty-item:empty").remove();$this.on("vaa-resizable",function(){if($this.is(":empty")){$this.css({"max-height":"",height:"",resize:""});return}newHeight=maxHeight;height=$this.height();$this.css({"max-height":"",height:"",resize:""});if(height){$this.css({"max-height":"none"});innerHeight=$this.height();$this.css({"max-height":""});if(innerHeight=maxHeight){if(innerHeight=maxHeight)){$this.css({"max-height":"none",height:newHeight?newHeight+"px":"",resize:"vertical"})}}).trigger("vaa-resizable")});$vaa.on("click touchend",".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){$vaa.on("click touchend",".vaa-"+type+"-item > a.ab-item",function(e){e.preventDefault();if(true===VAA_View_Admin_As._touchmove){return}var $this=$(this);if(VAA_View_Admin_As._mobile){var $parent=$this.parent();if($parent.hasClass("menupop")&&!$parent.hasClass("active")){$parent.addClass("active");$this.next().show();return false}}$this.data("vaa-continue-event",true).trigger("vaa-apply-view");if(!$this.parent().hasClass("not-a-view")&&$this.data("vaa-continue-event")){var view_data={},val=$this.find(".vaa-view-data").attr("vaa-view-value");view_data[type]=VAA_View_Admin_As.maybe_json_decode(val);if("object"===typeof view_data[type]){view_data=view_data[type]}VAA_View_Admin_As.ajax(view_data,true);return false}})});$vaa.on("click touchend",".remove",function(e){e.preventDefault();if(true===VAA_View_Admin_As._touchmove){return}$(this).parent().slideUp("fast",function(){$(this).remove()})})};VAA_View_Admin_As.init_touch=function(){var $root=$(".vaa-mobile "+VAA_View_Admin_As.prefix);$root.on("click touchend"," > .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").removeClass("active")}else{$sub.slideDown("fast").addClass("active")}}});$root.on("click touchend","input, textarea, 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});$root.on("click touchend","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(false===html){$overlay.fadeOut("fast",function(){$(this).remove()});$document.off("mouseup.vaa_overlay");return}if(!$overlay.length){html='
'+html+"
";$body.append(html);$overlay=$("body #vaa-overlay")}else if(html.length){$overlay.html(html)}$overlay.fadeIn("fast");$overlay.find(".remove").click(function(){VAA_View_Admin_As.overlay(false)});$document.on("mouseup.vaa_overlay",function(e){$overlay.find(".vaa-popup").each(function(){if(!$(this).is(e.target)&&0===$(this).has(e.target).length){VAA_View_Admin_As.overlay(false);return false}})})};VAA_View_Admin_As.ajax=function(data,refresh){$(".vaa-notice","#wpadminbar").remove();var loader_icon="";if(VAA_View_Admin_As._loader_icon){loader_icon=' style="background-image: url('+VAA_View_Admin_As._loader_icon+')"'}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;VAA_View_Admin_As.debug(response);if(response.hasOwnProperty("data")){if("object"===typeof response.data){data=response.data;if(data.hasOwnProperty("display")){display=data.display}}}if(success){if("download"===refresh){VAA_View_Admin_As.download(data);VAA_View_Admin_As.overlay(false);return}else 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")&&"object"===typeof data.list){html+="
      ";$.each(data.list,function(key,value){html+="
    • "+String(value)+"
    • "});html+="
    "}if(data.hasOwnProperty("textarea")){html+='"}html+="
    ";VAA_View_Admin_As.overlay(html);var root="#vaa-overlay",$overlay=$(root),$popup=$(root+" .vaa-popup"),$popup_content=$(root+" .vaa-popup-content");var textarea=$("textarea",$popup_content);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;$popup.css("max-height",max_height);$popup_content.css("max-height",max_height)};popupMaxHeight();$window.on("resize",function(){popupMaxHeight()})};VAA_View_Admin_As.download=function(data){var content="",filename="";if("string"===typeof data){content=data}else{if(data.hasOwnProperty("download")){content=String(data.download)}else if(data.hasOwnProperty("textarea")){content=String(data.textarea)}else if(data.hasOwnProperty("content")){content=String(data.content)}}content=VAA_View_Admin_As.maybe_json_decode(content);if("object"===typeof content){content=JSON.stringify(content,null,"\t")}if(!content){return}if(data.hasOwnProperty("filename")){filename=data.filename}var link="data:application/octet-stream;charset=utf-8,"+encodeURIComponent(content);$body.append('');document.getElementById("vaa_temp_download").click();$("a#vaa_temp_download").remove()};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.maybe_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}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;if(data.hasOwnProperty("callback")){VAA_View_Admin_As[data.callback](data);return}var val=VAA_View_Admin_As.get_auto_js_values_recursive(data,elem);if(null!==val){if(!setting){return}var view_data={};view_data[setting]=val;if(data.hasOwnProperty("download")&&data.download){refresh="download"}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,$root=$(root_prefix),$search_node=$(root_prefix+" .ab-vaa-search.search-users"),ajax_delay_timer;if($search_node.length){var search_ajax=$search_node.hasClass("search-ajax"),$search_results=$search_node.find(".ab-vaa-results"),no_results='
    '+VAA_View_Admin_As.__no_users_found+"
    ";$root.on("keyup",".ab-vaa-search.search-users input",function(){var $this=$(this),search=$this.val();if(1<=search.trim().length){if(search_ajax){search={search:search,return:"links"};var search_by=$root.find(".ab-vaa-search.search-users select").val();if(search_by){search["search_by"]=search_by}VAA_View_Admin_As.search_users_ajax(search,$search_results)}else{search_users(search)}}else{VAA_View_Admin_As.search_users_ajax(null,$search_results)}})}function search_users(search){$search_results.empty();$(VAA_View_Admin_As.prefix+".vaa-user-item").each(function(){var $this=$(this),name=$this.find(".ab-item").text();if(-1 .ab-item > .vaa-view-data");role=role?role.text():"";if(role&&false!==exists&&exists.length){exists.find(".user-role").text(exists.find(".user-role").text().replace(")",", "+role+")"))}else{role=role?'  ('+role+")":"";$this.clone().appendTo($search_results).children(".ab-item").append(role)}}});if(""===$.trim($search_results.html())){$search_results.html(no_results)}VAA_View_Admin_As.autoMaxHeight()}VAA_View_Admin_As.search_users_ajax=function(search,results_container){clearTimeout(ajax_delay_timer);var $results_container=$(results_container);if(!search){$results_container.empty();if($results_container.hasClass("vaa-resizable")){$results_container.trigger("vaa-resizable")}return}ajax_delay_timer=setTimeout(function(){$results_container.html('
    . . .
    ');var $loading=$(".ab-item",$results_container),loading=". . . ",loading_interval=setInterval(function(){if(20 .ab-item"}}combine_types.push("caps");combine_selectors["caps"]=VAA_View_Admin_As.prefix+VAA_View_Admin_As.root+"-caps > .menupop > .ab-item";VAA_View_Admin_As.reinit_combine_views=function(){if(is_active){enable_combine_views()}else{add_combine_checkboxes()}$.each(selection,function(type,data){data.el=$(data.el);if(!data.el.length||!data.el.closest("body").length){data.el=$(VAA_View_Admin_As.prefix+".vaa-combine-item[vaa-view-type="+data.type+"][vaa-view-value="+data.value+"]")}if(data.el.length){data.el.prop("checked",true);activate_combine_type(data.el,data.type,data.value)}})};function enable_combine_views(){is_active=true;add_combine_checkboxes();$combine_items=$(VAA_View_Admin_As.prefix+".vaa-combine-item");$combine_items.fadeIn("fast");update_selection_list()}function disable_combine_views(){is_active=false;$(VAA_View_Admin_As.prefix+".vaa-combine-item").fadeOut("fast");if($selection_container.is(":visible")){$selection_container.slideUp("fast")}else{$selection_container.hide()}}function add_combine_checkboxes(elements,type){if(!elements||!type){for(var key in combine_selectors){if(combine_selectors.hasOwnProperty(key)){add_combine_checkboxes(combine_selectors[key],key)}}return}var $elements=$(elements);$elements.each(function(){var $this=$(this),$parent=$this.parent(),val=null,text=$this.text(),$data_el=$this.find(".vaa-view-data"),label,attr;if($parent.find(".vaa-combine-item").length){return true}if($data_el.length){val=$data_el.attr("vaa-view-value");text=$data_el.text();label=$data_el.attr("vaa-view-type-label")}if("caps"===type){val="";text=$(VAA_View_Admin_As.root+"-caps-title > .ab-item").text()}attr=['type="checkbox"','class="checkbox vaa-right vaa-combine-item vaa-combine-'+type+'"','vaa-view-type="'+type+'"',"vaa-view-value='"+val+"'",'vaa-view-text="'+text+'"','style="display:none;"'];if(label){attr.push('vaa-view-type-label="'+label+'"')}$parent.prepend("")})}function parse_combine_type(element,type){var $element=$(element),val;if("caps"===type){val=type}else{val=VAA_View_Admin_As.maybe_json_decode($element.attr("vaa-view-value"));if("object"===typeof val){$.each(val,function(val_type,data){var $val_element=$(VAA_View_Admin_As.prefix+".vaa-combine-"+val_type+"[vaa-view-value="+data+"]");activate_combine_type($val_element,val_type,data)});$element.prop({checked:true,disabled:false});return}}activate_combine_type($element,type,val)}function activate_combine_type(element,type,value){var $element=$(element);deactivate_combine_type(type,false);selection[type]={el:$element,type:type,value:value};$(VAA_View_Admin_As.prefix+".vaa-combine-"+type).prop({checked:false,disabled:true});$element.prop({checked:true,disabled:false});update_selection_list()}function deactivate_combine_type(types,update){if("object"!==typeof types){type=types;types={};types[type]=0}for(var type in types){if(types.hasOwnProperty(type)){delete selection[type];$(VAA_View_Admin_As.prefix+".vaa-combine-"+type).prop({checked:false,disabled:false})}}if(update){update_selection_list()}}function update_selection_list(){$(root_prefix+" .vaa-combine-selection").each(function(){var $this=$(this),type=$this.attr("vaa-view-type");if(!selection.hasOwnProperty(type)){$this.slideUp("fast",function(){$(this).remove()})}});$.each(selection,function(type,data){var text=data.el.attr("vaa-view-text")+'',$existing=$(root_prefix+" .vaa-combine-selection-"+type),label=data.el.attr("vaa-view-type-label");if(label){text=''+label+": "+text}if($existing.length){$existing.html(text);if("none"===$existing.css("display")||!$existing.is(":visible")){$existing.slideDown("fast")}}else{var attr=['class="ab-item ab-empty-item vaa-combine-selection vaa-combine-selection-'+type+'"','vaa-view-type="'+type+'"','style="display:none;"'];var html="
  • "+text+"
  • ";$selection_container.append(html);$(root_prefix+" .vaa-combine-selection-"+type).slideDown("fast")}});if(is_active&&!$.isEmptyObject(selection)){if("none"===$selection_container.css("display")||!$selection_container.is(":visible")){$selection_container.slideDown("fast")}}else{$selection_container.slideUp("fast")}}$root.on("change","input#"+prefix,function(){$selection_container=$($selection_container);if(true===VAA_View_Admin_As._touchmove){return}if(this.checked){enable_combine_views()}else{disable_combine_views()}});$vaa.on("change","input.vaa-combine-item",function(){if(true===VAA_View_Admin_As._touchmove){return}var $this=$(this),type=$this.attr("vaa-view-type");if(this.checked){parse_combine_type($this,type)}else{var val=VAA_View_Admin_As.maybe_json_decode($this.attr("vaa-view-value"));if("object"===typeof val){deactivate_combine_type(val,true);return}deactivate_combine_type(type,true)}});$root.on("click touchend",".vaa-combine-selection .remove",function(){if(true===VAA_View_Admin_As._touchmove){return}deactivate_combine_type($(this).parent().attr("vaa-view-type"),true)});$root.on("click touchend","button#"+prefix+"-apply",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();var view_data={};for(var type in selection){if(selection.hasOwnProperty(type)){if("caps"===type){view_data[type]=VAA_View_Admin_As.get_selected_capabilities()}else{view_data[type]=selection[type].value}}}if(!$.isEmptyObject(view_data)){VAA_View_Admin_As.ajax(view_data,true)}else{}});$.each(combine_types,function(index,type){$vaa.on("vaa-apply-view",".vaa-"+type+"-item > a.ab-item",function(e){if(!is_active){return}e.preventDefault();var $this=$(this);if(!$this.parent().hasClass("not-a-view")){if(!VAA_View_Admin_As._mobile){var $combine_item=$this.parent().children(".vaa-combine-item");if($combine_item.is(":checked")){$combine_item.prop("checked",false)}else{$combine_item.prop("checked",true)}$combine_item.trigger("change")}e.stopPropagation();e.stopImmediatePropagation();$this.data("vaa-continue-event",false);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,$root=$(root_prefix);if(!$root.length){return}$root.on("click touchend",root+"-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(),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)}});if($root.find(root+"-bulk-users-filter").length){$root.on("keyup",root+"-bulk-users-filter input#"+prefix+"-bulk-users-filter",function(e){e.preventDefault();var $items=$(root_prefix+"-bulk-users-select .ab-item.vaa-item");if(1<=$(this).val().length){var input_text=$(this).val();$items.each(function(){var name=$(".user-name",this).text();if(-1 .ab-item").prepend(item)}})};VAA_View_Admin_As.assign_file_content=function(data){if("function"!==typeof FileReader){return}var param=data.hasOwnProperty("param")?data.param:{},$target=param.hasOwnProperty("target")?$(param.target):null,$element=param.hasOwnProperty("element")?$(param.element):null,wait=true;if(!$target||!$element){return}var files=$element[0].files,length=files.length,val="";if(length){$.each(files,function(key,file){var reader=new FileReader;reader.onload=function(){var content=VAA_View_Admin_As.maybe_json_decode(this.result);if("object"===typeof content){content=JSON.stringify(content)}val+=content;length--;if(!length){wait=false}};reader.readAsText(file)})}var areWeThereYet=setInterval(function(){if(!wait){$target.val(val);clearInterval(areWeThereYet)}},100)};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$body.innerWidth()){$body.addClass("vaa-mobile");VAA_View_Admin_As._mobile=true;VAA_View_Admin_As.init_touch()}VAA_View_Admin_As.maxHeightListenerElements.each(function(){$(this).parents(".menupop").on("mouseenter",VAA_View_Admin_As.autoMaxHeight)});$(".vaa-resizable",$vaa).each(function(){var $this=$(this),maxHeight=parseInt($this.css("max-height"),10),height,innerHeight,newHeight;$this.find(".ab-empty-item:empty").remove();$this.on("vaa-resizable",function(){if($this.is(":empty")){$this.css({"max-height":"",height:"",resize:""});return}newHeight=maxHeight;height=$this.height();$this.css({"max-height":"",height:"",resize:""});if(height){$this.css({"max-height":"none"});innerHeight=$this.height();$this.css({"max-height":""});if(innerHeight=maxHeight){if(innerHeight=maxHeight)){$this.css({"max-height":"none",height:newHeight?newHeight+"px":"",resize:"vertical"})}}).trigger("vaa-resizable")});$vaa.on("click touchend",".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){$vaa.on("click touchend",".vaa-"+type+"-item > a.ab-item",function(e){e.preventDefault();if(true===VAA_View_Admin_As._touchmove){return}var $this=$(this);if(VAA_View_Admin_As._mobile){var $parent=$this.parent();if($parent.hasClass("menupop")&&!$parent.hasClass("active")){$parent.addClass("active");$this.next().show();return false}}$this.data("vaa-continue-event",true).trigger("vaa-apply-view");if(!$this.parent().hasClass("not-a-view")&&$this.data("vaa-continue-event")){var view_data={},val=$this.find(".vaa-view-data").attr("vaa-view-value");view_data[type]=VAA_View_Admin_As.maybe_json_decode(val);if("object"===typeof view_data[type]){view_data=view_data[type]}VAA_View_Admin_As.ajax(view_data,true);return false}})});$vaa.on("click touchend",".remove",function(e){e.preventDefault();if(true===VAA_View_Admin_As._touchmove){return}$(this).parent().slideUp("fast",function(){$(this).remove()})})};VAA_View_Admin_As.init_touch=function(){var $root=$(".vaa-mobile "+VAA_View_Admin_As.prefix);$root.on("click touchend"," > .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").removeClass("active")}else{$sub.slideDown("fast").addClass("active")}}});$root.on("click touchend","input, textarea, 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});$root.on("click touchend","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(false===html){$overlay.fadeOut("fast",function(){$(this).remove()});$document.off("mouseup.vaa_overlay");return}if(!$overlay.length){html='
    '+html+"
    ";$body.append(html);$overlay=$("body #vaa-overlay")}else if(html.length){$overlay.html(html)}$overlay.fadeIn("fast");$overlay.find(".remove").click(function(){VAA_View_Admin_As.overlay(false)});$document.on("mouseup.vaa_overlay",function(e){$overlay.find(".vaa-popup").each(function(){if(!$(this).is(e.target)&&0===$(this).has(e.target).length){VAA_View_Admin_As.overlay(false);return false}})})};VAA_View_Admin_As.ajax=function(data,refresh){$(".vaa-notice","#wpadminbar").remove();var loader_icon="";if(VAA_View_Admin_As._loader_icon){loader_icon=' style="background-image: url('+VAA_View_Admin_As._loader_icon+')"'}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;VAA_View_Admin_As.debug(response);if(response.hasOwnProperty("data")){if("object"===typeof response.data){data=response.data;if(data.hasOwnProperty("display")){display=data.display}}}if(success){if("download"===refresh){VAA_View_Admin_As.download(data);VAA_View_Admin_As.overlay(false);return}else 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")&&"object"===typeof data.list){html+="
      ";$.each(data.list,function(key,value){html+="
    • "+String(value)+"
    • "});html+="
    "}if(data.hasOwnProperty("textarea")){html+='"}html+="
    ";VAA_View_Admin_As.overlay(html);var root="#vaa-overlay",$overlay=$(root),$popup=$(root+" .vaa-popup"),$popup_content=$(root+" .vaa-popup-content");var textarea=$("textarea",$popup_content);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;$popup.css("max-height",max_height);$popup_content.css("max-height",max_height)};popupMaxHeight();$window.on("resize",function(){popupMaxHeight()})};VAA_View_Admin_As.download=function(data){var content="",filename="";if("string"===typeof data){content=data}else{if(data.hasOwnProperty("download")){content=String(data.download)}else if(data.hasOwnProperty("textarea")){content=String(data.textarea)}else if(data.hasOwnProperty("content")){content=String(data.content)}}content=VAA_View_Admin_As.maybe_json_decode(content);if("object"===typeof content){content=JSON.stringify(content,null,"\t")}if(!content){return}if(data.hasOwnProperty("filename")){filename=data.filename}var link="data:application/octet-stream;charset=utf-8,"+encodeURIComponent(content);$body.append('');document.getElementById("vaa_temp_download").click();$("a#vaa_temp_download").remove()};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.maybe_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}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;if(data.hasOwnProperty("callback")){VAA_View_Admin_As[data.callback](data);return}var val=VAA_View_Admin_As.get_auto_js_values_recursive(data,elem);if(null!==val){if(!setting){return}var view_data={};view_data[setting]=val;if(data.hasOwnProperty("download")&&data.download){refresh="download"}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,$root=$(root_prefix),$search_node=$(root_prefix+" .ab-vaa-search.search-users"),ajax_delay_timer;if($search_node.length){var search_ajax=$search_node.hasClass("search-ajax"),$search_results=$search_node.find(".ab-vaa-results"),no_results='
    '+VAA_View_Admin_As.__no_users_found+"
    ";$root.on("keyup",".ab-vaa-search.search-users input",function(){var $this=$(this),search=$this.val();if(1<=search.trim().length){if(search_ajax){search={search:search,return:"links"};var search_by=$root.find(".ab-vaa-search.search-users select").val();if(search_by){search["search_by"]=search_by}VAA_View_Admin_As.search_users_ajax(search,$search_results)}else{search_users(search)}}else{VAA_View_Admin_As.search_users_ajax(null,$search_results)}})}function search_users(search){$search_results.empty();$(VAA_View_Admin_As.prefix+".vaa-user-item").each(function(){var $this=$(this),name=$this.find(".ab-item").text();if(-1 .ab-item > .vaa-view-data");role=role?role.text():"";if(role&&false!==exists&&exists.length){exists.find(".user-role").text(exists.find(".user-role").text().replace(")",", "+role+")"))}else{role=role?'  ('+role+")":"";$this.clone().appendTo($search_results).children(".ab-item").append(role)}}});if(""===$.trim($search_results.html())){$search_results.html(no_results)}VAA_View_Admin_As.autoMaxHeight()}VAA_View_Admin_As.search_users_ajax=function(search,results_container){clearTimeout(ajax_delay_timer);var $results_container=$(results_container);if(!search){$results_container.empty();if($results_container.hasClass("vaa-resizable")){$results_container.trigger("vaa-resizable")}return}ajax_delay_timer=setTimeout(function(){$results_container.html('
    . . .
    ');var $loading=$(".ab-item",$results_container),loading=". . . ",loading_interval=setInterval(function(){if(20 .ab-item"}}combine_types.push("caps");combine_selectors["caps"]=VAA_View_Admin_As.prefix+VAA_View_Admin_As.root+"-caps > .menupop > .ab-item";VAA_View_Admin_As.reinit_combine_views=function(){if(is_active){enable_combine_views()}else{add_combine_checkboxes()}$.each(selection,function(type,data){data.el=$(data.el);if(!data.el.length||!data.el.closest("body").length){data.el=$(VAA_View_Admin_As.prefix+".vaa-combine-item[vaa-view-type="+data.type+"][vaa-view-value="+data.value+"]")}if(data.el.length){data.el.prop("checked",true);activate_combine_type(data.el,data.type,data.value)}})};function enable_combine_views(){is_active=true;add_combine_checkboxes();$combine_items=$(VAA_View_Admin_As.prefix+".vaa-combine-item");$combine_items.fadeIn("fast");update_selection_list()}function disable_combine_views(){is_active=false;$(VAA_View_Admin_As.prefix+".vaa-combine-item").fadeOut("fast");if($selection_container.is(":visible")){$selection_container.slideUp("fast")}else{$selection_container.hide()}}function add_combine_checkboxes(elements,type){if(!elements||!type){for(var key in combine_selectors){if(combine_selectors.hasOwnProperty(key)){add_combine_checkboxes(combine_selectors[key],key)}}return}var $elements=$(elements);$elements.each(function(){var $this=$(this),$parent=$this.parent(),val=null,text=$this.text(),$data_el=$this.find(".vaa-view-data"),label,attr;if($parent.find(".vaa-combine-item").length){return true}if($data_el.length){val=$data_el.attr("vaa-view-value");text=$data_el.text();label=$data_el.attr("vaa-view-type-label")}if("caps"===type){val="";text=$(VAA_View_Admin_As.root+"-caps-title > .ab-item").text()}attr=['type="checkbox"','class="checkbox vaa-right vaa-combine-item vaa-combine-'+type+'"','vaa-view-type="'+type+'"',"vaa-view-value='"+val+"'",'vaa-view-text="'+text+'"','style="display:none;"'];if(label){attr.push('vaa-view-type-label="'+label+'"')}$parent.prepend("")})}function parse_combine_type(element,type){var $element=$(element),val;if("caps"===type){val=type}else{val=VAA_View_Admin_As.maybe_json_decode($element.attr("vaa-view-value"));if("object"===typeof val){$.each(val,function(val_type,data){var $val_element=$(VAA_View_Admin_As.prefix+".vaa-combine-"+val_type+"[vaa-view-value="+data+"]");activate_combine_type($val_element,val_type,data)});$element.prop({checked:true,disabled:false});return}}activate_combine_type($element,type,val)}function activate_combine_type(element,type,value){var $element=$(element);deactivate_combine_type(type,false);selection[type]={el:$element,type:type,value:value};$(VAA_View_Admin_As.prefix+".vaa-combine-"+type).prop({checked:false,disabled:true});$element.prop({checked:true,disabled:false});update_selection_list()}function deactivate_combine_type(types,update){if("object"!==typeof types){type=types;types={};types[type]=0}for(var type in types){if(types.hasOwnProperty(type)){delete selection[type];$(VAA_View_Admin_As.prefix+".vaa-combine-"+type).prop({checked:false,disabled:false})}}if(update){update_selection_list()}}function update_selection_list(){$(root_prefix+" .vaa-combine-selection").each(function(){var $this=$(this),type=$this.attr("vaa-view-type");if(!selection.hasOwnProperty(type)){$this.slideUp("fast",function(){$(this).remove()})}});$.each(selection,function(type,data){var text=data.el.attr("vaa-view-text")+'',$existing=$(root_prefix+" .vaa-combine-selection-"+type),label=data.el.attr("vaa-view-type-label");if(label){text=''+label+": "+text}if($existing.length){$existing.html(text);if("none"===$existing.css("display")||!$existing.is(":visible")){$existing.slideDown("fast")}}else{var attr=['class="ab-item ab-empty-item vaa-combine-selection vaa-combine-selection-'+type+'"','vaa-view-type="'+type+'"','style="display:none;"'];var html="
  • "+text+"
  • ";$selection_container.append(html);$(root_prefix+" .vaa-combine-selection-"+type).slideDown("fast")}});if(is_active&&!$.isEmptyObject(selection)){if("none"===$selection_container.css("display")||!$selection_container.is(":visible")){$selection_container.slideDown("fast")}}else{$selection_container.slideUp("fast")}}$root.on("change","input#"+prefix,function(){$selection_container=$($selection_container);if(true===VAA_View_Admin_As._touchmove){return}if(this.checked){enable_combine_views()}else{disable_combine_views()}});$vaa.on("change","input.vaa-combine-item",function(){if(true===VAA_View_Admin_As._touchmove){return}var $this=$(this),type=$this.attr("vaa-view-type");if(this.checked){parse_combine_type($this,type)}else{var val=VAA_View_Admin_As.maybe_json_decode($this.attr("vaa-view-value"));if("object"===typeof val){deactivate_combine_type(val,true);return}deactivate_combine_type(type,true)}});$root.on("click touchend",".vaa-combine-selection .remove",function(){if(true===VAA_View_Admin_As._touchmove){return}deactivate_combine_type($(this).parent().attr("vaa-view-type"),true)});$root.on("click touchend","button#"+prefix+"-apply",function(e){if(true===VAA_View_Admin_As._touchmove){return}e.preventDefault();var view_data={};for(var type in selection){if(selection.hasOwnProperty(type)){if("caps"===type){view_data[type]=VAA_View_Admin_As.get_selected_capabilities()}else{view_data[type]=selection[type].value}}}if(!$.isEmptyObject(view_data)){VAA_View_Admin_As.ajax(view_data,true)}else{}});$.each(combine_types,function(index,type){$vaa.on("vaa-apply-view",".vaa-"+type+"-item > a.ab-item",function(e){if(!is_active){return}e.preventDefault();var $this=$(this);if(!$this.parent().hasClass("not-a-view")){if(!VAA_View_Admin_As._mobile){var $combine_item=$this.parent().children(".vaa-combine-item");if($combine_item.is(":checked")){$combine_item.prop("checked",false)}else{$combine_item.prop("checked",true)}$combine_item.trigger("change")}e.stopPropagation();e.stopImmediatePropagation();$this.data("vaa-continue-event",false);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,$root=$(root_prefix);if(!$root.length){return}$root.on("click touchend",root+"-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(),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)}});if($root.find(root+"-bulk-users-filter").length){$root.on("keyup",root+"-bulk-users-filter input#"+prefix+"-bulk-users-filter",function(e){e.preventDefault();var $items=$(root_prefix+"-bulk-users-select .ab-item.vaa-item");if(1<=$(this).val().length){var input_text=$(this).val();$items.each(function(){var name=$(".user-name",this).text();if(-1 .ab-item").prepend(item)}})};VAA_View_Admin_As.assign_file_content=function(data){if("function"!==typeof FileReader){return}var param=data.hasOwnProperty("param")?data.param:{},$target=param.hasOwnProperty("target")?$(param.target):null,$element=param.hasOwnProperty("element")?$(param.element):null,wait=true;if(!$target||!$element){return}var files=$element[0].files,length=files.length,val="";if(length){$.each(files,function(key,file){var reader=new FileReader;reader.onload=function(){var content=VAA_View_Admin_As.maybe_json_decode(this.result);if("object"===typeof content){content=JSON.stringify(content)}val+=content;length--;if(!length){wait=false}};reader.readAsText(file)})}var areWeThereYet=setInterval(function(){if(!wait){$target.val(val);clearInterval(areWeThereYet)}},100)};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")&&0store(); + if ( $store ) { + return $store->get_view( $type ); + } + return null; + } + /** * Check if the provided data is the same as the current view. * @@ -240,6 +261,30 @@ public static function is_user_modified() { return false; } + /** + * Set the current view. + * + * @see \VAA_View_Admin_As_Controller::update() + * @see \VAA_View_Admin_As_Controller::update_view() + * + * @since 1.8.3 + * @access public + * @static + * @api + * + * @param array $view The view. + * @return bool + */ + public static function update_view( $view ) { + $controller = view_admin_as()->controller(); + if ( $controller ) { + $view = array_intersect_key( $view, array_flip( $controller->get_view_types() ) ); + $success = $controller->update( $view ); + return ( true === $success ); + } + return false; + } + /** * Is any toolbar showing? * Do not use this before the `init` hook. diff --git a/includes/class-compat.php b/includes/class-compat.php index d8554ecb..5cbb8bd8 100644 --- a/includes/class-compat.php +++ b/includes/class-compat.php @@ -186,11 +186,10 @@ public function get_vaa_capabilities( $caps = array() ) { public function get_wordpress_capabilities( $caps = array() ) { // @since 1.7.1 Store available capabilities existing in roles. - foreach ( $this->store->get_roles() as $key => $role ) { + foreach ( $this->store->get_roles() as $role ) { if ( is_array( $role->capabilities ) ) { - foreach ( $role->capabilities as $cap => $grant ) { - $caps[ (string) $cap ] = $cap; - } + $role_caps = array_keys( $role->capabilities ); + $caps = array_merge( array_combine( $role_caps, $role_caps ), $caps ); } } @@ -212,6 +211,7 @@ public function get_wordpress_capabilities( $caps = array() ) { /** * Other WordPress capabilities. * @since 1.7.4 WordPress 4.9 capabilities. + * @since 1.8.3 WordPress 4.9.6 privacy capabilities. */ if ( VAA_API::validate_wp_version( '4.9' ) ) { $caps['activate_plugin'] = 'activate_plugin'; @@ -220,6 +220,11 @@ public function get_wordpress_capabilities( $caps = array() ) { $caps['install_languages'] = 'install_languages'; $caps['update_languages'] = 'update_languages'; } + if ( VAA_API::validate_wp_version( '4.9.6' ) ) { + $caps['erase_others_personal_data'] = 'erase_others_personal_data'; + $caps['export_others_personal_data'] = 'export_others_personal_data'; + $caps['manage_privacy_options'] = 'manage_privacy_options'; + } /** * Network capabilities. @@ -444,8 +449,8 @@ public function filter_ure_capabilities_groups_tree( $groups ) { * @access public * @see \VAA_View_Admin_As_Compat::init() * @see \URE_Capabilities_Groups_Manager::get_cap_groups() - * @param array $groups Current capability groups - * @param string $cap_id Capability identifier + * @param array $groups Current capability groups. + * @param string $cap_id Capability identifier. * @return array */ public function filter_ure_custom_capability_groups( $groups, $cap_id ) { diff --git a/includes/class-controller.php b/includes/class-controller.php index 537da3ea..863eb0fb 100644 --- a/includes/class-controller.php +++ b/includes/class-controller.php @@ -149,9 +149,19 @@ public function ajax_view_admin_as() { $data = $this->validate_data_keys( $data ); + // Stop selecting the same view! + if ( $this->is_current_view( $data ) ) { + wp_send_json_error( + array( + 'type' => 'message', + 'text' => esc_html__( 'This view is already selected!', VIEW_ADMIN_AS_DOMAIN ), + ) + ); + } + $success = false; if ( ! empty( $data ) ) { - $success = $this->ajax_handler( $data ); + $success = $this->update( $data ); } if ( true === $success ) { @@ -162,35 +172,30 @@ public function ajax_view_admin_as() { die(); } - wp_send_json_error( array( - 'type' => 'error', - 'text' => esc_html__( 'Something went wrong, please try again.', VIEW_ADMIN_AS_DOMAIN ), - ) ); + wp_send_json_error( + array( + 'type' => 'error', + 'text' => esc_html__( 'Something went wrong, please try again.', VIEW_ADMIN_AS_DOMAIN ), + ) + ); die(); } /** - * AJAX handler. - * Applies the data input. + * Applies the data input to update views and settings. * * @since 1.7.0 + * @since 1.8.3 Renamed from `ajax_handler` + made public. * @param array $data Post data. * @return array|bool */ - private function ajax_handler( $data ) { + public function update( $data ) { $success = false; $view_types = array(); - - // Stop selecting the same view! - if ( $this->is_current_view( $data ) ) { - wp_send_json_error( array( - 'type' => 'message', - 'text' => esc_html__( 'This view is already selected!', VIEW_ADMIN_AS_DOMAIN ), - ) ); - } + $data = $this->validate_data_keys( $data ); /** - * Ajax return filters. + * Update data return filters. * * @see `view_admin_as_update_view_{$key}` * @see `view_admin_as_handle_ajax_{$key}` @@ -200,21 +205,21 @@ private function ajax_handler( $data ) { * @param mixed $value View data value. * @param string $key View data key. * @return bool|array { - * In case of array. Uses wp_json_return() structure. + * In case of array. Uses wp_json_return() when AJAX is used. * @type bool $success Send JSON success or error? * @type array $data { * Optional extra data to send with the JSON return. * In case of a view the page normally refreshes. * @type string $redirect (URL) Redirect the user? (Only works on success). - * @type string $display Options: notice A notice type in the admin bar - * popup A popup/overlay with content - * @type string $type Options: success Ureka! (green) - Default when $success is true - * error Send an error (red) - Default when $success is false - * message Just a message (blue) - * warning Send a warning (orange) - * @type string $text The text to show - * @type array $list Show multiple messages (Popup only) - * @type string $textarea Textarea content (Popup only) + * @type string $display Options: `notice` A notice type in the admin bar. + * `popup` A popup/overlay with content. + * @type string $type Options: `success` Ureka! (green) - Default when $success is true. + * `error` Send an error (red) - Default when $success is false. + * `message` Just a message (blue). + * `warning` Send a warning (orange). + * @type string $text The text to show. + * @type array $list Show multiple messages (Popup only). + * @type string $textarea Textarea content (Popup only). * } * } */ @@ -224,6 +229,7 @@ private function ajax_handler( $data ) { $success = apply_filters( 'view_admin_as_update_view_' . $key, null, $value, $key ); } else { + // @todo 1.9 Rename this to `view_admin_as_update_{$key}` $success = apply_filters( 'view_admin_as_handle_ajax_' . $key, null, $value, $key ); } if ( true !== $success ) { @@ -353,10 +359,12 @@ public function get_view_types() { _deprecated_hook( 'view_admin_as_view_types', 1.8, 'view_admin_as()->register_view_type()' ); } - $view_types = array_unique( array_merge( - array_filter( $dep_view_types, 'is_string' ), - $view_types - ) ); + $view_types = array_unique( + array_merge( + array_filter( $dep_view_types, 'is_string' ), + $view_types + ) + ); } return $view_types; @@ -416,11 +424,12 @@ private function get_view() { * * @since 1.3.4 * @since 1.6.0 Moved from `VAA_View_Admin_As`. + * @since 1.8.3 Made public. * @access public * * @return bool */ - private function update_view() { + public function update_view() { $data = $this->validate_view_data( $this->store->get_view() ); if ( $data ) { $meta = $this->store->get_userMeta( 'views' ); @@ -454,8 +463,8 @@ private function update_view() { */ public function reset_view( $user_login = null, $user = null ) { - // function is not triggered by the wp_login action hook. if ( null === $user ) { + // Function is not triggered by the wp_login action hook. $user = $this->store->get_curUser(); } if ( ! empty( $user->ID ) ) { @@ -492,8 +501,8 @@ public function reset_view( $user_login = null, $user = null ) { */ public function cleanup_views( $user_login = null, $user = null ) { - // function is not triggered by the wp_login action hook. if ( null === $user ) { + // Function is not triggered by the wp_login action hook. $user = $this->store->get_curUser(); } if ( ! empty( $user->ID ) ) { @@ -534,8 +543,8 @@ public function cleanup_views( $user_login = null, $user = null ) { */ public function reset_all_views( $user_login = null, $user = null ) { - // function is not triggered by the wp_login action hook. if ( null === $user ) { + // Function is not triggered by the wp_login action hook. $user = $this->store->get_curUser(); } if ( ! empty( $user->ID ) ) { @@ -568,14 +577,16 @@ public function validate_data_keys( $data ) { return array(); } - $allowed_keys = array_unique( array_merge( - // View types. - $this->get_view_types(), - // Module keys. - array_keys( $this->vaa->get_modules() ), - // VAA core keys. - array( 'setting', 'user_setting', 'reset' ) - ) ); + $allowed_keys = array_unique( + array_merge( + // View types. + $this->get_view_types(), + // Module keys. + array_keys( $this->vaa->get_modules() ), + // VAA core keys. + array( 'setting', 'user_setting', 'reset' ) + ) + ); $data = array_intersect_key( $data, array_flip( $allowed_keys ) ); diff --git a/includes/class-store.php b/includes/class-store.php index c567796a..e3f486bc 100644 --- a/includes/class-store.php +++ b/includes/class-store.php @@ -258,7 +258,7 @@ public function get_curUserSession() { } /** - * Get view data (meta). + * Get view data. * @since 1.7.0 * @param string $key Key for array. * @return mixed @@ -269,7 +269,6 @@ public function get_view( $key = null ) { /** * Get view type data - * * @since 1.7.0 * @param string $type Type key. * @param string $key (optional) Type data key. diff --git a/includes/class-type.php b/includes/class-type.php index 600d68a4..88cc1ef5 100644 --- a/includes/class-type.php +++ b/includes/class-type.php @@ -258,11 +258,11 @@ public function init_user_modifications() { /** * View update handler (Ajax probably), called from main handler. * - * @since 1.8.0 Renamed from `ajax_handler()` + * @since 1.8.0 Renamed from `ajax_handler()`. * @access public - * @param null $null Null. - * @param array $data The ajax data for this module. - * @param string $type The view type. + * @param null $null Null. + * @param array $data The ajax data for this module. + * @param string $type The view type. * @return bool */ public function update_view( $null, $data, $type = null ) { diff --git a/includes/class-vaa.php b/includes/class-vaa.php index 74b2a49c..5b82919d 100644 --- a/includes/class-vaa.php +++ b/includes/class-vaa.php @@ -110,7 +110,7 @@ final class VAA_View_Admin_As private $view_types = array(); /** - * Class registry + * Class registry. * * @since 1.8.0 * @var array @@ -251,7 +251,7 @@ private function run() { $this->welcome_notice(); } - // Fix some compatibility issues, more to come! + // Third party compatibility. VAA_View_Admin_As_Compat::get_instance( $this )->init(); /** diff --git a/includes/class-view.php b/includes/class-view.php index 08caa06b..bc713e2a 100644 --- a/includes/class-view.php +++ b/includes/class-view.php @@ -170,22 +170,15 @@ public function init_user_modifications() { */ $this->add_filter( 'get_user_metadata', array( $this, 'filter_overrule_get_user_metadata' ), 999999999, 3 ); - // `user_has_cap` priority. - $priority = -999999999; - if ( $this->store->get_view( 'caps' ) ) { - // Overwrite everything when the capability view is active. - remove_all_filters( 'user_has_cap' ); - $priority = 999999999; - } /** * The priority value of the VAA `user_has_cap` filter. * Runs as first by default. * * @since 1.7.2 - * @param int $priority + * @param int $priority Default: -999999999. * @return int */ - $priority = (int) apply_filters( 'view_admin_as_user_has_cap_priority', $priority ); + $priority = (int) apply_filters( 'view_admin_as_user_has_cap_priority', -999999999 ); /** * Change the capabilities. @@ -341,7 +334,7 @@ public function filter_overrule_get_user_metadata( $null, $object_id, $meta_key * @since 0.1.0 * @since 1.5.0 Renamed from `change_caps()`. * @since 1.6.0 Moved from `VAA_View_Admin_As`. - * @since 1.6.2 Use logic from current_view_can(). + * @since 1.6.2 Use logic from `self::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 @@ -381,6 +374,14 @@ public function filter_map_meta_cap( $caps, $cap, $user_id, $args = array() ) { ); } + /** + * Everyone is allowed to exist. + * @since 1.8.3 + * @see \WP_User::has_cap() + * @link https://wordpress.org/support/topic/compatibility-with-view-admin-as-2/ + */ + $filter_caps['exist'] = true; + foreach ( (array) $caps as $actual_cap ) { if ( ! $this->current_view_can( $actual_cap, $filter_caps ) ) { // Regular users. Assuming this capability never exists.. diff --git a/modules/class-caps.php b/modules/class-caps.php index 60f4bf5f..adbcdb2b 100644 --- a/modules/class-caps.php +++ b/modules/class-caps.php @@ -82,11 +82,22 @@ public function do_view() { if ( parent::do_view() ) { + $this->add_filter( 'view_admin_as_user_has_cap_priority', array( $this, 'filter_user_has_cap_priority' ) ); $this->add_action( 'vaa_view_admin_as_modify_user', array( $this, 'modify_user' ), 2, 2 ); $this->init_user_modifications(); } } + /** + * Make sure to run `user_has_cap` view filter as last if this view is active. + * + * @since 1.8.3 + * @return int + */ + public function filter_user_has_cap_priority() { + return 999999999; + } + /** * Modify the current user object. * diff --git a/modules/class-groups.php b/modules/class-groups.php index 6970f033..cecbc075 100644 --- a/modules/class-groups.php +++ b/modules/class-groups.php @@ -138,8 +138,8 @@ public function do_view() { $this->reset_groups_user(); - $this->vaa->view()->init_user_modifications(); $this->add_action( 'vaa_view_admin_as_modify_user', array( $this, 'modify_user' ), 10, 2 ); + $this->init_user_modifications(); $this->add_filter( 'groups_post_access_user_can_read_post', array( $this, 'groups_post_access_user_can_read_post' ), 99, 3 ); diff --git a/modules/class-restrict-user-access.php b/modules/class-restrict-user-access.php index d20bb8bd..b53b981d 100644 --- a/modules/class-restrict-user-access.php +++ b/modules/class-restrict-user-access.php @@ -188,8 +188,8 @@ public function do_view() { //$this->selected = $this->store->get_view( $this->type ); $this->selectedCaps = $this->get_level_caps( $this->selected, true ); - $this->vaa->view()->init_user_modifications(); $this->add_action( 'vaa_view_admin_as_modify_user', array( $this, 'modify_user' ), 10, 2 ); + $this->init_user_modifications(); $this->add_filter( 'get_user_metadata', array( $this, 'get_user_metadata' ), 10, 3 ); diff --git a/modules/class-role-defaults.php b/modules/class-role-defaults.php index c01fbb3c..dab7cbdd 100644 --- a/modules/class-role-defaults.php +++ b/modules/class-role-defaults.php @@ -1111,6 +1111,17 @@ public function admin_bar_menu( $admin_bar, $root ) { $root = $root . '-role-defaults'; + $admin_bar->add_node( array( + 'id' => $root . '-docs', + 'parent' => $root, + 'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-book-alt' ) . __( 'Documentation', VIEW_ADMIN_AS_DOMAIN ), + 'href' => 'https://github.com/JoryHogeveen/view-admin-as/wiki/Role-Defaults', + 'meta' => array( + 'class' => 'auto-height vaa-has-icon', + 'target' => '_blank', + ), + ) ); + // This module requires the role view type to enable all it's features. if ( ! VAA_API::is_view_type_enabled( 'role' ) ) { $view_type = view_admin_as()->get_view_types( 'role' ); @@ -1237,8 +1248,8 @@ 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_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', + 'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-book-alt' ) . __( 'Documentation', VIEW_ADMIN_AS_DOMAIN ), + 'href' => 'https://github.com/JoryHogeveen/view-admin-as/wiki/Role-Defaults#what-data-is-stored-for-role-defaults-and-how-can-this-be-changed', 'meta' => array( 'class' => 'auto-height vaa-has-icon', 'target' => '_blank', diff --git a/modules/class-role-manager.php b/modules/class-role-manager.php index e47495c0..9c0687dc 100644 --- a/modules/class-role-manager.php +++ b/modules/class-role-manager.php @@ -771,6 +771,17 @@ public function admin_bar_menu( $admin_bar, $root ) { $root = $root . '-role-manager'; + $admin_bar->add_node( array( + 'id' => $root . '-docs', + 'parent' => $root, + 'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-book-alt' ) . __( 'Documentation', VIEW_ADMIN_AS_DOMAIN ), + 'href' => 'https://github.com/JoryHogeveen/view-admin-as/wiki/Role-Manager', + 'meta' => array( + 'class' => 'auto-height vaa-has-icon', + 'target' => '_blank', + ), + ) ); + $view_type = view_admin_as()->get_view_types( 'caps' ); if ( $view_type instanceof VAA_View_Admin_As_Caps ) { $view_type_label = $view_type->get_label(); diff --git a/modules/class-users.php b/modules/class-users.php index 692dd6a3..89216174 100644 --- a/modules/class-users.php +++ b/modules/class-users.php @@ -103,7 +103,7 @@ protected function __construct( $vaa ) { /** * Force AJAX search for users at all times. * @since 1.8.1 - * @param bool $ajax_search Default: `false` + * @param bool $ajax_search Default: `false`. * @return bool */ $this->ajax_search = (bool) apply_filters( 'view_admin_as_user_ajax_search', $this->ajax_search ); @@ -278,13 +278,13 @@ public function update_view( $null, $data, $type = null ) { } /** - * Validate data for this view type + * Validate data for this view type. * * @since 1.7.0 * @since 1.8.0 Moved from `VAA_View_Admin_As_Controller`. * @access public - * @param null $null Default return (invalid) - * @param mixed $data The view data + * @param null $null Default return (invalid). + * @param mixed $data The view data. * @return mixed */ public function validate_view_data( $null, $data = null ) { @@ -967,7 +967,12 @@ public function _filter_get_user_capabilities( $null, $user_id, $meta_key ) { global $wpdb; if ( $wpdb->get_blog_prefix() . 'capabilities' === $meta_key && array_key_exists( $user_id, $this->get_data() ) ) { - $roles = $this->get_data( $user_id )->roles; + $user = $this->get_data( $user_id ); + if ( ! $user ) { + return $null; + } + + $roles = $user->roles; if ( is_string( $roles ) ) { // It is still raw DB data, unserialize it. $roles = maybe_unserialize( $roles ); @@ -989,8 +994,8 @@ public function _filter_get_user_capabilities( $null, $user_id, $meta_key ) { * * @since 1.8.0 * @access public - * @param \WP_User[]|\WP_User $users - * @param null|int|\WP_User $user_id + * @param \WP_User[]|\WP_User $users + * @param int|\WP_User (optional) $user_id * @return array */ public function filter_users_by_access( $users, $user_id = null ) { @@ -1032,7 +1037,8 @@ public function filter_users_by_access( $users, $user_id = null ) { * @see is_super_admin() >> wp-includes/capabilities.php * @link https://developer.wordpress.org/reference/functions/is_super_admin/ */ - if ( // Remove super admins for multisites. + if ( + // Remove super admins for multisites. ( is_multisite() && in_array( $user->user_login, (array) $super_admins, true ) ) || // Remove regular admins for normal installs. ( ! is_multisite() && $user->has_cap( 'administrator' ) ) || @@ -1063,7 +1069,7 @@ public function filter_users_by_access( $users, $user_id = null ) { * @since 1.7.1 User ID as array key. * @access public * - * @see store_users() + * @see VAA_View_Admin_As_Users::store_data() * * @param \WP_User[] $users Array of user objects (WP_User). * @return \WP_User[] $users diff --git a/readme.txt b/readme.txt index 6f463744..6cd9ec33 100644 --- a/readme.txt +++ b/readme.txt @@ -3,9 +3,9 @@ Contributors: keraweb Donate link: https://www.keraweb.nl/donate.php?for=view-admin-as Tags: admin, view, roles, users, switch, user switching, role switching, capabilities, caps, screen settings, defaults, visitor Requires at least: 4.1 -Tested up to: 4.9 +Tested up to: 5.0 Requires PHP: 5.2.4 -Stable tag: 1.8.2 +Stable tag: 1.8.3 View the WordPress admin as a different role or visitor, switch between users, temporarily change your capabilities, set screen settings for roles. @@ -208,6 +208,14 @@ Yes, see *Install as a must-use plugin* on the *Installation* tab. == Changelog == += 1.8.3 = + +* **Compatibility:** Users always have the exists capability. [Go to issue](https://wordpress.org/support/topic/compatibility-with-view-admin-as-2/) +* **Compatibility:** WordPress 4.9.6 privacy capabilities. +* **API:** Added several API methods & enhancements. + +Detailed info: [PR on GitHub](https://github.com/JoryHogeveen/view-admin-as/pull/102) + = 1.8.2 = * **Enhancement/Fix:** Support AJAX search in the Role Defaults module. [#100](https://github.com/JoryHogeveen/view-admin-as/issues/100) diff --git a/ui/class-admin-bar.php b/ui/class-admin-bar.php index 3bacb5a9..99bc86a5 100644 --- a/ui/class-admin-bar.php +++ b/ui/class-admin-bar.php @@ -123,11 +123,12 @@ public function vaa_init() { * Get the toolbar title for the main VAA node. * * @since 1.7.2 - * @access private + * @since 1.8.3 Made public. + * @access public * @see \VAA_View_Admin_As_Admin_Bar::admin_bar_menu() * @return string */ - private function get_admin_bar_menu_title() { + public function get_admin_bar_menu_title() { if ( ! $this->store->get_view() ) { return __( 'View As', VIEW_ADMIN_AS_DOMAIN ); } diff --git a/ui/templates/adminbar-caps-actions.php b/ui/templates/adminbar-caps-actions.php index d34a1d5d..cdae0709 100644 --- a/ui/templates/adminbar-caps-actions.php +++ b/ui/templates/adminbar-caps-actions.php @@ -51,7 +51,7 @@ ); // View filter if ( $this->store->get_view() ) { - $data_caps = wp_json_encode( $this->store->get_selectedCaps() ); + $data_caps = wp_json_encode( $this->store->get_selectedCaps() ); $role_select_options[] = array( 'compare' => 'vaa', 'label' => '= ' . __( 'Current view', VIEW_ADMIN_AS_DOMAIN ), @@ -70,7 +70,7 @@ } // Role filters foreach ( $this->store->get_roles() as $role_key => $role ) { - $data_caps = wp_json_encode( $role->capabilities ); + $data_caps = wp_json_encode( $role->capabilities ); $role_select_options[] = array( 'compare' => esc_attr( $role_key ), 'label' => '= ' . $this->store->get_rolenames( $role_key ), diff --git a/ui/templates/adminbar-role-items.php b/ui/templates/adminbar-role-items.php index 112a3b1a..f932585a 100644 --- a/ui/templates/adminbar-role-items.php +++ b/ui/templates/adminbar-role-items.php @@ -40,8 +40,9 @@ // Used to align items properly when some roles don't have users. $class .= ' vaa-menupop'; // Check if the current view is a user with this role. - if ( $this->store->get_view( 'user' ) && - in_array( $role_key, $this->store->get_selectedUser()->roles, true ) + if ( + $this->store->get_view( 'user' ) + && in_array( $role_key, $this->store->get_selectedUser()->roles, true ) ) { $class .= ' current-parent'; } diff --git a/ui/templates/adminbar-settings-user.php b/ui/templates/adminbar-settings-user.php index 542acefd..5fb786fa 100644 --- a/ui/templates/adminbar-settings-user.php +++ b/ui/templates/adminbar-settings-user.php @@ -21,10 +21,11 @@ die(); } -if ( isset( $this ) && - isset( $this->store ) && - isset( $admin_bar ) && $admin_bar instanceof WP_Admin_Bar && - isset( $root ) +if ( + isset( $this ) + && isset( $this->store ) + && isset( $admin_bar ) && $admin_bar instanceof WP_Admin_Bar + && isset( $root ) ) { /** diff --git a/view-admin-as.php b/view-admin-as.php index a2b4eecf..802093dd 100644 --- a/view-admin-as.php +++ b/view-admin-as.php @@ -3,7 +3,7 @@ * @author Jory Hogeveen * @package View_Admin_As * @since 0.1.0 - * @version 1.8.2 + * @version 1.8.3 * @licence GPL-2.0+ * @link https://github.com/JoryHogeveen/view-admin-as * @@ -11,7 +11,7 @@ * Plugin Name: View Admin As * Plugin URI: https://wordpress.org/plugins/view-admin-as/ * Description: View the WordPress admin as a different role or visitor, switch between users, temporarily change your capabilities, set default screen settings for roles. - * Version: 1.8.2 + * Version: 1.8.3 * Author: Jory Hogeveen * Author URI: https://www.keraweb.nl * Text Domain: view-admin-as @@ -20,7 +20,7 @@ * License URI: http://www.gnu.org/licenses/gpl-2.0.html * GitHub Plugin URI: https://github.com/JoryHogeveen/view-admin-as * - * @copyright 2015-2018 Jory Hogeveen + * @copyright 2015-2019 Jory Hogeveen * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -44,7 +44,7 @@ if ( ! class_exists( 'VAA_View_Admin_As' ) && ! function_exists( 'view_admin_as' ) ) { - define( 'VIEW_ADMIN_AS_VERSION', '1.8.2' ); + define( 'VIEW_ADMIN_AS_VERSION', '1.8.3' ); define( 'VIEW_ADMIN_AS_DB_VERSION', '1.8' ); define( 'VIEW_ADMIN_AS_DOMAIN', 'view-admin-as' ); define( 'VIEW_ADMIN_AS_FILE', __FILE__ );