Custom Product Tabs for WooCommerce - Version 1.6.8

Version Description

  • January 2nd, 2018 =
  • Fixing some HTML markup.
  • Applying PHPCS fixes.
Download this release

Release Info

Developer yikesitskevin
Plugin Icon 128x128 Custom Product Tabs for WooCommerce
Version 1.6.8
Comparing to
See all releases

Code changes from version 1.6.7 to 1.6.8

admin/page.yikes-woo-saved-tabs.php CHANGED
@@ -42,20 +42,20 @@
42
  </div>
43
  <br class="clear">
44
  </div>
45
- <table class="widefat fixed" cellspacing="0">
46
  <thead>
47
  <tr>
48
  <td id="cb" class="manage-column column-cb check-column" scope="col">
49
  <label class="screen-reader-text" for="cb-select-all-1"><?php _e( 'Select All', 'yikes-inc-easy-custom-woocommerce-product-tabs' ); ?></label>
50
  <input id="cb-select-all-1" type="checkbox">
51
  </td>
52
- <th class="manage-column column-title" scope="col">
53
  <?php _e( 'Tab Title', 'yikes-inc-easy-custom-woocommerce-product-tabs' ); ?>
54
  </th>
55
- <th class="manage-column column-name" scope="col">
56
  <?php _e( 'Tab Name', 'yikes-inc-easy-custom-woocommerce-product-tabs' ); ?>
57
  </th>
58
- <th class="manage-column column-content" scope="col">
59
  <?php _e( 'Tab Content Preview', 'yikes-inc-easy-custom-woocommerce-product-tabs' ); ?>
60
  </th>
61
  <?php do_action( 'yikes-woo-saved-tabs-table-header' ); ?>
@@ -83,7 +83,7 @@
83
  </tr>
84
  </tfoot>
85
 
86
- <tbody id="yikes-woo-saved-tabs-list-table">
87
  <?php
