Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/wp-admin/edit-form-advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@
<div id="post-body" class="metabox-holder columns-<?php echo ( 1 === get_current_screen()->get_columns() ) ? '1' : '2'; ?>">
<div id="post-body-content">

<?php if ( post_type_supports( $post_type, 'title' ) ) { ?>
<div id="titlediv">
<?php if ( post_type_supports( $post_type, 'title' ) ) { ?>
<div id="titlewrap">
<?php
/**
Expand All @@ -547,6 +547,7 @@
}
?>
</div>
<?php } ?>
<?php
/**
* Fires before the permalink field in the edit form.
Expand Down Expand Up @@ -595,8 +596,7 @@
wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false );
?>
</div><!-- /titlediv -->
<?php
}
<?php
/**
* Fires after the title field.
*
Expand Down
77 changes: 77 additions & 0 deletions tests/e2e/specs/edit-post-without-title-support.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* Internal dependencies
*/
import { test, expect } from '../fixtures';

const POST_TYPES_MU_PLUGIN = `<?php
add_action(
'init',
function () {
register_post_type(
'no_title_cpt',
array(
'public' => true,
'label' => 'No Title CPT',
'supports' => array( 'editor' ),
'show_in_rest' => false,
)
);
register_post_type(
'with_title_cpt',
array(
'public' => true,
'label' => 'With Title CPT',
'supports' => array( 'title', 'editor' ),
'show_in_rest' => false,
)
);
}
);`;

test.describe( 'Edit post without title support', () => {
test.beforeEach( async ( { muPlugin } ) => {
await muPlugin.write(
'post-types-title-support.php',
POST_TYPES_MU_PLUGIN
);
} );

test( 'shows the permalink for a published post of a type that does not support titles', async ( {
admin,
page,
} ) => {
await admin.visitAdminPage( 'post-new.php', 'post_type=no_title_cpt' );
await expect( page.locator( '#title' ) ).toHaveCount( 0 );

await page.locator( '#publish' ).click();
await expect( page.locator( '#message.updated' ) ).toBeVisible();

const slugBox = page.locator( '#edit-slug-box' );
await expect( slugBox ).toBeVisible();
await expect( slugBox ).toContainText( 'Permalink:' );
await expect(
slugBox.locator( '#sample-permalink a' )
).toHaveAttribute( 'href', /no_title_cpt/ );
} );

test( 'still shows the title field and permalink for post types that support titles', async ( {
admin,
page,
} ) => {
await admin.visitAdminPage(
'post-new.php',
'post_type=with_title_cpt'
);
await expect( page.locator( '#title' ) ).toBeVisible();

await page.locator( '#title' ).fill( 'Post with a title' );
await page.locator( '#publish' ).click();
await expect( page.locator( '#message.updated' ) ).toBeVisible();

const slugBox = page.locator( '#edit-slug-box' );
await expect( slugBox ).toBeVisible();
await expect(
slugBox.locator( '#sample-permalink a' )
).toHaveAttribute( 'href', /post-with-a-title/ );
} );
} );
Loading