From bc4260d4fcb379d67713e242dffc8990204269a5 Mon Sep 17 00:00:00 2001 From: Szymon Kasprzyk Date: Thu, 14 Nov 2024 15:49:58 +0100 Subject: [PATCH] adds option to hide terms --- .../assets/embl-taxonomy-edit-tags.css | 5 ++++ .../embl-taxonomy/includes/register.php | 13 +++++++-- .../embl-taxonomy/includes/settings.php | 28 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/wp-content/plugins/embl-taxonomy/assets/embl-taxonomy-edit-tags.css b/wp-content/plugins/embl-taxonomy/assets/embl-taxonomy-edit-tags.css index c36b9cb1b..f7c6fa4f4 100644 --- a/wp-content/plugins/embl-taxonomy/assets/embl-taxonomy-edit-tags.css +++ b/wp-content/plugins/embl-taxonomy/assets/embl-taxonomy-edit-tags.css @@ -27,6 +27,11 @@ padding: 2px 5px; background-color: #E58F9E; } +.statusHidden { + width: fit-content; + padding: 2px 5px; + background-color: #D0D0CE; +} diff --git a/wp-content/plugins/embl-taxonomy/includes/register.php b/wp-content/plugins/embl-taxonomy/includes/register.php index 1fbb8fa06..cc7952299 100644 --- a/wp-content/plugins/embl-taxonomy/includes/register.php +++ b/wp-content/plugins/embl-taxonomy/includes/register.php @@ -95,8 +95,16 @@ public function embl_taxonomy_column_content($content, $column_name, $term_id) { // $content = '' . get_term_meta($term_id, EMBL_Taxonomy::META_NAME, true) . ''; } elseif ($column_name === 'embl_taxonomy_meta_deprecated') { $deprecatedValue = get_term_meta($term_id, EMBL_Taxonomy::META_DEPRECATED, true); - $statusClass = $deprecatedValue == '1' ? 'statusDeprecated' : 'statusActive'; - $statusText = $deprecatedValue == '1' ? 'Deprecated' : 'Active'; + $excludeTerms = get_field('field_embl_taxonomy_exclude', 'option'); // Get excluded terms + + // Check if the current term is in the excluded terms + if (in_array($term_id, $excludeTerms)) { + $statusClass = 'statusHidden'; + $statusText = 'Hidden'; + } else { + $statusClass = $deprecatedValue == '1' ? 'statusDeprecated' : 'statusActive'; + $statusText = $deprecatedValue == '1' ? 'Deprecated' : 'Active'; + } $content = '

' . $statusText . '

'; } @@ -140,6 +148,7 @@ public function register_taxonomy() { 'hierarchical' => false, 'public' => $is_news_theme, // true only for the news theme 'show_ui' => true, + 'meta_box_cb' => false, 'show_in_menu' => true, 'show_admin_column' => true, 'show_in_rest' => true, diff --git a/wp-content/plugins/embl-taxonomy/includes/settings.php b/wp-content/plugins/embl-taxonomy/includes/settings.php index 6f838feed..7aacb0628 100644 --- a/wp-content/plugins/embl-taxonomy/includes/settings.php +++ b/wp-content/plugins/embl-taxonomy/includes/settings.php @@ -139,6 +139,34 @@ function acf_init() { ) ); + acf_add_local_field( + array( + 'parent' => 'group_embl_taxonomy_setings', + 'key' => 'field_embl_taxonomy_exclude', + 'label' => 'Exclude terms', + 'name' => 'embl_taxonomy_exclude', + 'type' => 'taxonomy', + 'instructions' => 'Select terms that should by excluded by taxonomy sync', + 'required' => 0, + 'conditional_logic' => 0, + 'wrapper' => array( + 'width' => '', + 'class' => '', + 'id' => '', + ), + 'taxonomy' => 'embl_taxonomy', + 'add_term' => 0, + 'save_terms' => 0, + 'load_terms' => 0, + 'return_format' => 'id', + 'field_type' => 'multi_select', // Changed to multi_select for multiple selections + 'allow_null' => 1, + 'bidirectional' => 0, + 'multiple' => 1, // Set to 1 to allow multiple selections + 'bidirectional_target' => [], + ) + ); + // New field group specifically for Deprecated checkbox acf_add_local_field_group(array( 'key' => 'group_embl_taxonomy_deprecated',