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 |
|---|---|
| 2139 | $term_group = 0; |
| 2140 | if ( $alias_of ) { |
| 2141 | $alias = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $alias_of) ); |
| 2142 | if ( $alias->term_group ) { |
| 2143 | // The alias we want is already in a group, so let's use that one. |
| 2144 | $term_group = $alias->term_group; |
| 2145 | } else { |
| 2146 | // The alias isn't in a group, so let's create a new one and firstly add the alias term to it. |
| 2147 | $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1; |
| 2148 | do_action( 'edit_terms', $alias->term_id, $taxonomy ); |
| 2149 | $wpdb->update($wpdb->terms, compact('term_group'), array('term_id' => $alias->term_id) ); |
| 2150 | do_action( 'edited_terms', $alias->term_id, $taxonomy ); |
| 2151 | } |
| 2152 | } |
| 2153 | |
| 2154 | if ( $term_id = term_exists($slug) ) { |
| 2155 | $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A ); |
| 2156 | // We've got an existing term in the same taxonomy, which matches the name of the new term: |
| 2157 | if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && $exists = term_exists( (int) $term_id, $taxonomy ) ) { |
| Line | Code |
| 2180 | $slug = wp_unique_term_slug($slug, (object) $args); |
| 2181 | if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) |
| 2182 | return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); |
| 2183 | $term_id = (int) $wpdb->insert_id; |
| 2184 | } |
| 2185 | |
| 2186 | // Seems unreachable, However, Is used in the case that a term name is provided, which sanitizes to an empty string. |
| 2187 | if ( empty($slug) ) { |
| 2188 | $slug = sanitize_title($slug, $term_id); |
| 2189 | do_action( 'edit_terms', $term_id, $taxonomy ); |
| 2190 | $wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) ); |
| 2191 | do_action( 'edited_terms', $term_id, $taxonomy ); |
| 2192 | } |
| 2193 | |
| 2194 | $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 ) ); |
| 2195 | |
| 2196 | if ( !empty($tt_id) ) |
| 2197 | return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); |
| 2198 | |
| Line | Code |
| 2538 | |
| 2539 | if ( $alias_of ) { |
| 2540 | $alias = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $alias_of) ); |
| 2541 | if ( $alias->term_group ) { |
| 2542 | // The alias we want is already in a group, so let's use that one. |
| 2543 | $term_group = $alias->term_group; |
| 2544 | } else { |
| 2545 | // The alias isn't in a group, so let's create a new one and firstly add the alias term to it. |
| 2546 | $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1; |
| 2547 | do_action( 'edit_terms', $alias->term_id, $taxonomy ); |
| 2548 | $wpdb->update( $wpdb->terms, compact('term_group'), array( 'term_id' => $alias->term_id ) ); |
| 2549 | do_action( 'edited_terms', $alias->term_id, $taxonomy ); |
| 2550 | } |
| 2551 | } |
| 2552 | |
| 2553 | // Check $parent to see if it will cause a hierarchy loop |
| 2554 | $parent = apply_filters( 'wp_update_term_parent', $parent, $term_id, $taxonomy, compact( array_keys( $args ) ), $args ); |
| 2555 | |
| 2556 | // Check for duplicate slug |
| 2557 | $id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE slug = %s", $slug ) ); |
| 2558 | if ( $id && ($id != $term_id) ) { |
| 2559 | // If an empty slug was passed or the parent changed, reset the slug to something unique. |
| 2560 | // Otherwise, bail. |
| 2561 | if ( $empty_slug || ( $parent != $term['parent']) ) |
| 2562 | $slug = wp_unique_term_slug($slug, (object) $args); |
| 2563 | else |
| 2564 | return new WP_Error('duplicate_term_slug', sprintf(__('The slug “%s” is already in use by another term'), $slug)); |
| 2565 | } |
| 2566 | do_action( 'edit_terms', $term_id, $taxonomy ); |
| 2567 | $wpdb->update($wpdb->terms, compact( 'name', 'slug', 'term_group' ), compact( 'term_id' ) ); |
| 2568 | if ( empty($slug) ) { |
| 2569 | $slug = sanitize_title($name, $term_id); |
| 2570 | $wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) ); |
| 2571 | } |
| 2572 | do_action( 'edited_terms', $term_id, $taxonomy ); |
| 2573 | |
| 2574 | $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) ); |
| 2575 | do_action( 'edit_term_taxonomy', $tt_id, $taxonomy ); |