PluginProbe
Bulk Page Generator – LPagery / trunk
Bulk Page Generator – LPagery vtrunk
2.5.8 2.5.7 1.4.24 1.4.25 1.4.26 1.4.27 1.4.28 1.4.29 1.4.3 1.4.31 1.4.32 1.4.33 1.4.5 1.4.7 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.5 1.5.6 2.0.0 2.0.1 2.0.10 2.0.11 All 154 releases
lpagery / src / controller / TaxonomyController.php

TaxonomyController.php in Bulk Page Generator – LPagery trunk, at src/controller/TaxonomyController.php

76 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace LPagery\controller;
4
5 /**
6 * Controller for handling taxonomy-related operations
7 */
8 class TaxonomyController
9 {
10 private static $instance;
11
12 /**
13 * Singleton pattern implementation
14 */
15 public static function get_instance(): self
16 {
17 if (null === self::$instance) {
18 self::$instance = new self();
19 }
20 return self::$instance;
21 }
22
23 /**
24 * Gets taxonomy terms
25 *
26 * @return array Taxonomy terms organized by taxonomy
27 */
28 public function getTaxonomyTerms(): array
29 {
30 $categories = get_terms(array('hide_empty' => false,
31 'orderby' => 'name',
32 'order' => 'ASC'));
33
34 $result = [];
35 foreach ($categories as $category) {
36 // Only add unique term IDs
37 if (!isset($result[$category->taxonomy][$category->term_id])) {
38 $result[$category->taxonomy][$category->term_id] = [
39 "id" => $category->term_id,
40 "name" => $category->name
41 ];
42 }
43 }
44
45 // Reformat result to remove keys as term IDs
46 foreach ($result as $taxonomy => $terms) {
47 $result[$taxonomy] = array_values($terms);
48 }
49
50 return $result;
51 }
52
53 /**
54 * Gets taxonomies for a specific post type or all taxonomies
55 *
56 * @param string|null $post_type Post type to get taxonomies for
57 * @return array Array of taxonomies
58 */
59 public function getTaxonomies(?string $post_type = null): array
60 {
61 if (!$post_type) {
62 $taxonomies = get_taxonomies(array(), 'objects');
63 } else {
64 $taxonomies = get_object_taxonomies($post_type, 'objects');
65 }
66
67 $result = array_map(function ($taxonomy) {
68 return [
69 "name" => $taxonomy->name,
70 "label" => $taxonomy->label != null ? $taxonomy->label : $taxonomy->name
71 ];
72 }, $taxonomies);
73
74 return array_values($result);
75 }
76 }