Skip to content

Conversation

@AKSHAT2802
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant