post_type || ! in_array( $hook_suffix, array( 'post.php', 'post-new.php' ), true ) ) { return; } wp_enqueue_style( 'pnscripts-product-tabs-admin', PNSCRIPTS_PRODUCT_TABS_URL . 'assets/css/admin.css', array(), PNSCRIPTS_PRODUCT_TABS_VERSION ); wp_enqueue_style( 'woocommerce_admin_styles' ); wp_enqueue_script( 'pnscripts-product-tabs-global', PNSCRIPTS_PRODUCT_TABS_URL . 'assets/js/admin-global.js', array( 'jquery', 'wc-enhanced-select' ), PNSCRIPTS_PRODUCT_TABS_VERSION, true ); } /** * Box markup. * * @param \WP_Post $post Post. */ public function render( $post ): void { $tab = $this->globals->get( (int) $post->ID ); if ( null === $tab ) { return; } if ( 'auto-draft' === $post->post_status ) { $tab['scope'] = TabSanitizer::SCOPE_ALL; $tab['schema'] = true; } $name = self::FIELD; wp_nonce_field( self::NONCE, self::NONCE . '_nonce' ); ?>

'', 'a' => '', ), ); foreach ( $items as $i => $item ) { self::faq_item( $name . '[faq][' . $i . ']', $item ); } ?>






$selected Selected ids. */ private static function term_options( string $taxonomy, array $selected ): void { $terms = get_terms( array( 'taxonomy' => $taxonomy, 'hide_empty' => false, 'orderby' => 'name', 'number' => 2000, ) ); if ( ! is_array( $terms ) ) { return; } $by_id = array(); foreach ( $terms as $term ) { if ( $term instanceof \WP_Term ) { $by_id[ $term->term_id ] = $term; } } foreach ( $by_id as $term ) { $label = $term->name; $parent = $term->parent; $guard = 0; while ( $parent > 0 && isset( $by_id[ $parent ] ) && $guard < 10 ) { $label = $by_id[ $parent ]->name . ' › ' . $label; $parent = $by_id[ $parent ]->parent; ++$guard; } printf( '', esc_attr( (string) $term->term_id ), selected( in_array( $term->term_id, $selected, true ), true, false ), esc_html( $label ) ); } } /** * Question/answer fields. * * @param string $name Field prefix. * @param array{q: string, a: string} $item Item. */ private static function faq_item( string $name, array $item ): void { ?>

$value ) { $data[ (string) $key ] = $value; } if ( isset( $data['faq'] ) && is_array( $data['faq'] ) ) { $data['faq'] = array_values( $data['faq'] ); } $this->globals->save_settings( (int) $post_id, $data, current_user_can( 'unfiltered_html' ) ); /** * Fires after a global tab's settings were saved (add-ons save their own fields). * * @param int $post_id Post id. * @param array $raw Unslashed, unsanitised submitted settings. */ do_action( 'pnscripts_product_tabs_global_tab_saved', (int) $post_id, $data ); } /** * List columns. * * @param mixed $columns Columns. * @return array */ public function columns( mixed $columns ): array { $columns = is_array( $columns ) ? $columns : array(); $out = array(); foreach ( $columns as $key => $label ) { $out[ (string) $key ] = is_string( $label ) ? $label : ''; if ( 'title' === $key ) { $out['pnscripts_pt_scope'] = __( 'Shown on', 'pnscripts-tabcrest' ); $out['pnscripts_pt_type'] = __( 'Type', 'pnscripts-tabcrest' ); $out['pnscripts_pt_priority'] = __( 'Priority', 'pnscripts-tabcrest' ); } } return $out; } /** * Column values. * * @param string $column Column. * @param int $post_id Post id. */ public function column( $column, $post_id ): void { $tab = $this->globals->get( (int) $post_id ); if ( null === $tab ) { return; } switch ( $column ) { case 'pnscripts_pt_scope': echo esc_html( self::scope_label( $tab ) ); break; case 'pnscripts_pt_type': echo esc_html( TabSanitizer::TYPE_FAQ === $tab['type'] ? __( 'FAQ', 'pnscripts-tabcrest' ) : __( 'Rich text', 'pnscripts-tabcrest' ) ); break; case 'pnscripts_pt_priority': echo esc_html( (string) $tab['priority'] ); break; } } /** * Human description of where a tab shows. * * @param GlobalTab $tab Tab. */ public static function scope_label( array $tab ): string { if ( TabSanitizer::SCOPE_ALL === $tab['scope'] ) { return __( 'All products', 'pnscripts-tabcrest' ); } if ( TabSanitizer::SCOPE_MANUAL === $tab['scope'] ) { return __( 'Products where added', 'pnscripts-tabcrest' ); } $names = array(); foreach ( array_merge( $tab['categories'], $tab['tags'] ) as $term_id ) { $term = get_term( $term_id ); if ( $term instanceof \WP_Term ) { $names[] = $term->name; } } return array() === $names ? __( 'No categories or tags chosen', 'pnscripts-tabcrest' ) : implode( ', ', $names ); } }