Add JavaScript to conditionally disable the publish button in the classic Editor #226
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR solves : https://core.trac.wordpress.org/ticket/62769
Summary
This PR adds logic to disable the "Publish" button in the Classic Editor interface when both the post title and content fields are empty. The button is automatically re-enabled once either field has valid input.
Key Features
Applies to:
post, page, and any custom post types (CPTs) using the Classic Editor.
Skips block editor (Gutenberg) screens using use_block_editor_for_post_type().
Prevents users from accidentally publishing completely empty content.
Improves UX by disabling the button immediately on page load (avoids flicker).
Listens to title input and content changes (including TinyMCE events).
Technical Details
Hook used: admin_print_footer_scripts
Detects screen type using get_current_screen().
Disables #publish button early and conditionally re-enables it.
TinyMCE support: content changes tracked even within WYSIWYG editor.
How to Test
Open the Classic Editor for any post, page, or CPT.
Ensure both the title and content fields are empty.
Observe that the "Publish" button is disabled on load.
Add either a title or content — the button should become enabled.
Clear both fields — the button should disable again.
Notes
This change is purely front-end (JS in admin), ensuring a better editorial workflow. It does not add server-side validation — users with direct access (e.g., via REST API or browser overrides) can still submit empty posts.