Ticket #38928: 38928.5.diff
File 38928.5.diff, 22.0 KB (added by , 8 years ago) |
---|
-
src/wp-includes/class-wp-customize-manager.php
diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php index 1f5da60..45f4435 100644
final class WP_Customize_Manager { 971 971 $starter_content_auto_draft_post_ids = array_merge( $starter_content_auto_draft_post_ids, $changeset_data['nav_menus_created_posts']['value'] ); 972 972 } 973 973 974 // Make an index of all the posts needed and what their slugs are. 975 $needed_posts = array(); 976 $attachments = $this->prepare_starter_content_attachments( $attachments ); 977 foreach ( $attachments as $attachment ) { 978 $key = 'attachment:' . $attachment['post_name']; 979 $needed_posts[ $key ] = true; 980 } 981 foreach ( array_keys( $posts ) as $post_symbol ) { 982 if ( empty( $posts[ $post_symbol ]['post_name'] ) && empty( $posts[ $post_symbol ]['post_title'] ) ) { 983 unset( $posts[ $post_symbol ] ); 984 continue; 985 } 986 if ( empty( $posts[ $post_symbol ]['post_name'] ) ) { 987 $posts[ $post_symbol ]['post_name'] = sanitize_title( $posts[ $post_symbol ]['post_title'] ); 988 } 989 if ( empty( $posts[ $post_symbol ]['post_type'] ) ) { 990 $posts[ $post_symbol ]['post_type'] = 'post'; 991 } 992 $needed_posts[ $posts[ $post_symbol ]['post_type'] . ':' . $posts[ $post_symbol ]['post_name'] ] = true; 993 } 994 $all_post_slugs = array_merge( 995 wp_list_pluck( $attachments, 'post_name' ), 996 wp_list_pluck( $posts, 'post_name' ) 997 ); 998 999 // Re-use auto-draft starter content posts referenced in the current customized state. 974 1000 $existing_starter_content_posts = array(); 975 1001 if ( ! empty( $starter_content_auto_draft_post_ids ) ) { 976 1002 $existing_posts_query = new WP_Query( array( … … final class WP_Customize_Manager { 984 1010 } 985 1011 } 986 1012 1013 // Re-use non-auto-draft posts. 1014 if ( ! empty( $all_post_slugs ) ) { 1015 $existing_posts_query = new WP_Query( array( 1016 'post_name__in' => $all_post_slugs, 1017 'post_status' => array_diff( get_post_stati(), array( 'auto-draft' ) ), 1018 'post_type' => 'any', 1019 'number' => -1, 1020 ) ); 1021 foreach ( $existing_posts_query->posts as $existing_post ) { 1022 $key = $existing_post->post_type . ':' . $existing_post->post_name; 1023 if ( isset( $needed_posts[ $key ] ) && ! isset( $existing_starter_content_posts[ $key ] ) ) { 1024 $existing_starter_content_posts[ $key ] = $existing_post; 1025 } 1026 } 1027 } 1028 987 1029 // Attachments are technically posts but handled differently. 988 1030 if ( ! empty( $attachments ) ) { 989 // Such is The WordPress Way.990 require_once( ABSPATH . 'wp-admin/includes/file.php' );991 require_once( ABSPATH . 'wp-admin/includes/media.php' );992 require_once( ABSPATH . 'wp-admin/includes/image.php' );993 1031 994 1032 $attachment_ids = array(); 995 1033 996 1034 foreach ( $attachments as $symbol => $attachment ) { 997 998 // A file is required and URLs to files are not currently allowed. 999 if ( empty( $attachment['file'] ) || preg_match( '#^https?://$#', $attachment['file'] ) ) { 1000 continue; 1001 } 1002 1003 $file_array = array(); 1004 $file_path = null; 1005 if ( file_exists( $attachment['file'] ) ) { 1006 $file_path = $attachment['file']; // Could be absolute path to file in plugin. 1007 } elseif ( is_child_theme() && file_exists( get_stylesheet_directory() . '/' . $attachment['file'] ) ) { 1008 $file_path = get_stylesheet_directory() . '/' . $attachment['file']; 1009 } elseif ( file_exists( get_template_directory() . '/' . $attachment['file'] ) ) { 1010 $file_path = get_template_directory() . '/' . $attachment['file']; 1011 } else { 1012 continue; 1013 } 1014 $file_array['name'] = basename( $attachment['file'] ); 1015 1016 // Skip file types that are not recognized. 1017 $checked_filetype = wp_check_filetype( $file_array['name'] ); 1018 if ( empty( $checked_filetype['type'] ) ) { 1019 continue; 1020 } 1021 1022 // Ensure post_name is set since not automatically derived from post_title for new auto-draft posts. 1023 if ( empty( $attachment['post_name'] ) ) { 1024 if ( ! empty( $attachment['post_title'] ) ) { 1025 $attachment['post_name'] = sanitize_title( $attachment['post_title'] ); 1026 } else { 1027 $attachment['post_name'] = sanitize_title( preg_replace( '/\.\w+$/', '', $file_array['name'] ) ); 1028 } 1029 } 1030 1035 $file_array = array( 1036 'name' => $attachment['file_name'], 1037 ); 1038 $file_path = $attachment['file_path']; 1031 1039 $attachment_id = null; 1032 1040 $attached_file = null; 1033 1041 if ( isset( $existing_starter_content_posts[ 'attachment:' . $attachment['post_name'] ] ) ) { … … final class WP_Customize_Manager { 1080 1088 } 1081 1089 1082 1090 $attachment_ids[ $symbol ] = $attachment_id; 1083 $starter_content_auto_draft_post_ids = array_merge( $starter_content_auto_draft_post_ids, array_values( $attachment_ids ) );1084 1091 } 1092 $starter_content_auto_draft_post_ids = array_merge( $starter_content_auto_draft_post_ids, array_values( $attachment_ids ) ); 1085 1093 } 1086 1094 1087 1095 // Posts & pages. 1088 1096 if ( ! empty( $posts ) ) { 1089 1097 foreach ( array_keys( $posts ) as $post_symbol ) { 1090 if ( empty( $posts[ $post_symbol ]['post_type'] ) ) {1098 if ( empty( $posts[ $post_symbol ]['post_type'] ) || empty( $posts[ $post_symbol ]['post_name'] ) ) { 1091 1099 continue; 1092 1100 } 1093 1101 $post_type = $posts[ $post_symbol ]['post_type']; … … final class WP_Customize_Manager { 1209 1217 1210 1218 // Options. 1211 1219 foreach ( $options as $name => $value ) { 1212 if ( preg_match( '/^{{(?P<symbol>.+)}}$/', $value, $matches ) && isset( $posts[ $matches['symbol'] ] ) ) { 1213 $value = $posts[ $matches['symbol'] ]['ID']; 1220 if ( preg_match( '/^{{(?P<symbol>.+)}}$/', $value, $matches ) ) { 1221 if ( isset( $posts[ $matches['symbol'] ] ) ) { 1222 $value = $posts[ $matches['symbol'] ]['ID']; 1223 } elseif ( isset( $attachment_ids[ $matches['symbol'] ] ) ) { 1224 $value = $attachment_ids[ $matches['symbol'] ]; 1225 } else { 1226 continue; 1227 } 1214 1228 } 1215 1229 1216 1230 if ( empty( $changeset_data[ $name ] ) || ! empty( $changeset_data[ $name ]['starter_content'] ) ) { … … final class WP_Customize_Manager { 1221 1235 1222 1236 // Theme mods. 1223 1237 foreach ( $theme_mods as $name => $value ) { 1224 if ( preg_match( '/^{{(?P<symbol>.+)}}$/', $value, $matches ) && isset( $posts[ $matches['symbol'] ] ) ) { 1225 $value = $posts[ $matches['symbol'] ]['ID']; 1238 if ( preg_match( '/^{{(?P<symbol>.+)}}$/', $value, $matches ) ) { 1239 if ( isset( $posts[ $matches['symbol'] ] ) ) { 1240 $value = $posts[ $matches['symbol'] ]['ID']; 1241 } elseif ( isset( $attachment_ids[ $matches['symbol'] ] ) ) { 1242 $value = $attachment_ids[ $matches['symbol'] ]; 1243 } else { 1244 continue; 1245 } 1246 } 1247 1248 // Handle header image as special case since setting has a legacy format. 1249 if ( 'header_image' === $name ) { 1250 $name = 'header_image_data'; 1251 $metadata = wp_get_attachment_metadata( $value ); 1252 if ( empty( $metadata ) ) { 1253 continue; 1254 } 1255 $value = array( 1256 'attachment_id' => $value, 1257 'url' => wp_get_attachment_url( $value ), 1258 'height' => $metadata['height'], 1259 'width' => $metadata['width'], 1260 ); 1226 1261 } 1227 1262 1228 1263 if ( empty( $changeset_data[ $name ] ) || ! empty( $changeset_data[ $name ]['starter_content'] ) ) { … … final class WP_Customize_Manager { 1241 1276 } 1242 1277 1243 1278 /** 1279 * Prepare starter content attachments. 1280 * 1281 * Ensure that the attachments are valid and that they have slugs and file name/path. 1282 * 1283 * @since 4.7.0 1284 * @access private 1285 * 1286 * @param array $attachments Attachments. 1287 * @return array Prepared attachments. 1288 */ 1289 protected function prepare_starter_content_attachments( $attachments ) { 1290 $prepared_attachments = array(); 1291 if ( empty( $attachments ) ) { 1292 return $prepared_attachments; 1293 } 1294 1295 // Such is The WordPress Way. 1296 require_once( ABSPATH . 'wp-admin/includes/file.php' ); 1297 require_once( ABSPATH . 'wp-admin/includes/media.php' ); 1298 require_once( ABSPATH . 'wp-admin/includes/image.php' ); 1299 1300 foreach ( $attachments as $symbol => $attachment ) { 1301 1302 // A file is required and URLs to files are not currently allowed. 1303 if ( empty( $attachment['file'] ) || preg_match( '#^https?://$#', $attachment['file'] ) ) { 1304 continue; 1305 } 1306 1307 $file_path = null; 1308 if ( file_exists( $attachment['file'] ) ) { 1309 $file_path = $attachment['file']; // Could be absolute path to file in plugin. 1310 } elseif ( is_child_theme() && file_exists( get_stylesheet_directory() . '/' . $attachment['file'] ) ) { 1311 $file_path = get_stylesheet_directory() . '/' . $attachment['file']; 1312 } elseif ( file_exists( get_template_directory() . '/' . $attachment['file'] ) ) { 1313 $file_path = get_template_directory() . '/' . $attachment['file']; 1314 } else { 1315 continue; 1316 } 1317 $file_name = basename( $attachment['file'] ); 1318 1319 // Skip file types that are not recognized. 1320 $checked_filetype = wp_check_filetype( $file_name ); 1321 if ( empty( $checked_filetype['type'] ) ) { 1322 continue; 1323 } 1324 1325 // Ensure post_name is set since not automatically derived from post_title for new auto-draft posts. 1326 if ( empty( $attachment['post_name'] ) ) { 1327 if ( ! empty( $attachment['post_title'] ) ) { 1328 $attachment['post_name'] = sanitize_title( $attachment['post_title'] ); 1329 } else { 1330 $attachment['post_name'] = sanitize_title( preg_replace( '/\.\w+$/', '', $file_name ) ); 1331 } 1332 } 1333 1334 $attachment['file_name'] = $file_name; 1335 $attachment['file_path'] = $file_path; 1336 $prepared_attachments[ $symbol ] = $attachment; 1337 } 1338 return $prepared_attachments; 1339 } 1340 1341 /** 1244 1342 * Save starter content changeset. 1245 1343 * 1246 1344 * @since 4.7.0 -
src/wp-includes/customize/class-wp-customize-header-image-setting.php
diff --git src/wp-includes/customize/class-wp-customize-header-image-setting.php src/wp-includes/customize/class-wp-customize-header-image-setting.php index 98b79ae..af5c516 100644
final class WP_Customize_Header_Image_Setting extends WP_Customize_Setting { 29 29 public function update( $value ) { 30 30 global $custom_image_header; 31 31 32 // If _custom_header_background_just_in_time() fails to initialize $custom_image_header when not is_admin(). 33 if ( empty( $custom_image_header ) ) { 34 require_once( ABSPATH . 'wp-admin/custom-header.php' ); 35 $args = get_theme_support( 'custom-header' ); 36 $admin_head_callback = isset( $args[0]['admin-head-callback'] ) ? $args[0]['admin-head-callback'] : null; 37 $admin_preview_callback = isset( $args[0]['admin-preview-callback'] ) ? $args[0]['admin-preview-callback'] : null; 38 $custom_image_header = new Custom_Image_Header( $admin_head_callback, $admin_preview_callback ); 39 } 40 32 41 // If the value doesn't exist (removed or random), 33 42 // use the header_image value. 34 43 if ( ! $value ) -
src/wp-includes/post.php
diff --git src/wp-includes/post.php src/wp-includes/post.php index 620d1e4..2c70fdd 100644
function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p 3673 3673 3674 3674 if ( 'attachment' == $post_type ) { 3675 3675 // Attachment slugs must be unique across all types. 3676 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_ name = %s AND ID != %d LIMIT 1";3676 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_status != 'auto-draft' AND post_name = %s AND ID != %d LIMIT 1"; 3677 3677 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID ) ); 3678 3678 3679 3679 /** … … function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p 3701 3701 * Page slugs must be unique within their own trees. Pages are in a separate 3702 3702 * namespace than posts so page slugs are allowed to overlap post slugs. 3703 3703 */ 3704 $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";3704 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_status != 'auto-draft' AND post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1"; 3705 3705 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID, $post_parent ) ); 3706 3706 3707 3707 /** … … function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p 3725 3725 } 3726 3726 } else { 3727 3727 // Post slugs must be unique across all posts. 3728 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_ name = %s AND post_type = %s AND ID != %d LIMIT 1";3728 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_status != 'auto-draft' AND post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; 3729 3729 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) ); 3730 3730 3731 3731 // Prevent new post slugs that could result in URLs that conflict with date archives. -
tests/phpunit/tests/customize/manager.php
diff --git tests/phpunit/tests/customize/manager.php tests/phpunit/tests/customize/manager.php index f487990..a138bef 100644
class Tests_WP_Customize_Manager extends WP_UnitTestCase { 314 314 function test_import_theme_starter_content() { 315 315 wp_set_current_user( self::$admin_user_id ); 316 316 register_nav_menu( 'top', 'Top' ); 317 add_theme_support( 'custom-logo' ); 318 add_theme_support( 'custom-header' ); 319 add_theme_support( 'custom-backgorund' ); 320 321 $canola_file = DIR_TESTDATA . '/images/canola.jpg'; 322 $existing_canola_attachment_id = self::factory()->attachment->create_object( $canola_file, 0, array( 323 'post_mime_type' => 'image/jpeg', 324 'post_type' => 'attachment', 325 'post_name' => 'canola', 326 ) ); 327 $existing_published_home_page_id = $this->factory()->post->create( array( 328 'post_name' => 'home', 329 'post_type' => 'page', 330 'post_status' => 'publish' 331 ) ); 332 $existing_auto_draft_about_page_id = $this->factory()->post->create( array( 333 'post_name' => 'about', 334 'post_type' => 'page', 335 'post_status' => 'auto-draft' 336 ) ); 317 337 318 338 global $wp_customize; 319 339 $wp_customize = new WP_Customize_Manager(); … … class Tests_WP_Customize_Manager extends WP_UnitTestCase { 351 371 'custom' => array( 352 372 'post_type' => 'post', 353 373 'post_title' => 'Custom', 354 'thumbnail' => '{{ featured-image-logo}}',374 'thumbnail' => '{{waffles}}', 355 375 ), 356 376 ), 357 377 'attachments' => array( 358 ' featured-image-logo' => array(359 'post_title' => ' Featured Image',360 'post_content' => ' Attachment Description',361 'post_excerpt' => ' Attachment Caption',378 'waffles' => array( 379 'post_title' => 'Waffles', 380 'post_content' => 'Waffles Attachment Description', 381 'post_excerpt' => 'Waffles Attachment Caption', 362 382 'file' => DIR_TESTDATA . '/images/waffles.jpg', 363 383 ), 384 'canola' => array( 385 'post_title' => 'Canola', 386 'post_content' => 'Canola Attachment Description', 387 'post_excerpt' => 'Canola Attachment Caption', 388 'file' => DIR_TESTDATA . '/images/canola.jpg', 389 ), 364 390 ), 365 391 'options' => array( 366 392 'blogname' => 'Starter Content Title', … … class Tests_WP_Customize_Manager extends WP_UnitTestCase { 369 395 'page_on_front' => '{{home}}', 370 396 'page_for_posts' => '{{blog}}', 371 397 ), 398 'theme_mods' => array( 399 'custom_logo' => '{{canola}}', 400 'header_image' => '{{waffles}}', 401 'background_image' => '{{waffles}}', 402 ), 372 403 ); 373 404 374 405 add_theme_support( 'starter-content', $starter_content_config ); … … class Tests_WP_Customize_Manager extends WP_UnitTestCase { 378 409 $expected_setting_ids = array( 379 410 'blogname', 380 411 'blogdescription', 412 'custom_logo', 413 'header_image_data', 414 'background_image', 381 415 'widget_text[2]', 382 416 'widget_meta[3]', 383 417 'sidebars_widgets[sidebar-1]', … … class Tests_WP_Customize_Manager extends WP_UnitTestCase { 406 440 $this->assertEquals( array( 'text-2', 'meta-3' ), $changeset_values['sidebars_widgets[sidebar-1]'] ); 407 441 408 442 $posts_by_name = array(); 409 $this->assertCount( 5, $changeset_values['nav_menus_created_posts'] ); 443 $this->assertCount( 6, $changeset_values['nav_menus_created_posts'] ); 444 $this->assertContains( $existing_published_home_page_id, $changeset_values['nav_menus_created_posts'], 'Expected reuse of non-auto-draft posts.' ); 445 $this->assertContains( $existing_canola_attachment_id, $changeset_values['nav_menus_created_posts'], 'Expected reuse of non-auto-draft attachment.' ); 446 $this->assertNotContains( $existing_auto_draft_about_page_id, $changeset_values['nav_menus_created_posts'], 'Expected non-reuse of auto-draft posts.' ); 410 447 foreach ( $changeset_values['nav_menus_created_posts'] as $post_id ) { 411 448 $post = get_post( $post_id ); 412 $this->assertEquals( 'auto-draft', $post->post_status ); 449 if ( $post->ID === $existing_published_home_page_id ) { 450 $this->assertEquals( 'publish', $post->post_status ); 451 } elseif ( $post->ID === $existing_canola_attachment_id ) { 452 $this->assertEquals( 'inherit', $post->post_status ); 453 } else { 454 $this->assertEquals( 'auto-draft', $post->post_status ); 455 } 413 456 $posts_by_name[ $post->post_name ] = $post->ID; 414 457 } 415 $this->assertEquals( array( ' featured-image', 'home', 'about', 'blog', 'custom' ), array_keys( $posts_by_name ) );458 $this->assertEquals( array( 'waffles', 'canola', 'home', 'about', 'blog', 'custom' ), array_keys( $posts_by_name ) ); 416 459 $this->assertEquals( 'Custom', get_post( $posts_by_name['custom'] )->post_title ); 417 460 $this->assertEquals( 'sample-page-template.php', get_page_template_slug( $posts_by_name['about'] ) ); 418 461 $this->assertEquals( '', get_page_template_slug( $posts_by_name['blog'] ) ); 419 $this->assertEquals( $posts_by_name[' featured-image'], get_post_thumbnail_id( $posts_by_name['custom'] ) );462 $this->assertEquals( $posts_by_name['waffles'], get_post_thumbnail_id( $posts_by_name['custom'] ) ); 420 463 $this->assertEquals( '', get_post_thumbnail_id( $posts_by_name['blog'] ) ); 421 $attachment_metadata = wp_get_attachment_metadata( $posts_by_name[' featured-image'] );422 $this->assertEquals( ' Featured Image', get_post( $posts_by_name['featured-image'] )->post_title );464 $attachment_metadata = wp_get_attachment_metadata( $posts_by_name['waffles'] ); 465 $this->assertEquals( 'Waffles', get_post( $posts_by_name['waffles'] )->post_title ); 423 466 $this->assertArrayHasKey( 'file', $attachment_metadata ); 424 467 $this->assertContains( 'waffles', $attachment_metadata['file'] ); 425 468 … … class Tests_WP_Customize_Manager extends WP_UnitTestCase { 472 515 $this->assertArrayHasKey( 'starter_content', $changeset_data['blogdescription'] ); 473 516 474 517 // Publish. 518 $this->assertEmpty( get_custom_logo() ); 519 $this->assertEmpty( get_header_image() ); 520 $this->assertEmpty( get_theme_mod( 'custom_logo' ) ); 521 $this->assertEmpty( get_theme_mod( 'header_image' ) ); 475 522 $this->assertEquals( 'auto-draft', get_post( $posts_by_name['about'] )->post_status ); 476 $this->assertEquals( 'auto-draft', get_post( $posts_by_name[' featured-image'] )->post_status );523 $this->assertEquals( 'auto-draft', get_post( $posts_by_name['waffles'] )->post_status ); 477 524 $this->assertNotEquals( $changeset_data['blogname']['value'], get_option( 'blogname' ) ); 478 525 $r = $wp_customize->save_changeset_post( array( 'status' => 'publish' ) ); 479 526 $this->assertInternalType( 'array', $r ); 480 527 $this->assertEquals( 'publish', get_post( $posts_by_name['about'] )->post_status ); 481 $this->assertEquals( 'inherit', get_post( $posts_by_name[' featured-image'] )->post_status );528 $this->assertEquals( 'inherit', get_post( $posts_by_name['waffles'] )->post_status ); 482 529 $this->assertEquals( $changeset_data['blogname']['value'], get_option( 'blogname' ) ); 530 $this->assertNotEmpty( get_theme_mod( 'custom_logo' ) ); 531 $this->assertNotEmpty( get_theme_mod( 'header_image' ) ); 532 $this->assertNotEmpty( get_custom_logo() ); 533 $this->assertNotEmpty( get_header_image() ); 534 $this->assertContains( 'canola', get_custom_logo() ); 535 $this->assertContains( 'waffles', get_header_image() ); 483 536 } 484 537 485 538 /** -
tests/phpunit/tests/post/wpUniquePostSlug.php
diff --git tests/phpunit/tests/post/wpUniquePostSlug.php tests/phpunit/tests/post/wpUniquePostSlug.php index 536017d..a728454 100644
class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 347 347 $found = wp_unique_post_slug( 'embed', $p, 'publish', 'attachment', 0 ); 348 348 $this->assertSame( 'embed-2', $found ); 349 349 } 350 351 /** 352 * @ticket 38928 353 */ 354 public function test_non_unique_slugs_for_existing_auto_draft_posts() { 355 $auto_draft_post_id = self::factory()->post->create( array( 356 'post_type' => 'post', 357 'post_name' => 'existing-post', 358 'post_status' => 'auto-draft', 359 ) ); 360 $auto_draft_page_id = self::factory()->post->create( array( 361 'post_type' => 'page', 362 'post_name' => 'existing-page', 363 'post_status' => 'auto-draft', 364 ) ); 365 $auto_draft_attachment_id = self::factory()->attachment->create_object( 'image.jpg', $auto_draft_page_id, array( 366 'post_mime_type' => 'image/jpeg', 367 'post_type' => 'attachment', 368 'post_name' => 'existing-attachment', 369 'post_status' => 'auto-draft', 370 ) ); 371 372 $post_id = self::factory()->post->create( array( 'post_type' => 'post' ) ); 373 $page_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); 374 $attachment_id = self::factory()->attachment->create_object( 'image2.jpg', $page_id, array( 375 'post_mime_type' => 'image/jpeg', 376 'post_type' => 'attachment', 377 'post_name' => 'existing-image', 378 ) ); 379 380 $this->assertEquals( 'existing-post', wp_unique_post_slug( 'existing-post', $post_id, 'publish', get_post_type( $post_id ), 0 ) ); 381 wp_publish_post( $auto_draft_post_id ); 382 $this->assertEquals( 'existing-post-2', wp_unique_post_slug( 'existing-post', $post_id, 'publish', get_post_type( $post_id ), 0 ) ); 383 384 $this->assertEquals( 'existing-page', wp_unique_post_slug( 'existing-page', $page_id, 'publish', get_post_type( $page_id ), 0 ) ); 385 wp_publish_post( $auto_draft_page_id ); 386 $this->assertEquals( 'existing-page-2', wp_unique_post_slug( 'existing-page', $page_id, 'publish', get_post_type( $page_id ), 0 ) ); 387 388 $this->assertEquals( 'existing-attachment', wp_unique_post_slug( 'existing-attachment', $attachment_id, 'publish', get_post_type( $attachment_id ), 0 ) ); 389 wp_publish_post( $auto_draft_attachment_id ); 390 $this->assertEquals( 'existing-attachment-2', wp_unique_post_slug( 'existing-attachment', $attachment_id, 'publish', get_post_type( $attachment_id ), 0 ) ); 391 } 350 392 }