88
  if( ! empty( $yikes_custom_tab_data ) ) {
89
 
42
  </div>
43
  <br class="clear">
44
  </div>
45
+ <table id="yikes-woo-saved-tabs-list-table" class="widefat fixed" cellspacing="0">
46
  <thead>
47
  <tr>
48
  <td id="cb" class="manage-column column-cb check-column" scope="col">
49
  <label class="screen-reader-text" for="cb-select-all-1"><?php _e( 'Select All', 'yikes-inc-easy-custom-woocommerce-product-tabs' ); ?></label>
50
  <input id="cb-select-all-1" type="checkbox">
51
  </td>
52
+ <th class="manage-column column-tab-title" scope="col">
53
  <?php _e( 'Tab Title', 'yikes-inc-easy-custom-woocommerce-product-tabs' ); ?>
54
  </th>
55
+ <th class="manage-column column-tab-name" scope="col">
56
  <?php _e( 'Tab Name', 'yikes-inc-easy-custom-woocommerce-product-tabs' ); ?>
57
  </th>
58
+ <th class="manage-column column-tab-content-preview" scope="col">
59
  <?php _e( 'Tab Content Preview', 'yikes-inc-easy-custom-woocommerce-product-tabs' ); ?>
60
  </th>
61
  <?php do_action( 'yikes-woo-saved-tabs-table-header' ); ?>
83
  </tr>
84
  </tfoot>
85
 
86
+ <tbody id="yikes-woo-saved-tabs-list-tbody">
87
  <?php
88
  if( ! empty( $yikes_custom_tab_data ) ) {
89
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://yikesinc.com
4
  Tags: woocommerce, product tabs, repeatable, duplicate, customize, custom, tabs, product, woo, commerce
5
  Requires at least: 3.8
6
  Tested up to: 5.0.2
7
- Stable tag: 1.6.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -75,6 +75,10 @@ Yes! Since v1.4 we've added the necessary code to ensure the custom tab data is
75
 
76
  == Changelog ==
77
 
 
 
 
 
78
  = 1.6.7 - December 18th, 2018 =
79
  * Adding filter to help allow importing of custom tabs.
80
  * Changing our export filters so custom tabs work with WooCommerce's native meta export/import features.
4
  Tags: woocommerce, product tabs, repeatable, duplicate, customize, custom, tabs, product, woo, commerce
5
  Requires at least: 3.8
6
  Tested up to: 5.0.2
7
+ Stable tag: 1.6.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
75
 
76
  == Changelog ==
77
 
78
+ = 1.6.8 - January 2nd, 2018 =
79
+ * Fixing some HTML markup.
80
+ * Applying PHPCS fixes.
81
+
82
  = 1.6.7 - December 18th, 2018 =
83
  * Adding filter to help allow importing of custom tabs.
84
  * Changing our export filters so custom tabs work with WooCommerce's native meta export/import features.
yikes-inc-easy-custom-woocommerce-product-tabs.php CHANGED
@@ -1,11 +1,11 @@
1
  <?php
2
  /**
3
- * Plugin Name: Custom Product Tabs for WooCommerce
4
  * Plugin URI: http://www.yikesinc.com
5
  * Description: Extend WooCommerce to add and manage custom product tabs. Create as many product tabs as needed per product.
6
  * Author: YIKES, Inc.
7
  * Author URI: http://www.yikesinc.com
8
- * Version: 1.6.7
9
  * Text Domain: yikes-inc-easy-custom-woocommerce-product-tabs
10
  * Domain Path: languages/
11
  *
@@ -16,317 +16,307 @@
16
  *
17
  * License: GNU General Public License v3.0
18
  * License URI: http://www.gnu.org/licenses/gpl-3.0.html
19
- *
20
- * This plugin is originally a fork of SkyVerge WooCommerce Custom Product Tabs Lite
21
  *
 
22
  */
23
 
24
- // Exit if accessed directly
25
- if ( ! defined( 'ABSPATH' ) ) exit;
26
-
27
- // Must include plugin.php to use is_plugin_active()
28
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
29
 
30
- if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
 
31
 
32
- new YIKES_Custom_Product_Tabs();
 
 
 
 
 
 
33
 
34
- } else {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
- /* Deactivate the plugin, and display our error notification */
37
- deactivate_plugins( '/yikes-inc-easy-custom-woocommerce-product-tabs/yikes-inc-easy-custom-woocommerce-product-tabs.php' );
38
- add_action( 'admin_notices' , 'yikes_woo_display_admin_notice_error' );
39
- }
40
-
41
- /**
42
- * Display our error admin notice if WooCommerce is not installed + active
43
- */
44
- function yikes_woo_display_admin_notice_error() {
45
- ?>
46
- <!-- hide the 'Plugin Activated' default message -->
47
- <style>
48
- #message.updated {
49
- display: none;
50
- }
51
- </style>
52
- <!-- display our error message -->
53
- <div class="error">
54
- <p><?php _e( 'Custom Product Tabs for WooCommerce could not be activated because WooCommerce is not installed and active.', 'yikes-inc-easy-custom-woocommerce-product-tabs' ); ?></p>
55
- <p><?php _e( 'Please install and activate ', 'yikes-inc-easy-custom-woocommerce-product-tabs' ); ?><a href="<?php echo admin_url( 'plugin-install.php?tab=search&type=term&s=WooCommerce' ); ?>" title="WooCommerce">WooCommerce</a><?php _e( ' before activating the plugin.', 'yikes-inc-easy-custom-woocommerce-product-tabs' ); ?></p>
56
- </div>
57
- <?php
58
- }
59
-
60
  /**
61
- * Initialize the Custom Product Tab Class
62
- */
63
- class YIKES_Custom_Product_Tabs {
64
 
65
- /**
66
- * Construct :)
67
- */
68
- public function __construct() {
69
 
70
- $this->define_constants();
71
 
72
- add_action( 'admin_init', array( $this, 'run_update_check' ) );
 
 
 
 
 
 
 
73
 
74
- // Require our classes
75
- require_once YIKES_Custom_Product_Tabs_Path . 'admin/class.yikes-woo-saved-tabs.php';
76
- require_once YIKES_Custom_Product_Tabs_Path . 'admin/class.yikes-woo-tabs.php';
77
- require_once YIKES_Custom_Product_Tabs_Path . 'admin/class.support.php';
78
- require_once YIKES_Custom_Product_Tabs_Path . 'public/class.yikes-woo-tabs-display.php';
79
- require_once YIKES_Custom_Product_Tabs_Path . 'admin/class.premium.php';
80
- require_once YIKES_Custom_Product_Tabs_Path . 'admin/class.export.php';
81
- require_once YIKES_Custom_Product_Tabs_Path . 'admin/class.import.php';
82
 
83
- add_action( 'admin_init', array( $this, 'init' ) );
84
- }
 
 
85
 
86
  /**
87
- * Define our constants
88
- */
89
- private function define_constants() {
90
-
91
- /**
92
- * Define the text domain
93
- *
94
- * This isn't used anywhere as I don't believe you can use a constant as a text domain
95
- */
96
- if ( ! defined( 'YIKES_Custom_Product_Tabs_Text_Domain' ) ) {
97
- define( 'YIKES_Custom_Product_Tabs_Text_Domain', 'yikes-inc-easy-custom-woocommerce-product-tabs' );
98
- }
99
-
100
- /**
101
- * Define the page slug for our plugin's custom settings page in one central location
102
- */
103
- if ( ! defined( 'YIKES_Custom_Product_Tabs_Settings_Page' ) ) {
104
- define( 'YIKES_Custom_Product_Tabs_Settings_Page', 'yikes-woo-settings' );
105
- }
106
-
107
- /**
108
- * Define the plugin's version
109
- */
110
- if ( ! defined( 'YIKES_Custom_Product_Tabs_Version' ) ) {
111
- define( 'YIKES_Custom_Product_Tabs_Version', '1.6.7' );
112
- }
113
 
114
- /**
115
- * Define the plugin's URI
116
- */
117
- if ( ! defined( 'YIKES_Custom_Product_Tabs_URI' ) ) {
118
- define( 'YIKES_Custom_Product_Tabs_URI', plugin_dir_url( __FILE__ ) );
119
- }
120
 
121
- /**
122
- * Define the plugin's path
123
- */
124
- if ( ! defined( 'YIKES_Custom_Product_Tabs_Path' ) ) {
125
- define( 'YIKES_Custom_Product_Tabs_Path', plugin_dir_path( __FILE__ ) );
126
- }
127
 
128
- /**
129
- * Define the page slug for our plugin's support page
130
- */
131
- if ( ! defined( 'YIKES_Custom_Product_Tabs_Support_Page' ) ) {
132
- define( 'YIKES_Custom_Product_Tabs_Support_Page', 'yikes-woo-support' );
133
- }
134
 
135
- /**
136
- * Define the page slug for our plugin's premium page
137
- */
138
- if ( ! defined( 'YIKES_Custom_Product_Tabs_Premium_Page' ) ) {
139
- define( 'YIKES_Custom_Product_Tabs_Premium_Page', 'yikes-woo-premium' );
140
- }
141
  }
142
 
143
  /**
144
- * Run any update scripts
145
- */
146
- public function run_update_check() {
 
 
 
147
 
148
- $run_onesixone_data_update = get_option( 'custom_product_tabs_onesixone_data_update' );
 
 
 
149
 
150
- // If we don't have a value for this option then run our update again
151
- if ( empty( $run_onesixone_data_update ) ) {
152
- $this->run_onesixone_data_update();
153
- }
154
 
 
 
 
155
  }
156
 
157
- private function run_onesixone_data_update() {
158
-
159
- /** Update Saved Tabs **/
160
- $saved_tabs = get_option( 'yikes_woo_reusable_products_tabs' );
161
 
162
- if ( ! empty( $saved_tabs ) ) {
 
 
 
163
 
164
- foreach( $saved_tabs as $tab_id => &$tab ) {
 
165
 
166
- // Set the tab slug to the sanitized tab's title
167
- $tab['tab_slug'] = urldecode( sanitize_title( $tab['tab_title'] ) );
168
 
169
- // Default these elements
170
- $tab['taxonomies'] = ! isset( $tab['taxonomies'] ) ? array() : $tab['taxonomies'];
171
- $tab['global_tab'] = ! isset( $tab['global_tab'] ) ? false : $tab['global_tab'];
172
- $tab['tab_name'] = ! isset( $tab['tab_name'] ) ? '' : $tab['tab_name'];
173
- }
174
 
175
- update_option( 'yikes_woo_reusable_products_tabs', $saved_tabs );
 
176
 
 
 
 
 
177
  }
178
 
179
- /** Update Saved Tabs Applied **/
180
- $saved_tabs_applied = get_option( 'yikes_woo_reusable_products_tabs_applied' );
181
 
182
- if ( ! empty( $saved_tabs_applied ) ) {
183
 
184
- foreach( $saved_tabs_applied as $product_id => &$tabs ) {
 
185
 
186
- if ( ! empty( $tabs ) ) {
187
 
188
- foreach( $tabs as $saved_tab_id => &$tab ) {
189
 
190
- if ( ! empty( $tab ) ) {
191
 
192
- if ( isset( $saved_tabs[ $saved_tab_id ] ) ) {
193
 
194
- // Set the tab ID to the saved tab's slug
195
- $tab_id = $saved_tabs[ $saved_tab_id ]['tab_slug'];
196
- $tab['tab_id'] = $tab_id;
197
- }
198
 
199
- } else {
200
 
201
- // In previous versions of the plugin we were leaving some empty arrays. Clean 'em up.
202
- unset( $tab );
 
203
  }
204
- }
205
- } else {
206
 
207
- // In previous versions of the plugin we were leaving some empty arrays. Clean 'em up.
208
- unset( $saved_tabs_applied[ $product_id ] );
 
209
  }
210
- }
211
 
212
- update_option( 'yikes_woo_reusable_products_tabs_applied', $saved_tabs_applied );
 
 
213
  }
214
 
215
- /** Update Post Meta **/
216
- global $wpdb;
 
 
 
217
 
218
- // Fetch all of the post meta items where meta_key = 'yikes_woo_products_tabs'
219
- $yikes_woo_products_tabs = $wpdb->get_results(
220
- "
221
- SELECT *
222
- FROM {$wpdb->postmeta}
223
- WHERE meta_key = 'yikes_woo_products_tabs'
224
- "
225
- );
226
 
227
- if ( ! empty( $yikes_woo_products_tabs ) ) {
228
 
229
- foreach( $yikes_woo_products_tabs as $table_row ) {
230
 
231
- // Unserialize our tabs
232
- $tabs = unserialize( $table_row->meta_value );
233
 
234
- // If we have tabs...
235
- if ( ! empty( $tabs ) ) {
236
 
237
- foreach( $tabs as &$tab ) {
238
 
239
- // Set the tab slug ('id') to the sanitized tab's title
240
- $tab['id'] = urldecode( sanitize_title( $tab['title'] ) );
241
- }
242
 
243
- update_post_meta( $table_row->post_id, 'yikes_woo_products_tabs', $tabs );
244
 
245
- } else {
246
 
247
- // In previous versions of the plugin we were leaving some empty arrays. Clean 'em up.
248
- delete_post_meta( $table_row->post_id, 'yikes_woo_products_tabs' );
249
- }
250
  }
251
  }
252
-
253
- // Set a flag so we don't run this update more than once
254
- add_option( 'custom_product_tabs_onesixone_data_update', true );
255
  }
256
 
 
 
 
257
 
258
- /**
259
- * Run our basic plugin setup
260
- */
261
- public function init() {
262
-
263
- // Default WYSIWYG to 'visual'
264
- add_filter( 'wp_default_editor', array( $this, 'yikes_woo_set_editor_to_visual' ), 10, 1 );
265
-
266
- // i18n
267
- add_action( 'plugins_loaded', array( $this, 'yikes_woo_load_plugin_textdomain' ) );
268
-
269
- // Add settings link to plugin on plugins page
270
- add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_plugin_action_links' ), 10, 1 );
271
- }
272
-
273
- /**
274
- * Add a link to the settings page to the plugin's action links
275
- *
276
- * @since 1.5
277
- *
278
- * @param array | $links | array of links passed from the plugin_action_links_{plugin_name} filter
279
- */
280
- public function add_plugin_action_links( $links ) {
281
- $href = esc_url_raw( add_query_arg( array( 'page' => YIKES_Custom_Product_Tabs_Settings_Page ), admin_url() ) );
282
- $links[] = '<a href="'. $href .'">Saved Tabs</a>';
283
- return $links;
284
- }
285
 
286
-
287
- /* i18n */
 
 
288
 
289
- /**
290
- * Register the textdomain for proper i18n / l10n
291
- * @since 1.5
292
- */
293
- public function yikes_woo_load_plugin_textdomain() {
294
- load_plugin_textdomain(
295
- 'yikes-inc-easy-custom-woocommerce-product-tabs',
296
- false,
297
- YIKES_Custom_Product_Tabs_Path . 'languages/'
298
- );
299
- }
300
 
301
- /* End i18n */
 
302
 
 
 
 
303
 
304
- /* Misc. */
 
 
 
 
 
 
 
 
 
 
 
 
 
305
 
306
- /**
307
- * Default the wp_editor to 'Visual' tab (this helps prevent errors with dynamically generating WYSIWYG)
308
- *
309
- * @since 1.5
310
- *
311
- * @param string | $mode | The current mode of the editor
312
- * @return string 'tinymce' || $mode
313
- */
314
- public function yikes_woo_set_editor_to_visual( $mode ) {
315
- global $post;
316
-
317
- // Only continue if we're on the products page
318
- if ( isset( $post ) && isset( $post->post_type ) && $post->post_type !== 'product' ) {
319
- return $mode;
320
- }
321
 
322
- // This is funky, but only default the editor when we don't have a post (and we're on the product page)
323
- // This a result of calling the wp_editor via AJAX - I think
324
- if ( ! isset( $post ) ) {
325
- return apply_filters( 'yikes_woocommerce_default_editor_mode', 'tinymce' );
326
- } else {
327
- return $mode;
328
- }
 
 
 
 
 
 
 
 
329
  }
330
 
331
- /* End Misc. */
 
 
 
 
 
 
332
  }
 
