Make WordPress Core


Ignore:
Timestamp:
04/05/2007 09:16:02 PM (18 years ago)
Author:
ryan
Message:

Bit twiddling. Add type bitfield to categories table. see #3723

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-db.php

    r5177 r5184  
    122122        $links_private = 0;
    123123
     124    if ( empty($type) )
     125        $type = TAXONOMY_CATEGORY;
     126
    124127    // Let's check if we have this category already, if so just do an update
    125     if ( $cat_ID = category_exists( $category_nicename ) )
     128    if ( $cat_ID = category_exists( $category_nicename ) ) {
    126129        $update = true;
     130        $category = get_category($cat_ID);
     131        // If inserting a category that already exists, OR in the new type rather
     132        // than replacing the entire value.
     133        $type = $category->type | $type;
     134    }
    127135
    128136    if (!$update) {
    129         $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent, links_private, posts_private) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$category_parent', '$links_private', '$posts_private')");
     137        $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent, links_private, posts_private, type) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$category_parent', '$links_private', '$posts_private', '$type')");
    130138        $cat_ID = (int) $wpdb->insert_id;
    131139    } else {
    132         $wpdb->query ("UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$category_parent', links_private = '$links_private', posts_private = '$posts_private' WHERE cat_ID = '$cat_ID'");
     140        $wpdb->query ("UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$category_parent', links_private = '$links_private', posts_private = '$posts_private', type = '$type' WHERE cat_ID = '$cat_ID'");
    133141    }
    134142
     
    196204    $parent = $category->category_parent;
    197205
    198     // Delete the category
    199     if ( !$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'") )
    200         return 0;
    201 
     206    // Delete the category if it is not also a tag.
     207    if ( 0 == ($category->type & TAXONOMY_TAG) ) {
     208        if ( !$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'") )
     209            return 0;
     210    } else {
     211        $wpdb->query("UPDATE $wpdb->categories SET type = type & ~" . TAXONOMY_CATEGORY . " WHERE cat_ID = '$cat_ID'");
     212    }
    202213    // Update children to point to new parent
    203214    $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'");
    204215
    205216    // Only set posts and links to the default category if they're not in another category already
    206     $posts = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id='$cat_ID'");
     217    $posts = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id='$cat_ID' AND rel_type = 'category'");
    207218    foreach ( (array) $posts as $post_id ) {
    208219        $cats = wp_get_post_categories($post_id);
     
    256267
    257268    return (int) $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$category_nicename'");
     269}
     270
     271function wp_create_tag($tag_name) {
     272    $tag_array = array('cat_name' => $tag_name, 'type' => TAXONOMY_TAG);
     273    return wp_insert_category($tag_array);
    258274}
    259275
Note: See TracChangeset for help on using the changeset viewer.