Changeset 3454451
- Timestamp:
- 02/05/2026 10:12:12 AM (8 weeks ago)
- Location:
- preview-ai/trunk
- Files:
-
- 7 edited
-
admin/class-preview-ai-admin-settings.php (modified) (2 diffs)
-
admin/partials/preview-ai-admin-display.php (modified) (2 diffs)
-
preview-ai.php (modified) (2 diffs)
-
public/class-preview-ai-public.php (modified) (1 diff)
-
public/js/preview-ai-api.js (modified) (2 diffs)
-
public/js/preview-ai-storage.js (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
preview-ai/trunk/admin/class-preview-ai-admin-settings.php
r3446676 r3454451 17 17 register_setting( 'preview_ai_general_settings', 'preview_ai_api_key', 'sanitize_text_field' ); 18 18 register_setting( 'preview_ai_general_settings', 'preview_ai_enabled', 'absint' ); 19 register_setting( 20 'preview_ai_general_settings', 21 'preview_ai_max_previews_per_user_weekly', 22 array( 23 'type' => 'integer', 24 'sanitize_callback' => 'absint', 25 'default' => 8, 26 ) 27 ); 19 28 20 29 // Widget settings group. … … 76 85 77 86 /** 87 * Get maximum previews allowed per user per week. 88 * 89 * @return int Maximum number of previews per user per week. 90 */ 91 public static function get_max_previews_per_user_weekly() { 92 return absint( get_option( 'preview_ai_max_previews_per_user_weekly', 8 ) ); 93 } 94 95 /** 78 96 * Get available product types for AI context. 79 97 */ -
preview-ai/trunk/admin/partials/preview-ai-admin-display.php
r3446676 r3454451 209 209 </tr> 210 210 211 <!-- Max Previews Per User Weekly --> 212 <tr> 213 <th scope="row"> 214 <label for="preview_ai_max_previews_per_user_weekly"> 215 <?php esc_html_e( 'Max Previews Per User (Weekly)', 'preview-ai' ); ?> 216 </label> 217 </th> 218 <td> 219 <input type="number" 220 id="preview_ai_max_previews_per_user_weekly" 221 name="preview_ai_max_previews_per_user_weekly" 222 value="<?php echo esc_attr( PREVIEW_AI_Admin_Settings::get_max_previews_per_user_weekly() ); ?>" 223 class="small-text" 224 min="1" 225 step="1" 226 /> 227 <p class="description"> 228 <?php esc_html_e( 'Maximum number of previews each visitor can generate per week. Default: 8.', 'preview-ai' ); ?> 229 </p> 230 </td> 231 </tr> 232 211 233 <!-- API Key --> 212 234 <tr> … … 303 325 <?php esc_html_e( 'Preview AI will automatically detect what type of product each one is (t-shirts, dresses, belts, earrings, fanny packs…).', 'preview-ai' ); ?> 304 326 <br><strong> 305 <?php esc_html_e( 'This is necessary to generate much more precise previews without manual configuration.', 'preview-ai' ); ?></strong>327 <?php esc_html_e( 'This will analyze your catalog and assign the appropriate product type to each product.', 'preview-ai' ); ?></strong> 306 328 </p> 307 329 <p class="preview-ai-catalog-note"> -
preview-ai/trunk/preview-ai.php
r3447207 r3454451 10 10 * Plugin URI: https://previewai.app/ 11 11 * Description: Preview AI is a plugin that allows your customers to preview your products in real-time using AI image generation. 12 * Version: 1.0. 112 * Version: 1.0.2 13 13 * Author: Preview AI 14 14 * Author URI: https://profiles.wordpress.org/previewai/ … … 27 27 * Current plugin version. 28 28 */ 29 define( 'PREVIEW_AI_VERSION', '1.0. 1' );29 define( 'PREVIEW_AI_VERSION', '1.0.2' ); 30 30 define( 'PREVIEW_AI_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); 31 31 -
preview-ai/trunk/public/class-preview-ai-public.php
r3446676 r3454451 244 244 'previewAiData', 245 245 array( 246 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 247 'nonce' => wp_create_nonce( 'preview_ai_ajax' ), 248 'productId' => $product_id, 249 'variationId' => '', 250 'productName' => $product_name, 251 'productUrl' => $product_url, 252 'productImageUrl' => $product_image_url, 246 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 247 'nonce' => wp_create_nonce( 'preview_ai_ajax' ), 248 'productId' => $product_id, 249 'variationId' => '', 250 'productName' => $product_name, 251 'productUrl' => $product_url, 252 'productImageUrl' => $product_image_url, 253 'maxPreviewsWeekly' => PREVIEW_AI_Admin_Settings::get_max_previews_per_user_weekly(), 253 254 'i18n' => array( 254 'error' => __( 'Something went wrong. Please try again later.', 'preview-ai' ), 255 'openCamera' => __( 'Open camera', 'preview-ai' ), 256 'uploadPhoto' => __( 'Upload photo', 'preview-ai' ), 257 'checkingPhoto' => __( 'Checking photo…', 'preview-ai' ), 258 'photoOk' => __( 'Photo looks good.', 'preview-ai' ), 259 'photoWarning' => __( 'Photo is valid, but could be improved.', 'preview-ai' ), 260 'photoBad' => __( 'Photo is not valid. Please try another one.', 'preview-ai' ), 255 'error' => __( 'Something went wrong. Please try again later.', 'preview-ai' ), 256 'weeklyLimitReached' => __( 'You have used all your weekly previews! Come back next week to try on more products.', 'preview-ai' ), 257 'openCamera' => __( 'Open camera', 'preview-ai' ), 258 'uploadPhoto' => __( 'Upload photo', 'preview-ai' ), 259 'checkingPhoto' => __( 'Checking photo…', 'preview-ai' ), 260 'photoOk' => __( 'Photo looks good.', 'preview-ai' ), 261 'photoWarning' => __( 'Photo is valid, but could be improved.', 'preview-ai' ), 262 'photoBad' => __( 'Photo is not valid. Please try another one.', 'preview-ai' ), 261 263 'warningCodes' => array( 262 264 // Generic / heuristic checks (backend/src/api/routes/generate.py). -
preview-ai/trunk/public/js/preview-ai-api.js
r3446676 r3454451 193 193 } 194 194 if ( ! state.selectedFile ) { 195 return; 196 } 197 198 // Check weekly usage limit. 199 if ( ! PreviewAI.Storage.canGeneratePreview() ) { 200 var limitMsg = ( previewAiData.i18n && previewAiData.i18n.weeklyLimitReached ) 201 || 'You have used all your weekly previews! Come back next week to try on more products.'; 202 this.showError( $els, limitMsg, modal.stopLoadingSteps ); 195 203 return; 196 204 } … … 233 241 $els.$resultActions.addClass( 'is-visible' ); 234 242 $els.$disclaimer.addClass( 'is-visible' ); 243 244 // Increment weekly usage counter. 245 PreviewAI.Storage.incrementWeeklyUsage(); 235 246 236 247 var variationId = $( 'input.variation_id' ).val() || ''; -
preview-ai/trunk/public/js/preview-ai-storage.js
r3446676 r3454451 8 8 var STORAGE_KEY = 'previewAiUserPhoto'; 9 9 var TRYONS_STORAGE_KEY = 'previewAiTryOns'; 10 var USAGE_KEY = 'previewAiWeeklyUsage'; 10 11 var MAX_TRYONS = 10; 11 12 13 /** 14 * Get the start of the current week (Monday 00:00:00 UTC). 15 */ 16 function getWeekStart() { 17 var now = new Date(); 18 var day = now.getUTCDay(); 19 var diff = ( day === 0 ) ? 6 : day - 1; // Monday = 0. 20 var monday = new Date( Date.UTC( now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - diff ) ); 21 return monday.toISOString().split( 'T' )[0]; // "YYYY-MM-DD". 22 } 23 12 24 return { 25 /** 26 * Get how many previews the user has generated this week. 27 */ 28 getWeeklyUsage: function() { 29 try { 30 var data = JSON.parse( localStorage.getItem( USAGE_KEY ) || '{}' ); 31 var weekStart = getWeekStart(); 32 return ( data.week === weekStart ) ? ( data.count || 0 ) : 0; 33 } catch ( e ) { 34 return 0; 35 } 36 }, 37 38 /** 39 * Increment the weekly usage counter. 40 */ 41 incrementWeeklyUsage: function() { 42 try { 43 var weekStart = getWeekStart(); 44 var currentCount = this.getWeeklyUsage(); 45 localStorage.setItem( USAGE_KEY, JSON.stringify( { 46 week: weekStart, 47 count: currentCount + 1 48 } ) ); 49 } catch ( e ) { 50 // Storage not available. 51 } 52 }, 53 54 /** 55 * Check if user can generate more previews this week. 56 */ 57 canGeneratePreview: function() { 58 if ( typeof previewAiData === 'undefined' || ! previewAiData.maxPreviewsWeekly ) { 59 return true; // No limit configured. 60 } 61 return this.getWeeklyUsage() < previewAiData.maxPreviewsWeekly; 62 }, 63 64 /** 65 * Get remaining previews for this week. 66 */ 67 getRemainingPreviews: function() { 68 if ( typeof previewAiData === 'undefined' || ! previewAiData.maxPreviewsWeekly ) { 69 return null; // No limit. 70 } 71 return Math.max( 0, previewAiData.maxPreviewsWeekly - this.getWeeklyUsage() ); 72 }, 73 13 74 // Check if we have a saved photo 14 75 getSavedPhoto: function() { -
preview-ai/trunk/readme.txt
r3447207 r3454451 8 8 WC requires at least: 8.0 9 9 WC tested up to: 10.4 10 Stable tag: 1.0. 110 Stable tag: 1.0.2 11 11 License: GPLv2 or later 12 12 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 155 155 == Changelog == 156 156 157 = 1.0.2 = 158 – Added weekly preview limit per visitor (configurable in Settings > General) 159 – Default limit: 8 previews per visitor per week 160 157 161 = 1.0.1 = 158 162 – Updated plugin name to "Preview AI – Virtual Try-On for WooCommerce"
Note: See TracChangeset
for help on using the changeset viewer.