WooCommerce Customizer - Version 1.1

Version Description

  • Refactor to support the upcoming WooCommerce 2.1 beta
  • Localization - Text domain changed from wc_customizer to wc-customizer and loaded properly on init hook
Download this release

Release Info

Developer SkyVerge
Plugin Icon WooCommerce Customizer
Version 1.1
Comparing to
See all releases

Code changes from version 1.0.1 to 1.1

admin/class-wc-customizer-admin.php DELETED
@@ -1,513 +0,0 @@
1
- <?php
2
- /**
3
- * WooCommerce Customizer Admin Class
4
- *
5
- * Loads / Saves admin settings page
6
- *
7
- *
8
- * @package WooCommerce Customizer
9
- * @subpackage WC_Customizer_Admin
10
- * @category Class
11
- * @author Max Rice
12
- * @since 1.0
13
- */
14
-
15
- class WC_Customizer_Admin {
16
-
17
- /** @var array tab IDs / titles admin page */
18
- public static $tabs;
19
-
20
- /** @var string sub-menu page hook suffix */
21
- public static $page;
22
-
23
-
24
- /**
25
- * Init Admin class
26
- *
27
- * @access public
28
- * @since 1.0
29
- * @return void
30
- */
31
- public static function init() {
32
-
33
- self::$tabs = array( 'shop_loop' => __( 'Shop Loop', WC_Customizer::$text_domain ),
34
- 'product_page' => __( 'Product Page', WC_Customizer::$text_domain ),
35
- 'checkout' => __( 'Checkout', WC_Customizer::$text_domain ),
36
- 'misc' => __( 'Misc', WC_Customizer::$text_domain )
37
- );
38
-
39
- // Add settings page screen ID to list of pages for WC CSS/JS to load on
40
- add_filter( 'woocommerce_screen_ids', array( __CLASS__, 'load_woocommerce_styles_scripts' ) );
41
-
42
- // Add 'Customizer' link under WooCommerce menu
43
- add_action( 'admin_menu', array( __CLASS__, 'add_menu_link' ) );
44
-
45
- }
46
-
47
-
48
- /**
49
- * Add Customizer settings screen ID to the list of pages for WC to load CSS/JS on
50
- *
51
- * @since 1.0
52
- * @param array $screen_ids
53
- * @return array
54
- */
55
- public static function load_woocommerce_styles_scripts( $screen_ids ) {
56
-
57
- $screen_ids[] = 'woocommerce_page_woocommerce_customizer';
58
-
59
- return $screen_ids;
60
- }
61
-
62
-
63
- /**
64
- * Add 'Customizer' menu link under 'WooCommerce' top level menu
65
- *
66
- * @access public
67
- * @since 1.0
68
- * @return void
69
- */
70
- public static function add_menu_link() {
71
-
72
- self::$page = add_submenu_page( 'woocommerce',
73
- __( 'WooCommerce Customizer', WC_Customizer::$text_domain ),
74
- __( 'Customizer', WC_Customizer::$text_domain ),
75
- 'manage_woocommerce',
76
- 'woocommerce_customizer',
77
- __CLASS__ . '::display_settings_page'
78
- );
79
-
80
- }
81
-
82
- /**
83
- * Show Customizer settings page content for all tabs.
84
- *
85
- * @access public
86
- * @since 1.0
87
- * @return void
88
- */
89
- public static function display_settings_page() {
90
-
91
- if ( false === ( $current_tab = self::get_current_tab() ) )
92
- return;
93
- ?>
94
- <div class="wrap woocommerce">
95
- <form method="post" id="mainform" action="" enctype="multipart/form-data">
96
- <div class="icon32 icon32-woocommerce-settings" id="icon-woocommerce"><br /></div>
97
- <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
98
- <?php
99
-
100
- foreach ( self::$tabs as $tab_id => $tab_title ) :
101
-
102
- $class = ( $tab_id == $current_tab ) ? 'nav-tab nav-tab-active' : 'nav-tab';
103
- $url = add_query_arg( 'tab', $tab_id, admin_url( 'admin.php?page=woocommerce_customizer&tab=' ) );
104
-
105
- printf( '<a href="%s" class="%s">%s</a>', $url, $class, $tab_title );
106
-
107
- endforeach;
108
-
109
- ?> </h2> <?php
110
-
111
- wp_nonce_field( 'wc-customizer-settings', '_wpnonce', true, true );
112
-
113
- //check post & verify nonce
114
- if ( ! empty( $_POST ) ) {
115
-
116
- if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'wc-customizer-settings' ) )
117
- wp_die( __( 'Action failed. Please refresh the page and retry.', WC_Customizer::$text_domain ) );
118
-
119
- self::save_fields( self::load_fields(), $current_tab );
120
-
121
- // Redirect to settings
122
- wp_redirect( add_query_arg( 'saved', 'true' ) );
123
- exit;
124
-
125
- }
126
-
127
- // show error / success message
128
- if ( ! empty( $_GET['saved'] ) )
129
- echo '<div id="message" class="updated fade"><p><strong>' . __( 'Your customizations have been saved.', WC_Customizer::$text_domain ) . '</strong></p></div>';
130
-
131
-
132
- self::output_fields( self::load_fields(), $current_tab );
133
-
134
- ?>
135
- <p class="submit">
136
- <input name="save" class="button-primary" type="submit" value="<?php _e( 'Save Customizations', WC_Customizer::$text_domain ); ?>" />
137
- </p>
138
- </form>
139
- </div>
140
- <?php
141
- }
142
-
143
- /**
144
- * Output fields to page
145
- *
146
- * @access public
147
- * @since 1.0
148
- * @param array $fields
149
- * @param string $tab current tab slug
150
- * @return void
151
- */
152
- public static function output_fields( $fields, $tab ) {
153
- global $woocommerce;
154
-
155
- // only use fields for current tab
156
- $fields = $fields[$tab];
157
-
158
- $customizations = maybe_unserialize( get_option( WC_Customizer::$option_name ) );
159
-
160
- foreach ( $fields as $field ) :
161
-
162
- if ( ! isset( $field['type'] ) ) continue;
163
- if ( ! isset( $field['filter_id'] ) ) $field['filter_id'] = '';
164
- if ( ! isset( $field['name'] ) ) $field['name'] = '';
165
- if ( ! isset( $field['class'] ) ) $field['class'] = '';
166
- if ( ! isset( $field['css'] ) ) $field['css'] = '';
167
- if ( ! isset( $field['std'] ) ) $field['std'] = '';
168
- if ( ! isset( $field['desc'] ) ) $field['desc'] = '';
169
- if ( ! isset( $field['desc_tip'] ) ) $field['desc_tip'] = false;
170
-
171
- if ( $field['desc_tip'] === true ) {
172
- $description = '<img height="16" width="16" class="help_tip" data-tip="' . esc_attr( $field['desc'] ) . '" src="' . $woocommerce->plugin_url() . '/assets/images/help.png" />';
173
- } elseif ( $field['desc_tip'] ) {
174
- $description = '<img height="16" width="16" class="help_tip" data-tip="' . esc_attr( $field['desc_tip'] ) . '" src="' . $woocommerce->plugin_url() . '/assets/images/help.png" />';
175
- } else {
176
- $description = '<span class="description">' . $field['desc'] . '</span>';
177
- }
178
-
179
- switch ( $field['type'] ) :
180
-
181
- case 'title':
182
- if ( isset( $field['name'] ) && $field['name'] ) echo '<h3>' . $field['name'] . '</h3>';
183
- if ( isset( $field['desc'] ) && $field['desc'] ) echo wpautop( wptexturize( $field['desc'] ) );
184
- echo '<table class="form-table">' . "\n\n";
185
- break;
186
-
187
- case 'sectionend':
188
- echo '</table>';
189
- break;
190
-
191
- case 'text':
192
- ?>
193
- <tr valign="top">
194
- <th scope="row" class="titledesc">
195
- <label for="<?php echo esc_attr( $field['filter_id'] ); ?>"><?php echo $field['name']; ?></label>
196
- </th>
197
- <td class="forminp">
198
- <input name="<?php echo esc_attr( $field['filter_id'] ); ?>" id="<?php echo esc_attr( $field['filter_id'] ); ?>" type="<?php echo esc_attr( $field['type'] ); ?>" style="<?php echo esc_attr( $field['css'] ); ?>" value="<?php if ( isset( $customizations[$field['filter_id']] ) && ! empty( $customizations[$field['filter_id']] ) ) {
199
- echo esc_attr( stripslashes( $customizations[$field['filter_id']] ) );
200
- } else {
201
- echo esc_attr( $field['std'] );
202
- } ?>" /> <?php echo $description; ?></td>
203
- </tr><?php
204
- break;
205
-
206
- default:
207
- break;
208
-
209
- endswitch;
210
-
211
- endforeach;
212
- }
213
-
214
- /**
215
- * Save admin fields into serialized option
216
- *
217
- * @access public
218
- * @since 1.0
219
- * @param array $fields
220
- * @param string $tab current tab slug
221
- * @return bool
222
- */
223
- public static function save_fields( $fields, $tab ) {
224
-
225
- // only use fields for current tab
226
- $fields = $fields[$tab];
227
-
228
- $customizations = maybe_unserialize( get_option( WC_Customizer::$option_name ) );
229
-
230
- foreach ( $fields as $field ) :
231
-
232
- if ( ! isset( $field['filter_id'] ) )
233
- continue;
234
-
235
- if ( isset( $field['filter_id'] ) && ! empty( $_POST[$field['filter_id']] ) ) {
236
-
237
- $customizations[$field['filter_id']] = woocommerce_clean( $_POST[$field['filter_id']] );
238
-
239
- } elseif ( isset( $field['filter_id'] ) ) {
240
-
241
- unset( $customizations[$field['filter_id']] );
242
-
243
- }
244
-
245
- endforeach;
246
-
247
- update_option( WC_Customizer::$option_name, $customizations );
248
-
249
- return true;
250
- }
251
-
252
- /**
253
- * Return admin fields in proper format for outputting / saving
254
- *
255
- * @access private
256
- * @since 1.0
257
- * @return array
258
- */
259
- private static function load_fields() {
260
-
261
- return array(
262
-
263
- 'shop_loop' =>
264
-
265
- array(
266
-
267
- array(
268
- 'name' => __( 'Add to Cart Button Text', WC_Customizer::$text_domain ),
269
- 'type' => 'title'
270
- ),
271
-
272
- array(
273
- 'filter_id' => 'add_to_cart_text',
274
- 'name' => __( 'Simple Product', WC_Customizer::$text_domain ),
275
- 'desc_tip' => __( 'Changes the add to cart button text for simple products on all loop pages', WC_Customizer::$text_domain ),
276
- 'type' => 'text'
277
- ),
278
-
279
- array(
280
- 'filter_id' => 'variable_add_to_cart_text',
281
- 'name' => __( 'Variable Product', WC_Customizer::$text_domain ),
282
- 'desc_tip' => __( 'Changes the add to cart button text for variable products on all loop pages', WC_Customizer::$text_domain ),
283
- 'type' => 'text'
284
- ),
285
-
286
- array(
287
- 'filter_id' => 'grouped_add_to_cart_text',
288
- 'name' => __( 'Grouped Product', WC_Customizer::$text_domain ),
289
- 'desc_tip' => __( 'Changes the add to cart button text for grouped products on all loop pages', WC_Customizer::$text_domain ),
290
- 'type' => 'text'
291
- ),
292
-
293
- array(
294
- 'filter_id' => 'external_add_to_cart_text',
295
- 'name' => __( 'External Product', WC_Customizer::$text_domain ),
296
- 'desc_tip' => __( 'Changes the add to cart button text for external products on all loop pages', WC_Customizer::$text_domain ),
297
- 'type' => 'text'
298
- ),
299
-
300
- array(
301
- 'filter_id' => 'out_of_stock_add_to_cart_text',
302
- 'name' => __( 'Out of Stock Product', WC_Customizer::$text_domain ),
303
- 'desc_tip' => __( 'Changes the add to cart button text for out of stock products on all loop pages', WC_Customizer::$text_domain ),
304
- 'type' => 'text'
305
- ),
306
-
307
- array( 'type' => 'sectionend' ),
308
-
309
- array(
310
- 'name' => __( 'Layout', WC_Customizer::$text_domain ),
311
- 'type' => 'title'
312
- ),
313
-
314
- array(
315
- 'filter_id' => 'loop_shop_per_page',
316
- 'name' => __( 'Products displayed per page', WC_Customizer::$text_domain ),
317
- 'desc_tip' => __( 'Changes the number of products displayed per page', WC_Customizer::$text_domain ),
318
- 'type' => 'text'
319
- ),
320
-
321
- array(
322
- 'filter_id' => 'loop_shop_columns',
323
- 'name' => __( 'Product columns displayed per page', WC_Customizer::$text_domain ),
324
- 'desc_tip' => __( 'Changes the number of columns displayed per page', WC_Customizer::$text_domain ),
325
- 'type' => 'text'
326
- ),
327
-
328
- array(
329
- 'filter_id' => 'woocommerce_product_thumbnails_columns',
330
- 'name' => __( 'Product thumbnail columns displayed', WC_Customizer::$text_domain ),
331
- 'desc_tip' => __( 'Changes the number of product thumbnail columns displayed', WC_Customizer::$text_domain ),
332
- 'type' => 'text'
333
- ),
334
-
335
- array( 'type' => 'sectionend' )
336
-
337
- ),
338
-
339
- 'product_page' =>
340
-
341
- array(
342
-
343
- array(
344
- 'name' => __( 'Tab Titles', WC_Customizer::$text_domain ),
345
- 'type' => 'title'
346
- ),
347
-
348
- array(
349
- 'filter_id' => 'woocommerce_product_description_tab_title',
350
- 'name' => __( 'Product Description', WC_Customizer::$text_domain ),
351
- 'desc_tip' => __( 'Changes the Production Description tab title', WC_Customizer::$text_domain ),
352
- 'type' => 'text'
353
- ),
354
-
355
- array(
356
- 'filter_id' => 'woocommerce_product_additional_information_tab_title',
357
- 'name' => __( 'Additional Information', WC_Customizer::$text_domain ),
358
- 'desc_tip' => __( 'Changes the Additional Information tab title', WC_Customizer::$text_domain ),
359
- 'type' => 'text'
360
- ),
361
-
362
- array( 'type' => 'sectionend' ),
363
-
364
- array(
365
- 'name' => __( 'Tab Content Headings', WC_Customizer::$text_domain ),
366
- 'type' => 'title'
367
- ),
368
-
369
- array(
370
- 'filter_id' => 'woocommerce_product_description_heading',
371
- 'name' => __( 'Product Description', WC_Customizer::$text_domain ),
372
- 'desc_tip' => __( 'Changes the Product Description tab heading', WC_Customizer::$text_domain ),
373
- 'type' => 'text'
374
- ),
375
-
376
- array(
377
- 'filter_id' => 'woocommerce_product_additional_information_heading',
378
- 'name' => __( 'Additional Information', WC_Customizer::$text_domain ),
379
- 'desc_tip' => __( 'Changes the Additional Information tab heading', WC_Customizer::$text_domain ),
380
- 'type' => 'text'
381
- ),
382
-
383
- array( 'type' => 'sectionend' ),
384
-
385
- array(
386
- 'name' => __( 'Add to Cart Button Text', WC_Customizer::$text_domain ),
387
- 'type' => 'title'
388
- ),
389
-
390
- array(
391
- 'filter_id' => 'single_add_to_cart_text',
392
- 'name' => __( 'All Product Types', WC_Customizer::$text_domain ),
393
- 'desc_tip' => __( 'Changes the Add to Cart button text on the single product page for all product type', WC_Customizer::$text_domain ),
394
- 'type' => 'text'
395
- ),
396
-
397
- array( 'type' => 'sectionend' )
398
- ),
399
-
400
- 'checkout' =>
401
-
402
- array(
403
-
404
- array(
405
- 'name' => __( 'Messages', WC_Customizer::$text_domain ),
406
- 'type' => 'title'
407
- ),
408
-
409
- array(
410
- 'filter_id' => 'woocommerce_checkout_must_be_logged_in_message',
411
- 'name' => __( 'Must be logged in text', WC_Customizer::$text_domain ),
412
- 'desc_tip' => __( 'Changes the message displayed when a customer must be logged in to checkout', WC_Customizer::$text_domain ),
413
- 'type' => 'text'
414
- ),
415
-
416
- array(
417
- 'filter_id' => 'woocommerce_checkout_coupon_message',
418
- 'name' => __( 'Coupon text', WC_Customizer::$text_domain ),
419
- 'desc_tip' => __( 'Changes the message displayed if the coupon form is enabled on checkout', WC_Customizer::$text_domain ),
420
- 'type' => 'text'
421
- ),
422
-
423
- array(
424
- 'filter_id' => 'woocommerce_checkout_login_message',
425
- 'name' => __( 'Login text', WC_Customizer::$text_domain ),
426
- 'desc_tip' => __( 'Changes the message displayed if customers can login at checkout', WC_Customizer::$text_domain ),
427
- 'type' => 'text'
428
- ),
429
-
430
- array( 'type' => 'sectionend' ),
431
-
432
- array(
433
- 'name' => __( 'Button Text', WC_Customizer::$text_domain ),
434
- 'type' => 'title'
435
- ),
436
-
437
- array(
438
- 'filter_id' => 'woocommerce_order_button_text',
439
- 'name' => __( 'Submit Order button', WC_Customizer::$text_domain ),
440
- 'desc_tip' => __( 'Changes the Place Order button text on checkout', WC_Customizer::$text_domain ),
441
- 'type' => 'text'
442
- ),
443
-
444
- array( 'type' => 'sectionend' )
445
-
446
- ),
447
-
448
- 'misc' =>
449
-
450
- array(
451
-
452
- array(
453
- 'name' => __( 'Tax', WC_Customizer::$text_domain ),
454
- 'type' => 'title'
455
- ),
456
-
457
- array(
458
- 'filter_id' => 'woocommerce_countries_tax_or_vat',
459
- 'name' => __( 'Tax Label', WC_Customizer::$text_domain ),
460
- 'desc_tip' => __( 'Changes the Taxes label. Defaults to Tax for USA, VAT for European countries', WC_Customizer::$text_domain ),
461
- 'type' => 'text'
462
- ),
463
-
464
- array(
465
- 'filter_id' => 'woocommerce_countries_inc_tax_or_vat',
466
- 'name' => __( 'Including Tax Label', WC_Customizer::$text_domain ),
467
- 'desc_tip' => __( 'Changes the Including Taxes label. Defaults to Inc. tax for USA, Inc. VAT for European countries', WC_Customizer::$text_domain ),
468
- 'type' => 'text'
469
- ),
470
-
471
- array(
472
- 'filter_id' => 'woocommerce_countries_ex_tax_or_vat',
473
- 'name' => __( 'Excluding Tax Label', WC_Customizer::$text_domain ),
474
- 'desc_tip' => __( 'Changes the Excluding Taxes label. Defaults to Exc. tax for USA, Exc. VAT for European countries', WC_Customizer::$text_domain ),
475
- 'type' => 'text'
476
- ),
477
-
478
- array( 'type' => 'sectionend' )
479
-
480
- )
481
-
482
- );
483
- }
484
-
485
- /**
486
- * Get current tab slug
487
- *
488
- * @access private
489
- * @since 1.0
490
- * @return string slug of current tab
491
- */
492
- private static function get_current_tab() {
493
-
494
- if ( empty( $_GET['tab'] ) ) {
495
- // default to the first tab
496
- reset( self::$tabs );
497
- return key( self::$tabs );
498
-
499
- } elseif ( array_key_exists( $_GET['tab'], self::$tabs ) ) {
500
-
501
- return urldecode( $_GET['tab'] );
502
-
503
- } else {
504
-
505
- return false;
506
- }
507
- }
508
-
509
- } // end class
510
-
511
- WC_Customizer_Admin::init();
512
-
513
- // end file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-wc-customizer-admin.php ADDED
@@ -0,0 +1,462 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Customizer
4
+ *
5
+ * This source file is subject to the GNU General Public License v3.0
6
+ * that is bundled with this package in the file license.txt.
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://www.gnu.org/licenses/gpl-3.0.html
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@skyverge.com so we can send you a copy immediately.
12
+ *
13
+ * DISCLAIMER
14
+ *
15
+ * Do not edit or add to this file if you wish to upgrade WooCommerce Customizer to newer
16
+ * versions in the future. If you wish to customize WooCommerce Customizer for your
17
+ * needs please refer to http://www.skyverge.com/product/woocommerce-customizer/ for more information.
18
+ *
19
+ * @package WC-Customizer/Classes
20
+ * @author SkyVerge
21
+ * @copyright Copyright (c) 2013, SkyVerge, Inc.
22
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
23
+ */
24
+
25
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
26
+
27
+ /**
28
+ * Admin class
29
+ *
30
+ * Adds UX for adding/modifying customizations
31
+ *
32
+ * @since 1.0
33
+ */
34
+ class WC_Customizer_Admin {
35
+
36
+
37
+ /** @var array tab IDs / titles admin page */
38
+ public $tabs;
39
+
40
+ /** @var string sub-menu page hook suffix */
41
+ public $page;
42
+
43
+
44
+ /**
45
+ * Setup admin class
46
+ *
47
+ * @since 1.0
48
+ * @return \WC_Customizer_Admin
49
+ */
50
+ public function __construct() {
51
+
52
+ $this->tabs = array(
53
+ 'shop_loop' => __( 'Shop Loop', 'wc-customizer' ),
54
+ 'product_page' => __( 'Product Page', 'wc-customizer' ),
55
+ 'checkout' => __( 'Checkout', 'wc-customizer' ),
56
+ 'misc' => __( 'Misc', 'wc-customizer' )
57
+ );
58
+
59
+ // Add settings page screen ID to list of pages for WC CSS/JS to load on
60
+ add_filter( 'woocommerce_screen_ids', array( $this, 'load_woocommerce_styles_scripts' ) );
61
+
62
+ // Add 'Customizer' link under WooCommerce menu
63
+ add_action( 'admin_menu', array( $this, 'add_menu_link' ) );
64
+ }
65
+
66
+
67
+ /**
68
+ * Add Customizer settings screen ID to the list of pages for WC to load CSS/JS on
69
+ *
70
+ * @since 1.0
71
+ * @param array $screen_ids
72
+ * @return array
73
+ */
74
+ public function load_woocommerce_styles_scripts( $screen_ids ) {
75
+
76
+ $screen_ids[] = 'woocommerce_page_wc_customizer';
77
+
78
+ return $screen_ids;
79
+ }
80
+
81
+
82
+ /**
83
+ * Add 'Customizer' menu link under 'WooCommerce' top level menu
84
+ *
85
+ * @since 1.0
86
+ */
87
+ public function add_menu_link() {
88
+
89
+ $this->page = add_submenu_page(
90
+ 'woocommerce',
91
+ __( 'WooCommerce Customizer', 'wc-customizer' ),
92
+ __( 'Customizer', 'wc-customizer' ),
93
+ 'manage_woocommerce',
94
+ 'wc_customizer',
95
+ array( $this, 'render_settings_page' )
96
+ );
97
+ }
98
+
99
+
100
+ /**
101
+ * Show Customizer settings page content for all tabs.
102
+ *
103
+ * @since 1.1
104
+ */
105
+ public function render_settings_page() {
106
+
107
+ $current_tab = ( empty( $_GET['tab'] ) ) ? 'shop_loop' : urldecode( $_GET['tab'] );
108
+
109
+ ?>
110
+ <div class="wrap woocommerce">
111
+ <form method="post" id="mainform" action="" enctype="multipart/form-data">
112
+ <div id="icon-woocommerce" class="icon32-woocommerce-settings icon32"><br /></div>
113
+ <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
114
+
115
+ <?php
116
+
117
+ // display tabs
118
+ foreach ( $this->tabs as $tab_id => $tab_title ) {
119
+
120
+ $class = ( $tab_id === $current_tab ) ? 'nav-tab nav-tab-active' : 'nav-tab';
121
+ $url = add_query_arg( 'tab', $tab_id, admin_url( 'admin.php?page=wc_customizer' ) );
122
+
123
+ printf( '<a href="%s" class="%s">%s</a>', $url, $class, $tab_title );
124
+ }
125
+
126
+ ?> </h2> <?php
127
+
128
+ // save settings
129
+ if ( ! empty( $_POST ) ) {
130
+
131
+ if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'wc-customizer-settings' ) )
132
+ wp_die( __( 'Action failed. Please refresh the page and retry.', 'wc-customizer' ) );
133
+
134
+
135
+ $this->save_settings( $this->get_settings( $current_tab ) );
136
+
137
+ wp_redirect( add_query_arg( array( 'saved' => 'true' ) ) );
138
+
139
+ exit;
140
+ }
141
+
142
+ // display success message
143
+ if ( ! empty( $_GET['saved'] ) )
144
+ echo '<div id="message" class="updated fade"><p><strong>' . __( 'Your customizations have been saved.', 'wc-customizer' ) . '</strong></p></div>';
145
+
146
+ // display filters
147
+ $this->render_settings( $this->get_settings( $current_tab ) );
148
+
149
+ submit_button( __( 'Save Customizations', 'wc-customizer' ) );
150
+
151
+ wp_nonce_field( 'wc-customizer-settings', '_wpnonce', true, true );
152
+
153
+ ?></form></div> <?php
154
+ }
155
+
156
+
157
+ /**
158
+ * Show customization fields for a given tab
159
+ *
160
+ * @see adapted from woocommerce_admin_fields()
161
+ *
162
+ * @since 1.1
163
+ * @param array $fields the customization fields to show
164
+ */
165
+ private function render_settings( $fields ) {
166
+
167
+ $customizations = get_option( 'wc_customizer_active_customizations' );
168
+
169
+ foreach ( $fields as $field ) {
170
+
171
+ switch ( $field['type'] ) {
172
+
173
+ case 'title':
174
+ echo '<h3>' . esc_html( $field['title'] ) . '</h3>';
175
+ echo '<table class="form-table">';
176
+ break;
177
+
178
+ case 'sectionend':
179
+ echo '</table>';
180
+ break;
181
+
182
+ case 'text':;
183
+ $value = ( isset( $customizations[ $field['id'] ] ) ) ? $customizations[ $field['id'] ] : '';
184
+ ?>
185
+ <tr valign="top">
186
+ <th scope="row" class="titledesc">
187
+ <label for="<?php echo esc_attr( $field['id'] ); ?>"><?php echo esc_html( $field['title'] ); ?></label>
188
+ <img class="help_tip" data-tip="<?php echo esc_attr( $field['desc_tip'] ); ?>" src="<?php echo esc_url( $GLOBALS['woocommerce']->plugin_url() . '/assets/images/help.png' ); ?>" height="16" width="16" />
189
+ </th>
190
+ <td class="forminp forminp-text">
191
+ <input name="<?php echo esc_attr( $field['id'] ); ?>" id="<?php echo esc_attr( $field['id'] ); ?>" type="text" value="<?php echo esc_attr( $value ); ?>" />
192
+ </td>
193
+ </tr>
194
+ <?php
195
+ break;
196
+ }
197
+ }
198
+ }
199
+
200
+
201
+ /**
202
+ * Save customizations for a given tab
203
+ *
204
+ * @since 1.1
205
+ */
206
+ public function save_settings( $fields ) {
207
+
208
+ $customizations = get_option( 'wc_customizer_active_customizations' );
209
+
210
+ foreach ( $fields as $field ) {
211
+
212
+ if ( ! isset( $field['id'] ) )
213
+ continue;
214
+
215
+ if ( ! empty( $_POST[ $field['id'] ] ) )
216
+ $customizations[ $field['id'] ] = wp_kses_post( $_POST[ $field['id'] ] );
217
+
218
+ elseif ( isset( $customizations[ $field['id'] ] ) )
219
+ unset( $customizations[ $field['id'] ] );
220
+ }
221
+
222
+ update_option( 'wc_customizer_active_customizations', $customizations );
223
+ }
224
+
225
+
226
+ /**
227
+ * Return admin fields in proper format for outputting / saving
228
+ *
229
+ * @since 1.1
230
+ * @param string $tab_id the tab to get settings for
231
+ * @return array
232
+ */
233
+ private function get_settings( $tab_id ) {
234
+
235
+ $settings = array(
236
+
237
+ 'shop_loop' =>
238
+
239
+ array(
240
+
241
+ array(
242
+ 'title' => __( 'Add to Cart Button Text', 'wc-customizer' ),
243
+ 'type' => 'title'
244
+ ),
245
+
246
+ array(
247
+ 'id' => 'add_to_cart_text',
248
+ 'title' => __( 'Simple Product', 'wc-customizer' ),
249
+ 'desc_tip' => __( 'Changes the add to cart button text for simple products on all loop pages', 'wc-customizer' ),
250
+ 'type' => 'text'
251
+ ),
252
+
253
+ array(
254
+ 'id' => 'variable_add_to_cart_text',
255
+ 'title' => __( 'Variable Product', 'wc-customizer' ),
256
+ 'desc_tip' => __( 'Changes the add to cart button text for variable products on all loop pages', 'wc-customizer' ),
257
+ 'type' => 'text'
258
+ ),
259
+
260
+ array(
261
+ 'id' => 'grouped_add_to_cart_text',
262
+ 'title' => __( 'Grouped Product', 'wc-customizer' ),
263
+ 'desc_tip' => __( 'Changes the add to cart button text for grouped products on all loop pages', 'wc-customizer' ),
264
+ 'type' => 'text'
265
+ ),
266
+
267
+ array(
268
+ 'id' => 'external_add_to_cart_text',
269
+ 'title' => __( 'External Product', 'wc-customizer' ),
270
+ 'desc_tip' => __( 'Changes the add to cart button text for external products on all loop pages', 'wc-customizer' ),
271
+ 'type' => 'text'
272
+ ),
273
+
274
+ array(
275
+ 'id' => 'out_of_stock_add_to_cart_text',
276
+ 'title' => __( 'Out of Stock Product', 'wc-customizer' ),
277
+ 'desc_tip' => __( 'Changes the add to cart button text for out of stock products on all loop pages', 'wc-customizer' ),
278
+ 'type' => 'text'
279
+ ),
280
+
281
+ array( 'type' => 'sectionend' ),
282
+
283
+ array(
284
+ 'title' => __( 'Layout', 'wc-customizer' ),
285
+ 'type' => 'title'
286
+ ),
287
+
288
+ array(
289
+ 'id' => 'loop_shop_per_page',
290
+ 'title' => __( 'Products displayed per page', 'wc-customizer' ),
291
+ 'desc_tip' => __( 'Changes the number of products displayed per page', 'wc-customizer' ),
292
+ 'type' => 'text'
293
+ ),
294
+
295
+ array(
296
+ 'id' => 'loop_shop_columns',
297
+ 'title' => __( 'Product columns displayed per page', 'wc-customizer' ),
298
+ 'desc_tip' => __( 'Changes the number of columns displayed per page', 'wc-customizer' ),
299
+ 'type' => 'text'
300
+ ),
301
+
302
+ array(
303
+ 'id' => 'woocommerce_product_thumbnails_columns',
304
+ 'title' => __( 'Product thumbnail columns displayed', 'wc-customizer' ),
305
+ 'desc_tip' => __( 'Changes the number of product thumbnail columns displayed', 'wc-customizer' ),
306
+ 'type' => 'text'
307
+ ),
308
+
309
+ array( 'type' => 'sectionend' )
310
+
311
+ ),
312
+
313
+ 'product_page' =>
314
+
315
+ array(
316
+
317
+ array(
318
+ 'title' => __( 'Tab Titles', 'wc-customizer' ),
319
+ 'type' => 'title'
320
+ ),
321
+
322
+ array(
323
+ 'id' => 'woocommerce_product_description_tab_title',
324
+ 'title' => __( 'Product Description', 'wc-customizer' ),
325
+ 'desc_tip' => __( 'Changes the Production Description tab title', 'wc-customizer' ),
326
+ 'type' => 'text'
327
+ ),
328
+
329
+ array(
330
+ 'id' => 'woocommerce_product_additional_information_tab_title',
331
+ 'title' => __( 'Additional Information', 'wc-customizer' ),
332
+ 'desc_tip' => __( 'Changes the Additional Information tab title', 'wc-customizer' ),
333
+ 'type' => 'text'
334
+ ),
335
+
336
+ array( 'type' => 'sectionend' ),
337
+
338
+ array(
339
+ 'title' => __( 'Tab Content Headings', 'wc-customizer' ),
340
+ 'type' => 'title'
341
+ ),
342
+
343
+ array(
344
+ 'id' => 'woocommerce_product_description_heading',
345
+ 'title' => __( 'Product Description', 'wc-customizer' ),
346
+ 'desc_tip' => __( 'Changes the Product Description tab heading', 'wc-customizer' ),
347
+ 'type' => 'text'
348
+ ),
349
+
350
+ array(
351
+ 'id' => 'woocommerce_product_additional_information_heading',
352
+ 'title' => __( 'Additional Information', 'wc-customizer' ),
353
+ 'desc_tip' => __( 'Changes the Additional Information tab heading', 'wc-customizer' ),
354
+ 'type' => 'text'
355
+ ),
356
+
357
+ array( 'type' => 'sectionend' ),
358
+
359
+ array(
360
+ 'title' => __( 'Add to Cart Button Text', 'wc-customizer' ),
361
+ 'type' => 'title'
362
+ ),
363
+
364
+ array(
365
+ 'id' => 'single_add_to_cart_text',
366
+ 'title' => __( 'All Product Types', 'wc-customizer' ),
367
+ 'desc_tip' => __( 'Changes the Add to Cart button text on the single product page for all product type', 'wc-customizer' ),
368
+ 'type' => 'text'
369
+ ),
370
+
371
+ array( 'type' => 'sectionend' )
372
+ ),
373
+
374
+ 'checkout' =>
375
+
376
+ array(
377
+
378
+ array(
379
+ 'title' => __( 'Messages', 'wc-customizer' ),
380
+ 'type' => 'title'
381
+ ),
382
+
383
+ array(
384
+ 'id' => 'woocommerce_checkout_must_be_logged_in_message',
385
+ 'title' => __( 'Must be logged in text', 'wc-customizer' ),
386
+ 'desc_tip' => __( 'Changes the message displayed when a customer must be logged in to checkout', 'wc-customizer' ),
387
+ 'type' => 'text'
388
+ ),
389
+
390
+ array(
391
+ 'id' => 'woocommerce_checkout_coupon_message',
392
+ 'title' => __( 'Coupon text', 'wc-customizer' ),
393
+ 'desc_tip' => __( 'Changes the message displayed if the coupon form is enabled on checkout', 'wc-customizer' ),
394
+ 'type' => 'text'
395
+ ),
396
+
397
+ array(
398
+ 'id' => 'woocommerce_checkout_login_message',
399
+ 'title' => __( 'Login text', 'wc-customizer' ),
400
+ 'desc_tip' => __( 'Changes the message displayed if customers can login at checkout', 'wc-customizer' ),
401
+ 'type' => 'text'
402
+ ),
403
+
404
+ array( 'type' => 'sectionend' ),
405
+
406
+ array(
407
+ 'title' => __( 'Button Text', 'wc-customizer' ),
408
+ 'type' => 'title'
409
+ ),
410
+
411
+ array(
412
+ 'id' => 'woocommerce_order_button_text',
413
+ 'title' => __( 'Submit Order button', 'wc-customizer' ),
414
+ 'desc_tip' => __( 'Changes the Place Order button text on checkout', 'wc-customizer' ),
415
+ 'type' => 'text'
416
+ ),
417
+
418
+ array( 'type' => 'sectionend' )
419
+
420
+ ),
421
+
422
+ 'misc' =>
423
+
424
+ array(
425
+
426
+ array(
427
+ 'title' => __( 'Tax', 'wc-customizer' ),
428
+ 'type' => 'title'
429
+ ),
430
+
431
+ array(
432
+ 'id' => 'woocommerce_countries_tax_or_vat',
433
+ 'title' => __( 'Tax Label', 'wc-customizer' ),
434
+ 'desc_tip' => __( 'Changes the Taxes label. Defaults to Tax for USA, VAT for European countries', 'wc-customizer' ),
435
+ 'type' => 'text'
436
+ ),
437
+
438
+ array(
439
+ 'id' => 'woocommerce_countries_inc_tax_or_vat',
440
+ 'title' => __( 'Including Tax Label', 'wc-customizer' ),
441
+ 'desc_tip' => __( 'Changes the Including Taxes label. Defaults to Inc. tax for USA, Inc. VAT for European countries', 'wc-customizer' ),
442
+ 'type' => 'text'
443
+ ),
444
+
445
+ array(
446
+ 'id' => 'woocommerce_countries_ex_tax_or_vat',
447
+ 'title' => __( 'Excluding Tax Label', 'wc-customizer' ),
448
+ 'desc_tip' => __( 'Changes the Excluding Taxes label. Defaults to Exc. tax for USA, Exc. VAT for European countries', 'wc-customizer' ),
449
+ 'type' => 'text'
450
+ ),
451
+
452
+ array( 'type' => 'sectionend' )
453
+
454
+ ),
455
+
456
+ );
457
+
458
+ return ( isset( $settings[ $tab_id ] ) ) ? $settings[ $tab_id ] : array();
459
+ }
460
+
461
+
462
+ } // end \WC_Customizer_Admin class
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === WooCommerce Customizer ===
2
- Contributors: maxrice
3
- Donate link: http://www.maxrice.com
4
  Tags: woocommerce
