~katiekitty/+junk/wordpress-byet

« back to all changes in this revision

Viewing changes to wp-includes/taxonomy.php

  • Committer: kserver
  • Date: 2010-05-15 01:16:36 UTC
  • Revision ID: kserver@kserver-desktop-20100515011636-mnr1j7t637suptdq
Wordpress 2.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
301
301
 */
302
302
function &get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') {
303
303
        global $wpdb;
 
304
        $null = null;
304
305
 
305
306
        if ( empty($term) ) {
306
307
                $error = new WP_Error('invalid_term', __('Empty Term'));
321
322
                $term = (int) $term;
322
323
                if ( ! $_term = wp_cache_get($term, $taxonomy) ) {
323
324
                        $_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND t.term_id = %s LIMIT 1", $taxonomy, $term) );
 
325
                        if ( ! $_term )
 
326
                                return $null;
324
327
                        wp_cache_add($term, $_term, $taxonomy);
325
328
                }
326
329
        }
1078
1081
        foreach ( (array) $taxonomies as $taxonomy ) {
1079
1082
                $tt_ids = wp_get_object_terms($object_id, $taxonomy, 'fields=tt_ids');
1080
1083
                $in_tt_ids = "'" . implode("', '", $tt_ids) . "'";
 
1084
                do_action( 'delete_term_relationships', $object_id, $tt_ids );
1081
1085
                $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_tt_ids)", $object_id) );
 
1086
                do_action( 'deleted_term_relationships', $object_id, $tt_ids );
1082
1087
                wp_update_term_count($tt_ids, $taxonomy);
1083
1088
        }
1084
1089
}
1137
1142
                        return $term_obj;
1138
1143
                $parent = $term_obj->parent;
1139
1144
 
 
1145
                $edit_tt_ids = $wpdb->get_col( "SELECT `term_taxonomy_id` FROM $wpdb->term_taxonomy WHERE `parent` = " . (int)$term_obj->term_id );
 
1146
                do_action( 'edit_term_taxonomies', $edit_tt_ids );
1140
1147
                $wpdb->update( $wpdb->term_taxonomy, compact( 'parent' ), array( 'parent' => $term_obj->term_id) + compact( 'taxonomy' ) );
 
1148
                do_action( 'edited_term_taxonomies', $edit_tt_ids );
1141
1149
        }
1142
1150
 
1143
1151
        $objects = $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tt_id ) );
1155
1163
                wp_set_object_terms($object, $terms, $taxonomy);
1156
1164
        }
1157
1165
 
 
1166
        do_action( 'delete_term_taxonomy', $tt_id );
1158
1167
        $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", $tt_id ) );
 
1168
        do_action( 'deleted_term_taxonomy', $tt_id );
1159
1169
 
1160
1170
        // Delete the term if no taxonomies use it.
1161
1171
        if ( !$wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term) ) )
1377
1387
                } else {
1378
1388
                        // The alias isn't in a group, so let's create a new one and firstly add the alias term to it.
1379
1389
                        $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1;
 
1390
                        do_action( 'edit_terms', $alias->term_id );
1380
1391
                        $wpdb->update($wpdb->terms, compact('term_group'), array('term_id' => $alias->term_id) );
 
1392
                        do_action( 'edited_terms', $alias->term_id );
1381
1393
                }
1382
1394
        }
1383
1395
 
1396
1408
 
1397
1409
        if ( empty($slug) ) {
1398
1410
                $slug = sanitize_title($slug, $term_id);
 
1411
                do_action( 'edit_terms', $term_id );
1399
1412
                $wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) );
 
1413
                do_action( 'edited_terms', $term_id );
1400
1414
        }
1401
1415
 
1402
1416
        $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 ) );
1407
1421
        $wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent') + array( 'count' => 0 ) );
1408
1422
        $tt_id = (int) $wpdb->insert_id;
1409
1423
 
1410
 
        do_action("create_term", $term_id, $tt_id);
 
1424
        do_action("create_term", $term_id, $tt_id, $taxonomy);
1411
1425
        do_action("create_$taxonomy", $term_id, $tt_id);
1412
1426
 
1413
1427
        $term_id = apply_filters('term_id_filter', $term_id, $tt_id);
1414
1428
 
1415
1429
        clean_term_cache($term_id, $taxonomy);
1416
1430
 
1417
 
        do_action("created_term", $term_id, $tt_id);
 
1431
        do_action("created_term", $term_id, $tt_id, $taxonomy);
1418
1432
        do_action("created_$taxonomy", $term_id, $tt_id);
1419
1433
 
1420
1434
        return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);
1474
1488
 
1475
1489
                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 ) ) )
1476
1490
                        continue;
 
