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.
| Line | Code |
|---|---|
| 1299 | * @param string|array $taxonomy List of Taxonomy Names or single Taxonomy name. |
| 1300 | */ |
| 1301 | function wp_delete_object_term_relationships( $object_id, $taxonomies ) { |
| 1302 | global $wpdb; |
| 1303 | |
| 1304 | $object_id = (int) $object_id; |
| 1305 | |
| 1306 | if ( !is_array($taxonomies) ) |
| 1307 | $taxonomies = array($taxonomies); |
| 1308 | |
| 1309 | foreach ( (array) $taxonomies as $taxonomy ) { |
| 1310 | $tt_ids = wp_get_object_terms($object_id, $taxonomy, array('fields' => 'tt_ids')); |
| 1311 | $in_tt_ids = "'" . implode("', '", $tt_ids) . "'"; |
| 1312 | do_action( 'delete_term_relationships', $object_id, $tt_ids ); |
| 1313 | $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_tt_ids)", $object_id) ); |
| 1314 | do_action( 'deleted_term_relationships', $object_id, $tt_ids ); |
| 1315 | wp_update_term_count($tt_ids, $taxonomy); |
| 1316 | } |
| 1317 | } |
| 1318 | |
| 1319 | /** |
| 1320 | * Removes a term from the database. |
| 1321 | * |
| 1322 | * If the term is a parent of other terms, then the children will be updated to |
| 1323 | * that term's parent. |
| 1324 | * |
| 1325 | * The $args 'default' will only override the terms found, if there is only one |
| 1326 | * term found. Any other and the found terms are used. |
| 1327 | * |
| 1328 | * The $args 'force_default' will force the term supplied as default to be |
| 1329 | * assigned even if the object was not going to be termless |
| Line | Code |
| 1748 | if ( $wpdb->get_var( $wpdb->prepare( "SELECT term_taxonomy_id FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id = %d", $object_id, $tt_id ) ) ) |
| 1749 | continue; |
| 1750 | do_action( 'add_term_relationship', $object_id, $tt_id ); |
| 1751 | $wpdb->insert( $wpdb->term_relationships, array( 'object_id' => $object_id, 'term_taxonomy_id' => $tt_id ) ); |
| 1752 | do_action( 'added_term_relationship', $object_id, $tt_id ); |
| 1753 | } |
| 1754 | |
| 1755 | wp_update_term_count($tt_ids, $taxonomy); |
| 1756 | |
| 1757 | if ( ! $append ) { |
| 1758 | $delete_terms = array_diff($old_tt_ids, $tt_ids); |
| 1759 | if ( $delete_terms ) { |
| 1760 | $in_delete_terms = "'" . implode("', '", $delete_terms) . "'"; |
| 1761 | do_action( 'delete_term_relationships', $object_id, $delete_terms ); |
| 1762 | $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_delete_terms)", $object_id) ); |
| 1763 | do_action( 'deleted_term_relationships', $object_id, $delete_terms ); |
| 1764 | wp_update_term_count($delete_terms, $taxonomy); |
| 1765 | } |
| 1766 | } |
| 1767 | |
| 1768 | $t = get_taxonomy($taxonomy); |
| 1769 | if ( ! $append && isset($t->sort) && $t->sort ) { |
| 1770 | $values = array(); |
| 1771 | $term_order = 0; |
| 1772 | $final_tt_ids = wp_get_object_terms($object_id, $taxonomy, array('fields' => 'tt_ids')); |
| 1773 | foreach ( $tt_ids as $tt_id ) |
| 1774 | if ( in_array($tt_id, $final_tt_ids) ) |
| 1775 | $values[] = $wpdb->prepare( "(%d, %d, %d)", $object_id, $tt_id, ++$term_order); |
| 1776 | if ( $values ) |
| 1777 | $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)"); |
| 1778 | } |