Changeset 3754408
- Timestamp:
- 10/19/2026 09:34:46 AM (4 weeks ago)
- Location:
- sayan-variation-swatches/trunk
- Files:
-
- 1 added
- 16 edited
-
admin/class-svsw-admin.php (modified) (1 diff)
-
admin/js/svsw-admin.js (modified) (1 diff)
-
admin/views/settings-page.php (modified) (11 diffs)
-
includes/class-svsw-ai-finder.php (modified) (2 diffs)
-
includes/class-svsw-attribute-manager.php (modified) (2 diffs)
-
includes/class-svsw-blocks-compat.php (modified) (4 diffs)
-
includes/class-svsw-frontend.php (modified) (18 diffs)
-
includes/class-svsw-pro-teaser.php (modified) (3 diffs)
-
includes/class-svsw-product-meta.php (modified) (5 diffs)
-
includes/class-svsw-review-notice.php (modified) (5 diffs)
-
includes/class-svsw-settings-io.php (modified) (2 diffs)
-
includes/class-svsw-settings.php (modified) (14 diffs)
-
languages/sayan-variation-swatches.pot (modified) (1 diff)
-
public/css/svsw-frontend-rtl.css (added)
-
readme.txt (modified) (1 diff)
-
sayan-variation-swatches.php (modified) (10 diffs)
-
uninstall.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sayan-variation-swatches/trunk/admin/class-svsw-admin.php
r3650520 r3754408 124 124 ); 125 125 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 126 131 /** 127 132 * Filter the settings page tabs. -
sayan-variation-swatches/trunk/admin/js/svsw-admin.js
r3555281 r3754408 94 94 $preview.find( 'img' ).length 95 95 ? $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' } ) ); 97 97 98 98 $preview.removeClass( 'svsw-hidden' ); -
sayan-variation-swatches/trunk/admin/views/settings-page.php
r3722355 r3754408 17 17 'archive' => 'dashicons-store', 18 18 'advanced'=> 'dashicons-editor-code', 19 'pro' => 'dashicons-star-filled', 19 20 ); 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.NonceVerification22 echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( '✅ Settings imported successfully.', 'sayan-variation-swatches' ) . '</p></div>';23 }24 21 ?> 25 22 <div class="wrap svsw-admin-wrap"> … … 34 31 </h1> 35 32 <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> 37 36 </p> 38 37 </div> … … 40 39 <span class="svsw-version-badge">v<?php echo esc_html( SVSW_VERSION ); ?></span> 41 40 </div> 41 42 <?php SVSW_Settings_IO::render_notice(); ?> 42 43 43 44 <!-- ── Two-column layout ── --> … … 172 173 </div> 173 174 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 174 232 <?php elseif ( 'design' === $tab ) : ?> 175 233 … … 239 297 </tr> 240 298 <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> 241 318 <th scope="row"><?php esc_html_e( 'Tooltip BG Color', 'sayan-variation-swatches' ); ?></th> 242 319 <td> … … 333 410 </div> 334 411 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> 336 431 337 432 <?php endif; ?> 338 433 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 340 450 <div class="svsw-settings-card"> 341 451 <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> 344 454 </div> 345 455 … … 354 464 </div> 355 465 </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' ) ); ?> 357 467 </div> 358 468 … … 367 477 </div> 368 478 </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' ) ); ?> 370 480 </div> 371 481 … … 380 490 </div> 381 491 </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' ) ); ?> 383 493 </div> 384 494 … … 393 503 </div> 394 504 </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' ) ); ?> 409 506 </div> 410 507 … … 419 516 </div> 420 517 </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' ) ); ?> 422 519 </div> 423 520 424 521 <div style="text-align:center;padding:24px 0 8px;"> 425 522 <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 SwatchlyPro', 'sayan-variation-swatches' ); ?> →523 <?php esc_html_e( 'Upgrade to Pro', 'sayan-variation-swatches' ); ?> → 427 524 </a> 428 525 </div> 429 526 </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 438 528 <?php else : ?> 439 529 -
sayan-variation-swatches/trunk/includes/class-svsw-ai-finder.php
r3722355 r3754408 1 1 <?php 2 2 /** 3 * S VSW AI Variation Finder — client-side fuzzysearch.3 * Smart Variation Finder — client-side keyword search. 4 4 * No API key. No AJAX. GDPR safe. 5 5 * … … 15 15 } 16 16 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 } 17 21 add_action( 'woocommerce_before_variations_form', array( $this, 'inject_search_box' ) ); 18 22 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ), 25 ); -
sayan-variation-swatches/trunk/includes/class-svsw-attribute-manager.php
r3722355 r3754408 44 44 add_action( 'created_term', array( $this, 'save_term_meta' ), 10, 3 ); 45 45 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' ) );48 46 } 49 47 … … 232 230 return; 233 231 } 232 if ( ! current_user_can( 'manage_product_terms' ) ) { 233 return; 234 } 234 235 235 236 // Only process pa_* attribute taxonomies. -
sayan-variation-swatches/trunk/includes/class-svsw-blocks-compat.php
r3722355 r3754408 34 34 35 35 private function __construct() { 36 if ( ! SVSW_Helpers:: show_on_archive() ) {36 if ( ! SVSW_Helpers::is_enabled() || ! SVSW_Helpers::show_on_archive() ) { 37 37 return; 38 38 } … … 45 45 // Product Collection block (WC 8.0+). 46 46 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 );49 47 } 50 48 … … 119 117 ob_start(); 120 118 SVSW_Frontend::get_instance()->output_archive_swatches_markup( $product, $attrs ); 119 $this->enqueue_reinit(); 121 120 return ob_get_clean(); 122 121 } … … 124 123 /* ── Reinit script ─────────────────────────────── */ 125 124 125 /** 126 * Add the re-init script once per request, after the swatch assets are enqueued. 127 */ 126 128 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' ) ) { 128 131 return; 129 132 } 133 $added = true; 130 134 $js = <<<'JS' 131 135 ( function() { -
sayan-variation-swatches/trunk/includes/class-svsw-frontend.php
r3722355 r3754408 29 29 30 30 /** 31 * Per-request cache of available variations, keyed by product ID. 32 * 33 * @var array 34 */ 35 private $variations_cache = array(); 36 37 /** 31 38 * Get or create the singleton. 32 39 * … … 49 56 50 57 // Enqueue assets. 51 add_action( 'wp_enqueue_scripts', array( $this, ' enqueue_scripts' ) );58 add_action( 'wp_enqueue_scripts', array( $this, 'maybe_enqueue_assets' ) ); 52 59 53 60 // Replace dropdown with swatch HTML on product page. … … 72 79 73 80 /** 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 /** 74 104 * 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; 77 113 $settings = SVSW_Settings::get_all(); 78 114 … … 83 119 SVSW_VERSION 84 120 ); 121 wp_style_add_data( 'svsw-frontend', 'rtl', true ); 85 122 86 123 wp_enqueue_script( … … 107 144 'enable_tooltip' => SVSW_Helpers::is_tooltip_enabled(), 108 145 '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'], 110 147 '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' ) ), 117 154 ) 118 155 ) … … 124 161 // Custom CSS from settings. 125 162 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'] ) ); 127 164 } 128 165 } … … 198 235 $has_swatches = true; 199 236 $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 ); 201 238 } 202 239 } else { … … 206 243 if ( 'select' === $type ) { 207 244 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'; 208 249 } 209 250 $has_swatches = true; … … 223 264 } 224 265 266 // Make sure CSS/JS are present even on pages where they were not enqueued early. 267 $this->enqueue_assets(); 268 225 269 $shape_class = SVSW_Helpers::get_shape_class(); 226 270 $name = 'attribute_' . esc_attr( $taxonomy ); … … 284 328 * @return string HTML. 285 329 */ 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 ) { 287 331 $is_available = $this->is_term_available( $product, $taxonomy, $slug ); 288 332 … … 306 350 $classes = array( 'svsw-swatch', 'svsw-type-' . esc_attr( $type ) ); 307 351 $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 } 308 358 if ( ! $is_available && 'blur_cross' === $oos_style ) { 309 359 $classes[] = 'svsw-cross'; … … 389 439 390 440 /** 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. 394 458 * @param string $taxonomy Attribute taxonomy. 395 459 * @param string $slug Term slug. … … 400 464 return true; 401 465 } 402 $variations = $ product->get_available_variations( 'array');466 $variations = $this->get_cached_variations( $product ); 403 467 $attr_key = 'attribute_' . $taxonomy; 404 468 … … 428 492 $main_img_id = (int) $product->get_image_id(); 429 493 430 $variations = $ product->get_available_variations( 'array');494 $variations = $this->get_cached_variations( $product ); 431 495 432 496 foreach ( $variations as $variation_data ) { … … 528 592 ); 529 593 $max = absint( $args['max_swatches'] ); 594 595 $this->enqueue_assets(); 530 596 531 597 echo '<div class="svsw-archive-swatches" data-product_id="' . absint( $product->get_id() ) . '">'; … … 586 652 $swatch_data = SVSW_Attribute_Manager::get_term_swatch_data( $term->term_id, $product->get_id() ); 587 653 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 ) ); 589 655 $count++; 590 656 } … … 607 673 } 608 674 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', '' ); 611 678 612 679 echo '<div class="svsw-notify-popup" style="display:none;" aria-live="polite">'; 613 680 echo '<span class="svsw-notify-icon" aria-hidden="true">⏰</span> '; 614 681 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>'; 617 684 } 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>'; 619 686 } 620 687 echo '</div>'; … … 676 743 * @return string HTML. 677 744 */ 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 ); 680 747 $classes = 'svsw-swatch svsw-archive-swatch svsw-type-' . esc_attr( $type ) . ' ' . $shape_class; 681 748 -
sayan-variation-swatches/trunk/includes/class-svsw-pro-teaser.php
r3722355 r3754408 44 44 '<a href="%1$s" target="_blank" rel="noopener noreferrer" class="svsw-pro-badge" title="%2$s">%3$s</a>', 45 45 esc_url( self::UPGRADE_URL ), 46 esc_attr__( 'Upgrade to SwatchlyPro', 'sayan-variation-swatches' ),46 esc_attr__( 'Upgrade to Pro', 'sayan-variation-swatches' ), 47 47 esc_html__( '⚡ Pro', 'sayan-variation-swatches' ) 48 48 ); … … 62 62 public static function lock_notice( $feature = '', $echo = true ) { 63 63 $feature_label = $feature 64 /* translators: %s: feature name */ 64 65 ? sprintf( esc_html__( '%s is a Pro feature.', 'sayan-variation-swatches' ), esc_html( $feature ) ) 65 66 : esc_html__( 'This is a Pro feature.', 'sayan-variation-swatches' ); … … 73 74 $feature_label, 74 75 esc_url( self::UPGRADE_URL ), 75 esc_html__( 'Upgrade to SwatchlyPro →', 'sayan-variation-swatches' )76 esc_html__( 'Upgrade to Pro →', 'sayan-variation-swatches' ) 76 77 ); 77 78 -
sayan-variation-swatches/trunk/includes/class-svsw-product-meta.php
r3580855 r3754408 38 38 */ 39 39 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. 45 41 add_action( 'woocommerce_product_options_attributes', array( $this, 'product_attribute_swatch_meta' ) ); 46 42 add_action( 'woocommerce_process_product_meta', array( $this, 'save_product_attribute_meta' ) ); … … 48 44 49 45 /** 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. 100 48 */ 101 49 public function product_attribute_swatch_meta() { … … 104 52 return; 105 53 } 54 106 55 $overrides = get_post_meta( $post->ID, '_svsw_attribute_overrides', true ); 107 56 $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 } 108 68 ?> 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;"> 111 70 <?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; ?> 112 89 </div> 113 90 <?php … … 127 104 return; 128 105 } 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 } 129 110 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. 137 112 $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 ) { 139 115 $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 } 141 120 $clean[ $attr_name ] = $type; 142 121 } 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 } 144 128 } 145 129 … … 154 138 */ 155 139 public static function get_effective_type( $product_id, $taxonomy, $term_id ) { 140 $allowed = array_keys( SVSW_Helpers::get_swatch_types() ); 141 156 142 // Check per-product override first. 157 143 $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 ) ) { 159 145 return $overrides[ $taxonomy ]; 160 146 } 147 161 148 // 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'; 163 160 } 164 161 } -
sayan-variation-swatches/trunk/includes/class-svsw-review-notice.php
r3650520 r3754408 22 22 /** @var string Option key: cumulative admin session counter. */ 23 23 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'; 24 27 25 28 /** @var string Option key: dismissed flag. */ … … 47 50 48 51 /** 49 * Increment the admin session counter once per page load.50 * Bails early if the notice has already beendismissed.52 * Increment the admin session counter once per login session 53 * (not once per page load). Bails early if the notice was dismissed. 51 54 */ 52 55 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' ) ) { 54 57 return; 55 58 } 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 ); 58 69 } 59 70 … … 69 80 // Only show to users who can manage WooCommerce. 70 81 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 ) ) { 71 88 return; 72 89 } … … 95 112 $ajax_nonce = wp_create_nonce( 'svsw_dismiss_review_ajax' ); 96 113 ?> 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 ); ?>"> 98 115 <span class="dashicons dashicons-star-filled" style="color:#f0b429;font-size:28px;margin-top:2px;flex-shrink:0;"></span> 99 116 <div style="flex:1;"> … … 113 130 target="_blank" rel="noopener noreferrer" 114 131 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' ); ?> 116 133 </a> 117 134 118 135 <a href="<?php echo esc_url( $dismiss_url ); ?>" 119 136 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' ); ?> 121 138 </a> 122 139 </p> 123 140 </div> 124 141 </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: formData140 } );141 if ( notice ) { notice.style.display = 'none'; }142 } );143 } )();144 </script>145 142 <?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 ); 146 158 } 147 159 -
sayan-variation-swatches/trunk/includes/class-svsw-settings-io.php
r3682054 r3754408 3 3 * SVSW Settings Import / Export 4 4 * 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. 14 8 * 15 9 * @package Sayan_Variation_Swatches … … 24 18 25 19 /** 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 /** 26 35 * Register hooks. 27 * Called from svsw_init() when is_admin() is true.28 36 */ 29 37 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. 116 83 */ 117 84 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 ); 137 92 ?> 138 93 <div class="svsw-card"> 139 94 <div class="svsw-card__header"> 140 95 <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> 142 97 </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> 190 119 </div> 191 120 <?php 192 121 } 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 } 193 241 } -
sayan-variation-swatches/trunk/includes/class-svsw-settings.php
r3722355 r3754408 39 39 private function __construct() { 40 40 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'; 41 53 } 42 54 … … 55 67 56 68 /** 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 /** 57 84 * Sanitize the settings array before saving. 58 85 * … … 67 94 $existing = get_option( 'svsw_settings', array() ); 68 95 $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 } 69 101 70 102 // Checkbox / yes-no fields — only update ones present in this submission. … … 77 109 'show_selected_name', 78 110 'enable_custom_css', 111 'oos_notify_me', 112 'smart_finder', 113 'delete_data_on_uninstall', 79 114 ); 80 115 foreach ( $yes_no_fields as $field ) { … … 87 122 // Select fields with allowed values. 88 123 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() ); 90 125 $output['swatch_shape'] = in_array( $input['swatch_shape'], $shape_options, true ) 91 126 ? $input['swatch_shape'] … … 94 129 95 130 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() ); 97 132 $output['out_of_stock_style'] = in_array( $input['out_of_stock_style'], $oos_options, true ) 98 133 ? $input['out_of_stock_style'] 99 134 : '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'; 100 141 } 101 142 … … 113 154 } 114 155 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 ) ); 118 159 } 119 160 … … 121 162 $color_fields = array( 122 163 'selected_checkmark_color' => '#ffffff', 123 'tooltip_position' => 'top',124 164 'tooltip_bg_color' => '#333333', 125 165 'tooltip_text_color' => '#ffffff', … … 131 171 continue; 132 172 } 133 $val = SVSW_Helpers::sanitize_hex_color( $input[ $field ]);173 $val = SVSW_Helpers::sanitize_hex_color( is_scalar( $input[ $field ] ) ? (string) $input[ $field ] : '' ); 134 174 $output[ $field ] = $val ? $val : $default; 135 175 } 136 176 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'] : '' ); 140 194 } 141 195 142 196 // Always ensure defaults exist for any keys never saved before 143 197 // (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 ); 147 199 } 148 200 … … 164 216 165 217 $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' ), 167 219 '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' ), 168 220 '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' ), 170 222 ); 171 223 … … 179 231 * @return array 180 232 */ 181 p rivatestatic function get_default_settings() {233 public static function get_default_settings() { 182 234 return array( 183 235 'enable_swatches' => 'yes', … … 192 244 'selected_checkmark' => 'yes', 193 245 'selected_checkmark_color' => '#ffffff', 194 'auto_convert' => ' yes',246 'auto_convert' => 'no', 195 247 'oos_notify_me' => 'yes', 196 248 'oos_notify_text' => 'Notify me when available', 197 249 'oos_notify_url' => '', 198 250 'show_selected_name' => 'yes', 251 'tooltip_position' => 'top', 199 252 'tooltip_bg_color' => '#333333', 200 253 'tooltip_text_color' => '#ffffff', … … 204 257 'custom_css' => '', 205 258 'enable_custom_css' => 'no', 259 'smart_finder' => 'no', 260 'delete_data_on_uninstall' => 'no', 206 261 ); 207 262 } … … 214 269 public static function get_all() { 215 270 $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() ); 217 272 } 218 273 } -
sayan-variation-swatches/trunk/languages/sayan-variation-swatches.pot
r3555281 r3754408 1 # Copyright (C) 202 4 Sayan2 # 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. 3 3 msgid "" 4 4 msgstr "" 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: 202 4-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" 8 8 "MIME-Version: 1.0\n" 9 9 "Content-Type: text/plain; charset=UTF-8\n" 10 10 "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" 17 13 "X-Domain: sayan-variation-swatches\n" 18 14 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 16 msgid "Variation Swatches" 17 msgstr "" 18 19 #: admin/class-svsw-admin.php:102 20 msgid "Select Swatch Image" 21 msgstr "" 22 23 #: admin/class-svsw-admin.php:103 24 msgid "Use this image" 25 msgstr "" 26 27 #: admin/class-svsw-admin.php:114 28 msgid "You do not have permission to access this page." 29 msgstr "" 30 31 #: admin/class-svsw-admin.php:120 32 msgid "General" 33 msgstr "" 34 35 #: admin/class-svsw-admin.php:121 36 msgid "Design & Style" 37 msgstr "" 38 39 #: admin/class-svsw-admin.php:122 40 msgid "Shop / Archive" 41 msgstr "" 42 43 #: admin/class-svsw-admin.php:123 44 msgid "Advanced" 45 msgstr "" 46 47 #: admin/class-svsw-admin.php:128 admin/views/settings-page.php:452 48 msgid "Pro Features" 49 msgstr "" 50 51 #: admin/views/settings-page.php:30 52 msgid "Variation Swatches for WooCommerce" 53 msgstr "" 54 55 #: admin/views/settings-page.php:33 56 msgid "Color, image, label and radio swatches for your variable products." 57 msgstr "" 58 59 #: admin/views/settings-page.php:34 sayan-variation-swatches.php:212 60 msgid "Docs" 61 msgstr "" 62 63 #: admin/views/settings-page.php:35 sayan-variation-swatches.php:213 64 msgid "Support" 65 msgstr "" 66 67 #: admin/views/settings-page.php:49 sayan-variation-swatches.php:197 68 msgid "Settings" 69 msgstr "" 70 71 #: admin/views/settings-page.php:87 72 msgid "Core Settings" 73 msgstr "" 74 75 #: admin/views/settings-page.php:91 76 msgid "Enable Swatches" 77 msgstr "" 78 79 #: admin/views/settings-page.php:98 80 msgid "Enable or disable variation swatches globally." 81 msgstr "" 82 83 #: admin/views/settings-page.php:102 84 msgid "Auto-convert Dropdowns" 85 msgstr "" 86 87 #: admin/views/settings-page.php:109 88 msgid "Automatically convert all dropdowns to label swatches when no type is set." 89 msgstr "" 90 91 #: admin/views/settings-page.php:113 92 msgid "Swatch Shape" 93 msgstr "" 94 95 #: admin/views/settings-page.php:128 96 msgid "Out-of-Stock Style" 97 msgstr "" 98 99 #: admin/views/settings-page.php:137 100 msgid "How to display unavailable or out-of-stock variation swatches." 101 msgstr "" 102 103 #: admin/views/settings-page.php:141 104 msgid "Show Selected Name" 105 msgstr "" 106 107 #: admin/views/settings-page.php:148 108 msgid "Show the selected attribute name next to each swatch group." 109 msgstr "" 110 111 #: admin/views/settings-page.php:158 112 msgid "Tooltip" 113 msgstr "" 114 115 #: admin/views/settings-page.php:162 116 msgid "Enable Tooltip" 117 msgstr "" 118 119 #: admin/views/settings-page.php:169 120 msgid "Show attribute name on hover as a tooltip." 121 msgstr "" 122 123 #: admin/views/settings-page.php:179 124 msgid "Out-of-Stock \"Notify Me\"" 125 msgstr "" 126 127 #: admin/views/settings-page.php:183 128 msgid "Show Notify Me" 129 msgstr "" 130 131 #: admin/views/settings-page.php:190 132 msgid "When a shopper picks an unavailable option, show a \"Notify me\" message under the swatches." 133 msgstr "" 134 135 #: admin/views/settings-page.php:194 136 msgid "Message Text" 137 msgstr "" 138 139 #: admin/views/settings-page.php:201 140 msgid "Link URL" 141 msgstr "" 142 143 #: admin/views/settings-page.php:205 144 msgid "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." 145 msgstr "" 146 147 #: admin/views/settings-page.php:215 148 msgid "Smart Variation Finder" 149 msgstr "" 150 151 #: admin/views/settings-page.php:219 152 msgid "Enable Finder" 153 msgstr "" 154 155 #: admin/views/settings-page.php:226 156 msgid "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." 157 msgstr "" 158 159 #: admin/views/settings-page.php:238 160 msgid "Swatch Dimensions — Product Page" 161 msgstr "" 162 163 #: admin/views/settings-page.php:242 164 msgid "Width (px)" 165 msgstr "" 166 167 #: admin/views/settings-page.php:250 168 msgid "Height (px)" 169 msgstr "" 170 171 #: admin/views/settings-page.php:264 172 msgid "Colors" 173 msgstr "" 174 175 #: admin/views/settings-page.php:268 176 msgid "Border Color" 177 msgstr "" 178 179 #: admin/views/settings-page.php:276 180 msgid "Selected Border Color" 181 msgstr "" 182 183 #: admin/views/settings-page.php:284 184 msgid "Checkmark" 185 msgstr "" 186 187 #: admin/views/settings-page.php:295 188 msgid "Enable checkmark on selected swatches and choose its color." 189 msgstr "" 190 191 #: admin/views/settings-page.php:299 192 msgid "Tooltip Position" 193 msgstr "" 194 195 #: admin/views/settings-page.php:304 196 msgid "Top" 197 msgstr "" 198 199 #: admin/views/settings-page.php:305 200 msgid "Bottom" 201 msgstr "" 202 203 #: admin/views/settings-page.php:306 204 msgid "Left" 205 msgstr "" 206 207 #: admin/views/settings-page.php:307 208 msgid "Right" 209 msgstr "" 210 211 #: admin/views/settings-page.php:314 212 msgid "Where the tooltip appears relative to the swatch." 213 msgstr "" 214 215 #: admin/views/settings-page.php:318 216 msgid "Tooltip BG Color" 217 msgstr "" 218 219 #: admin/views/settings-page.php:326 220 msgid "Tooltip Text Color" 221 msgstr "" 222 223 #: admin/views/settings-page.php:334 224 msgid "Tooltip Font Size (px)" 225 msgstr "" 226 227 #: admin/views/settings-page.php:349 228 msgid "Shop / Archive / Category Pages" 229 msgstr "" 230 231 #: admin/views/settings-page.php:353 232 msgid "Show Swatches on Archive" 233 msgstr "" 234 235 #: admin/views/settings-page.php:360 236 msgid "Display swatches on shop, archive, and category pages." 237 msgstr "" 238 239 #: admin/views/settings-page.php:364 240 msgid "Archive Swatch Width (px)" 241 msgstr "" 242 243 #: admin/views/settings-page.php:372 244 msgid "Archive Swatch Height (px)" 245 msgstr "" 246 247 #: admin/views/settings-page.php:387 admin/views/settings-page.php:401 248 msgid "Custom CSS" 249 msgstr "" 250 251 #: admin/views/settings-page.php:391 252 msgid "Enable Custom CSS" 253 msgstr "" 254 255 #: admin/views/settings-page.php:406 256 msgid "Target swatches using .svsw-* classes." 257 msgstr "" 258 259 #: admin/views/settings-page.php:415 260 msgid "Data" 261 msgstr "" 262 263 #: admin/views/settings-page.php:419 264 msgid "Delete Data on Uninstall" 265 msgstr "" 266 267 #: admin/views/settings-page.php:426 268 msgid "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." 269 msgstr "" 270 271 #: admin/views/settings-page.php:437 272 msgid "Save Settings" 273 msgstr "" 274 275 #: admin/views/settings-page.php:453 276 msgid "A separate Pro plugin adds these features. The free plugin stays fully functional on its own." 277 msgstr "" 278 279 #: admin/views/settings-page.php:461 admin/views/settings-page.php:466 280 msgid "Sticky Add-to-Cart Bar" 281 msgstr "" 282 283 #: admin/views/settings-page.php:463 284 msgid "Show a floating bar with selected swatch, price, and Add to Cart button as customers scroll down the product page." 285 msgstr "" 286 287 #: admin/views/settings-page.php:474 admin/views/settings-page.php:479 288 msgid "Per-Swatch Custom Badges" 289 msgstr "" 290 291 #: admin/views/settings-page.php:476 292 msgid "Add \"New\", \"Hot\", \"Sale\", \"Limited\" or custom badges to individual swatches directly from the term edit screen." 293 msgstr "" 294 295 #: admin/views/settings-page.php:487 admin/views/settings-page.php:492 296 msgid "Per-Variation Multi-Gallery" 297 msgstr "" 298 299 #: admin/views/settings-page.php:489 300 msgid "Assign a full image gallery to each variation. Selecting a swatch replaces the entire product gallery — main image and all thumbnails." 301 msgstr "" 302 303 #: admin/views/settings-page.php:500 admin/views/settings-page.php:505 304 msgid "Bulk Swatch Generator" 305 msgstr "" 306 307 #: admin/views/settings-page.php:502 308 msgid "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." 309 msgstr "" 310 311 #: admin/views/settings-page.php:513 admin/views/settings-page.php:518 312 msgid "Live Stock Badge on Swatch" 313 msgstr "" 314 315 #: admin/views/settings-page.php:515 316 msgid "Show exact stock count on each swatch — \"Only 3 left!\" Creates urgency and drives faster purchase decisions." 317 msgstr "" 318 319 #: admin/views/settings-page.php:523 includes/class-svsw-pro-teaser.php:46 320 msgid "Upgrade to Pro" 321 msgstr "" 322 323 #: includes/class-svsw-ai-finder.php:30 includes/class-svsw-ai-finder.php:36 324 msgid "Find a variation" 325 msgstr "" 326 327 #: includes/class-svsw-ai-finder.php:34 328 msgid "e.g. \"dark blue large\"" 329 msgstr "" 330 331 #: includes/class-svsw-ai-finder.php:38 includes/class-svsw-frontend.php:150 includes/class-svsw-frontend.php:699 332 msgid "Clear" 333 msgstr "" 334 335 #: includes/class-svsw-ai-finder.php:85 336 msgid "No matching variation found. Try different keywords." 337 msgstr "" 338 339 #: includes/class-svsw-ai-finder.php:86 340 msgid "Partial match — select remaining options below." 341 msgstr "" 342 343 #: includes/class-svsw-attribute-manager.php:74 includes/class-svsw-attribute-manager.php:130 344 msgid "Swatch Type" 345 msgstr "" 346 347 #: includes/class-svsw-attribute-manager.php:80 includes/class-svsw-attribute-manager.php:140 348 msgid "Select how this attribute will be displayed as a swatch." 349 msgstr "" 350 351 #: includes/class-svsw-attribute-manager.php:84 includes/class-svsw-attribute-manager.php:146 352 msgid "Swatch Color" 353 msgstr "" 354 355 #: includes/class-svsw-attribute-manager.php:86 includes/class-svsw-attribute-manager.php:150 356 msgid "Choose the swatch color." 357 msgstr "" 358 359 #: includes/class-svsw-attribute-manager.php:90 includes/class-svsw-attribute-manager.php:156 360 msgid "Second Color (Dual)" 361 msgstr "" 362 363 #: includes/class-svsw-attribute-manager.php:92 364 msgid "Optional: add a second color for a split/dual swatch." 365 msgstr "" 366 367 #: includes/class-svsw-attribute-manager.php:96 includes/class-svsw-attribute-manager.php:166 368 msgid "Swatch Image" 369 msgstr "" 370 371 #: includes/class-svsw-attribute-manager.php:98 includes/class-svsw-attribute-manager.php:170 372 msgid "Upload or select an image for this swatch." 373 msgstr "" 374 375 #: includes/class-svsw-attribute-manager.php:102 includes/class-svsw-attribute-manager.php:176 376 msgid "Swatch Shape Override" 377 msgstr "" 378 379 #: includes/class-svsw-attribute-manager.php:104 includes/class-svsw-attribute-manager.php:181 380 msgid "— Use Global Setting —" 381 msgstr "" 382 383 #: includes/class-svsw-attribute-manager.php:109 384 msgid "Override the global swatch shape for this specific term (e.g. Circle for colors, Square for sizes)." 385 msgstr "" 386 387 #: includes/class-svsw-attribute-manager.php:160 388 msgid "Optional second color for a split/dual swatch." 389 msgstr "" 390 391 #: includes/class-svsw-attribute-manager.php:188 392 msgid "Override the global swatch shape for this term only." 393 msgstr "" 394 395 #: includes/class-svsw-attribute-manager.php:210 396 msgid "Upload / Select Image" 397 msgstr "" 398 399 #: includes/class-svsw-attribute-manager.php:213 400 msgid "Remove" 401 msgstr "" 402 403 #: includes/class-svsw-attribute-manager.php:282 404 msgid "Swatch" 405 msgstr "" 406 407 #: includes/class-svsw-frontend.php:680 408 msgid "This option is currently unavailable." 409 msgstr "" 410 411 #: includes/class-svsw-helpers.php:86 36 412 msgid "Color" 37 413 msgstr "" 38 414 39 #: includes/class-svsw-helpers.php: 33415 #: includes/class-svsw-helpers.php:87 40 416 msgid "Image" 41 417 msgstr "" 42 418 43 #: includes/class-svsw-helpers.php: 34419 #: includes/class-svsw-helpers.php:88 44 420 msgid "Label / Button" 45 421 msgstr "" 46 422 47 #: includes/class-svsw-helpers.php: 35423 #: includes/class-svsw-helpers.php:89 48 424 msgid "Radio" 49 425 msgstr "" 50 426 51 #: includes/class-svsw-helpers.php: 36427 #: includes/class-svsw-helpers.php:90 52 428 msgid "Select (Default)" 53 429 msgstr "" 54 430 55 #: includes/class-svsw-helpers.php: 47431 #: includes/class-svsw-helpers.php:101 56 432 msgid "Square" 57 433 msgstr "" 58 434 59 #: includes/class-svsw-helpers.php: 48435 #: includes/class-svsw-helpers.php:102 60 436 msgid "Rounded" 61 437 msgstr "" 62 438 63 #: includes/class-svsw-helpers.php: 49439 #: includes/class-svsw-helpers.php:103 64 440 msgid "Circle" 65 441 msgstr "" 66 442 67 #: includes/class-svsw-helpers.php: 58443 #: includes/class-svsw-helpers.php:122 68 444 msgid "Blur with Cross" 69 445 msgstr "" 70 446 71 #: includes/class-svsw-helpers.php: 59447 #: includes/class-svsw-helpers.php:123 72 448 msgid "Blur only" 73 449 msgstr "" 74 450 75 #: includes/class-svsw-helpers.php: 60451 #: includes/class-svsw-helpers.php:124 76 452 msgid "Hide" 77 453 msgstr "" 78 454 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 456 msgid "⚡ Pro" 457 msgstr "" 458 459 #. translators: %s: feature name 460 #: includes/class-svsw-pro-teaser.php:65 461 #, php-format 462 msgid "%s is a Pro feature." 463 msgstr "" 464 465 #. translators: %s: feature name 466 #: includes/class-svsw-pro-teaser.php:66 467 msgid "This is a Pro feature." 468 msgstr "" 469 470 #: includes/class-svsw-pro-teaser.php:76 471 msgid "Upgrade to Pro →" 472 msgstr "" 473 474 #: includes/class-svsw-product-meta.php:71 475 msgid "Swatch type for this product" 476 msgstr "" 477 478 #: includes/class-svsw-product-meta.php:73 479 msgid "Add a global attribute, save the product, then choose a swatch type here for just this product." 480 msgstr "" 481 482 #: includes/class-svsw-product-meta.php:75 483 msgid "Optional. Overrides the swatch type set on the attribute terms, for this product only." 484 msgstr "" 485 486 #: includes/class-svsw-product-meta.php:81 487 msgid "— Use attribute setting —" 488 msgstr "" 489 490 #: includes/class-svsw-review-notice.php:118 491 msgid "Enjoying Variation Swatches for WooCommerce?" 492 msgstr "" 493 494 #: includes/class-svsw-review-notice.php:122 495 msgid "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." 496 msgstr "" 497 498 #: includes/class-svsw-review-notice.php:132 499 msgid "Leave a Review" 500 msgstr "" 501 502 #: includes/class-svsw-review-notice.php:137 503 msgid "Don't ask again" 504 msgstr "" 505 506 #: includes/class-svsw-settings-io.php:49 507 msgid "Settings imported successfully." 508 msgstr "" 509 510 #: includes/class-svsw-settings-io.php:50 511 msgid "No file was uploaded. Choose a JSON file exported from this plugin and try again." 512 msgstr "" 513 514 #: includes/class-svsw-settings-io.php:51 515 msgid "The file is empty or larger than 64 KB, so it was not imported." 516 msgstr "" 517 518 #: includes/class-svsw-settings-io.php:52 519 msgid "Only a .json file exported from this plugin can be imported." 520 msgstr "" 521 522 #: includes/class-svsw-settings-io.php:53 523 msgid "The file could not be read as JSON." 524 msgstr "" 525 526 #: includes/class-svsw-settings-io.php:54 527 msgid "The file does not look like a settings export from this plugin." 528 msgstr "" 529 530 #: includes/class-svsw-settings-io.php:55 531 msgid "The file contains a value of an unexpected type, so nothing was imported." 532 msgstr "" 533 534 #: includes/class-svsw-settings-io.php:96 535 msgid "Export / Import Settings" 536 msgstr "" 537 538 #: includes/class-svsw-settings-io.php:100 539 msgid "Export" 540 msgstr "" 541 542 #: includes/class-svsw-settings-io.php:102 543 msgid "Download settings (JSON)" 544 msgstr "" 545 546 #: includes/class-svsw-settings-io.php:103 547 msgid "Saves all plugin settings to a file. Swatch values on attribute terms are not included." 548 msgstr "" 549 550 #: includes/class-svsw-settings-io.php:107 551 msgid "Import" 552 msgstr "" 553 554 #: includes/class-svsw-settings-io.php:113 555 msgid "Import settings" 556 msgstr "" 557 558 #: includes/class-svsw-settings-io.php:115 559 msgid "Import replaces your current settings with the values in the file. Maximum file size is 64 KB." 560 msgstr "" 561 562 #: includes/class-svsw-settings-io.php:128 563 msgid "You do not have permission to export these settings." 564 msgstr "" 565 566 #: includes/class-svsw-settings-io.php:150 567 msgid "You do not have permission to import settings." 568 msgstr "" 569 570 #. translators: %s: WooCommerce link 571 #: sayan-variation-swatches.php:67 572 #, php-format 573 msgid "Variation Swatches for WooCommerce requires %s to be installed and active." 574 msgstr "" 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 579 msgid "%d more option" 580 msgid_plural "%d more options" 581 msgstr[0] "" 582 msgstr[1] "" -
sayan-variation-swatches/trunk/readme.txt
r3722355 r3754408 1 1 === Variation Swatches for WooCommerce – Color, Image & Label Swatches === 2 Contributors: devhasib, webtendhq3 Tags: variation -swatches, color-swatches, woocommerce, variable-products, product-attributes2 Contributors: devhasib, webtendhq 3 Tags: variation swatches, color swatches, woocommerce, swatches, variable products 4 4 Requires at least: 6.4 5 5 Tested up to: 7.1 6 6 Requires PHP: 7.4 7 Stable tag: 1.0.5 7 Requires Plugins: woocommerce 8 Stable tag: 1.0.6 8 9 License: GPLv2 or later 9 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 WC requires at least: 7.011 WC tested up to: 9.912 11 13 Replace WooCommerce dropdowns with color, image, label & radio swatches. Works on product, shop & archive pages.12 Variation swatches for WooCommerce: color, image, label & radio swatches on product, shop & archive pages. Free dual-color swatches. 14 13 15 14 == Description == 16 15 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. 18 17 19 📖 [View Documentation](https://storzen.webtend.net/variation-swatches-docs.html) | 🌐 [WebTend](https://webtend.net/) 18 You 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. 20 19 21 = 🎨 FREE Features = 20 📖 [View Documentation](https://webtend.net/docs/variation-swatches-doc.html) | 🌐 [WebTend](https://webtend.net/) 22 21 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 attribute26 * ✅ **Image Swatches** — upload per-term images for visual variation selection27 * ✅ **Label / Button Swatches** — S, M, L, XL text buttons for size and more28 * ✅ **Radio Button Swatches** — classic radio-style selectors29 * ✅ **Archive "+N More" Indicator** — shows overflow count cleanly on shop pages30 * ✅ **WooCommerce Product Blocks** — archive swatches inside woocommerce/product-collection & all-products blocks31 * ✅ **Out-of-Stock Notify Me** — inline popup with "Notify me when available" link on OOS swatch click32 * ✅ **Selected Swatch Animation** — smooth scale-pop & ripple ring on selection (CSS-only, reduced-motion safe)33 * ✅ **Attribute Label Display** — shows "Color: Red" inline with swatches34 22 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 36 30 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 42 35 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 44 39 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 50 44 51 = 🏪 Shop & Archive Enhancements = 45 = Smart Variation Finder (optional) = 46 A 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. 52 47 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 = 49 Swatches use radio roles with ARIA states, work with the keyboard and show a visible focus outline. Animations respect reduced motion. 54 50 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 56 55 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 = 57 1. Go to **Products → Attributes**, then add or edit an attribute such as Color and add its terms. 58 2. Edit a term and choose a **Swatch Type**, then set the color, second color or image. 59 3. Create a variable product that uses the attribute. 60 4. Open the product page or the shop page. The dropdown is replaced by swatches. 61 5. Fine-tune the look under **Variation Swatches**, in the General, Design & Style, Shop / Archive and Advanced tabs. 60 62 61 = ⚙️ Performance & Compatibility = 63 = Perfect for = 64 Fashion, furniture, cosmetics, electronics and any other store that wants clearer variation swatches for its variable products. 62 65 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/ 68 70 69 = 🏆 Perfect For = 71 = Pro version = 72 A 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/ 70 73 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 = 75 This plugin does not collect personal data and makes no external requests. It uses no third-party services, trackers or CDNs. 75 76 76 = How It Works =77 78 1. Install and activate the plugin79 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 radio82 5. Assign values and save — swatches appear automatically83 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 =89 77 == Installation == 90 78 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. 79 1. Make sure WooCommerce is installed and active. 80 2. Upload the plugin to the `/wp-content/plugins/` directory, or install it from **Plugins → Add New**. 81 3. Activate it, then edit an attribute term under **Products → Attributes** and choose a swatch type. 96 82 97 83 == Frequently Asked Questions == 98 84 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? = 86 It 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. 101 87 102 88 = Does it work with Elementor? = 103 Yes, on standard product pages . Elementor Loop Builder archive swatches are a Pro (Swatchly Pro) feature.89 Yes, 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. 104 90 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? = 92 Yes. Archive swatches are added to the Product Collection and All Products blocks. Turn them on under **Variation Swatches → Shop / Archive**. 107 93 108 94 = Does it work with WPML or Polylang? = 109 Yes — fully translation-ready with a .pot file included.95 The 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. 110 96 111 97 = Does it work on shop and category pages? = 112 Yes. Archive/shop page swatches are a free feature. Enable them under Settings → Archive tab.98 Yes. Shop and archive swatches are on by default. Change them under **Variation Swatches → Shop / Archive**. 113 99 114 100 = 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.101 Choose 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. 116 102 117 = Can I c ontrol 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? = 104 Yes. Go to **Variation Swatches → Design & Style → Tooltip Position**. 119 105 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? = 107 A 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. 122 108 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? = 110 Yes. The plugin declares compatibility with both. It does not change orders or the checkout. 125 111 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? = 113 The 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? = 116 Partly. 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? = 119 On the support forum: https://wordpress.org/support/plugin/sayan-variation-swatches/ 120 121 = What is the difference between free and Pro? = 122 The 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. 128 123 129 124 == Screenshots == 130 125 131 1. Product page with Color, Image, and Label swatches132 2. Plugin Settings Panel — General and Design tabs133 3. Archive / Shop page swatches with overflowbadge134 4. Attribute Term Edit screen —swatch type and color picker135 5. AI Variation Finder search box in action126 1. Product page with color, image and label swatches 127 2. Plugin settings panel, General tab 128 3. Archive and shop page swatches with the "+N more" badge 129 4. Attribute term edit screen with swatch type and color picker 130 5. Smart Variation Finder search box on a product page 136 131 137 132 == Changelog == 138 133 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 172 151 173 152 = 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 prompts175 * **New:** WooCommerce Product Blocks compatibility -- archive swatches now render inside woocommerce/product-collection (WC 8.0+) and woocommerce/all-products blocks176 * **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-motion153 * 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 178 157 179 158 = 1.0.4 = 180 * **New:** Elementor Loop Builder compatibility — archive swatches now render correctly inside Elementor's Loop Builder, WooCommerce Products, and related product widgets181 * **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 setting183 * **New:** Styled "Clear Selection" button — replaces WooCommerce's plain text clear link with a polished, accessiblebutton184 * **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 shape159 * 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 185 164 186 165 = 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 196 169 197 170 = 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 199 172 200 173 = 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 202 175 203 176 = 1.0.0 = 204 177 * Initial release 178 179 == Upgrade Notice == 180 181 = 1.0.6 = 182 Fixes 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 3 3 * Plugin Name: Variation Swatches for WooCommerce – Color, Image & Label Swatches 4 4 * 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. 55 * Description: Replace WooCommerce variation dropdowns with color, image, label, and radio swatches on product, shop, and archive pages. 6 * Version: 1.0.6 7 7 * Requires at least: 6.4 8 8 * Tested up to: 7.1 9 9 * Requires PHP: 7.4 10 * Author: WebTend 10 * Requires Plugins: woocommerce 11 * Author: devhasib 11 12 * Author URI: https://webtend.net/ 12 13 * License: GPL-2.0-or-later … … 32 33 33 34 // Plugin constants. 34 define( 'SVSW_VERSION', '1.0. 5' );35 define( 'SVSW_VERSION', '1.0.6' ); 35 36 define( 'SVSW_PLUGIN_FILE', __FILE__ ); 36 37 define( 'SVSW_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 37 38 define( 'SVSW_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); 38 39 define( 'SVSW_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); 40 define( 'SVSW_DOCS_URL', 'https://webtend.net/docs/variation-swatches/' ); 41 define( 'SVSW_SUPPORT_URL', 'https://wordpress.org/support/plugin/sayan-variation-swatches/' ); 39 42 40 43 /** … … 53 56 */ 54 57 function svsw_woocommerce_missing_notice() { 58 if ( ! current_user_can( 'activate_plugins' ) ) { 59 return; 60 } 55 61 ?> 56 <div class="notice notice-error ">62 <div class="notice notice-error is-dismissible"> 57 63 <p> 58 64 <?php … … 60 66 /* translators: %s: WooCommerce link */ 61 67 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>' 63 69 ); 64 70 ?> … … 84 90 85 91 /** 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 */ 99 function 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 } 92 109 93 110 /** … … 103 120 require_once SVSW_PLUGIN_DIR . 'includes/class-svsw-helpers.php'; 104 121 require_once SVSW_PLUGIN_DIR . 'includes/class-svsw-settings.php'; 122 require_once SVSW_PLUGIN_DIR . 'includes/class-svsw-settings-io.php'; 105 123 require_once SVSW_PLUGIN_DIR . 'includes/class-svsw-attribute-manager.php'; 106 124 require_once SVSW_PLUGIN_DIR . 'includes/class-svsw-product-meta.php'; … … 111 129 require_once SVSW_PLUGIN_DIR . 'admin/class-svsw-admin.php'; 112 130 131 // Keep existing stores behaving as before when new settings are introduced. 132 svsw_maybe_migrate_settings(); 133 113 134 // Boot. 114 135 SVSW_Settings::get_instance(); … … 118 139 SVSW_Blocks_Compat::get_instance(); 119 140 SVSW_AI_Finder::get_instance(); 120 SVSW_Blocks_Compat::get_instance();121 141 122 142 if ( is_admin() ) { 123 143 SVSW_Admin::get_instance(); 144 SVSW_Settings_IO::init(); 124 145 SVSW_Review_Notice::init(); 125 146 } … … 146 167 'selected_checkmark' => 'yes', 147 168 'selected_checkmark_color' => '#ffffff', 148 'auto_convert' => 'yes', 169 'auto_convert' => 'no', 170 'smart_finder' => 'no', 171 'delete_data_on_uninstall' => 'no', 149 172 ); 150 173 update_option( 'svsw_settings', $defaults ); … … 177 200 } 178 201 add_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 */ 210 function 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 } 217 add_filter( 'plugin_row_meta', 'svsw_plugin_row_meta', 10, 2 ); -
sayan-variation-swatches/trunk/uninstall.php
r3682054 r3754408 4 4 * 5 5 * 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). 7 8 * 8 9 * @package Sayan_Variation_Swatches … … 13 14 } 14 15 16 $svsw_saved_settings = get_option( 'svsw_settings', array() ); 17 if ( ! 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 15 23 // Remove plugin settings and review notice options. 16 24 $svsw_options_to_delete = array( … … 18 26 'svsw_install_date', 19 27 'svsw_admin_sessions', 28 'svsw_last_session', 20 29 'svsw_review_dismissed', 21 30 ); … … 32 41 'svsw_term_shape', 33 42 ); 34 35 43 foreach ( $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. 55 45 } 56 46 … … 60 50 '_svsw_shape', 61 51 ); 52 foreach ( $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 } 62 55 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 } 56 wp_cache_flush();
Note:
See TracChangeset
for help on using the changeset viewer.