-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Woo
committed
Apr 23, 2024
1 parent
da88b6b
commit 38414e7
Showing
75 changed files
with
27,291 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
<?php | ||
/** | ||
* WooCommerce Tab Manager | ||
* | ||
* This source file is subject to the GNU General Public License v3.0 | ||
* that is bundled with this package in the file license.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://www.gnu.org/licenses/gpl-3.0.html | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@skyverge.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade WooCommerce Tab Manager to newer | ||
* versions in the future. If you wish to customize WooCommerce Tab Manager for your | ||
* needs please refer to http://docs.woocommerce.com/document/tab-manager/ | ||
* | ||
* @author SkyVerge | ||
* @copyright Copyright (c) 2012-2023, SkyVerge, Inc. (info@skyverge.com) | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 | ||
*/ | ||
|
||
defined( 'ABSPATH' ) or exit; | ||
|
||
use SkyVerge\WooCommerce\PluginFramework\v5_11_0 as Framework; | ||
|
||
function wc_tab_manager_add_metabox() { | ||
new \WC_Tab_Manager_Categories_Metabox(); | ||
} | ||
|
||
if ( is_admin() ) { | ||
add_action( 'load-post.php', 'wc_tab_manager_add_metabox' ); | ||
add_action( 'load-post-new.php', 'wc_tab_manager_add_metabox' ); | ||
} | ||
|
||
|
||
/** | ||
* Tab Manager Product Categories selector metabox | ||
* | ||
* @since 1.7.0 | ||
*/ | ||
class WC_Tab_Manager_Categories_Metabox { | ||
|
||
/** | ||
* WC_Tab_Manager_Categories_Metabox constructor | ||
* | ||
* @since 1.7.0 | ||
*/ | ||
public function __construct() { | ||
add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ), 100 ); | ||
add_action( 'save_post', array( $this, 'save' ) ); | ||
} | ||
|
||
|
||
/** | ||
* Adds the meta box container | ||
* | ||
* @since 1.7.0 | ||
*/ | ||
public function add_meta_box() { | ||
|
||
add_meta_box( | ||
'tab_categories', | ||
__( 'Product Categories', 'textdomain' ), | ||
array( $this, 'render_meta_box_content' ), | ||
'wc_product_tab', | ||
'side', | ||
'default' | ||
); | ||
} | ||
|
||
|
||
/** | ||
* Save the meta when the post is saved | ||
* | ||
* @since 1.7.0 | ||
* @param int $post_id The ID of the post being saved | ||
*/ | ||
public function save( $post_id ) { | ||
|
||
// check if our nonce is set | ||
if ( ! isset( $_POST['wc_tab_manager_metabox_nonce'] ) ) { | ||
return; | ||
} | ||
|
||
$nonce = $_POST['wc_tab_manager_metabox_nonce']; | ||
|
||
// verify that the nonce is valid | ||
if ( ! wp_verify_nonce( $nonce, 'wc_tab_manager_metabox' ) ) { | ||
return; | ||
} | ||
|
||
// if this is an autosave, we don't want to do anything | ||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { | ||
return; | ||
} | ||
|
||
// check the user's permissions | ||
if ( isset( $_POST['post_type'] ) && 'wc_product_tab' === $_POST['post_type'] && ! current_user_can( 'edit_post', $post_id ) ) { | ||
return; | ||
} | ||
|
||
if ( ! empty( $_POST['_wc_tab_categories'] ) ) { | ||
|
||
// sanitize the user input & update the meta field | ||
$product_cats = sanitize_meta( '_wc_tab_categories', $_POST['_wc_tab_categories'], 'post' ); | ||
|
||
update_post_meta( $post_id, '_wc_tab_categories', $product_cats ); | ||
|
||
} else { | ||
|
||
delete_post_meta( $post_id, '_wc_tab_categories' ); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Render Meta Box content | ||
* | ||
* @since 1.7.0 | ||
* @param \WP_Post $post The post object | ||
*/ | ||
public function render_meta_box_content( $post ) { | ||
|
||
// show a notice on a product tab | ||
if ( $post->post_parent ) { | ||
?><p><?php esc_html_e( 'Product-level tabs will always be shown on their assigned product.', 'woocommerce-tab-manager' ); ?></p><?php | ||
return; | ||
} | ||
|
||
// add an nonce field so we can check for it later. | ||
wp_nonce_field( 'wc_tab_manager_metabox', 'wc_tab_manager_metabox_nonce' ); | ||
|
||
// display the form, using the current values | ||
?> | ||
<p class="form-field"><label for="product_categories"><?php _e( 'Product Categories', 'woocommerce-tab-manager' ); ?></label> | ||
|
||
<?php echo wc_help_tip( __( 'Select categories to restrict the display of this tab to certain products.', 'woocommerce-tab-manager' ) ); ?> | ||
|
||
<select | ||
id="_wc_tab_categories" | ||
name="_wc_tab_categories[]" | ||
style="width: 75%;" | ||
class="wc-enhanced-select" | ||
multiple="multiple" | ||
data-placeholder="<?php esc_attr_e( 'Any category', 'woocommerce-tab-manager' ); ?>"> | ||
<?php $category_ids = (array) get_post_meta( $post->ID, '_wc_tab_categories', true ); ?> | ||
<?php $categories = get_terms( 'product_cat', 'orderby=name&hide_empty=0' ); ?> | ||
<?php if ( is_array( $categories ) ) : ?> | ||
<?php foreach ( $categories as $cat ) : ?> | ||
<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> | ||
<?php endforeach; ?> | ||
<?php endif; ?> | ||
</select> | ||
</p> | ||
<?php | ||
} | ||
|
||
|
||
} |
75 changes: 75 additions & 0 deletions
75
admin/post-types/writepanels/writepanel-product-tab_actions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* WooCommerce Tab Manager | ||
* | ||
* This source file is subject to the GNU General Public License v3.0 | ||
* that is bundled with this package in the file license.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://www.gnu.org/licenses/gpl-3.0.html | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@skyverge.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade WooCommerce Tab Manager to newer | ||
* versions in the future. If you wish to customize WooCommerce Tab Manager for your | ||
* needs please refer to http://docs.woocommerce.com/document/tab-manager/ | ||
* | ||
* @author SkyVerge | ||
* @copyright Copyright (c) 2012-2023, SkyVerge, Inc. (info@skyverge.com) | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 | ||
*/ | ||
|
||
/** | ||
* Tab Manager Tab Actions panel | ||
* | ||
* Functions for displaying the Tab Manager Tab Actions panel on the Edit Tab page | ||
*/ | ||
|
||
defined( 'ABSPATH' ) or exit; | ||
|
||
use SkyVerge\WooCommerce\PluginFramework\v5_11_0 as Framework; | ||
|
||
|
||
/** | ||
* Display the product tab actions meta box. | ||
* | ||
* Displays the product actions meta box - buttons for creating and deleting the tab | ||
* | ||
* @access public | ||
* @param object $post product post object | ||
*/ | ||
function wc_tab_manager_product_tab_actions_meta_box( $post ) { | ||
?> | ||
<style type="text/css"> | ||
#edit-slug-box, #major-publishing-actions, #minor-publishing-actions, #visibility, #submitdiv { display:none } | ||
</style> | ||
|
||
<ul class="wc_product_tab_actions"> | ||
<?php wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' ); ?> | ||
|
||
<?php do_action( 'woocommerce_tab_manager_product_tab_actions_top', $post ); ?> | ||
|
||
<li class="wide"> | ||
<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' ); ?>" /> | ||
</li> | ||
|
||
<?php do_action( 'woocommerce_tab_manager_product_tab_actions', $post->ID ); ?> | ||
<?php do_action( 'woocommerce_tab_manager_product_tab_actions_bottom', $post ); ?> | ||
|
||
<?php if ( current_user_can( 'delete_post', $post->ID ) ) : ?> | ||
<li class="wide"> | ||
<?php | ||
if ( ! EMPTY_TRASH_DAYS ) { | ||
$delete_text = __( 'Delete Permanently', 'woocommerce-tab-manager' ); | ||
} else { | ||
$delete_text = __( 'Move to Trash', 'woocommerce-tab-manager' ); | ||
} | ||
?> | ||
<a class="submitdelete deletion" href="<?php echo esc_url( get_delete_post_link( $post->ID ) ); ?>"><?php echo esc_attr( $delete_text ); ?></a> | ||
</li> | ||
<?php endif; ?> | ||
</ul> | ||
<?php | ||
} |
109 changes: 109 additions & 0 deletions
109
admin/post-types/writepanels/writepanel-product_data-tabs.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
/** | ||
* WooCommerce Tab Manager | ||
* | ||
* This source file is subject to the GNU General Public License v3.0 | ||
* that is bundled with this package in the file license.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://www.gnu.org/licenses/gpl-3.0.html | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@skyverge.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade WooCommerce Tab Manager to newer | ||
* versions in the future. If you wish to customize WooCommerce Tab Manager for your | ||
* needs please refer to http://docs.woocommerce.com/document/tab-manager/ | ||
* | ||
* @author SkyVerge | ||
* @copyright Copyright (c) 2012-2023, SkyVerge, Inc. (info@skyverge.com) | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 | ||
*/ | ||
|
||
/** | ||
* Tab Manager Product Data Panel - Tabs tab | ||
* | ||
* Functions for displaying the Tab Manager product data panel Tabs tab | ||
*/ | ||
|
||
defined( 'ABSPATH' ) or exit; | ||
|
||
use SkyVerge\WooCommerce\PluginFramework\v5_11_0 as Framework; | ||
|
||
|
||
add_action( 'woocommerce_product_write_panel_tabs', 'wc_tab_manager_product_tabs_panel_tab' ); | ||
|
||
/** | ||
* Adds the "Tabs" tab to the Product Data postbox in the admin product interface | ||
* @access public | ||
*/ | ||
function wc_tab_manager_product_tabs_panel_tab() { | ||
echo '<li class="product_tabs_tab"><a href="#woocommerce_product_tabs"><span>' . esc_html__( 'Tabs', 'woocommerce-tab-manager' ) . '</span></a></li>'; | ||
} | ||
|
||
|
||
add_action( 'woocommerce_product_data_panels', 'wc_tab_manager_product_tabs_panel_content' ); | ||
|
||
/** | ||
* Adds the "Tabs" tab panel to the Product Data postbox in the product interface. | ||
*/ | ||
function wc_tab_manager_product_tabs_panel_content() { | ||
global $post; | ||
|
||
wc_tab_manager_sortable_product_tabs( get_post_meta( $post->ID, '_product_tabs', true ) ); | ||
} | ||
|
||
|
||
add_action( 'woocommerce_process_product_meta', 'wc_tab_manager_process_product_meta_tabs_tab', 10, 2 ); | ||
|
||
/** | ||
* Create/Update/Delete the product tabs | ||
* | ||
* @access public | ||
* @param int $post_id the post identifier | ||
* @param \WP_Post $post the post object | ||
*/ | ||
function wc_tab_manager_process_product_meta_tabs_tab( $post_id, $post ) { | ||
|
||
$new_tabs = wc_tab_manager_process_tabs( $post_id, $post ); | ||
|
||
$old_tabs = get_post_meta( $post_id, '_product_tabs', true ); | ||
|
||
if ( ! is_array( $old_tabs ) ) { | ||
$old_tabs = array(); | ||
} | ||
|
||
update_post_meta( $post_id, '_product_tabs', $new_tabs ); | ||
|
||
do_action( 'wc_tab_manager_product_tabs_updated', $new_tabs, $old_tabs ); | ||
|
||
// Whether the tab layout defined at the product level should be used. | ||
$override_tab_layout = isset( $_POST['_override_tab_layout'] ) && $_POST['_override_tab_layout'] ? 'yes' : 'no'; | ||
|
||
update_post_meta( $post_id, '_override_tab_layout', $override_tab_layout ); | ||
|
||
// Update / remove tab content meta. | ||
$args = array( | ||
'product_id' => $post_id, | ||
); | ||
|
||
if ( 'yes' === $override_tab_layout ) { | ||
$args['action'] = 'update'; | ||
} else { | ||
$args['action'] = 'remove'; | ||
} | ||
|
||
// Extract product & global tab IDs from tab data array. | ||
$tab_id_list = array(); | ||
foreach ( $new_tabs as $key => $tab ) { | ||
if ( 'product' === $tab['type'] || 'global' === $tab['type'] ) { | ||
$tab_id_list[] = $tab['id']; | ||
} | ||
} | ||
|
||
// Only update meta if we have any tabs to process. | ||
if ( ! empty( $tab_id_list ) ) { | ||
wc_tab_manager()->get_search_instance()->update_products_for_tabs( $tab_id_list, $args ); | ||
} | ||
} |
Oops, something went wrong.