Custom Product Tabs for WooCommerce - Version 1.6.7

Version Description

  • December 18th, 2018 =
  • Adding filter to help allow importing of custom tabs.
  • Changing our export filters so custom tabs work with WooCommerce's native meta export/import features.
  • The default capability for all admin pages is now publish_products.
Download this release

Release Info

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

Code changes from version 1.6.6 to 1.6.7

admin/class.export.php CHANGED
@@ -1,32 +1,33 @@
1
  <?php
2
 
 
 
 
3
  class YIKES_Custom_Product_Tabs_Export {
4
 
 
 
 
5
  public function __construct() {
6
-
7
- add_filter( 'woocommerce_product_export_product_default_columns', array( $this, 'add_custom_product_tabs_header_to_product_export' ), 10, 1 );
8
-
9
- add_filter( 'woocommerce_product_export_product_column_yikes_woo_products_tabs', array( $this, 'add_custom_product_tabs_data_to_product_export' ), 10, 3 );
10
  }
11
 
12
- public function add_custom_product_tabs_header_to_product_export( $columns ) {
13
-
14
- if ( apply_filters( 'yikes-woo-do-not-export-tabs', false ) === true ) {
15
- return $columns;
 
 
 
 
 
 
 
 
 
16
  }
17
-
18
- $columns['yikes_woo_products_tabs'] = 'yikes_woo_products_tabs';
19
- return $columns;
20
- }
21
-
22
- public function add_custom_product_tabs_data_to_product_export( $value, $product, $column_id ) {
23
-
24
- $tabs = get_post_meta( $product->get_id(), 'yikes_woo_products_tabs', true );
25
-
26
- $tabs = ! empty( $tabs ) ? serialize( $tabs ) : '';
27
-
28
- return $tabs;
29
  }
30
  }
31
 
32
- new YIKES_Custom_Product_Tabs_Export();
1
  <?php
2
 
3
+ /**
4
+ * Class YIKES_Custom_Product_Tabs_Export.
5
+ */
6
  class YIKES_Custom_Product_Tabs_Export {
7
 
8
+ /**
9
+ * Define our hooks.
10
+ */
11
  public function __construct() {
12
+ add_filter( 'woocommerce_product_export_meta_value', array( $this, 'prep_product_tabs_for_export' ), 10, 4 );
 
 
 
13
  }
14
 
15
+ /**
16
+ * Prep our tabs for an export.
17
+ *
18
+ * @param mixed $meta_value The meta value.
19
+ * @param object $meta The meta field.
20
+ * @param WC_Product $product Product being exported.
21
+ * @param array $row Row data.
22
+ */
23
+ public function prep_product_tabs_for_export( $meta_value, $meta, $product, $row ) {
24
+ if ( isset( $meta->key ) && $meta->key === 'yikes_woo_products_tabs' ) {
25
+ if ( is_array( $meta_value ) ) {
26
+ return serialize( $meta_value );
27
+ }
28
  }
29
+ return $meta_value;
 
 
 
 
 
 
 
 
 
 
 
30
  }
31
  }
32
 
