Ticket #20419: 20419.3.diff
File 20419.3.diff, 22.0 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/ajax-actions.php
1648 1648 } 1649 1649 } 1650 1650 1651 // Hack: wp_unique_post_slug() doesn't work for drafts, so we will fake that our post is published. 1652 if ( ! empty( $data['post_name'] ) && in_array( $post['post_status'], array( 'draft', 'pending' ) ) ) { 1653 $post['post_status'] = 'publish'; 1654 $data['post_name'] = wp_unique_post_slug( $data['post_name'], $post['ID'], $post['post_status'], $post['post_type'], $post['post_parent'] ); 1651 if ( ! empty( $data['post_name'] ) ) { 1652 $data['post_name'] = wp_unique_post_slug( $data['post_name'], $post_ID ); 1655 1653 } 1656 1654 1657 1655 // Update the post. -
src/wp-admin/includes/post.php
1206 1206 */ 1207 1207 function get_sample_permalink($id, $title = null, $name = null) { 1208 1208 $post = get_post( $id ); 1209 if ( ! $post ) 1209 if ( ! $post ) { 1210 1210 return array( '', '' ); 1211 } 1211 1212 1212 1213 $ptype = get_post_type_object($post->post_type); 1213 1214 … … 1215 1216 $original_date = $post->post_date; 1216 1217 $original_name = $post->post_name; 1217 1218 1218 // Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.1219 if ( in_array( $post->post_status, array( 'draft', 'pending', 'future' ) ) ) {1220 $post->post_status = 'publish';1221 $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);1222 }1223 1224 1219 // If the user wants to set a new name -- override the current one 1225 1220 // Note: if empty name is supplied -- use the title instead, see #6072 1226 if ( !is_null($name) ) 1227 $post->post_name = sanitize_title($name ? $name : $title, $post->ID); 1221 if ( !is_null( $name ) ) { 1222 $name = ( $name ) ? $name : $title; 1223 $post->post_name = sanitize_title( $name, $post->ID ); 1224 } 1225 // Otherwise, use our default behaviour 1226 else if ( empty( $post->post_name ) ) { 1227 $post->post_name = sanitize_title( $post->post_title, $post->ID ); 1228 } 1228 1229 1229 $post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent);1230 1231 1230 $post->filter = 'sample'; 1232 1231 1232 // wp_unique_post_slug() now knows this is a "sample" post 1233 $post->post_name = wp_unique_post_slug( $post->post_name, $post ); 1234 1233 1235 $permalink = get_permalink($post, true); 1234 1236 1235 1237 // Replace custom post_type Token with generic pagename token for ease of use. -
src/wp-includes/link-template.php
161 161 */ 162 162 $permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename ); 163 163 164 if ( '' != $permalink && !in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ) ) { 164 // Don't use pretty permalinks for non-published post statuses, otherwise we risk exposing the unpublished post slug (which may contain sensitive info) publicly. See #30910 165 // Ensure we're using pretty permalinks for sample permalinks. See #20419 166 if ( '' != $permalink && ( 'sample' === $post->filter || !in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ) ) ) { 165 167 $unixtime = strtotime($post->post_date); 166 168 167 169 $category = ''; -
src/wp-includes/post.php
3146 3146 */ 3147 3147 $post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, compact( array_keys( $postarr ) ), $postarr ); 3148 3148 3149 $post_name = wp_unique_post_slug( $post_name, $post_ID, $post_status, $post_type, $post_parent );3150 3151 3149 // Don't unslash. 3152 3150 $post_mime_type = isset( $postarr['post_mime_type'] ) ? $postarr['post_mime_type'] : ''; 3153 3151 … … 3165 3163 } 3166 3164 } 3167 3165 3166 $data['post_name'] = wp_unique_post_slug( $data['post_name'], (object) $data ); 3167 3168 3168 if ( 'attachment' === $post_type ) { 3169 3169 /** 3170 3170 * Filter attachment post data before it is updated in or added to the database. … … 3228 3228 } 3229 3229 3230 3230 if ( empty( $data['post_name'] ) && ! in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) { 3231 $data['post_name'] = wp_unique_post_slug( sanitize_title( $data['post_title'], $post_ID ), $post_ID, $data['post_status'], $post_type, $post_parent ); 3231 // This is a brand new post, so we want to mock a WP_Post object to pass wp_unique_post_slug() as much info 3232 // as we know about this post. This way wp_unique_post_slug() doesn't have to mock it itself, and we're 3233 // probably preventing a bug. 3234 $_post_data_for_slug = new WP_Post( (object) array( 3235 'ID' => $post_ID, 3236 'post_status' => $data['post_status'], 3237 'post_type' => $post_type, 3238 'post_parent' => $post_parent, 3239 ) ); 3240 $_slug = sanitize_title( $data['post_title'], $post_ID ); 3241 $data['post_name'] = wp_unique_post_slug( $_slug, $_post_data_for_slug ); 3242 unset( $_slug, $_post_data_for_slug ); // Make it clear we don't need this anymore 3243 3232 3244 $wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where ); 3233 3245 clean_post_cache( $post_ID ); 3234 3246 } … … 3542 3554 * @global wpdb $wpdb WordPress database abstraction object. 3543 3555 * @global WP_Rewrite $wp_rewrite 3544 3556 * 3545 * @param string $slugThe desired slug (post_name).3546 * @param int $post_ID PostID.3547 * @param string $post_status No uniqueness checks are made if the post is still draft or pending.3548 * @param string $post_type Post type.3549 * @param int $post_parent Post parent ID.3557 * @param string $slug The desired slug (post_name). 3558 * @param obj $post Post object or ID. 3559 * @param string $deprecated_post_status No uniqueness checks are made if the post is still draft or pending. 3560 * @param string $deprecated_post_type Post type from the post object. 3561 * @param int $deprecated_post_parent Post parent ID from the post object. 3550 3562 * @return string Unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) 3551 3563 */ 3552 function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) { 3553 if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) || ( 'inherit' == $post_status && 'revision' == $post_type ) ) 3564 function wp_unique_post_slug( $slug, $post, $deprecated_post_status = null, $deprecated_post_type = null, $deprecated_post_parent = null ) { 3565 if ( $deprecated_post_status || $deprecated_post_type || $deprecated_post_parent ) { 3566 _deprecated_argument( __FUNCTION__, '4.5' ); 3567 } 3568 3569 $_post = get_post( $post ); 3570 if ( ! $_post ) { 3571 // This is a brand new post, it doesn't exist in the DB or memory. Mock it. 3572 // The value of post_status, post_type, and post_parent don't matter. They're only present so that we don't throw a warning 3573 // when checking for backwards compatible (deprecated) values. 3574 $_post = new WP_Post( (object) array( 3575 'post_status' => 'publish', 3576 'post_type' => 'post', 3577 'post_parent' => 0, 3578 ) ); 3579 } 3580 $post = $_post; 3581 unset($_post); // Don't need this any more 3582 $post->post_status = ( $deprecated_post_status ) ? $deprecated_post_status : $post->post_status; 3583 $post->post_type = ( $deprecated_post_type ) ? $deprecated_post_type : $post->post_type; 3584 $post->post_parent = ( $deprecated_post_parent ) ? $deprecated_post_parent : $post->post_parent; 3585 3586 // There's a few circumstances where we don't want to check for uniqueness: auto-draft saves and revisions. 3587 if ( 'auto-draft' === $post->post_status || ( 'inherit' == $post->post_status && 'revision' == $post->post_type ) ) { 3554 3588 return $slug; 3589 } 3555 3590 3556 3591 global $wpdb, $wp_rewrite; 3557 3592 … … 3558 3593 $original_slug = $slug; 3559 3594 3560 3595 $feeds = $wp_rewrite->feeds; 3561 if ( ! is_array( $feeds ) ) 3596 if ( ! is_array( $feeds ) ) { 3562 3597 $feeds = array(); 3598 } 3563 3599 3564 if ( 'attachment' == $post_type ) {3600 if ( 'attachment' === $post->post_type ) { 3565 3601 // Attachment slugs must be unique across all types. 3566 3602 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1"; 3567 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post _ID ) );3603 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post->ID ) ); 3568 3604 3569 3605 /** 3570 3606 * Filter whether the post slug would make a bad attachment slug. … … 3578 3614 $suffix = 2; 3579 3615 do { 3580 3616 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 3581 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post _ID ) );3617 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post->ID ) ); 3582 3618 $suffix++; 3583 3619 } while ( $post_name_check ); 3584 3620 $slug = $alt_post_name; 3585 3621 } 3586 } elseif ( is_post_type_hierarchical( $post _type ) ) {3587 if ( 'nav_menu_item' == $post_type )3622 } elseif ( is_post_type_hierarchical( $post->post_type ) ) { 3623 if ( 'nav_menu_item' === $post->post_type ) { 3588 3624 return $slug; 3625 } 3589 3626 3590 3627 /* 3591 3628 * Page slugs must be unique within their own trees. Pages are in a separate … … 3592 3629 * namespace than posts so page slugs are allowed to overlap post slugs. 3593 3630 */ 3594 3631 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1"; 3595 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post _type, $post_ID, $post_parent ) );3632 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post->post_type, $post->ID, $post->post_parent ) ); 3596 3633 3597 3634 /** 3598 3635 * Filter whether the post slug would make a bad hierarchical post slug. … … 3604 3641 * @param string $post_type Post type. 3605 3642 * @param int $post_parent Post parent ID. 3606 3643 */ 3607 if ( $post_name_check || in_array( $slug, $feeds ) || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post _type, $post_parent ) ) {3644 if ( $post_name_check || in_array( $slug, $feeds ) || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post->post_type, $post->post_parent ) ) { 3608 3645 $suffix = 2; 3609 3646 do { 3610 3647 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 3611 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post _type, $post_ID, $post_parent ) );3648 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post->post_type, $post->ID, $post->post_parent ) ); 3612 3649 $suffix++; 3613 3650 } while ( $post_name_check ); 3614 3651 $slug = $alt_post_name; … … 3616 3653 } else { 3617 3654 // Post slugs must be unique across all posts. 3618 3655 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; 3619 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post _type, $post_ID ) );3656 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post->post_type, $post->ID ) ); 3620 3657 3621 3658 // Prevent new post slugs that could result in URLs that conflict with date archives. 3622 $ post = get_post( $post_ID );3659 $_post = get_post( $post->ID ); 3623 3660 $conflicts_with_date_archive = false; 3624 if ( 'post' === $post_type && ( ! $post || $post->post_name !== $slug ) && preg_match( '/^[0-9]+$/', $slug ) && $slug_num = intval( $slug ) ) { 3661 $slug_num = intval( $slug ); 3662 if ( 'post' === $post->post_type && ( ! $_post || $_post->post_name !== $slug ) && preg_match( '/^[0-9]+$/', $slug ) && $slug_num ) { 3625 3663 $permastructs = array_values( array_filter( explode( '/', get_option( 'permalink_structure' ) ) ) ); 3626 3664 $postname_index = array_search( '%postname%', $permastructs ); 3627 3628 3665 /* 3629 3666 * Potential date clashes are as follows: 3630 3667 * … … 3649 3686 * @param string $slug The post slug. 3650 3687 * @param string $post_type Post type. 3651 3688 */ 3652 if ( $post_name_check || in_array( $slug, $feeds ) || $conflicts_with_date_archive || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post _type ) ) {3689 if ( $post_name_check || in_array( $slug, $feeds ) || $conflicts_with_date_archive || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post->post_type ) ) { 3653 3690 $suffix = 2; 3654 3691 do { 3655 3692 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 3656 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post _type, $post_ID ) );3693 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post->post_type, $post->ID ) ); 3657 3694 $suffix++; 3658 3695 } while ( $post_name_check ); 3659 3696 $slug = $alt_post_name; … … 3672 3709 * @param int $post_parent Post parent ID 3673 3710 * @param string $original_slug The original post slug. 3674 3711 */ 3675 return apply_filters( 'wp_unique_post_slug', $slug, $post _ID, $post_status, $post_type, $post_parent, $original_slug );3712 return apply_filters( 'wp_unique_post_slug', $slug, $post->ID, $post->post_status, $post->post_type, $post->post_parent, $original_slug ); 3676 3713 } 3677 3714 3678 3715 /** -
tests/phpunit/tests/admin/includesPost.php
254 254 255 255 /** 256 256 * @ticket 30910 257 * @ticket 20419 257 258 */ 258 259 public function test_get_sample_permalink_should_return_pretty_permalink_for_posts_with_post_status_future() { 259 260 $permalink_structure = '%postname%'; … … 271 272 /** 272 273 * @ticket 30910 273 274 * @ticket 18306 275 * @ticket 20419 274 276 */ 275 277 public function test_get_sample_permalink_html_should_use_default_permalink_for_view_post_link_when_pretty_permalinks_are_disabled() { 276 278 wp_set_current_user( self::$admin_id ); … … 285 287 /** 286 288 * @ticket 30910 287 289 * @ticket 18306 290 * @ticket 20419 288 291 */ 289 292 public function test_get_sample_permalink_html_should_use_pretty_permalink_for_view_post_link_when_pretty_permalinks_are_enabled() { 290 293 $this->set_permalink_structure( '/%postname%/' ); … … 302 305 /** 303 306 * @ticket 32954 304 307 * @ticket 18306 308 * @ticket 20419 305 309 */ 306 310 public function test_get_sample_permalink_html_should_use_correct_permalink_for_view_post_link_when_changing_slug() { 307 311 $this->set_permalink_structure( '/%postname%/' ); -
tests/phpunit/tests/link.php
306 306 307 307 /** 308 308 * @ticket 30910 309 * @ticket 20419 309 310 */ 310 311 public function test_get_permalink_should_not_reveal_post_name_for_post_with_post_status_future() { 311 312 update_option( 'permalink_structure','/%year%/%monthnum%/%day%/%postname%/' ); … … 324 325 325 326 /** 326 327 * @ticket 30910 328 * @ticket 20419 327 329 */ 328 330 public function test_get_permalink_should_not_reveal_post_name_for_cpt_with_post_status_future() { 329 331 update_option( 'permalink_structure','/%year%/%monthnum%/%day%/%postname%/' ); -
tests/phpunit/tests/post/wpUniquePostSlug.php
31 31 'post_title' => $post_title, 32 32 ); 33 33 34 $id = $this->post_ids[] = wp_insert_post( $post );34 $id = $this->post_ids[] = self::factory()->post->create( $post ); 35 35 } 36 36 37 37 $post = get_post( $id ); … … 41 41 42 42 /** 43 43 * @ticket 18962 44 * @expectedDeprecated wp_unique_post_slug 44 45 */ 45 46 public function test_with_multiple_hierarchies() { 46 47 register_post_type( 'post-type-1', array( 'hierarchical' => true ) ); … … 67 68 68 69 /** 69 70 * @ticket 30339 71 * @expectedDeprecated wp_unique_post_slug 70 72 */ 71 73 public function test_with_hierarchy() { 72 74 register_post_type( 'post-type-1', array( 'hierarchical' => true ) ); … … 90 92 91 93 /** 92 94 * @ticket 18962 95 * @expectedDeprecated wp_unique_post_slug 93 96 */ 94 97 function test_wp_unique_post_slug_with_hierarchy_and_attachments() { 95 98 register_post_type( 'post-type-1', array( 'hierarchical' => true ) ); … … 104 107 $args = array( 105 108 'post_mime_type' => 'image/jpeg', 106 109 'post_type' => 'attachment', 107 'post_name' => 'image' 110 'post_name' => 'image', 111 'post_status' => 'inherit', 108 112 ); 109 113 $attachment = self::factory()->attachment->create_object( 'image.jpg', $one, $args ); 110 114 … … 134 138 'post_type' => 'post', 135 139 'post_name' => 'foo', 136 140 ) ); 137 138 141 $p2 = self::factory()->post->create( array( 139 142 'post_type' => 'post', 143 'post_status' => $status, 144 'post_type' => 'post', 145 'post_parent' => 0, 140 146 ) ); 141 147 142 $actual = wp_unique_post_slug( 'foo', $p2 , $status, 'post', 0);148 $actual = wp_unique_post_slug( 'foo', $p2 ); 143 149 144 150 $this->assertSame( 'foo', $actual ); 145 151 } … … 146 152 147 153 public function whitelist_post_statuses() { 148 154 return array( 149 array( 'draft' ), 150 array( 'pending' ), 155 // Removed 'draft' and 'pending', see #20419 151 156 array( 'auto-draft' ), 152 157 ); 153 158 } … … 160 165 161 166 $p2 = self::factory()->post->create( array( 162 167 'post_type' => 'post', 168 'post_status' => 'inherit', 169 'post_type' => 'revision', 170 'post_parent' => 0, 163 171 ) ); 164 172 165 $actual = wp_unique_post_slug( 'foo', $p2 , 'inherit', 'revision', 0);173 $actual = wp_unique_post_slug( 'foo', $p2 ); 166 174 167 175 $this->assertSame( 'foo', $actual ); 168 176 } … … 176 184 $p = self::factory()->post->create( array( 177 185 'post_type' => 'post', 178 186 'post_name' => 'foo', 187 'post_status' => 'publish', 188 'post_type' => 'post', 189 'post_parent' => 0, 179 190 ) ); 180 191 181 $found = wp_unique_post_slug( '2015', $p , 'publish', 'post', 0);192 $found = wp_unique_post_slug( '2015', $p ); 182 193 $this->assertEquals( '2015-2', $found ); 183 194 } 184 195 … … 192 203 'post_type' => 'post', 193 204 'post_name' => 'foo', 194 205 'post_status' => 'publish', 206 'post_type' => 'post', 207 'post_parent' => 0, 195 208 ) ); 196 209 197 $found = wp_unique_post_slug( '2015', $p , 'publish', 'post', 0);210 $found = wp_unique_post_slug( '2015', $p ); 198 211 $this->assertEquals( '2015-2', $found ); 199 212 } 200 213 … … 207 220 $p = self::factory()->post->create( array( 208 221 'post_type' => 'post', 209 222 'post_name' => 'foo', 223 'post_status' => 'publish', 224 'post_type' => 'post', 225 'post_parent' => 0, 210 226 ) ); 211 227 212 $found = wp_unique_post_slug( '2015', $p , 'publish', 'post', 0);228 $found = wp_unique_post_slug( '2015', $p ); 213 229 $this->assertEquals( '2015', $found ); 214 230 } 215 231 … … 222 238 $p = self::factory()->post->create( array( 223 239 'post_type' => 'post', 224 240 'post_name' => 'foo', 241 'post_status' => 'publish', 242 'post_type' => 'post', 243 'post_parent' => 0, 225 244 ) ); 226 245 227 $found = wp_unique_post_slug( '11', $p , 'publish', 'post', 0);246 $found = wp_unique_post_slug( '11', $p ); 228 247 $this->assertEquals( '11-2', $found ); 229 248 } 230 249 … … 237 256 $p = self::factory()->post->create( array( 238 257 'post_type' => 'post', 239 258 'post_name' => 'foo', 259 'post_status' => 'publish', 260 'post_type' => 'post', 261 'post_parent' => 0, 240 262 ) ); 241 263 242 $found = wp_unique_post_slug( '11', $p , 'publish', 'post', 0);264 $found = wp_unique_post_slug( '11', $p ); 243 265 $this->assertEquals( '11', $found ); 244 266 } 245 267 … … 252 274 $p = self::factory()->post->create( array( 253 275 'post_type' => 'post', 254 276 'post_name' => 'foo', 277 'post_status' => 'publish', 278 'post_type' => 'post', 279 'post_parent' => 0, 255 280 ) ); 256 281 257 $found = wp_unique_post_slug( '13', $p , 'publish', 'post', 0);282 $found = wp_unique_post_slug( '13', $p ); 258 283 $this->assertEquals( '13', $found ); 259 284 } 260 285 … … 267 292 $p = self::factory()->post->create( array( 268 293 'post_type' => 'post', 269 294 'post_name' => 'foo', 295 'post_status' => 'publish', 296 'post_type' => 'post', 297 'post_parent' => 0, 270 298 ) ); 271 299 272 $found = wp_unique_post_slug( '30', $p , 'publish', 'post', 0);300 $found = wp_unique_post_slug( '30', $p ); 273 301 $this->assertEquals( '30-2', $found ); 274 302 } 275 303 … … 282 310 $p = self::factory()->post->create( array( 283 311 'post_type' => 'post', 284 312 'post_name' => 'foo', 313 'post_status' => 'publish', 314 'post_type' => 'post', 315 'post_parent' => 0, 285 316 ) ); 286 317 287 $found = wp_unique_post_slug( '30', $p , 'publish', 'post', 0);318 $found = wp_unique_post_slug( '30', $p ); 288 319 $this->assertEquals( '30', $found ); 289 320 } 290 321 … … 297 328 $p = self::factory()->post->create( array( 298 329 'post_type' => 'post', 299 330 'post_name' => 'foo', 331 'post_status' => 'publish', 332 'post_type' => 'post', 333 'post_parent' => 0, 300 334 ) ); 301 335 302 $found = wp_unique_post_slug( '32', $p , 'publish', 'post', 0);336 $found = wp_unique_post_slug( '32', $p ); 303 337 $this->assertEquals( '32', $found ); 304 338 } 339 340 /** 341 * @ticket 20419 342 * @expectedDeprecated wp_unique_post_slug 343 */ 344 public function test_post_status_parameter_with_deprecated_params() { 345 $slug = wp_unique_post_slug( 'foo', 0, 'publish', 'post', 0 ); 346 $this->assertSame( 'foo', $slug ); 347 } 348 349 /** 350 * @ticket 20419 351 * @expectedDeprecated wp_unique_post_slug 352 */ 353 public function test_post_status_parameter_with_some_deprecated_params() { 354 $post = new WP_Post( (object) array( 355 'post_name' => 'foo', 356 'post_status' => 'publish', 357 'post_type' => 'post', 358 ) ); 359 360 $slug = wp_unique_post_slug( 'foo', $post, 'draft', 'page' ); 361 $this->assertSame( 'foo', $slug ); 362 } 363 364 /** 365 * @ticket 20419 366 */ 367 public function test_post_status_parameter_with_post_object() { 368 $post = new WP_Post( (object) array( 369 'post_name' => 'foo', 370 'post_status' => 'publish', 371 ) ); 372 373 $slug = wp_unique_post_slug( $post->post_name, $post ); 374 $this->assertSame( 'foo', $slug ); 375 } 376 377 /** 378 * @ticket 20419 379 */ 380 public function test_post_status_parameter_with_post_id() { 381 $post_id = self::factory()->post->create( array( 382 'post_name' => 'foo', 383 'post_status' => 'publish', 384 'post_type' => 'post', 385 ) ); 386 387 $slug = wp_unique_post_slug( 'foo', $post_id ); 388 $this->assertSame( 'foo', $slug ); 389 } 390 305 391 }