5
- Requires at least: 3.5.1
6
- Tested up to: 3.5.1
7
- Stable tag: 1.0.1
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -40,11 +40,11 @@ Most likely because a filter does not yet exist within WooCommerce, or a filter
40
 
41
  = I found a bug! What do I do? =
42
 
43
- Please submit an issue on [Github](https://github.com/maxrice/woocommerce-customizer/) along with a description of the problem so I can fix it :)
44
 
45
  = Can I contribute to the plugin? =
46
 
47
- Yes! Fork the plugin on [Github](https://github.com/maxrice/woocommerce-customizer/) and send a pull request.
48
 
49
  == Screenshots ==
50
 
@@ -53,6 +53,10 @@ Yes! Fork the plugin on [Github](https://github.com/maxrice/woocommerce-customiz
53
 
54
  == Changelog ==
55
 
 
 
 
 
56
  = 1.0.1 =
57
  * Add two new filters for customizing the Product Description and Additional Information tab titles
58
  * Fix TipTips on Customizer page
1
  === WooCommerce Customizer ===
2
+ Contributors: maxrice, justinstern, skyverge
3
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=paypal@skyverge.com&item_name=Donation+for+WooCommerce+Customizer
4
  Tags: woocommerce
5
+ Requires at least: 3.5
6
+ Tested up to: 3.6
7
+ Stable tag: 1.1
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
40
 
41
  = I found a bug! What do I do? =
42
 
43
+ Please submit an issue on [Github](https://github.com/skyverge/woocommerce-customizer/) along with a description of the problem so we can fix it :)
44
 
45
  = Can I contribute to the plugin? =
46
 
47
+ Yes! Fork the plugin on [Github](https://github.com/skyverge/woocommerce-customizer/) and send a pull request.
48
 
49
  == Screenshots ==
50
 
53
 
54
  == Changelog ==
55
 
56
+ = 1.1 =
57
+ * Refactor to support the upcoming WooCommerce 2.1 beta
58
+ * Localization - Text domain changed from `wc_customizer` to `wc-customizer` and loaded properly on `init` hook
59
+
60
  = 1.0.1 =
61
  * Add two new filters for customizing the Product Description and Additional Information tab titles
62
  * Fix TipTips on Customizer page
woocommerce-customizer.php CHANGED
@@ -1,28 +1,27 @@
1
  <?php
2
  /**
3
  * Plugin Name: WooCommerce Customizer
4
- * Plugin URI: http://www.maxrice.com/wordpress/woocommerce-customizer/
5
- * Description: Helps you customize WooCommerce without writing any code
6
- * Version: 1.0.1
7
- * Author: Max Rice
8
- * Author URI: http://www.maxrice.com
 
 
9
  *
10
- *
11
- * Copyright: © 2012 Max Rice (max@maxrice.com)
12
  *
13
  * License: GNU General Public License v3.0
14
  * License URI: http://www.gnu.org/licenses/gpl-3.0.html
15
  *
16
- * @package WooCommerce-Customizer
17
- * @author Max Rice
18
- * @since 1.0
 
 
19
  */
20
 
21
- /**
22
- * Plugin Setup
23
- *
24
- * @since 1.0
25
- */
26
 
27
  // Check if WooCommerce is active
28
  if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) )
@@ -30,114 +29,197 @@ if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins',
30
 
31
 
32
  /**
33
- * Main Class
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  *
35
- * @since 1.0
36
  */
37
  class WC_Customizer {
38
 
39
- /** @var string option db prefix */
40
- public static $option_name = 'wc_customizer_active_customizations';
41
 
42
- /** @var string text domain */
43
- public static $text_domain = 'wc_customizer';
44
 
45
- /** @var plugin path */
46
- public static $plugin_path;
47
 
48
- /** @var plugin url */
49
- public static $plugin_url;
50
-
51
- /** @var active filters */
52
- public static $filters;
53
 
54
  /**
55
- * Init plugin
56
  *
57
- * @access public
58
- * @since 1.0
59
- * @return void
60
  */
61
- public static function init() {
62
 
63
- self::$plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) );
64
- self::$plugin_url = plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) );
65
 
66
- if ( is_admin() ) {
 
67
 
68
- self::admin_includes();
 
69
 
70
- // add a 'Start Customizing' link to the plugin action links
71
- // remember, __FILE__ derefs symlinks :(
72
- add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), __CLASS__ . '::plugin_manage_link' );
73
 
 
 
