Plugin Directory

Changeset 3295993


Ignore:
Timestamp:
05/18/2025 10:40:14 PM (9 months ago)
Author:
signcustomiser
Message:

Release version 1.5.0

Location:
sign-customiser
Files:
10 added
7 edited

Legend:

Unmodified
Added
Removed
  • sign-customiser/trunk/.gitignore

    r3183468 r3295993  
    11config.php
     2debug.txt
  • sign-customiser/trunk/api.php

    r3183468 r3295993  
    11<?php
    22
    3 function spcwp_remote_post($path, $body = [], $headers = []) {
     3function spcwp_remote_post($path, $body = [], $headers = [], $opts = []) {
    44  $apiKey = spcwp_get_api_key();
    55
     
    1515  }
    1616
    17   return wp_remote_post("{$apiBase}/{$path}", [
     17  return wp_remote_post("{$apiBase}/{$path}", array_merge($opts, [
    1818    'body' => json_encode($body),
    1919    'headers' => array_merge($headers, [
     
    2323      'X-API-Client' => 'woocommerce',
    2424    ]),
    25   ]);
     25  ]));
    2626}
  • sign-customiser/trunk/bootstrap.php

    r3275164 r3295993  
    4040  HTML;
    4141  }
     42
     43  if (get_option('spcwp_debug') === 'true') {
     44    echo <<<HTML
     45    <div class="notice notice-warning is-dismissible">
     46      <p>You have debug mode enabled for Sign Customiser. This is intended for support reasons only and should be turned off when done debugging.</p>
     47    </div>
     48  HTML;
     49  }
    4250});
    4351
  • sign-customiser/trunk/cart.php

    r3272826 r3295993  
    1111
    1212function spcwp_product_callback($request) {
     13  $start_time = null;
     14  $last_time = null;
     15  $logs = [];
     16
     17  $debug = spcwp_get_debug();
     18
     19  $log = function($step_name, $reset = false) use ($debug, &$start_time, &$last_time, &$logs) {
     20    if (!$debug) {
     21      return;
     22    }
     23
     24    // Get current time
     25    $current_time = microtime(true);
     26
     27    // Initialize start time if not set or reset requested
     28    if ($start_time === null || $reset) {
     29      $start_time = $current_time;
     30      $last_time = $current_time;
     31      $time_since_start = 0;
     32      $time_since_last = 0;
     33    } else {
     34      $time_since_start = $current_time - $start_time;
     35      $time_since_last = $current_time - $last_time;
     36      $last_time = $current_time;
     37    }
     38
     39    // Format the log entry
     40    $logs[] = sprintf(
     41      "[%s] %s - Time since start: %.4f sec, Time since last step: %.4f sec",
     42      date('Y-m-d H:i:s'),
     43      $step_name,
     44      $time_since_start,
     45      $time_since_last
     46    );
     47  };
     48
     49  $log("Starting product create", true);
     50
    1351  $data = $request['product'];
    1452
     
    2462  $product->add_meta_data('_hide_from_search_engines', '1');
    2563
    26   $upload = function ($base64, $ext = '.png') {
     64  $log("Product properties set");
     65
     66  $upload = function ($base64, $ext = '.png') use ($log) {
    2767    $upload_dir = wp_upload_dir();
    2868    $image_data = base64_decode($base64);
     69    $log("Decoded base64");
     70
    2971    $dir = $upload_dir['path'] . '/sign-customiser/';
    3072    $filename = $dir . uniqid() . $ext;
     
    3274    $fs = new WP_Filesystem_Direct( true );
    3375    $fs->put_contents($filename, $image_data);
     76    $log("Wrote decoded image to disk");
    3477
    3578    $filetype = wp_check_filetype(basename($filename), null);
     
    4184    ];
    4285    $attach_id = wp_insert_attachment($attachment, $filename);
     86    $log("Inserted attachment");
    4387    $file = get_attached_file($attach_id);
    4488    $attach_data = wp_generate_attachment_metadata($attach_id, $file);
     89    $log("Generated attachment metadata");
    4590    wp_update_attachment_metadata($attach_id, $attach_data);
     91    $log("Updated attachment metadata");
    4692
    4793    return $attach_id;
     
    54100
    55101  if (!empty($data['productImage'])) {
     102    $log("Begin product image");
    56103    $imageId = $upload($data['productImage']);
    57104    $product->set_image_id($imageId);
     
    60107  }
    61108  if (!empty($data['productImageWhite'])) {
     109    $log("Begin product image white");
    62110    $imageId = $upload($data['productImageWhite']);
    63111    $product->add_meta_data('spcwp_white_image_id', $imageId);
     
    65113  }
    66114  if (!empty($request['svg'])) {
     115    $log("Begin svg");
    67116    $imageId = $upload(base64_encode($request['svg']), '.svg');
    68117    $product->add_meta_data('spcwp_svg_image_id', $imageId);
    69118  }
    70119  if (!empty($data['customBackground'])) {
     120    $log("Begin custom background");
    71121    $imageId = $upload($data['customBackground'], '.jpeg');
    72122    $product->add_meta_data('spcwp_custom_background_image_id', $imageId);
     
    75125  }
    76126  if (!empty($data['customBackgroundOriginal'])) {
     127    $log("Begin custom background original");
    77128    $imageId = $upload($data['customBackgroundOriginal'], '.jpeg');
    78129    $product->add_meta_data('spcwp_custom_background_original_image_id', $imageId);
     
    81132  }
    82133  if (!empty($data['productTypeImageUrls'])) {
     134    $log("Begin product type images");
    83135    foreach ($data['productTypeImageUrls'] as $part => $arr) {
    84136      foreach (['cropped', 'original'] as $variant) {
     
    100152  }
    101153
     154  $log("Before product save");
     155
    102156  $id = $product->save();
     157
     158  $log("Product saved");
    103159
    104160  wp_set_object_terms($id, 'SignCustomiser', 'product_tag');
     
    111167
    112168  if ($customiserId) {
     169    $log("Sending /products request");
    113170    spcwp_remote_post("/api/customisers/{$customiserId}/products", [
    114171      'product_id' => strval($id),
     
    118175      'custom_background_original_path' => $customBackgroundOriginalUrl,
    119176      'product_type_paths' => $productTypePaths
     177    ], [], [
     178      'blocking' => false,
    120179    ]);
     180  }
     181
     182  $log("Product saved: " . strval($id));
     183
     184  if ($debug) {
     185    $log_file = dirname(__FILE__) . '/debug.txt';
     186    file_put_contents($log_file, implode(PHP_EOL, $logs), FILE_APPEND);
    121187  }
    122188
    123189  return rest_ensure_response(['product_id' => $id]);
    124190}
     191
    125192
    126193add_action('rest_api_init', function () {
  • sign-customiser/trunk/readme.txt

    r3294469 r3295993  
    33Tested up to: 6.6.1
    44Requires at least: 6.5
    5 Stable tag: 1.4.1
     5Stable tag: 1.5.0
    66Requires PHP: 7.4
    77License: GPLv2 or later
     
    6363== Changelog ==
    6464
     65= 1.5.0 =
     66* Added a debug mode to help resolve performance issues.
     67
    6568= 1.4.1 =
    6669* Fixes an issue where the customers last name did not appear in orders.
  • sign-customiser/trunk/settings.php

    r3183468 r3295993  
    3232function spcwp_register_settings() {
    3333  register_setting('spcwp_settings_group', 'spcwp_api_key');
     34  register_setting('spcwp_settings_group', 'spcwp_debug');
    3435
    3536  add_settings_section(
     
    4445    'API Key',
    4546    'spcwp_api_key_callback',
     47    'spcwp-settings',
     48    'spcwp_main_section'
     49  );
     50
     51  add_settings_field(
     52    'spcwp_debug',
     53    'Debug Mode',
     54    'spcwp_debug_callback',
    4655    'spcwp-settings',
    4756    'spcwp_main_section'
     
    6069}
    6170
    62 // Callback for the API Key field
    6371function spcwp_api_key_callback() {
    6472  $api_key = get_option('spcwp_api_key');
    6573  echo '<input type="text" name="spcwp_api_key" value="' . esc_attr($api_key) . '" class="regular-text" />';
     74}
     75
     76function spcwp_debug_callback() {
     77  $checked = get_option('spcwp_debug');
     78  $checkedAttr = $checked === 'true' ? ' checked="checked" ' : '';
     79  echo "<input type=\"checkbox\" name=\"spcwp_debug\" value=\"true\" {$checkedAttr} />";
    6680}
    6781
     
    7084  return get_option('spcwp_api_key', '');
    7185}
     86
     87function spcwp_get_debug() {
     88  return get_option('spcwp_debug') === 'true';
     89}
  • sign-customiser/trunk/sign-customiser.php

    r3294469 r3295993  
    44Plugin Name: Sign Customiser
    55Plugin URI: https://signcustomiser.com
    6 Version: 1.4.1
     6Version: 1.5.0
    77Requires Plugins: woocommerce
    88License: GPL v2 or later
     
    2424require_once 'config.php';
    2525require_once 'bootstrap.php';
     26require_once 'settings.php';
    2627require_once 'api.php';
    2728require_once 'cart.php';
    28 require_once 'settings.php';
    2929require_once 'orders.php';
Note: See TracChangeset for help on using the changeset viewer.