Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: edited_terms

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

This hook occurs 4 times in this file.

Line Code
1952           $alias = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $alias_of) );
1953           if ( $alias->term_group ) {
1954                // The alias we want is already in a group, so let's use that one.
1955                $term_group = $alias->term_group;
1956           } else {
1957                // The alias isn't in a group, so let's create a new one and firstly add the alias term to it.
1958                $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1;
1959                do_action( 'edit_terms', $alias->term_id );
1960                $wpdb->update($wpdb->terms, compact('term_group'), array('term_id' => $alias->term_id) );
1961                do_action( 'edited_terms', $alias->term_id );
1962           }
1963      }
1964
1965      if ( $term_id = term_exists($slug) ) {
1966           $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A );
1967           // We've got an existing term in the same taxonomy, which matches the name of the new term:
1968           if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && $exists = term_exists( (int) $term_id, $taxonomy ) ) {
1969                // Hierarchical, and it matches an existing term, Do not allow same "name" in the same level.
1970                $siblings = get_terms($taxonomy, array('fields' => 'names', 'get' => 'all', 'parent' => (int)$parent) );
 
Line Code
1993                return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
1994           $term_id = (int) $wpdb->insert_id;
1995      }
1996
1997      // Seems unreachable, However, Is used in the case that a term name is provided, which sanitizes to an empty string.
1998      if ( empty($slug) ) {
1999           $slug = sanitize_title($slug, $term_id);
2000           do_action( 'edit_terms', $term_id );
2001           $wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) );
2002           do_action( 'edited_terms', $term_id );
2003      }
2004
2005      $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 ) );
2006
2007      if ( !empty($tt_id) )
2008           return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);
2009
2010      $wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent') + array( 'count' => 0 ) );
2011      $tt_id = (int) $wpdb->insert_id;
 
Line Code
2261           $alias = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $alias_of) );
2262           if ( $alias->term_group ) {
2263                // The alias we want is already in a group, so let's use that one.
2264                $term_group = $alias->term_group;
2265           } else {
2266                // The alias isn't in a group, so let's create a new one and firstly add the alias term to it.
2267                $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1;
2268                do_action( 'edit_terms', $alias->term_id );
2269                $wpdb->update( $wpdb->terms, compact('term_group'), array( 'term_id' => $alias->term_id ) );
2270                do_action( 'edited_terms', $alias->term_id );
2271           }
2272      }
2273
2274      // Check $parent to see if it will cause a hierarchy loop
2275      $parent = apply_filters( 'wp_update_term_parent', $parent, $term_id, $taxonomy, compact( array_keys( $args ) ), $args );
2276
2277      // Check for duplicate slug
2278      $id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE slug = %s", $slug ) );
2279      if ( $id && ($id != $term_id) ) {
 
Line Code
2284           else
2285                return new WP_Error('duplicate_term_slug', sprintf(__('The slug “%s” is already in use by another term'), $slug));
2286      }
2287      do_action( 'edit_terms', $term_id );
2288      $wpdb->update($wpdb->terms, compact( 'name', 'slug', 'term_group' ), compact( 'term_id' ) );
2289      if ( empty($slug) ) {
2290           $slug = sanitize_title($name, $term_id);
2291           $wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) );
2292      }
2293      do_action( 'edited_terms', $term_id );
2294
2295      $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) );
2296      do_action( 'edit_term_taxonomy', $tt_id, $taxonomy );
2297      $wpdb->update( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent' ), array( 'term_taxonomy_id' => $tt_id ) );
2298      do_action( 'edited_term_taxonomy', $tt_id, $taxonomy );
2299
2300      do_action("edit_term", $term_id, $tt_id, $taxonomy);
2301      do_action("edit_$taxonomy", $term_id, $tt_id);
2302