74
  }
75
 
76
- // load filter 'tags' and values
77
- self::$filters = maybe_unserialize( get_option( self::$option_name ) );
78
 
79
  // only add filters if some exist
80
- if ( self::$filters ) {
81
 
82
- foreach ( self::$filters as $filter_name => $filter_value ) {
83
- add_filter( $filter_name, __CLASS__ . '::customize' );
84
- }
85
 
86
- //for use some day, in a galaxy far, far away, when PHP 5.3+ has greater WP adoption
87
- //add_filter( $filter_name, function() use ( $filter_value ) { return $filter_value; } );
88
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
 
 
 
 
 
 
 
 
 
90
  }
91
 
92
 
 
 
 
93
  /**
94
  * Add hook to selected filters
95
  *
96
- * @access public
97
- * @since 1.0
98
  * @return string $filter_value value to use for selected hook
99
  */
100
- public static function customize() {
 
101
  $current_filter = current_filter();
102
 
103
- foreach ( self::$filters as $filter_name => $filter_value ) {
104
- if ( $filter_name == $current_filter )
105
- return $filter_value;
106
- }
107
 
 
108
  }
109
 
 
 
 
 
110
  /**
111
  * Return the plugin action links. This will only be called if the plugin
112
  * is active.
113
  *
114
- * @access public
115
- * @since 1.0
116
  * @param array $actions associative array of action names to anchor tags
117
  * @return array associative array of plugin action links
118
  */
