| 1516 | | $post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent); |
| | 1517 | // If updating a published post, make slug unique only if it has changed. |
| | 1518 | // This prevents slugs for already published posts from being changed due to new uniqueness rules. |
| | 1519 | if ( !isset($previous_slug) || ('publish' != $previous_status) || ('publish' != $post_status) || ($previous_slug != $post_name)) |
| | 1520 | $post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent); |
| 1517 | 1521 | |
| 1518 | 1522 | // expected_slashed (everything!) |
| 1519 | 1523 | $data = compact( array( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'guid' ) ); |
| 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 | | } |
| 1751 | | if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) { |
| 1752 | | $suffix = 2; |
| 1753 | | do { |
| 1754 | | $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)); |
| 1756 | | $suffix++; |
| 1757 | | } while ($post_name_check); |
| 1758 | | $slug = $alt_post_name; |
| 1759 | | } |
| | 1746 | $original_slug = $slug; |
| | 1747 | |
| | 1748 | if ( in_array( $post_status, array( 'draft', 'pending' ) ) ) |
| | 1749 | return apply_filters('unique_post_slug', $slug, $original_slug, $post_ID, $post_status, $post_type, $post_parent); |
| | 1750 | |
| | 1751 | $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type != 'revision' AND post_status != 'draft' AND ID != %d LIMIT 1"; |
| | 1752 | $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_ID)); |
| | 1753 | if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) { |
| | 1754 | $suffix = 2; |
| | 1755 | do { |
| | 1756 | $alt_post_name = substr($slug, 0, 200-(strlen($suffix)+1)). "-$suffix"; |
| | 1757 | $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_ID)); |
| | 1758 | $suffix++; |
| | 1759 | } while ($post_name_check); |
| | 1760 | $slug = $alt_post_name; |