Created
July 30, 2013 21:59
-
-
Save nciske/6117419 to your computer and use it in GitHub Desktop.
Email site admin when a term slug changes (any taxonomy). Cleaner single taxonomy version here: [https://gist.github.com/nciske/6117497]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'edit_terms', 'example_terms_edit' ); | |
function example_terms_edit( $term_id ){ | |
global $wpdb; | |
global $example_old_slug; | |
$example_old_slug = $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE term_id = %d", $term_id ) ); | |
} | |
add_action( 'edited_terms', 'example_terms_edited' ); | |
function example_terms_edited( $term_id ){ | |
global $wpdb; | |
global $example_old_slug; | |
$new_slug = $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE term_id = %d", $term_id ) ); | |
if( $new_slug != $example_old_slug ) | |
wp_mail( get_option('admin_email') , 'Slug changed for term #'.$term_id, "Old Slug: {$example_old_slug}\r\nNew Slug: {$new_slug}" ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why not use a single function and a static variable? That will save having to use a global. You will just need to check the value of the static variable to see which hook is being called, and you will need to clear it after you've checked whether the slug has been updated.