119
- public static function plugin_manage_link( $actions ) {
120
- // add the link to the front of the actions list
121
- return ( array_merge( array( 'start_customizing' => sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php?page=woocommerce_customizer' ), __( 'Start Customizing', self::$text_domain ) ) ),
122
- $actions )
 
 
123
  );
 
 
 
124
  }
125
 
 
 
 
 
126
  /**
127
- * Include admin class
128
  *
129
- * @access private
130
- * @since 1.0
131
- * @return void
132
  */
133
- private static function admin_includes() {
134
 
135
- require_once( 'admin/class-wc-customizer-admin.php' );
 
 
 
 
 
 
 
 
 
 
 
136
  }
137
 
138
 
139
- } // end class
 
 
 
 
 
 
 
 
 
 
140
 
141
- WC_Customizer::init();
142
 
143
- //end file
1
  <?php
2
  /**
3
  * Plugin Name: WooCommerce Customizer
4
+ * Plugin URI: http://www.skyverge.com/product/woocommerce-customizer/
5
+ * Description: Customize WooCommerce without code! Easily change add to cart button text and more.
6
+ * Author: SkyVerge
7
+ * Author URI: http://www.skyverge.com
8
+ * Version: 1.1
9
+ * Text Domain: wc-customizer
10
+ * Domain Path: /languages/
11
  *
12
+ * Copyright: (c) 2013 SkyVerge, Inc. (info@skyverge.com)
 
13
  *
14
  * License: GNU General Public License v3.0
15
  * License URI: http://www.gnu.org/licenses/gpl-3.0.html
16
  *
17
+ * @package WC-Customizer
18
+ * @author SkyVerge
19
+ * @category Utility
20
+ * @copyright Copyright (c) 2013, SkyVerge, Inc.
21
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
22
  */
