Ticket #9726: 9726.3.diff
| File 9726.3.diff, 4.2 KB (added by , 17 years ago) |
|---|
-
wp-includes/post.php
1737 1737 * @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) 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)); 1744 $hierarchical_post_types = apply_filters('hierarchical_post_types', array('page')); 1745 if ( $post_status == 'inherit' ) { 1746 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_status = 'inherit' AND ID != %d LIMIT 1"; 1747 $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_ID)); 1748 1749 if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) { 1750 $suffix = 2; 1751 do { 1752 $alt_post_name = substr($slug, 0, 200-(strlen($suffix)+1)). "-$suffix"; 1753 $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_ID)); 1754 $suffix++; 1755 } while ($post_name_check); 1756 $slug = $alt_post_name; 1749 1757 } 1750 1758 } elseif ( in_array($post_type, $hierarchical_post_types) ) { 1759 $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"; 1760 $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_ID, $post_parent)); 1761 1751 1762 if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) { 1752 1763 $suffix = 2; 1753 1764 do { 1754 1765 $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));1766 $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_ID, $post_parent)); 1756 1767 $suffix++; 1757 1768 } while ($post_name_check); 1758 1769 $slug = $alt_post_name; 1759 1770 } 1771 } else { 1772 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; 1773 $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_type, $post_ID)); 1774 1775 if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) { 1776 $suffix = 2; 1777 do { 1778 $alt_post_name = substr($slug, 0, 200-(strlen($suffix)+1)). "-$suffix"; 1779 $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_type, $post_ID)); 1780 $suffix++; 1781 } while ($post_name_check); 1782 $slug = $alt_post_name; 1783 } 1760 1784 } 1785 1761 1786 return $slug; 1762 1787 } 1763 1788 … … 2453 2478 $post_name = sanitize_title($post_name); 2454 2479 2455 2480 // 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 ));2481 $post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent); 2457 2482 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 }2468 2469 2483 if ( empty($post_date) ) 2470 2484 $post_date = current_time('mysql'); 2471 2485 if ( empty($post_date_gmt) )