1491
                do_action( 'add_term_relationship', $object_id, $tt_id );
1477
1492
                $wpdb->insert( $wpdb->term_relationships, array( 'object_id' => $object_id, 'term_taxonomy_id' => $tt_id ) );
 
1493
                do_action( 'added_term_relationship', $object_id, $tt_id );
1478
1494
        }
1479
1495
 
1480
1496
        wp_update_term_count($tt_ids, $taxonomy);
1483
1499
                $delete_terms = array_diff($old_tt_ids, $tt_ids);
1484
1500
                if ( $delete_terms ) {
1485
1501
                        $in_delete_terms = "'" . implode("', '", $delete_terms) . "'";
 
1502
                        do_action( 'delete_term_relationships', $object_id, $delete_terms );
1486
1503
                        $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_delete_terms)", $object_id) );
 
1504
                        do_action( 'deleted_term_relationships', $object_id, $delete_terms );
1487
1505
                        wp_update_term_count($delete_terms, $taxonomy);
1488
1506
                }
1489
1507
        }
1500
1518
                        $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)");
1501
1519
        }
1502
1520
 
1503
 
        do_action('set_object_terms', $object_id, $terms, $tt_ids, $taxonomy, $append);
 
1521
        do_action('set_object_terms', $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids);
1504
1522
        return $tt_ids;
1505
1523
}
1506
1524
 
1646
1664
                } else {
1647
1665
                        // The alias isn't in a group, so let's create a new one and firstly add the alias term to it.
1648
1666
                        $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1;
 
1667
                        do_action( 'edit_terms', $alias->term_id );
1649
1668
                        $wpdb->update( $wpdb->terms, compact('term_group'), array( 'term_id' => $alias->term_id ) );
 
1669
                        do_action( 'edited_terms', $alias->term_id );
1650
1670
                }
1651
1671
        }
1652
1672
 
1660
1680
                else
1661
1681
                        return new WP_Error('duplicate_term_slug', sprintf(__('The slug “%s” is already in use by another term'), $slug));
1662
1682
        }
1663
 
 
 
1683
        do_action( 'edit_terms', $term_id );
1664
1684
        $wpdb->update($wpdb->terms, compact( 'name', 'slug', 'term_group' ), compact( 'term_id' ) );
1665
 
 
1666
1685
        if ( empty($slug) ) {
1667
1686
                $slug = sanitize_title($name, $term_id);
1668
1687
                $wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) );
1669
1688
        }
 
1689
        do_action( 'edited_terms', $term_id );
1670
1690
 
1671
1691
        $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) );
1672
 
 
 
1692
        do_action( 'edit_term_taxonomy', $tt_id );
1673
1693
        $wpdb->update( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent' ), array( 'term_taxonomy_id' => $tt_id ) );
 
1694
        do_action( 'edited_term_taxonomy', $tt_id );
1674
1695
 
1675
 
        do_action("edit_term", $term_id, $tt_id);
 
1696
        do_action("edit_term", $term_id, $tt_id, $taxonomy);
1676
1697
        do_action("edit_$taxonomy", $term_id, $tt_id);
1677
1698
 
1678
1699
        $term_id = apply_filters('term_id_filter', $term_id, $tt_id);
1679
1700
 
1680
1701
        clean_term_cache($term_id, $taxonomy);
1681
1702
 
1682
 
        do_action("edited_term", $term_id, $tt_id);
 
1703
        do_action("edited_term", $term_id, $tt_id, $taxonomy);
1683
1704
        do_action("edited_$taxonomy", $term_id, $tt_id);
1684
1705
 
1685
1706
        return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);
1771
1792
                // Default count updater
1772
1793
                foreach ( (array) $terms as $term) {
1773
1794
                        $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term) );
 
1795
                        do_action( 'edit_term_taxonomy', $term );
1774
1796
                        $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
 
1797
                        do_action( 'edited_term_taxonomy', $term );
1775
1798
                }
1776
1799
 
1777
1800
        }
2153
2176
 
2154
2177
        foreach ( (array) $terms as $term ) {
2155
2178
                $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term ) );
 
2179
                do_action( 'edit_term_taxonomy', $term );
2156
2180
                $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
 
2181
                do_action( 'edited_term_taxonomy', $term );
2157
2182
        }
2158
2183
}
2159
2184
 
2191
2216
        $slug = $term->slug;
2192
2217
 
2193
2218
        if ( empty($termlink) ) {
2194
 
                $file = get_option('home') . '/';
 
2219
                $file = trailingslashit( get_option('home') );
2195
2220
                $t = get_taxonomy($taxonomy);
2196
2221
                if ( $t->query_var )
2197
2222
                        $termlink = "$file?$t->query_var=$slug";