23
 
24
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
 
 
 
 
25
 
26
  // Check if WooCommerce is active
27
  if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) )
29
 
30
 
31
  /**
32
+ * The WC_Customizer global object
33
+ * @name $wc_customizer
34
+ * @global WC_Customizer $GLOBALS['wc_customizer']
35
+ */
36
+ $GLOBALS['wc_customizer'] = new WC_Customizer();
37
+
38
+ /**
39
+ * # WooCommerce Customizer Main Plugin Class
40
+ *
41
+ * ## Plugin Overview
42
+ *
43
+ * Adds a few settings pages which make uses of some of the simpler filters inside WooCommerce, so if you want to quickly
44
+ * change button text or the number of products per page, you can use this instead of having to write code for the filter.
45
+ * Note this isn't designed as a rapid development/prototyping tool -- for a production site you should use the actual filter
46
+ * instead of relying on this plugin.
47
+ *
48
+ * ## Admin Considerations
49
+ *
50
+ * A 'Customizer' sub-menu page is added to the top-level WooCommerce page, which contains 4 tabs with the settings
51
+ * for each section - Shop Loop, Product Page, Checkout, Misc
52
+ *
53
+ * ## Frontend Considerations
54
+ *
55
+ * The filters that the plugin exposes as settings as used exclusively on the frontend.
56
+ *
57
+ * ## Database
58
+ *
59
+ * ### Global Settings
60
+ *
61
+ * + `wc_customizer_active_customizations` - a serialized array of active customizations in the format
62
+ * filter name => filter value
63
+ *
64
+ * ### Options table
65
+ *
66
+ * + `wc_customizer_version` - the current plugin version, set on install/upgrade
67
  *
 
68
  */
