Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Settings navigation tabs on Product Sets taxonomy screens #2814

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion class-wc-facebookcommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public function register_custom_taxonomy() {
// translators: No items found text
'not_found' => sprintf( esc_html__( 'No %s found.', 'facebook-for-woocommerce' ), $plural ),
// translators: Search label
'search_items' => sprintf( esc_html__( 'Search %s.', 'facebook-for-woocommerce' ), $plural ),
'search_items' => sprintf( esc_html__( 'Search %s', 'facebook-for-woocommerce' ), $plural ),
// translators: Text label
'separate_items_with_commas' => sprintf( esc_html__( 'Separate %s with commas', 'facebook-for-woocommerce' ), $plural ),
// translators: Text label
Expand Down
96 changes: 84 additions & 12 deletions includes/Admin/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use WooCommerce\Facebook\Admin\Settings_Screens;
use WooCommerce\Facebook\Admin\Settings_Screens\Connection;
use WooCommerce\Facebook\Framework\Helper;
use WooCommerce\Facebook\Framework\Plugin\Compatibility;
use WooCommerce\Facebook\Framework\Plugin\Exception as PluginException;

defined( 'ABSPATH' ) || exit;
Expand Down Expand Up @@ -52,6 +51,8 @@ public function __construct( bool $is_connected ) {
add_action( 'admin_menu', array( $this, 'add_menu_item' ) );
add_action( 'wp_loaded', array( $this, 'save' ) );
add_filter( 'parent_file', array( $this, 'set_parent_and_submenu_file' ) );

add_action( 'all_admin_notices', array( $this, 'add_tabs_to_product_sets_taxonomy' ) );
}

/**
Expand Down Expand Up @@ -191,19 +192,11 @@ private function connect_to_enhanced_admin( $screen_id ) {
* @since 2.0.0
*/
public function render() {
$tabs = $this->get_tabs();
$current_tab = Helper::get_requested_value( 'tab' );
if ( ! $current_tab ) {
$current_tab = current( array_keys( $tabs ) );
}
$screen = $this->get_screen( $current_tab );
$current_tab = $this->get_current_tab();
$screen = $this->get_screen( $current_tab );
?>
<div class="wrap woocommerce">
<nav class="nav-tab-wrapper woo-nav-tab-wrapper">
<?php foreach ( $tabs as $id => $label ) : ?>
<a href="<?php echo esc_html( admin_url( 'admin.php?page=' . self::PAGE_ID . '&tab=' . esc_attr( $id ) ) ); ?>" class="nav-tab <?php echo $current_tab === $id ? 'nav-tab-active' : ''; ?>"><?php echo esc_html( $label ); ?></a>
<?php endforeach; ?>
</nav>
<?php $this->render_tabs( $current_tab ); ?>
<?php facebook_for_woocommerce()->get_message_handler()->show_messages(); ?>
<?php if ( $screen ) : ?>
<h1 class="screen-reader-text"><?php echo esc_html( $screen->get_title() ); ?></h1>
Expand All @@ -214,6 +207,40 @@ public function render() {
<?php
}

/**
* Render the Facebook for WooCommerce extension navigation tabs.
*
* @since 3.3.0
*
* @param string $current_tab The current tab ID.
*/
public function render_tabs( $current_tab ) {
$tabs = $this->get_tabs();
?>
<nav class="nav-tab-wrapper woo-nav-tab-wrapper facebook-for-woocommerce-tabs">
<?php foreach ( $tabs as $id => $label ) : ?>
<a href="<?php echo esc_html( admin_url( 'admin.php?page=' . self::PAGE_ID . '&tab=' . esc_attr( $id ) ) ); ?>" class="nav-tab <?php echo $current_tab === $id ? 'nav-tab-active' : ''; ?>"><?php echo esc_html( $label ); ?></a>
<?php endforeach; ?>
</nav>
<?php
}

/**
* Get the current tab ID.
*
* @since 3.3.0
*
* @return string
*/
protected function get_current_tab() {
$tabs = $this->get_tabs();
$current_tab = Helper::get_requested_value( 'tab' );
if ( ! $current_tab ) {
$current_tab = current( array_keys( $tabs ) );
}
return $current_tab;
}


/**
* Saves the settings page.
Expand Down Expand Up @@ -312,4 +339,49 @@ public function get_tabs() {
*/
return (array) apply_filters( 'wc_facebook_admin_settings_tabs', $tabs, $this );
}

/**
* Add the Facebook for WooCommerce tabs to the Facebook Product Set taxonomy page.
* Renders the tabs (hidden by default) at the stop of the page,
* then moves them to the correct DOM location with JavaScript and displays them.
*
* @since 3.3.0
*/
public function add_tabs_to_product_sets_taxonomy() {

// Only load this on the edit-tags.php page
$screen = get_current_screen();
$is_taxonomy_list_page = 'edit-tags' === $screen->base;
$is_taxonomy_term_page = 'term' === $screen->base;
$is_taxonomy_page = $is_taxonomy_list_page || $is_taxonomy_term_page;
$is_product_set_taxonomy = 'fb_product_set' === $screen->taxonomy && $is_taxonomy_page;

if ( $is_product_set_taxonomy ) {
$this->render_tabs( Settings_Screens\Product_Sets::ID );
?>
<style>
.facebook-for-woocommerce-tabs {
margin: 30px 20px 0 20px;
}
#wpbody-content > .wrap > h1 {
font-size: 1.3em;
font-weight: 600;
}

@media (max-width: 782px) {
.facebook-for-woocommerce-tabs {
padding-top: 19px;
margin-bottom: -1px;
}
.edit-tags-php .facebook-for-woocommerce-tabs {
clear: both;
padding-top: 0;
position: relative;
top: -10px;
margin-bottom: -11px;
}
</style>
<?php
}
}
}
Loading