Changeset 864479
- Timestamp:
- 02/25/2014 04:42:58 AM (12 years ago)
- Location:
- woocommerce-customizer/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (2 diffs)
-
woocommerce-customizer.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woocommerce-customizer/trunk/readme.txt
r855936 r864479 4 4 Tags: woocommerce 5 5 Requires at least: 3.5 6 Tested up to: 3.8 7 Stable tag: 1. 1.16 Tested up to: 3.8.1 7 Stable tag: 1.2 8 8 License: GPLv3 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 54 54 == Changelog == 55 55 56 = 1.2 = 57 * Fixed issues with add to cart button text customizations in WooCommerce 2.1 58 56 59 = 1.1.1 = 57 60 * WooCommerce 2.1 Compatibility -
woocommerce-customizer/trunk/woocommerce-customizer.php
r855936 r864479 6 6 * Author: SkyVerge 7 7 * Author URI: http://www.skyverge.com 8 * Version: 1. 1.18 * Version: 1.2 9 9 * Text Domain: wc-customizer 10 10 * Domain Path: /languages/ … … 28 28 return; 29 29 30 // required compatibility class 31 require_once( 'includes/class-wc-customizer-compatibility.php' ); 30 32 31 33 /** … … 71 73 72 74 /** plugin version number */ 73 const VERSION = '1. 1.1';75 const VERSION = '1.2'; 74 76 75 77 /** var array the active filters */ … … 100 102 } 101 103 104 add_action( 'woocommerce_init', array( $this, 'load_customizations' ) ); 105 } 106 107 108 /** 109 * Load customizations after WC is loaded so the version can be checked 110 * 111 * @since 1.2 112 */ 113 public function load_customizations() { 114 102 115 // load filter names and values 103 116 $this->filters = get_option( 'wc_customizer_active_customizations' ); … … 107 120 108 121 foreach ( $this->filters as $filter_name => $filter_value ) { 109 add_filter( $filter_name, array( $this, 'customize' ) ); 110 } 111 112 // for use some day, in a galaxy far, far away, when PHP 5.3+ has greater WP adoption 122 123 // WC 2.1 changed the add to cart text filter signatures so conditionally add the new filters 124 if ( false !== strpos( $filter_name, 'add_to_cart_text' ) && WC_Customizer_Compatibility::is_wc_version_gte_2_1() ) { 125 126 if ( $filter_name == 'single_add_to_cart_text' ) { 127 128 add_filter( 'woocommerce_product_single_add_to_cart_text', array( $this, 'customize_single_add_to_cart_text' ) ); 129 130 } else { 131 132 add_filter( 'woocommerce_product_add_to_cart_text', array( $this, 'customize_add_to_cart_text' ), 10, 2 ); 133 } 134 135 } else { 136 137 add_filter( $filter_name, array( $this, 'customize' ) ); 138 } 139 } 140 141 // for use some day, in a galaxy far, far away, when WP has greater 5.3 adoption 113 142 // add_filter( $filter_name, function() use ( $filter_value ) { return $filter_value; } ); 114 143 } … … 154 183 $current_filter = current_filter(); 155 184 156 if ( isset( $this->filters[ $current_filter ] ) ) 185 if ( isset( $this->filters[ $current_filter ] ) ) { 157 186 return $this->filters[ $current_filter ]; 187 } 158 188 159 189 // no need to return a value passed in, because if a filter is set, it's designed to only return that value 190 } 191 192 193 /** 194 * Apply the single add to cart button text customization in WC 2.1+ 195 * 196 * The filter signature changed from `single_add_to_cart_text` to `woocommerce_product_single_add_to_cart_text` 197 * 198 * @since 1.2 199 */ 200 public function customize_single_add_to_cart_text() { 201 202 return $this->filters['single_add_to_cart_text']; 203 } 204 205 206 /** 207 * Apply the shop loop add to cart button text customization in WC 2.1+ 208 * 209 * The filter signature changed from `add_to_cart_text|{type}_add_to_cart_text` to `woocommerce_product_add_to_cart_text` 210 * 211 * This is sort of a hack but prevents a major refactoring and maintains backwards compatibility until WC 2.1+ can 212 * be required 213 * 214 * @since 1.2 215 * @param string $text add to cart text 216 * @param WC_Product $product product object 217 * @return string modified add to cart text 218 */ 219 public function customize_add_to_cart_text( $text, $product ) { 220 221 // out of stock add to cart text 222 if ( isset( $this->filters['out_of_stock_add_to_cart_text'] ) && ! $product->is_in_stock() ) { 223 224 return $this->filters['out_of_stock_add_to_cart_text']; 225 } 226 227 if ( isset( $this->filters['add_to_cart_text'] ) && $product->is_type( 'simple' ) ) { 228 229 // simple add to cart text 230 return $this->filters['add_to_cart_text']; 231 232 } elseif ( isset( $this->filters['variable_add_to_cart_text'] ) && $product->is_type( 'variable') ) { 233 234 // variable add to cart text 235 return $this->filters['variable_add_to_cart_text']; 236 237 } elseif ( isset( $this->filters['grouped_add_to_cart_text'] ) && $product->is_type( 'grouped' ) ) { 238 239 // grouped add to cart text 240 return $this->filters['grouped_add_to_cart_text']; 241 242 } elseif( isset( $this->filters['external_add_to_cart_text'] ) && $product->is_type( 'external' ) ) { 243 244 // external add to cart text 245 return $this->filters['external_add_to_cart_text']; 246 } 247 248 return $text; 160 249 } 161 250 … … 168 257 * is active. 169 258 * 170 * @since 0.1259 * @since 1.0 171 260 * @param array $actions associative array of action names to anchor tags 172 261 * @return array associative array of plugin action links … … 205 294 206 295 // upgrade if installed version lower than plugin version 207 if ( -1 === version_compare( $installed_version, self::VERSION ) ) 296 if ( -1 === version_compare( $installed_version, self::VERSION ) ) { 208 297 $this->upgrade( $installed_version ); 298 } 209 299 } 210 300
Note: See TracChangeset
for help on using the changeset viewer.