Last active
December 20, 2015 10:39
-
-
Save nciske/6117497 to your computer and use it in GitHub Desktop.
One hook and no global variable version of [https://gist.github.com/nciske/6117419]
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( 'edited_terms', 'example_terms_edited' ); | |
function example_terms_edited( $term_id ){ | |
$tax = 'post_tag'; //category, custom_taxonomy, etc. | |
global $wpdb; | |
$term = get_term( $term_id, $tax ); | |
$old_slug = $term->slug; | |
$new_slug = $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE term_id = %d", $term_id ) ); | |
if( $new_slug != $old_slug ) | |
wp_mail( get_option('admin_email'), 'Slug changed for term #'.$term_id, "Old Slug: {$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
interesting! the only thing I'd add is to place some comments...
cause it is not obvious that this code is taking advantage of an exploit that the slug change doesn’t immediately update the object cache, so you can compare the cached version to the database.