The edit_terms WordPress PHP action fires immediately before the given terms are edited.
Usage
add_action('edit_terms', 'your_custom_function', 10, 3);
function your_custom_function($term_id, $taxonomy, $args) {
// your custom code here
}
Parameters
$term_id(int): Term ID.$taxonomy(string): Taxonomy slug.$args(array): Arguments passed towp_update_term().
More information
See WordPress Developer Resources: edit_terms
Examples
Log term edits
Log when a term is being edited.
add_action('edit_terms', 'log_term_edits', 10, 3);
function log_term_edits($term_id, $taxonomy, $args) {
error_log("Term {$term_id} in {$taxonomy} is being edited.");
}
Check for duplicate terms
Prevent duplicate terms in a custom taxonomy.
add_action('edit_terms', 'prevent_duplicate_terms', 10, 3);
function prevent_duplicate_terms($term_id, $taxonomy, $args) {
if ('your_custom_taxonomy' === $taxonomy) {
// Check for duplicate terms
}
}
Update term metadata
Update term metadata when a term is edited.
add_action('edit_terms', 'update_term_metadata', 10, 3);
function update_term_metadata($term_id, $taxonomy, $args) {
// Update term metadata
}
Custom term validation
Perform custom validation on term data before editing.
add_action('edit_terms', 'custom_term_validation', 10, 3);
function custom_term_validation($term_id, $taxonomy, $args) {
// Perform custom validation
}
Send email notification on term edit
Send email notifications to the admin when a term is edited.
add_action('edit_terms', 'send_email_on_term_edit', 10, 3);
function send_email_on_term_edit($term_id, $taxonomy, $args) {
// Send email notification
}