Make WordPress Core


Ignore:
Timestamp:
05/23/2007 05:28:13 PM (17 years ago)
Author:
ryan
Message:

wp_insert_category(), cat_rows(), and others using taxonomy. see #4189

File:
1 edited

Legend:

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

    r5523 r5528  
    8585    extract($catarr);
    8686
    87     if( trim( $cat_name ) == '' )
     87    if ( trim( $cat_name ) == '' )
    8888        return 0;
    8989
     
    9191
    9292    // Are we updating or creating?
    93     if (!empty ($cat_ID))
     93    if ( !empty ($cat_ID) )
    9494        $update = true;
    9595    else
    9696        $update = false;
    9797
    98     $cat_name = apply_filters('pre_category_name', $cat_name);
    99 
    100     if (empty ($category_nicename))
    101         $category_nicename = sanitize_title($cat_name);
    102     else
    103         $category_nicename = sanitize_title($category_nicename);
    104     $category_nicename = apply_filters('pre_category_nicename', $category_nicename);
    105 
    106     if (empty ($category_description))
    107         $category_description = '';
    108     $category_description = apply_filters('pre_category_description', $category_description);
    109 
    110     $category_parent = (int) $category_parent;
    111     if ( empty($category_parent) || !get_category( $category_parent ) || ($cat_ID && cat_is_ancestor_of($cat_ID, $category_parent) ) )
    112         $category_parent = 0;
    113 
    114     if ( isset($posts_private) )
    115         $posts_private = (int) $posts_private;
    116     else
    117         $posts_private = 0;
    118 
    119     if ( isset($links_private) )
    120         $links_private = (int) $links_private;
    121     else
    122         $links_private = 0;
    123 
    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 
    131     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')");
    133         $cat_ID = (int) $wpdb->insert_id;
    134     } 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'");
    136     }
    137 
    138     if ( $category_nicename == '' ) {
    139         $category_nicename = sanitize_title($cat_name, $cat_ID );
    140         $wpdb->query( "UPDATE $wpdb->categories SET category_nicename = '$category_nicename' WHERE cat_ID = '$cat_ID'" );
    141     }
    142 
    143     // Keep in mind when using this filter and altering the cat_ID that the two queries above
    144     // have already taken place with the OLD cat_ID
    145     // Also note that you may have post2cat entries with the old cat_ID if this is an update
    146 
    147     if ($update) {
    148         do_action('edit_category', $cat_ID);
    149     } else {
    150         do_action('create_category', $cat_ID);
    151         do_action('add_category', $cat_ID);
    152     }
    153 
    154     $cat_ID = apply_filters('cat_id_filter', $cat_ID, $update);
    155 
    156     clean_category_cache($cat_ID);
    157 
    158     if ($update)
    159         do_action('edited_category', $cat_ID);
    160     else
    161         do_action('created_category', $cat_ID);
    162    
    163     return $cat_ID;
     98    $name = $cat_name;
     99    $description = $category_description;
     100    $slug = $category_nicename;
     101    $parent = $category_parent;
     102
     103    $name = apply_filters('pre_category_name', $name);
     104
     105    if ( empty ($slug) )
     106        $slug = sanitize_title($slug);
     107    else
     108        $slug = sanitize_title($slug);
     109    $slug = apply_filters('pre_category_nicename', $slug);
     110
     111    if ( empty ($description) )
     112        $description = '';
     113    $description = apply_filters('pre_category_description', $description);
     114
     115    $parent = (int) $parent;
     116    if ( empty($parent) || !get_category( $parent ) || ($cat_ID && cat_is_ancestor_of($cat_ID, $parent) ) )
     117        $parent = 0;
     118
     119    $args = compact('slug', 'parent', 'description');
     120
     121    if ( $update )
     122        $cat_ID = wp_update_term($cat_ID, 'category', $args);
     123    else
     124        $cat_ID = wp_insert_term($cat_name, 'category', $args);
     125
     126    return $cat_ID['term_id'];
    164127}
    165128
Note: See TracChangeset for help on using the changeset viewer.