Changeset 5289 for branches/2.2/wp-includes/post.php
- Timestamp:
- 04/19/2007 10:26:52 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2/wp-includes/post.php
r5271 r5289 459 459 } 460 460 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_cache468 469 return $tag_cache[$blog_id][$post_id];470 }471 472 461 function wp_get_recent_posts($num = 10) { 473 462 global $wpdb; … … 531 520 $comment_status = apply_filters('comment_status_pre', $comment_status); 532 521 $ping_status = apply_filters('ping_status_pre', $ping_status); 533 $tags_input = apply_filters('tags_input_pre', $tags_input);534 522 } 535 523 … … 666 654 } 667 655 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); 670 657 671 658 if ( 'page' == $post_type ) { … … 785 772 } 786 773 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 variables801 $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; // discard811 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 tags822 $old_tags = $wpdb->get_col("823 SELECT category_id824 FROM $wpdb->post2cat825 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->post2cat839 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 871 774 function wp_set_post_categories($post_ID = 0, $post_categories = array()) { 872 775 global $wpdb; … … 883 786 SELECT category_id 884 787 FROM $wpdb->post2cat 885 WHERE post_id = '$post_ID' AND rel_type = 'category'");788 WHERE post_id = '$post_ID'"); 886 789 887 790 if (!$old_categories) { … … 899 802 DELETE FROM $wpdb->post2cat 900 803 WHERE category_id = '$del' 901 AND post_id = '$post_ID' AND rel_type = 'category'804 AND post_id = '$post_ID' 902 805 "); 903 806 } … … 920 823 $all_affected_cats = array_unique(array_merge($post_categories, $old_categories)); 921 824 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'"); 924 827 clean_category_cache($cat_id); 925 828 do_action('edit_category', $cat_id);
Note: See TracChangeset
for help on using the changeset viewer.