Skip to content

Commit 38414e7

Browse files
author
Woo
committed
Updates to 1.16.0
1 parent da88b6b commit 38414e7

File tree

75 files changed

+27291
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+27291
-0
lines changed

admin/post-types/wc_product_tab.php

Lines changed: 471 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
<?php
2+
/**
3+
* WooCommerce Tab Manager
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 [email protected] 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 Tab Manager to newer
16+
* versions in the future. If you wish to customize WooCommerce Tab Manager for your
17+
* needs please refer to http://docs.woocommerce.com/document/tab-manager/
18+
*
19+
* @author SkyVerge
20+
* @copyright Copyright (c) 2012-2023, SkyVerge, Inc. ([email protected])
21+
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
22+
*/
23+
24+
defined( 'ABSPATH' ) or exit;
25+
26+
use SkyVerge\WooCommerce\PluginFramework\v5_11_0 as Framework;
27+
28+
function wc_tab_manager_add_metabox() {
29+
new \WC_Tab_Manager_Categories_Metabox();
30+
}
31+
32+
if ( is_admin() ) {
33+
add_action( 'load-post.php', 'wc_tab_manager_add_metabox' );
34+
add_action( 'load-post-new.php', 'wc_tab_manager_add_metabox' );
35+
}
36+
37+
38+
/**
39+
* Tab Manager Product Categories selector metabox
40+
*
41+
* @since 1.7.0
42+
*/
43+
class WC_Tab_Manager_Categories_Metabox {
44+
45+
/**
46+
* WC_Tab_Manager_Categories_Metabox constructor
47+
*
48+
* @since 1.7.0
49+
*/
50+
public function __construct() {
51+
add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ), 100 );
52+
add_action( 'save_post', array( $this, 'save' ) );
53+
}
54+
55+
56+
/**
57+
* Adds the meta box container
58+
*
59+
* @since 1.7.0
60+
*/
61+
public function add_meta_box() {
62+
63+
add_meta_box(
64+
'tab_categories',
65+
__( 'Product Categories', 'textdomain' ),
66+
array( $this, 'render_meta_box_content' ),
67+
'wc_product_tab',
68+
'side',
69+
'default'
70+
);
71+
}
72+
73+
74+
/**
75+
* Save the meta when the post is saved
76+
*
77+
* @since 1.7.0
78+
* @param int $post_id The ID of the post being saved
79+
*/
80+
public function save( $post_id ) {
81+
82+
// check if our nonce is set
83+
if ( ! isset( $_POST['wc_tab_manager_metabox_nonce'] ) ) {
84+
return;
85+
}
86+
87+
$nonce = $_POST['wc_tab_manager_metabox_nonce'];
88+
89+
// verify that the nonce is valid
90+
if ( ! wp_verify_nonce( $nonce, 'wc_tab_manager_metabox' ) ) {
91+
return;
92+
}
93+
94+
// if this is an autosave, we don't want to do anything
95+
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
96+
return;
97+
}
98+
99+
// check the user's permissions
100+
if ( isset( $_POST['post_type'] ) && 'wc_product_tab' === $_POST['post_type'] && ! current_user_can( 'edit_post', $post_id ) ) {
101+
return;
102+
}
103+
104+
if ( ! empty( $_POST['_wc_tab_categories'] ) ) {
105+
106+
// sanitize the user input & update the meta field
107+
$product_cats = sanitize_meta( '_wc_tab_categories', $_POST['_wc_tab_categories'], 'post' );
108+
109+
update_post_meta( $post_id, '_wc_tab_categories', $product_cats );
110+
111+
} else {
112+
113+
delete_post_meta( $post_id, '_wc_tab_categories' );
114+
}
115+
}
116+
117+
118+
/**
119+
* Render Meta Box content
120+
*
121+
* @since 1.7.0
122+
* @param \WP_Post $post The post object
123+
*/
124+
public function render_meta_box_content( $post ) {
125+
126+
// show a notice on a product tab
127+
if ( $post->post_parent ) {
128+
?><p><?php esc_html_e( 'Product-level tabs will always be shown on their assigned product.', 'woocommerce-tab-manager' ); ?></p><?php
129+
return;
130+
}
131+
132+
// add an nonce field so we can check for it later.
133+
wp_nonce_field( 'wc_tab_manager_metabox', 'wc_tab_manager_metabox_nonce' );
134+
135+
// display the form, using the current values
136+
?>
137+
<p class="form-field"><label for="product_categories"><?php _e( 'Product Categories', 'woocommerce-tab-manager' ); ?></label>
138+
139+
<?php echo wc_help_tip( __( 'Select categories to restrict the display of this tab to certain products.', 'woocommerce-tab-manager' ) ); ?>
140+
141+
<select
142+
id="_wc_tab_categories"
143+
name="_wc_tab_categories[]"
144+
style="width: 75%;"
145+
class="wc-enhanced-select"
146+
multiple="multiple"
147+
data-placeholder="<?php esc_attr_e( 'Any category', 'woocommerce-tab-manager' ); ?>">
148+
<?php $category_ids = (array) get_post_meta( $post->ID, '_wc_tab_categories', true ); ?>
149+
<?php $categories = get_terms( 'product_cat', 'orderby=name&hide_empty=0' ); ?>
150+
<?php if ( is_array( $categories ) ) : ?>
151+
<?php foreach ( $categories as $cat ) : ?>
152+
<option value="<?php echo esc_attr( $cat->term_id ); ?>" <?php selected( in_array( $cat->term_id, $category_ids, false ), true, true ); ?>><?php echo esc_html( $cat->name ); ?></option>
153+
<?php endforeach; ?>
154+
<?php endif; ?>
155+
</select>
156+
</p>
157+
<?php
158+
}
159+
160+
161+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* WooCommerce Tab Manager
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 [email protected] 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 Tab Manager to newer
16+
* versions in the future. If you wish to customize WooCommerce Tab Manager for your
17+
* needs please refer to http://docs.woocommerce.com/document/tab-manager/
18+
*
19+
* @author SkyVerge
20+
* @copyright Copyright (c) 2012-2023, SkyVerge, Inc. ([email protected])
21+
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
22+
*/
23+
24+
/**
25+
* Tab Manager Tab Actions panel
26+
*
27+
* Functions for displaying the Tab Manager Tab Actions panel on the Edit Tab page
28+
*/
29+
30+
defined( 'ABSPATH' ) or exit;
31+
32+
use SkyVerge\WooCommerce\PluginFramework\v5_11_0 as Framework;
33+
34+
35+
/**
36+
* Display the product tab actions meta box.
37+
*
38+
* Displays the product actions meta box - buttons for creating and deleting the tab
39+
*
40+
* @access public
41+
* @param object $post product post object
42+
*/
43+
function wc_tab_manager_product_tab_actions_meta_box( $post ) {
44+
?>
45+
<style type="text/css">
46+
#edit-slug-box, #major-publishing-actions, #minor-publishing-actions, #visibility, #submitdiv { display:none }
47+
</style>
48+
49+
<ul class="wc_product_tab_actions">
50+
<?php wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' ); ?>
51+
52+
<?php do_action( 'woocommerce_tab_manager_product_tab_actions_top', $post ); ?>
53+
54+
<li class="wide">
55+
<input type="submit" class="button button-primary tips" name="publish" value="<?php esc_attr_e( 'Save Tab', 'woocommerce-tab-manager' ); ?>" data-tip="<?php esc_attr_e( 'Save/update the tab', 'woocommerce-tab-manager' ); ?>" />
56+
</li>
57+
58+
<?php do_action( 'woocommerce_tab_manager_product_tab_actions', $post->ID ); ?>
59+
<?php do_action( 'woocommerce_tab_manager_product_tab_actions_bottom', $post ); ?>
60+
61+
<?php if ( current_user_can( 'delete_post', $post->ID ) ) : ?>
62+
<li class="wide">
63+
<?php
64+
if ( ! EMPTY_TRASH_DAYS ) {
65+
$delete_text = __( 'Delete Permanently', 'woocommerce-tab-manager' );
66+
} else {
67+
$delete_text = __( 'Move to Trash', 'woocommerce-tab-manager' );
68+
}
69+
?>
70+
<a class="submitdelete deletion" href="<?php echo esc_url( get_delete_post_link( $post->ID ) ); ?>"><?php echo esc_attr( $delete_text ); ?></a>
71+
</li>
72+
<?php endif; ?>
73+
</ul>
74+
<?php
75+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
/**
3+
* WooCommerce Tab Manager
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 [email protected] 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 Tab Manager to newer
16+
* versions in the future. If you wish to customize WooCommerce Tab Manager for your
17+
* needs please refer to http://docs.woocommerce.com/document/tab-manager/
18+
*
19+
* @author SkyVerge
20+
* @copyright Copyright (c) 2012-2023, SkyVerge, Inc. ([email protected])
21+
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
22+
*/
23+
24+
/**
25+
* Tab Manager Product Data Panel - Tabs tab
26+
*
27+
* Functions for displaying the Tab Manager product data panel Tabs tab
28+
*/
29+
30+
defined( 'ABSPATH' ) or exit;
31+
32+
use SkyVerge\WooCommerce\PluginFramework\v5_11_0 as Framework;
33+
34+
35+
add_action( 'woocommerce_product_write_panel_tabs', 'wc_tab_manager_product_tabs_panel_tab' );
36+
37+
/**
38+
* Adds the "Tabs" tab to the Product Data postbox in the admin product interface
39+
* @access public
40+
*/
41+
function wc_tab_manager_product_tabs_panel_tab() {
42+
echo '<li class="product_tabs_tab"><a href="#woocommerce_product_tabs"><span>' . esc_html__( 'Tabs', 'woocommerce-tab-manager' ) . '</span></a></li>';
43+
}
44+
45+
46+
add_action( 'woocommerce_product_data_panels', 'wc_tab_manager_product_tabs_panel_content' );
47+
48+
/**
49+
* Adds the "Tabs" tab panel to the Product Data postbox in the product interface.
50+
*/
51+
function wc_tab_manager_product_tabs_panel_content() {
52+
global $post;
53+
54+
wc_tab_manager_sortable_product_tabs( get_post_meta( $post->ID, '_product_tabs', true ) );
55+
}
56+
57+
58+
add_action( 'woocommerce_process_product_meta', 'wc_tab_manager_process_product_meta_tabs_tab', 10, 2 );
59+
60+
/**
61+
* Create/Update/Delete the product tabs
62+
*
63+
* @access public
64+
* @param int $post_id the post identifier
65+
* @param \WP_Post $post the post object
66+
*/
67+
function wc_tab_manager_process_product_meta_tabs_tab( $post_id, $post ) {
68+
69+
$new_tabs = wc_tab_manager_process_tabs( $post_id, $post );
70+
71+
$old_tabs = get_post_meta( $post_id, '_product_tabs', true );
72+
73+
if ( ! is_array( $old_tabs ) ) {
74+
$old_tabs = array();
75+
}
76+
77+
update_post_meta( $post_id, '_product_tabs', $new_tabs );
78+
79+
do_action( 'wc_tab_manager_product_tabs_updated', $new_tabs, $old_tabs );
80+
81+
// Whether the tab layout defined at the product level should be used.
82+
$override_tab_layout = isset( $_POST['_override_tab_layout'] ) && $_POST['_override_tab_layout'] ? 'yes' : 'no';
83+
84+
update_post_meta( $post_id, '_override_tab_layout', $override_tab_layout );
85+
86+
// Update / remove tab content meta.
87+
$args = array(
88+
'product_id' => $post_id,
89+
);
90+
91+
if ( 'yes' === $override_tab_layout ) {
92+
$args['action'] = 'update';
93+
} else {
94+
$args['action'] = 'remove';
95+
}
96+
97+
// Extract product & global tab IDs from tab data array.
98+
$tab_id_list = array();
99+
foreach ( $new_tabs as $key => $tab ) {
100+
if ( 'product' === $tab['type'] || 'global' === $tab['type'] ) {
101+
$tab_id_list[] = $tab['id'];
102+
}
103+
}
104+
105+
// Only update meta if we have any tabs to process.
106+
if ( ! empty( $tab_id_list ) ) {
107+
wc_tab_manager()->get_search_instance()->update_products_for_tabs( $tab_id_list, $args );
108+
}
109+
}

0 commit comments

Comments
 (0)