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-includes/post.php

    r5271 r5289  
    459459}
    460460
    461 function wp_get_post_tags( $post_id = 0 ) {
    462     global $tag_cache, $blog_id;
    463 
    464     $post_id = (int) $post_id;
    465    
    466     if ( !isset( $tag_cache[$blog_id][$post_id] ) )
    467         update_post_category_cache( $post_id ); // loads $tag_cache
    468 
    469     return $tag_cache[$blog_id][$post_id];
    470 }
    471 
    472461function wp_get_recent_posts($num = 10) {
    473462    global $wpdb;
     
    531520        $comment_status  = apply_filters('comment_status_pre', $comment_status);
    532521        $ping_status     = apply_filters('ping_status_pre',    $ping_status);
    533         $tags_input      = apply_filters('tags_input_pre',     $tags_input);
    534522    }
    535523
     
    666654    }
    667655
    668     wp_set_post_categories( $post_ID, $post_category );
    669     wp_set_post_tags( $post_ID, $tags_input );
     656    wp_set_post_categories($post_ID, $post_category);
    670657
    671658    if ( 'page' == $post_type ) {
     
    785772}
    786773
    787 function wp_add_post_tags($post_id = 0, $tags = '') {
    788     return wp_set_post_tags($post_id, $tags, true);
    789 }
    790 
    791 function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) {
    792     /* $append - true = don't delete existing tags, just add on, false = replace the tags with the new tags */
    793     global $wpdb;
    794    
    795     $post_id = (int) $post_id;
    796    
    797     if ( !$post_id )
    798         return false;
    799    
    800     // prevent warnings for unintialized variables
    801     $tag_ids = array();
    802 
    803     if ( empty($tags) )
    804         $tags = array();
    805     $tags = (is_array($tags)) ? $tags : explode( ',', $tags );
    806    
    807     foreach ( $tags as $tag ) {
    808         $tag = trim( $tag );
    809         if ( !$tag_slug = sanitize_title( $tag ) )
    810             continue; // discard
    811         if ( !$tag_id = tag_exists( $tag ) )
    812             $tag_id = wp_create_tag( $tag );
    813         $tag_ids[] = $tag_id;
    814     }
    815 
    816     if ( empty($tag_ids) && ( !empty($tags) || $append ) )
    817         return false;
    818    
    819     $tag_ids = array_unique( $tag_ids );
    820    
    821     // First the old tags
    822     $old_tags = $wpdb->get_col("
    823         SELECT category_id
    824         FROM $wpdb->post2cat
    825         WHERE post_id = '$post_id' AND rel_type = 'tag'");
    826    
    827     if ( !$old_tags ) {
    828         $old_tags = array();
    829     } else {
    830         $old_tags = array_unique( $old_tags );
    831     }
    832    
    833     // Delete any?
    834     $delete_tags = array_diff( $old_tags, $tag_ids);
    835     if ( $delete_tags && !$append ) {
    836         foreach ( $delete_tags as $del ) {
    837             $wpdb->query("
    838                 DELETE FROM $wpdb->post2cat
    839                 WHERE category_id = '$del'
    840                     AND post_id = '$post_id'
    841                     AND rel_type = 'tag'
    842                 ");
    843         }
    844     }
    845    
    846     // Add any?
    847     $add_tags = array_diff( $tag_ids, $old_tags );
    848     if ( $add_tags ) {
    849         foreach ( $add_tags as $new_tag ) {
    850             $new_tag = (int) $new_tag;
    851             if ( !empty($new_tag) )
    852                 $wpdb->query("
    853                     INSERT INTO $wpdb->post2cat (post_id, category_id, rel_type)
    854                     VALUES ('$post_id', '$new_tag', 'tag')");
    855         }
    856     }
    857    
    858     // Update category counts.
    859     $all_affected_tags = array_unique( array_merge( $tag_ids, $old_tags ) );
    860     foreach ( $all_affected_tags as $tag_id ) {
    861         $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'" );
    862         $wpdb->query( "UPDATE $wpdb->categories SET tag_count = '$count', type = type | " . TAXONOMY_TAG . " WHERE cat_ID = '$tag_id'" );
    863         if ( $count == 0 )
    864             $wpdb->query( "UPDATE $wpdb->categories SET type = type & ~". TAXONOMY_TAG . " WHERE cat_ID = '$tag_id'" );
    865         clean_category_cache( $tag_id );
    866         do_action( 'edit_category', $tag_id );
    867         do_action( 'edit_tag', $tag_id );
    868     }
    869 }
    870 
    871774function wp_set_post_categories($post_ID = 0, $post_categories = array()) {
    872775    global $wpdb;
     
    883786        SELECT category_id
    884787        FROM $wpdb->post2cat
    885         WHERE post_id = '$post_ID' AND rel_type = 'category'");
     788        WHERE post_id = '$post_ID'");
    886789
    887790    if (!$old_categories) {
     
    899802                DELETE FROM $wpdb->post2cat
    900803                WHERE category_id = '$del'
    901                     AND post_id = '$post_ID' AND rel_type = 'category'
     804                    AND post_id = '$post_ID'
    902805                ");
    903806        }
     
    920823    $all_affected_cats = array_unique(array_merge($post_categories, $old_categories));
    921824    foreach ( $all_affected_cats as $cat_id ) {
    922         $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 = '$cat_id' AND rel_type = 'category'");
    923         $wpdb->query("UPDATE $wpdb->categories SET category_count = '$count', type = type | " . TAXONOMY_CATEGORY . " WHERE cat_ID = '$cat_id'");
     825        $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 = '$cat_id'");
     826        $wpdb->query("UPDATE $wpdb->categories SET category_count = '$count' WHERE cat_ID = '$cat_id'");
    924827        clean_category_cache($cat_id);
    925828        do_action('edit_category', $cat_id);
Note: See TracChangeset for help on using the changeset viewer.