69
  class WC_Customizer {
70
 
 
 
71
 
72
+ /** plugin version number */
73
+ const VERSION = '1.1';
74
 
75
+ /** var array the active filters */
76
+ public $filters;
77
 
 
 
 
 
 
78
 
79
  /**
80
+ * Initializes the plugin
81
  *
82
+ * @since 1.0
 
 
83
  */
84
+ public function __construct() {
85
 
86
+ // load translation
87
+ add_action( 'init', array( $this, 'load_translation' ) );
88
 
89
+ // admin
90
+ if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
91
 
92
+ // include required files
93
+ $this->admin_includes();
94
 
95
+ // add a 'Configure' link to the plugin action links
96
+ add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_plugin_action_links' ) );
 
97
 
98
+ // run every time
99
+ $this->install();
100
  }
101
 
102
+ // load filter names and values
103
+ $this->filters = get_option( 'wc_customizer_active_customizations' );
104
 
105
  // only add filters if some exist
106
+ if ( ! empty( $this->filters ) ) {
107
 
108
+ 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
113
+ // add_filter( $filter_name, function() use ( $filter_value ) { return $filter_value; } );
114
  }
115
+ }
116
+
117
+
118
+ /**
119
+ * Include required admin files
120
+ *
121
+ * @since 1.1
122
+ */
123
+ private function admin_includes() {
124
+
125
+ // admin UI
126
+ require( 'includes/class-wc-customizer-admin.php' );
127
+ $this->admin = new WC_Customizer_Admin();
128
+ }
129
+
130
 
