Changeset 11467
- Timestamp:
- 05/27/2009 04:21:53 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/post.php
r11461 r11467 1738 1738 */ 1739 1739 function wp_unique_post_slug($slug, $post_ID, $post_status, $post_type, $post_parent) { 1740 if ( in_array( $post_status, array( 'draft', 'pending' ) ) ) 1741 return $slug; 1742 1740 1743 global $wpdb, $wp_rewrite; 1741 if ( !in_array( $post_status, array( 'draft', 'pending' ) ) ) { 1742 $hierarchical_post_types = apply_filters('hierarchical_post_types', array('page', 'attachment')); 1743 if ( in_array($post_type, $hierarchical_post_types) ) { 1744 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( '" . implode("', '", $wpdb->escape($hierarchical_post_types)) . "' ) AND ID != %d AND post_parent = %d LIMIT 1"; 1745 $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_ID, $post_parent)); 1746 } else { 1747 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d AND post_parent = %d LIMIT 1"; 1748 $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_type, $post_ID, $post_parent)); 1749 } 1750 1744 $hierarchical_post_types = apply_filters('hierarchical_post_types', array('page')); 1745 if ( 'attachment' == $post_type ) { 1746 // Attachment slugs must be unique across all types. 1747 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1"; 1748 $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_ID)); 1749 1751 1750 if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) { 1752 1751 $suffix = 2; 1753 1752 do { 1754 1753 $alt_post_name = substr($slug, 0, 200-(strlen($suffix)+1)). "-$suffix"; 1755 $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_ type, $post_ID, $post_parent));1754 $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_ID)); 1756 1755 $suffix++; 1757 1756 } while ($post_name_check); 1758 1757 $slug = $alt_post_name; 1759 1758 } 1760 } 1759 } elseif ( in_array($post_type, $hierarchical_post_types) ) { 1760 // Page slugs must be unique within their own trees. Pages are in a 1761 // separate namespace than posts so page slugs are allowed to overlap post slugs. 1762 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( '" . implode("', '", $wpdb->escape($hierarchical_post_types)) . "' ) AND ID != %d AND post_parent = %d LIMIT 1"; 1763 $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_ID, $post_parent)); 1764 1765 if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) { 1766 $suffix = 2; 1767 do { 1768 $alt_post_name = substr($slug, 0, 200-(strlen($suffix)+1)). "-$suffix"; 1769 $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_ID, $post_parent)); 1770 $suffix++; 1771 } while ($post_name_check); 1772 $slug = $alt_post_name; 1773 } 1774 } else { 1775 // Post slugs must be unique across all posts. 1776 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; 1777 $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_type, $post_ID)); 1778 1779 if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) { 1780 $suffix = 2; 1781 do { 1782 $alt_post_name = substr($slug, 0, 200-(strlen($suffix)+1)). "-$suffix"; 1783 $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_type, $post_ID)); 1784 $suffix++; 1785 } while ($post_name_check); 1786 $slug = $alt_post_name; 1787 } 1788 } 1789 1761 1790 return $slug; 1762 1791 } … … 2454 2483 2455 2484 // expected_slashed ($post_name) 2456 $post_name_check = $wpdb->get_var( $wpdb->prepare( "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_status = 'inherit' AND ID != %d LIMIT 1", $post_name, $post_ID ) ); 2457 2458 if ( $post_name_check ) { 2459 $suffix = 2; 2460 while ( $post_name_check ) { 2461 $alt_post_name = $post_name . "-$suffix"; 2462 // expected_slashed ($alt_post_name, $post_name) 2463 $post_name_check = $wpdb->get_var( $wpdb->prepare( "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_status = 'inherit' AND ID != %d LIMIT 1", $alt_post_name, $post_ID ) ); 2464 $suffix++; 2465 } 2466 $post_name = $alt_post_name; 2467 } 2485 $post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent); 2468 2486 2469 2487 if ( empty($post_date) )
Note: See TracChangeset
for help on using the changeset viewer.