Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EMBL Taxonomy update #1381

Merged
merged 20 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin
Submodule bin updated from 478ffe to 7f10fd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
.wp-list-table .column-description {
display: none;
}
.statusActive {
width: fit-content;
padding: 2px 5px;
background-color: #D0DEBB;
}
.statusDeprecated {
width: fit-content;
padding: 2px 5px;
background-color: #E58F9E;
}



/* If you wish to hide the term slug column */
/* .wp-list-table .column-slug {
Expand Down
104 changes: 104 additions & 0 deletions wp-content/plugins/embl-taxonomy/assets/embl-taxonomy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
(() => {

/**
* Sync button
*/

// Bail if no sync button
$button = document.querySelector('#embl-taxonomy-sync');
if (!$button) return;
Expand Down Expand Up @@ -93,4 +98,103 @@
$modal.showModal();
startSync(new URL(path));
});




/**
* Delete button
*/

// Bail if no delete button
const $deleteButton = document.querySelector('#embl-taxonomy-delete-deprecated');
if (!$deleteButton) return;

// Confirmation modal for deletion
const $deleteModal = document.createElement('dialog');
$deleteModal.id = 'embl-delete-modal';
$deleteModal.innerHTML = `
<h3><b>Confirm Deletion</b></h3>
<p>Are you sure you want to delete all deprecated terms? This action cannot be undone.</p>
<button id="confirm-delete" class="button button-small">Delete</button>
<button id="cancel-delete" class="button button-small">Cancel</button>
`;
document.body.appendChild($deleteModal);

// Show confirmation modal on delete button click
$deleteButton.addEventListener('click', (ev) => {
ev.preventDefault();
$deleteModal.showModal();
});

// Handle delete confirmation
$deleteModal.querySelector('#confirm-delete').addEventListener('click', async () => {
$deleteModal.close();
$deleteButton.disabled = true;
$deleteButton.innerText = 'Deleting...';

try {
const response = await fetch(window.emblTaxonomySettings.deletePath, {
method: 'POST',
headers: {
'X-WP-Nonce': window.emblTaxonomySettings.token
}
});
const json = await response.json();

if (json.success) {
window.location.href = `${emblTaxonomySettings.adminUrl}edit-tags.php?taxonomy=${emblTaxonomySettings.taxonomyName}&delete_deprecated=true`;
} else {
throw new Error(json.error || 'Failed to delete deprecated terms.');
}
} catch (error) {
alert(`Error: ${error.message}`);
$deleteButton.disabled = false;
$deleteButton.innerText = 'Delete all deprecated terms';
}
});

// Handle delete cancellation
$deleteModal.querySelector('#cancel-delete').addEventListener('click', () => {
$deleteModal.close();
});

document.addEventListener('DOMContentLoaded', function() {
const showDeprecatedButton = document.getElementById('embl-taxonomy-show-deprecated');

if (showDeprecatedButton) {
showDeprecatedButton.addEventListener('click', function() {
const url = this.getAttribute('data-href');
window.location.href = url; // Redirect to the URL
});
}
});




/**
* Show deprecated terms button
*/

document.addEventListener('DOMContentLoaded', function() {
const showDeprecatedButton = document.getElementById('embl-taxonomy-show-deprecated');

if (showDeprecatedButton) {
// Check if the URL contains 'filter=deprecated'
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('filter') && urlParams.get('filter') === 'deprecated') {
// Change button text and URL
showDeprecatedButton.textContent = 'See all taxonomy terms';
showDeprecatedButton.setAttribute('data-href', `${emblTaxonomySettings.adminUrl}edit-tags.php?taxonomy=${emblTaxonomySettings.taxonomyName}`);
}

showDeprecatedButton.addEventListener('click', function() {
const url = this.getAttribute('data-href');
window.location.href = url; // Redirect to the URL
});
}
});


})();
7 changes: 7 additions & 0 deletions wp-content/plugins/embl-taxonomy/embl-taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class EMBL_Taxonomy {
public function __construct() {
register_activation_hook( __FILE__, array( $this, 'activation' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivation' ) );

}

function initialize() {
Expand Down Expand Up @@ -82,6 +83,12 @@ function embl_taxonomy_get_term($term_id) {
if (!$term_id) {
return null;
}
// Ensure embl_taxonomy()->register and get_wp_taxonomy() are available
$taxonomy_instance = embl_taxonomy();
if (!$taxonomy_instance || !isset($taxonomy_instance->register)) {
error_log('Register instance is not set or initialized.');
return null;
}
$wp_terms = embl_taxonomy()->register->get_wp_taxonomy();
// Get by `WP_Term->term_id`
if (is_int($term_id)) {
Expand Down
Loading
Loading