Changeset 2789773
- Timestamp:
- 09/25/2022 05:41:26 AM (4 years ago)
- Location:
- mailbluster4wp/trunk
- Files:
-
- 11 edited
-
README.txt (modified) (2 diffs)
-
admin/class-mailbluster4wp-admin.php (modified) (4 diffs)
-
admin/css/mailbluster4wp-admin.css (modified) (2 diffs)
-
admin/js/mailbluster4wp-form-builder.js (modified) (11 diffs)
-
admin/partials/form-options/builder.php (modified) (3 diffs)
-
admin/partials/form-options/settings.php (modified) (2 diffs)
-
includes/class-mailbluster4wp-helper.php (modified) (14 diffs)
-
includes/class-mailbluster4wp.php (modified) (1 diff)
-
mailbluster4wp.php (modified) (2 diffs)
-
public/class-mailbluster4wp-public.php (modified) (1 diff)
-
public/js/mailbluster4wp-public.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
mailbluster4wp/trunk/README.txt
r2781859 r2789773 6 6 Tested up to: 6.0.1 7 7 Requires PHP: 5.6 8 Stable tag: 1.1. 78 Stable tag: 1.1.8 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 70 70 == Changelog == 71 71 72 = 1.1.8 = 73 * added custom fields. 74 * removed meta fields. 75 * General improvements. 76 72 77 = 1.1.7 = 73 78 * Support multiple themes. -
mailbluster4wp/trunk/admin/class-mailbluster4wp-admin.php
r2776930 r2789773 155 155 false 156 156 ); 157 157 158 wp_enqueue_script( 158 159 'clipboradjs', … … 162 163 true 163 164 ); 165 166 $ajax_data = array( 167 'ajax_url' => admin_url( 'admin-ajax.php' ), 168 'form_nonce' => wp_create_nonce( 'mb4wp_dialog_form_nonce' ), 169 ); 170 171 wp_localize_script( $this->mailbluster4wp.'-builder', 'mb4wpAjaxDialogForm', $ajax_data ); 164 172 } 165 173 } 174 } 175 176 /** 177 * POST/UPDATE/DELETE the data of the custom field 178 */ 179 180 public static function mb4wp_dialog_form_process(){ 181 182 check_ajax_referer( "mb4wp_dialog_form_nonce", "security" ); 183 $post_data = MailBluster4WP_Helper::sanitize_field_array($_POST["formData"]); 184 parse_str($post_data, $response); 185 186 if($response["mb4wp_dialog_form"]["id"] === ''){ 187 $method = "POST"; 188 } else { 189 $method = $_REQUEST["method"]; 190 } 191 192 $response_data = MailBluster4WP_Helper::cud_custom_field($response, $method); 193 194 if ( is_wp_error($response_data) ) { 195 $error_message = $response_data->get_error_message(); 196 echo "Something went wrong: $error_message"; 197 198 } else { 199 $response_code = json_decode(wp_remote_retrieve_response_code($response_data)); 200 $decoded_response = json_decode($response_data["body"]); 201 202 setcookie("mb4wp-dialog-code", $response_code, time() + (3 * 30), "/"); 203 204 echo $decoded_response->message; 205 if($decoded_response->message){ 206 echo '<br/>'; 207 } 208 echo $decoded_response->fieldLabel; 209 if($decoded_response->fieldLabel){ 210 echo '<br/>'; 211 } 212 echo $decoded_response->fieldMergeTag; 213 } 214 215 wp_die(); 166 216 } 167 217 … … 601 651 602 652 echo '<p class="isa_info regular-text">' . $api_name . '</p>'; 653 } 654 } 655 656 /** 657 * Admin notice for dialog 658 * 659 *@since 1.0.0 660 */ 661 public function mb4wp_admin_notice_dialog(){ 662 global $pagenow; 663 664 if (in_array($pagenow, array('post.php', 'post-new.php'))) { 665 $screen = get_current_screen(); 666 667 if (is_object($screen) && $this->get_post_type() == $screen->post_type && isset($_COOKIE["mb4wp-dialog-msg"])) { 668 if( 200 <= $_COOKIE["mb4wp-dialog-code"] && $_COOKIE["mb4wp-dialog-code"] < 300 ){ 669 $class = "notice-success"; 670 } else if ( 400 <= $_COOKIE["mb4wp-dialog-code"] && $_COOKIE["mb4wp-dialog-code"] < 500 ){ 671 $class = "notice-error"; 672 } else { 673 $class = "notice-warning"; 674 } 675 ?> 676 <div class="notice is-dismissible <?php echo $class; ?>"> 677 <p><?php echo $_COOKIE["mb4wp-dialog-msg"]; ?></p> 678 </div> 679 <?php 680 } 603 681 } 604 682 } … … 669 747 <p><?php echo $link; ?></p> 670 748 </div> 671 <?php749 <?php 672 750 } 673 751 } -
mailbluster4wp/trunk/admin/css/mailbluster4wp-admin.css
r2781859 r2789773 224 224 font-size: 1.6em; 225 225 } 226 .mb4wp-fmbldr-notice{ 227 color: #856404; 228 background-color: #fff3cd; 229 padding: 5px; 230 } 231 .mb4wp-fmbldr-notice::before{ 232 content: "!"; 233 color: #856404; 234 background-color: #efe3af; 235 padding: 0 7px; 236 font-weight: 700; 237 border-radius: 50%; 238 margin-right: 5px; 239 } 240 226 241 #mb4wp-form-submit-message{ 227 242 width: 400px; 228 243 max-width: 400px; 229 244 } 230 .m t-4{245 .mb4wp-mt-4{ 231 246 padding-top: 25px!important; 232 247 } … … 263 278 padding: 4px 4px 9px 0px; 264 279 border-radius: 4px; 280 } 281 .mb4wp-pb-1{ 282 padding-bottom: 1rem; 283 } 284 .mb4wp-pt-1{ 285 padding-top: 1rem; 286 } 287 #mb4wp-custom-field-add{ 288 margin: 5px 0; 289 padding: 3px 20px; 290 font-size: 1em; 291 overflow: hidden; 292 white-space: nowrap; 293 text-overflow: ellipsis; 294 user-select: none; 295 width: 100%; 296 cursor: pointer; 297 } 298 299 /* modal */ 300 .mb4wp-predefined-button{ 301 display: flex; 302 align-items: center; 303 } 304 button.edit_image_container{ 305 margin: 5px 0 5px 3px; 306 align-self: stretch; 307 padding: 0 10px; 308 cursor: pointer; 309 } 310 button[disabled].edit_image_container{ 311 cursor: default; 312 color: #ababab; 313 } 314 button[disabled].edit_image_container .edit_image{ 315 color: #ababab; 316 } 317 .edit_image{ 318 color: #566379; 319 } 320 .mb4wp-overlay{ 321 position: fixed; 322 background-color: #00000059; 323 top: 0; 324 right: 0; 325 bottom: 0; 326 left: 0; 327 z-index: 1; 328 } 329 .mb4wp-modal-dialog{ 330 max-width: 500px; 331 position: fixed; 332 width: auto; 333 top: 50%; 334 left: 50%; 335 transform: translate(-50%, -50%); 336 z-index: 2; 337 } 338 .mb4wp-modal-header{ 339 display: flex; 340 align-items: center; 341 justify-content: space-between; 342 flex-shrink: 0; 343 flex-wrap: wrap; 344 line-height:0.01 345 } 346 .mb4wp-modal-body{ 347 display: flex; 348 flex-direction: column; 349 align-items: center; 350 } 351 .mb4wp-modal-body label { 352 margin-top: 10px; 353 align-self: start; 354 font-weight: 600; 355 } 356 .mb4wp-modal-body input{ 357 width: 100%; 358 padding: 5px; 359 margin: 5px; 360 } 361 .mb4wp-modal-content{ 362 display: flex; 363 flex-direction: column; 364 width: 25rem; 365 padding: 20px; 366 background-color: #ffffff; 367 border: 1px solid #0000002d; 368 border-radius: 0.5rem; 369 } 370 .mb4wp-modal-content.mb4wp-delete-box{ 371 box-shadow: 0 10px 25px 5px #191D24; 372 } 373 .mb4wp-modal-footer{ 374 display: flex; 375 align-items: center; 376 justify-content: flex-end; 377 flex-shrink: 0; 378 flex-wrap: wrap; 379 } 380 .mb4wp-modal-footer input{ 381 padding: 4px 18px!important; 382 } 383 .mb4wp-button-warning{ 384 border-radius: 3px; 385 color: #E64D43; 386 background-color: transparent; 387 border: 1px solid #E64D43; 388 cursor: pointer; 389 font-size: 13px; 390 line-height: 2.15384615; 391 transition: all .15s ease-in-out; 392 } 393 .mb4wp-button-warning:hover{ 394 background-color: #E64D43; 395 color: white; 396 } 397 .mb4wp-delete-modal-close, 398 .mb4wp-modal-close{ 399 cursor: pointer; 400 margin-left: auto; 401 } 402 .mb4wp-flex-1{ 403 flex: 1; 404 } 405 .mb4wp-ml-5{ 406 margin-left: 5px !important; 407 } 408 .mb4wp-delete-content{ 409 margin-bottom: 24px; 265 410 } 266 411 -
mailbluster4wp/trunk/admin/js/mailbluster4wp-form-builder.js
r2781859 r2789773 108 108 // console.log("after ready", arrayHiddenInput); 109 109 110 arrayHiddenInput.forEach(function (item) { 111 if ('*' == item.slice(-1)) { 112 item = item.slice(0, -1); 113 }; 114 switch (item) { 115 case "email": 116 case "first_name": 117 case "last_name": 118 case "timezone": 119 $optionPanelPredefined 120 .find("button[value=" + item + "]") 121 .attr("disabled", true); 122 break; 123 default: 124 break; 125 } 126 }); 127 128 var $predefinedButton = $optionPanelPredefined.find("button"); 110 const buttonList = $optionPanelPredefined.find(".mb4wp-field-button"); 111 buttonList.each(function (index, button){ 112 const value = $(button).attr('value'); 113 if(hiddenInputValue.includes(value)) { 114 $(button).attr("disabled", true); 115 const editIcon = $(button).closest($(".mb4wp-predefined-button")).find(".edit_image_container"); 116 if(editIcon){ 117 editIcon.attr("disabled", true); 118 } 119 120 } 121 }) 122 123 $(document).on("click",".edit_image_container", function (){ 124 const id = $(this).data("id"); 125 const fieldMergeTag = $(this).data("fieldmergetag"); 126 const fieldLabel = $(this).closest($(".mb4wp-predefined-button")) 127 .find(".mb4wp-field-button").val(); 128 $("body").append(mb4wp_render_modal(id, fieldLabel, fieldMergeTag)); 129 return false; 130 }) 131 132 $(document).on("click", "#mb4wp-custom-field-add", function(){ 133 const id = ''; 134 const fieldLabel = ''; 135 const fieldMergeTag = ''; 136 $("body").append(mb4wp_render_addField_modal(id, fieldLabel, fieldMergeTag)); 137 }) 138 139 // modal disappear on close button click 140 $(document).on("click", ".mb4wp-modal-close", function(){ 141 $(".mb4wp-dialog").remove(); 142 }) 143 144 // delete modal disappear on close button click 145 $(document).on("click", ".mb4wp-delete-modal-close", function(){ 146 $(".mb4wp-delete-dialog").remove(); 147 }) 148 149 // get modal field value 150 const observer = new MutationObserver(function(){ 151 if($(".mb4wp-modal-dialog")){ 152 $(document).on("submit", ".mb4wp-modal-dialog", function(e){ 153 e.preventDefault(); 154 const form = $(".mb4wp_dialog_form") 155 .find('input[name^=mb4wp_dialog_form]') 156 .serialize(); 157 158 var data = {}; 159 data["action"] = "mb4wp_dialog_form_process"; 160 data["method"] = "PUT"; 161 data["security"] = mb4wpAjaxDialogForm.form_nonce; 162 data["formData"] = form; 163 164 $.ajax({ 165 url: mb4wpAjaxDialogForm.ajax_url, 166 type: "POST", 167 data: data, 168 success:function ( res ) { 169 mb4wp_setCookie("mb4wp-dialog-msg", res, 30); 170 $(".mb4wp-dialog").remove(); 171 location.reload() 172 }, 173 error: function ( res ){ 174 mb4wp_setCookie("mb4wp-dialog-msg", res, 30); 175 $(".mb4wp-dialog").remove(); 176 location.reload() 177 } 178 }) 179 }) 180 observer.disconnect(); 181 } 182 }) 183 184 const target = document.querySelector("body"); 185 const config = { childList: true }; 186 187 observer.observe(target, config); 188 189 $(document).on("click", '.mb4wp-button-warning[value="Delete Field"][type="button"]', function(){ 190 // $(".mb4wp-dialog").remove(); 191 $("body").append(mb4wp_render_delete_modal()); 192 }) 193 194 // DELETE the custom field 195 $(document).on("click", '.mb4wp-button-warning[value="Delete Field"][type="submit"]', function(){ 196 const form = $(".mb4wp_dialog_form") 197 .find('input[name^=mb4wp_dialog_form]') 198 .serialize(); 199 200 var data = {}; 201 data["action"] = "mb4wp_dialog_form_process"; 202 data["method"] = "DELETE"; 203 data["security"] = mb4wpAjaxDialogForm.form_nonce; 204 data["formData"] = form; 205 206 $.ajax({ 207 url: mb4wpAjaxDialogForm.ajax_url, 208 type: "POST", 209 data: data, 210 success:function ( res ) { 211 mb4wp_setCookie("mb4wp-dialog-msg", res, 30); 212 $(".mb4wp-delete-dialog").remove(); 213 $(".mb4wp-dialog").remove(); 214 location.reload() 215 }, 216 error: function ( res ){ 217 mb4wp_setCookie("mb4wp-dialog-msg", res, 30); 218 location.reload() 219 } 220 }) 221 }) 222 223 // generate merge tag from label 224 $(document).on("blur", "#fieldLabel", function (){ 225 const fieldLabel = $(this).val(); 226 if(!$("#fieldMergeTag").val()){ 227 $("#fieldMergeTag").val(fieldLabel.toLowerCase().replace(/\s+/g, "_")); 228 } 229 }) 230 231 var $predefinedButton = $optionPanelPredefined.find(".mb4wp-field-button"); 129 232 $predefinedButton.on("click", function () { 130 233 var hiddenVal = $hiddenInput.val(), … … 136 239 // console.log($hiddenInput.val()); 137 240 $(this).attr("disabled", true); 241 const editIcon = $(this).closest($(".mb4wp-predefined-button")).find(".edit_image_container"); 242 if(editIcon){ 243 editIcon.attr("disabled", true); 244 } 138 245 }); 139 246 … … 178 285 }) 179 286 180 // var currentItemInputPlaceholder = $currentCloseItem181 // .find("input")182 // .attr("placeholder");183 // console.log('currentItemInputId ',currentItemInputId);184 287 if (currentItemInputId !== "email") { 185 288 var removeItem = ""; … … 197 300 } 198 301 199 // console.log(plainArrayHiddenInput, arrayHiddenInput)200 // console.log('before removing item', arrayHiddenInput);201 202 302 // console.log('remove Item', removeItem); 203 303 arrayHiddenInput.splice(removeItem, 1); 204 $optionPanelPredefined 205 .find("button[value=" + currentItemInputId + "]") 206 .attr("disabled", false); 304 const button = $optionPanelPredefined.find("button[value=" + currentItemInputId + "]"); 305 button.attr("disabled", false); 306 const editIcon = $(button).closest($(".mb4wp-predefined-button")).find(".edit_image_container"); 307 if(editIcon){ 308 editIcon.attr("disabled", false); 309 } 207 310 // console.log("after close arrayHiddenInput", arrayHiddenInput); 208 311 $hiddenInput.val(arrayHiddenInput.toString()); … … 210 313 } 211 314 }); 212 // console.log($hiddenInput.val());213 315 $sortable.sortable({ 214 316 // revert: true, … … 219 321 arrayHiddenInput.splice(dataStart, 1); 220 322 arrayHiddenInput.splice(dataUpdate, 0, dataItem); 221 // console.log('update: '+ui.item.index());222 // console.log("in update", arrayHiddenInput);223 323 $hiddenInput.val(arrayHiddenInput.toString()); 224 324 }, … … 226 326 var dataStart = ui.item.index(); 227 327 ui.item.data("start_pos", dataStart); 228 // console.log('start: '+ui.item.index());229 328 }, 230 329 }); 231 330 $sortable.disableSelection(); 232 $(document).on("click", ".requ red-field", function () {331 $(document).on("click", ".required-field", function () { 233 332 var hiddenVal = $hiddenInput.val(); 234 333 … … 237 336 const itemInputId = currentCloseParent.find($('.regular-text')).attr('id'); 238 337 239 // console.log(itemInputId)240 338 let itemLabel = currentCloseParent.find($('.mb4wp-label')); 241 339 if(checkbox.prop('checked')){ … … 244 342 } 245 343 itemLabel.text(itemLabel.text() + '*'); 246 // console.log("got position")247 344 const updatedHiddenVal = hiddenVal.replace(itemInputId, itemInputId + '*'); 248 345 $hiddenInput.val(updatedHiddenVal); 249 250 // console.log(itemLabel)251 346 } else { 252 // else er moddhe kichu likhlam253 347 const updatedHiddenVal = hiddenVal.replace(itemInputId + '*', itemInputId); 254 348 $hiddenInput.val(updatedHiddenVal) … … 256 350 itemLabel.text(itemLabel.text().slice(0,-1)); 257 351 } 258 // console.log('not checked')259 352 } 260 353 }) 261 354 }); 355 356 function mb4wp_render_delete_modal() { 357 return ( 358 `<div class="mb4wp-delete-dialog"> 359 <div class="mb4wp-overlay"></div> 360 <div class="mb4wp-modal-dialog"> 361 <div class="mb4wp-modal-content mb4wp-delete-box"> 362 <div class="mb4wp-modal-header"> 363 <h2>Delete Field</h2> 364 <div class="dashicons dashicons-no-alt mb4wp-delete-modal-close"></div> 365 </div> 366 <div class="mb4wp-delete-content"> 367 <p>This action will delete the field along with all the data associated with it. It might take some time depending on the number of leads.</p> 368 <p>Are you sure you want to proceed?</p> 369 </div> 370 <div class="mb4wp-modal-footer"> 371 <input type="button" value="Cancel" class="button mb4wp-delete-modal-close"> 372 <input type="submit" value="Delete Field" name="delete" class="mb4wp-button-warning mb4wp-ml-5"> 373 </div> 374 </div> 375 </div> 376 </div>` 377 ) 378 } 379 380 function mb4wp_render_addField_modal( id, fieldLabel, fieldMergeTag ) { 381 382 return ( 383 `<div class="mb4wp-dialog"> 384 <div class="mb4wp-overlay"></div> 385 <form class="mb4wp-modal-dialog mb4wp_dialog_form" method="post"> 386 <div class="mb4wp-modal-content"> 387 <div class="mb4wp-modal-header"> 388 <h2>Add New Field</h2> 389 <div class="dashicons dashicons-no-alt mb4wp-modal-close"></div> 390 </div> 391 <div class="mb4wp-modal-body"> 392 <input type="hidden" name="mb4wp_dialog_form[id]" value${id}> 393 <label for="fieldLabel">Field Label</label> 394 <input type="text" name="mb4wp_dialog_form[fieldLabel]" id="fieldLabel" value="${fieldLabel}"> 395 <label for="fieldMergeTag">Field Merge Tag</label> 396 <input type="text" name="mb4wp_dialog_form[fieldMergeTag]" id="fieldMergeTag" value="${fieldMergeTag}"> 397 </div> 398 <div class="mb4wp-modal-footer mb4wp-pt-1"> 399 <input type="button" value="Cancel" class="button mb4wp-modal-close"> 400 <input type="submit" value="Add Field" name="save" class="button button-primary mb4wp-ml-5"> 401 </div> 402 </div> 403 </form> 404 </div>` 405 ) 406 } 407 408 function mb4wp_render_modal(id, fieldLabel, fieldMergeTag) { 409 return ( 410 `<div class="mb4wp-dialog"> 411 <div class="mb4wp-overlay"></div> 412 <form class="mb4wp-modal-dialog mb4wp_dialog_form" method="post"> 413 <div class="mb4wp-modal-content"> 414 <div class="mb4wp-modal-header"> 415 <h2>Update Field</h2> 416 <div class="dashicons dashicons-no-alt mb4wp-modal-close"></div> 417 </div> 418 <div class="mb4wp-modal-body"> 419 <input type="hidden" name="mb4wp_dialog_form[id]" value="${id}"> 420 <label for="fieldLabel">Field Label</label> 421 <input type="text" name="mb4wp_dialog_form[fieldLabel]" id="fieldLabel" value="${fieldLabel}"> 422 <label for="fieldMergeTag">Field Merge Tag</label> 423 <input type="text" name="mb4wp_dialog_form[fieldMergeTag]" id="fieldMergeTag" value="${fieldMergeTag}"> 424 </div> 425 <div class="mb4wp-modal-footer mb4wp-pt-1"> 426 <div class="mb4wp-flex-1"> 427 <input type="button" value="Delete Field" name="delete" class="mb4wp-button-warning button-large"> 428 </div> 429 <input type="button" value="Cancel" class="button mb4wp-modal-close"> 430 <input type="submit" value="Save Field" name="save" class="button button-primary mb4wp-ml-5"> 431 </div> 432 </div> 433 </form> 434 </div>` 435 ) 436 } 262 437 263 438 function renderHTML(clickFieldValue, readonly) { … … 286 461 } 287 462 return ( 288 '<div class="mb4wp-fmbldr-dynamic-form-fields"><div class="mb4wp-fmbldr-text-inputs"><label for="' + 289 strClickValue + 290 '" class="mb4wp-label">' + 291 placeholderText + 292 '</label><input type="text" id="' + 293 strClickValue + 294 '" class="regular-text" ' + 295 readonly + 296 '><span style="margin-left: 3px;" class="dashicons dashicons-dismiss mb4wp-fmbldr-close"></span><span class="dashicons dashicons-move"></span><p class="requred-field"><input value="checked" name="required_' + strClickValue + '" type="checkbox" id="required_' + strClickValue + '"><label for="required_'+ strClickValue +'">Required field</label></p></div></div>' 463 `<div class="mb4wp-fmbldr-dynamic-form-fields"> 464 <div class="mb4wp-fmbldr-text-inputs"> 465 <label for="${ strClickValue }" class="mb4wp-label">${ placeholderText }</label> 466 <input type="text" id="${ strClickValue }" class="regular-text"${ readonly }> 467 <span style="margin-left: 3px;" class="dashicons dashicons-dismiss mb4wp-fmbldr-close"></span> 468 <span class="dashicons dashicons-move"></span> 469 <p class="required-field"> 470 <input value="checked" name="required_${ strClickValue }" type="checkbox" id="required_${ strClickValue }"> 471 <label for="required_${ strClickValue }">Required field</label> 472 </p> 473 </div> 474 </div>` 297 475 ); 298 476 } 477 478 function mb4wp_setCookie(cookieName, cookieValue, expiryInSeconds){ 479 const expiry = new Date(); 480 expiry.setTime(expiry.getTime() + 1000 * expiryInSeconds); 481 document.cookie = cookieName + "=" + escape(cookieValue) 482 + ";expires=" + expiry.toGMTString() + "; path=/"; 483 } 299 484 })(jQuery); -
mailbluster4wp/trunk/admin/partials/form-options/builder.php
r2781859 r2789773 3 3 $form_input_field = get_post_meta($post_id, 'mb4wp_form_builder_options', true); 4 4 $form_input_field = isset($form_input_field) && !empty($form_input_field) ? $form_input_field : 'email'; 5 $custom_field = MailBluster4WP_Helper::get_custom_field(); 6 $newArr = []; 7 foreach($custom_field->fields as $v){ 8 array_push($newArr, $v->fieldLabel); 9 }; 10 $newArrStr = implode(",", $newArr); 5 11 ?> 6 12 <div class="mb4wp-container builder"> … … 14 20 <button type="button" id="mb4wp-builder-first-name" class="mb4wp-field-button" value="first_name"><?php esc_html_e('First Name', 'mailbluster4wp'); ?></button> 15 21 <button type="button" id="mb4wp-builder-last-name" class="mb4wp-field-button" value="last_name"><?php esc_html_e('Last Name', 'mailbluster4wp'); ?></button> 16 </div> 17 <div class="mb4wp-fmbldr-custom-fields"> 18 <h4 class="mb4wp-fmbldr-h4"><?php esc_html_e('Custom Fields', 'mailbluster4wp'); ?></h4> 19 <div class="mb4wp-fmbldr-input-fields"> 20 <input type="text" id="mb4wp-fmbldr-extra-fields" placeholder="Input Field Label" class="mb4wp-input-padding width-full" value="" pattern="[a-zA-Z0-9\s]+"> 21 <input type="button" class="button mb4wp-fmbldr-add" value="Add"> 22 </div> 23 <div class="mb4wp-fmbldr-validation-box"><?php esc_html_e('alphanumeric only', 'mailbluster4wp'); ?></div> 22 <?php 23 if (is_array($custom_field->fields)) { 24 foreach ($custom_field->fields as $custom_field) { 25 ?> 26 <div class="mb4wp-predefined-button"> 27 <button type="button" class="mb4wp-field-button" value="<?php echo $custom_field->fieldLabel; ?>"><?php echo $custom_field->fieldLabel; ?></button> 28 <button data-id="<?php echo $custom_field->id; ?>" data-fieldMergeTag="<?php echo $custom_field->fieldMergeTag; ?>" class="edit_image_container"> 29 <div class="dashicons dashicons-edit edit_image"></div> 30 </button> 31 </div> 32 <?php 33 } 34 } 35 ?> 36 <input type="button" id="mb4wp-custom-field-add" class="button button-primary" value="Add New Field"/> 24 37 </div> 25 38 </div> … … 76 89 <?php } ?> 77 90 <span class="dashicons dashicons-move"></span> 78 <p class="requred-field"> 91 <?php 92 if(!str_contains($newArrStr, $single_field_str) && $single_field_str != 'email' && $single_field_str != "first_name" && $single_field_str != "last_name"){ 93 ?> 94 95 <p class="mb4wp-fmbldr-notice"><?php echo esc_html_e("This field has been deprecated and won’t be displayed on the subscription form. Please replace it by adding a new field.", "mailbluster4wp"); ?></p> 96 97 <?php } ?> 98 <p class="required-field"> 79 99 <input type="checkbox" name="<?php echo esc_attr('required_' . $modified_single_field); ?>" id="<?php echo esc_attr('required_' . $modified_single_field); ?>" <?php echo ($single_field_str != 'email') ? '' : 'disabled checked' ?> <?php echo ('*' == substr($single_field, -1)) ? 'checked' : '' ?>> 80 100 <label for="<?php echo esc_attr('required_' . $modified_single_field); ?>">Required field</label><br> -
mailbluster4wp/trunk/admin/partials/form-options/settings.php
r2781859 r2789773 35 35 <label for="mb4wp-form-consent-checkbox"><?php esc_attr_e('Consent', 'mailbluster4wp'); ?></label> 36 36 </th> 37 <td class="m t-4">37 <td class="mb4wp-mt-4"> 38 38 <input type="checkbox" id="mb4wp-form-consent-checkbox" class="regular-text" name="mb4wp_form_settings_options[consent_checkbox]" value="yes" <?php checked($form_consent_settings, "yes") ?>> 39 39 <label class="" for="mb4wp-form-consent-checkbox"><?php esc_html_e('Include a consent checkbox', 'mailbluster4wp'); ?></label> … … 45 45 <label for="mb4wp-form-redirectURL"><?php esc_attr_e('Redirect URL', 'mailbluster4wp'); ?></label> 46 46 </th> 47 <td class="m t-4">47 <td class="mb4wp-mt-4"> 48 48 <input type="checkbox" id="mb4wp-form-redirectURL" class="regular-text" name="mb4wp_form_settings_options[redirectURL]" value="yes" <?php checked($form_redirectURL_settings, "yes") ?>> 49 49 <label class="" for="mb4wp-form-redirectURL"><?php esc_html_e('Instead of thanking the subscriber, this will redirect them to a URL', 'mailbluster4wp'); ?></label> -
mailbluster4wp/trunk/includes/class-mailbluster4wp-helper.php
r2781859 r2789773 211 211 } else { 212 212 ob_start(); 213 ?>213 ?> 214 214 <div class="alert alert-warning"> 215 215 <p><?php esc_html_e('Currently the form is not available.', 'mailbluster4wp'); ?></p> … … 261 261 $appearance_btnText_size = self::mb4wp_get_appearance_by_key('btnText_size', $post_id); 262 262 $appearance_labelTextColor = self::mb4wp_get_appearance_by_key('labelTextColor', $post_id); 263 $appearance_fieldPaddingY = self::mb4wp_get_appearance_by_key('fieldPaddingY', $post_id); 264 $appearance_fieldPaddingX = self::mb4wp_get_appearance_by_key('fieldPaddingX', $post_id); 263 265 264 266 // Get form branding … … 282 284 if (isset($show_consent_checkbox) && ($show_consent_checkbox == 'yes')) { 283 285 ?> 284 <div class="mb4wp-consent-checkbox"> 286 <div 287 class="mb4wp-consent-checkbox" 288 style="<?php echo $appearance_theme === 'custom' ? "padding:{$appearance_fieldPaddingY}px {$appearance_fieldPaddingX}px;" : ''; ?>" 289 > 285 290 <input type="checkbox" id="mb4wp_public_consent_checkbox"> 286 291 <label … … 293 298 <div class="mb4wp-form-group"> 294 299 <button 295 <?php echo $appearance_theme === 'custom' ? 'data-theme=custom' : ''; ?>300 <?php echo "data-theme=$appearance_theme"; ?> 296 301 type="submit" 297 302 id="mb4wp_subscribe" … … 346 351 * @return array 347 352 */ 348 private static function mb4wp_process_form_input_fields($post_id) 349 { 353 private static function mb4wp_process_form_input_fields($post_id){ 350 354 351 355 // Get all form fields … … 356 360 $prefix_n_ar = $prefix_s . intval($post_id); 357 361 362 $custom_fields = self::get_custom_field()->fields; 363 $custom_field_label = []; 364 foreach ( $custom_fields as $custom_field ) { 365 array_push( $custom_field_label, $custom_field->fieldLabel ); 366 } 367 $custom_field_label_str = implode( ",", $custom_field_label ); 368 358 369 // Prepare single form fields input attributes 359 370 $form_detailed = array(); … … 368 379 $single_field_str = $single_field; 369 380 } 370 switch ($single_field_str) { 371 case 'email': 372 $form_detailed['email'] = array( 373 'id' => $prefix_s . 'email', 374 'name' => $prefix_n_ar . '[def][email]', 375 'placeholder' => esc_html__('Email Address', 'mailbluster4wp'), 376 'required' => 'required' 377 ); 378 break; 379 case 'first_name': 380 $form_detailed['first_name'] = array( 381 'id' => $prefix_s . 'first_name', 382 'name' => $prefix_n_ar . '[def][first_name]', 383 'placeholder' => esc_html__('First Name', 'mailbluster4wp'), 384 'required' => $required 385 ); 386 break; 387 case 'last_name': 388 $form_detailed['last_name'] = array( 389 'id' => $prefix_s . 'last_name', 390 'name' => $prefix_n_ar . '[def][last_name]', 391 'placeholder' => esc_html__('Last Name', 'mailbluster4wp'), 392 'required' => $required 393 ); 394 break; 395 default: 396 if('*' == substr($single_field, -1)){ 397 $single_field = substr($single_field, 0, -1); 398 }; 399 $single_field = str_replace('_', ' ', trim($single_field)); 400 $form_detailed[$single_field_key] = array( 401 'id' => $prefix_s . $single_field_key, 402 'name' => $prefix_n_ar . '[meta][' . $single_field_key . ']', 403 'placeholder' => $single_field, 404 'required' => $required 405 ); 406 break; 381 // if('*' == substr($single_field, -1)){ 382 // $single_field = substr($single_field, 0, -1); 383 // }; 384 // $single_field = str_replace('_', ' ', trim($single_field)); 385 // $form_detailed[$single_field_key] = array( 386 // 'id' => $prefix_s . $single_field_key, 387 // 'name' => $prefix_n_ar . '[meta][' . $single_field_key . ']', 388 // 'placeholder' => $single_field, 389 // 'required' => $required 390 // ); 391 if('email' == $single_field_str){ 392 $form_detailed['email'] = array( 393 'id' => $prefix_s . 'email', 394 'name' => $prefix_n_ar . '[def][email]', 395 'placeholder' => esc_html__('Email Address', 'mailbluster4wp'), 396 'required' => 'required' 397 ); 398 } elseif ('first_name' == $single_field_str){ 399 $form_detailed['first_name'] = array( 400 'id' => $prefix_s . 'first_name', 401 'name' => $prefix_n_ar . '[def][first_name]', 402 'placeholder' => esc_html__('First Name', 'mailbluster4wp'), 403 'required' => $required 404 ); 405 } elseif ('last_name' == $single_field_str){ 406 $form_detailed['last_name'] = array( 407 'id' => $prefix_s . 'last_name', 408 'name' => $prefix_n_ar . '[def][last_name]', 409 'placeholder' => esc_html__('Last Name', 'mailbluster4wp'), 410 'required' => $required 411 ); 412 } else { 413 if('*' == substr($single_field, -1)){ 414 $single_field = substr($single_field, 0, -1); 415 }; 416 $single_field = str_replace('_', ' ', trim($single_field)); 417 if(str_contains($custom_field_label_str, $single_field)){ 418 foreach($custom_fields as $custom_field){ 419 if($single_field_str == $custom_field->fieldLabel){ 420 $form_detailed[$single_field_key] = array( 421 'id' => $prefix_s . $custom_field->fieldMergeTag, 422 'name' => $prefix_n_ar . '[fields][' . $custom_field->fieldMergeTag . ']', 423 'placeholder' => $single_field, 424 'required' => $required 425 ); 426 } 427 } 428 } 407 429 } 408 430 } 409 431 return $form_detailed; 432 } 433 434 /** 435 * Get the data of custom field from app.mailbluster.com dashboard 436 * 437 * @return array|string|WP_Error 438 */ 439 public static function get_custom_field(){ 440 441 // Set custom field API 442 $lead_url = 'https://api.mailbluster.com/api/fields'; 443 444 // Get response by hitting API 445 $response = wp_safe_remote_get(esc_url_raw($lead_url), array( 446 'headers' => array( 447 'Content-Type' => 'application/json', 448 'authorization' => self::mb4wp_get_valid_api_key() 449 ), 450 )); 451 452 return json_decode($response['body']); 453 } 454 455 /** 456 * Create(POST) Update(PUT) and Delete the data of custom field from app.mailbluster.com dashboard 457 * 458 * @param $submitted_response (an array of data from the admin dialog submitted form) 459 * @param $method (here post put or delete) 460 * @return array|string|WP_Error 461 */ 462 463 public static function cud_custom_field($submitted_response, $method){ 464 465 if (isset($submitted_response) && !empty(array_filter($submitted_response))) { 466 $submitted_response = $submitted_response["mb4wp_dialog_form"]; 467 $id = $submitted_response["id"]; 468 469 // Set custom field API 470 if($method === "POST"){ 471 $lead_url = "https://api.mailbluster.com/api/fields"; 472 } else { 473 $lead_url = "https://api.mailbluster.com/api/fields/$id"; 474 } 475 476 unset($submitted_response["id"]); 477 $submitted_response['authorization'] = self::mb4wp_get_valid_api_key(); 478 $json_data = json_encode($submitted_response); 479 480 // Get response by hitting API 481 $response = wp_safe_remote_post(esc_url_raw($lead_url), array( 482 'headers' => array('Content-Type' => 'application/json'), 483 'body' => $json_data, 484 'method' => $method, 485 'data_format' => 'body', 486 )); 487 488 // Return response 489 return $response; 490 } 491 return ''; 410 492 } 411 493 … … 430 512 $form_response = $submitted_response; 431 513 $default_form_data = $form_response[$key]['def']; 432 $meta_form_data = $form_response[$key]['meta']; 514 // $meta_form_data = $form_response[$key]['meta']; 515 $custom_form_data = $form_response[$key]['fields']; 433 516 434 517 // Prepare, format and sanitize all fields to set request body. … … 443 526 } 444 527 } 445 foreach ($meta_form_data as $single_data => $value) { 528 // foreach ($meta_form_data as $single_data => $value) { 529 // $key = self::mb4wp_make_camel_case($single_data); 530 // $request_meta[$key] = self::mb4wp_sanitize_value_of_key($single_data, $value); 531 // $request_body['meta'] = $request_meta; 532 // } 533 foreach ($custom_form_data as $single_data => $value) { 446 534 $key = self::mb4wp_make_camel_case($single_data); 447 $request_ meta[$key] = self::mb4wp_sanitize_value_of_key($single_data, $value);448 $request_body[' meta'] = $request_meta;535 $request_custom[$key] = self::mb4wp_sanitize_value_of_key($single_data, $value); 536 $request_body['fields'] = $request_custom; 449 537 } 450 538 … … 491 579 $builder_options = explode(',', sanitize_text_field(get_post_meta($post_id, 'mb4wp_form_builder_options', true))); 492 580 493 foreach($request_body['meta'] as $k => $v){ 581 // foreach($request_body['meta'] as $k => $v){ 582 583 // if('*' == substr($k, -1)){ 584 // $newKey = substr($k, 0, -1); 585 // $request_body['meta'][$newKey] = $v; 586 // // var_dump($request_body['meta'][$k]); 587 // // die; 588 // if(empty($request_body['meta'][$newKey])){ 589 // return; 590 // } 591 // unset($request_body['meta'][$k]); 592 // } 593 // } 594 595 foreach($request_body['fields'] as $k => $v){ 494 596 495 597 if('*' == substr($k, -1)){ 496 598 $newKey = substr($k, 0, -1); 497 $request_body[' meta'][$newKey] = $v;599 $request_body['fields'][$newKey] = $v; 498 600 // var_dump($request_body['meta'][$k]); 499 601 // die; 500 if(empty($request_body[' meta'][$newKey])){602 if(empty($request_body['fields'][$newKey])){ 501 603 return; 502 604 } 503 unset($request_body[' meta'][$k]);605 unset($request_body['fields'][$k]); 504 606 } 505 607 } … … 507 609 if (is_array($builder_options)) { 508 610 foreach ($builder_options as $single_field) { 509 // var_dump($single_field);510 611 if('*' === substr($single_field, -1)){ 612 511 613 $requireItem = self::mb4wp_make_camel_case(substr($single_field, 0, -1)); 512 614 foreach($request_body as $key => $value){ 513 // var_dump($key); 514 if($key == 'meta' && !empty(is_array($request_body[$key]))){ 515 // var_dump($request_body[$key]); 615 616 // if($key == 'meta' && !empty(is_array($request_body[$key]))){ 617 // foreach($request_body[$key] as $metaKey => $metaValue){ 618 619 // if($requireItem == $metaKey && empty($metaValue) ){ 620 // return; 621 // } 622 // } 623 // } 624 625 if($key == 'fields' && !empty(is_array($request_body[$key]))){ 516 626 foreach($request_body[$key] as $metaKey => $metaValue){ 627 517 628 if($requireItem == $metaKey && empty($metaValue) ){ 518 // var_dump('It is meta loop');519 629 return; 520 630 } … … 522 632 } 523 633 524 if($requireItem == $key && $key !== 'meta' && empty($value)){ 525 // var_dump($key); 634 if($requireItem == $key && $key !== 'fields' && empty($value)){ 526 635 return; 527 636 } … … 545 654 546 655 // Filter request body's meta array property 547 $request_body['meta'] = array_filter((array) $request_body['meta']); 656 // $request_body['meta'] = array_filter((array) $request_body['meta']); 657 658 // Filter request body's custom fields array property 659 $request_body['fields'] = array_filter((array) $request_body['fields']); 548 660 549 661 // Filter request body … … 586 698 </script>'; 587 699 } 700 701 // var_dump($request_body); 702 // die(); 588 703 589 704 // Return response -
mailbluster4wp/trunk/includes/class-mailbluster4wp.php
r2776930 r2789773 210 210 $this->loader->add_filter( 'manage_'.$this->post_type.'_posts_columns', $plugin_admin, 'add_custom_columns' ) ; 211 211 $this->loader->add_filter( 'post_updated_messages', $plugin_admin, 'mb4wp_cpt_updated_messages' ) ; 212 213 $this->loader->add_action('wp_ajax_mb4wp_dialog_form_process', $plugin_admin, 'mb4wp_dialog_form_process'); 214 $this->loader->add_action('admin_notices', $plugin_admin, 'mb4wp_admin_notice_dialog'); 215 212 216 } 213 217 -
mailbluster4wp/trunk/mailbluster4wp.php
r2781859 r2789773 17 17 * Plugin URI: https://mailbluster.com 18 18 * Description: A free and simple WordPress plugin for MailBluster which provides different methods to create and include subscription forms into WordPress pages or posts by utilizing AmazonSES service. 19 * Version: 1.1. 719 * Version: 1.1.8 20 20 * Tested up to: 6.0.1 21 21 * Author: MailBluster … … 37 37 * Rename this for your plugin and update it as you release new versions. 38 38 */ 39 define('MAILBLUSTER4WP_VERSION', '1.1. 7');39 define('MAILBLUSTER4WP_VERSION', '1.1.8'); 40 40 41 41 /** -
mailbluster4wp/trunk/public/class-mailbluster4wp-public.php
r2781859 r2789773 146 146 147 147 /** 148 * 148 * POST the data of the form 149 149 */ 150 150 public function mb4wp_form_process() { -
mailbluster4wp/trunk/public/js/mailbluster4wp-public.js
r2781859 r2789773 32 32 const consentCheckbox = $("#mb4wp_public_consent_checkbox"); 33 33 const subscribeButton = $("#mb4wp_subscribe"); 34 if( "disabled" === subscribeButton.attr("disabled") && subscribeButton.data("theme") !== "custom"){34 if("disabled" === subscribeButton.attr("disabled") && (subscribeButton.data("theme") === "light" || subscribeButton.data("theme") === "dark")){ 35 35 subscribeButton.css({ 36 36 "background-color": "#79AFEA", 37 "border": "1px solid #79AFEA" 37 "border": "1px solid #79AFEA", 38 "cursor": "default" 39 }) 40 } else if("disabled" === subscribeButton.attr("disabled") && subscribeButton.data("theme") === "custom"){ 41 subscribeButton.css({ 42 "opacity": ".5", 43 "cursor": "default" 38 44 }) 39 45 } … … 41 47 if (consentCheckbox.prop("checked")) { 42 48 subscribeButton.prop("disabled", false); 43 if(subscribeButton.data("theme") !== "custom"){49 if(subscribeButton.data("theme") === "light" || subscribeButton.data("theme") === "dark"){ 44 50 subscribeButton.css({ 45 51 "background-color": "#057BDE", 46 "border": "1px solid #057BDE" 52 "border": "1px solid #057BDE", 53 "cursor": "pointer" 54 }) 55 } else if(subscribeButton.data("theme") === "custom"){ 56 subscribeButton.css({ 57 "opacity": "1", 58 "cursor": "pointer" 47 59 }) 48 60 } 49 61 } else { 50 62 subscribeButton.prop("disabled", true); 51 if(subscribeButton.data("theme") !== "custom"){63 if(subscribeButton.data("theme") === "light" || subscribeButton.data("theme") === "dark"){ 52 64 subscribeButton.css({ 53 65 "background-color": "#79AFEA", 54 "border-color": "#79AFEA" 66 "border-color": "#79AFEA", 67 "cursor": "default" 68 }) 69 } else if(subscribeButton.data("theme") === "custom"){ 70 subscribeButton.css({ 71 "opacity": ".5", 72 "cursor": "default" 55 73 }) 56 74 }
Note: See TracChangeset
for help on using the changeset viewer.