*/ public function add_tab( mixed $tabs ): array { $tabs = is_array( $tabs ) ? $tabs : array(); $tabs['pnscripts_product_tabs'] = array( 'label' => __( 'Custom tabs', 'pnscripts-tabcrest' ), 'target' => 'pnscripts_product_tabs_panel', 'class' => array(), 'priority' => 75, ); return $tabs; } /** * Scripts on the product edit screen only. * * @param string $hook_suffix Admin page. */ public function enqueue( string $hook_suffix ): void { if ( ! in_array( $hook_suffix, array( 'post.php', 'post-new.php' ), true ) ) { return; } $screen = get_current_screen(); if ( null === $screen || 'product' !== $screen->post_type ) { return; } wp_enqueue_editor(); wp_enqueue_style( 'pnscripts-product-tabs-admin', PNSCRIPTS_PRODUCT_TABS_URL . 'assets/css/admin.css', array(), PNSCRIPTS_PRODUCT_TABS_VERSION ); wp_enqueue_script( 'pnscripts-product-tabs-product', PNSCRIPTS_PRODUCT_TABS_URL . 'assets/js/admin-product.js', array( 'jquery', 'jquery-ui-sortable', 'editor' ), PNSCRIPTS_PRODUCT_TABS_VERSION, true ); wp_localize_script( 'pnscripts-product-tabs-product', 'pnscriptsProductTabs', array( 'confirmRemove' => __( 'Remove this tab? It is deleted when you update the product.', 'pnscripts-tabcrest' ), 'untitled' => __( '(no title)', 'pnscripts-tabcrest' ), ) ); } /** * Panel markup. */ public function render_panel(): void { global $post; $product_id = $post instanceof \WP_Post ? (int) $post->ID : 0; $tabs = $product_id > 0 ? $this->product_tabs->tabs( $product_id ) : array(); $globals = $this->all_globals(); $hidden_g = $product_id > 0 ? $this->product_tabs->hidden_globals( $product_id ) : array(); $hidden_d = $product_id > 0 ? $this->product_tabs->hidden_defaults( $product_id ) : array(); $linked = array(); foreach ( $tabs as $tab ) { if ( TabSanitizer::TYPE_GLOBAL === $tab['type'] ) { $linked[ $tab['global_id'] ] = true; } } $context = array( 'product_id' => $product_id, 'categories' => $product_id > 0 ? TabRenderer::with_ancestors( array_map( 'intval', wc_get_product_term_ids( $product_id, 'product_cat' ) ), 'product_cat' ) : array(), 'tags' => $product_id > 0 ? array_values( array_map( 'intval', wc_get_product_term_ids( $product_id, 'product_tag' ) ) ) : array(), ); ?>
$globals Global tabs. */ private function render_row( string $index, array $tab, array $globals ): void { $name = self::FIELD . '[tabs][' . $index . ']'; $is_new = '__INDEX__' === $index; $editor = 'pnscripts-pt-content-' . $index; $global = TabSanitizer::TYPE_GLOBAL === $tab['type'] ? ( $globals[ $tab['global_id'] ] ?? null ) : null; $title = TabSanitizer::TYPE_GLOBAL === $tab['type'] ? ( null !== $global ? $global['title'] : __( '(deleted global tab)', 'pnscripts-tabcrest' ) ) : $tab['title']; $type_txt = array( TabSanitizer::TYPE_CONTENT => __( 'Rich text', 'pnscripts-tabcrest' ), TabSanitizer::TYPE_FAQ => __( 'FAQ', 'pnscripts-tabcrest' ), TabSanitizer::TYPE_GLOBAL => __( 'Global', 'pnscripts-tabcrest' ), )[ $tab['type'] ] ?? ''; ?>