1
  <?php
2
  /**
3
+ * Plugin Name: Custom Product Tabs for WooCommerce
4
  * Plugin URI: http://www.yikesinc.com
5
  * Description: Extend WooCommerce to add and manage custom product tabs. Create as many product tabs as needed per product.
6
  * Author: YIKES, Inc.
7
  * Author URI: http://www.yikesinc.com
8
+ * Version: 1.6.8
9
  * Text Domain: yikes-inc-easy-custom-woocommerce-product-tabs
10
  * Domain Path: languages/
11
  *
16
  *
17
  * License: GNU General Public License v3.0
18
  * License URI: http://www.gnu.org/licenses/gpl-3.0.html
 
 
19
  *
20
+ * This plugin is originally a fork of SkyVerge WooCommerce Custom Product Tabs Lite.
21
  */
22
 
23
+ // Exit if accessed directly.
24
+ if ( ! defined( 'ABSPATH' ) ) exit;
 
 
 
25
 
26
+ // Must include plugin.php to use is_plugin_active().
27
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
28
 
29
+ if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
30
+ new YIKES_Custom_Product_Tabs();
31
+ } else {
32
+ // Deactivate the plugin, and display our error notification.
33
+ deactivate_plugins( '/yikes-inc-easy-custom-woocommerce-product-tabs/yikes-inc-easy-custom-woocommerce-product-tabs.php' );
34
+ add_action( 'admin_notices', 'yikes_woo_display_admin_notice_error' );
35
+ }
36
 