131
+ /**
132
+ * Handle localization, WPML compatible
133
+ *
134
+ * @since 1.1
135
+ */
136
+ public function load_translation() {
137
+
138
+ // localization in the init action for WPML support
139
+ load_plugin_textdomain( 'wc-customizer', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
140
  }
141
 
142
 
143
+ /** Frontend methods ******************************************************/
144
+
145
+
146
  /**
147
  * Add hook to selected filters
148
  *
149
+ * @since 1.0
 
150
  * @return string $filter_value value to use for selected hook
151
  */
152
+ public function customize() {
153
+
154
  $current_filter = current_filter();
155
 
156
+ if ( isset( $this->filters[ $current_filter ] ) )
157
+ return $this->filters[ $current_filter ];
 
 
158
 
159
+ // no need to return a value passed in, because if a filter is set, it's designed to only return that value
160
  }
161
 
162
+
163
+ /** Admin methods ******************************************************/
164
+
165
+
166
  /**
167
  * Return the plugin action links. This will only be called if the plugin
168
  * is active.
169
  *
170
+ * @since 0.1
 
171
  * @param array $actions associative array of action names to anchor tags
172
  * @return array associative array of plugin action links
173
  */
174
+ public function add_plugin_action_links( $actions ) {
175
+
176
+ $custom_actions = array(
177
+ 'configure' => sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php?page=wc_customizer' ), __( 'Configure', 'wc-customizer' ) ),
178
+ 'faq' => sprintf( '<a href="%s">%s</a>', 'http://wordpress.org/plugins/woocommerce-customizer/faq/', __( 'FAQ', 'wc-customizer' ) ),
179
+ 'support' => sprintf( '<a href="%s">%s</a>', 'http://wordpress.org/support/plugin/woocommerce-customizer', __( 'Support', 'wc-customizer' ) ),
180
  );
181
+
182
+ // add the links to the front of the actions list
183
+ return array_merge( $custom_actions, $actions );
184
  }
185
 
186
+
187
+ /** Lifecycle methods ******************************************************/
188
+
189
+
190
  /**
191
+ * Run every time. Used since the activation hook is not executed when updating a plugin
192
  *
193
+ * @since 1.1
 
 
194
  */
195
+ private function install() {
196
 
197
+ // get current version to check for upgrade
198
+ $installed_version = get_option( 'wc_customizer_version' );
199
+
200
+ // install
201
+ if ( ! $installed_version ) {
202
+
203
+ // install default settings
204
+ }
205
+
206
+ // upgrade if installed version lower than plugin version
207
+ if ( -1 === version_compare( $installed_version, self::VERSION ) )
208
+ $this->upgrade( $installed_version );
209
  }
210
 
211
 
212
+ /**
213
+ * Perform any version-related changes.
214
+ *
215
+ * @since 1.1
216
+ * @param int $installed_version the currently installed version of the plugin
217
+ */
218
+ private function upgrade( $installed_version ) {
219
+
220
+ // update the installed version option
221
+ update_option( 'wc_customizer_version', self::VERSION );
222
+ }
223
 
 
224
 
225
+ } // end \WC_Customizer