33
+ new YIKES_Custom_Product_Tabs_Export();
admin/class.import.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class YIKES_Custom_Product_Tabs_Import.
5
+ */
6
+ class YIKES_Custom_Product_Tabs_Import {
7
+
8
+ /**
9
+ * Define hooks.
10
+ */
11
+ public function __construct() {
12
+ add_filter( 'woocommerce_product_importer_formatting_callbacks', array( $this, 'remove_wp_kses_posts_callback_from_import' ), 10, 2 );
13
+ }
14
+
15
+ /**
16
+ * When importing our meta field via WooCommerce's native import, replace the wp_kses_post sanitization callback with trim().
17
+ *
18
+ * The wp_kses_post function gets ran on all meta and this breaks some serialized arrays.
19
+ */
20
+ public function remove_wp_kses_posts_callback_from_import( $callbacks, $importer ) {
21
+
22
+ $meta_key = false;
23
+
24
+ // Go through the file's keys and look for our meta field.
25
+ if ( method_exists( $importer, 'get_mapped_keys' ) ) {
26
+ foreach ( $importer->get_mapped_keys() as $key_number => $field_name ) {
27
+ if ( $field_name === 'meta:yikes_woo_products_tabs' ) {
28
+ $meta_key = $key_number;
29
+ break;
30
+ }
31
+ }
32
+ }
33
+
34
+ // Set our meta field's callback to `trim()`.
35
+ if ( $meta_key !== false ) {
36
+ foreach ( $callbacks as $key => $callback ) {
37
+ if ( $key === $meta_key ) {
38
+ $callbacks[ $key ] = 'trim';
39
+ }
40
+ }
41
+ }
42
+
43
+ return $callbacks;
44
+ }
45
+ }
46
+
47
+ new YIKES_Custom_Product_Tabs_Import();
admin/class.yikes-woo-saved-tabs.php CHANGED
@@ -501,7 +501,7 @@ if ( ! class_exists( 'YIKES_Custom_Product_Tabs_Saved_Tabs' ) ) {
501
  add_menu_page(
502
  apply_filters( 'yikes-woo-settings-menu-title', __( 'Custom Product Tabs', 'yikes-inc-easy-custom-woocommerce-product-tabs' ) ), // Tab title name (HTML title)
503
  apply_filters( 'yikes-woo-settings-menu-title', __( 'Custom Product Tabs', 'yikes-inc-easy-custom-woocommerce-product-tabs' ) ), // Menu page name
504
- apply_filters( 'yikes-woo-settings-menu-capability', 'publish_products' ), // Capability required
505
  YIKES_Custom_Product_Tabs_Settings_Page, // Page slug (?page=slug-name)
506
  array( $this, 'generate_yikes_settings_page' ), // Function to generate page
507
  'dashicons-exerpt-view', // Icon
501
  add_menu_page(
502
  apply_filters( 'yikes-woo-settings-menu-title', __( 'Custom Product Tabs', 'yikes-inc-easy-custom-woocommerce-product-tabs' ) ), // Tab title name (HTML title)
503
  apply_filters( 'yikes-woo-settings-menu-title', __( 'Custom Product Tabs', 'yikes-inc-easy-custom-woocommerce-product-tabs' ) ), // Menu page name
504
+ apply_filters( 'yikes-woo-settings-menu-capability', 'publish_products' ), // Capability required
505
  YIKES_Custom_Product_Tabs_Settings_Page, // Page slug (?page=slug-name)
506
  array( $this, 'generate_yikes_settings_page' ), // Function to generate page
507
  'dashicons-exerpt-view', // Icon
admin/page.yikes-woo-saved-tabs.php CHANGED
@@ -83,20 +83,23 @@
83
  </tr>
84
  </tfoot>
85
 
86
- <tbody>
87
  <?php
88
  if( ! empty( $yikes_custom_tab_data ) ) {
89
 
 
 
 
90
  foreach ( $yikes_custom_tab_data as $key => $tab_data ) {
91
 
92
- // Set variables before using them
93
  $tab_title = isset( $tab_data['tab_title'] ) && ! empty( $tab_data['tab_title'] ) ? $tab_data['tab_title'] : '';
94
  $tab_name = isset( $tab_data['tab_name'] ) ? $tab_data['tab_name'] : '';
95
  $tab_content_excerpt = isset( $tab_data['tab_content'] ) && ! empty( $tab_data['tab_content'] ) ? stripslashes( substr( wp_strip_all_tags( $tab_data['tab_content'] ), 0, 150 ) ) : '';
96
  $tab_id = isset( $tab_data['tab_id'] ) && ! empty( $tab_data['tab_id'] ) ? (int) $tab_data['tab_id'] : 0;
97
  $edit_tab_url = esc_url_raw( add_query_arg( array( 'page' => YIKES_Custom_Product_Tabs_Settings_Page, 'saved-tab-id' => $tab_id ), admin_url() ) );
98
  ?>
99
- <tr class="yikes_woo_saved_tabs_row" id="yikes_woo_saved_tabs_row_<?php echo $tab_id; ?>" data-tab-id="<?php echo $tab_id; ?>">
100
  <th class="check-column" scope="row">
101
  <input class="entry-bulk-action-checkbox" type="checkbox" value="<?php echo $tab_id; ?>" />
102
  </th>
@@ -121,6 +124,7 @@
121
  </td>
122
  </tr>
123
  <?php
 
124
  }
125
  } else {
126
  ?>
83
  </tr>
84
  </tfoot>
85
 
86
+ <tbody id="yikes-woo-saved-tabs-list-table">
87
  <?php
88
  if( ! empty( $yikes_custom_tab_data ) ) {
89
 
90
+ $yikes_custom_tab_data = apply_filters( 'yikes_woo_reorder_saved_tabs', $yikes_custom_tab_data );
91
+ $tab_order = 1;
92
+
93
  foreach ( $yikes_custom_tab_data as $key => $tab_data ) {
94
 
95
+ // Set variables before using them.
96
  $tab_title = isset( $tab_data['tab_title'] ) && ! empty( $tab_data['tab_title'] ) ? $tab_data['tab_title'] : '';
97
  $tab_name = isset( $tab_data['tab_name'] ) ? $tab_data['tab_name'] : '';
98
  $tab_content_excerpt = isset( $tab_data['tab_content'] ) && ! empty( $tab_data['tab_content'] ) ? stripslashes( substr( wp_strip_all_tags( $tab_data['tab_content'] ), 0, 150 ) ) : '';
99
  $tab_id = isset( $tab_data['tab_id'] ) && ! empty( $tab_data['tab_id'] ) ? (int) $tab_data['tab_id'] : 0;
100
  $edit_tab_url = esc_url_raw( add_query_arg( array( 'page' => YIKES_Custom_Product_Tabs_Settings_Page, 'saved-tab-id' => $tab_id ), admin_url() ) );
101
  ?>
102
+ <tr class="yikes_woo_saved_tabs_row" id="yikes_woo_saved_tabs_row_<?php echo $tab_id; ?>" data-tab-id="<?php echo $tab_id; ?>" data-order="<?php echo esc_attr( $tab_order ); ?>">
103
  <th class="check-column" scope="row">
104
  <input class="entry-bulk-action-checkbox" type="checkbox" value="<?php echo $tab_id; ?>" />
105
  </th>
124
  </td>
125
  </tr>
126
  <?php
127
+ $tab_order++;
128
  }
129
  } else {
130
  ?>
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: yikesinc, eherman24, liljimmi, yikesitskevin, metalandcoffee, mial
3
  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: 4.9.8
7
- Stable tag: 1.6.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -75,6 +75,11 @@ Yes! Since v1.4 we've added the necessary code to ensure the custom tab data is
75
 
76
  == Changelog ==
77
 
 
 
 
 
 
78
  = 1.6.6 - October 26th, 2018 =
79
  * Bumping WooCo Compatibility.
80
  * Changed `wp_send_json_failure()` to `wp_send_json_error()`.
3
  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
 
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.
81
+ * The default capability for all admin pages is now `publish_products`.
82
+
83
  = 1.6.6 - October 26th, 2018 =
84
  * Bumping WooCo Compatibility.
85
  * Changed `wp_send_json_failure()` to `wp_send_json_error()`.
yikes-inc-easy-custom-woocommerce-product-tabs.php CHANGED
@@ -5,7 +5,7 @@
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.6
9
  * Text Domain: yikes-inc-easy-custom-woocommerce-product-tabs
10
  * Domain Path: languages/
11
  *
@@ -78,6 +78,7 @@
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
 
82
  add_action( 'admin_init', array( $this, 'init' ) );
83
  }
@@ -107,7 +108,7 @@
107
  * Define the plugin's version
108
  */
109
  if ( ! defined( 'YIKES_Custom_Product_Tabs_Version' ) ) {
110
- define( 'YIKES_Custom_Product_Tabs_Version', '1.6.6' );
111
  }
112
 
113
  /**
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
  *
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
  }
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
  /**