Fix #65024: Add item_draft_saved label to make 'Draft saved.' message…#11477
Fix #65024: Add item_draft_saved label to make 'Draft saved.' message…#11477Vedanshmini26 wants to merge 1 commit intoWordPress:trunkfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
a856dc0 to
47f2ec3
Compare
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Core Trac Ticket: https://core.trac.wordpress.org/ticket/65024
Problem
The "Draft saved." message that appears in the block editor snackbar notification when saving a post in draft status cannot be modified by plugins or themes. Unlike other editor save messages (e.g. "Post published.", "Post updated.", "Post trashed."), there is no WordPress filter or hook that exposes this string.
Root Cause
All other save notification messages in the block editor are sourced from postType.labels — PHP-defined post type label objects that are exposed via the REST API and filterable using the post_type_labels_{post_type} hook. However, the "Draft saved." message is hardcoded directly in JavaScript (wp-includes/js/dist/editor.js) inside the getNotificationArgumentsForSaveSuccess() function, bypassing the label system entirely and making it impossible to override.
Solution
This PR handles the PHP side of the fix by adding a new item_draft_saved label to the post type labels system, following the same pattern as existing labels like item_updated, item_published, and item_trashed:
class-wp-post-type.php: Added item_draft_saved to WP_Post_Type::get_default_labels() with a default value of 'Draft saved.' for both hierarchical and non-hierarchical post types.
post.php: Added a contextual 'Pattern draft saved.' label for the wp_block post type (which already defines its own full set of custom labels), and updated the get_post_type_labels() docblock to document the new label.
Since the REST API post types controller already exposes the full $post_type->labels object, the new label flows to the JavaScript side automatically with no REST API changes needed.
The corresponding JS change — replacing the hardcoded __("Draft saved.") with postType2.labels.item_draft_saved in packages/editor/src/store/utils/notice-builder.js — needs to be made in a separate Gutenberg PR, as wp-includes/js/dist/editor.js is a compiled build artifact synced from the Gutenberg monorepo.
Once both the PHP (this PR) and the Gutenberg JS change land, plugins will be able to filter the message using the existing hook:
add_filter( 'post_type_labels_post', function( $labels ) {
$labels->item_draft_saved = 'Your custom message.';
return $labels;
} );