37
+ /**
38
+ * Display our error admin notice if WooCommerce is not installed + active.
39
+ */
40
+ function yikes_woo_display_admin_notice_error() {
41
+ ?>
42
+ <!-- hide the 'Plugin Activated' default message -->
43
+ <style>
44
+ #message.updated {
45
+ display: none;
46
+ }
47
+ </style>
48
+ <!-- display our error message -->
49
+ <div class="error">
50
+ <p>
51
+ <?php
52
+ esc_html_e( 'Custom Product Tabs for WooCommerce could not be activated because WooCommerce is not installed and active.', 'yikes-inc-easy-custom-woocommerce-product-tabs' );
53
+ ?>
54
+ </p>
55
+ <p>
56
+ <?php
57
+ /* translators: The placeholder is a URL to the WooCommerce plugin. */
58
+ echo sprintf( esc_html( 'Please install and activate %1s before activating the plugin.', 'yikes-inc-easy-custom-woocommerce-product-tabs' ), '<a href="' . esc_url( admin_url( 'plugin-install.php?tab=search&type=term&s=WooCommerce' ) ) . '" title="WooCommerce">WooCommerce</a>' );
59
+ ?>
60
+ </p>
61
+ </div>
62
+ <?php
63
+ }
64
+
65
+ /**
66
+ * Initialize the Custom Product Tab Class.
67
+ */
68
+ class YIKES_Custom_Product_Tabs {
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  /**
71
+ * Define hooks/require files.
72
+ */
73
+ public function __construct() {
74
 
75
+ $this->define_constants();
 
 
 
76
 
77
+ add_action( 'admin_init', array( $this, 'run_update_check' ) );
78
 
79
+ // Require our classes.
80
+ require_once YIKES_Custom_Product_Tabs_Path . 'admin/class.yikes-woo-saved-tabs.php';
81
+ require_once YIKES_Custom_Product_Tabs_Path . 'admin/class.yikes-woo-tabs.php';
82
+ require_once YIKES_Custom_Product_Tabs_Path . 'admin/class.support.php';
83
+ require_once YIKES_Custom_Product_Tabs_Path . 'public/class.yikes-woo-tabs-display.php';
84
+ require_once YIKES_Custom_Product_Tabs_Path . 'admin/class.premium.php';
85
+ require_once YIKES_Custom_Product_Tabs_Path . 'admin/class.export.php';
86
+ require_once YIKES_Custom_Product_Tabs_Path . 'admin/class.import.php';
87
 
88
+ add_action( 'admin_init', array( $this, 'init' ) );
89
+ }
 
 
 
 
 
 
90
 
91
+ /**
92
+ * Define our constants.
93
+ */
94
+ private function define_constants() {
95
 
96
  /**
97
+ * Define the page slug for our plugin's custom settings page in one central location.
98
+ */
99
+ if ( ! defined( 'YIKES_Custom_Product_Tabs_Settings_Page' ) ) {
100
+ define( 'YIKES_Custom_Product_Tabs_Settings_Page', 'yikes-woo-settings' );
101
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
+ /**
104
+ * Define the plugin's version.
105
+ */
106
+ if ( ! defined( 'YIKES_Custom_Product_Tabs_Version' ) ) {
107
+ define( 'YIKES_Custom_Product_Tabs_Version', '1.6.7' );
108
+ }
109
 
110
+ /**
111
+ * Define the plugin's URI.
112
+ */
113
+ if ( ! defined( 'YIKES_Custom_Product_Tabs_URI' ) ) {
114
+ define( 'YIKES_Custom_Product_Tabs_URI', plugin_dir_url( __FILE__ ) );
115
+ }
116
 
117
+ /**
118
+ * Define the plugin's path.
119
+ */
120
+ if ( ! defined( 'YIKES_Custom_Product_Tabs_Path' ) ) {
121
+ define( 'YIKES_Custom_Product_Tabs_Path', plugin_dir_path( __FILE__ ) );
122
+ }
123
 
124
+ /**
125
+ * Define the page slug for our plugin's support page.
126
+ */
127
+ if ( ! defined( 'YIKES_Custom_Product_Tabs_Support_Page' ) ) {
128
+ define( 'YIKES_Custom_Product_Tabs_Support_Page', 'yikes-woo-support' );
 
129
  }
130
 
131
  /**
132
+ * Define the page slug for our plugin's premium page.
133
+ */
134
+ if ( ! defined( 'YIKES_Custom_Product_Tabs_Premium_Page' ) ) {
135
+ define( 'YIKES_Custom_Product_Tabs_Premium_Page', 'yikes-woo-premium' );
136
+ }
137
+ }
138
 
139
+ /**
140
+ * Run any update scripts.
141
+ */
142
+ public function run_update_check() {
143
 
144
+ $run_onesixone_data_update = get_option( 'custom_product_tabs_onesixone_data_update' );
 
 
 
145
 
146
+ // If we don't have a value for this option then run our update again.
147
+ if ( empty( $run_onesixone_data_update ) ) {
148
+ $this->run_onesixone_data_update();
149
  }
150
 
151
+ }
 
 
 
152
 
153
+ /**
154
+ * Run the v1.6 update. This changes the tabs' slug and adds some default elements to our tab items.
155
+ */
156
+ private function run_onesixone_data_update() {
157
 
158
+ // Update Saved Tabs.
159
+ $saved_tabs = get_option( 'yikes_woo_reusable_products_tabs' );
160
 
161
+ if ( ! empty( $saved_tabs ) ) {
 
162
 
163
+ foreach ( $saved_tabs as $tab_id => &$tab ) {
 
 
 
 
164
 
165
+ // Set the tab slug to the sanitized tab's title.
166
+ $tab['tab_slug'] = urldecode( sanitize_title( $tab['tab_title'] ) );
167
 
168
+ // Default these elements.
169
+ $tab['taxonomies'] = ! isset( $tab['taxonomies'] ) ? array() : $tab['taxonomies'];
170
+ $tab['global_tab'] = ! isset( $tab['global_tab'] ) ? false : $tab['global_tab'];
171
+ $tab['tab_name'] = ! isset( $tab['tab_name'] ) ? '' : $tab['tab_name'];
172
  }
173
 
174
+ update_option( 'yikes_woo_reusable_products_tabs', $saved_tabs );
 
175
 
176
+ }
177
 
178
+ // Update Saved Tabs Applied.
179
+ $saved_tabs_applied = get_option( 'yikes_woo_reusable_products_tabs_applied' );
180
 
181
+ if ( ! empty( $saved_tabs_applied ) ) {
182
 
183
+ foreach ( $saved_tabs_applied as $product_id => &$tabs ) {
184
 
185
+ if ( ! empty( $tabs ) ) {
186
 
187
+ foreach ( $tabs as $saved_tab_id => &$tab ) {
188
 
189
+ if ( ! empty( $tab ) ) {
 
 
 
190
 
191
+ if ( isset( $saved_tabs[ $saved_tab_id ] ) ) {
192
 
193
+ // Set the tab ID to the saved tab's slug.
194
+ $tab_id = $saved_tabs[ $saved_tab_id ]['tab_slug'];
195
+ $tab['tab_id'] = $tab_id;
196
  }
197
+ } else {
 
198
 
199
+ // In previous versions of the plugin we were leaving some empty arrays. Clean 'em up.
200
+ unset( $tab );
201
+ }
202
  }
203
+ } else {
204
 
205
+ // In previous versions of the plugin we were leaving some empty arrays. Clean 'em up.
206
+ unset( $saved_tabs_applied[ $product_id ] );
207
+ }
208
  }
209
 
210
+ update_option( 'yikes_woo_reusable_products_tabs_applied', $saved_tabs_applied );
211
+ }
212
+
213
+ // Update Post Meta.
214
+ global $wpdb;
215
 
216
+ // Fetch all of the post meta items where meta_key = 'yikes_woo_products_tabs'.
217
+ $yikes_woo_products_tabs = $wpdb->get_results(
218
+ "
219
+ SELECT *
220
+ FROM {$wpdb->postmeta}
221
+ WHERE meta_key = 'yikes_woo_products_tabs'
222
+ "
223
+ );
224
 
225
+ if ( ! empty( $yikes_woo_products_tabs ) ) {
226
 
227
+ foreach ( $yikes_woo_products_tabs as $table_row ) {
228
 
229
+ // Unserialize our tabs.
230
+ $tabs = unserialize( $table_row->meta_value );
231
 
232
+ // If we have tabs...
233
+ if ( ! empty( $tabs ) ) {
234
 
235
+ foreach ( $tabs as &$tab ) {
236
 
237
+ // Set the tab slug ('id') to the sanitized tab's title.
238
+ $tab['id'] = urldecode( sanitize_title( $tab['title'] ) );
239
+ }
240
 
241
+ update_post_meta( $table_row->post_id, 'yikes_woo_products_tabs', $tabs );
242
 
243
+ } else {
244
 
245
+ // In previous versions of the plugin we were leaving some empty arrays. Clean 'em up.
246
+ delete_post_meta( $table_row->post_id, 'yikes_woo_products_tabs' );
 
247
  }
248
  }
 
 
 
249
  }
250
 
251
+ // Set a flag so we don't run this update more than once.
252
+ add_option( 'custom_product_tabs_onesixone_data_update', true );
253
+ }
254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
 
256
+ /**
257
+ * Run our basic plugin setup.
258
+ */
259
+ public function init() {
260
 
261
+ // Default WYSIWYG to 'visual'.
262
+ add_filter( 'wp_default_editor', array( $this, 'yikes_woo_set_editor_to_visual' ), 10, 1 );
 
 
 
 
 
 
 
 
 
263
 
264
+ // i18n.
265
+ add_action( 'plugins_loaded', array( $this, 'yikes_woo_load_plugin_textdomain' ) );
266
 
267
+ // Add settings link to plugin on plugins page.
268
+ add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_plugin_action_links' ), 10, 1 );
269
+ }
270
 
271
+ /**
272
+ * Add a link to the settings page to the plugin's action links
273
+ *
274
+ * @since 1.5
275
+ *
276
+ * @param array $links An array of links passed from the plugin_action_links_{plugin_name} filter.
277
+ *
278
+ * @return array $links The $links array, with our saved tabs page appended.
279
+ */
280
+ public function add_plugin_action_links( $links ) {
281
+ $href = esc_url_raw( add_query_arg( array( 'page' => YIKES_Custom_Product_Tabs_Settings_Page ), admin_url() ) );
282
+ $links[] = '<a href="' . $href . '">Saved Tabs</a>';
283
+ return $links;
284
+ }
285
 
286
+ /**
287
+ * Register the textdomain for proper i18n / l10n.
288
+ */
289
+ public function yikes_woo_load_plugin_textdomain() {
290
+ load_plugin_textdomain(
291
+ 'yikes-inc-easy-custom-woocommerce-product-tabs',
292
+ false,
293
+ YIKES_Custom_Product_Tabs_Path . 'languages/'
294
+ );
295
+ }
 
 
 
 
 
296
 
297
+ /**
298
+ * Default the wp_editor to 'Visual' tab (this helps prevent errors with dynamically generating WYSIWYG)
299
+ *
300
+ * @since 1.5
301
+ *
302
+ * @param string $mode The current mode of the editor.
303
+ *
304
+ * @return string 'tinymce' || $mode
305
+ */
306
+ public function yikes_woo_set_editor_to_visual( $mode ) {
307
+ global $post;
308
+
309
+ // Only continue if we're on the products page.
310
+ if ( isset( $post ) && isset( $post->post_type ) && $post->post_type !== 'product' ) {
311
+ return $mode;
312
  }
313
 
314
+ // This is funky, but only default the editor when we don't have a post (and we're on the product page).
315
+ // This a result of calling the wp_editor via AJAX - I think.
316
+ if ( ! isset( $post ) ) {
317
+ return apply_filters( 'yikes_woocommerce_default_editor_mode', 'tinymce' );
318
+ } else {
319
+ return $mode;
320
+ }
321
  }
322
+ }