WordPress.org

Plugin Directory

Changeset 1427953


Ignore:
Timestamp:
06/01/16 00:11:28 (17 months ago)
Author:
beka.rice
Message:

Tagging 2.2.0

Location:
woocommerce-product-sku-generator/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • woocommerce-product-sku-generator/trunk/i18n/languages/woocommerce-product-sku-generator.pot

    r1330720 r1427953  
    33msgid "" 
    44msgstr "" 
    5 "Project-Id-Version: WooCommerce Product SKU Generator 2.1.0\n" 
     5"Project-Id-Version: WooCommerce Product SKU Generator 2.2.0\n" 
    66"Report-Msgid-Bugs-To: " 
    77"https://github.com/skyverge/woocommerce-product-sku-generator/issues\n" 
     
    1414"Language-Team: LANGUAGE <LL@li.org>\n" 
    1515 
    16 #: build/woocommerce-product-sku-generator.php:41 
    17 #: woocommerce-product-sku-generator.php:41 
     16#: build/woocommerce-product-sku-generator.php:121 
     17#: woocommerce-product-sku-generator.php:121 
     18#. translators: Placeholders: %s - plugin name 
     19msgid "You cannot clone instances of %s." 
     20msgstr "" 
     21 
     22#: build/woocommerce-product-sku-generator.php:133 
     23#: woocommerce-product-sku-generator.php:133 
     24#. translators: Placeholders: %s - plugin name 
     25msgid "You cannot unserialize instances of %s." 
     26msgstr "" 
     27 
     28#: build/woocommerce-product-sku-generator.php:147 
     29#: woocommerce-product-sku-generator.php:147 
     30msgid "Configure" 
     31msgstr "" 
     32 
     33#: build/woocommerce-product-sku-generator.php:148 
     34#: woocommerce-product-sku-generator.php:148 
     35msgid "FAQ" 
     36msgstr "" 
     37 
     38#: build/woocommerce-product-sku-generator.php:149 
     39#: woocommerce-product-sku-generator.php:149 
     40msgid "Support" 
     41msgstr "" 
     42 
     43#: build/woocommerce-product-sku-generator.php:194 
     44#: woocommerce-product-sku-generator.php:194 
    1845#. translators: %1$s and %2$s are <strong> tags. %3$s and %4$s are <a> tags 
    1946msgid "" 
    2047"%1$sWooCommerce Product SKU Generator is inactive.%2$s This plugin requires " 
    21 "WooCommerce 2.2 or newer. Please %3$supdate WooCommerce to version 2.2 or " 
     48"WooCommerce 2.3 or newer. Please %3$supdate WooCommerce to version 2.3 or " 
    2249"newer%4$s" 
    2350msgstr "" 
    2451 
    25 #: build/woocommerce-product-sku-generator.php:141 
    26 #: woocommerce-product-sku-generator.php:137 
    27 msgid "Configure" 
    28 msgstr "" 
    29  
    30 #: build/woocommerce-product-sku-generator.php:142 
    31 #: woocommerce-product-sku-generator.php:138 
    32 msgid "Support" 
    33 msgstr "" 
    34  
    35 #: build/woocommerce-product-sku-generator.php:283 
    36 #: woocommerce-product-sku-generator.php:279 
     52#: build/woocommerce-product-sku-generator.php:339 
     53#: woocommerce-product-sku-generator.php:339 
    3754msgid "SKU" 
    3855msgstr "" 
    3956 
    40 #: build/woocommerce-product-sku-generator.php:355 
    41 #: woocommerce-product-sku-generator.php:329 
     57#: build/woocommerce-product-sku-generator.php:387 
     58#: woocommerce-product-sku-generator.php:387 
    4259msgid "Product SKUs" 
    4360msgstr "" 
    4461 
    45 #: build/woocommerce-product-sku-generator.php:361 
    46 #: woocommerce-product-sku-generator.php:335 
     62#: build/woocommerce-product-sku-generator.php:393 
     63#: woocommerce-product-sku-generator.php:393 
    4764msgid "Generate Simple / Parent SKUs:" 
    4865msgstr "" 
    4966 
    50 #: build/woocommerce-product-sku-generator.php:362 
    51 #: woocommerce-product-sku-generator.php:336 
     67#: build/woocommerce-product-sku-generator.php:394 
     68#: woocommerce-product-sku-generator.php:394 
    5269msgid "" 
    5370"Generating simple / parent SKUs disables the SKU field while editing " 
     
    5572msgstr "" 
    5673 
    57 #: build/woocommerce-product-sku-generator.php:366 
    58 #: build/woocommerce-product-sku-generator.php:382 
    59 #: woocommerce-product-sku-generator.php:340 
    60 #: woocommerce-product-sku-generator.php:356 
     74#: build/woocommerce-product-sku-generator.php:398 
     75#: build/woocommerce-product-sku-generator.php:414 
     76#: woocommerce-product-sku-generator.php:398 
     77#: woocommerce-product-sku-generator.php:414 
    6178msgid "Never (let me set them)" 
    6279msgstr "" 
    6380 
    64 #: build/woocommerce-product-sku-generator.php:367 
    65 #: woocommerce-product-sku-generator.php:341 
     81#: build/woocommerce-product-sku-generator.php:399 
     82#: woocommerce-product-sku-generator.php:399 
    6683msgid "Using the product slug (name)" 
    6784msgstr "" 
    6885 
    69 #: build/woocommerce-product-sku-generator.php:368 
    70 #: woocommerce-product-sku-generator.php:342 
     86#: build/woocommerce-product-sku-generator.php:400 
     87#: woocommerce-product-sku-generator.php:400 
    7188msgid "Using the product ID" 
    7289msgstr "" 
    7390 
    74 #: build/woocommerce-product-sku-generator.php:373 
    75 #: woocommerce-product-sku-generator.php:347 
     91#: build/woocommerce-product-sku-generator.php:405 
     92#: woocommerce-product-sku-generator.php:405 
    7693msgid "" 
    7794"Determine how SKUs for simple, external, or parent products will be " 
     
    7996msgstr "" 
    8097 
    81 #: build/woocommerce-product-sku-generator.php:377 
    82 #: woocommerce-product-sku-generator.php:351 
     98#: build/woocommerce-product-sku-generator.php:409 
     99#: woocommerce-product-sku-generator.php:409 
    83100msgid "Generate Variation SKUs:" 
    84101msgstr "" 
    85102 
    86 #: build/woocommerce-product-sku-generator.php:378 
    87 #: woocommerce-product-sku-generator.php:352 
     103#: build/woocommerce-product-sku-generator.php:410 
     104#: woocommerce-product-sku-generator.php:410 
    88105msgid "Determine how SKUs for product variations will be generated." 
    89106msgstr "" 
    90107 
    91 #: build/woocommerce-product-sku-generator.php:383 
    92 #: woocommerce-product-sku-generator.php:357 
     108#: build/woocommerce-product-sku-generator.php:415 
     109#: woocommerce-product-sku-generator.php:415 
    93110msgid "Using the attribute slugs (names)" 
    94111msgstr "" 
    95112 
    96 #: build/woocommerce-product-sku-generator.php:384 
    97 #: woocommerce-product-sku-generator.php:358 
     113#: build/woocommerce-product-sku-generator.php:416 
     114#: woocommerce-product-sku-generator.php:416 
    98115msgid "Using the variation ID" 
    99116msgstr "" 
    100117 
    101 #: build/woocommerce-product-sku-generator.php:393 
    102 #: woocommerce-product-sku-generator.php:367 
    103 msgid "Replace spaces in attributes" 
     118#: build/woocommerce-product-sku-generator.php:425 
     119#: woocommerce-product-sku-generator.php:425 
     120msgid "Replace spaces in attributes?" 
    104121msgstr "" 
    105122 
    106 #: build/woocommerce-product-sku-generator.php:395 
    107 #: woocommerce-product-sku-generator.php:369 
     123#: build/woocommerce-product-sku-generator.php:427 
     124#: woocommerce-product-sku-generator.php:427 
    108125#. translators: placeholders are <strong> tags 
    109126msgid "" 
    110 "Replace spaces in attribute names with underscores.%1$sWill update existing " 
    111 "variation SKUs when product is saved%2$s." 
     127"%1$sWill update existing variation SKUs when product is saved if they " 
     128"contain spaces%2$s." 
     129msgstr "" 
     130 
     131#: build/woocommerce-product-sku-generator.php:431 
     132#: woocommerce-product-sku-generator.php:431 
     133msgid "Do not replace spaces in attribute names." 
     134msgstr "" 
     135 
     136#: build/woocommerce-product-sku-generator.php:432 
     137#: woocommerce-product-sku-generator.php:432 
     138msgid "Replace spaces with underscores" 
     139msgstr "" 
     140 
     141#: build/woocommerce-product-sku-generator.php:433 
     142#: woocommerce-product-sku-generator.php:433 
     143msgid "Replace spaces with dashes / hyphens" 
     144msgstr "" 
     145 
     146#: build/woocommerce-product-sku-generator.php:438 
     147#: woocommerce-product-sku-generator.php:438 
     148msgid "Replace spaces in attribute names when used in a SKU." 
    112149msgstr "" 
    113150 
  • woocommerce-product-sku-generator/trunk/readme.txt

    r1330720 r1427953  
    33Tags: woocommerce, sku, product sku 
    44Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=paypal@skyverge.com&item_name=Donation+for+WooCommerce+SKU+Generator 
    5 Requires at least: 3.8 
    6 Tested up to: 4.4.1 
    7 Requires WooCommerce at least: 2.2 
    8 Tested WooCommerce up to: 2.5 
    9 Stable Tag: 2.1.0 
     5Requires at least: 4.0 
     6Tested up to: 4.5.2 
     7Requires WooCommerce at least: 2.3 
     8Tested WooCommerce up to: 2.6 
     9Stable Tag: 2.2.0 
    1010License: GPLv3 
    1111License URI: http://www.gnu.org/licenses/gpl-3.0.html 
     
    1515== Description == 
    1616 
    17 > **Requires: WooCommerce 2.2** or newer 
     17> **Requires: WooCommerce 2.3** or newer 
    1818 
    1919Automatically generate a SKU for parent / simple products, variations, or both when the product is published or updated. 
     
    6767> **NOTE that** any time a product is updated, its SKU will be generated, so this may override old SKUs if you update products. This plugin is meant for complete SKU automation, or you can selectively enable / disable it as needed. 
    6868 
    69 1. Be sure you're running WooCommerce 2.2+ in your shop. 
    70 2. You can: (1) upload the entire `woocommerce-product-sku-generator` folder to the `/wp-content/plugins/` directory, (2) upload the .zip file with the plugin under **Plugins &gt; Add New &gt; Upload**, or (3) Search for "WooCommerce Product SKU Generator" under Plugins &gt; Add New 
    71 3. Activate the plugin through the **Plugins** menu in WordPress 
    72 4. Click the "Configure" plugin link or go to **WooCommerce &gt; Settings &gt; Products** and scroll down to the "Product SKUs". Select which SKUs you'd like to generate and what should be used to generate them. 
    73 5. If you generate variation SKUs with slugs, determine if spaces in attribute names should be replaced with underscores instead. 
    74 6. View [documentation on the product page](http://www.skyverge.com/product/woocommerce-product-sku-generator/) for more help if needed. 
     69 1. Be sure you're running WooCommerce 2.3+ in your shop. 
     70 
     71 2. You can: 
     72 
     73    - upload the entire `woocommerce-product-sku-generator` folder to the `/wp-content/plugins/` directory, 
     74    - upload the .zip file with the plugin under **Plugins &gt; Add New &gt; Upload**, or 
     75    - Search for "WooCommerce Product SKU Generator" under Plugins &gt; Add New 
     76 
     77 3. Activate the plugin through the **Plugins** menu in WordPress 
     78 
     79 4. Click the "Configure" plugin link or go to **WooCommerce &gt; Settings &gt; Products** and scroll down to the "Product SKUs". Select which SKUs you'd like to generate and what should be used to generate them. 
     80 
     81 5. If you generate variation SKUs with slugs, determine if spaces in attribute names should be replaced with underscores instead. 
     82 
     83 6. View [documentation on the product page](http://www.skyverge.com/product/woocommerce-product-sku-generator/) for more help if needed. 
    7584 
    7685== Frequently Asked Questions == 
     
    9099Variation SKUs can be set manually if you're _not_ generating them. **They will be overridden** if your settings are set auto-generate them, even if you try to change them manually. Please check your settings here. 
    91100 
    92 If you'd like to change an SKU for a product, disable the plugin, change the SKU, and update the product. You can re-enable the plugin as needed. 
     101If you'd like to change a SKU for a product, disable the plugin, change the SKU, and update the product. You can re-enable the plugin as needed. 
     102 
     103= I'm using IDs for SKUs. Will they be sequential? = 
     104 
     105Roughly, yes. Actually, no. The SKUs will increase as you add more products / variations, but these use the post ID from WordPress (similar to your orders). Each SKU will be higher than the last, but they won't be exactly in order, as other posts (like blog posts, orders or products), also use the same ID counter. Your SKUs will increase, but skip numbers. 
    93106 
    94107= Can I use something other than the product slug to generate the SKUs? = 
     
    96109Yep! Version 2.0 added the ability to use product slugs or IDs. 
    97110 
    98 For more advanced uses, you can use the `wc_sku_generator_sku` filter (v1.2.2+), which passes the parent SKU as the value and the product as a variable, to change what's used as the parent SKU. You can change the variation SKU using the `wc_sku_generator_variation_sku` filter (v2.0.0+). 
     111For more advanced uses, you can use the `wc_sku_generator_sku` filter, which passes the parent SKU as the value and the product as a variable, to change what's used as the parent SKU. You can change the variation SKU using the `wc_sku_generator_variation_sku` filter. 
    99112 
    100113You **must** use a unique value for SKUs (WooCommerce checks this). For example, you could generate a unique string or number in a custom snippet to use for the SKU with the help of a developer. 
    101  
    102 = I'm using IDs for SKUs. Will they be sequential? = 
    103  
    104 Roughly, yes. Actually, no. The SKUs will increase as you add more products / variations, but these use the post ID from WordPress (similar to your orders). Each SKU will be higher than the last, but they won't be exactly in order, as other posts (like blog posts, orders or products), also use the same ID counter. Your SKUs will increase, but skip numbers. 
    105114 
    106115= Sometimes attributes for my variation SKUs aren't in the same order. Can I fix this? = 
     
    130139By default, if you have an attribute name with a space (such as "Burnt Marshmallow" for color), the SKU will use this exact formatting. A SKU for this variation would look like: `parentSKU-Burnt Marshmallow` 
    131140 
    132 If you enable the setting to replace spaces, this will instead look like: `parentSKU-Burnt_Marshmallow` -- this is helpful if your external fulfillment service does not allow spaces in SKUs. 
     141If you enable the setting to replace spaces, this will instead look like: `parentSKU-Burnt_Marshmallow` or `parentSKU-Burnt-Marshmallow` -- depending on which setting you've chose. This is helpful if your external fulfillment service does not allow spaces in SKUs. 
    133142 
    134143= Attribute Sorting = 
     
    147156 
    148157== Changelog == 
     158 
     159= 2016.05.31 - version 2.2.0 = 
     160 * Feature: attribute names can now replace spaces with hyphens in addition to underscores 
     161 * Misc: added support for WooCommerce 2.6 
     162 * Misc: removed support for WooCommerce 2.2 
    149163 
    150164= 2016.01.18 - version 2.1.0 = 
  • woocommerce-product-sku-generator/trunk/woocommerce-product-sku-generator.php

    r1330720 r1427953  
    66 * Author: SkyVerge 
    77 * Author URI: http://www.skyverge.com/ 
    8  * Version: 2.1.0 
     8 * Version: 2.2.0 
    99 * Text Domain: woocommerce-product-sku-generator 
    1010 * Domain Path: /i18n/languages/ 
     
    2424 
    2525 
    26 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly 
     26defined( 'ABSPATH' ) or exit; 
    2727 
    2828 
    2929// Check if WooCommerce is active 
    30 if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) 
     30if ( ! WC_SKU_Generator::is_woocommerce_active() ) { 
    3131    return; 
     32} 
    3233 
    3334 
    3435// WC version check 
    35 if ( version_compare( get_option( 'woocommerce_db_version' ), '2.2.0', '<' ) ) { 
    36  
    37     function wc_sku_generator_outdated_version_notice() { 
     36if ( version_compare( get_option( 'woocommerce_db_version' ), '2.3.0', '<' ) ) { 
     37    add_action( 'admin_notices', WC_SKU_Generator::render_outdated_wc_version_notice() ); 
     38    return; 
     39} 
     40 
     41 
     42// Make sure we're loaded after WC and fire it up! 
     43function init_wc_sku_generator() { 
     44    wc_sku_generator(); 
     45} 
     46add_action( 'plugins_loaded', 'init_wc_sku_generator' ); 
     47 
     48 
     49/** 
     50 * Plugin Description 
     51 * 
     52 * Generate a SKU for products that is equal to the product slug or product ID. 
     53 * Simple / parent products can have a SKU equal to the slug or ID. 
     54 * Variable products can have a SKU that combines the parent SKU + variation ID or attributes 
     55 */ 
     56 
     57class WC_SKU_Generator { 
     58 
     59 
     60    const VERSION = '2.2.0'; 
     61 
     62 
     63    /** @var WC_SKU_Generator single instance of this plugin */ 
     64    protected static $instance; 
     65 
     66 
     67    public function __construct() { 
     68 
     69        // load translations 
     70        add_action( 'init', array( $this, 'load_translation' ) ); 
     71 
     72        if ( is_admin() && ! is_ajax() ) { 
     73 
     74            // add settings 
     75            add_filter( 'woocommerce_products_general_settings', array( $this, 'add_settings' ) ); 
     76            add_filter( 'woocommerce_product_settings', array( $this, 'add_settings' ) ); 
     77            add_action( 'admin_print_scripts', array( $this, 'admin_js' ) ); 
     78 
     79            // add plugin links 
     80            add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_plugin_links' ) ); 
     81 
     82            // save the generated SKUs during product edit / bulk edit 
     83            add_action( 'woocommerce_product_bulk_edit_save', array( $this, 'maybe_save_sku' ) ); 
     84            add_action( 'woocommerce_process_product_meta', array( $this, 'maybe_save_sku' ), 100, 2 ); 
     85 
     86            // disable SKU fields when being generated by us 
     87            add_action( 'init', array( $this, 'maybe_disable_skus' ) ); 
     88 
     89            // run every time 
     90            $this->install(); 
     91        } 
     92    } 
     93 
     94 
     95    /** Helper methods ***************************************/ 
     96 
     97 
     98    /** 
     99     * Main Sku Generator Instance, ensures only one instance is/can be loaded 
     100     * 
     101     * @since 2.0.0 
     102     * @see wc_sku_generator() 
     103     * @return WC_SKU_Generator 
     104     */ 
     105    public static function instance() { 
     106        if ( is_null( self::$instance ) ) { 
     107            self::$instance = new self(); 
     108        } 
     109        return self::$instance; 
     110    } 
     111 
     112 
     113    /** 
     114     * Cloning instances is forbidden due to singleton pattern. 
     115     * 
     116     * @since 2.2.0 
     117     */ 
     118    public function __clone() { 
     119 
     120        /* translators: Placeholders: %s - plugin name */ 
     121        _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'You cannot clone instances of %s.', 'woocommerce-product-sku-generator' ), 'WooCommerce Product SKU Generator' ), '2.2.0' ); 
     122    } 
     123 
     124 
     125    /** 
     126     * Unserializing instances is forbidden due to singleton pattern. 
     127     * 
     128     * @since 2.2.0 
     129     */ 
     130    public function __wakeup() { 
     131 
     132        /* translators: Placeholders: %s - plugin name */ 
     133        _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'You cannot unserialize instances of %s.', 'woocommerce-product-sku-generator' ), 'WooCommerce Product SKU Generator' ), '2.2.0' ); 
     134    } 
     135 
     136 
     137    /** 
     138     * Adds plugin page links 
     139     * 
     140     * @since 2.0.0 
     141     * @param array $links all plugin links 
     142     * @return array $links all plugin links + our custom links (i.e., "Settings") 
     143     */ 
     144    public function add_plugin_links( $links ) { 
     145 
     146        $plugin_links = array( 
     147            '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=products' ) . '">' . __( 'Configure', 'woocommerce-product-sku-generator' ) . '</a>', 
     148            '<a href="https://wordpress.org/plugins/woocommerce-product-sku-generator/faq/">' . __( 'FAQ', 'woocommerce-product-sku-generator' ) . '</a>', 
     149            '<a href="https://wordpress.org/support/plugin/woocommerce-product-sku-generator">' . __( 'Support', 'woocommerce-product-sku-generator' ) . '</a>', 
     150        ); 
     151 
     152        return array_merge( $plugin_links, $links ); 
     153    } 
     154 
     155 
     156    /** 
     157     * Load Translations 
     158     * 
     159     * @since 1.2.1 
     160     */ 
     161    public function load_translation() { 
     162        // localization 
     163        load_plugin_textdomain( 'woocommerce-product-sku-generator', false, dirname( plugin_basename( __FILE__ ) ) . '/i18n/languages' ); 
     164    } 
     165 
     166 
     167    /** 
     168     * Checks if WooCommerce is active 
     169     * 
     170     * @since 2.2.0 
     171     * @return bool true if WooCommerce is active, false otherwise 
     172     */ 
     173    public static function is_woocommerce_active() { 
     174 
     175        $active_plugins = (array) get_option( 'active_plugins', array() ); 
     176 
     177        if ( is_multisite() ) { 
     178            $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); 
     179        } 
     180 
     181        return in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); 
     182    } 
     183 
     184 
     185    /** 
     186     * Renders a notice when WooCommerce version is outdated 
     187     * 
     188     * @since 2.2.0 
     189     */ 
     190    public static function render_outdated_wc_version_notice() { 
    38191 
    39192        $message = sprintf( 
    40             /* translators: %1$s and %2$s are <strong> tags. %3$s and %4$s are <a> tags */ 
    41             esc_html__( '%1$sWooCommerce Product SKU Generator is inactive.%2$s This plugin requires WooCommerce 2.2 or newer. Please %3$supdate WooCommerce to version 2.2 or newer%4$s', 'woocommerce-product-sku-generator' ), 
     193        /* translators: %1$s and %2$s are <strong> tags. %3$s and %4$s are <a> tags */ 
     194            esc_html__( '%1$sWooCommerce Product SKU Generator is inactive.%2$s This plugin requires WooCommerce 2.3 or newer. Please %3$supdate WooCommerce to version 2.3 or newer%4$s', 'woocommerce-product-sku-generator' ), 
    42195            '<strong>', 
    43196            '</strong>', 
     
    46199        ); 
    47200 
    48         echo sprintf( '<div class="error"><p>%s</p></div>', $message ); 
    49     } 
    50  
    51     add_action( 'admin_notices', 'wc_sku_generator_outdated_version_notice' ); 
    52  
    53     return; 
    54 } 
    55  
    56  
    57 // Make sure we're loaded after WC 
    58 function init_wc_sku_generator() { 
    59     // Fire it up! 
    60     wc_sku_generator(); 
    61 } 
    62 add_action( 'plugins_loaded', 'init_wc_sku_generator' ); 
    63  
    64  
    65 /** 
    66  * Plugin Description 
    67  * 
    68  * Generate a SKU for products that is equal to the product slug or product ID. 
    69  * Simple / parent products will have one SKU equal to the slug or ID. 
    70  * Variable products 
    71  */ 
    72  
    73  
    74 class WC_SKU_Generator { 
    75  
    76  
    77     const VERSION = '2.1.0'; 
    78  
    79  
    80     /** @var WC_SKU_Generator single instance of this plugin */ 
    81     protected static $instance; 
    82  
    83  
    84     public function __construct() { 
    85  
    86         // load translations 
    87         add_action( 'init', array( $this, 'load_translation' ) ); 
    88  
    89         if ( is_admin() && ! is_ajax() ) { 
    90  
    91             // add settings 
    92             add_filter( 'woocommerce_products_general_settings', array( $this, 'add_settings' ) ); 
    93             add_filter( 'woocommerce_product_settings', array( $this, 'add_settings' ) ); 
    94             add_action( 'admin_print_scripts', array( $this, 'admin_js' ) ); 
    95  
    96             // add plugin links 
    97             add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_plugin_links' ) ); 
    98  
    99             // save the generated SKUs during product edit / bulk edit 
    100             add_action( 'woocommerce_product_bulk_edit_save', array( $this, 'maybe_save_sku' ) ); 
    101             add_action( 'woocommerce_process_product_meta', array( $this, 'maybe_save_sku' ), 100, 2 ); 
    102  
    103             // disable SKU fields when being generated by us 
    104             add_action( 'init', array( $this, 'maybe_disable_skus' ) ); 
    105  
    106             // run every time 
    107             $this->install(); 
    108         } 
    109     } 
    110  
    111  
    112     /** 
    113      * Main Sku Generator Instance, ensures only one instance is/can be loaded 
    114      * 
    115      * @since 2.0.0 
    116      * @see wc_sku_generator() 
    117      * @return WC_SKU_Generator 
    118      */ 
    119     public static function instance() { 
    120         if ( is_null( self::$instance ) ) { 
    121             self::$instance = new self(); 
    122         } 
    123         return self::$instance; 
    124     } 
    125  
    126  
    127     /** 
    128      * Adds plugin page links 
    129      * 
    130      * @since 2.0.0 
    131      * @param array $links all plugin links 
    132      * @return array $links all plugin links + our custom links (i.e., "Settings") 
    133      */ 
    134     public function add_plugin_links( $links ) { 
    135  
    136         $plugin_links = array( 
    137             '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=products' ) . '">' . __( 'Configure', 'woocommerce-product-sku-generator' ) . '</a>', 
    138             '<a href="https://wordpress.org/support/plugin/woocommerce-product-sku-generator">' . __( 'Support', 'woocommerce-product-sku-generator' ) . '</a>', 
    139         ); 
    140  
    141         return array_merge( $plugin_links, $links ); 
    142     } 
    143  
    144  
    145     /** 
    146      * Load Translations 
    147      * 
    148      * @since 1.2.1 
    149      */ 
    150     public function load_translation() { 
    151         // localization 
    152         load_plugin_textdomain( 'woocommerce-product-sku-generator', false, dirname( plugin_basename( __FILE__ ) ) . '/i18n/languages' ); 
    153     } 
     201        printf( '<div class="error"><p>%s</p></div>', $message ); 
     202    } 
     203 
     204 
     205    /** Plugin methods ***************************************/ 
    154206 
    155207 
     
    189241        if ( 'slugs' === get_option( 'wc_sku_generator_variation' ) ) { 
    190242 
    191             // replace spaces in attributes with underscores if set 
    192             if ( 'yes' === get_option( 'wc_sku_generator_attribute_spaces' ) ) { 
    193                 $variation['attributes'] = str_replace( ' ', '_', $variation['attributes'] ); 
     243            // replace spaces in attributes depending on settings 
     244            switch ( get_option( 'wc_sku_generator_attribute_spaces' ) ) { 
     245 
     246                case 'underscore': 
     247                    $variation['attributes'] = str_replace( ' ', '_', $variation['attributes'] ); 
     248                break; 
     249 
     250                case 'dash': 
     251                    $variation['attributes'] = str_replace( ' ', '-', $variation['attributes'] ); 
     252                break; 
     253                 
    194254            } 
    195255 
     
    301361        $updated_settings = array(); 
    302362 
    303         $setting_id = version_compare( WC_VERSION, '2.3', '>=' ) ? 'product_measurement_options' : 'product_data_options'; 
    304  
    305363        foreach ( $settings as $setting ) { 
    306364 
    307365            $updated_settings[] = $setting; 
    308366 
    309             if ( isset( $setting['id'] ) && $setting_id === $setting['id'] && 'sectionend' === $setting['type'] ) { 
     367            if ( isset( $setting['id'] ) && 'product_measurement_options' === $setting['id'] && 'sectionend' === $setting['type'] ) { 
    310368 
    311369                $updated_settings = array_merge( $updated_settings, $this->get_settings() ); 
     
    365423 
    366424            array( 
    367                 'title'   => __( 'Replace spaces in attributes', 'woocommerce-product-sku-generator' ), 
     425                'title'    => __( 'Replace spaces in attributes?', 'woocommerce-product-sku-generator' ), 
    368426                /* translators: placeholders are <strong> tags */ 
    369                 'desc'    => sprintf( __( 'Replace spaces in attribute names with underscores.%1$sWill update existing variation SKUs when product is saved%2$s.', 'woocommerce-product-sku-generator' ), '<br /><strong>', '</strong>' ), 
    370                 'id'      => 'wc_sku_generator_attribute_spaces', 
    371                 'type'    => 'checkbox', 
    372                 'default' => 'no', 
     427                'desc'     => sprintf( __( '%1$sWill update existing variation SKUs when product is saved if they contain spaces%2$s.', 'woocommerce-product-sku-generator' ), '<strong>', '</strong>' ), 
     428                'id'       => 'wc_sku_generator_attribute_spaces', 
     429                'type'     => 'select', 
     430                'options'  => array( 
     431                    'no'         => __( 'Do not replace spaces in attribute names.', 'woocommerce-product-sku-generator' ), 
     432                    'underscore' => __( 'Replace spaces with underscores', 'woocommerce-product-sku-generator' ), 
     433                    'dash'       => __( 'Replace spaces with dashes / hyphens', 'woocommerce-product-sku-generator' ), 
     434                ), 
     435                'default'  => 'no', 
     436                'class'    => 'wc-enhanced-select chosen_select', 
     437                'css'      => 'min-width:300px;', 
     438                'desc_tip' => __( 'Replace spaces in attribute names when used in a SKU.', 'woocommerce-product-sku-generator' ), 
    373439            ), 
    374440 
     
    414480 
    415481 
     482    /** Lifecycle methods ***************************************/ 
     483 
     484 
    416485    /** 
    417486     * Run every time.  Used since the activation hook is not executed when updating a plugin 
     
    475544            // Delete the old option now that we've upgraded 
    476545            delete_option( 'wc_sku_generator_select' ); 
     546        } 
     547 
     548        // Upgrade to version 2.2.0, this setting was only available in 2.1.0 
     549        if ( '2.1.0' === $installed_version ) { 
     550 
     551            if ( 'yes' === get_option( 'wc_sku_generator_attribute_spaces' ) ) { 
     552                update_option( 'wc_sku_generator_attribute_spaces', 'underscore' ); 
     553            } 
    477554        } 
    478555 
Note: See TracChangeset for help on using the changeset viewer.