Changeset 3295993
- Timestamp:
- 05/18/2025 10:40:14 PM (9 months ago)
- Location:
- sign-customiser
- Files:
-
- 10 added
- 7 edited
-
tags/1.5.0 (added)
-
tags/1.5.0/.gitignore (added)
-
tags/1.5.0/api.php (added)
-
tags/1.5.0/bootstrap.php (added)
-
tags/1.5.0/cart.php (added)
-
tags/1.5.0/config.php (added)
-
tags/1.5.0/orders.php (added)
-
tags/1.5.0/readme.txt (added)
-
tags/1.5.0/settings.php (added)
-
tags/1.5.0/sign-customiser.php (added)
-
trunk/.gitignore (modified) (1 diff)
-
trunk/api.php (modified) (3 diffs)
-
trunk/bootstrap.php (modified) (1 diff)
-
trunk/cart.php (modified) (12 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/settings.php (modified) (4 diffs)
-
trunk/sign-customiser.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sign-customiser/trunk/.gitignore
r3183468 r3295993 1 1 config.php 2 debug.txt -
sign-customiser/trunk/api.php
r3183468 r3295993 1 1 <?php 2 2 3 function spcwp_remote_post($path, $body = [], $headers = [] ) {3 function spcwp_remote_post($path, $body = [], $headers = [], $opts = []) { 4 4 $apiKey = spcwp_get_api_key(); 5 5 … … 15 15 } 16 16 17 return wp_remote_post("{$apiBase}/{$path}", [17 return wp_remote_post("{$apiBase}/{$path}", array_merge($opts, [ 18 18 'body' => json_encode($body), 19 19 'headers' => array_merge($headers, [ … … 23 23 'X-API-Client' => 'woocommerce', 24 24 ]), 25 ]) ;25 ])); 26 26 } -
sign-customiser/trunk/bootstrap.php
r3275164 r3295993 40 40 HTML; 41 41 } 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 } 42 50 }); 43 51 -
sign-customiser/trunk/cart.php
r3272826 r3295993 11 11 12 12 function 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 13 51 $data = $request['product']; 14 52 … … 24 62 $product->add_meta_data('_hide_from_search_engines', '1'); 25 63 26 $upload = function ($base64, $ext = '.png') { 64 $log("Product properties set"); 65 66 $upload = function ($base64, $ext = '.png') use ($log) { 27 67 $upload_dir = wp_upload_dir(); 28 68 $image_data = base64_decode($base64); 69 $log("Decoded base64"); 70 29 71 $dir = $upload_dir['path'] . '/sign-customiser/'; 30 72 $filename = $dir . uniqid() . $ext; … … 32 74 $fs = new WP_Filesystem_Direct( true ); 33 75 $fs->put_contents($filename, $image_data); 76 $log("Wrote decoded image to disk"); 34 77 35 78 $filetype = wp_check_filetype(basename($filename), null); … … 41 84 ]; 42 85 $attach_id = wp_insert_attachment($attachment, $filename); 86 $log("Inserted attachment"); 43 87 $file = get_attached_file($attach_id); 44 88 $attach_data = wp_generate_attachment_metadata($attach_id, $file); 89 $log("Generated attachment metadata"); 45 90 wp_update_attachment_metadata($attach_id, $attach_data); 91 $log("Updated attachment metadata"); 46 92 47 93 return $attach_id; … … 54 100 55 101 if (!empty($data['productImage'])) { 102 $log("Begin product image"); 56 103 $imageId = $upload($data['productImage']); 57 104 $product->set_image_id($imageId); … … 60 107 } 61 108 if (!empty($data['productImageWhite'])) { 109 $log("Begin product image white"); 62 110 $imageId = $upload($data['productImageWhite']); 63 111 $product->add_meta_data('spcwp_white_image_id', $imageId); … … 65 113 } 66 114 if (!empty($request['svg'])) { 115 $log("Begin svg"); 67 116 $imageId = $upload(base64_encode($request['svg']), '.svg'); 68 117 $product->add_meta_data('spcwp_svg_image_id', $imageId); 69 118 } 70 119 if (!empty($data['customBackground'])) { 120 $log("Begin custom background"); 71 121 $imageId = $upload($data['customBackground'], '.jpeg'); 72 122 $product->add_meta_data('spcwp_custom_background_image_id', $imageId); … … 75 125 } 76 126 if (!empty($data['customBackgroundOriginal'])) { 127 $log("Begin custom background original"); 77 128 $imageId = $upload($data['customBackgroundOriginal'], '.jpeg'); 78 129 $product->add_meta_data('spcwp_custom_background_original_image_id', $imageId); … … 81 132 } 82 133 if (!empty($data['productTypeImageUrls'])) { 134 $log("Begin product type images"); 83 135 foreach ($data['productTypeImageUrls'] as $part => $arr) { 84 136 foreach (['cropped', 'original'] as $variant) { … … 100 152 } 101 153 154 $log("Before product save"); 155 102 156 $id = $product->save(); 157 158 $log("Product saved"); 103 159 104 160 wp_set_object_terms($id, 'SignCustomiser', 'product_tag'); … … 111 167 112 168 if ($customiserId) { 169 $log("Sending /products request"); 113 170 spcwp_remote_post("/api/customisers/{$customiserId}/products", [ 114 171 'product_id' => strval($id), … … 118 175 'custom_background_original_path' => $customBackgroundOriginalUrl, 119 176 'product_type_paths' => $productTypePaths 177 ], [], [ 178 'blocking' => false, 120 179 ]); 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); 121 187 } 122 188 123 189 return rest_ensure_response(['product_id' => $id]); 124 190 } 191 125 192 126 193 add_action('rest_api_init', function () { -
sign-customiser/trunk/readme.txt
r3294469 r3295993 3 3 Tested up to: 6.6.1 4 4 Requires at least: 6.5 5 Stable tag: 1. 4.15 Stable tag: 1.5.0 6 6 Requires PHP: 7.4 7 7 License: GPLv2 or later … … 63 63 == Changelog == 64 64 65 = 1.5.0 = 66 * Added a debug mode to help resolve performance issues. 67 65 68 = 1.4.1 = 66 69 * Fixes an issue where the customers last name did not appear in orders. -
sign-customiser/trunk/settings.php
r3183468 r3295993 32 32 function spcwp_register_settings() { 33 33 register_setting('spcwp_settings_group', 'spcwp_api_key'); 34 register_setting('spcwp_settings_group', 'spcwp_debug'); 34 35 35 36 add_settings_section( … … 44 45 'API Key', 45 46 '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', 46 55 'spcwp-settings', 47 56 'spcwp_main_section' … … 60 69 } 61 70 62 // Callback for the API Key field63 71 function spcwp_api_key_callback() { 64 72 $api_key = get_option('spcwp_api_key'); 65 73 echo '<input type="text" name="spcwp_api_key" value="' . esc_attr($api_key) . '" class="regular-text" />'; 74 } 75 76 function 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} />"; 66 80 } 67 81 … … 70 84 return get_option('spcwp_api_key', ''); 71 85 } 86 87 function spcwp_get_debug() { 88 return get_option('spcwp_debug') === 'true'; 89 } -
sign-customiser/trunk/sign-customiser.php
r3294469 r3295993 4 4 Plugin Name: Sign Customiser 5 5 Plugin URI: https://signcustomiser.com 6 Version: 1. 4.16 Version: 1.5.0 7 7 Requires Plugins: woocommerce 8 8 License: GPL v2 or later … … 24 24 require_once 'config.php'; 25 25 require_once 'bootstrap.php'; 26 require_once 'settings.php'; 26 27 require_once 'api.php'; 27 28 require_once 'cart.php'; 28 require_once 'settings.php';29 29 require_once 'orders.php';
Note: See TracChangeset
for help on using the changeset viewer.