Plugin Directory

Changeset 3394006


Ignore:
Timestamp:
11/12/2025 04:35:25 AM (3 months ago)
Author:
codemenschen
Message:

Version 4.5.9 - Released: November 12, 2025

Location:
gift-voucher
Files:
975 added
4 edited

Legend:

Unmodified
Added
Removed
  • gift-voucher/trunk/assets/js/voucher-template-script.js

    r3375423 r3394006  
    201201            success: function (results) {
    202202
    203                 var data = JSON.parse(results);
    204                 imagesGiftCard = data.url;
    205                 currency = data.currency;
    206                 giftto = data.giftto;
    207                 giftfrom = data.giftfrom;
    208                 date_of = data.date_of;
    209                 company_name = data.company_name;
    210                 email = data.email;
    211                 website = data.web;
    212                 expiryDate = data.expiryDate;
    213                 notice = data.leftside_notice;
    214                 counpon_label = data.counpon;
    215                 json = data.json;
     203                // Accept both WordPress-standard JSON (object with {success: true, data: {...}})
     204                // and legacy stringified JSON. Keep backwards compatibility.
     205                var payload;
     206                if (typeof results === 'object' && results !== null) {
     207                    // WP returns {success: true, data: {...}}
     208                    payload = results.data ? results.data : results;
     209                } else if (typeof results === 'string') {
     210                    try {
     211                        payload = JSON.parse(results);
     212                    } catch (e) {
     213                        // fallback: treat as empty
     214                        payload = {};
     215                    }
     216                } else {
     217                    payload = {};
     218                }
     219
     220                imagesGiftCard = payload.url || '';
     221                currency = payload.currency || '';
     222                giftto = payload.giftto || '';
     223                giftfrom = payload.giftfrom || '';
     224                date_of = payload.date_of || '';
     225                company_name = payload.company_name || '';
     226                email = payload.email || '';
     227                website = payload.web || '';
     228                expiryDate = payload.expiryDate || '';
     229                notice = payload.leftside_notice || '';
     230                counpon_label = payload.counpon || '';
     231                json = payload.json || {};
    216232
    217233                changeStepVoucher(step_voucher + 1);
  • gift-voucher/trunk/gift-voucher.php

    r3375423 r3394006  
    77 * Author: Codemenschen GmbH
    88 * Author URI: https://www.codemenschen.at/
    9  * Version: 4.5.8
     9 * Version: 4.5.9
    1010 * Text Domain: gift-voucher
    1111 * Domain Path: /languages
     
    2323if (!defined('ABSPATH')) exit;  // Exit if accessed directly
    2424
    25 define('WPGIFT_VERSION', '4.5.8');
     25// Start an early output buffer to capture any accidental output from included
     26// libraries (fonts, third-party files with closing PHP tags, etc.). We will
     27// discard this buffer on 'init' and start a fresh one to avoid leaking any
     28// characters during plugin activation.
     29if (!ob_get_level()) {
     30  ob_start();
     31  add_action('init', function () {
     32    // Discard any output generated during plugin file inclusion
     33    while (ob_get_level()) {
     34      @ob_end_clean();
     35    }
     36    // Start a fresh buffer for normal runtime output handling
     37    ob_start();
     38  });
     39}
     40
     41define('WPGIFT_VERSION', '4.5.9');
    2642define('WPGIFT__MINIMUM_WP_VERSION', '4.0');
    2743define('WPGIFT__PLUGIN_DIR', untrailingslashit(plugin_dir_path(__FILE__)));
     
    5066{
    5167  global $wpdb;
    52   $setting_table_name = $wpdb->prefix . 'giftvouchers_setting';
    53   $options = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}giftvouchers_setting WHERE id = %d", 1));
    54   if ($options->is_woocommerce_enable) {
    55     return true;
    56   } else {
     68  // Defensive: during activation/upgrade the plugin tables may not exist yet.
     69  // Check for the settings table before querying it to avoid warnings / output.
     70  $table_name = $wpdb->prefix . 'giftvouchers_setting';
     71  $table_exists = $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $wpdb->esc_like($table_name)));
     72
     73  if (!$table_exists) {
     74    // Table doesn't exist yet (activation / install context). Treat WooCommerce as disabled so
     75    // the conditional requires below won't include admin front-end files that may produce output.
    5776    return false;
    5877  }
     78
     79  $options = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$table_name} WHERE id = %d", 1));
     80  if (!$options) {
     81    return false;
     82  }
     83
     84  return !empty($options->is_woocommerce_enable);
    5985}
    6086function wpgiftv_plugin_init()
  • gift-voucher/trunk/giftcard.php

    r3375423 r3394006  
    280280function getSelectTemplateVoucher()
    281281{
     282    // Return JSON using WP helpers so the response is consistent for AJAX consumers (and nopriv users)
    282283    $setting_options = get_data_settings_voucher();
     284
     285    // Basic localized labels
    283286    $giftto = __('Gift To', 'gift-voucher');
    284287    $giftfrom = __('Gift From', 'gift-voucher');
    285     //$date_of = __('Date of Expiry', 'gift-voucher');
    286     $date_of = __('Date', 'gift-voucher');
     288    $date_of_label = __('Date', 'gift-voucher');
    287289    $counpon = __('Coupon', 'gift-voucher');
    288     $voucher_id = !empty($_POST['voucher_id']) ? sanitize_text_field(wp_unslash($_POST['voucher_id'])) : 0;
     290
     291    // Sanitize incoming voucher id
     292    $voucher_id = isset($_POST['voucher_id']) ? intval(wp_unslash($_POST['voucher_id'])) : 0;
     293
     294    // Defaults from settings
    289295    $web = !empty($setting_options->pdf_footer_url) ? $setting_options->pdf_footer_url : get_site_url();
    290     $email = !empty($setting_options->pdf_footer_email) ? $setting_options->pdf_footer_email : get_option('admin_email');;
    291     $company_name = !empty($setting_options->company_name) ? $setting_options->company_name : get_bloginfo('name');;
    292     // check expiry
    293     $wpgv_hide_expiry = get_option('wpgv_hide_expiry') ? get_option('wpgv_hide_expiry') : 'yes';
    294     $wpgv_expiry_date_format = get_option('wpgv_expiry_date_format') ? get_option('wpgv_expiry_date_format') : 'd.m.Y';
    295     $voucher_expiry_value = !empty(esc_html(get_post_meta($voucher_id, 'wpgv_customize_template_voucher_expiry_value', true))) ? esc_html(get_post_meta($voucher_id, 'wpgv_customize_template_voucher_expiry_value', true)) : $setting_options->voucher_expiry; // format day and number
    296     if ($wpgv_hide_expiry == 'no') {
     296    $email = !empty($setting_options->pdf_footer_email) ? $setting_options->pdf_footer_email : get_option('admin_email');
     297    $company_name = !empty($setting_options->company_name) ? $setting_options->company_name : get_bloginfo('name');
     298
     299    // Expiry handling
     300    $wpgv_hide_expiry = get_option('wpgv_hide_expiry', 'yes');
     301    $wpgv_expiry_date_format = get_option('wpgv_expiry_date_format', 'd.m.Y');
     302    $voucher_expiry_value = $setting_options->voucher_expiry;
     303    if ($voucher_id > 0) {
     304        $meta_val = get_post_meta($voucher_id, 'wpgv_customize_template_voucher_expiry_value', true);
     305        if ($meta_val !== '') {
     306            $voucher_expiry_value = esc_html($meta_val);
     307        }
     308    }
     309
     310    if ($wpgv_hide_expiry === 'no') {
    297311        $expiryDate = __('No Expiry', 'gift-voucher');
    298312    } else {
    299         $expiryDate = ($setting_options->voucher_expiry_type == 'days')
    300             ? gmdate($wpgv_expiry_date_format, strtotime('+' . $voucher_expiry_value . ' days', time())) . PHP_EOL
    301             : $voucher_expiry_value;
    302     }
    303     $wpgv_leftside_notice = (get_option('wpgv_leftside_notice') != '') ? get_option('wpgv_leftside_notice') : __('Cash payment is not possible. The terms and conditions apply.', 'gift-voucher');
    304 
    305     //WPGIFT__PLUGIN_URL
    306     $select_template = esc_html(get_post_meta($voucher_id, 'wpgv_customize_template_template-style', true));
    307     $title_template = str_replace(".png", ".svg", $select_template);
    308 
    309     //$images_template = !empty(get_post_meta( $voucher_id, 'wpgv_customize_template_image', true )) ? get_post_meta( $voucher_id, 'wpgv_customize_template_image', true ) : WPGIFT__PLUGIN_URL.'/assets/img/template-images/'.$title_template;
    310     $images_template = WPGIFT__PLUGIN_URL . '/assets/img/templates/svg/' . $title_template;
    311     $name_template = str_replace(".png", ".json", $select_template);
    312     $json = WPGIFT__PLUGIN_URL . '/assets/img/templates/json/' . $name_template;
    313     $response = wp_remote_get($json);
    314 
    315     if (is_wp_error($response)) {
    316         $json = '';
    317     } else {
    318         $json = wp_remote_retrieve_body($response);
    319 
    320         $json_data = json_decode($json, true);
    321     }
     313        if (!empty($setting_options->voucher_expiry_type) && $setting_options->voucher_expiry_type === 'days') {
     314            $expiryDate = gmdate($wpgv_expiry_date_format, strtotime('+' . $voucher_expiry_value . ' days', time()));
     315        } else {
     316            $expiryDate = $voucher_expiry_value;
     317        }
     318    }
     319
     320    $wpgv_leftside_notice = get_option('wpgv_leftside_notice', __('Cash payment is not possible. The terms and conditions apply.', 'gift-voucher'));
     321
     322    // Determine template and JSON path (only if voucher_id provided)
     323    $json_data = array();
     324    $images_template = '';
     325    if ($voucher_id > 0) {
     326        $select_template = get_post_meta($voucher_id, 'wpgv_customize_template_template-style', true);
     327        $select_template = is_string($select_template) ? esc_html($select_template) : '';
     328        $title_template = str_replace('.png', '.svg', $select_template);
     329        $images_template = WPGIFT__PLUGIN_URL . '/assets/img/templates/svg/' . $title_template;
     330        $name_template = str_replace('.png', '.json', $select_template);
     331        $json_url = WPGIFT__PLUGIN_URL . '/assets/img/templates/json/' . $name_template;
     332
     333        if (!empty($json_url)) {
     334            $response = wp_remote_get($json_url, array('timeout' => 5));
     335            if (!is_wp_error($response)) {
     336                $body = wp_remote_retrieve_body($response);
     337                $decoded = json_decode($body, true);
     338                if (is_array($decoded)) {
     339                    $json_data = $decoded;
     340                }
     341            } else {
     342                // Log remote fetch errors for debugging but don't expose internal details to the client
     343                error_log('wpgv: failed to fetch template json at ' . $json_url . ' - ' . $response->get_error_message());
     344            }
     345        }
     346    }
     347
    322348    $result = array(
    323349        'url' => $images_template,
    324         'currency' => $setting_options->currency,
     350        'currency' => isset($setting_options->currency) ? $setting_options->currency : '',
    325351        'giftto' => $giftto,
    326352        'giftfrom' => $giftfrom,
    327         'date_of' => $date_of,
     353        'date_of' => $date_of_label,
    328354        'company_name' => $company_name,
    329355        'email' => $email,
     
    334360        'json' => $json_data,
    335361    );
    336     echo json_encode($result);
    337     wp_die();
     362
     363    wp_send_json_success($result);
    338364}
    339365add_action('wp_ajax_ajax_select_voucher_template', 'getSelectTemplateVoucher');
  • gift-voucher/trunk/readme.txt

    r3375423 r3394006  
    44Requires at least: 4.0
    55Tested up to: 6.8.3
    6 Stable tag: 4.5.8
     6Stable tag: 4.5.9
    77Requires PHP: 5.6
    88License: GPLv2 or later
     
    226226== Changelog ==
    227227
     228= Version 4.5.9 - Released: November 12, 2025 =
     229* Fix: The plugin generated 192 characters of unexpected output during activation. If you notice "headers already sent" messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.
     230
    228231= Version 4.5.8 - Released: October 08, 2025 =
    229232* Feature: Add Quotes suggestions for Personal Message (frontend & backend).
Note: See TracChangeset for help on using the changeset viewer.