'taxonomy', 'type' => 'text', 'label' => __('Taxonomy', 'zadex'), 'default' => 'category', 'dynamicOptions' => true], ['id' => 'separator', 'type' => 'text', 'label' => __('Separator', 'zadex'), 'default' => ', '], ['id' => 'link', 'type' => 'switch', 'label' => __('Link to archive', 'zadex'), 'default' => true], ]; } public function options(string $control, string $search, Context $ctx): array { if ($control !== 'taxonomy' || !function_exists('get_taxonomies')) { return []; } $out = []; foreach ((array) get_taxonomies(['public' => true], 'objects') as $slug => $tax) { $label = is_object($tax) && isset($tax->label) ? (string) $tax->label : (string) $slug; $out[] = ['value' => (string) $slug, 'label' => $label]; } return self::filter_options($out, $search); } public function render(array $settings, Context $ctx) { if ($ctx->post_id <= 0) { return ''; } $taxonomy = isset($settings['taxonomy']) && is_string($settings['taxonomy']) && $settings['taxonomy'] !== '' ? sanitize_key($settings['taxonomy']) : 'category'; $terms = get_the_terms($ctx->post_id, $taxonomy); if (!is_array($terms) || !$terms) { return ''; } $separator = isset($settings['separator']) && is_string($settings['separator']) ? $settings['separator'] : ', '; $link = !array_key_exists('link', $settings) || !empty($settings['link']); $parts = []; foreach ($terms as $term) { if (!is_object($term) || !isset($term->name)) { continue; } $name = esc_html((string) $term->name); if ($link) { $url = get_term_link($term); if (is_string($url) && $url !== '') { $name = '' . $name . ''; } } $parts[] = $name; } return implode(esc_html($separator), $parts); } }