Plugin Directory

Changeset 3754408


Ignore:
Timestamp:
10/19/2026 09:34:46 AM (4 weeks ago)
Author:
devhasib
Message:

updated version 1.0.6

Location:
sayan-variation-swatches/trunk
Files:
1 added
16 edited

Legend:

Unmodified
Added
Removed
  • sayan-variation-swatches/trunk/admin/class-svsw-admin.php

    r3650520 r3754408  
    124124                );
    125125
     126                // Calm overview of the separate Pro plugin; hidden once Pro is active.
     127                if ( ! SVSW_Pro_Teaser::is_pro() ) {
     128                        $tabs['pro'] = __( 'Pro Features', 'sayan-variation-swatches' );
     129                }
     130
    126131                /**
    127132                 * Filter the settings page tabs.
  • sayan-variation-swatches/trunk/admin/js/svsw-admin.js

    r3555281 r3754408  
    9494                                $preview.find( 'img' ).length
    9595                                        ? $preview.find( 'img' ).attr( 'src', url )
    96                                         : $preview.append( '<img src="' + url + '" style="max-width:60px;max-height:60px;" />' );
     96                                        : $preview.append( $( '<img>' ).attr( 'src', url ).css( { 'max-width': '60px', 'max-height': '60px' } ) );
    9797
    9898                                $preview.removeClass( 'svsw-hidden' );
  • sayan-variation-swatches/trunk/admin/views/settings-page.php

    r3722355 r3754408  
    1717        'archive' => 'dashicons-store',
    1818        'advanced'=> 'dashicons-editor-code',
     19        'pro'     => 'dashicons-star-filled',
    1920);
    20 // Import status notice (shown after redirect from import handler).
    21 if ( isset( $_GET['svsw_import'] ) && 'success' === sanitize_key( $_GET['svsw_import'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
    22         echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( '✅ Settings imported successfully.', 'sayan-variation-swatches' ) . '</p></div>';
    23 }
    2421?>
    2522<div class="wrap svsw-admin-wrap">
    … …  
    3431                                </h1>
    3532                                <p class="svsw-admin-header__subtitle">
    36                                         <?php esc_html_e( 'Variation Swatches for WooCommerce', 'sayan-variation-swatches' ); ?>
     33                                        <?php esc_html_e( 'Color, image, label and radio swatches for your variable products.', 'sayan-variation-swatches' ); ?>
     34                                        <a href="<?php echo esc_url( SVSW_DOCS_URL ); ?>" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Docs', 'sayan-variation-swatches' ); ?></a> |
     35                                        <a href="<?php echo esc_url( SVSW_SUPPORT_URL ); ?>" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Support', 'sayan-variation-swatches' ); ?></a>
    3736                                </p>
    3837                        </div>
    … …  
    4039                <span class="svsw-version-badge">v<?php echo esc_html( SVSW_VERSION ); ?></span>
    4140        </div>
     41
     42        <?php SVSW_Settings_IO::render_notice(); ?>
    4243
    4344        <!-- ── Two-column layout ── -->
    … …  
    172173                                        </div>
    173174
     175                                        <!-- Out-of-stock Notify Me -->
     176                                        <div class="svsw-card">
     177                                                <div class="svsw-card__header">
     178                                                        <span class="dashicons dashicons-bell"></span>
     179                                                        <h2 class="svsw-card__title"><?php esc_html_e( 'Out-of-Stock "Notify Me"', 'sayan-variation-swatches' ); ?></h2>
     180                                                </div>
     181                                                <table class="form-table" role="presentation">
     182                                                        <tr>
     183                                                                <th scope="row"><?php esc_html_e( 'Show Notify Me', 'sayan-variation-swatches' ); ?></th>
     184                                                                <td>
     185                                                                        <label class="svsw-toggle">
     186                                                                                <input type="checkbox" name="svsw_settings[oos_notify_me]" value="yes"
     187                                                                                       <?php checked( $settings['oos_notify_me'], 'yes' ); ?> />
     188                                                                                <span class="svsw-toggle__slider"></span>
     189                                                                        </label>
     190                                                                        <p class="description"><?php esc_html_e( 'When a shopper picks an unavailable option, show a "Notify me" message under the swatches.', 'sayan-variation-swatches' ); ?></p>
     191                                                                </td>
     192                                                        </tr>
     193                                                        <tr>
     194                                                                <th scope="row"><label for="svsw_oos_notify_text"><?php esc_html_e( 'Message Text', 'sayan-variation-swatches' ); ?></label></th>
     195                                                                <td>
     196                                                                        <input type="text" id="svsw_oos_notify_text" name="svsw_settings[oos_notify_text]"
     197                                                                               value="<?php echo esc_attr( $settings['oos_notify_text'] ); ?>" class="regular-text" maxlength="80" />
     198                                                                </td>
     199                                                        </tr>
     200                                                        <tr>
     201                                                                <th scope="row"><label for="svsw_oos_notify_url"><?php esc_html_e( 'Link URL', 'sayan-variation-swatches' ); ?></label></th>
     202                                                                <td>
     203                                                                        <input type="url" id="svsw_oos_notify_url" name="svsw_settings[oos_notify_url]"
     204                                                                               value="<?php echo esc_attr( $settings['oos_notify_url'] ); ?>" class="regular-text" placeholder="https://" />
     205                                                                        <p class="description"><?php esc_html_e( 'Optional. Where the message links to (for example a back-in-stock form). Only http and https links are accepted. Leave empty to show the text without a link.', 'sayan-variation-swatches' ); ?></p>
     206                                                                </td>
     207                                                        </tr>
     208                                                </table>
     209                                        </div>
     210
     211                                        <!-- Smart Variation Finder -->
     212                                        <div class="svsw-card">
     213                                                <div class="svsw-card__header">
     214                                                        <span class="dashicons dashicons-search"></span>
     215                                                        <h2 class="svsw-card__title"><?php esc_html_e( 'Smart Variation Finder', 'sayan-variation-swatches' ); ?></h2>
     216                                                </div>
     217                                                <table class="form-table" role="presentation">
     218                                                        <tr>
     219                                                                <th scope="row"><?php esc_html_e( 'Enable Finder', 'sayan-variation-swatches' ); ?></th>
     220                                                                <td>
     221                                                                        <label class="svsw-toggle">
     222                                                                                <input type="checkbox" name="svsw_settings[smart_finder]" value="yes"
     223                                                                                       <?php checked( $settings['smart_finder'], 'yes' ); ?> />
     224                                                                                <span class="svsw-toggle__slider"></span>
     225                                                                        </label>
     226                                                                        <p class="description"><?php esc_html_e( 'Adds a search box above the swatches on variable product pages. Shoppers can type words such as "dark blue large" to pick the matching options. It runs in the browser and contacts no external service.', 'sayan-variation-swatches' ); ?></p>
     227                                                                </td>
     228                                                        </tr>
     229                                                </table>
     230                                        </div>
     231
    174232                                <?php elseif ( 'design' === $tab ) : ?>
    175233
    … …  
    239297                                                        </tr>
    240298                                                        <tr>
     299                                                                <th scope="row"><label for="svsw_tooltip_position"><?php esc_html_e( 'Tooltip Position', 'sayan-variation-swatches' ); ?></label></th>
     300                                                                <td>
     301                                                                        <select id="svsw_tooltip_position" name="svsw_settings[tooltip_position]">
     302                                                                                <?php
     303                                                                                $svsw_positions = array(
     304                                                                                        'top'    => __( 'Top', 'sayan-variation-swatches' ),
     305                                                                                        'bottom' => __( 'Bottom', 'sayan-variation-swatches' ),
     306                                                                                        'left'   => __( 'Left', 'sayan-variation-swatches' ),
     307                                                                                        'right'  => __( 'Right', 'sayan-variation-swatches' ),
     308                                                                                );
     309                                                                                foreach ( $svsw_positions as $svsw_pos_value => $svsw_pos_label ) :
     310                                                                                        ?>
     311                                                                                        <option value="<?php echo esc_attr( $svsw_pos_value ); ?>" <?php selected( $settings['tooltip_position'], $svsw_pos_value ); ?>><?php echo esc_html( $svsw_pos_label ); ?></option>
     312                                                                                <?php endforeach; ?>
     313                                                                        </select>
     314                                                                        <p class="description"><?php esc_html_e( 'Where the tooltip appears relative to the swatch.', 'sayan-variation-swatches' ); ?></p>
     315                                                                </td>
     316                                                        </tr>
     317                                                        <tr>
    241318                                                                <th scope="row"><?php esc_html_e( 'Tooltip BG Color', 'sayan-variation-swatches' ); ?></th>
    242319                                                                <td>
    … …  
    333410                                        </div>
    334411
    335                                         <?php // Settings Import/Export — Pro feature (removed from free). ?>
     412                                        <div class="svsw-card">
     413                                                <div class="svsw-card__header">
     414                                                        <span class="dashicons dashicons-database"></span>
     415                                                        <h2 class="svsw-card__title"><?php esc_html_e( 'Data', 'sayan-variation-swatches' ); ?></h2>
     416                                                </div>
     417                                                <table class="form-table" role="presentation">
     418                                                        <tr>
     419                                                                <th scope="row"><?php esc_html_e( 'Delete Data on Uninstall', 'sayan-variation-swatches' ); ?></th>
     420                                                                <td>
     421                                                                        <label class="svsw-toggle">
     422                                                                                <input type="checkbox" name="svsw_settings[delete_data_on_uninstall]" value="yes"
     423                                                                                       <?php checked( $settings['delete_data_on_uninstall'], 'yes' ); ?> />
     424                                                                                <span class="svsw-toggle__slider"></span>
     425                                                                        </label>
     426                                                                        <p class="description"><?php esc_html_e( 'When you delete the plugin, also remove its settings and the swatch values saved on attribute terms and products. Off by default, so your swatches survive a reinstall.', 'sayan-variation-swatches' ); ?></p>
     427                                                                </td>
     428                                                        </tr>
     429                                                </table>
     430                                        </div>
    336431
    337432                                <?php endif; ?>
    338433
    339                                 <?php if ( 'pro' === $tab ) : ?>
     434
     435                        <!-- Save Button -->
     436                                <div class="svsw-save-row">
     437                                        <?php submit_button( esc_html__( 'Save Settings', 'sayan-variation-swatches' ), 'primary', 'submit', false ); ?>
     438                                </div>
     439
     440                        </form>
     441
     442                        <?php
     443                        if ( 'advanced' === $tab ) {
     444                                SVSW_Settings_IO::render_ui();
     445                        }
     446                        ?>
     447
     448                        <?php elseif ( 'pro' === $tab ) : ?>
     449
    340450                                <div class="svsw-settings-card">
    341451                                        <div class="svsw-settings-card__header">
    342                                                 <h2><?php esc_html_e( '⚡ Pro Features', 'sayan-variation-swatches' ); ?></h2>
    343                                                 <p class="description"><?php esc_html_e( 'Upgrade to Swatchly Pro to unlock these powerful features.', 'sayan-variation-swatches' ); ?></p>
     452                                                <h2><?php esc_html_e( 'Pro Features', 'sayan-variation-swatches' ); ?></h2>
     453                                                <p class="description"><?php esc_html_e( 'A separate Pro plugin adds these features. The free plugin stays fully functional on its own.', 'sayan-variation-swatches' ); ?></p>
    344454                                        </div>
    345455
    … …  
    354464                                                        </div>
    355465                                                </div>
    356                                                 <?php SVSW_Pro_Teaser::lock_notice( 'Sticky Add-to-Cart Bar' ); ?>
     466                                                <?php SVSW_Pro_Teaser::lock_notice( __( 'Sticky Add-to-Cart Bar', 'sayan-variation-swatches' ) ); ?>
    357467                                        </div>
    358468
    … …  
    367477                                                        </div>
    368478                                                </div>
    369                                                 <?php SVSW_Pro_Teaser::lock_notice( 'Per-Swatch Custom Badges' ); ?>
     479                                                <?php SVSW_Pro_Teaser::lock_notice( __( 'Per-Swatch Custom Badges', 'sayan-variation-swatches' ) ); ?>
    370480                                        </div>
    371481
    … …  
    380490                                                        </div>
    381491                                                </div>
    382                                                 <?php SVSW_Pro_Teaser::lock_notice( 'Per-Variation Multi-Gallery' ); ?>
     492                                                <?php SVSW_Pro_Teaser::lock_notice( __( 'Per-Variation Multi-Gallery', 'sayan-variation-swatches' ) ); ?>
    383493                                        </div>
    384494
    … …  
    393503                                                        </div>
    394504                                                </div>
    395                                                 <?php SVSW_Pro_Teaser::lock_notice( 'Bulk Swatch Generator' ); ?>
    396                                         </div>
    397 
    398                                         <!-- 5. Elementor Loop Builder -->
    399                                         <div class="svsw-pro-feature-row">
    400                                                 <div class="svsw-pro-feature-info">
    401                                                         <span class="svsw-pro-feature-icon">🔌</span>
    402                                                         <div>
    403                                                                 <strong><?php esc_html_e( 'Elementor Loop Builder Support', 'sayan-variation-swatches' ); ?></strong>
    404                                                                 <?php SVSW_Pro_Teaser::upgrade_badge(); ?>
    405                                                                 <p class="description"><?php esc_html_e( 'Archive swatches work inside Elementor Loop Builder, WooCommerce Products, and Loop Grid widgets — no extra setup needed.', 'sayan-variation-swatches' ); ?></p>
    406                                                         </div>
    407                                                 </div>
    408                                                 <?php SVSW_Pro_Teaser::lock_notice( 'Elementor Loop Builder Support' ); ?>
     505                                                <?php SVSW_Pro_Teaser::lock_notice( __( 'Bulk Swatch Generator', 'sayan-variation-swatches' ) ); ?>
    409506                                        </div>
    410507
    … …  
    419516                                                        </div>
    420517                                                </div>
    421                                                 <?php SVSW_Pro_Teaser::lock_notice( 'Live Stock Badge on Swatch' ); ?>
     518                                                <?php SVSW_Pro_Teaser::lock_notice( __( 'Live Stock Badge on Swatch', 'sayan-variation-swatches' ) ); ?>
    422519                                        </div>
    423520
    424521                                        <div style="text-align:center;padding:24px 0 8px;">
    425522                                                <a href="<?php echo esc_url( SVSW_Pro_Teaser::UPGRADE_URL ); ?>" target="_blank" rel="noopener noreferrer" class="button button-primary svsw-upgrade-btn">
    426                                                         ⚡ <?php esc_html_e( 'Upgrade to Swatchly Pro', 'sayan-variation-swatches' ); ?> →
     523                                                        <?php esc_html_e( 'Upgrade to Pro', 'sayan-variation-swatches' ); ?> →
    427524                                                </a>
    428525                                        </div>
    429526                                </div>
    430                         <?php endif; ?>
    431 
    432                         <!-- Save Button -->
    433                                 <div class="svsw-save-row">
    434                                         <?php submit_button( esc_html__( 'Save Settings', 'sayan-variation-swatches' ), 'primary', 'submit', false ); ?>
    435                                 </div>
    436 
    437                         </form>
     527
    438528                        <?php else : ?>
    439529
  • sayan-variation-swatches/trunk/includes/class-svsw-ai-finder.php

    r3722355 r3754408  
    11<?php
    22/**
    3  * SVSW AI Variation Finder — client-side fuzzy search.
     3 * Smart Variation Finder — client-side keyword search.
    44 * No API key. No AJAX. GDPR safe.
    55 *
    … …  
    1515        }
    1616        private function __construct() {
     17                // Opt-in: only active when "Smart Variation Finder" is switched on in the settings.
     18                if ( 'yes' !== SVSW_Helpers::get_setting( 'smart_finder', 'no' ) || ! SVSW_Helpers::is_enabled() ) {
     19                        return;
     20                }
    1721                add_action( 'woocommerce_before_variations_form', array( $this, 'inject_search_box' ) );
    1822                add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ), 25 );
  • sayan-variation-swatches/trunk/includes/class-svsw-attribute-manager.php

    r3722355 r3754408  
    4444                add_action( 'created_term', array( $this, 'save_term_meta' ), 10, 3 );
    4545                add_action( 'edited_term',  array( $this, 'save_term_meta' ), 10, 3 );
    46                 // AJAX media upload response handling.
    47                 add_action( 'wp_ajax_svsw_upload_term_image', array( $this, 'ajax_upload_term_image' ) );
    4846        }
    4947
    … …  
    232230                        return;
    233231                }
     232                if ( ! current_user_can( 'manage_product_terms' ) ) {
     233                        return;
     234                }
    234235
    235236                // Only process pa_* attribute taxonomies.
  • sayan-variation-swatches/trunk/includes/class-svsw-blocks-compat.php

    r3722355 r3754408  
    3434
    3535        private function __construct() {
    36                 if ( ! SVSW_Helpers::show_on_archive() ) {
     36                if ( ! SVSW_Helpers::is_enabled() || ! SVSW_Helpers::show_on_archive() ) {
    3737                        return;
    3838                }
    … …  
    4545                // Product Collection block (WC 8.0+).
    4646                add_filter( 'render_block', array( $this, 'inject_product_collection' ), 20, 2 );
    47                 // Reinit JS after block hydration.
    48                 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_reinit' ), 30 );
    4947        }
    5048
    … …  
    119117                ob_start();
    120118                SVSW_Frontend::get_instance()->output_archive_swatches_markup( $product, $attrs );
     119                $this->enqueue_reinit();
    121120                return ob_get_clean();
    122121        }
    … …  
    124123        /* ── Reinit script ─────────────────────────────── */
    125124
     125        /**
     126         * Add the re-init script once per request, after the swatch assets are enqueued.
     127         */
    126128        public function enqueue_reinit() {
    127                 if ( ! wp_script_is( 'svsw-frontend', 'enqueued' ) ) {
     129                static $added = false;
     130                if ( $added || ! wp_script_is( 'svsw-frontend', 'enqueued' ) ) {
    128131                        return;
    129132                }
     133                $added = true;
    130134                $js = <<<'JS'
    131135( function() {
  • sayan-variation-swatches/trunk/includes/class-svsw-frontend.php

    r3722355 r3754408  
    2929
    3030        /**
     31         * Per-request cache of available variations, keyed by product ID.
     32         *
     33         * @var array
     34         */
     35        private $variations_cache = array();
     36
     37        /**
    3138         * Get or create the singleton.
    3239         *
    … …  
    4956
    5057                // Enqueue assets.
    51                 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
     58                add_action( 'wp_enqueue_scripts', array( $this, 'maybe_enqueue_assets' ) );
    5259
    5360                // Replace dropdown with swatch HTML on product page.
    … …  
    7279
    7380        /**
     81         * Load the assets early on pages that always show swatches
     82         * (single product, shop, product category / tag / attribute archives).
     83         * On every other page (blocks, shortcodes, page builders) the assets are
     84         * enqueued the moment a swatch is actually rendered — see enqueue_assets().
     85         */
     86        public function maybe_enqueue_assets() {
     87                if ( function_exists( 'is_product' ) && ( is_product() || is_shop() || is_product_taxonomy() ) ) {
     88                        $this->enqueue_assets();
     89                        return;
     90                }
     91
     92                /**
     93                 * Force the swatch assets to load on a page where they are needed
     94                 * but cannot be detected automatically.
     95                 *
     96                 * @param bool $load Whether to load the assets. Default false.
     97                 */
     98                if ( apply_filters( 'svsw_load_assets', false ) ) {
     99                        $this->enqueue_assets();
     100                }
     101        }
     102
     103        /**
    74104         * Enqueue frontend CSS and JS, and pass localised data.
    75          */
    76         public function enqueue_scripts() {
     105         * Safe to call more than once; the work is done a single time per request.
     106         */
     107        public function enqueue_assets() {
     108                static $done = false;
     109                if ( $done ) {
     110                        return;
     111                }
     112                $done     = true;
    77113                $settings = SVSW_Settings::get_all();
    78114
    … …  
    83119                        SVSW_VERSION
    84120                );
     121                wp_style_add_data( 'svsw-frontend', 'rtl', true );
    85122
    86123                wp_enqueue_script(
    … …  
    107144                                        'enable_tooltip'     => SVSW_Helpers::is_tooltip_enabled(),
    108145                                        'show_selected_name' => $settings['show_selected_name'],
    109                                         'out_of_stock_style' => esc_js( $settings['out_of_stock_style'] ),
     146                                        'out_of_stock_style' => $settings['out_of_stock_style'],
    110147                                        'auto_image_change'  => 'yes',
    111                                         'show_attr_label'    => 'yes',
    112                                         'tooltip_position'   => esc_js( SVSW_Helpers::get_setting( 'tooltip_position', 'top' ) ),
    113                                         'i18n_clear'         => esc_html__( 'Clear', 'sayan-variation-swatches' ),
    114                                         'oos_notify_me'      => SVSW_Helpers::get_setting( 'oos_notify_me', 'yes' ),
    115                                         'oos_notify_text'    => esc_js( SVSW_Helpers::get_setting( 'oos_notify_text', 'Notify me when available' ) ),
    116                                         'oos_notify_url'     => esc_js( SVSW_Helpers::get_setting( 'oos_notify_url', '' ) ),
     148                                        'show_attr_label'    => $settings['show_selected_name'],
     149                                        'tooltip_position'   => $settings['tooltip_position'],
     150                                        'i18n_clear'         => __( 'Clear', 'sayan-variation-swatches' ),
     151                                        'oos_notify_me'      => $settings['oos_notify_me'],
     152                                        'oos_notify_text'    => $settings['oos_notify_text'],
     153                                        'oos_notify_url'     => esc_url_raw( $settings['oos_notify_url'], array( 'http', 'https' ) ),
    117154                                )
    118155                        )
    … …  
    124161                // Custom CSS from settings.
    125162                if ( 'yes' === $settings['enable_custom_css'] && ! empty( $settings['custom_css'] ) ) {
    126                         wp_add_inline_style( 'svsw-frontend', wp_strip_all_tags( $settings['custom_css'] ) );
     163                        wp_add_inline_style( 'svsw-frontend', SVSW_Settings::sanitize_css( $settings['custom_css'] ) );
    127164                }
    128165        }
    … …  
    198235                                $has_swatches = true;
    199236                                $swatch_data  = SVSW_Attribute_Manager::get_term_swatch_data( $term->term_id, $product_id );
    200                                 $swatch_html .= $this->build_swatch_item( $term->slug, $term->name, $effective_type, $swatch_data, $product, $taxonomy );
     237                                $swatch_html .= $this->build_swatch_item( $term->slug, $term->name, $effective_type, $swatch_data, $product, $taxonomy, $term->term_id );
    201238                        }
    202239                } else {
    … …  
    206243                                if ( 'select' === $type ) {
    207244                                        continue;
     245                                }
     246                                // Colors and images are stored on global attribute terms, so a custom attribute can only use text swatches.
     247                                if ( in_array( $type, array( 'color', 'image' ), true ) ) {
     248                                        $type = 'label';
    208249                                }
    209250                                $has_swatches = true;
    … …  
    223264                }
    224265
     266                // Make sure CSS/JS are present even on pages where they were not enqueued early.
     267                $this->enqueue_assets();
     268
    225269                $shape_class = SVSW_Helpers::get_shape_class();
    226270                $name        = 'attribute_' . esc_attr( $taxonomy );
    … …  
    284328         * @return string HTML.
    285329         */
    286         private function build_swatch_item( $slug, $name, $type, $swatch_data, $product, $taxonomy ) {
     330        private function build_swatch_item( $slug, $name, $type, $swatch_data, $product, $taxonomy, $term_id = 0 ) {
    287331                $is_available = $this->is_term_available( $product, $taxonomy, $slug );
    288332
    … …  
    306350                $classes   = array( 'svsw-swatch', 'svsw-type-' . esc_attr( $type ) );
    307351                $classes[] = $is_available ? 'svsw-available' : 'svsw-unavailable';
     352                if ( $term_id ) {
     353                        $term_shape = get_term_meta( $term_id, 'svsw_term_shape', true );
     354                        if ( $term_shape ) {
     355                                $classes[] = SVSW_Helpers::get_shape_class( $term_shape );
     356                        }
     357                }
    308358                if ( ! $is_available && 'blur_cross' === $oos_style ) {
    309359                        $classes[] = 'svsw-cross';
    … …  
    389439
    390440        /**
    391          * Check if a term/option is purchasable (not out of stock) for a product.
    392          *
    393          * @param WC_Product $product  Product object.
     441         * Get a product's available variations, computed once per request.
     442         *
     443         * @param WC_Product $product Variable product.
     444         * @return array
     445         */
     446        private function get_cached_variations( $product ) {
     447                $id = $product->get_id();
     448                if ( ! isset( $this->variations_cache[ $id ] ) ) {
     449                        $this->variations_cache[ $id ] = $product->get_available_variations( 'array' );
     450                }
     451                return $this->variations_cache[ $id ];
     452        }
     453
     454        /**
     455         * Check whether a term is available in at least one variation.
     456         *
     457         * @param WC_Product $product  Variable product.
    394458         * @param string     $taxonomy Attribute taxonomy.
    395459         * @param string     $slug     Term slug.
    … …  
    400464                        return true;
    401465                }
    402                 $variations = $product->get_available_variations( 'array' );
     466                $variations = $this->get_cached_variations( $product );
    403467                $attr_key   = 'attribute_' . $taxonomy;
    404468
    … …  
    428492                $main_img_id = (int) $product->get_image_id();
    429493
    430                 $variations = $product->get_available_variations( 'array' );
     494                $variations = $this->get_cached_variations( $product );
    431495
    432496                foreach ( $variations as $variation_data ) {
    … …  
    528592                );
    529593                $max  = absint( $args['max_swatches'] );
     594
     595                $this->enqueue_assets();
    530596
    531597                echo '<div class="svsw-archive-swatches" data-product_id="' . absint( $product->get_id() ) . '">';
    … …  
    586652                                        $swatch_data    = SVSW_Attribute_Manager::get_term_swatch_data( $term->term_id, $product->get_id() );
    587653
    588                                         echo wp_kses_post( $this->build_archive_swatch( $term->slug, $term->name, $effective_type, $swatch_data ) );
     654                                        echo wp_kses_post( $this->build_archive_swatch( $term->slug, $term->name, $effective_type, $swatch_data, $term->term_id ) );
    589655                                        $count++;
    590656                                }
    … …  
    607673                }
    608674
    609                 $notify_text = esc_html( SVSW_Helpers::get_setting( 'oos_notify_text', 'Notify me when available' ) );
    610                 $notify_url  = esc_url( SVSW_Helpers::get_setting( 'oos_notify_url', '' ) );
     675                // Keep raw values here; escape late, at the point of output.
     676                $notify_text = SVSW_Helpers::get_setting( 'oos_notify_text', 'Notify me when available' );
     677                $notify_url  = SVSW_Helpers::get_setting( 'oos_notify_url', '' );
    611678
    612679                echo '<div class="svsw-notify-popup" style="display:none;" aria-live="polite">';
    613680                echo '<span class="svsw-notify-icon" aria-hidden="true">⏰</span> ';
    614681                echo '<span class="svsw-notify-unavail">' . esc_html__( 'This option is currently unavailable.', 'sayan-variation-swatches' ) . '</span>';
    615                 if ( $notify_url ) {
    616                         echo ' <a href="' . $notify_url . '" class="svsw-notify-link" target="_blank" rel="noopener noreferrer">' . $notify_text . '</a>';
     682                if ( '' !== esc_url( $notify_url ) ) { // Only treat as a link when the URL survives escaping.
     683                        echo ' <a href="' . esc_url( $notify_url ) . '" class="svsw-notify-link" target="_blank" rel="noopener noreferrer">' . esc_html( $notify_text ) . '</a>';
    617684                } else {
    618                         echo ' <span class="svsw-notify-link svsw-notify-mailto" data-product-id="' . absint( $product->get_id() ) . '">' . $notify_text . '</span>';
     685                        echo ' <span class="svsw-notify-link svsw-notify-mailto" data-product-id="' . absint( $product->get_id() ) . '">' . esc_html( $notify_text ) . '</span>';
    619686                }
    620687                echo '</div>';
    … …  
    676743         * @return string HTML.
    677744         */
    678         private function build_archive_swatch( $slug, $name, $type, $swatch_data ) {
    679                 $shape_class = SVSW_Helpers::get_shape_class();
     745        private function build_archive_swatch( $slug, $name, $type, $swatch_data, $term_id = 0 ) {
     746                $shape_class = SVSW_Helpers::get_shape_class( '', $term_id );
    680747                $classes     = 'svsw-swatch svsw-archive-swatch svsw-type-' . esc_attr( $type ) . ' ' . $shape_class;
    681748
  • sayan-variation-swatches/trunk/includes/class-svsw-pro-teaser.php

    r3722355 r3754408  
    4444                        '<a href="%1$s" target="_blank" rel="noopener noreferrer" class="svsw-pro-badge" title="%2$s">%3$s</a>',
    4545                        esc_url( self::UPGRADE_URL ),
    46                         esc_attr__( 'Upgrade to Swatchly Pro', 'sayan-variation-swatches' ),
     46                        esc_attr__( 'Upgrade to Pro', 'sayan-variation-swatches' ),
    4747                        esc_html__( '⚡ Pro', 'sayan-variation-swatches' )
    4848                );
    … …  
    6262        public static function lock_notice( $feature = '', $echo = true ) {
    6363                $feature_label = $feature
     64                        /* translators: %s: feature name */
    6465                        ? sprintf( esc_html__( '%s is a Pro feature.', 'sayan-variation-swatches' ), esc_html( $feature ) )
    6566                        : esc_html__( 'This is a Pro feature.', 'sayan-variation-swatches' );
    … …  
    7374                        $feature_label,
    7475                        esc_url( self::UPGRADE_URL ),
    75                         esc_html__( 'Upgrade to Swatchly Pro →', 'sayan-variation-swatches' )
     76                        esc_html__( 'Upgrade to Pro →', 'sayan-variation-swatches' )
    7677                );
    7778
  • sayan-variation-swatches/trunk/includes/class-svsw-product-meta.php

    r3580855 r3754408  
    3838         */
    3939        private function __construct() {
    40                 // Add swatch override panel inside the Variations tab.
    41                 add_action( 'woocommerce_product_after_variable_attributes', array( $this, 'variation_swatch_fields' ), 10, 3 );
    42                 add_action( 'woocommerce_save_product_variation', array( $this, 'save_variation_swatch_fields' ), 10, 2 );
    43 
    44                 // Per-product attribute swatch type override metabox.
     40                // Per-product attribute swatch type override, shown under the attribute list.
    4541                add_action( 'woocommerce_product_options_attributes', array( $this, 'product_attribute_swatch_meta' ) );
    4642                add_action( 'woocommerce_process_product_meta', array( $this, 'save_product_attribute_meta' ) );
    … …  
    4844
    4945        /**
    50          * Add swatch shape override to each variation row.
    51          *
    52          * @param int     $loop           Loop index.
    53          * @param array   $variation_data Variation data array.
    54          * @param WP_Post $variation      Variation post object.
    55          */
    56         public function variation_swatch_fields( $loop, $variation_data, $variation ) {
    57                 $shape = get_post_meta( $variation->ID, '_svsw_shape', true );
    58                 $shapes = SVSW_Helpers::get_swatch_shapes();
    59                 ?>
    60                 <div class="form-row form-row-full svsw-variation-field">
    61                         <label><?php esc_html_e( 'Swatch Shape Override', 'sayan-variation-swatches' ); ?></label>
    62                         <select name="svsw_shape[<?php echo absint( $loop ); ?>]">
    63                                 <option value=""><?php esc_html_e( '— Use Global Setting —', 'sayan-variation-swatches' ); ?></option>
    64                                 <?php foreach ( $shapes as $val => $label ) : ?>
    65                                         <option value="<?php echo esc_attr( $val ); ?>" <?php selected( $shape, $val ); ?>>
    66                                                 <?php echo esc_html( $label ); ?>
    67                                         </option>
    68                                 <?php endforeach; ?>
    69                         </select>
    70                 </div>
    71                 <?php
    72         }
    73 
    74         /**
    75          * Save variation swatch shape override.
    76          *
    77          * WooCommerce core verifies the product nonce before firing
    78          * woocommerce_save_product_variation, so we just check capability here.
    79          *
    80          * @param int $variation_id Variation post ID.
    81          * @param int $loop         Loop index.
    82          */
    83         public function save_variation_swatch_fields( $variation_id, $loop ) {
    84                 // WooCommerce has already verified the nonce before this action fires.
    85                 if ( ! current_user_can( 'edit_product', $variation_id ) ) {
    86                         return;
    87                 }
    88 
    89                 if ( ! isset( $_POST['svsw_shape'][ $loop ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
    90                         return;
    91                 }
    92                 $allowed = array_merge( array( '' ), array_keys( SVSW_Helpers::get_swatch_shapes() ) );
    93                 $shape   = sanitize_key( wp_unslash( $_POST['svsw_shape'][ $loop ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
    94                 $shape   = in_array( $shape, $allowed, true ) ? $shape : '';
    95                 update_post_meta( $variation_id, '_svsw_shape', $shape );
    96         }
    97 
    98         /**
    99          * Output per-product attribute type override fields below attribute list.
     46         * Output per-product attribute type override fields below the attribute list.
     47         * Only global (taxonomy) attributes that are already saved on the product are listed.
    10048         */
    10149        public function product_attribute_swatch_meta() {
    … …  
    10452                        return;
    10553                }
     54
    10655                $overrides = get_post_meta( $post->ID, '_svsw_attribute_overrides', true );
    10756                $overrides = is_array( $overrides ) ? $overrides : array();
     57                $types     = SVSW_Helpers::get_swatch_types();
     58                $product   = wc_get_product( $post->ID );
     59
     60                $rows = array();
     61                if ( $product ) {
     62                        foreach ( $product->get_attributes() as $attribute ) {
     63                                if ( is_object( $attribute ) && $attribute->is_taxonomy() ) {
     64                                        $rows[ $attribute->get_name() ] = wc_attribute_label( $attribute->get_name() );
     65                                }
     66                        }
     67                }
    10868                ?>
    109                 <div id="svsw-attribute-overrides" style="margin-top:12px;">
    110                         <input type="hidden" id="svsw_attribute_overrides_data" name="svsw_attribute_overrides_data" value="<?php echo esc_attr( wp_json_encode( $overrides ) ); ?>" />
     69                <div id="svsw-attribute-overrides" class="toolbar" style="margin-top:12px;padding:0 12px 12px;">
    11170                        <?php wp_nonce_field( 'svsw_product_meta', 'svsw_product_nonce' ); ?>
     71                        <h4 style="margin:0 0 6px;"><?php esc_html_e( 'Swatch type for this product', 'sayan-variation-swatches' ); ?></h4>
     72                        <?php if ( empty( $rows ) ) : ?>
     73                                <p class="description"><?php esc_html_e( 'Add a global attribute, save the product, then choose a swatch type here for just this product.', 'sayan-variation-swatches' ); ?></p>
     74                        <?php else : ?>
     75                                <p class="description"><?php esc_html_e( 'Optional. Overrides the swatch type set on the attribute terms, for this product only.', 'sayan-variation-swatches' ); ?></p>
     76                                <?php foreach ( $rows as $svsw_taxonomy => $svsw_label ) : ?>
     77                                        <?php $svsw_current = isset( $overrides[ $svsw_taxonomy ] ) ? $overrides[ $svsw_taxonomy ] : ''; ?>
     78                                        <p>
     79                                                <label for="svsw_override_<?php echo esc_attr( $svsw_taxonomy ); ?>" style="display:inline-block;min-width:140px;"><?php echo esc_html( $svsw_label ); ?></label>
     80                                                <select id="svsw_override_<?php echo esc_attr( $svsw_taxonomy ); ?>" name="svsw_attr_override[<?php echo esc_attr( $svsw_taxonomy ); ?>]">
     81                                                        <option value=""><?php esc_html_e( '— Use attribute setting —', 'sayan-variation-swatches' ); ?></option>
     82                                                        <?php foreach ( $types as $svsw_type => $svsw_type_label ) : ?>
     83                                                                <option value="<?php echo esc_attr( $svsw_type ); ?>" <?php selected( $svsw_current, $svsw_type ); ?>><?php echo esc_html( $svsw_type_label ); ?></option>
     84                                                        <?php endforeach; ?>
     85                                                </select>
     86                                        </p>
     87                                <?php endforeach; ?>
     88                        <?php endif; ?>
    11289                </div>
    11390                <?php
    … …  
    127104                        return;
    128105                }
     106                // Nothing was submitted (no global attributes on the product): keep what is stored.
     107                if ( ! isset( $_POST['svsw_attr_override'] ) || ! is_array( $_POST['svsw_attr_override'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce verified above.
     108                        return;
     109                }
    129110
    130                 $raw = isset( $_POST['svsw_attribute_overrides_data'] ) ? sanitize_text_field( wp_unslash( $_POST['svsw_attribute_overrides_data'] ) ) : '{}'; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce verified above.
    131                 $data = json_decode( $raw, true );
    132                 if ( ! is_array( $data ) ) {
    133                         $data = array();
    134                 }
    135                 // Sanitize each override entry.
    136                 $clean        = array();
     111                $raw           = wp_unslash( $_POST['svsw_attr_override'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce verified above; each entry is whitelisted below.
    137112                $allowed_types = array_keys( SVSW_Helpers::get_swatch_types() );
    138                 foreach ( $data as $attr_name => $type ) {
     113                $clean         = array();
     114                foreach ( $raw as $attr_name => $type ) {
    139115                        $attr_name = sanitize_key( $attr_name );
    140                         $type      = in_array( $type, $allowed_types, true ) ? $type : 'select';
     116                        $type      = is_string( $type ) ? sanitize_key( $type ) : '';
     117                        if ( '' === $attr_name || ! in_array( $type, $allowed_types, true ) ) {
     118                                continue; // Empty value = no override.
     119                        }
    141120                        $clean[ $attr_name ] = $type;
    142121                }
    143                 update_post_meta( $post_id, '_svsw_attribute_overrides', $clean );
     122
     123                if ( $clean ) {
     124                        update_post_meta( $post_id, '_svsw_attribute_overrides', $clean );
     125                } else {
     126                        delete_post_meta( $post_id, '_svsw_attribute_overrides' );
     127                }
    144128        }
    145129
    … …  
    154138         */
    155139        public static function get_effective_type( $product_id, $taxonomy, $term_id ) {
     140                $allowed = array_keys( SVSW_Helpers::get_swatch_types() );
     141
    156142                // Check per-product override first.
    157143                $overrides = get_post_meta( $product_id, '_svsw_attribute_overrides', true );
    158                 if ( is_array( $overrides ) && isset( $overrides[ $taxonomy ] ) ) {
     144                if ( is_array( $overrides ) && isset( $overrides[ $taxonomy ] ) && in_array( $overrides[ $taxonomy ], $allowed, true ) ) {
    159145                        return $overrides[ $taxonomy ];
    160146                }
     147
    161148                // Fall back to global term meta.
    162                 return get_term_meta( $term_id, 'svsw_type', true ) ?: 'select';
     149                $type = $term_id ? get_term_meta( $term_id, 'svsw_type', true ) : '';
     150                if ( $type && in_array( $type, $allowed, true ) ) {
     151                        return $type;
     152                }
     153
     154                // Nothing chosen yet: optionally show text swatches instead of the dropdown.
     155                if ( '' === (string) $type && 'yes' === SVSW_Helpers::get_setting( 'auto_convert', 'no' ) ) {
     156                        return 'label';
     157                }
     158
     159                return 'select';
    163160        }
    164161}
  • sayan-variation-swatches/trunk/includes/class-svsw-review-notice.php

    r3650520 r3754408  
    2222        /** @var string Option key: cumulative admin session counter. */
    2323        const SESSION_KEY = 'svsw_admin_sessions';
     24
     25        /** @var string Option key: hash of the last login session that was counted. */
     26        const TOKEN_KEY = 'svsw_last_session';
    2427
    2528        /** @var string Option key: dismissed flag. */
    … …  
    4750
    4851        /**
    49          * Increment the admin session counter once per page load.
    50          * Bails early if the notice has already been dismissed.
     52         * Increment the admin session counter once per login session
     53         * (not once per page load). Bails early if the notice was dismissed.
    5154         */
    5255        public static function count_session() {
    53                 if ( get_option( self::DISMISS_KEY ) ) {
     56                if ( wp_doing_ajax() || get_option( self::DISMISS_KEY ) || ! current_user_can( 'manage_woocommerce' ) ) {
    5457                        return;
    5558                }
    56                 $sessions = (int) get_option( self::SESSION_KEY, 0 );
    57                 update_option( self::SESSION_KEY, $sessions + 1, false );
     59                $token = function_exists( 'wp_get_session_token' ) ? wp_get_session_token() : '';
     60                if ( '' === $token ) {
     61                        return;
     62                }
     63                $hash = md5( $token );
     64                if ( get_option( self::TOKEN_KEY ) === $hash ) {
     65                        return;
     66                }
     67                update_option( self::TOKEN_KEY, $hash, false );
     68                update_option( self::SESSION_KEY, (int) get_option( self::SESSION_KEY, 0 ) + 1, false );
    5869        }
    5970
    … …  
    6980                // Only show to users who can manage WooCommerce.
    7081                if ( ! current_user_can( 'manage_woocommerce' ) ) {
     82                        return;
     83                }
     84
     85                // Only on the Dashboard, the Plugins screen and this plugin's own settings page.
     86                $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
     87                if ( ! $screen || ! in_array( $screen->id, array( 'dashboard', 'plugins', 'toplevel_page_svsw-settings' ), true ) ) {
    7188                        return;
    7289                }
    … …  
    95112                $ajax_nonce  = wp_create_nonce( 'svsw_dismiss_review_ajax' );
    96113                ?>
    97                 <div class="notice notice-info svsw-review-notice" style="padding:16px 20px;display:flex;align-items:flex-start;gap:16px;" data-nonce="<?php echo esc_attr( $ajax_nonce ); ?>">
     114                <div class="notice notice-info is-dismissible svsw-review-notice" style="padding:16px 20px;display:flex;align-items:flex-start;gap:16px;" data-nonce="<?php echo esc_attr( $ajax_nonce ); ?>">
    98115                        <span class="dashicons dashicons-star-filled" style="color:#f0b429;font-size:28px;margin-top:2px;flex-shrink:0;"></span>
    99116                        <div style="flex:1;">
    … …  
    113130                                           target="_blank" rel="noopener noreferrer"
    114131                                           class="button button-primary">
    115                                                 ⭐ <?php esc_html_e( 'Leave a Review', 'sayan-variation-swatches' ); ?>
     132                                                <?php esc_html_e( 'Leave a Review', 'sayan-variation-swatches' ); ?>
    116133                                        </a>
    117134                                        &nbsp;
    118135                                        <a href="<?php echo esc_url( $dismiss_url ); ?>"
    119136                                           class="button svsw-review-dismiss">
    120                                                 <?php esc_html_e( 'Already did / No thanks', 'sayan-variation-swatches' ); ?>
     137                                                <?php esc_html_e( 'Don\'t ask again', 'sayan-variation-swatches' ); ?>
    121138                                        </a>
    122139                                </p>
    123140                        </div>
    124141                </div>
    125                 <script>
    126                 ( function() {
    127                         var btn = document.querySelector( '.svsw-review-dismiss' );
    128                         if ( ! btn ) return;
    129                         btn.addEventListener( 'click', function( e ) {
    130                                 e.preventDefault();
    131                                 var notice  = btn.closest( '.svsw-review-notice' );
    132                                 var nonce   = notice ? notice.dataset.nonce : '';
    133                                 var formData = new FormData();
    134                                 formData.append( 'action', 'svsw_dismiss_review_ajax' );
    135                                 formData.append( 'nonce', nonce );
    136                                 fetch( '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>', {
    137                                         method: 'POST',
    138                                         credentials: 'same-origin',
    139                                         body: formData
    140                                 } );
    141                                 if ( notice ) { notice.style.display = 'none'; }
    142                         } );
    143                 } )();
    144                 </script>
    145142                <?php
     143                $svsw_js = '( function() {'
     144                        . 'var notice = document.querySelector( ".svsw-review-notice" );'
     145                        . 'if ( ! notice ) { return; }'
     146                        . 'var url = ' . wp_json_encode( admin_url( 'admin-ajax.php' ) ) . ';'
     147                        . 'function dismiss() {'
     148                        . 'var data = new FormData();'
     149                        . 'data.append( "action", "svsw_dismiss_review_ajax" );'
     150                        . 'data.append( "nonce", notice.getAttribute( "data-nonce" ) || "" );'
     151                        . 'fetch( url, { method: "POST", credentials: "same-origin", body: data } );'
     152                        . '}'
     153                        . 'var btn = notice.querySelector( ".svsw-review-dismiss" );'
     154                        . 'if ( btn ) { btn.addEventListener( "click", function( e ) { e.preventDefault(); dismiss(); notice.style.display = "none"; } ); }'
     155                        . 'notice.addEventListener( "click", function( e ) { if ( e.target.closest && e.target.closest( ".notice-dismiss" ) ) { dismiss(); } } );'
     156                        . '} )();';
     157                wp_print_inline_script_tag( $svsw_js );
    146158        }
    147159
  • sayan-variation-swatches/trunk/includes/class-svsw-settings-io.php

    r3682054 r3754408  
    33 * SVSW Settings Import / Export
    44 *
    5  * Adds JSON export (download) and import (upload) functionality to
    6  * the plugin settings page. Accessible via the Advanced tab.
    7  *
    8  * Security:
    9  *  - Export: nonce + manage_woocommerce capability check.
    10  *  - Import: nonce + manage_woocommerce + file validation.
    11  *  - Imported JSON is decoded and run through the existing
    12  *    SVSW_Settings::sanitize_settings() before saving — so no
    13  *    raw untrusted data ever reaches the DB.
     5 * Lets administrators download the plugin settings as a JSON file and
     6 * restore them on another site. Imports are validated against a
     7 * whitelist of known keys and types; everything else is rejected.
    148 *
    159 * @package Sayan_Variation_Swatches
    … …  
    2418
    2519        /**
     20         * Maximum accepted import file size in bytes.
     21         */
     22        const MAX_FILE_SIZE = 65536;
     23
     24        /**
     25         * Export admin-post action / nonce action.
     26         */
     27        const EXPORT_ACTION = 'svsw_export_settings';
     28
     29        /**
     30         * Import admin-post action / nonce action.
     31         */
     32        const IMPORT_ACTION = 'svsw_import_settings';
     33
     34        /**
    2635         * Register hooks.
    27          * Called from svsw_init() when is_admin() is true.
    2836         */
    2937        public static function init() {
    30                 // Handle export (GET request from a form button with action=svsw_export_settings).
    31                 add_action( 'admin_post_svsw_export_settings', array( __CLASS__, 'handle_export' ) );
    32                 // Handle import (POST with uploaded JSON file).
    33                 add_action( 'admin_post_svsw_import_settings', array( __CLASS__, 'handle_import' ) );
    34         }
    35 
    36         /**
    37          * Output the plugin settings as a JSON file download.
    38          * Triggered by admin-post.php?action=svsw_export_settings.
    39          */
    40         public static function handle_export() {
    41                 check_admin_referer( 'svsw_export_settings' );
    42 
    43                 if ( ! current_user_can( 'manage_woocommerce' ) ) {
    44                         wp_die( esc_html__( 'Permission denied.', 'sayan-variation-swatches' ) );
    45                 }
    46 
    47                 $settings  = SVSW_Settings::get_all();
    48                 $json      = wp_json_encode( $settings, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE );
    49                 $filename  = 'svsw-settings-' . gmdate( 'Y-m-d' ) . '.json';
    50 
    51                 nocache_headers();
    52                 header( 'Content-Type: application/json; charset=utf-8' );
    53                 header( 'Content-Disposition: attachment; filename="' . sanitize_file_name( $filename ) . '"' );
    54                 header( 'Content-Length: ' . strlen( $json ) );
    55                 echo $json; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- JSON for file download.
    56                 exit;
    57         }
    58 
    59         /**
    60          * Handle an uploaded JSON settings file and merge into saved settings.
    61          * Triggered by admin-post.php?action=svsw_import_settings.
    62          */
    63         public static function handle_import() {
    64                 check_admin_referer( 'svsw_import_settings' );
    65 
    66                 if ( ! current_user_can( 'manage_woocommerce' ) ) {
    67                         wp_die( esc_html__( 'Permission denied.', 'sayan-variation-swatches' ) );
    68                 }
    69 
    70                 $redirect_base = admin_url( 'admin.php?page=svsw-settings&tab=advanced' );
    71 
    72                 // Validate file upload.
    73                 if ( empty( $_FILES['svsw_import_file']['tmp_name'] ) ) {
    74                         wp_safe_redirect( add_query_arg( 'svsw_import', 'no_file', $redirect_base ) );
    75                         exit;
    76                 }
    77 
    78                 $file     = $_FILES['svsw_import_file']; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
    79                 $ext      = strtolower( pathinfo( sanitize_file_name( $file['name'] ), PATHINFO_EXTENSION ) );
    80                 $tmp_name = $file['tmp_name'];
    81 
    82                 if ( 'json' !== $ext ) {
    83                         wp_safe_redirect( add_query_arg( 'svsw_import', 'invalid_type', $redirect_base ) );
    84                         exit;
    85                 }
    86 
    87                 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
    88                 $raw_json = file_get_contents( $tmp_name );
    89                 if ( false === $raw_json ) {
    90                         wp_safe_redirect( add_query_arg( 'svsw_import', 'read_error', $redirect_base ) );
    91                         exit;
    92                 }
    93 
    94                 $data = json_decode( $raw_json, true );
    95                 if ( ! is_array( $data ) || empty( $data ) ) {
    96                         wp_safe_redirect( add_query_arg( 'svsw_import', 'invalid_json', $redirect_base ) );
    97                         exit;
    98                 }
    99 
    100                 // Run through the existing sanitize routine — same as a normal settings save.
    101                 $settings_instance = SVSW_Settings::get_instance();
    102                 $clean             = $settings_instance->sanitize_settings( $data );
    103 
    104                 update_option( 'svsw_settings', $clean );
    105 
    106                 // Flush in-memory cache so the new settings take effect immediately.
    107                 SVSW_Helpers::flush_cache();
    108 
    109                 wp_safe_redirect( add_query_arg( 'svsw_import', 'success', $redirect_base ) );
    110                 exit;
    111         }
    112 
    113         /**
    114          * Render the Export / Import UI block.
    115          * Called directly from the Advanced tab in settings-page.php.
     38                add_action( 'admin_post_' . self::EXPORT_ACTION, array( __CLASS__, 'handle_export' ) );
     39                add_action( 'admin_post_' . self::IMPORT_ACTION, array( __CLASS__, 'handle_import' ) );
     40        }
     41
     42        /**
     43         * Messages for the import result notice.
     44         *
     45         * @return array
     46         */
     47        private static function get_messages() {
     48                return array(
     49                        'success'     => __( 'Settings imported successfully.', 'sayan-variation-swatches' ),
     50                        'no_file'     => __( 'No file was uploaded. Choose a JSON file exported from this plugin and try again.', 'sayan-variation-swatches' ),
     51                        'too_large'   => __( 'The file is empty or larger than 64 KB, so it was not imported.', 'sayan-variation-swatches' ),
     52                        'invalid'     => __( 'Only a .json file exported from this plugin can be imported.', 'sayan-variation-swatches' ),
     53                        'bad_json'    => __( 'The file could not be read as JSON.', 'sayan-variation-swatches' ),
     54                        'bad_format'  => __( 'The file does not look like a settings export from this plugin.', 'sayan-variation-swatches' ),
     55                        'bad_value'   => __( 'The file contains a value of an unexpected type, so nothing was imported.', 'sayan-variation-swatches' ),
     56                );
     57        }
     58
     59        /**
     60         * Show the result notice after an import redirect.
     61         */
     62        public static function render_notice() {
     63                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only status flag, nothing is changed.
     64                $status = isset( $_GET['svsw_import'] ) ? sanitize_key( wp_unslash( $_GET['svsw_import'] ) ) : '';
     65                if ( '' === $status ) {
     66                        return;
     67                }
     68                $messages = self::get_messages();
     69                if ( ! isset( $messages[ $status ] ) ) {
     70                        return;
     71                }
     72                $class = 'success' === $status ? 'notice-success' : 'notice-error';
     73                printf(
     74                        '<div class="notice %1$s is-dismissible"><p>%2$s</p></div>',
     75                        esc_attr( $class ),
     76                        esc_html( $messages[ $status ] )
     77                );
     78        }
     79
     80        /**
     81         * Render the Export / Import card. Must be called OUTSIDE the main
     82         * settings <form> because it contains its own form.
    11683         */
    11784        public static function render_ui() {
    118                 // Import status notice.
    119                 $import_status = isset( $_GET['svsw_import'] ) ? sanitize_key( $_GET['svsw_import'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
    120                 if ( $import_status ) {
    121                         $messages = array(
    122                                 'success'      => array( 'updated', __( '✅ Settings imported successfully.', 'sayan-variation-swatches' ) ),
    123                                 'no_file'      => array( 'error', __( '❌ No file selected. Please choose a JSON file to import.', 'sayan-variation-swatches' ) ),
    124                                 'invalid_type' => array( 'error', __( '❌ Invalid file type. Please upload a .json file.', 'sayan-variation-swatches' ) ),
    125                                 'invalid_json' => array( 'error', __( '❌ Invalid JSON. The file could not be parsed.', 'sayan-variation-swatches' ) ),
    126                                 'read_error'   => array( 'error', __( '❌ Could not read the uploaded file.', 'sayan-variation-swatches' ) ),
    127                         );
    128                         if ( isset( $messages[ $import_status ] ) ) {
    129                                 list( $type, $msg ) = $messages[ $import_status ];
    130                                 printf(
    131                                         '<div class="notice notice-%s is-dismissible"><p>%s</p></div>',
    132                                         esc_attr( $type ),
    133                                         esc_html( $msg )
    134                                 );
    135                         }
    136                 }
     85                if ( ! current_user_can( 'manage_options' ) ) {
     86                        return;
     87                }
     88                $export_url = wp_nonce_url(
     89                        admin_url( 'admin-post.php?action=' . self::EXPORT_ACTION ),
     90                        self::EXPORT_ACTION
     91                );
    13792                ?>
    13893                <div class="svsw-card">
    13994                        <div class="svsw-card__header">
    14095                                <span class="dashicons dashicons-migrate"></span>
    141                                 <h2 class="svsw-card__title"><?php esc_html_e( 'Settings Export / Import', 'sayan-variation-swatches' ); ?></h2>
     96                                <h2 class="svsw-card__title"><?php esc_html_e( 'Export / Import Settings', 'sayan-variation-swatches' ); ?></h2>
    14297                        </div>
    143 
    144                         <div class="svsw-io-grid">
    145 
    146                                 <!-- Export -->
    147                                 <div class="svsw-io-panel">
    148                                         <h3 class="svsw-io-panel__title">
    149                                                 <span class="dashicons dashicons-download"></span>
    150                                                 <?php esc_html_e( 'Export Settings', 'sayan-variation-swatches' ); ?>
    151                                         </h3>
    152                                         <p class="description">
    153                                                 <?php esc_html_e( 'Download all plugin settings as a JSON file. Use this to back up your configuration or copy it to another site.', 'sayan-variation-swatches' ); ?>
    154                                         </p>
    155                                         <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
    156                                                 <input type="hidden" name="action" value="svsw_export_settings" />
    157                                                 <?php wp_nonce_field( 'svsw_export_settings' ); ?>
    158                                                 <button type="submit" class="button button-secondary svsw-io-btn">
    159                                                         <span class="dashicons dashicons-download" style="margin-top:3px;"></span>
    160                                                         <?php esc_html_e( 'Download JSON', 'sayan-variation-swatches' ); ?>
    161                                                 </button>
    162                                         </form>
    163                                 </div>
    164 
    165                                 <!-- Import -->
    166                                 <div class="svsw-io-panel">
    167                                         <h3 class="svsw-io-panel__title">
    168                                                 <span class="dashicons dashicons-upload"></span>
    169                                                 <?php esc_html_e( 'Import Settings', 'sayan-variation-swatches' ); ?>
    170                                         </h3>
    171                                         <p class="description">
    172                                                 <?php esc_html_e( 'Upload a previously exported JSON file to restore settings. Existing settings will be overwritten.', 'sayan-variation-swatches' ); ?>
    173                                         </p>
    174                                         <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>"
    175                                               enctype="multipart/form-data">
    176                                                 <input type="hidden" name="action" value="svsw_import_settings" />
    177                                                 <?php wp_nonce_field( 'svsw_import_settings' ); ?>
    178                                                 <div class="svsw-io-file-row">
    179                                                         <input type="file" name="svsw_import_file" accept=".json"
    180                                                                class="svsw-file-input" required />
    181                                                         <button type="submit" class="button button-primary svsw-io-btn">
    182                                                                 <span class="dashicons dashicons-upload" style="margin-top:3px;"></span>
    183                                                                 <?php esc_html_e( 'Import JSON', 'sayan-variation-swatches' ); ?>
    184                                                         </button>
    185                                                 </div>
    186                                         </form>
    187                                 </div>
    188 
    189                         </div><!-- .svsw-io-grid -->
     98                        <table class="form-table" role="presentation">
     99                                <tr>
     100                                        <th scope="row"><?php esc_html_e( 'Export', 'sayan-variation-swatches' ); ?></th>
     101                                        <td>
     102                                                <a class="button" href="<?php echo esc_url( $export_url ); ?>"><?php esc_html_e( 'Download settings (JSON)', 'sayan-variation-swatches' ); ?></a>
     103                                                <p class="description"><?php esc_html_e( 'Saves all plugin settings to a file. Swatch values on attribute terms are not included.', 'sayan-variation-swatches' ); ?></p>
     104                                        </td>
     105                                </tr>
     106                                <tr>
     107                                        <th scope="row"><label for="svsw_import_file"><?php esc_html_e( 'Import', 'sayan-variation-swatches' ); ?></label></th>
     108                                        <td>
     109                                                <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" enctype="multipart/form-data">
     110                                                        <input type="hidden" name="action" value="<?php echo esc_attr( self::IMPORT_ACTION ); ?>" />
     111                                                        <?php wp_nonce_field( self::IMPORT_ACTION ); ?>
     112                                                        <input type="file" id="svsw_import_file" name="svsw_import_file" accept=".json,application/json" />
     113                                                        <?php submit_button( __( 'Import settings', 'sayan-variation-swatches' ), 'secondary', 'svsw_import_submit', false ); ?>
     114                                                </form>
     115                                                <p class="description"><?php esc_html_e( 'Import replaces your current settings with the values in the file. Maximum file size is 64 KB.', 'sayan-variation-swatches' ); ?></p>
     116                                        </td>
     117                                </tr>
     118                        </table>
    190119                </div>
    191120                <?php
    192121        }
     122
     123        /**
     124         * Send the settings file.
     125         */
     126        public static function handle_export() {
     127                if ( ! current_user_can( 'manage_options' ) ) {
     128                        wp_die( esc_html__( 'You do not have permission to export these settings.', 'sayan-variation-swatches' ), '', array( 'response' => 403 ) );
     129                }
     130                check_admin_referer( self::EXPORT_ACTION );
     131
     132                $payload = array(
     133                        'plugin'   => 'sayan-variation-swatches',
     134                        'version'  => SVSW_VERSION,
     135                        'settings' => SVSW_Settings::get_all(),
     136                );
     137
     138                nocache_headers();
     139                header( 'Content-Type: application/json; charset=utf-8' );
     140                header( 'Content-Disposition: attachment; filename="svsw-settings-' . gmdate( 'Y-m-d' ) . '.json"' );
     141                echo wp_json_encode( $payload, JSON_PRETTY_PRINT ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- JSON file download.
     142                exit;
     143        }
     144
     145        /**
     146         * Handle the uploaded file and redirect back with a status.
     147         */
     148        public static function handle_import() {
     149                if ( ! current_user_can( 'manage_options' ) ) {
     150                        wp_die( esc_html__( 'You do not have permission to import settings.', 'sayan-variation-swatches' ), '', array( 'response' => 403 ) );
     151                }
     152                check_admin_referer( self::IMPORT_ACTION );
     153
     154                $result = self::process_upload();
     155                $status = is_wp_error( $result ) ? $result->get_error_code() : 'success';
     156
     157                wp_safe_redirect(
     158                        add_query_arg(
     159                                array( 'svsw_import' => $status ),
     160                                admin_url( 'admin.php?page=svsw-settings&tab=advanced' )
     161                        )
     162                );
     163                exit;
     164        }
     165
     166        /**
     167         * Validate and apply the uploaded settings file.
     168         *
     169         * @return true|WP_Error
     170         */
     171        private static function process_upload() {
     172                // phpcs:disable WordPress.Security.NonceVerification.Missing -- Nonce is verified in handle_import().
     173                // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
     174                if ( empty( $_FILES['svsw_import_file'] ) || ! is_array( $_FILES['svsw_import_file'] ) ) {
     175                        return new WP_Error( 'no_file' );
     176                }
     177                $file = $_FILES['svsw_import_file'];
     178                // phpcs:enable
     179
     180                $error = isset( $file['error'] ) ? (int) $file['error'] : UPLOAD_ERR_NO_FILE;
     181                if ( UPLOAD_ERR_OK !== $error ) {
     182                        return new WP_Error( 'no_file' );
     183                }
     184
     185                $size = isset( $file['size'] ) ? (int) $file['size'] : 0;
     186                if ( $size < 1 || $size > self::MAX_FILE_SIZE ) {
     187                        return new WP_Error( 'too_large' );
     188                }
     189
     190                $tmp  = isset( $file['tmp_name'] ) ? (string) $file['tmp_name'] : '';
     191                $name = isset( $file['name'] ) ? sanitize_file_name( wp_unslash( (string) $file['name'] ) ) : '';
     192                if ( '' === $tmp || ! is_uploaded_file( $tmp ) || 'json' !== strtolower( pathinfo( $name, PATHINFO_EXTENSION ) ) ) {
     193                        return new WP_Error( 'invalid' );
     194                }
     195
     196                $raw = file_get_contents( $tmp ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Reading a local uploaded file.
     197                if ( false === $raw || strlen( $raw ) > self::MAX_FILE_SIZE ) {
     198                        return new WP_Error( 'invalid' );
     199                }
     200
     201                $data = json_decode( $raw, true );
     202                if ( ! is_array( $data ) ) {
     203                        return new WP_Error( 'bad_json' );
     204                }
     205                if ( ! isset( $data['plugin'], $data['settings'] )
     206                        || 'sayan-variation-swatches' !== $data['plugin']
     207                        || ! is_array( $data['settings'] ) ) {
     208                        return new WP_Error( 'bad_format' );
     209                }
     210
     211                // Whitelist: only keys that exist in the defaults, type-checked
     212                // against the default value's type. Unknown keys are dropped.
     213                $defaults = SVSW_Settings::get_default_settings();
     214                $clean    = array();
     215                foreach ( $data['settings'] as $key => $value ) {
     216                        if ( ! is_string( $key ) || ! array_key_exists( $key, $defaults ) ) {
     217                                continue;
     218                        }
     219                        if ( is_int( $defaults[ $key ] ) ) {
     220                                if ( is_int( $value ) || ( is_string( $value ) && ctype_digit( $value ) ) ) {
     221                                        $clean[ $key ] = (int) $value;
     222                                        continue;
     223                                }
     224                                return new WP_Error( 'bad_value' );
     225                        }
     226                        if ( ! is_string( $value ) || strlen( $value ) > 20000 ) {
     227                                return new WP_Error( 'bad_value' );
     228                        }
     229                        $clean[ $key ] = $value;
     230                }
     231                if ( empty( $clean ) ) {
     232                        return new WP_Error( 'bad_format' );
     233                }
     234
     235                // Values are sanitized again by the settings sanitize callback.
     236                update_option( 'svsw_settings', array_merge( SVSW_Settings::get_all(), $clean ) );
     237                SVSW_Helpers::flush_cache();
     238
     239                return true;
     240        }
    193241}
  • sayan-variation-swatches/trunk/includes/class-svsw-settings.php

    r3722355 r3754408  
    3939        private function __construct() {
    4040                add_action( 'admin_init', array( $this, 'register_settings' ) );
     41                // The settings screen is available to shop managers, so saving must be too.
     42                add_filter( 'option_page_capability_svsw_settings_group', array( $this, 'settings_capability' ) );
     43                add_action( 'update_option_svsw_settings', array( 'SVSW_Helpers', 'flush_cache' ) );
     44        }
     45
     46        /**
     47         * Capability required to save the plugin settings.
     48         *
     49         * @return string
     50         */
     51        public function settings_capability() {
     52                return 'manage_woocommerce';
    4153        }
    4254
    … …  
    5567
    5668        /**
     69         * Sanitize custom CSS: strip tags, block </style> breakouts, remove
     70         * remote @import rules and legacy script-capable CSS constructs.
     71         *
     72         * @param string $css Raw CSS.
     73         * @return string Safe CSS.
     74         */
     75        public static function sanitize_css( $css ) {
     76                $css = wp_strip_all_tags( (string) $css );
     77                $css = preg_replace( '#</?\s*style[^>]*>?#i', '', $css );
     78                $css = preg_replace( '/@import[^;]*;?/i', '', $css );
     79                $css = preg_replace( '/(expression\s*\(|javascript\s*:|vbscript\s*:|behavior\s*:|-moz-binding)/i', '', $css );
     80                return trim( (string) $css );
     81        }
     82
     83        /**
    5784         * Sanitize the settings array before saving.
    5885         *
    … …  
    6794                $existing = get_option( 'svsw_settings', array() );
    6895                $output   = is_array( $existing ) ? $existing : array();
     96                $defaults = self::get_default_settings();
     97
     98                if ( ! is_array( $input ) ) {
     99                        return wp_parse_args( $output, $defaults );
     100                }
    69101
    70102                // Checkbox / yes-no fields — only update ones present in this submission.
    … …  
    77109                        'show_selected_name',
    78110                        'enable_custom_css',
     111                        'oos_notify_me',
     112                        'smart_finder',
     113                        'delete_data_on_uninstall',
    79114                );
    80115                foreach ( $yes_no_fields as $field ) {
    … …  
    87122                // Select fields with allowed values.
    88123                if ( array_key_exists( 'swatch_shape', $input ) ) {
    89                         $shape_options           = array_keys( SVSW_Helpers::get_swatch_shapes() );
     124                        $shape_options          = array_keys( SVSW_Helpers::get_swatch_shapes() );
    90125                        $output['swatch_shape'] = in_array( $input['swatch_shape'], $shape_options, true )
    91126                                ? $input['swatch_shape']
    … …  
    94129
    95130                if ( array_key_exists( 'out_of_stock_style', $input ) ) {
    96                         $oos_options                   = array_keys( SVSW_Helpers::get_oos_styles() );
     131                        $oos_options                  = array_keys( SVSW_Helpers::get_oos_styles() );
    97132                        $output['out_of_stock_style'] = in_array( $input['out_of_stock_style'], $oos_options, true )
    98133                                ? $input['out_of_stock_style']
    99134                                : 'blur_cross';
     135                }
     136
     137                if ( array_key_exists( 'tooltip_position', $input ) ) {
     138                        $output['tooltip_position'] = in_array( $input['tooltip_position'], array( 'top', 'bottom', 'left', 'right' ), true )
     139                                ? $input['tooltip_position']
     140                                : 'top';
    100141                }
    101142
    … …  
    113154                        }
    114155                        list( $min, $max, $default ) = $range;
    115                         $val               = absint( $input[ $field ] );
    116                         $val               = $val ? $val : $default;
    117                         $output[ $field ] = max( $min, min( $max, $val ) );
     156                        $val                         = absint( $input[ $field ] );
     157                        $val                         = $val ? $val : $default;
     158                        $output[ $field ]            = max( $min, min( $max, $val ) );
    118159                }
    119160
    … …  
    121162                $color_fields = array(
    122163                        'selected_checkmark_color' => '#ffffff',
    123                         'tooltip_position'         => 'top',
    124164                        'tooltip_bg_color'         => '#333333',
    125165                        'tooltip_text_color'       => '#ffffff',
    … …  
    131171                                continue;
    132172                        }
    133                         $val               = SVSW_Helpers::sanitize_hex_color( $input[ $field ] );
     173                        $val              = SVSW_Helpers::sanitize_hex_color( is_scalar( $input[ $field ] ) ? (string) $input[ $field ] : '' );
    134174                        $output[ $field ] = $val ? $val : $default;
    135175                }
    136176
    137                 // Custom CSS – allowed for editors/admins only, strip tags.
    138                 if ( array_key_exists( 'custom_css', $input ) && current_user_can( 'edit_theme_options' ) ) {
    139                         $output['custom_css'] = wp_strip_all_tags( $input['custom_css'] );
     177                // "Notify me" link text and URL (http/https only).
     178                if ( array_key_exists( 'oos_notify_text', $input ) ) {
     179                        $text = sanitize_text_field( is_scalar( $input['oos_notify_text'] ) ? (string) $input['oos_notify_text'] : '' );
     180                        $text = function_exists( 'mb_substr' ) ? mb_substr( $text, 0, 80 ) : substr( $text, 0, 80 );
     181
     182                        $output['oos_notify_text'] = '' !== $text ? $text : $defaults['oos_notify_text'];
     183                }
     184                if ( array_key_exists( 'oos_notify_url', $input ) ) {
     185                        $output['oos_notify_url'] = esc_url_raw(
     186                                trim( is_scalar( $input['oos_notify_url'] ) ? (string) $input['oos_notify_url'] : '' ),
     187                                array( 'http', 'https' )
     188                        );
     189                }
     190
     191                // Custom CSS – administrators only.
     192                if ( array_key_exists( 'custom_css', $input ) && current_user_can( 'manage_options' ) ) {
     193                        $output['custom_css'] = self::sanitize_css( is_scalar( $input['custom_css'] ) ? (string) $input['custom_css'] : '' );
    140194                }
    141195
    142196                // Always ensure defaults exist for any keys never saved before
    143197                // (first-ever save, or a key added in a newer plugin version).
    144                 $output = wp_parse_args( $output, $this->get_default_settings() );
    145 
    146                 return $output;
     198                return wp_parse_args( $output, $defaults );
    147199        }
    148200
    … …  
    164216
    165217                $tab_fields = array(
    166                         'general'  => array( 'enable_swatches', 'enable_tooltip', 'auto_convert', 'out_of_stock_style', 'show_selected_name', 'swatch_shape', 'oos_notify_me', 'oos_notify_text', 'oos_notify_url' ),
     218                        'general'  => array( 'enable_swatches', 'enable_tooltip', 'auto_convert', 'out_of_stock_style', 'show_selected_name', 'swatch_shape', 'oos_notify_me', 'oos_notify_text', 'oos_notify_url', 'smart_finder' ),
    167219                        'design'   => array( 'tooltip_position', 'swatch_width', 'swatch_height', 'selected_checkmark', 'selected_checkmark_color', 'selected_border_color', 'border_color', 'tooltip_bg_color', 'tooltip_text_color', 'tooltip_font_size' ),
    168220                        'archive'  => array( 'show_on_archive', 'archive_swatch_width', 'archive_swatch_height' ),
    169                         'advanced' => array( 'enable_custom_css', 'custom_css' ),
     221                        'advanced' => array( 'enable_custom_css', 'custom_css', 'delete_data_on_uninstall' ),
    170222                );
    171223
    … …  
    179231         * @return array
    180232         */
    181         private static function get_default_settings() {
     233        public static function get_default_settings() {
    182234                return array(
    183235                        'enable_swatches'          => 'yes',
    … …  
    192244                        'selected_checkmark'       => 'yes',
    193245                        'selected_checkmark_color' => '#ffffff',
    194                         'auto_convert'             => 'yes',
     246                        'auto_convert'             => 'no',
    195247                        'oos_notify_me'            => 'yes',
    196248                        'oos_notify_text'          => 'Notify me when available',
    197249                        'oos_notify_url'           => '',
    198250                        'show_selected_name'       => 'yes',
     251                        'tooltip_position'         => 'top',
    199252                        'tooltip_bg_color'         => '#333333',
    200253                        'tooltip_text_color'       => '#ffffff',
    … …  
    204257                        'custom_css'               => '',
    205258                        'enable_custom_css'        => 'no',
     259                        'smart_finder'             => 'no',
     260                        'delete_data_on_uninstall' => 'no',
    206261                );
    207262        }
    … …  
    214269        public static function get_all() {
    215270                $saved = get_option( 'svsw_settings', array() );
    216                 return wp_parse_args( $saved, self::get_default_settings() );
     271                return wp_parse_args( is_array( $saved ) ? $saved : array(), self::get_default_settings() );
    217272        }
    218273}
  • sayan-variation-swatches/trunk/languages/sayan-variation-swatches.pot

    r3555281 r3754408  
    1 # Copyright (C) 2024 Sayan
    2 # This file is distributed under the same license as the Sayan Variation Swatches – Variation Swatches for WooCommerce plugin.
     1# Copyright (C) 2026 devhasib
     2# This file is distributed under the GPL-2.0-or-later.
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Sayan Variation Swatches for WooCommerce 1.0.0\n"
    6 "Report-Msgid-Bugs-To: https://profiles.wordpress.org/devhasib/\n"
    7 "POT-Creation-Date: 2024-01-01 00:00+0000\n"
     5"Project-Id-Version: Variation Swatches for WooCommerce 1.0.6\n"
     6"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/sayan-variation-swatches\n"
     7"POT-Creation-Date: 2026-10-08T00:00:00+00:00\n"
    88"MIME-Version: 1.0\n"
    99"Content-Type: text/plain; charset=UTF-8\n"
    1010"Content-Transfer-Encoding: 8bit\n"
    11 "PO-Revision-Date: 2024-01-01 00:00+0000\n"
    12 "Last-Translator: devhasib <https://github.com/hasibur12>\n"
    13 "Language-Team: devhasib <https://github.com/hasibur12>\n"
    14 "Language: \n"
    15 "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
    16 "X-Generator: WP-CLI 2.9.0\n"
     11"Language: en\n"
     12"Plural-Forms: nplurals=2; plural=(n != 1);\n"
    1713"X-Domain: sayan-variation-swatches\n"
    1814
    19 #. Plugin Name of the plugin
    20 msgid "Sayan Variation Swatches – Variation Swatches for WooCommerce"
    21 msgstr ""
    22 
    23 #. Plugin URI of the plugin
    24 msgid "https://github.com/hasibur12/plugins/variation-swatches"
    25 msgstr ""
    26 
    27 #. Description of the plugin
    28 msgid "Transform boring WooCommerce variation dropdowns into beautiful color, image, label, and radio swatches. Boost conversions with a stunning product selection experience."
    29 msgstr ""
    30 
    31 #. Author of the plugin
    32 msgid "devhasib"
    33 msgstr ""
    34 
    35 #: includes/class-svsw-helpers.php:32
     15#: admin/class-svsw-admin.php:50 admin/class-svsw-admin.php:51
     16msgid "Variation Swatches"
     17msgstr ""
     18
     19#: admin/class-svsw-admin.php:102
     20msgid "Select Swatch Image"
     21msgstr ""
     22
     23#: admin/class-svsw-admin.php:103
     24msgid "Use this image"
     25msgstr ""
     26
     27#: admin/class-svsw-admin.php:114
     28msgid "You do not have permission to access this page."
     29msgstr ""
     30
     31#: admin/class-svsw-admin.php:120
     32msgid "General"
     33msgstr ""
     34
     35#: admin/class-svsw-admin.php:121
     36msgid "Design & Style"
     37msgstr ""
     38
     39#: admin/class-svsw-admin.php:122
     40msgid "Shop / Archive"
     41msgstr ""
     42
     43#: admin/class-svsw-admin.php:123
     44msgid "Advanced"
     45msgstr ""
     46
     47#: admin/class-svsw-admin.php:128 admin/views/settings-page.php:452
     48msgid "Pro Features"
     49msgstr ""
     50
     51#: admin/views/settings-page.php:30
     52msgid "Variation Swatches for WooCommerce"
     53msgstr ""
     54
     55#: admin/views/settings-page.php:33
     56msgid "Color, image, label and radio swatches for your variable products."
     57msgstr ""
     58
     59#: admin/views/settings-page.php:34 sayan-variation-swatches.php:212
     60msgid "Docs"
     61msgstr ""
     62
     63#: admin/views/settings-page.php:35 sayan-variation-swatches.php:213
     64msgid "Support"
     65msgstr ""
     66
     67#: admin/views/settings-page.php:49 sayan-variation-swatches.php:197
     68msgid "Settings"
     69msgstr ""
     70
     71#: admin/views/settings-page.php:87
     72msgid "Core Settings"
     73msgstr ""
     74
     75#: admin/views/settings-page.php:91
     76msgid "Enable Swatches"
     77msgstr ""
     78
     79#: admin/views/settings-page.php:98
     80msgid "Enable or disable variation swatches globally."
     81msgstr ""
     82
     83#: admin/views/settings-page.php:102
     84msgid "Auto-convert Dropdowns"
     85msgstr ""
     86
     87#: admin/views/settings-page.php:109
     88msgid "Automatically convert all dropdowns to label swatches when no type is set."
     89msgstr ""
     90
     91#: admin/views/settings-page.php:113
     92msgid "Swatch Shape"
     93msgstr ""
     94
     95#: admin/views/settings-page.php:128
     96msgid "Out-of-Stock Style"
     97msgstr ""
     98
     99#: admin/views/settings-page.php:137
     100msgid "How to display unavailable or out-of-stock variation swatches."
     101msgstr ""
     102
     103#: admin/views/settings-page.php:141
     104msgid "Show Selected Name"
     105msgstr ""
     106
     107#: admin/views/settings-page.php:148
     108msgid "Show the selected attribute name next to each swatch group."
     109msgstr ""
     110
     111#: admin/views/settings-page.php:158
     112msgid "Tooltip"
     113msgstr ""
     114
     115#: admin/views/settings-page.php:162
     116msgid "Enable Tooltip"
     117msgstr ""
     118
     119#: admin/views/settings-page.php:169
     120msgid "Show attribute name on hover as a tooltip."
     121msgstr ""
     122
     123#: admin/views/settings-page.php:179
     124msgid "Out-of-Stock \"Notify Me\""
     125msgstr ""
     126
     127#: admin/views/settings-page.php:183
     128msgid "Show Notify Me"
     129msgstr ""
     130
     131#: admin/views/settings-page.php:190
     132msgid "When a shopper picks an unavailable option, show a \"Notify me\" message under the swatches."
     133msgstr ""
     134
     135#: admin/views/settings-page.php:194
     136msgid "Message Text"
     137msgstr ""
     138
     139#: admin/views/settings-page.php:201
     140msgid "Link URL"
     141msgstr ""
     142
     143#: admin/views/settings-page.php:205
     144msgid "Optional. Where the message links to (for example a back-in-stock form). Only http and https links are accepted. Leave empty to show the text without a link."
     145msgstr ""
     146
     147#: admin/views/settings-page.php:215
     148msgid "Smart Variation Finder"
     149msgstr ""
     150
     151#: admin/views/settings-page.php:219
     152msgid "Enable Finder"
     153msgstr ""
     154
     155#: admin/views/settings-page.php:226
     156msgid "Adds a search box above the swatches on variable product pages. Shoppers can type words such as \"dark blue large\" to pick the matching options. It runs in the browser and contacts no external service."
     157msgstr ""
     158
     159#: admin/views/settings-page.php:238
     160msgid "Swatch Dimensions — Product Page"
     161msgstr ""
     162
     163#: admin/views/settings-page.php:242
     164msgid "Width (px)"
     165msgstr ""
     166
     167#: admin/views/settings-page.php:250
     168msgid "Height (px)"
     169msgstr ""
     170
     171#: admin/views/settings-page.php:264
     172msgid "Colors"
     173msgstr ""
     174
     175#: admin/views/settings-page.php:268
     176msgid "Border Color"
     177msgstr ""
     178
     179#: admin/views/settings-page.php:276
     180msgid "Selected Border Color"
     181msgstr ""
     182
     183#: admin/views/settings-page.php:284
     184msgid "Checkmark"
     185msgstr ""
     186
     187#: admin/views/settings-page.php:295
     188msgid "Enable checkmark on selected swatches and choose its color."
     189msgstr ""
     190
     191#: admin/views/settings-page.php:299
     192msgid "Tooltip Position"
     193msgstr ""
     194
     195#: admin/views/settings-page.php:304
     196msgid "Top"
     197msgstr ""
     198
     199#: admin/views/settings-page.php:305
     200msgid "Bottom"
     201msgstr ""
     202
     203#: admin/views/settings-page.php:306
     204msgid "Left"
     205msgstr ""
     206
     207#: admin/views/settings-page.php:307
     208msgid "Right"
     209msgstr ""
     210
     211#: admin/views/settings-page.php:314
     212msgid "Where the tooltip appears relative to the swatch."
     213msgstr ""
     214
     215#: admin/views/settings-page.php:318
     216msgid "Tooltip BG Color"
     217msgstr ""
     218
     219#: admin/views/settings-page.php:326
     220msgid "Tooltip Text Color"
     221msgstr ""
     222
     223#: admin/views/settings-page.php:334
     224msgid "Tooltip Font Size (px)"
     225msgstr ""
     226
     227#: admin/views/settings-page.php:349
     228msgid "Shop / Archive / Category Pages"
     229msgstr ""
     230
     231#: admin/views/settings-page.php:353
     232msgid "Show Swatches on Archive"
     233msgstr ""
     234
     235#: admin/views/settings-page.php:360
     236msgid "Display swatches on shop, archive, and category pages."
     237msgstr ""
     238
     239#: admin/views/settings-page.php:364
     240msgid "Archive Swatch Width (px)"
     241msgstr ""
     242
     243#: admin/views/settings-page.php:372
     244msgid "Archive Swatch Height (px)"
     245msgstr ""
     246
     247#: admin/views/settings-page.php:387 admin/views/settings-page.php:401
     248msgid "Custom CSS"
     249msgstr ""
     250
     251#: admin/views/settings-page.php:391
     252msgid "Enable Custom CSS"
     253msgstr ""
     254
     255#: admin/views/settings-page.php:406
     256msgid "Target swatches using .svsw-* classes."
     257msgstr ""
     258
     259#: admin/views/settings-page.php:415
     260msgid "Data"
     261msgstr ""
     262
     263#: admin/views/settings-page.php:419
     264msgid "Delete Data on Uninstall"
     265msgstr ""
     266
     267#: admin/views/settings-page.php:426
     268msgid "When you delete the plugin, also remove its settings and the swatch values saved on attribute terms and products. Off by default, so your swatches survive a reinstall."
     269msgstr ""
     270
     271#: admin/views/settings-page.php:437
     272msgid "Save Settings"
     273msgstr ""
     274
     275#: admin/views/settings-page.php:453
     276msgid "A separate Pro plugin adds these features. The free plugin stays fully functional on its own."
     277msgstr ""
     278
     279#: admin/views/settings-page.php:461 admin/views/settings-page.php:466
     280msgid "Sticky Add-to-Cart Bar"
     281msgstr ""
     282
     283#: admin/views/settings-page.php:463
     284msgid "Show a floating bar with selected swatch, price, and Add to Cart button as customers scroll down the product page."
     285msgstr ""
     286
     287#: admin/views/settings-page.php:474 admin/views/settings-page.php:479
     288msgid "Per-Swatch Custom Badges"
     289msgstr ""
     290
     291#: admin/views/settings-page.php:476
     292msgid "Add \"New\", \"Hot\", \"Sale\", \"Limited\" or custom badges to individual swatches directly from the term edit screen."
     293msgstr ""
     294
     295#: admin/views/settings-page.php:487 admin/views/settings-page.php:492
     296msgid "Per-Variation Multi-Gallery"
     297msgstr ""
     298
     299#: admin/views/settings-page.php:489
     300msgid "Assign a full image gallery to each variation. Selecting a swatch replaces the entire product gallery — main image and all thumbnails."
     301msgstr ""
     302
     303#: admin/views/settings-page.php:500 admin/views/settings-page.php:505
     304msgid "Bulk Swatch Generator"
     305msgstr ""
     306
     307#: admin/views/settings-page.php:502
     308msgid "Auto-assign colors, images, or types to all terms of an attribute at once. Includes auto color-detect from term names like \"Navy Blue\" → #000080."
     309msgstr ""
     310
     311#: admin/views/settings-page.php:513 admin/views/settings-page.php:518
     312msgid "Live Stock Badge on Swatch"
     313msgstr ""
     314
     315#: admin/views/settings-page.php:515
     316msgid "Show exact stock count on each swatch — \"Only 3 left!\" Creates urgency and drives faster purchase decisions."
     317msgstr ""
     318
     319#: admin/views/settings-page.php:523 includes/class-svsw-pro-teaser.php:46
     320msgid "Upgrade to Pro"
     321msgstr ""
     322
     323#: includes/class-svsw-ai-finder.php:30 includes/class-svsw-ai-finder.php:36
     324msgid "Find a variation"
     325msgstr ""
     326
     327#: includes/class-svsw-ai-finder.php:34
     328msgid "e.g. \"dark blue large\""
     329msgstr ""
     330
     331#: includes/class-svsw-ai-finder.php:38 includes/class-svsw-frontend.php:150 includes/class-svsw-frontend.php:699
     332msgid "Clear"
     333msgstr ""
     334
     335#: includes/class-svsw-ai-finder.php:85
     336msgid "No matching variation found. Try different keywords."
     337msgstr ""
     338
     339#: includes/class-svsw-ai-finder.php:86
     340msgid "Partial match — select remaining options below."
     341msgstr ""
     342
     343#: includes/class-svsw-attribute-manager.php:74 includes/class-svsw-attribute-manager.php:130
     344msgid "Swatch Type"
     345msgstr ""
     346
     347#: includes/class-svsw-attribute-manager.php:80 includes/class-svsw-attribute-manager.php:140
     348msgid "Select how this attribute will be displayed as a swatch."
     349msgstr ""
     350
     351#: includes/class-svsw-attribute-manager.php:84 includes/class-svsw-attribute-manager.php:146
     352msgid "Swatch Color"
     353msgstr ""
     354
     355#: includes/class-svsw-attribute-manager.php:86 includes/class-svsw-attribute-manager.php:150
     356msgid "Choose the swatch color."
     357msgstr ""
     358
     359#: includes/class-svsw-attribute-manager.php:90 includes/class-svsw-attribute-manager.php:156
     360msgid "Second Color (Dual)"
     361msgstr ""
     362
     363#: includes/class-svsw-attribute-manager.php:92
     364msgid "Optional: add a second color for a split/dual swatch."
     365msgstr ""
     366
     367#: includes/class-svsw-attribute-manager.php:96 includes/class-svsw-attribute-manager.php:166
     368msgid "Swatch Image"
     369msgstr ""
     370
     371#: includes/class-svsw-attribute-manager.php:98 includes/class-svsw-attribute-manager.php:170
     372msgid "Upload or select an image for this swatch."
     373msgstr ""
     374
     375#: includes/class-svsw-attribute-manager.php:102 includes/class-svsw-attribute-manager.php:176
     376msgid "Swatch Shape Override"
     377msgstr ""
     378
     379#: includes/class-svsw-attribute-manager.php:104 includes/class-svsw-attribute-manager.php:181
     380msgid "— Use Global Setting —"
     381msgstr ""
     382
     383#: includes/class-svsw-attribute-manager.php:109
     384msgid "Override the global swatch shape for this specific term (e.g. Circle for colors, Square for sizes)."
     385msgstr ""
     386
     387#: includes/class-svsw-attribute-manager.php:160
     388msgid "Optional second color for a split/dual swatch."
     389msgstr ""
     390
     391#: includes/class-svsw-attribute-manager.php:188
     392msgid "Override the global swatch shape for this term only."
     393msgstr ""
     394
     395#: includes/class-svsw-attribute-manager.php:210
     396msgid "Upload / Select Image"
     397msgstr ""
     398
     399#: includes/class-svsw-attribute-manager.php:213
     400msgid "Remove"
     401msgstr ""
     402
     403#: includes/class-svsw-attribute-manager.php:282
     404msgid "Swatch"
     405msgstr ""
     406
     407#: includes/class-svsw-frontend.php:680
     408msgid "This option is currently unavailable."
     409msgstr ""
     410
     411#: includes/class-svsw-helpers.php:86
    36412msgid "Color"
    37413msgstr ""
    38414
    39 #: includes/class-svsw-helpers.php:33
     415#: includes/class-svsw-helpers.php:87
    40416msgid "Image"
    41417msgstr ""
    42418
    43 #: includes/class-svsw-helpers.php:34
     419#: includes/class-svsw-helpers.php:88
    44420msgid "Label / Button"
    45421msgstr ""
    46422
    47 #: includes/class-svsw-helpers.php:35
     423#: includes/class-svsw-helpers.php:89
    48424msgid "Radio"
    49425msgstr ""
    50426
    51 #: includes/class-svsw-helpers.php:36
     427#: includes/class-svsw-helpers.php:90
    52428msgid "Select (Default)"
    53429msgstr ""
    54430
    55 #: includes/class-svsw-helpers.php:47
     431#: includes/class-svsw-helpers.php:101
    56432msgid "Square"
    57433msgstr ""
    58434
    59 #: includes/class-svsw-helpers.php:48
     435#: includes/class-svsw-helpers.php:102
    60436msgid "Rounded"
    61437msgstr ""
    62438
    63 #: includes/class-svsw-helpers.php:49
     439#: includes/class-svsw-helpers.php:103
    64440msgid "Circle"
    65441msgstr ""
    66442
    67 #: includes/class-svsw-helpers.php:58
     443#: includes/class-svsw-helpers.php:122
    68444msgid "Blur with Cross"
    69445msgstr ""
    70446
    71 #: includes/class-svsw-helpers.php:59
     447#: includes/class-svsw-helpers.php:123
    72448msgid "Blur only"
    73449msgstr ""
    74450
    75 #: includes/class-svsw-helpers.php:60
     451#: includes/class-svsw-helpers.php:124
    76452msgid "Hide"
    77453msgstr ""
    78454
    79 #: sayan-variation-swatches.php:57
    80 msgid "Sayan Variation Swatches requires %s to be installed and active."
    81 msgstr ""
    82 
    83 #: sayan-variation-swatches.php:111
    84 msgid "Settings"
    85 msgstr ""
    86 
    87 #: admin/class-svsw-admin.php:56
    88 msgid "Sayan Variation Swatches"
    89 msgstr ""
    90 
    91 #: admin/class-svsw-admin.php:85
    92 msgid "Select Swatch Image"
    93 msgstr ""
    94 
    95 #: admin/class-svsw-admin.php:86
    96 msgid "Use this image"
    97 msgstr ""
    98 
    99 #: admin/class-svsw-admin.php:91
    100 msgid "You do not have permission to access this page."
    101 msgstr ""
    102 
    103 #: admin/views/settings-page.php
    104 msgid "Sayan Variation Swatches"
    105 msgstr ""
    106 
    107 #: admin/views/settings-page.php
    108 msgid "Beautiful product swatches for WooCommerce"
    109 msgstr ""
    110 
    111 #: admin/views/settings-page.php
    112 msgid "General"
    113 msgstr ""
    114 
    115 #: admin/views/settings-page.php
    116 msgid "Design & Style"
    117 msgstr ""
    118 
    119 #: admin/views/settings-page.php
    120 msgid "Shop / Archive"
    121 msgstr ""
    122 
    123 #: admin/views/settings-page.php
    124 msgid "Advanced"
    125 msgstr ""
    126 
    127 #: admin/views/settings-page.php
    128 msgid "Save Settings"
    129 msgstr ""
    130 
    131 #: public/js/svsw-frontend.js
    132 msgid "Clear"
    133 msgstr ""
     455#: includes/class-svsw-pro-teaser.php:47
     456msgid "⚡ Pro"
     457msgstr ""
     458
     459#. translators: %s: feature name
     460#: includes/class-svsw-pro-teaser.php:65
     461#, php-format
     462msgid "%s is a Pro feature."
     463msgstr ""
     464
     465#. translators: %s: feature name
     466#: includes/class-svsw-pro-teaser.php:66
     467msgid "This is a Pro feature."
     468msgstr ""
     469
     470#: includes/class-svsw-pro-teaser.php:76
     471msgid "Upgrade to Pro →"
     472msgstr ""
     473
     474#: includes/class-svsw-product-meta.php:71
     475msgid "Swatch type for this product"
     476msgstr ""
     477
     478#: includes/class-svsw-product-meta.php:73
     479msgid "Add a global attribute, save the product, then choose a swatch type here for just this product."
     480msgstr ""
     481
     482#: includes/class-svsw-product-meta.php:75
     483msgid "Optional. Overrides the swatch type set on the attribute terms, for this product only."
     484msgstr ""
     485
     486#: includes/class-svsw-product-meta.php:81
     487msgid "— Use attribute setting —"
     488msgstr ""
     489
     490#: includes/class-svsw-review-notice.php:118
     491msgid "Enjoying Variation Swatches for WooCommerce?"
     492msgstr ""
     493
     494#: includes/class-svsw-review-notice.php:122
     495msgid "You've been using the plugin for a while — great! Would you mind taking 1 minute to leave a review on WordPress.org? It helps other store owners discover the plugin and motivates us to keep improving it."
     496msgstr ""
     497
     498#: includes/class-svsw-review-notice.php:132
     499msgid "Leave a Review"
     500msgstr ""
     501
     502#: includes/class-svsw-review-notice.php:137
     503msgid "Don't ask again"
     504msgstr ""
     505
     506#: includes/class-svsw-settings-io.php:49
     507msgid "Settings imported successfully."
     508msgstr ""
     509
     510#: includes/class-svsw-settings-io.php:50
     511msgid "No file was uploaded. Choose a JSON file exported from this plugin and try again."
     512msgstr ""
     513
     514#: includes/class-svsw-settings-io.php:51
     515msgid "The file is empty or larger than 64 KB, so it was not imported."
     516msgstr ""
     517
     518#: includes/class-svsw-settings-io.php:52
     519msgid "Only a .json file exported from this plugin can be imported."
     520msgstr ""
     521
     522#: includes/class-svsw-settings-io.php:53
     523msgid "The file could not be read as JSON."
     524msgstr ""
     525
     526#: includes/class-svsw-settings-io.php:54
     527msgid "The file does not look like a settings export from this plugin."
     528msgstr ""
     529
     530#: includes/class-svsw-settings-io.php:55
     531msgid "The file contains a value of an unexpected type, so nothing was imported."
     532msgstr ""
     533
     534#: includes/class-svsw-settings-io.php:96
     535msgid "Export / Import Settings"
     536msgstr ""
     537
     538#: includes/class-svsw-settings-io.php:100
     539msgid "Export"
     540msgstr ""
     541
     542#: includes/class-svsw-settings-io.php:102
     543msgid "Download settings (JSON)"
     544msgstr ""
     545
     546#: includes/class-svsw-settings-io.php:103
     547msgid "Saves all plugin settings to a file. Swatch values on attribute terms are not included."
     548msgstr ""
     549
     550#: includes/class-svsw-settings-io.php:107
     551msgid "Import"
     552msgstr ""
     553
     554#: includes/class-svsw-settings-io.php:113
     555msgid "Import settings"
     556msgstr ""
     557
     558#: includes/class-svsw-settings-io.php:115
     559msgid "Import replaces your current settings with the values in the file. Maximum file size is 64 KB."
     560msgstr ""
     561
     562#: includes/class-svsw-settings-io.php:128
     563msgid "You do not have permission to export these settings."
     564msgstr ""
     565
     566#: includes/class-svsw-settings-io.php:150
     567msgid "You do not have permission to import settings."
     568msgstr ""
     569
     570#. translators: %s: WooCommerce link
     571#: sayan-variation-swatches.php:67
     572#, php-format
     573msgid "Variation Swatches for WooCommerce requires %s to be installed and active."
     574msgstr ""
     575
     576#. translators: %d: number of hidden variation options
     577#: includes/class-svsw-frontend.php:720 includes/class-svsw-frontend.php:727
     578#, php-format
     579msgid "%d more option"
     580msgid_plural "%d more options"
     581msgstr[0] ""
     582msgstr[1] ""
  • sayan-variation-swatches/trunk/readme.txt

    r3722355 r3754408  
    11=== Variation Swatches for WooCommerce – Color, Image & Label Swatches ===
    2 Contributors: devhasib,webtendhq
    3 Tags: variation-swatches, color-swatches, woocommerce, variable-products, product-attributes
     2Contributors: devhasib, webtendhq
     3Tags: variation swatches, color swatches, woocommerce, swatches, variable products
    44Requires at least: 6.4
    55Tested up to: 7.1
    66Requires PHP: 7.4
    7 Stable tag: 1.0.5
     7Requires Plugins: woocommerce
     8Stable tag: 1.0.6
    89License: GPLv2 or later
    910License URI: https://www.gnu.org/licenses/gpl-2.0.html
    10 WC requires at least: 7.0
    11 WC tested up to: 9.9
    1211
    13 Replace WooCommerce dropdowns with color, image, label & radio swatches. Works on product, shop & archive pages.
     12Variation swatches for WooCommerce: color, image, label & radio swatches on product, shop & archive pages. Free dual-color swatches.
    1413
    1514== Description ==
    1615
    17 **Variation Swatches for WooCommerce** replaces the default dropdown-based variation selectors with visually rich swatches — colors, images, labels, and radio buttons. It improves product browsing experience by making variation selection faster, clearer, and more user-friendly.
     16**Variation Swatches for WooCommerce** replaces the default dropdowns on variable products with color, image, label and radio swatches. Shoppers see every option at a glance, choose faster and get a clearer product page on desktop and mobile.
    1817
    19 📖 [View Documentation](https://storzen.webtend.net/variation-swatches-docs.html) | 🌐 [WebTend](https://webtend.net/)
     18You pick a swatch type for each global product attribute term under **Products → Attributes**, and the variation swatches appear on the product page and on shop and archive pages. Everything listed below is included in the free plugin, with no key or account needed.
    2019
    21 = 🎨 FREE Features  =
     20📖 [View Documentation](https://webtend.net/docs/variation-swatches-doc.html) | 🌐 [WebTend](https://webtend.net/)
    2221
    23 * ✅ **Dual / Split Color Swatches** — two-tone color swatches, free (competitors charge Pro for this)
    24 * ✅ **Archive & Shop Page Swatches** — show swatches on category/shop pages, free (usually a Pro feature)
    25 * ✅ **Color Swatches** — solid hex color swatches for any attribute
    26 * ✅ **Image Swatches** — upload per-term images for visual variation selection
    27 * ✅ **Label / Button Swatches** — S, M, L, XL text buttons for size and more
    28 * ✅ **Radio Button Swatches** — classic radio-style selectors
    29 * ✅ **Archive "+N More" Indicator** — shows overflow count cleanly on shop pages
    30 * ✅ **WooCommerce Product Blocks** — archive swatches inside woocommerce/product-collection & all-products blocks
    31 * ✅ **Out-of-Stock Notify Me** — inline popup with "Notify me when available" link on OOS swatch click
    32 * ✅ **Selected Swatch Animation** — smooth scale-pop & ripple ring on selection (CSS-only, reduced-motion safe)
    33 * ✅ **Attribute Label Display** — shows "Color: Red" inline with swatches
    3422
    35 = ⚡ Advanced Variation Features =
     23= Swatch types =
     24* Color swatches, including dual (split) color swatches
     25* Image swatches, uploaded per attribute term
     26* Label (button) swatches for sizes and other text options
     27* Radio swatches
     28* Square, rounded or circle shapes, with an optional shape per attribute term
     29* A different swatch type for a single product, set on the product's attribute panel
    3630
    37 * Automatic variation image switching on swatch click (no page reload)
    38 * Out-of-stock display control: blur, blur + cross, or hide completely
    39 * Per-product swatch type override (global attribute type overridable per product)
    40 * Auto-convert all dropdowns to label swatches with one toggle
    41 * Show / hide selected attribute name alongside swatches
     31= Shop & archive pages =
     32* WooCommerce variation swatches on shop, category and other archive pages
     33* A "+N more" badge when a product has more options than fit
     34* Works inside the WooCommerce Product Collection and All Products blocks
    4235
    43 = 🎨 Design & Customization =
     36= Stock handling =
     37* Out-of-stock variations can be blurred, blurred with a cross, or hidden
     38* An optional "Notify me" message with your own text and link when a shopper picks an unavailable option
    4439
    45 * Square, rounded, and circle swatch shapes (global setting)
    46 * Custom swatch size for product pages and archive pages separately
    47 * Tooltip support with customizable background and text colors
    48 * Selected state indicator with custom checkmark color
    49 * Custom CSS field for advanced styling
     40= Design controls =
     41* Swatch size, border and selected-state colors, checkmark, tooltip colors and size
     42* Tooltip position: top, bottom, left or right
     43* Optional custom CSS
    5044
    51 = 🏪 Shop & Archive Enhancements =
     45= Smart Variation Finder (optional) =
     46A search box above the swatches on product pages. Shoppers can type words such as "dark blue large" and the matching options are selected. It runs in the browser and is switched off until you enable it.
    5247
    53 Show variation swatches directly on shop and category pages. Customers can preview product color/size options without opening product pages — proven to increase click-through rates.
     48= Accessibility =
     49Swatches use radio roles with ARIA states, work with the keyboard and show a visible focus outline. Animations respect reduced motion.
    5450
    55 = ♿ Accessibility =
     51= Compatibility =
     52* Declares HPOS and Cart and Checkout Blocks compatibility
     53* Built on standard WooCommerce hooks, so it is designed to work with most themes
     54* Re-initializes inside quick view modals and Elementor product widgets
    5655
    57 * ARIA roles (`role="radio"`, `aria-checked`) for screen readers
    58 * Full keyboard navigation: Arrow keys, Enter, Space, Escape
    59 * Screen-reader-friendly markup structure
     56= How it works =
     571. Go to **Products → Attributes**, then add or edit an attribute such as Color and add its terms.
     582. Edit a term and choose a **Swatch Type**, then set the color, second color or image.
     593. Create a variable product that uses the attribute.
     604. Open the product page or the shop page. The dropdown is replaced by swatches.
     615. Fine-tune the look under **Variation Swatches**, in the General, Design & Style, Shop / Archive and Advanced tabs.
    6062
    61 = ⚙️ Performance & Compatibility =
     63= Perfect for =
     64Fashion, furniture, cosmetics, electronics and any other store that wants clearer variation swatches for its variable products.
    6265
    63 * Lightweight — settings cached in memory, no repeated DB queries on archive pages
    64 * No unnecessary AJAX requests on the frontend
    65 * Fully compatible with WooCommerce HPOS (High-Performance Order Storage)
    66 * Compatible with WooCommerce Cart and Checkout Blocks
    67 * Works with Astra, Flatsome, OceanWP, Storefront, GeneratePress, Divi, and most WooCommerce themes
     66= Documentation & support =
     67* Documentation: https://webtend.net/docs/variation-swatches/
     68* Support forum: https://wordpress.org/support/plugin/sayan-variation-swatches/
     69* Help translate the plugin: https://translate.wordpress.org/projects/wp-plugins/sayan-variation-swatches/
    6870
    69 = 🏆 Perfect For =
     71= Pro version =
     72A separate Pro plugin from webtend.net adds a sticky add-to-cart bar, per-swatch badges, per-variation galleries, a bulk swatch generator and a live stock badge. The free plugin stays fully functional on its own and nothing in it is locked. Details: https://webtend.net/
    7073
    71 * Fashion and clothing stores (color + size swatches)
    72 * Furniture and home décor shops (image swatches)
    73 * Cosmetics and beauty products (dual-color swatches)
    74 * Any WooCommerce store with variable products
     74= Privacy =
     75This plugin does not collect personal data and makes no external requests. It uses no third-party services, trackers or CDNs.
    7576
    76 = How It Works =
    77 
    78 1. Install and activate the plugin
    79 2. Go to **Products → Attributes**
    80 3. Edit an attribute term (e.g. "Red" under Color)
    81 4. Choose swatch type: color, image, label, or radio
    82 5. Assign values and save — swatches appear automatically
    83 
    84 = Variation Image Switching =
    85 
    86 When a customer selects a swatch, the product gallery image updates instantly — no page reload. Smooth, fast, conversion-friendly.
    87 
    88 = Frequently Asked Questions =
    8977== Installation ==
    9078
    91 1. Upload the plugin folder to `/wp-content/plugins/`, or install via the WordPress plugin screen.
    92 2. Activate through **Plugins → Installed Plugins**.
    93 3. Go to **Products → Attributes**, edit any attribute term, and set its Swatch type, color, or image.
    94 4. Configure plugin-wide settings under **Variation Swatches** in the WP admin menu.
    95 5. Done — swatches automatically replace dropdowns on product and shop pages.
     791. Make sure WooCommerce is installed and active.
     802. Upload the plugin to the `/wp-content/plugins/` directory, or install it from **Plugins → Add New**.
     813. Activate it, then edit an attribute term under **Products → Attributes** and choose a swatch type.
    9682
    9783== Frequently Asked Questions ==
    9884
    99 = Does this work with all WooCommerce themes? =
    100 Yes. Works with Astra, Flatsome, OceanWP, Storefront, GeneratePress, Divi, and most WooCommerce themes.
     85= Does it work with my theme? =
     86It uses standard WooCommerce hooks and is designed to work with most themes. If a theme replaces the variation form with its own markup, tell us on the support forum.
    10187
    10288= Does it work with Elementor? =
    103 Yes, on standard product pages. Elementor Loop Builder archive swatches are a Pro (Swatchly Pro) feature.
     89Yes, on standard product pages, including the Single Product widget gallery. On archive pages the swatches appear where your template runs WooCommerce's standard product loop hooks. Please check Loop Grid and Loop Builder templates on your own site and report any problem on the support forum.
    10490
    105 = Does it work with WooCommerce Product Blocks? =
    106 Yes. From v1.0.5, archive swatches render inside woocommerce/product-collection (WC 8.0+) and woocommerce/all-products blocks.
     91= Does it work with the WooCommerce product blocks? =
     92Yes. Archive swatches are added to the Product Collection and All Products blocks. Turn them on under **Variation Swatches → Shop / Archive**.
    10793
    10894= Does it work with WPML or Polylang? =
    109 Yes — fully translation-ready with a .pot file included.
     95The plugin is translation ready and ships a .pot file. Attribute term names come from WooCommerce, so they follow your multilingual plugin. Please test your own setup.
    11096
    11197= Does it work on shop and category pages? =
    112 Yes. Archive/shop page swatches are a free feature. Enable them under Settings → Archive tab.
     98Yes. Shop and archive swatches are on by default. Change them under **Variation Swatches → Shop / Archive**.
    11399
    114100= What happens to out-of-stock variations? =
    115 Choose to blur, blur + cross, or hide OOS swatches. From v1.0.5, clicking an OOS swatch shows a "Notify me when available" popup.
     101Choose to blur, blur with a cross, or hide them under **Variation Swatches → General → Out-of-Stock Style**. The "Notify me" message is set up in the same tab.
    116102
    117 = Can I control which direction the tooltip appears? =
    118 Yes. From v1.0.5, go to Settings → Design → Tooltip Position and choose Top, Bottom, Left, or Right.
     103= Can I change the tooltip direction? =
     104Yes. Go to **Variation Swatches → Design & Style → Tooltip Position**.
    119105
    120 = How does the AI Variation Finder work? =
    121 Type natural language like "dark blue large" in the search box on the product page. The finder auto-selects matching swatches — no API key, no AJAX, runs entirely in the browser.
     106= What is the Smart Variation Finder? =
     107A small search box on product pages that picks matching swatches from typed words. Enable it under **Variation Swatches → General → Smart Variation Finder**. It works in the browser only.
    122108
    123 = Is it mobile-friendly? =
    124 Yes. Swatches are touch-friendly on all screen sizes.
     109= Is it compatible with HPOS and the Cart and Checkout Blocks? =
     110Yes. The plugin declares compatibility with both. It does not change orders or the checkout.
    125111
    126 = Is it translation ready? =
    127 Yes. A .pot file is included and all strings use the sayan-variation-swatches text domain.
     112= Will it slow my store? =
     113The plugin's CSS and JavaScript load on product, shop and archive pages and wherever a swatch is rendered, not on every page. It makes no external requests.
     114
     115= Does it support custom (local) attributes? =
     116Partly. Color and image swatches need global attributes (**Products → Attributes**) because the colors and images are stored on the attribute terms. A custom attribute entered on a single product can be shown as label or radio swatches, chosen in the product's attribute panel.
     117
     118= Where do I get support? =
     119On the support forum: https://wordpress.org/support/plugin/sayan-variation-swatches/
     120
     121= What is the difference between free and Pro? =
     122The free plugin contains every swatch type, shop and archive swatches, stock handling and design controls. The separate Pro plugin adds a sticky add-to-cart bar, per-swatch badges, per-variation galleries, a bulk swatch generator and a live stock badge.
    128123
    129124== Screenshots ==
    130125
    131 1. Product page with Color, Image, and Label swatches
    132 2. Plugin Settings Panel — General and Design tabs
    133 3. Archive / Shop page swatches with overflow badge
    134 4. Attribute Term Edit screen — swatch type and color picker
    135 5. AI Variation Finder search box in action
     1261. Product page with color, image and label swatches
     1272. Plugin settings panel, General tab
     1283. Archive and shop page swatches with the "+N more" badge
     1294. Attribute term edit screen with swatch type and color picker
     1305. Smart Variation Finder search box on a product page
    136131
    137132== Changelog ==
    138133
    139 = Does this work with all WooCommerce themes? =
    140 
    141 Yes. The plugin uses standard WooCommerce hooks and works with most modern WooCommerce themes including Astra, Flatsome, OceanWP, Storefront, GeneratePress, and Divi.
    142 
    143 = Can I assign different swatches per product? =
    144 
    145 Yes. Set global swatches per attribute term, then override the swatch type per product if needed.
    146 
    147 = Does it support custom (local) attributes? =
    148 
    149 Yes. Both global WooCommerce attributes and custom per-product attributes work with swatches.
    150 
    151 = What happens to out-of-stock variations? =
    152 
    153 You can choose to blur, blur + cross-mark, or completely hide out-of-stock swatches from the Settings panel.
    154 
    155 = Does it work on shop and category pages? =
    156 
    157 Yes — archive/shop page swatches are available in the free version. Enable them from **Settings → Shop / Archive** tab.
    158 
    159 = Is it translation ready? =
    160 
    161 Yes. Fully translation ready and compatible with WPML, Polylang, and other multilingual plugins. A .pot file is included.
    162 
    163 = Screenshots =
    164 
    165 1. Product page with color, image, and label variation swatches
    166 2. Plugin settings panel — General tab
    167 3. Design & Style customization options
    168 4. Archive / shop page swatches display
    169 5. Attribute term edit screen with swatch type selector
    170 
    171 = Changelog =
     134= 1.0.6 =
     135* New: Pro Features tab under Variation Swatches with an overview of the separate Pro plugin
     136* New: Smart Variation Finder switch under Variation Swatches → General (off for new installs, stays on for existing stores)
     137* New: "Delete Data on Uninstall" switch under Variation Swatches → Advanced (off by default)
     138* New: Per-product swatch type on the product's Attributes panel
     139* New: Docs and Support links on the Plugins screen and in the settings header
     140* Improved: CSS and JavaScript now load only on product, shop and archive pages and where swatches are shown
     141* Improved: The review notice counts login sessions, appears only on the Dashboard, Plugins and settings screens, and has a permanent "Don't ask again" button
     142* Fixed: Settings Export / Import now works on the Advanced tab
     143* Fixed: Tooltip Position and the Notify Me text and link can now be changed in the settings
     144* Fixed: The per-term shape override is now applied on product and archive pages
     145* Fixed: "Show Selected Name" now works, and "Auto-convert dropdowns" now converts unset attributes to label swatches (off by default)
     146* Fixed: Shop managers can now save the plugin settings
     147* Fixed: Block archive swatches no longer appear when swatches are switched off
     148* Fixed: A PHP error when rendering archive swatches
     149* Security: Stricter custom CSS (administrators only, remote imports removed), http and https only for the Notify Me link, extra capability check when saving term swatches
     150* Dev: New filter `svsw_load_assets` to load the swatch assets on a custom page
    172151
    173152= 1.0.5 =
    174 * **New:** Pro Features tab in Settings -- previews Sticky ATC Bar, Per-Swatch Badges, Multi-Gallery, Bulk Generator, Elementor Loop Builder, Live Stock Badge with upgrade prompts
    175 * **New:** WooCommerce Product Blocks compatibility -- archive swatches now render inside woocommerce/product-collection (WC 8.0+) and woocommerce/all-products blocks
    176 * **New:** Out-of-Stock Notify Me -- clicking an OOS swatch shows an inline "Notify me when available" popup with optional redirect link (configurable in General settings)
    177 * **New:** Selected swatch highlight animation -- CSS-only scale-pop and ripple ring on swatch selection; label/radio swatches get a smooth color transition instead; respects prefers-reduced-motion
     153* New: WooCommerce Product Blocks compatibility for Product Collection (WC 8.0+) and All Products blocks
     154* New: Out-of-Stock Notify Me message with optional link
     155* New: Tooltip Position setting under Design & Style
     156* New: Selected swatch highlight animation that respects prefers-reduced-motion
    178157
    179158= 1.0.4 =
    180 * **New:** Elementor Loop Builder compatibility — archive swatches now render correctly inside Elementor's Loop Builder, WooCommerce Products, and related product widgets
    181 * **New:** Settings Export / Import — download all settings as JSON, restore on any site with one click (Advanced tab)
    182 * **New:** Per-attribute term shape override — set Circle for Color attribute, Square for Size on the term edit screen independently of the global shape setting
    183 * **New:** Styled "Clear Selection" button — replaces WooCommerce's plain text clear link with a polished, accessible button
    184 * **Improvement:** Admin term list column — now shows a colored type badge (Color / Image / Label / Radio), shape override badge, and a more accurate swatch preview with correct border-radius per shape
     159* New: Elementor Loop Builder compatibility for archive swatches
     160* New: Settings Export / Import
     161* New: Per-attribute term shape override
     162* New: Styled "Clear Selection" button
     163* Improved: Admin term list column shows a type badge, shape badge and a more accurate preview
    185164
    186165= 1.0.3 =
    187 * **New:** Review notice system — politely prompts active users to leave a WP.org review after 7 days or 3 admin sessions
    188 * **New:** Archive "+N more" overflow badge — shows remaining swatch count cleanly when there are many variations
    189 * **New:** Attribute label display — shows "Color: Red" inline alongside swatches on product pages
    190 * **New:** Quick View plugin compatibility — MutationObserver-based reinit for dynamically loaded product modals
    191 * **Improvement:** Settings static cache — `get_option()` called once per request instead of once per swatch render, significantly reducing DB queries on archive pages with many products
    192 * **Fix:** "Tested up to" mismatch — plugin header and readme.txt now both declare WordPress 7.1
    193 * **Fix:** "WC tested up to" updated from "8.x" placeholder to accurate version
    194 * **Fix:** Plugin display name updated to keyword-first title for better WP.org search visibility
    195 * **Fix:** Author URI updated to webtend.net
     166* New: Review notice, archive "+N more" badge, attribute label next to swatches, Quick View compatibility
     167* Improved: Settings are read once per request instead of once per swatch
     168* Fixed: "Tested up to" values, plugin name and Author URI
    196169
    197170= 1.0.2 =
    198 * Fixed: saving settings on one tab was resetting settings on other tabs back to defaults. Each tab now saves independently.
     171* Fixed: Saving settings on one tab reset the other tabs to defaults
    199172
    200173= 1.0.1 =
    201 * Added compatibility guard so the plugin runs safely alongside Sayan Variation Swatches Pro without function/class redeclaration conflicts.
     174* New: Compatibility guard so the plugin runs next to Sayan Variation Swatches Pro
    202175
    203176= 1.0.0 =
    204177* Initial release
     178
     179== Upgrade Notice ==
     180
     181= 1.0.6 =
     182Fixes Settings Export/Import and the Pro Features tab, applies per-term shape overrides and loads assets only where swatches appear. Smart Variation Finder is now a setting and stays on for existing stores. Back up before updating.
  • sayan-variation-swatches/trunk/sayan-variation-swatches.php

    r3722355 r3754408  
    33 * Plugin Name:       Variation Swatches for WooCommerce – Color, Image & Label Swatches
    44 * Plugin URI:        https://wordpress.org/plugins/sayan-variation-swatches/
    5  * Description:       Replace WooCommerce variation dropdowns with beautiful color, image, label, and radio swatches. Boost conversions with a better product selection experience.
    6  * Version:           1.0.5
     5 * Description:       Replace WooCommerce variation dropdowns with color, image, label, and radio swatches on product, shop, and archive pages.
     6 * Version:           1.0.6
    77 * Requires at least: 6.4
    88 * Tested up to:      7.1
    99 * Requires PHP:      7.4
    10  * Author:            WebTend
     10 * Requires Plugins:  woocommerce
     11 * Author:            devhasib
    1112 * Author URI:        https://webtend.net/
    1213 * License:           GPL-2.0-or-later
    … …  
    3233
    3334// Plugin constants.
    34 define( 'SVSW_VERSION', '1.0.5' );
     35define( 'SVSW_VERSION', '1.0.6' );
    3536define( 'SVSW_PLUGIN_FILE', __FILE__ );
    3637define( 'SVSW_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
    3738define( 'SVSW_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
    3839define( 'SVSW_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
     40define( 'SVSW_DOCS_URL', 'https://webtend.net/docs/variation-swatches/' );
     41define( 'SVSW_SUPPORT_URL', 'https://wordpress.org/support/plugin/sayan-variation-swatches/' );
    3942
    4043/**
    … …  
    5356 */
    5457function svsw_woocommerce_missing_notice() {
     58        if ( ! current_user_can( 'activate_plugins' ) ) {
     59                return;
     60        }
    5561        ?>
    56         <div class="notice notice-error">
     62        <div class="notice notice-error is-dismissible">
    5763                <p>
    5864                        <?php
    … …  
    6066                                /* translators: %s: WooCommerce link */
    6167                                esc_html__( 'Variation Swatches for WooCommerce requires %s to be installed and active.', 'sayan-variation-swatches' ),
    62                                 '<a href="https://woocommerce.com/" target="_blank">WooCommerce</a>'
     68                                '<a href="https://woocommerce.com/" target="_blank" rel="noopener noreferrer">WooCommerce</a>'
    6369                        );
    6470                        ?>
    … …  
    8490
    8591/**
    86  * Load textdomain on init hook (WP coding standards).
    87  */
    88 function svsw_load_textdomain() {
    89         load_plugin_textdomain( 'sayan-variation-swatches', false, dirname( SVSW_PLUGIN_BASENAME ) . '/languages' );
    90 }
    91 add_action( 'init', 'svsw_load_textdomain' );
     92 * One-time settings migration for stores upgrading from earlier releases.
     93 *
     94 * - Smart Variation Finder used to be always on; keep it on for existing
     95 *   stores (new installs get it switched off, it is a visible change).
     96 * - "Auto-convert dropdowns" was a setting that did nothing; it now works,
     97 *   so it is switched off for existing stores to avoid changing their look.
     98 */
     99function svsw_maybe_migrate_settings() {
     100        $saved = get_option( 'svsw_settings' );
     101        if ( ! is_array( $saved ) || array_key_exists( 'smart_finder', $saved ) ) {
     102                return;
     103        }
     104        $saved['smart_finder']             = 'yes';
     105        $saved['auto_convert']             = 'no';
     106        $saved['delete_data_on_uninstall'] = 'no';
     107        update_option( 'svsw_settings', $saved );
     108}
    92109
    93110/**
    … …  
    103120        require_once SVSW_PLUGIN_DIR . 'includes/class-svsw-helpers.php';
    104121        require_once SVSW_PLUGIN_DIR . 'includes/class-svsw-settings.php';
     122        require_once SVSW_PLUGIN_DIR . 'includes/class-svsw-settings-io.php';
    105123        require_once SVSW_PLUGIN_DIR . 'includes/class-svsw-attribute-manager.php';
    106124        require_once SVSW_PLUGIN_DIR . 'includes/class-svsw-product-meta.php';
    … …  
    111129        require_once SVSW_PLUGIN_DIR . 'admin/class-svsw-admin.php';
    112130
     131        // Keep existing stores behaving as before when new settings are introduced.
     132        svsw_maybe_migrate_settings();
     133
    113134        // Boot.
    114135        SVSW_Settings::get_instance();
    … …  
    118139        SVSW_Blocks_Compat::get_instance();
    119140        SVSW_AI_Finder::get_instance();
    120         SVSW_Blocks_Compat::get_instance();
    121141
    122142        if ( is_admin() ) {
    123143                SVSW_Admin::get_instance();
     144                SVSW_Settings_IO::init();
    124145                SVSW_Review_Notice::init();
    125146        }
    … …  
    146167                        'selected_checkmark'       => 'yes',
    147168                        'selected_checkmark_color' => '#ffffff',
    148                         'auto_convert'             => 'yes',
     169                        'auto_convert'             => 'no',
     170                        'smart_finder'             => 'no',
     171                        'delete_data_on_uninstall' => 'no',
    149172                );
    150173                update_option( 'svsw_settings', $defaults );
    … …  
    177200}
    178201add_filter( 'plugin_action_links_' . SVSW_PLUGIN_BASENAME, 'svsw_plugin_action_links' );
     202
     203/**
     204 * Add Docs and Support links to the Plugins list row meta.
     205 *
     206 * @param array  $links Row meta links.
     207 * @param string $file  Plugin basename.
     208 * @return array
     209 */
     210function svsw_plugin_row_meta( $links, $file ) {
     211        if ( SVSW_PLUGIN_BASENAME === $file ) {
     212                $links[] = '<a href="' . esc_url( SVSW_DOCS_URL ) . '" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Docs', 'sayan-variation-swatches' ) . '</a>';
     213                $links[] = '<a href="' . esc_url( SVSW_SUPPORT_URL ) . '" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Support', 'sayan-variation-swatches' ) . '</a>';
     214        }
     215        return $links;
     216}
     217add_filter( 'plugin_row_meta', 'svsw_plugin_row_meta', 10, 2 );
  • sayan-variation-swatches/trunk/uninstall.php

    r3682054 r3754408  
    44 *
    55 * Runs when the plugin is deleted from the WordPress admin.
    6  * Removes all plugin options and meta so the database is left clean.
     6 * Data is only removed when the site owner switched on
     7 * "Delete Data on Uninstall" (Variation Swatches → Advanced).
    78 *
    89 * @package Sayan_Variation_Swatches
    … …  
    1314}
    1415
     16$svsw_saved_settings = get_option( 'svsw_settings', array() );
     17if ( ! is_array( $svsw_saved_settings )
     18        || ! isset( $svsw_saved_settings['delete_data_on_uninstall'] )
     19        || 'yes' !== $svsw_saved_settings['delete_data_on_uninstall'] ) {
     20        return; // Keep the data: the owner did not ask for it to be removed.
     21}
     22
    1523// Remove plugin settings and review notice options.
    1624$svsw_options_to_delete = array(
    … …  
    1826        'svsw_install_date',
    1927        'svsw_admin_sessions',
     28        'svsw_last_session',
    2029        'svsw_review_dismissed',
    2130);
    … …  
    3241        'svsw_term_shape',
    3342);
    34 
    3543foreach ( $svsw_uninstall_term_meta_keys as $svsw_meta_key ) {
    36         $svsw_term_ids = get_terms(
    37                 array(
    38                         'taxonomy'   => get_taxonomies(),
    39                         'fields'     => 'ids',
    40                         'hide_empty' => false,
    41                         'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
    42                                 array(
    43                                         'key'     => $svsw_meta_key, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
    44                                         'compare' => 'EXISTS',
    45                                 ),
    46                         ),
    47                 )
    48         );
    49 
    50         if ( is_array( $svsw_term_ids ) ) {
    51                 foreach ( $svsw_term_ids as $svsw_term_id ) {
    52                         delete_term_meta( (int) $svsw_term_id, $svsw_meta_key );
    53                 }
    54         }
     44        delete_metadata( 'term', 0, $svsw_meta_key, '', true ); // Delete this key for every term.
    5545}
    5646
    … …  
    6050        '_svsw_shape',
    6151);
     52foreach ( $svsw_uninstall_post_meta_keys as $svsw_meta_key ) {
     53        delete_metadata( 'post', 0, $svsw_meta_key, '', true ); // Delete this key for every post/variation.
     54}
    6255
    63 foreach ( $svsw_uninstall_post_meta_keys as $svsw_post_meta_key ) {
    64         $svsw_post_ids = get_posts(
    65                 array(
    66                         'post_type'      => array( 'product', 'product_variation' ),
    67                         'posts_per_page' => -1,
    68                         'fields'         => 'ids',
    69                         'meta_query'     => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
    70                                 array(
    71                                         'key'     => $svsw_post_meta_key, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
    72                                         'compare' => 'EXISTS',
    73                                 ),
    74                         ),
    75                 )
    76         );
    77 
    78         if ( is_array( $svsw_post_ids ) ) {
    79                 foreach ( $svsw_post_ids as $svsw_post_id ) {
    80                         delete_post_meta( (int) $svsw_post_id, $svsw_post_meta_key );
    81                 }
    82         }
    83 }
     56wp_cache_flush();
Note: See TracChangeset for help on using the changeset viewer.