Ticket #4189: terms.diff

File terms.diff, 9.3 KB (added by ryan, 5 years ago)
  • wp-includes/wp-db.php

     
    3434        var $optiongroups; 
    3535        var $optiongroup_options; 
    3636        var $postmeta; 
     37        var $terms; 
     38        var $term_taxonomy; 
     39        var $term_relationships; 
    3740 
    3841        var $charset; 
    3942        var $collate; 
  • wp-includes/post.php

     
    459459 
    460460        $post_id = (int) $post_id; 
    461461         
    462         if ( !isset( $tag_cache[$blog_id][$post_id] ) ) 
    463                 update_post_category_cache( $post_id ); // loads $tag_cache 
    464  
    465         return $tag_cache[$blog_id][$post_id]; 
     462        $tags = get_object_terms($post_id, 'post_tag'); 
     463        return $tags; 
    466464} 
    467465 
    468466function wp_get_recent_posts($num = 10) { 
     
    792790         
    793791        if ( !$post_id ) 
    794792                return false; 
    795          
    796         // prevent warnings for unintialized variables 
    797         $tag_ids = array(); 
    798793 
    799794        if ( empty($tags) ) 
    800795                $tags = array(); 
    801796        $tags = (is_array($tags)) ? $tags : explode( ',', $tags ); 
    802          
    803         foreach ( $tags as $tag ) { 
    804                 $tag = trim( $tag ); 
    805                 if ( !$tag_slug = sanitize_title( $tag ) ) 
    806                         continue; // discard 
    807                 if ( !$tag_id = tag_exists( $tag ) ) 
    808                         $tag_id = wp_create_tag( $tag ); 
    809                 $tag_ids[] = $tag_id; 
    810         } 
    811  
    812         if ( empty($tag_ids) && ( !empty($tags) || $append ) ) 
    813                 return false; 
    814          
    815         $tag_ids = array_unique( $tag_ids ); 
    816          
    817         // First the old tags 
    818         $old_tags = $wpdb->get_col(" 
    819                 SELECT category_id 
    820                 FROM $wpdb->post2cat 
    821                 WHERE post_id = '$post_id' AND rel_type = 'tag'"); 
    822          
    823         if ( !$old_tags ) { 
    824                 $old_tags = array(); 
    825         } else { 
    826                 $old_tags = array_unique( $old_tags ); 
    827         } 
    828          
    829         // Delete any? 
    830         $delete_tags = array_diff( $old_tags, $tag_ids); 
    831         if ( $delete_tags && !$append ) { 
    832                 foreach ( $delete_tags as $del ) { 
    833                         $wpdb->query(" 
    834                                 DELETE FROM $wpdb->post2cat 
    835                                 WHERE category_id = '$del' 
    836                                         AND post_id = '$post_id' 
    837                                         AND rel_type = 'tag' 
    838                                 "); 
    839                 } 
    840         } 
    841          
    842         // Add any? 
    843         $add_tags = array_diff( $tag_ids, $old_tags ); 
    844         if ( $add_tags ) { 
    845                 foreach ( $add_tags as $new_tag ) { 
    846                         $new_tag = (int) $new_tag; 
    847                         if ( !empty($new_tag) ) 
    848                                 $wpdb->query(" 
    849                                         INSERT INTO $wpdb->post2cat (post_id, category_id, rel_type)  
    850                                         VALUES ('$post_id', '$new_tag', 'tag')"); 
    851                 } 
    852         } 
    853          
    854         // Update category counts. 
    855         $all_affected_tags = array_unique( array_merge( $tag_ids, $old_tags ) ); 
    856         foreach ( $all_affected_tags as $tag_id ) { 
    857                 $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->post2cat, $wpdb->posts WHERE $wpdb->posts.ID=$wpdb->post2cat.post_id AND post_status = 'publish' AND post_type = 'post' AND category_id = '$tag_id' AND rel_type = 'tag'" ); 
    858                 $wpdb->query( "UPDATE $wpdb->categories SET tag_count = '$count', type = type | " . TAXONOMY_TAG . " WHERE cat_ID = '$tag_id'" ); 
    859                 if ( $count == 0 ) 
    860                         $wpdb->query( "UPDATE $wpdb->categories SET type = type & ~". TAXONOMY_TAG . " WHERE cat_ID = '$tag_id'" ); 
    861                 clean_category_cache( $tag_id ); 
    862                 do_action( 'edit_category', $tag_id ); 
    863                 do_action( 'edit_tag', $tag_id ); 
    864         } 
     797        add_term_relationship($tags, $post_id, 'post_tag'); 
    865798} 
    866799 
    867800function wp_set_post_categories($post_ID = 0, $post_categories = array()) { 
  • wp-includes/version.php

     
    33// This holds the version number in a separate file so we can bump it without cluttering the SVN 
    44 
    55$wp_version = '2.3-alpha'; 
    6 $wp_db_version = 5200; 
     6$wp_db_version = 5495; 
    77 
    88?> 
  • wp-settings.php

     
    116116$wpdb->options        = $wpdb->prefix . 'options'; 
    117117$wpdb->postmeta       = $wpdb->prefix . 'postmeta'; 
    118118$wpdb->usermeta       = $wpdb->prefix . 'usermeta'; 
     119$wpdb->terms          = $wpdb->prefix . 'terms'; 
     120$wpdb->term_taxonomy  = $wpdb->prefix . 'term_taxonomy'; 
     121$wpdb->term_relationships = $wpdb->prefix . 'term_relationships'; 
    119122 
    120123if ( defined('CUSTOM_USER_TABLE') ) 
    121124        $wpdb->users = CUSTOM_USER_TABLE; 
     
    168171require (ABSPATH . WPINC . '/version.php'); 
    169172require (ABSPATH . WPINC . '/deprecated.php'); 
    170173require (ABSPATH . WPINC . '/script-loader.php'); 
     174require (ABSPATH . WPINC . '/taxonomy.php'); 
    171175 
    172176if (strpos($_SERVER['PHP_SELF'], 'install.php') === false) { 
    173177    // Used to guarantee unique hash cookies 
  • wp-admin/admin-functions.php

     
    664664        if ( !$post_id ) 
    665665                return false; 
    666666 
    667         $tags = $wpdb->get_results( " 
    668                      SELECT category_id, cat_name 
    669                      FROM $wpdb->categories, $wpdb->post2cat 
    670                      WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_id' AND rel_type = 'tag' 
    671                      " ); 
     667        $tags = wp_get_post_tags($post_id); 
     668 
    672669        if ( !$tags ) 
    673670                return false; 
    674671 
    675672        foreach ( $tags as $tag ) 
    676                 $tag_names[] = $tag->cat_name; 
     673                $tag_names[] = $tag->term_name; 
    677674        $tags_to_edit = join( ', ', $tag_names ); 
    678675        $tags_to_edit = attribute_escape( $tags_to_edit ); 
    679676        $tags_to_edit = apply_filters( 'tags_to_edit', $tags_to_edit ); 
  • wp-admin/admin-db.php

     
    286286        if (! $tag_nicename = sanitize_title($tag_name)) 
    287287                return 0; 
    288288 
    289         return (int) $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$tag_nicename' AND ( type & " . TAXONOMY_TAG .  " != 0 )"); 
     289        return is_term($tag_name, 'post_tag'); 
    290290} 
    291291 
    292292function wp_create_tag($tag_name) { 
    293293        if ( $id = tag_exists($tag_name) ) 
    294294                return $id; 
    295         $tag_array = array('cat_name' => $tag_name, 'type' => TAXONOMY_TAG); 
    296295 
    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         } 
     296        $tag_id = add_term($tag_name, 'post_tag');       
    306297} 
    307298 
    308299function wp_delete_user($id, $reassign = 'novalue') { 
  • wp-admin/upgrade-schema.php

     
    1010                $charset_collate .= " COLLATE $wpdb->collate"; 
    1111} 
    1212 
    13 $wp_queries="CREATE TABLE $wpdb->categories ( 
    14   cat_ID bigint(20) NOT NULL auto_increment, 
    15   cat_name varchar(55) NOT NULL default '', 
    16   category_nicename varchar(200) NOT NULL default '', 
    17   category_description longtext NOT NULL, 
    18   category_parent bigint(20) NOT NULL default '0', 
    19   category_count bigint(20) NOT NULL default '0', 
    20   link_count bigint(20) NOT NULL default '0', 
    21   tag_count bigint(20) NOT NULL default '0', 
    22   posts_private tinyint(1) NOT NULL default '0', 
    23   links_private tinyint(1) NOT NULL default '0', 
    24   type tinyint NOT NULL default '1', 
    25   PRIMARY KEY  (cat_ID), 
    26   KEY category_nicename (category_nicename) 
     13$wp_queries="CREATE TABLE $wpdb->terms ( 
     14 term_id bigint(20) NOT NULL auto_increment, 
     15 term_name varchar(55) NOT NULL default '', 
     16 term_slug varchar(200) NOT NULL default '', 
     17 term_group bigint(10) NOT NULL default 0, 
     18 PRIMARY KEY  (term_id), 
     19 UNIQUE KEY term_slug (term_slug) 
    2720) $charset_collate; 
     21CREATE TABLE $wpdb->term_taxonomy ( 
     22 term_taxonomy_id bigint(20) NOT NULL auto_increment, 
     23 term_id bigint(20) NOT NULL default 0, 
     24 taxonomy varchar(32) NOT NULL default '', 
     25 term_description longtext NOT NULL, 
     26 parent bigint(20) NOT NULL default 0, 
     27 count bigint(20) NOT NULL default 0, 
     28 PRIMARY KEY (term_taxonomy_id), 
     29 UNIQUE KEY (term_id, taxonomy) 
     30) $charset_collate; 
     31CREATE TABLE $wpdb->term_relationships ( 
     32 object_id bigint(20) NOT NULL default 0, 
     33 term_taxonomy_id bigint(20) NOT NULL default 0, 
     34 PRIMARY KEY  (object_id), 
     35 KEY (term_taxonomy_id) 
     36) $charset_collate; 
    2837CREATE TABLE $wpdb->comments ( 
    2938  comment_ID bigint(20) unsigned NOT NULL auto_increment, 
    3039  comment_post_ID int(11) NOT NULL default '0', 
     
    4554  KEY comment_approved (comment_approved), 
    4655  KEY comment_post_ID (comment_post_ID) 
    4756) $charset_collate; 
    48 CREATE TABLE $wpdb->link2cat ( 
    49   rel_id bigint(20) NOT NULL auto_increment, 
    50   link_id bigint(20) NOT NULL default '0', 
    51   category_id bigint(20) NOT NULL default '0', 
    52   PRIMARY KEY  (rel_id), 
    53   KEY link_id (link_id,category_id) 
    54 ) $charset_collate; 
    5557CREATE TABLE $wpdb->links ( 
    5658  link_id bigint(20) NOT NULL auto_increment, 
    5759  link_url varchar(255) NOT NULL default '', 
     
    8688  PRIMARY KEY  (option_id,blog_id,option_name), 
    8789  KEY option_name (option_name) 
    8890) $charset_collate; 
    89 CREATE TABLE $wpdb->post2cat ( 
    90   rel_id bigint(20) NOT NULL auto_increment, 
    91   post_id bigint(20) NOT NULL default '0', 
    92   category_id bigint(20) NOT NULL default '0', 
    93   rel_type varchar(64) NOT NULL default 'category', 
    94   PRIMARY KEY  (rel_id), 
    95   KEY post_id (post_id,category_id) 
    96 ) $charset_collate; 
    9791CREATE TABLE $wpdb->postmeta ( 
    9892  meta_id bigint(20) NOT NULL auto_increment, 
    9993  post_id bigint(20) NOT NULL default '0', 
     
    404398        } 
    405399} 
    406400 
    407 ?> 
    408  No newline at end of file 
     401?>