Plugin Directory

Changeset 2789773


Ignore:
Timestamp:
09/25/2022 05:41:26 AM (4 years ago)
Author:
mailbluster
Message:

v-1.1.8

Location:
mailbluster4wp/trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • mailbluster4wp/trunk/README.txt

    r2781859 r2789773  
    66Tested up to: 6.0.1
    77Requires PHP: 5.6
    8 Stable tag: 1.1.7
     8Stable tag: 1.1.8
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    7070== Changelog ==
    7171
     72= 1.1.8 =
     73* added custom fields.
     74* removed meta fields.
     75* General improvements.
     76
    7277= 1.1.7 =
    7378* Support multiple themes.
  • mailbluster4wp/trunk/admin/class-mailbluster4wp-admin.php

    r2776930 r2789773  
    155155                    false
    156156                );
     157
    157158                wp_enqueue_script(
    158159                    'clipboradjs',
     
    162163                    true
    163164                );
     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 );
    164172            }
    165173        }
     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();
    166216    }
    167217
     
    601651
    602652            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            }
    603681        }
    604682    }
     
    669747                        <p><?php echo $link; ?></p>
    670748                    </div>
    671 <?php
     749                <?php
    672750                }
    673751            }
  • mailbluster4wp/trunk/admin/css/mailbluster4wp-admin.css

    r2781859 r2789773  
    224224    font-size: 1.6em;
    225225}
     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
    226241#mb4wp-form-submit-message{
    227242    width: 400px;
    228243    max-width: 400px;
    229244}
    230 .mt-4{
     245.mb4wp-mt-4{
    231246    padding-top: 25px!important;
    232247}
     
    263278    padding: 4px 4px 9px 0px;
    264279    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}
     304button.edit_image_container{
     305    margin: 5px 0 5px 3px;
     306    align-self: stretch;
     307    padding: 0 10px;
     308    cursor: pointer;
     309}
     310button[disabled].edit_image_container{
     311    cursor: default;
     312    color: #ababab;
     313}
     314button[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;
    265410}
    266411
  • mailbluster4wp/trunk/admin/js/mailbluster4wp-form-builder.js

    r2781859 r2789773  
    108108    // console.log("after ready", arrayHiddenInput);
    109109
    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");
    129232    $predefinedButton.on("click", function () {
    130233      var hiddenVal = $hiddenInput.val(),
     
    136239      // console.log($hiddenInput.val());
    137240      $(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        }
    138245    });
    139246
     
    178285      })
    179286
    180       // var currentItemInputPlaceholder = $currentCloseItem
    181       //   .find("input")
    182       //   .attr("placeholder");
    183       // console.log('currentItemInputId ',currentItemInputId);
    184287      if (currentItemInputId !== "email") {
    185288        var removeItem = "";
     
    197300        }
    198301
    199         // console.log(plainArrayHiddenInput, arrayHiddenInput)
    200         // console.log('before removing item', arrayHiddenInput);
    201 
    202302        // console.log('remove Item', removeItem);
    203303        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        }
    207310        // console.log("after close arrayHiddenInput", arrayHiddenInput);
    208311        $hiddenInput.val(arrayHiddenInput.toString());
     
    210313      }
    211314    });
    212     // console.log($hiddenInput.val());
    213315    $sortable.sortable({
    214316      // revert: true,
     
    219321        arrayHiddenInput.splice(dataStart, 1);
    220322        arrayHiddenInput.splice(dataUpdate, 0, dataItem);
    221         // console.log('update: '+ui.item.index());
    222         // console.log("in update", arrayHiddenInput);
    223323        $hiddenInput.val(arrayHiddenInput.toString());
    224324      },
     
    226326        var dataStart = ui.item.index();
    227327        ui.item.data("start_pos", dataStart);
    228         // console.log('start: '+ui.item.index());
    229328      },
    230329    });
    231330    $sortable.disableSelection();
    232     $(document).on("click", ".requred-field", function () {
     331    $(document).on("click", ".required-field", function () {
    233332      var hiddenVal = $hiddenInput.val();
    234333
     
    237336      const itemInputId = currentCloseParent.find($('.regular-text')).attr('id');
    238337
    239       // console.log(itemInputId)
    240338      let itemLabel = currentCloseParent.find($('.mb4wp-label'));
    241339      if(checkbox.prop('checked')){
     
    244342        }
    245343        itemLabel.text(itemLabel.text() + '*');
    246         // console.log("got position")
    247344        const updatedHiddenVal = hiddenVal.replace(itemInputId, itemInputId + '*');
    248345        $hiddenInput.val(updatedHiddenVal);
    249 
    250         // console.log(itemLabel)
    251346      } else {
    252         // else er moddhe kichu likhlam
    253347        const updatedHiddenVal = hiddenVal.replace(itemInputId + '*', itemInputId);
    254348        $hiddenInput.val(updatedHiddenVal)
     
    256350            itemLabel.text(itemLabel.text().slice(0,-1));
    257351          }
    258         // console.log('not checked')
    259352      }
    260353    })
    261354  });
     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  }
    262437
    263438  function renderHTML(clickFieldValue, readonly) {
     
    286461    }
    287462    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>`
    297475    );
    298476  }
     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  }
    299484})(jQuery);
  • mailbluster4wp/trunk/admin/partials/form-options/builder.php

    r2781859 r2789773  
    33$form_input_field = get_post_meta($post_id, 'mb4wp_form_builder_options', true);
    44$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 = [];
     7foreach($custom_field->fields as $v){
     8    array_push($newArr, $v->fieldLabel);
     9};
     10$newArrStr = implode(",", $newArr);
    511?>
    612<div class="mb4wp-container builder">
     
    1420                    <button type="button" id="mb4wp-builder-first-name" class="mb4wp-field-button" value="first_name"><?php esc_html_e('First Name', 'mailbluster4wp'); ?></button>
    1521                    <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"/>
    2437                </div>
    2538            </div>
     
    7689                                    <?php } ?>
    7790                                    <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">
    7999                                        <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' : '' ?>>
    80100                                        <label for="<?php echo esc_attr('required_' . $modified_single_field); ?>">Required field</label><br>
  • mailbluster4wp/trunk/admin/partials/form-options/settings.php

    r2781859 r2789773  
    3535                    <label for="mb4wp-form-consent-checkbox"><?php esc_attr_e('Consent', 'mailbluster4wp'); ?></label>
    3636                </th>
    37                 <td class="mt-4">
     37                <td class="mb4wp-mt-4">
    3838                    <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") ?>>
    3939                    <label class="" for="mb4wp-form-consent-checkbox"><?php esc_html_e('Include a consent checkbox', 'mailbluster4wp'); ?></label>
     
    4545                    <label for="mb4wp-form-redirectURL"><?php esc_attr_e('Redirect URL', 'mailbluster4wp'); ?></label>
    4646                </th>
    47                 <td class="mt-4">
     47                <td class="mb4wp-mt-4">
    4848                    <input type="checkbox" id="mb4wp-form-redirectURL" class="regular-text" name="mb4wp_form_settings_options[redirectURL]" value="yes" <?php checked($form_redirectURL_settings, "yes") ?>>
    4949                    <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  
    211211        } else {
    212212            ob_start();
    213 ?>
     213        ?>
    214214            <div class="alert alert-warning">
    215215                <p><?php esc_html_e('Currently the form is not available.', 'mailbluster4wp'); ?></p>
     
    261261        $appearance_btnText_size        =  self::mb4wp_get_appearance_by_key('btnText_size', $post_id);
    262262        $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);
    263265
    264266        // Get form branding
     
    282284                if (isset($show_consent_checkbox) && ($show_consent_checkbox == 'yes')) {
    283285                ?>
    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                    >
    285290                        <input type="checkbox" id="mb4wp_public_consent_checkbox">
    286291                        <label
     
    293298                <div class="mb4wp-form-group">
    294299                    <button
    295                         <?php echo $appearance_theme === 'custom' ? 'data-theme=custom' : ''; ?>
     300                        <?php echo "data-theme=$appearance_theme"; ?>
    296301                        type="submit"
    297302                        id="mb4wp_subscribe"
     
    346351     * @return array
    347352     */
    348     private static function mb4wp_process_form_input_fields($post_id)
    349     {
     353    private static function mb4wp_process_form_input_fields($post_id){
    350354
    351355        // Get all form fields
     
    356360        $prefix_n_ar = $prefix_s . intval($post_id);
    357361
     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       
    358369        // Prepare single form fields input attributes
    359370        $form_detailed = array();
     
    368379                $single_field_str = $single_field;
    369380            }
    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                }
    407429            }
    408430        }
    409431        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 '';
    410492    }
    411493
     
    430512            $form_response = $submitted_response;
    431513            $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'];
    433516
    434517            // Prepare, format and sanitize all fields to set request body.
     
    443526                }
    444527            }
    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) {
    446534                $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;
    449537            }
    450538
     
    491579        $builder_options = explode(',', sanitize_text_field(get_post_meta($post_id, 'mb4wp_form_builder_options', true)));
    492580
    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){
    494596
    495597            if('*' == substr($k, -1)){
    496598                $newKey = substr($k, 0, -1);
    497                 $request_body['meta'][$newKey] = $v;
     599                $request_body['fields'][$newKey] = $v;
    498600                // var_dump($request_body['meta'][$k]);
    499601                // die;
    500                 if(empty($request_body['meta'][$newKey])){
     602                if(empty($request_body['fields'][$newKey])){
    501603                    return;
    502604                }
    503                 unset($request_body['meta'][$k]);
     605                unset($request_body['fields'][$k]);
    504606            }
    505607        }
     
    507609        if (is_array($builder_options)) {
    508610            foreach ($builder_options as $single_field) {
    509                 // var_dump($single_field);
    510611                if('*' === substr($single_field, -1)){
     612
    511613                    $requireItem = self::mb4wp_make_camel_case(substr($single_field, 0, -1));
    512614                    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]))){
    516626                            foreach($request_body[$key] as $metaKey => $metaValue){
     627
    517628                                if($requireItem == $metaKey && empty($metaValue) ){
    518                                     // var_dump('It is meta loop');
    519629                                    return;
    520630                                }
     
    522632                        }
    523633
    524                         if($requireItem == $key && $key !== 'meta' && empty($value)){
    525                             // var_dump($key);
     634                        if($requireItem == $key && $key !== 'fields' && empty($value)){
    526635                            return;
    527636                        }
     
    545654
    546655        // 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']);
    548660
    549661        // Filter request body
     
    586698                </script>';
    587699            }
     700
     701            // var_dump($request_body);
     702            // die();
    588703
    589704            // Return response
  • mailbluster4wp/trunk/includes/class-mailbluster4wp.php

    r2776930 r2789773  
    210210        $this->loader->add_filter( 'manage_'.$this->post_type.'_posts_columns', $plugin_admin, 'add_custom_columns' ) ;
    211211        $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
    212216    }
    213217
  • mailbluster4wp/trunk/mailbluster4wp.php

    r2781859 r2789773  
    1717 * Plugin URI:        https://mailbluster.com
    1818 * 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.7
     19 * Version:           1.1.8
    2020 * Tested up to:      6.0.1
    2121 * Author:            MailBluster
     
    3737 * Rename this for your plugin and update it as you release new versions.
    3838 */
    39 define('MAILBLUSTER4WP_VERSION', '1.1.7');
     39define('MAILBLUSTER4WP_VERSION', '1.1.8');
    4040
    4141/**
  • mailbluster4wp/trunk/public/class-mailbluster4wp-public.php

    r2781859 r2789773  
    146146
    147147    /**
    148      *
     148     * POST the data of the form
    149149     */
    150150    public function mb4wp_form_process() {
  • mailbluster4wp/trunk/public/js/mailbluster4wp-public.js

    r2781859 r2789773  
    3232    const consentCheckbox = $("#mb4wp_public_consent_checkbox");
    3333    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")){
    3535      subscribeButton.css({
    3636        "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"
    3844      })
    3945    }
     
    4147      if (consentCheckbox.prop("checked")) {
    4248        subscribeButton.prop("disabled", false);
    43         if(subscribeButton.data("theme") !== "custom"){
     49        if(subscribeButton.data("theme") === "light" || subscribeButton.data("theme") === "dark"){
    4450          subscribeButton.css({
    4551            "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"
    4759          })
    4860        }
    4961      } else {
    5062        subscribeButton.prop("disabled", true);
    51         if(subscribeButton.data("theme") !== "custom"){
     63        if(subscribeButton.data("theme") === "light" || subscribeButton.data("theme") === "dark"){
    5264          subscribeButton.css({
    5365            "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"
    5573          })
    5674        }
Note: See TracChangeset for help on using the changeset viewer.