From 2627f564277d10f01df95612a8462804be0f71c8 Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Tue, 28 Nov 2023 12:30:18 +0600 Subject: [PATCH] store text field data --- assets/js/frontend-form.min.js | 2 +- includes/class-frontend-form-post.php | 42 +++++------ includes/class-frontend-render-form.php | 97 ++++++++++++++----------- 3 files changed, 78 insertions(+), 63 deletions(-) diff --git a/assets/js/frontend-form.min.js b/assets/js/frontend-form.min.js index 69499bcbf..fc00ae365 100644 --- a/assets/js/frontend-form.min.js +++ b/assets/js/frontend-form.min.js @@ -1 +1 @@ -!function(a,b){a.fn.listautowidth=function(){return this.each(function(){var b=a(this).width(),c=b/a(this).children("li").length;a(this).children("li").each(function(){var b=a(this).outerWidth(!0)-a(this).width();a(this).width(c-b)})})},b.WP_User_Frontend={init:function(){this.enableMultistep(this),a(".wpuf-form").on("click","img.wpuf-clone-field",this.cloneField),a(".wpuf-form").on("click","img.wpuf-remove-field",this.removeField),a(".wpuf-form").on("click","a.wpuf-delete-avatar",this.deleteAvatar),a(".wpuf-form").on("click","a#wpuf-post-draft",this.draftPost),a(".wpuf-form").on("click","button#wpuf-account-update-profile",this.account_update_profile),a(".wpuf-form-add").on("submit",this.formSubmit),a("form#post").on("submit",this.adminPostSubmit),b.matchMedia("(max-width: 600px)").matches&&(a("table.items-table tr td .post-edit-icon").click(function(b){b.preventDefault(),a(this).parents("tr").find(".data-column").toggleClass("flex-column"),a(this).toggleClass("toggle-icon")}),a(".wpuf-dashboard-navigation ul li:first-child").after().click(function(b){b.preventDefault(),a(".wpuf-dashboard-navigation ul li").not(":first").toggle()})),a(".wpuf-form").on("step-change-fieldset",function(a,b,c){if(wpuf_plupload_items.length)for(var d=wpuf_plupload_items.length-1;d>=0;d--)wpuf_plupload_items[d].refresh();if(wpuf_map_items.length)for(var d=wpuf_map_items.length-1;d>=0;d--)google.maps.event.trigger(wpuf_map_items[d].map,"resize"),wpuf_map_items[d].map.setCenter(wpuf_map_items[d].center)}),this.ajaxCategory(),a(':submit[name="wpuf_user_subscription_cancel"]').click(function(b){b.preventDefault(),Swal.fire({text:wpuf_frontend.cancelSubMsg,icon:"warning",showCancelButton:!0,confirmButtonColor:"#d54e21",confirmButtonText:wpuf_frontend.delete_it,cancelButtonText:wpuf_frontend.cancel_it,customClass:{confirmButton:"btn btn-success",cancelButton:"btn btn-danger"}}).then(function(b){if(!b.isConfirmed)return!1;a("#wpuf_cancel_subscription").submit()})}),this.warningOnExit(),this.handleReadOnly()},warningOnExit:function(){a('input[name="submit"], #wpuf-post-draft').on("click",function(){b.onbeforeunload=null}),a(".wpuf-form-add").on("change",function(){a(".wpuf-form-add input, .wpuf-form-add select, .wpuf-form-add textarea").each(function(c){"hidden"===a(this).attr("type")&&"submit"===a(this).attr("type")&&-1===a(this).val()||(b.onbeforeunload=function(){return"you have changes"})})})},handleReadOnly:function(){a(".wpuf-form .read-only").each(function(){a("input, select, textarea",this).each(function(){a(this).attr("disabled",!0)})})},check_pass_strength:function(){var b=a("#pass1").val();if(a("#pass-strength-result").show(),a("#pass-strength-result").removeClass("short bad good strong"),!b)return a("#pass-strength-result").html(" "),void a("#pass-strength-result").hide();if(void 0!==wp.passwordStrength)switch(wp.passwordStrength.meter(b,wp.passwordStrength.userInputDisallowedList(),b)){case 2:a("#pass-strength-result").addClass("bad").html(pwsL10n.bad);break;case 3:a("#pass-strength-result").addClass("good").html(pwsL10n.good);break;case 4:a("#pass-strength-result").addClass("strong").html(pwsL10n.strong);break;case 5:a("#pass-strength-result").addClass("short").html(pwsL10n.mismatch);break;default:a("#pass-strength-result").addClass("short").html(pwsL10n.short)}},enableMultistep:function(c){var d=this,e=0,f=a(':hidden[name="wpuf_multistep_type"]').val();if(null!=f){if(a("fieldset.wpuf-multistep-fieldset").find(".wpuf-multistep-prev-btn").first().remove(),a("fieldset.wpuf-multistep-fieldset").find(".wpuf-multistep-next-btn").last().remove(),a(".wpuf-form fieldset").removeClass("field-active").first().addClass("field-active"),"progressive"==f&&0!=a(".wpuf-form .wpuf-multistep-fieldset").length){a("fieldset.wpuf-multistep-fieldset legend").first();a(".wpuf-multistep-progressbar").html('
');var g=a(".wpuf-multistep-progressbar"),h=a(".wpuf-progress-percentage");a(".wpuf-multistep-progressbar").progressbar({change:function(){h.text(g.progressbar("value")+"%")}}),a(".wpuf-multistep-fieldset legend").hide()}else a(".wpuf-form").each(function(){var b=a(this),c=a(".wpuf-multistep-progressbar",b),d="";c.addClass("wizard-steps"),d+='",c.append(d),a(".wpuf-step-wizard li",c).first().addClass("active-step"),a(".wpuf-step-wizard",c).listautowidth()});this.change_fieldset(e,f),a("fieldset .wpuf-multistep-prev-btn, fieldset .wpuf-multistep-next-btn").click(function(g){if(a(this).hasClass("wpuf-multistep-next-btn")){0!=d.formStepCheck("",a(this).closest("fieldset"))&&c.change_fieldset(++e,f)}else a(this).hasClass("wpuf-multistep-prev-btn")&&c.change_fieldset(--e,f);var h=a("form.wpuf-form-add"),i=h.offset().top;return b.scrollTo({top:i-32,behavior:"smooth"}),!1})}},change_fieldset:function(b,c){var d=a("fieldset.wpuf-multistep-fieldset").eq(b);a("fieldset.wpuf-multistep-fieldset").removeClass("field-active").eq(b).addClass("field-active"),a(".wpuf-step-wizard li").each(function(){a(this).index()<=b?"step_by_step"==c?a(this).addClass("passed-wpuf-ms-bar"):a(".wpuf-ps-bar",this).addClass("passed-wpuf-ms-bar"):"step_by_step"==c?a(this).removeClass("passed-wpuf-ms-bar"):a(".wpuf-ps-bar",this).removeClass("passed-wpuf-ms-bar")}),a(".wpuf-step-wizard li").removeClass("wpuf-ms-bar-active active-step completed-step"),a(".passed-wpuf-ms-bar").addClass("completed-step").last().addClass("wpuf-ms-bar-active"),a(".wpuf-ms-bar-active").addClass("active-step");var e=a("fieldset.wpuf-multistep-fieldset").eq(b).find("legend").text();if(e=a.trim(e),"progressive"==c&&0!=a(".wpuf-form .wpuf-multistep-fieldset").length){var f=100*(b+1)/a("fieldset.wpuf-multistep-fieldset").length,f=Number(f.toFixed(2));a(".wpuf-multistep-progressbar").progressbar({value:f}),a(".wpuf-progress-percentage").text(e+" ("+f+"%)")}a(".wpuf-form").trigger("step-change-fieldset",[b,d])},ajaxCategory:function(){a(".category-wrap").on("change",".cat-ajax",function(){var b=a(this).data("form-id");currentLevel=parseInt(a(this).parent().attr("level")),WP_User_Frontend.getChildCats(a(this),currentLevel+1,"category",b)})},getChildCats:function(b,c,d,e){var f=a(b).val(),g="wpuf-category-dropdown-lvl-"+c,d=void 0!==d?d:"category",h=a(b).siblings("span").data("taxonomy");a.ajax({type:"post",url:wpuf_frontend.ajaxurl,data:{action:"wpuf_get_child_cat",catID:f,nonce:wpuf_frontend.nonce,field_attr:h,form_id:e},beforeSend:function(){a(b).parent().parent().next(".loading").addClass("wpuf-loading")},complete:function(){a(b).parent().parent().next(".loading").removeClass("wpuf-loading")},success:function(e){a(b).parent().nextAll().each(function(){a(this).remove()}),""!=e&&(a(b).parent().addClass("hasChild").parent().append('
'),b.parent().parent().find("#"+g).html(e).slideDown("fast")),a(document).trigger("wpuf-ajax-fetched-child-categories",g,c,d)}})},cloneField:function(b){b.preventDefault();var c=a(this).closest("tr"),d=c.clone();d.find("input").val(""),d.find(":checked").attr("checked",""),c.after(d)},removeField:function(){var b=a(this).closest("tr");b.siblings().addBack().length>1&&b.remove()},adminPostSubmit:function(b){b.preventDefault();var c=a(this);if(WP_User_Frontend.validateForm(c))return!0},draftPost:function(b){b.preventDefault();var c=a(this),d=a(this).closest("form"),e=d.serialize()+"&action=wpuf_draft_post",f=d.find('input[type="hidden"][name="post_id"]').val(),g=[];a(".wpuf-rich-validation").each(function(b,c){var c=a(c),d=c.data("id"),e=c.data("name"),f=a.trim(tinyMCE.get(d).getContent());g.push(e+"="+encodeURIComponent(f))}),e=e+"&"+g.join("&"),c.after(' '),a.post(wpuf_frontend.ajaxurl,e,function(b){if(void 0===f){var e='';e+='',e+='',e+='',d.append(e)}c.next("span.wpuf-loading").remove(),c.after('  '+b.message+""),a(".wpuf-draft-saved").delay(2500).fadeOut("fast",function(){a(this).remove()})})},account_update_profile:function(b){b.preventDefault();var c=a(this).closest("form");a.post(wpuf_frontend.ajaxurl,c.serialize(),function(a){a.success?(c.find(".wpuf-error").hide(),c.find(".wpuf-success").show()):(c.find(".wpuf-success").hide(),c.find(".wpuf-error").show(),c.find(".wpuf-error").text(a.data))})},formStepCheck:function(a,b){var c=b,d=(c.find("input[type=submit]"),WP_User_Frontend.validateForm(c));return 0==d&&WP_User_Frontend.addErrorNotice(self,"bottom"),d},formSubmit:function(c){c.preventDefault();var d=a(this),e=d.find("input[type=submit]");form_data=WP_User_Frontend.validateForm(d),form_data&&(d.find("li.wpuf-submit").append(''),e.attr("disabled","disabled").addClass("button-primary-disabled"),a.post(wpuf_frontend.ajaxurl,form_data,function(c){if(c.success)a("body").trigger("wpuf:postform:success",c),1==c.show_message?(d.before('
'+c.message+"
"),d.slideUp("fast",function(){d.remove()}),a("html, body").animate({scrollTop:a(".wpuf-success").offset().top-100},"fast")):b.location=c.redirect_to;else{if(void 0!==c.type&&"login"===c.type)return void(confirm(c.error)?b.location=c.redirect_to:(e.removeAttr("disabled"),e.removeClass("button-primary-disabled"),d.find("span.wpuf-loading").remove()));d.find(".g-recaptcha").length>0&&grecaptcha.reset(),Swal.fire({html:c.error,icon:"warning",showCancelButton:!1,confirmButtonColor:"#d54e21",confirmButtonText:"OK",customClass:{cancelButton:"btn btn-danger"}}),e.removeAttr("disabled")}e.removeClass("button-primary-disabled"),d.find("span.wpuf-loading").remove()}))},isTelephoneField:function(b){return a(b).hasClass("wpuf_telephone")&&"yes"===a(b).data("show-list")},validateForm:function(c){var d=[],e=[];if(WP_User_Frontend.removeErrors(c),WP_User_Frontend.removeErrorNotice(c),c.find("input:visible, textarea:visible, select:visible, div.br-widget:visible, .wpuf-rich-validation:visible, div.wpuf-attachment-upload-filelist:visible").each(function(f,g){var h="",i=a(g).data("type"),j=a(g).data("required");switch(i){case"rich":var k=a(g).data("id"),l=a(g).data("name");w=a.trim(tinyMCE.get(k).getContent()),"yes"===j&&""===w&&e.push({type:"required",container:g});var m=WP_User_Frontend.editorLimit.isRestrictionFailed(g);if(m){e.push({type:"limit",container:g});break}var n=WP_User_Frontend.editorContainingShortcode(g);if(n.shortcodeFound){e.push({type:"custom",container:g,message:wpuf_frontend.protected_shortcodes_message.replace("%shortcode%","["+n.shortcode+"]")});break}d.push(l+"="+encodeURIComponent(w));break;case"textarea":case"text":if(w=a.trim(a(g).val()),"yes"===j&&""===w){e.push({type:"required",container:g});break}var m=WP_User_Frontend.editorLimit.isRestrictionFailed(g);if(m){e.push({type:"limit",container:g});break}if(WP_User_Frontend.isTelephoneField(g)){var o=b.intlTelInputGlobals.getInstance(g);if(""!==o.getNumber()&&!o.isValidNumber()){e.push({type:"validation",container:g});break}var p=a(g).attr("name"),q=o.getNumber();a("").attr("type","hidden").attr("name",p).attr("value",q).appendTo(c);break}break;case"url":if(w=a.trim(a(g).val()),"yes"===j&&""===w){e.push({type:"required",container:g});break}if(""!==w&&!WP_User_Frontend.isValidURL(w)){e.push({type:"validation",container:g});break}break;case"password":case"confirm_password":var r=a(g).data("repeat"),s=a(g).data("strength"),t=a(g).data("minimum-length");if(w=a.trim(a(g).val()),"yes"===j&&""===w){e.push({type:"required",container:g});break}if(w.length'+wpuf_frontend.error_message+""):a(b).find("li.wpuf-submit").append('
'+wpuf_frontend.error_message+"
")},removeErrorNotice:function(b){a(b).find(".wpuf-errors").remove()},markError:function(b,c,d){if(a(b).closest("div").addClass("has-error"),c){var e="",f=a(b).data("label");switch(e=f||a(b).closest("li").data("label"),c){case"required":case"mismatch":case"validation":e=e+" "+error_str_obj[c];break;case"limit":e="";break;case"custom":e=d}a(b).siblings(".wpuf-error-msg").remove(),a(b).closest(".wpuf-fields.wpuf-fields-address").length?(a(b).closest("div.wpuf-sub-fields").find("div.wpuf-error-msg").remove(),a(b).closest("div.wpuf-sub-fields").append('
'+e+"
")):(a(b).closest("div.wpuf-fields").find("div.wpuf-error-msg").remove(),a(b).closest("div.wpuf-fields").append('
'+e+"
"))}},removeErrors:function(b){a(b).find(".has-error").removeClass("has-error"),a(".wpuf-error-msg").remove()},isValidEmail:function(a){return new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i).test(a)},isValidURL:function(a){return new RegExp("^(http:\\/\\/www\\.|https:\\/\\/www\\.|http:\\/\\/|https:\\/\\/){1}[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,20}(:[0-9]{1,20})?(\\/.*)?$").test(a)},insertImage:function(b,c){if(a("#"+b).length){var d=new plupload.Uploader({runtimes:"html5,html4",browse_button:b,container:"wpuf-insert-image-container",multipart:!0,multipart_params:{action:"wpuf_insert_image",form_id:a("#"+b).data("form_id")},multiple_queues:!1,multi_selection:!1,urlstream_upload:!0,file_data_name:"wpuf_file",max_file_size:wpuf_frontend_upload.max_filesize,url:wpuf_frontend_upload.plupload.url,flash_swf_url:wpuf_frontend_upload.flash_swf_url,filters:[{title:"Allowed Files",extensions:"jpg,jpeg,gif,png,bmp"}]});d.bind("Init",function(a,b){}),d.bind("FilesAdded",function(b,c){var d=a("#wpuf-insert-image-container");a.each(c,function(a,b){d.append('
')}),b.refresh(),b.start()}),d.bind("QueueChanged",function(a){d.start()}),d.bind("UploadProgress",function(b,c){var d=a("#"+c.id);a(".bar",d).css({width:c.percent+"%"}),a(".percent",d).html(c.percent+"%")}),d.bind("Error",function(a,b){alert("Error #"+b.code+": "+b.message)}),d.bind("FileUploaded",function(b,d,e){if(a("#"+d.id).remove(),"error"!==e.response){if("undefined"!=typeof tinyMCE)if("function"!=typeof tinyMCE.execInstanceCommand){var f=tinyMCE.get("post_content_"+c);null!==f&&f.insertContent(e.response)}else tinyMCE.execInstanceCommand("post_content_"+c,"mceInsertContent",!1,e.response);var g=a("#post_content_"+c);g.val(g.val()+e.response)}else alert("Something went wrong")}),d.init()}},deleteAvatar:function(b){b.preventDefault(),confirm(a(this).data("confirm"))&&a.post(wpuf_frontend.ajaxurl,{action:"wpuf_delete_avatar",_wpnonce:wpuf_frontend.nonce},function(){a(b.target).parent().remove(),a("[id^=wpuf-avatar]").css("display","")})},editorLimit:{bind:function(b,c,d,e,f){"no"===d?(a("textarea#"+c).keyup(function(a){WP_User_Frontend.editorLimit.textLimit.call(this,a,b,e,f)}),a("input#"+c).keyup(function(a){WP_User_Frontend.editorLimit.textLimit.call(this,a,b,e,f)}),a("input#"+c).change(function(a){WP_User_Frontend.editorLimit.textLimit.call(this,a,b,e,f)}),a("textarea#"+c).on("paste",function(c){var d=a(this);setTimeout(function(){WP_User_Frontend.editorLimit.textLimit.call(d,c,b,e,f)},100)}),a("input#"+c).on("paste",function(c){var d=a(this);setTimeout(function(){WP_User_Frontend.editorLimit.textLimit.call(d,c,b,e,f)},100)})):setTimeout(function(){tinyMCE.get(c).onKeyUp.add(function(a,c){WP_User_Frontend.editorLimit.tinymce.onKeyUp(a,c,b,e,f)}),tinyMCE.get(c).onPaste.add(function(a,c){setTimeout(function(){WP_User_Frontend.editorLimit.tinymce.onPaste(a,c,b,e,f)},100)})},1e3)},checkTinyMCERestriction:function(b,c,d){var e=0,f=void 0!==c[0]&&null!==c[0]?parseInt(c[0]):0,g=(void 0!==c[1]&&null!==c[1]&&c[1].trim(),void 0!==c[2]&&null!==c[2]&&c[2].trim(),void 0!==c[3]&&null!==c[3]?c[3].trim():""),h=void 0!==c[4]&&null!==c[4]?c[4].trim():"",i="";"word"===g?(e=WP_User_Frontend.editorLimit.tinymce.getStats(d).words,i="word_"+h):(e=WP_User_Frontend.editorLimit.tinymce.getStats(d).chars,i="char_"+h);wpuf_frontend["word_"+h];return 0!==e&&(e>f&&"max"===h?(WP_User_Frontend.markError(b,"limit"),jQuery(".mce-path-item.mce-last",d.container).html(wpuf_frontend[i]+" "+e+"/"+f),!0):ej&&"max"===l)return WP_User_Frontend.markError(b,"limit"),!0;if(gj&&"max"===l)return WP_User_Frontend.markError(b,"limit"),!0;if(fd&&"max"===f?(WP_User_Frontend.markError(g,"limit"),WP_User_Frontend.contentLimitMessage(a(g),e,f,d)):d&&hd&&"max"===f?(WP_User_Frontend.contentLimitMessage(i,e,f,d),WP_User_Frontend.markError(i,"limit")):d&&hc&&"max"===e?(WP_User_Frontend.contentLimitMessage(f,d,e,c),WP_User_Frontend.markError(f,"limit")):c&&gc&&"max"===e?(WP_User_Frontend.contentLimitMessage(f,d,e,c),WP_User_Frontend.markError(f,"limit")):c&&g=35&&b.keyCode<=40||(b.preventDefault(),b.stopPropagation())},make_media_embed_code:function(b,c){a.post(ajaxurl,{action:"make_media_embed_code",content:b},function(a){c.setContent(c.getContent()+c.setContent(a))})}},doUncheckRadioBtn:function(a){a.checked=!1},contentLimitMessage:function(a,b,c,d){var e="";"word"===b?"min"===c?(e=wpuf_frontend.word_min_title+"
",e+=wpuf_frontend.word_min_details.replace("%number%",d)):(e=wpuf_frontend.word_max_title+"
",e+=wpuf_frontend.word_max_details.replace("%number%",d)):"min"===c?(e=wpuf_frontend.char_min_title+"
",e+=wpuf_frontend.char_min_details.replace("%number%",d)):(e=wpuf_frontend.char_max_title+"
",e+=wpuf_frontend.char_max_details.replace("%number%",d)),a.closest(".wpuf-fields").find("span.wpuf-wordlimit-message").html(e)},editorContainingShortcode:function(b){var c=a(b),d=c.data("id"),e=a.trim(tinyMCE.get(d).getContent()).toLowerCase(),f=wpuf_frontend.protected_shortcodes;if(!f)return{shortcodeFound:!1};for(var g=0;g=35&&b.keyCode<=39||(b.shiftKey||(b.keyCode<65||b.keyCode>90)&&(b.keyCode<48||b.keyCode>57))&&(b.keyCode<96||b.keyCode>105)&&b.preventDefault()}),a('.wpuf-form-add input[name="shopurl"]').keyup(function(b){a("#url-alart").text(a(this).val())}),a('.wpuf-form-add input[name="shopurl"]').on("focusout",function(){var b=a(this),c={action:"shop_url",url_slug:b.val(),_nonce:dokan.nonce};""!==b.val()&&a.post(dokan.ajaxurl,c,function(b){0==b?(a("#url-alart").removeClass("text-success").addClass("text-danger"),a("#url-alart-mgs").removeClass("text-success").addClass("text-danger").text(dokan.seller.notAvailable)):(a("#url-alart").removeClass("text-danger").addClass("text-success"),a("#url-alart-mgs").removeClass("text-danger").addClass("text-success").text(dokan.seller.available))})}),a(".wpuf-form-add #wpuf-map-add-location").attr("name","find_address")})}(jQuery,window); \ No newline at end of file +!function(a,b){a.fn.listautowidth=function(){return this.each(function(){var b=a(this).width(),c=b/a(this).children("li").length;a(this).children("li").each(function(){var b=a(this).outerWidth(!0)-a(this).width();a(this).width(c-b)})})},b.WP_User_Frontend={init:function(){this.enableMultistep(this);var c=a(".wpuf-form");c.on("click","img.wpuf-clone-field",this.cloneField),c.on("click","img.wpuf-clone-repeat-field",this.cloneRepeatField),c.on("click","img.wpuf-remove-field",this.removeField),c.on("click","img.wpuf-remove-repeat-field",this.removeRepeatField),c.on("click","a.wpuf-delete-avatar",this.deleteAvatar),c.on("click","a#wpuf-post-draft",this.draftPost),c.on("click","button#wpuf-account-update-profile",this.account_update_profile),a(".wpuf-form-add").on("submit",this.formSubmit),a("form#post").on("submit",this.adminPostSubmit),b.matchMedia("(max-width: 600px)").matches&&(a("table.items-table tr td .post-edit-icon").click(function(b){b.preventDefault(),a(this).parents("tr").find(".data-column").toggleClass("flex-column"),a(this).toggleClass("toggle-icon")}),a(".wpuf-dashboard-navigation ul li:first-child").after().click(function(b){b.preventDefault(),a(".wpuf-dashboard-navigation ul li").not(":first").toggle()})),a(".wpuf-form").on("step-change-fieldset",function(a,b,c){if(wpuf_plupload_items.length)for(var d=wpuf_plupload_items.length-1;d>=0;d--)wpuf_plupload_items[d].refresh();if(wpuf_map_items.length)for(var d=wpuf_map_items.length-1;d>=0;d--)google.maps.event.trigger(wpuf_map_items[d].map,"resize"),wpuf_map_items[d].map.setCenter(wpuf_map_items[d].center)}),this.ajaxCategory(),a(':submit[name="wpuf_user_subscription_cancel"]').click(function(b){b.preventDefault(),Swal.fire({text:wpuf_frontend.cancelSubMsg,icon:"warning",showCancelButton:!0,confirmButtonColor:"#d54e21",confirmButtonText:wpuf_frontend.delete_it,cancelButtonText:wpuf_frontend.cancel_it,customClass:{confirmButton:"btn btn-success",cancelButton:"btn btn-danger"}}).then(function(b){if(!b.isConfirmed)return!1;a("#wpuf_cancel_subscription").submit()})}),this.warningOnExit(),this.handleReadOnly()},warningOnExit:function(){a('input[name="submit"], #wpuf-post-draft').on("click",function(){b.onbeforeunload=null}),a(".wpuf-form-add").on("change",function(){a(".wpuf-form-add input, .wpuf-form-add select, .wpuf-form-add textarea").each(function(c){"hidden"===a(this).attr("type")&&"submit"===a(this).attr("type")&&-1===a(this).val()||(b.onbeforeunload=function(){return"you have changes"})})})},handleReadOnly:function(){a(".wpuf-form .read-only").each(function(){a("input, select, textarea",this).each(function(){a(this).attr("disabled",!0)})})},check_pass_strength:function(){var b=a("#pass1").val();if(a("#pass-strength-result").show(),a("#pass-strength-result").removeClass("short bad good strong"),!b)return a("#pass-strength-result").html(" "),void a("#pass-strength-result").hide();if(void 0!==wp.passwordStrength)switch(wp.passwordStrength.meter(b,wp.passwordStrength.userInputDisallowedList(),b)){case 2:a("#pass-strength-result").addClass("bad").html(pwsL10n.bad);break;case 3:a("#pass-strength-result").addClass("good").html(pwsL10n.good);break;case 4:a("#pass-strength-result").addClass("strong").html(pwsL10n.strong);break;case 5:a("#pass-strength-result").addClass("short").html(pwsL10n.mismatch);break;default:a("#pass-strength-result").addClass("short").html(pwsL10n.short)}},enableMultistep:function(c){var d=this,e=0,f=a(':hidden[name="wpuf_multistep_type"]').val();if(null!=f){if(a("fieldset.wpuf-multistep-fieldset").find(".wpuf-multistep-prev-btn").first().remove(),a("fieldset.wpuf-multistep-fieldset").find(".wpuf-multistep-next-btn").last().remove(),a(".wpuf-form fieldset").removeClass("field-active").first().addClass("field-active"),"progressive"==f&&0!=a(".wpuf-form .wpuf-multistep-fieldset").length){a("fieldset.wpuf-multistep-fieldset legend").first();a(".wpuf-multistep-progressbar").html('
');var g=a(".wpuf-multistep-progressbar"),h=a(".wpuf-progress-percentage");a(".wpuf-multistep-progressbar").progressbar({change:function(){h.text(g.progressbar("value")+"%")}}),a(".wpuf-multistep-fieldset legend").hide()}else a(".wpuf-form").each(function(){var b=a(this),c=a(".wpuf-multistep-progressbar",b),d="";c.addClass("wizard-steps"),d+='
    ',a(".wpuf-multistep-fieldset",this).each(function(){d+="
  • "+a.trim(a("legend",this).text())+"
  • ",a("legend",this).hide()}),d+="
",c.append(d),a(".wpuf-step-wizard li",c).first().addClass("active-step"),a(".wpuf-step-wizard",c).listautowidth()});this.change_fieldset(e,f),a("fieldset .wpuf-multistep-prev-btn, fieldset .wpuf-multistep-next-btn").click(function(g){if(a(this).hasClass("wpuf-multistep-next-btn")){0!=d.formStepCheck("",a(this).closest("fieldset"))&&c.change_fieldset(++e,f)}else a(this).hasClass("wpuf-multistep-prev-btn")&&c.change_fieldset(--e,f);var h=a("form.wpuf-form-add"),i=h.offset().top;return b.scrollTo({top:i-32,behavior:"smooth"}),!1})}},change_fieldset:function(b,c){var d=a("fieldset.wpuf-multistep-fieldset").eq(b);a("fieldset.wpuf-multistep-fieldset").removeClass("field-active").eq(b).addClass("field-active"),a(".wpuf-step-wizard li").each(function(){a(this).index()<=b?"step_by_step"==c?a(this).addClass("passed-wpuf-ms-bar"):a(".wpuf-ps-bar",this).addClass("passed-wpuf-ms-bar"):"step_by_step"==c?a(this).removeClass("passed-wpuf-ms-bar"):a(".wpuf-ps-bar",this).removeClass("passed-wpuf-ms-bar")}),a(".wpuf-step-wizard li").removeClass("wpuf-ms-bar-active active-step completed-step"),a(".passed-wpuf-ms-bar").addClass("completed-step").last().addClass("wpuf-ms-bar-active"),a(".wpuf-ms-bar-active").addClass("active-step");var e=a("fieldset.wpuf-multistep-fieldset").eq(b).find("legend").text();if(e=a.trim(e),"progressive"==c&&0!=a(".wpuf-form .wpuf-multistep-fieldset").length){var f=100*(b+1)/a("fieldset.wpuf-multistep-fieldset").length,f=Number(f.toFixed(2));a(".wpuf-multistep-progressbar").progressbar({value:f}),a(".wpuf-progress-percentage").text(e+" ("+f+"%)")}a(".wpuf-form").trigger("step-change-fieldset",[b,d])},ajaxCategory:function(){a(".category-wrap").on("change",".cat-ajax",function(){var b=a(this).data("form-id");currentLevel=parseInt(a(this).parent().attr("level")),WP_User_Frontend.getChildCats(a(this),currentLevel+1,"category",b)})},getChildCats:function(b,c,d,e){var f=a(b).val(),g="wpuf-category-dropdown-lvl-"+c,d=void 0!==d?d:"category",h=a(b).siblings("span").data("taxonomy");a.ajax({type:"post",url:wpuf_frontend.ajaxurl,data:{action:"wpuf_get_child_cat",catID:f,nonce:wpuf_frontend.nonce,field_attr:h,form_id:e},beforeSend:function(){a(b).parent().parent().next(".loading").addClass("wpuf-loading")},complete:function(){a(b).parent().parent().next(".loading").removeClass("wpuf-loading")},success:function(e){a(b).parent().nextAll().each(function(){a(this).remove()}),""!=e&&(a(b).parent().addClass("hasChild").parent().append('
'),b.parent().parent().find("#"+g).html(e).slideDown("fast")),a(document).trigger("wpuf-ajax-fetched-child-categories",g,c,d)}})},cloneField:function(b){b.preventDefault();var c=a(this).closest("tr"),d=c.clone();d.find("input").val(""),d.find(":checked").attr("checked",""),c.after(d)},removeField:function(){var b=a(this).closest("tr");b.siblings().addBack().length>1&&b.remove()},cloneRepeatField:function(b){b.preventDefault();var c=a(this).closest(".wpuf-column-field-inner-columns.column-repeat"),d=c.clone();d.find("input").val(""),d.find("textarea").val(""),d.find(":checked").attr("checked",""),c.after(d),WP_User_Frontend.calculateFieldsName(a(this).parents(".wpuf-field-columns")),WP_User_Frontend.setRowNumber(a(this).closest(".wpuf-field-columns"))},removeRepeatField:function(){var b=a(this).closest(".wpuf-column-field-inner-columns.column-repeat"),c=b.siblings().addBack(),d=c.length,e=a(c).index(a(this).closest(".wpuf-column-field-inner-columns.column-repeat"));d>1&&(WP_User_Frontend.setRowNumber(a(b).closest(".wpuf-field-columns"),d-1),b.remove()),e+1!==d&&WP_User_Frontend.calculateFieldsName(b)},setRowNumber:function(b,c){c||(c=a(b).children().length),a(b).parent(".wpuf-fields").find("input.repeat_row_numbers").val(c)},calculateFieldsName:function(b){var c=b.children(),d=[],e=[],f=[],g=".wpuf-column input, .wpuf-column textarea, .wpuf-column select, .wpuf-column .wpuf-rich-validation";a(c[0]).find(g).each(function(b,c){d.push(a(c).attr("name").split("_0_")),e.push(a(c).attr("id").split("_0_")),f.push(a(c).attr("class").split("_0_"))}),c.each(function(b,c){a(c).find(g).each(function(c,g){a(g).attr("name",d[c][0]+"_"+b+"_"+d[c][1]),a(g).attr("id",e[c][0]+"_"+b+"_"+e[c][1]),a(g).attr("class",f[c][0]+"_"+b+"_"+f[c][1])})})},adminPostSubmit:function(b){b.preventDefault();var c=a(this);if(WP_User_Frontend.validateForm(c))return!0},draftPost:function(b){b.preventDefault();var c=a(this),d=a(this).closest("form"),e=d.serialize()+"&action=wpuf_draft_post",f=d.find('input[type="hidden"][name="post_id"]').val(),g=[];a(".wpuf-rich-validation").each(function(b,c){var c=a(c),d=c.data("id"),e=c.data("name"),f=a.trim(tinyMCE.get(d).getContent());g.push(e+"="+encodeURIComponent(f))}),e=e+"&"+g.join("&"),c.after(' '),a.post(wpuf_frontend.ajaxurl,e,function(b){if(void 0===f){var e='';e+='',e+='',e+='',d.append(e)}c.next("span.wpuf-loading").remove(),c.after('  '+b.message+""),a(".wpuf-draft-saved").delay(2500).fadeOut("fast",function(){a(this).remove()})})},account_update_profile:function(b){b.preventDefault();var c=a(this).closest("form");a.post(wpuf_frontend.ajaxurl,c.serialize(),function(a){a.success?(c.find(".wpuf-error").hide(),c.find(".wpuf-success").show()):(c.find(".wpuf-success").hide(),c.find(".wpuf-error").show(),c.find(".wpuf-error").text(a.data))})},formStepCheck:function(a,b){var c=b,d=(c.find("input[type=submit]"),WP_User_Frontend.validateForm(c));return 0==d&&WP_User_Frontend.addErrorNotice(self,"bottom"),d},formSubmit:function(c){c.preventDefault();var d=a(this),e=d.find("input[type=submit]");form_data=WP_User_Frontend.validateForm(d),form_data&&(d.find("li.wpuf-submit").append(''),e.attr("disabled","disabled").addClass("button-primary-disabled"),a.post(wpuf_frontend.ajaxurl,form_data,function(c){if(c.success)a("body").trigger("wpuf:postform:success",c),1==c.show_message?(d.before('
'+c.message+"
"),d.slideUp("fast",function(){d.remove()}),a("html, body").animate({scrollTop:a(".wpuf-success").offset().top-100},"fast")):b.location=c.redirect_to;else{if(void 0!==c.type&&"login"===c.type)return void(confirm(c.error)?b.location=c.redirect_to:(e.removeAttr("disabled"),e.removeClass("button-primary-disabled"),d.find("span.wpuf-loading").remove()));d.find(".g-recaptcha").length>0&&grecaptcha.reset(),Swal.fire({html:c.error,icon:"warning",showCancelButton:!1,confirmButtonColor:"#d54e21",confirmButtonText:"OK",customClass:{cancelButton:"btn btn-danger"}}),e.removeAttr("disabled")}e.removeClass("button-primary-disabled"),d.find("span.wpuf-loading").remove()}))},isTelephoneField:function(b){return a(b).hasClass("wpuf_telephone")&&"yes"===a(b).data("show-list")},validateForm:function(c){var d=[],e=[];if(WP_User_Frontend.removeErrors(c),WP_User_Frontend.removeErrorNotice(c),c.find("input:visible, textarea:visible, select:visible, div.br-widget:visible, .wpuf-rich-validation:visible, div.wpuf-attachment-upload-filelist:visible").each(function(f,g){var h="",i=a(g).data("type"),j=a(g).data("required");switch(i){case"rich":var k=a(g).data("id"),l=a(g).data("name");w=a.trim(tinyMCE.get(k).getContent()),"yes"===j&&""===w&&e.push({type:"required",container:g});var m=WP_User_Frontend.editorLimit.isRestrictionFailed(g);if(m){e.push({type:"limit",container:g});break}var n=WP_User_Frontend.editorContainingShortcode(g);if(n.shortcodeFound){e.push({type:"custom",container:g,message:wpuf_frontend.protected_shortcodes_message.replace("%shortcode%","["+n.shortcode+"]")});break}d.push(l+"="+encodeURIComponent(w));break;case"textarea":case"text":if(w=a.trim(a(g).val()),"yes"===j&&""===w){e.push({type:"required",container:g});break}var m=WP_User_Frontend.editorLimit.isRestrictionFailed(g);if(m){e.push({type:"limit",container:g});break}if(WP_User_Frontend.isTelephoneField(g)){var o=b.intlTelInputGlobals.getInstance(g);if(""!==o.getNumber()&&!o.isValidNumber()){e.push({type:"validation",container:g});break}var p=a(g).attr("name"),q=o.getNumber();a("").attr("type","hidden").attr("name",p).attr("value",q).appendTo(c);break}break;case"url":if(w=a.trim(a(g).val()),"yes"===j&&""===w){e.push({type:"required",container:g});break}if(""!==w&&!WP_User_Frontend.isValidURL(w)){e.push({type:"validation",container:g});break}break;case"password":case"confirm_password":var r=a(g).data("repeat"),s=a(g).data("strength"),t=a(g).data("minimum-length");if(w=a.trim(a(g).val()),"yes"===j&&""===w){e.push({type:"required",container:g});break}if(w.length'+wpuf_frontend.error_message+""):a(b).find("li.wpuf-submit").append('
'+wpuf_frontend.error_message+"
")},removeErrorNotice:function(b){a(b).find(".wpuf-errors").remove()},markError:function(b,c,d){if(a(b).closest("div").addClass("has-error"),c){var e="",f=a(b).data("label");switch(e=f||a(b).closest("li").data("label"),c){case"required":case"mismatch":case"validation":e=e+" "+error_str_obj[c];break;case"limit":e="";break;case"custom":e=d}a(b).siblings(".wpuf-error-msg").remove(),a(b).closest(".wpuf-fields.wpuf-fields-address").length?(a(b).closest("div.wpuf-sub-fields").find("div.wpuf-error-msg").remove(),a(b).closest("div.wpuf-sub-fields").append('
'+e+"
")):(a(b).closest("div.wpuf-fields").find("div.wpuf-error-msg").remove(),a(b).closest("div.wpuf-fields").append('
'+e+"
"))}},removeErrors:function(b){a(b).find(".has-error").removeClass("has-error"),a(".wpuf-error-msg").remove()},isValidEmail:function(a){return new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i).test(a)},isValidURL:function(a){return new RegExp("^(http:\\/\\/www\\.|https:\\/\\/www\\.|http:\\/\\/|https:\\/\\/){1}[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,20}(:[0-9]{1,20})?(\\/.*)?$").test(a)},insertImage:function(b,c){if(a("#"+b).length){var d=new plupload.Uploader({runtimes:"html5,html4",browse_button:b,container:"wpuf-insert-image-container",multipart:!0,multipart_params:{action:"wpuf_insert_image",form_id:a("#"+b).data("form_id")},multiple_queues:!1,multi_selection:!1,urlstream_upload:!0,file_data_name:"wpuf_file",max_file_size:wpuf_frontend_upload.max_filesize,url:wpuf_frontend_upload.plupload.url,flash_swf_url:wpuf_frontend_upload.flash_swf_url,filters:[{title:"Allowed Files",extensions:"jpg,jpeg,gif,png,bmp"}]});d.bind("Init",function(a,b){}),d.bind("FilesAdded",function(b,c){var d=a("#wpuf-insert-image-container");a.each(c,function(a,b){d.append('
')}),b.refresh(),b.start()}),d.bind("QueueChanged",function(a){d.start()}),d.bind("UploadProgress",function(b,c){var d=a("#"+c.id);a(".bar",d).css({width:c.percent+"%"}),a(".percent",d).html(c.percent+"%")}),d.bind("Error",function(a,b){alert("Error #"+b.code+": "+b.message)}),d.bind("FileUploaded",function(b,d,e){if(a("#"+d.id).remove(),"error"!==e.response){if("undefined"!=typeof tinyMCE)if("function"!=typeof tinyMCE.execInstanceCommand){var f=tinyMCE.get("post_content_"+c);null!==f&&f.insertContent(e.response)}else tinyMCE.execInstanceCommand("post_content_"+c,"mceInsertContent",!1,e.response);var g=a("#post_content_"+c);g.val(g.val()+e.response)}else alert("Something went wrong")}),d.init()}},deleteAvatar:function(b){b.preventDefault(),confirm(a(this).data("confirm"))&&a.post(wpuf_frontend.ajaxurl,{action:"wpuf_delete_avatar",_wpnonce:wpuf_frontend.nonce},function(){a(b.target).parent().remove(),a("[id^=wpuf-avatar]").css("display","")})},editorLimit:{bind:function(b,c,d,e,f){"no"===d?(a("textarea#"+c).keyup(function(a){WP_User_Frontend.editorLimit.textLimit.call(this,a,b,e,f)}),a("input#"+c).keyup(function(a){WP_User_Frontend.editorLimit.textLimit.call(this,a,b,e,f)}),a("input#"+c).change(function(a){WP_User_Frontend.editorLimit.textLimit.call(this,a,b,e,f)}),a("textarea#"+c).on("paste",function(c){var d=a(this);setTimeout(function(){WP_User_Frontend.editorLimit.textLimit.call(d,c,b,e,f)},100)}),a("input#"+c).on("paste",function(c){var d=a(this);setTimeout(function(){WP_User_Frontend.editorLimit.textLimit.call(d,c,b,e,f)},100)})):setTimeout(function(){tinyMCE.get(c).onKeyUp.add(function(a,c){WP_User_Frontend.editorLimit.tinymce.onKeyUp(a,c,b,e,f)}),tinyMCE.get(c).onPaste.add(function(a,c){setTimeout(function(){WP_User_Frontend.editorLimit.tinymce.onPaste(a,c,b,e,f)},100)})},1e3)},checkTinyMCERestriction:function(b,c,d){var e=0,f=void 0!==c[0]&&null!==c[0]?parseInt(c[0]):0,g=(void 0!==c[1]&&null!==c[1]&&c[1].trim(),void 0!==c[2]&&null!==c[2]&&c[2].trim(),void 0!==c[3]&&null!==c[3]?c[3].trim():""),h=void 0!==c[4]&&null!==c[4]?c[4].trim():"",i="";"word"===g?(e=WP_User_Frontend.editorLimit.tinymce.getStats(d).words,i="word_"+h):(e=WP_User_Frontend.editorLimit.tinymce.getStats(d).chars,i="char_"+h);wpuf_frontend["word_"+h];return 0!==e&&(e>f&&"max"===h?(WP_User_Frontend.markError(b,"limit"),jQuery(".mce-path-item.mce-last",d.container).html(wpuf_frontend[i]+" "+e+"/"+f),!0):ej&&"max"===l)return WP_User_Frontend.markError(b,"limit"),!0;if(gj&&"max"===l)return WP_User_Frontend.markError(b,"limit"),!0;if(fd&&"max"===f?(WP_User_Frontend.markError(g,"limit"),WP_User_Frontend.contentLimitMessage(a(g),e,f,d)):d&&hd&&"max"===f?(WP_User_Frontend.contentLimitMessage(i,e,f,d),WP_User_Frontend.markError(i,"limit")):d&&hc&&"max"===e?(WP_User_Frontend.contentLimitMessage(f,d,e,c),WP_User_Frontend.markError(f,"limit")):c&&gc&&"max"===e?(WP_User_Frontend.contentLimitMessage(f,d,e,c),WP_User_Frontend.markError(f,"limit")):c&&g=35&&b.keyCode<=40||(b.preventDefault(),b.stopPropagation())},make_media_embed_code:function(b,c){a.post(ajaxurl,{action:"make_media_embed_code",content:b},function(a){c.setContent(c.getContent()+c.setContent(a))})}},doUncheckRadioBtn:function(a){a.checked=!1},contentLimitMessage:function(a,b,c,d){var e="";"word"===b?"min"===c?(e=wpuf_frontend.word_min_title+"
",e+=wpuf_frontend.word_min_details.replace("%number%",d)):(e=wpuf_frontend.word_max_title+"
",e+=wpuf_frontend.word_max_details.replace("%number%",d)):"min"===c?(e=wpuf_frontend.char_min_title+"
",e+=wpuf_frontend.char_min_details.replace("%number%",d)):(e=wpuf_frontend.char_max_title+"
",e+=wpuf_frontend.char_max_details.replace("%number%",d)),a.closest(".wpuf-fields").find("span.wpuf-wordlimit-message").html(e)},editorContainingShortcode:function(b){var c=a(b),d=c.data("id"),e=a.trim(tinyMCE.get(d).getContent()).toLowerCase(),f=wpuf_frontend.protected_shortcodes;if(!f)return{shortcodeFound:!1};for(var g=0;g=35&&b.keyCode<=39||(b.shiftKey||(b.keyCode<65||b.keyCode>90)&&(b.keyCode<48||b.keyCode>57))&&(b.keyCode<96||b.keyCode>105)&&b.preventDefault()}),a('.wpuf-form-add input[name="shopurl"]').keyup(function(b){a("#url-alart").text(a(this).val())}),a('.wpuf-form-add input[name="shopurl"]').on("focusout",function(){var b=a(this),c={action:"shop_url",url_slug:b.val(),_nonce:dokan.nonce};""!==b.val()&&a.post(dokan.ajaxurl,c,function(b){0==b?(a("#url-alart").removeClass("text-success").addClass("text-danger"),a("#url-alart-mgs").removeClass("text-success").addClass("text-danger").text(dokan.seller.notAvailable)):(a("#url-alart").removeClass("text-danger").addClass("text-success"),a("#url-alart-mgs").removeClass("text-danger").addClass("text-success").text(dokan.seller.available))})}),a(".wpuf-form-add #wpuf-map-add-location").attr("name","find_address")})}(jQuery,window); \ No newline at end of file diff --git a/includes/class-frontend-form-post.php b/includes/class-frontend-form-post.php index 5cc7c0f28..a9e654cfb 100755 --- a/includes/class-frontend-form-post.php +++ b/includes/class-frontend-form-post.php @@ -753,32 +753,32 @@ public static function update_post_meta( $meta_vars, $post_id ) { } } - // delete previous repeat values - if ( ! empty( $repeat_fields ) ) { - $row_num = get_post_meta( $post_id, $repeat_fields['repeat_meta'], true ); - - if ( $row_num ) { - $sub_fields = ! empty( $repeat_fields['sub_fields'] ) ? $repeat_fields['sub_fields'] : []; - for ( $i = 0; $i <= $row_num; $i++ ) { - foreach ( $sub_fields as $value ) { - $field_meta = $repeat_fields['repeat_meta'] . '_' . $i . '_' . $value; - delete_post_meta( $post_id, $field_meta ); - delete_post_meta( $post_id, '_' . $field_meta ); + + if ( ! empty( $multi_repeated ) ) { + $fields_meta = ! empty( $multi_repeated['sub_fields'] ) ? $multi_repeated['sub_fields'] : []; + $parent = ! empty( $multi_repeated['parent'] ) ? $multi_repeated['parent'] : ''; + + if ( ! empty( $parent ) && ! empty( $fields_meta ) ) { + // get how many rows previously saved + $row_num = get_post_meta( $post_id, $parent, true ); + + // delete previous repeat values + foreach ( $fields_meta as $sub_field ) { + for ( $i = 0; $i < $row_num; $i++ ) { + $tmp_meta = $parent . '_' . $i . '_' . $sub_field; + delete_post_meta( $post_id, $tmp_meta ); + delete_post_meta( $post_id, '_' . $tmp_meta ); } } - } - } - // insert acf compatible data - if ( ! empty( $repeat_fields ) ) { - if ( ! empty( $meta_key_value[ $repeat_fields['repeat_meta'] ] ) ) { - $row_number = $meta_key_value[ $repeat_fields['repeat_meta'] ]; - $sub_fields = ! empty( $repeat_fields['sub_fields'] ) ? $repeat_fields['sub_fields'] : []; + $row_number = ! empty( $multi_repeated['row_number'] ) ? $multi_repeated['row_number'] : 0; + $sub_fields = ! empty( $multi_repeated['fields'] ) ? $multi_repeated['fields'] : []; + // save new data for ( $i = 0; $i < $row_number; $i++ ) { - foreach ( $sub_fields as $value ) { - $field_meta = $repeat_fields['repeat_meta'] . '_' . $i . '_' . $value; - update_post_meta( $post_id, '_' . $field_meta, uniqid( 'field_' ) ); + foreach ( $sub_fields as $key => $value ) { + update_post_meta( $post_id, $key, $value ); + update_post_meta( $post_id, '_' . $key, uniqid( 'field_' ) ); } } } diff --git a/includes/class-frontend-render-form.php b/includes/class-frontend-render-form.php index 7ffdb8a3e..62d637aee 100644 --- a/includes/class-frontend-render-form.php +++ b/includes/class-frontend-render-form.php @@ -505,14 +505,23 @@ public function get_input_fields( $form_vars ) { $post_vars = $meta_vars = $taxonomy_vars = []; foreach ( $form_vars as $key => $value ) { + // ignore section break and HTML input type + if ( in_array( $value['input_type'], $ignore_lists ) ) { + continue; + } + // get column field input fields - if ( $value['input_type'] == 'column_field' ) { + if ( ( 'column_field' === $value['input_type'] ) || ( 'repeat' === $value['input_type'] ) ) { $inner_fields = $value['inner_fields']; foreach ( $inner_fields as $column_key => $column_fields ) { if ( ! empty( $column_fields ) ) { // ignore section break and HTML input type foreach ( $column_fields as $column_field_key => $column_field ) { + if ( 'repeat' === $value['input_type'] ) { + $column_field['is_repeat_child'] = 'yes'; + } + if ( in_array( $column_field['input_type'], $ignore_lists ) ) { continue; } @@ -538,17 +547,12 @@ public function get_input_fields( $form_vars ) { } } continue; - } - - // ignore section break and HTML input type - if ( in_array( $value['input_type'], $ignore_lists ) ) { - continue; - } - - //separate the post and custom fields - if ( isset( $value['is_meta'] ) && $value['is_meta'] == 'yes' ) { - $meta_vars[] = $value; - continue; + } else { + // separate the post and custom fields + if ( isset( $value['is_meta'] ) && 'yes' === $value['is_meta'] ) { + $meta_vars[] = $value; + continue; + } } if ( $value['input_type'] == 'taxonomy' ) { @@ -708,6 +712,27 @@ public static function prepare_meta_fields( $meta_vars ) { $files = []; $meta_key_value = []; $repeat_fields = []; // repeat field and sub-fields data + $form_id = isset( $_POST['form_id'] ) ? intval( wp_unslash( $_POST['form_id'] ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification + $form = new WPUF_Form( $form_id ); + $form_fields = $form->get_fields(); + $repeat_field_childs = []; + + // processing repeat fields + foreach ( $form_fields as $field ) { + if ( ! empty( $field['input_type'] ) && 'repeat' === $field['input_type'] ) { + // loop for each column. we have 3 columns for repeated fields + for ( $i = 1; $i <= 3; $i++ ) { + if ( ! empty( $field['inner_fields'] ) && ! empty( $field['inner_fields'][ 'column-' . $i ] ) ) { + foreach ( $field['inner_fields'][ 'column-' . $i ] as $column_value ) { + $repeat_field_childs[ $column_value['name'] ] = $field['name']; + $repeat_fields['sub_fields'][] = $column_value['name']; + } + } + } + + $repeat_fields['parent'] = $field['name']; + } + } foreach ( $meta_vars as $key => $value ) { $wpuf_field = wpuf()->fields->get_field( $value['template'] ); @@ -728,8 +753,25 @@ public static function prepare_meta_fields( $meta_vars ) { $wpuf_files = []; } - switch ( $value['input_type'] ) { + if ( ! empty( $value['is_repeat_child'] ) && ( 'yes' === $value['is_repeat_child'] ) ) { + $parent_name = ! empty( $repeat_field_childs[ $value['name'] ] ) ? $repeat_field_childs[ $value['name'] ] : ''; + $row_count_key = $parent_name . '_row_num'; + $row_number = ! empty( $_POST[ $row_count_key ] ) ? absint( wp_unslash( $_POST[ $row_count_key ] ) ) : 1; // phpcs:ignore WordPress.Security.NonceVerification + $repeat_fields['row_number'] = $row_number; + + // loop for each column. we have 3 columns for repeated fields + for ( $i = 0; $i < $row_number; $i++ ) { + $meta_key = ! empty( $value['name'] ) ? $value['name'] : ''; + $formatted_key = $parent_name . '_' . $i . '_' . $meta_key; + + if ( '' !== $meta_key && ! empty( $_POST[ $formatted_key ] ) ) { + $repeat_fields['fields'][ $formatted_key ] = wp_unslash( $_POST[ $formatted_key ] ); + $meta_key_value[ $formatted_key ] = wp_unslash( $_POST[ $formatted_key ] ); // phpcs:ignore WordPress.Security + } + } + } + switch ( $value['input_type'] ) { // put files in a separate array, we'll process it later case 'file_upload': case 'image_upload': @@ -741,33 +783,6 @@ public static function prepare_meta_fields( $meta_vars ) { ]; break; - case 'repeat': - $row_count_key = $value['name'] . '_row_num'; - $row_number = ! empty( $_POST[ $row_count_key ] ) ? absint( wp_unslash( $_POST[ $row_count_key ] ) ) : 1; // phpcs:ignore WordPress.Security.NonceVerification - - // loop for each columns. we have 3 columns for repeated fields - for ( $i = 1; $i <= 3; $i++ ) { - if ( ! empty( $value['inner_fields'] ) && ! empty( $value['inner_fields'][ 'column-' . $i ] ) ) { - foreach ( $value['inner_fields'][ 'column-' . $i ] as $column_value ) { - $index = 0; - $meta_key = ! empty( $column_value['name'] ) ? $column_value['name'] : ''; - $formatted_key = $value['name'] . '_' . $index . '_' . $meta_key; - if ( '' !== $meta_key ) { - $repeat_fields['sub_fields'][] = $meta_key; - while ( isset( $_POST[ $formatted_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification - $meta_key_value[ $formatted_key ] = wp_unslash( $_POST[ $formatted_key ] ); - $index++; - $formatted_key = $value['name'] . '_' . $index . '_' . $meta_key; - } - } - } - } - } - $meta_key_value[ $value['name'] ] = $row_number; - $repeat_fields['repeat_meta'] = $value['name']; - - break; - case 'address': if ( is_array( $value_name ) ) { foreach ( $value_name as $address_field => $field_value ) { @@ -809,7 +824,7 @@ public static function prepare_meta_fields( $meta_vars ) { if ( is_array( $value_name ) && ! empty( $value_name ) ) { $meta_key_value[ $value['name'] ] = implode( self::$separator, $value_name ); } else { - $meta_key_value[ $value['name'] ] = $value_name[0]; + $meta_key_value[ $value['name'] ] = ! empty( $value_name[0] ) ? $value_name[0] : ''; } break;