WP hooks navigation: Home/browse • Actions index • Filters index
To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).
The best way to understand what a hook does is to look at where it occurs in the source code.
do_action( "hook_name" )apply_filters( "hook_name", "what_to_filter" ).Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.
This hook occurs 4 times in this file.
| Line | Code |
|---|---|
| 1998 | $term_group = 0; |
| 1999 | if ( $alias_of ) { |
| 2000 | $alias = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $alias_of) ); |
| 2001 | if ( $alias->term_group ) { |
| 2002 | // The alias we want is already in a group, so let's use that one. |
| 2003 | $term_group = $alias->term_group; |
| 2004 | } else { |
| 2005 | // The alias isn't in a group, so let's create a new one and firstly add the alias term to it. |
| 2006 | $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1; |
| 2007 | do_action( 'edit_terms', $alias->term_id ); |
| 2008 | $wpdb->update($wpdb->terms, compact('term_group'), array('term_id' => $alias->term_id) ); |
| 2009 | do_action( 'edited_terms', $alias->term_id ); |
| 2010 | } |
| 2011 | } |
| 2012 | |
| 2013 | if ( $term_id = term_exists($slug) ) { |
| 2014 | $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A ); |
| 2015 | // We've got an existing term in the same taxonomy, which matches the name of the new term: |
| 2016 | if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && $exists = term_exists( (int) $term_id, $taxonomy ) ) { |
| Line | Code |
| 2039 | $slug = wp_unique_term_slug($slug, (object) $args); |
| 2040 | if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) |
| 2041 | return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); |
| 2042 | $term_id = (int) $wpdb->insert_id; |
| 2043 | } |
| 2044 | |
| 2045 | // Seems unreachable, However, Is used in the case that a term name is provided, which sanitizes to an empty string. |
| 2046 | if ( empty($slug) ) { |
| 2047 | $slug = sanitize_title($slug, $term_id); |
| 2048 | do_action( 'edit_terms', $term_id ); |
| 2049 | $wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) ); |
| 2050 | do_action( 'edited_terms', $term_id ); |
| 2051 | } |
| 2052 | |
| 2053 | $tt_id = $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id ) ); |
| 2054 | |
| 2055 | if ( !empty($tt_id) ) |
| 2056 | return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); |
| 2057 | |
| Line | Code |
| 2307 | |
| 2308 | if ( $alias_of ) { |
| 2309 | $alias = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $alias_of) ); |
| 2310 | if ( $alias->term_group ) { |
| 2311 | // The alias we want is already in a group, so let's use that one. |
| 2312 | $term_group = $alias->term_group; |
| 2313 | } else { |
| 2314 | // The alias isn't in a group, so let's create a new one and firstly add the alias term to it. |
| 2315 | $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1; |
| 2316 | do_action( 'edit_terms', $alias->term_id ); |
| 2317 | $wpdb->update( $wpdb->terms, compact('term_group'), array( 'term_id' => $alias->term_id ) ); |
| 2318 | do_action( 'edited_terms', $alias->term_id ); |
| 2319 | } |
| 2320 | } |
| 2321 | |
| 2322 | // Check $parent to see if it will cause a hierarchy loop |
| 2323 | $parent = apply_filters( 'wp_update_term_parent', $parent, $term_id, $taxonomy, compact( array_keys( $args ) ), $args ); |
| 2324 | |
| 2325 | // Check for duplicate slug |
| 2326 | $id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE slug = %s", $slug ) ); |
| 2327 | if ( $id && ($id != $term_id) ) { |
| 2328 | // If an empty slug was passed or the parent changed, reset the slug to something unique. |
| 2329 | // Otherwise, bail. |
| 2330 | if ( $empty_slug || ( $parent != $term['parent']) ) |
| 2331 | $slug = wp_unique_term_slug($slug, (object) $args); |
| 2332 | else |
| 2333 | return new WP_Error('duplicate_term_slug', sprintf(__('The slug “%s” is already in use by another term'), $slug)); |
| 2334 | } |
| 2335 | do_action( 'edit_terms', $term_id ); |
| 2336 | $wpdb->update($wpdb->terms, compact( 'name', 'slug', 'term_group' ), compact( 'term_id' ) ); |
| 2337 | if ( empty($slug) ) { |
| 2338 | $slug = sanitize_title($name, $term_id); |
| 2339 | $wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) ); |
| 2340 | } |
| 2341 | do_action( 'edited_terms', $term_id ); |
| 2342 | |
| 2343 | $tt_id = $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id) ); |
| 2344 | do_action( 'edit_term_taxonomy', $tt_id, $taxonomy ); |