• When the Woo Checkout Field Editor Pro plugin is activated, a JavaScript error occurs on the plugins page wp-admin/plugins.php. The error message in the browser console is as follows:

    Uncaught SyntaxError: Unexpected string (at plugins.php:5381:89)

    This error is caused by the following line of code in the plugin:

    reason_input += '<option value="' . esc_attr(HOUR_IN_SECONDS) . '">1 Hour</option>';

    The issue arises because the HOUR_IN_SECONDS constant is not properly replaced with a numeric value when the HTML is generated by PHP. As a result, the client-side code fails due to a syntax error.

    Path to the Problematic Code:

    Plugin file: plugins\woo-checkout-field-editor-pro\includes\class-thwcfd.php

    Code lines (387–392):

    reason_input += '<label for="th-snooze">Snooze this panel while troubleshooting</label>';
    reason_input += '<select name="th-snooze-time" class="th-snooze-select" disabled>';
    reason_input += '<option value="' . esc_attr(HOUR_IN_SECONDS) . '">1 Hour</option>';
    reason_input += '<option value="' . esc_attr(12 * HOUR_IN_SECONDS) . '">12 Hour</option>';
    reason_input += '<option value="' . esc_attr(DAY_IN_SECONDS) . '">24 Hour</option>';
    reason_input += '<option value="' . esc_attr(WEEK_IN_SECONDS) . '">1 Week</option>';

    Cause of the Issue:

    PHP constants like HOUR_IN_SECONDS are not interpolated correctly in JavaScript. These constants need to be evaluated on the server side and passed as specific numeric values.

    Solution:

    To resolve this issue, the code should be modified so that the PHP constants are passed into JavaScript as numbers. For example:

    <script type="text/javascript">
    (function($){
    var popup = $("#thwcfd_deactivation_form");
    var deactivation_link = '';
    $('.thwcfd-deactivate-link').on('click', function(e){
    e.preventDefault();
    deactivation_link = $(this).attr('href');
    popup.css("display", "block");
    popup.find('a.thwcfd-deactivate').attr('href', deactivation_link);
    });

    popup.on('click', 'input[type="radio"]', function () {
    var parent = $(this).parents('li:first');
    popup.find('.reason-input').remove();

    var type = parent.data('type');
    var placeholder = parent.data('placeholder');

    var reason_input = '';
    if('text' == type){
    reason_input += '<div class="reason-input">';
    reason_input += '<input type="text" placeholder="'+ placeholder +'">';
    reason_input += '</div>';
    }else if('textarea' == type){
    reason_input += '<div class="reason-input">';
    reason_input += '<textarea row="5" placeholder="'+ placeholder +'">';
    reason_input += '</textarea>';
    reason_input += '</div>';
    }else if('checkbox' == type){
    reason_input += '<div class="reason-input ">';
    reason_input += '<input type="checkbox" id="th-snooze" name="th-snooze" class="th-snooze-checkbox">';
    reason_input += '<label for="th-snooze">Snooze this panel while troubleshooting</label>';
    reason_input += '<select name="th-snooze-time" class="th-snooze-select" disabled>';
    // PHP constants will be output here as actual values
    reason_input += '<option value="' + <?php echo HOUR_IN_SECONDS; ?> + '">1 Hour</option>';
    reason_input += '<option value="' + <?php echo 12 * HOUR_IN_SECONDS; ?> + '">12 Hour</option>';
    reason_input += '<option value="' + <?php echo DAY_IN_SECONDS; ?> + '">24 Hour</option>';
    reason_input += '<option value="' + <?php echo WEEK_IN_SECONDS; ?> + '">1 Week</option>';
    reason_input += '<option value="' + <?php echo MONTH_IN_SECONDS; ?> + '">1 Month</option>';
    reason_input += '</select>';
    reason_input += '</div>';
    }else if('reviewlink' == type){
    reason_input += '<div class="reason-input wcfe-review-link">';
    reason_input += '<input type="hidden" value="<?php esc_html_e('Upgraded', 'woo-checkout-field-editor-pro');?>">';
    reason_input += '</div>';
    }

    if(reason_input !== ''){
    parent.append($(reason_input));
    }
    });

    popup.on('click', '.thwcfd-close', function () {
    popup.css("display", "none");
    });

    popup.on('click', '.thwcfd-submit-deactivate', function (e) {
    e.preventDefault();
    var button = $(this);
    if (button.hasClass('disabled')) {
    return;
    }
    var radio = $('.deactivation-reason input[type="radio"]:checked');
    var parent_li = radio.parents('li:first');
    var parent_ul = radio.parents('ul:first');
    var input = parent_li.find('textarea, input[type="text"], input[type="hidden"]');
    var wcfe_deacive_nonce = parent_ul.data('nonce');

    $.ajax({
    url: ajaxurl,
    type: 'POST',
    data: {
    action: 'thwcfd_deactivation_reason',
    reason: (0 === radio.length) ? 'none' : radio.val(),
    comments: (0 !== input.length) ? input.val().trim() : '',
    security: wcfe_deacive_nonce,
    },
    beforeSend: function () {
    button.addClass('disabled');
    button.text('Processing...');
    },
    complete: function () {
    window.location.href = deactivation_link;
    }
    });
    });

    popup.on('click', '#th-snooze', function () {
    if($(this).is(':checked')){
    popup.find('.th-snooze-select').prop("disabled", false);
    }else{
    popup.find('.th-snooze-select').prop("disabled", true);
    }
    });

    }(jQuery))
    </script>

    The esc_attr(HOUR_IN_SECONDS) should be replaced with the actual numeric value of the constant, possibly by passing it through Ajax or another method of server-client interaction.

    Recommendation for Plugin Developers:

    1. Correct the handling of PHP constants in JavaScript by passing them as numbers.
    2. Ensure that all values that need to be calculated on the server are passed to JavaScript correctly.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Dina S.

    (@themehighsupport)

    Thank you for bringing this issue to our attention. We appreciate your feedback and have forwarded the details to our development team. They will make the necessary changes to address this problem in the upcoming version of the plugin.

    If you have any further questions or need assistance, please don’t hesitate to reach out.

    Thank you!

    Thread Starter Marcus Karlos

    (@power2009)

    I hope u help that, i fix your script and my issues is resolved

    Plugin Author ThemeHigh

    (@themehigh)

    Sure!

    Great! I’m glad to hear that you were able to resolve the issue on your end.

    Thank you!

    Thread Starter Marcus Karlos

    (@power2009)

    Yes, but you need to make these changes in the update so that I don’t have to manually edit your code every time, otherwise I will refuse to use the plugin.

    Plugin Support Dina S.

    (@themehighsupport)

    As we mentioned in our previous update, we’ve already forwarded the details to our development team. They are working on implementing the necessary changes to address this problem, and we will include the fix in the upcoming version of the plugin. This should prevent the need for any manual adjustments moving forward.

    We truly appreciate your patience and understanding.

    Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.