WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 19 months ago

#36157 new defect (bug)

Permalink UI shown without typing a title

Reported by: atimmer Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 2.5
Component: Permalinks Keywords: has-patch needs-unit-tests
Focuses: javascript, administration Cc:

Description

When creating a new post and jumping straight to the content to write a post the permalink UI will still be shown.

Steps to reproduce:

  • 'Add New' post in the admin
  • Type content inside the post content field.
  • Wait until an autosave triggers and finishes. This step can also be achieved by putting wp.autosave.server.triggerSave(); inside the console.

Expected behaviour:
The permalink UI isn't shown because no title has been set yet.

Actual behaviour:
The permalink UI is shown with a post ID as the slug.

Attachments (2)

36157.patch (620 bytes) - added by atimmer 2 years ago.
wp.36157.numeric-permalink.patch (877 bytes) - added by tha_sun 19 months ago.

Download all attachments as: .zip

Change History (8)

@atimmer
2 years ago

#1 @atimmer
2 years ago

  • Keywords has-patch added

36157.patch fixes this by checking correctly for a length of zero instead of casting the length to a boolean.

#2 @swissspidy
2 years ago

  • Milestone changed from Awaiting Review to Future Release
  • Version changed from 4.4.2 to 2.5

Looks like this was broken ever since, see [6953].

!! $('#edit-slug-box > *').length could be an alternative, but an explicit length check is definitely more clear.

#3 @tha_sun
19 months ago

  • Focuses administration added

I don't see how changing that condition would fix the root cause, because it only checks whether the permalink UI already exists on the page, so as to determine when it needs to be generated and initialized (once).

Instead, the root cause is the server-side function get_sample_permalink(), which happens to generate a numeric post_name/slug (the post ID) when an empty title is passed to it.

Therefore, I'd propose to re-categorize this issue into the component "Administration" or "Permalinks".

In addition, there's another bug that causes the permalink UI to still be displayed:

Even though get_sample_permalink() already contains an existing early return statement to cancel the operation (in which case no permalink UI should be generated), the calling function get_sample_permalink_html() does not handle that case yet, so the UI still appears (but with a draft preview link).

Attached patch fixes both issues.

#4 follow-up: @tha_sun
19 months ago

  • Component changed from Autosave to Permalinks
  • Version changed from 2.5 to 4.5.3

Is there anything I can do to move this issue forward?

The patch is used on a couple of our sites in production and it works correctly.

#5 in reply to: ↑ 4 @SergeyBiryukov
19 months ago

  • Version changed from 4.5.3 to 2.5

Replying to tha_sun:

Is there anything I can do to move this issue forward?

Unit tests would be helpful, see https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/.

P.S. The Version field indicates the earliest affected version, not the latest one.

#6 @SergeyBiryukov
19 months ago

  • Keywords needs-unit-tests added
Note: See TracTickets for help on using tickets.