Make WordPress Core


Ignore:
Timestamp:
04/19/2007 10:26:52 PM (18 years ago)
Author:
markjaquith
Message:

Roll tags out of 2.2 -- reverts [5272], [5271], [5257], [5254], [5253], [5251], [5250], [5243], [5235], [5234], [5232], [5231], [5229], [5228], [5217], [5216], [5215], [5213], half of [5210], [5209], [5205], [5203], [5201], [5196], [5184], [5168], [5163], [5162], [5150], [5149], [5148], [5147], [5113], [5112], [5111], and [5110]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/wp-admin/admin-db.php

    r5272 r5289  
    122122        $links_private = 0;
    123123
    124     if ( empty($type) )
    125         $type = TAXONOMY_CATEGORY;
    126 
    127     // Let's check if we have this category already, if so just do an update
    128     if ( !$update && $cat_ID = category_object_exists( $category_nicename ) )
    129         $update = true;
    130 
    131124    if (!$update) {
    132         $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')");
     125        $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')");
    133126        $cat_ID = (int) $wpdb->insert_id;
    134127    } else {
    135         $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'");
     128        $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'");
    136129    }
    137130
     
    199192    $parent = $category->category_parent;
    200193
    201     // Delete the category if it is not also a tag.
    202     if ( 0 == ($category->type & TAXONOMY_TAG) ) {
    203         if ( !$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'") )
    204             return 0;
    205     } else {
    206         $wpdb->query("UPDATE $wpdb->categories SET type = type & ~" . TAXONOMY_CATEGORY . " WHERE cat_ID = '$cat_ID'");
    207     }
     194    // Delete the category
     195    if ( !$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'") )
     196        return 0;
     197
    208198    // Update children to point to new parent
    209199    $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'");
    210200
    211201    // Only set posts and links to the default category if they're not in another category already
    212     $posts = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id='$cat_ID' AND rel_type = 'category'");
     202    $posts = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id='$cat_ID'");
    213203    foreach ( (array) $posts as $post_id ) {
    214204        $cats = wp_get_post_categories($post_id);
     
    236226
    237227function wp_create_category($cat_name) {
    238     if ( $id = category_exists($cat_name) )
    239         return $id;
    240     $cat_array = array('cat_name' => $cat_name, 'type' => TAXONOMY_CATEGORY);
    241 
    242     if ( $id = category_object_exists($cat_name) ) {
    243         $category = get_category($id);
    244         $cat_array['type'] = $category->type | $cat_array['type'];
    245         $cat_array['cat_ID'] = $id;
    246         return wp_update_category($cat_array);
    247     } else {
    248         return wp_insert_category($cat_array);
    249     }
     228    $cat_array = compact('cat_name');
     229    return wp_insert_category($cat_array);
    250230}
    251231
     
    266246}
    267247
    268 function category_object_exists($cat_name) {
     248function category_exists($cat_name) {
    269249    global $wpdb;
    270250    if (!$category_nicename = sanitize_title($cat_name))
     
    272252
    273253    return (int) $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$category_nicename'");
    274 }
    275 
    276 function category_exists($cat_name) {
    277     global $wpdb;
    278     if (!$category_nicename = sanitize_title($cat_name))
    279         return 0;
    280 
    281     return (int) $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$category_nicename' AND ( type & " . TAXONOMY_CATEGORY .  " != 0 )");
    282 }
    283 
    284 function tag_exists($tag_name) {
    285     global $wpdb;
    286     if (! $tag_nicename = sanitize_title($tag_name))
    287         return 0;
    288 
    289     return (int) $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$tag_nicename' AND ( type & " . TAXONOMY_TAG .  " != 0 )");
    290 }
    291 
    292 function wp_create_tag($tag_name) {
    293     if ( $id = tag_exists($tag_name) )
    294         return $id;
    295     $tag_array = array('cat_name' => $tag_name, 'type' => TAXONOMY_TAG);
    296 
    297     if ( $id = category_object_exists($tag_name) ) {
    298         $category = get_category($id);
    299         $tag_array['type'] = $category->type | $tag_array['type'];
    300         $tag_array['cat_ID'] = $id;
    301         $id = wp_update_category($tag_array);
    302         return $id;
    303     } else {
    304         return wp_insert_category($tag_array);
    305     }
    306254}
    307255
Note: See TracChangeset for help on using the changeset viewer.