WordPress.org

Make WordPress Core

Opened 10 months ago

Last modified 6 months ago

#45558 new defect (bug)

Move _draft_or_post_title() from wp-admin/includes to wp-includes

Reported by: swissspidy Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 5.0
Component: Editor Keywords: has-patch dev-feedback
Focuses: Cc:
PR Number:

Description

In the WordPress 5.0 release package, the wp_latest_comments_draft_or_post_title() and render_block_core_latest_comments() functions don't exist because they were overwritten during npm install in the build process. That's because the changes from https://github.com/WordPress/gutenberg/pull/12326 were manually added to core, before that PR was merged (which happened today).

Instead, we have gutenberg_draft_or_post_title() and gutenberg_render_block_core_latest_comments() in core now.

That's certainly less than ideal. Not only because the prefix is wrong, but also because gutenberg_draft_or_post_title() / wp_latest_comments_draft_or_post_title() duplicated the existing _draft_or_post_title() function. We should fix this as soon as possible, before people try to use gutenberg_ prefixed functions in their projects.

That function was duplicated in Gutenberg because they didn't want to include admin functions in front-end facing code, which makes sense.

Suggested solution:

  1. Move _draft_or_post_title() to wp-includes/template.php
  2. In the block-library package in Gutenberg, rename wp_latest_comments_draft_or_post_title() / gutenberg_draft_or_post_title() from latest-comments.php to _draft_or_post_title() and add a function_exists() check. This way, nothing should break.
  3. Use that function in render_block_core_latest_comments()

Alternatively to step 2, Gutenberg should just bump the minimum WP version to 5.0.1, which makes sure the _draft_or_post_title() function is available at all times.

Benefits:

  1. No duplicated code.
  2. No gutenberg_ prefixes in core

Attachments (1)

45558.diff (1.5 KB) - added by swissspidy 10 months ago.

Download all attachments as: .zip

Change History (10)

@swissspidy
10 months ago

#1 @swissspidy
10 months ago

  • Keywords has-patch added; needs-patch removed

#2 @pento
10 months ago

  • Milestone changed from 5.0.1 to 5.0.2

#3 @swissspidy
10 months ago

  • Version set to 5.0

#4 @pento
10 months ago

I'm a little concerned about moving such an old function.

Moving it from wp-admin to wp-includes means it's now defined everywhere, there's possibly ancient code that relies on it only being in wp-admin.

Moving the file it's in will break any code that specifically loads that file, rather than all of WordPress: we ran into this problem a bunch of times the last time functions were moved around.

I'd be more inclined to move wp_latest_comments_draft_or_post_title() out of the block file, and deprecate _draft_or_post_title().

#5 @pento
10 months ago

  • Milestone changed from 5.0.2 to 5.0.3

#6 @audrasjb
10 months ago

  • Keywords dev-feedback added
  • Milestone changed from 5.0.3 to 5.1

5.0.3 is going to be released in a couple of weeks. We are currently sorting the remaining tickets in the milestone. It doesn't appear that ticket can be handled in the next couple of weeks (needs feedback and maybe some additional work). Let's address it in 5.1 which is coming in February. Feel free to change/ask to change the milestone if you think the issue can be quickly resolved.

#7 follow-up: @swissspidy
9 months ago

I'd be more inclined to move wp_latest_comments_draft_or_post_title() out of the block file

That means moving it in core and removing it from the block-library package in Gutenberg, correct?

#8 in reply to: ↑ 7 @pento
9 months ago

  • Milestone changed from 5.1 to 5.2

Replying to swissspidy:

That means moving it in core and removing it from the block-library package in Gutenberg, correct?

Yup. Give it a better name in core, then wp_latest_comments_draft_or_post_title() and _draft_or_post_title() can both be deprecated, and just call the core function.

#9 @pento
6 months ago

  • Milestone changed from 5.2 to Future Release

This change needs to be coordinated across this ticket, and the Gutenberg repo.

Note: See TracTickets for help on using tickets.