Skip to content

Instantly share code, notes, and snippets.

@nciske
Last active December 20, 2015 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nciske/6117497 to your computer and use it in GitHub Desktop.
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]
<?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}" );
}
@halukkaramete
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment