Plugin Directory

Changeset 3454451


Ignore:
Timestamp:
02/05/2026 10:12:12 AM (8 weeks ago)
Author:
previewai
Message:

Release 1.0.2

Location:
preview-ai/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • preview-ai/trunk/admin/class-preview-ai-admin-settings.php

    r3446676 r3454451  
    1717        register_setting( 'preview_ai_general_settings', 'preview_ai_api_key', 'sanitize_text_field' );
    1818        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        );
    1928
    2029        // Widget settings group.
     
    7685
    7786    /**
     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    /**
    7896     * Get available product types for AI context.
    7997     */
  • preview-ai/trunk/admin/partials/preview-ai-admin-display.php

    r3446676 r3454451  
    209209                    </tr>
    210210
     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
    211233                    <!-- API Key -->
    212234                    <tr>
     
    303325                    <?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' ); ?>
    304326                    <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>
    306328                </p>
    307329                <p class="preview-ai-catalog-note">
  • preview-ai/trunk/preview-ai.php

    r3447207 r3454451  
    1010 * Plugin URI:        https://previewai.app/
    1111 * 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.1
     12 * Version:           1.0.2
    1313 * Author:            Preview AI
    1414 * Author URI:        https://profiles.wordpress.org/previewai/
     
    2727 * Current plugin version.
    2828 */
    29 define( 'PREVIEW_AI_VERSION', '1.0.1' );
     29define( 'PREVIEW_AI_VERSION', '1.0.2' );
    3030define( 'PREVIEW_AI_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
    3131
  • preview-ai/trunk/public/class-preview-ai-public.php

    r3446676 r3454451  
    244244            'previewAiData',
    245245            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(),
    253254                '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' ),
    261263                    'warningCodes'  => array(
    262264                        // Generic / heuristic checks (backend/src/api/routes/generate.py).
  • preview-ai/trunk/public/js/preview-ai-api.js

    r3446676 r3454451  
    193193                }
    194194                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 );
    195203                    return;
    196204                }
     
    233241                                $els.$resultActions.addClass( 'is-visible' );
    234242                                $els.$disclaimer.addClass( 'is-visible' );
     243
     244                                // Increment weekly usage counter.
     245                                PreviewAI.Storage.incrementWeeklyUsage();
    235246
    236247                                var variationId = $( 'input.variation_id' ).val() || '';
  • preview-ai/trunk/public/js/preview-ai-storage.js

    r3446676 r3454451  
    88        var STORAGE_KEY        = 'previewAiUserPhoto';
    99        var TRYONS_STORAGE_KEY = 'previewAiTryOns';
     10        var USAGE_KEY          = 'previewAiWeeklyUsage';
    1011        var MAX_TRYONS         = 10;
    1112
     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
    1224        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
    1374            // Check if we have a saved photo
    1475            getSavedPhoto: function() {
  • preview-ai/trunk/readme.txt

    r3447207 r3454451  
    88WC requires at least: 8.0
    99WC tested up to: 10.4
    10 Stable tag: 1.0.1
     10Stable tag: 1.0.2
    1111License: GPLv2 or later
    1212License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    155155== Changelog ==
    156156
     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
    157161= 1.0.1 =
    158162– Updated plugin name to "Preview AI – Virtual Try-On for WooCommerce"
Note: See TracChangeset for help on using the changeset viewer.