From c64ac6bfdc1a637c45b94029ed1fd5bf111f9ffd Mon Sep 17 00:00:00 2001 From: Bruno FG Date: Sun, 11 Feb 2024 21:49:04 +1100 Subject: [PATCH] Refactor to allow built-in public taxonomies to be displayed also modifies the view to show singular name --- includes/Admin/Post_Type_Form_Page.php | 25 ++++++++++++++++++- .../templates/custom-ptt-post-types-form.php | 12 ++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/includes/Admin/Post_Type_Form_Page.php b/includes/Admin/Post_Type_Form_Page.php index 643389e..2556ed9 100644 --- a/includes/Admin/Post_Type_Form_Page.php +++ b/includes/Admin/Post_Type_Form_Page.php @@ -85,7 +85,7 @@ public function render_form(): void { $post_type_data = null; $post_type = get_post_type_object( $post_type_name ); - $taxonomies = get_taxonomies( array( '_builtin' => false ) ); + $taxonomies = $this->get_taxonomies_filtered(); if ( $post_type instanceof WP_Post_Type ) { $post_types = get_option( CUSTOM_PTT_POST_TYPE_OPTION_NAME, array() ); @@ -94,4 +94,27 @@ public function render_form(): void { require __DIR__ . '/templates/custom-ptt-post-types-form.php'; } + + /** + * Filter taxonomies to show built-in public ones as well as custom ones. + * + * @return array + * + * @since 0.2.1 + */ + private function get_taxonomies_filtered(): array { + $taxonomies = get_taxonomies( array(), 'objects' ); + $filtered_taxonomies = array(); + + foreach ( $taxonomies as $key => $taxonomy ) { + + if ( $taxonomy->_builtin && ! $taxonomy->public ) { + continue; + } + + $filtered_taxonomies[ $key ] = $taxonomy; + } + + return $filtered_taxonomies; + } } diff --git a/includes/Admin/templates/custom-ptt-post-types-form.php b/includes/Admin/templates/custom-ptt-post-types-form.php index 5ba3682..228a7fd 100644 --- a/includes/Admin/templates/custom-ptt-post-types-form.php +++ b/includes/Admin/templates/custom-ptt-post-types-form.php @@ -72,10 +72,16 @@
- $taxonomy_label ) { ?> + $taxonomy ) { + if ( ! $taxonomy instanceof WP_Taxonomy ) { + continue; + } + + ?>
- class="form-checkbox"> - + rewrite->slug, $post_type_data['taxonomies'] ?? array(), true ) ); ?> class="form-checkbox"> +