Make WordPress Core

Changeset 5937


Ignore:
Timestamp:
08/24/2007 02:44:26 PM (17 years ago)
Author:
ryan
Message:

Update WP importer to use taxonomy and query cat based on slug. see #4613

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/import/wordpress.php

    r5870 r5937  
    221221        global $wpdb;
    222222
    223         $cat_names = (array) $wpdb->get_col("SELECT cat_name FROM $wpdb->categories");
     223        $cat_names = (array) get_terms('category', 'fields=names');
    224224
    225225        while ( $c = array_shift($this->categories) ) {
     
    324324                $post_cats = array();
    325325                foreach ($categories as $category) {
    326                     $cat_ID = (int) $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name = '$category'");
     326                    $slug = sanitize_term_field('slug', $category, 0, 'category', 'db');
     327                    $cat = get_term_by('slug', $slug, 'category');
     328                    $cat_ID = 0;
     329                    if ( ! empty($cat) )
     330                        $cat_ID = $cat->term_id;
    327331                    if ($cat_ID == 0) {
     332                        $category = $wpdb->escape($category);
    328333                        $cat_ID = wp_insert_category(array('cat_name' => $category));
    329334                    }
  • trunk/wp-includes/default-filters.php

    r5906 r5937  
    3434    add_filter($filter, 'clean_url');
    3535    add_filter($filter, 'wp_filter_kses');
     36}
     37
     38// Slugs
     39$filters = array('pre_term_slug');
     40foreach ( $filters as $filter ) {
     41    add_filter($filter, 'sanitize_title');
    3642}
    3743
  • trunk/wp-includes/taxonomy.php

    r5906 r5937  
    283283 *      might be inaccurate or wrong.
    284284 */
    285 function get_term_by($field, $value, $taxonomy, $output = OBJECT) {
     285function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw') {
    286286    global $wpdb;
    287287
     
    307307
    308308    wp_cache_add($term->term_id, $term, $taxonomy);
     309
     310    $term = sanitize_term($term, $taxonomy, $filter);
    309311
    310312    if ( $output == OBJECT ) {
     
    488490    else if ( 'ids' == $fields )
    489491        $select_this = 't.term_id';
     492    else if ( 'names' == $fields )
     493        $select_this == 't.name';
    490494
    491495    $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ($in_taxonomies) $where ORDER BY $orderby $order $number";
     
    772776    if ( empty($slug) )
    773777        $slug = sanitize_title($name);
    774     else
    775         $slug = sanitize_title($slug);
    776778
    777779    $term_group = 0;   
Note: See TracChangeset for help on using the changeset viewer.