Skip to content

Instantly share code, notes, and snippets.

@psorensen
Created July 24, 2017 01:53
Show Gist options
  • Select an option

  • Save psorensen/87c7cf091efcd8c368337f24541e1dca to your computer and use it in GitHub Desktop.

Select an option

Save psorensen/87c7cf091efcd8c368337f24541e1dca to your computer and use it in GitHub Desktop.
Wordpress: Fire event when term is created.
$( document ).ajaxComplete( function( event, xhr, settings ) {
try {
var queryStringArray = settings.data.split('&');
} catch(e) {
var queryStringArray = {};
}
// only when
if ( $.inArray( 'action=add-tag', queryStringArray ) !== -1 ) {
const $xml = $( xhr.responseXML );
const tag_id = $xml.find( 'term_id' ).text()
if ( "" !== tag_id ) {
$( document ).trigger( 'ami-term-created' );
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment