Discussion settings: save 'closed' instead of empty string when pingback/comment checkboxes are unchecked#11446
Conversation
…ack/comment checkboxes are unchecked When the 'Allow link notifications' or 'Allow comments' checkboxes are unchecked in Settings > Discussion, the form submits without those fields. The generic handler in options.php saves null, which update_option stores as an empty string. This causes problems because: - The REST API schema only accepts 'open' or 'closed' for ping_status and comment_status, rejecting empty strings with a 400 error - Gutenberg's Real-Time Collaboration feature round-trips the full entity record through REST on page load, exposing this as a visible error - MySQL strict mode configurations crash on NULL for NOT NULL columns The fix adds hidden inputs before each checkbox so that unchecking submits 'closed' instead of nothing. When checked, the checkbox value 'open' overrides the hidden input. This is the standard HTML pattern used elsewhere in WordPress.
|
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. |
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. |
Trac ticket
See https://core.trac.wordpress.org/ticket/51842 (related, previously closed as worksforme)
Description
When "Allow link notifications from other blogs (pingbacks and trackbacks) on new posts" is unchecked in Settings → Discussion and saved, the
default_ping_statusoption is stored as an empty string""instead of"closed".This happens because
options-discussion.phpuses a bare checkbox:When unchecked, HTML forms don't include the field in the submission. The generic handler in
options.phpsavesnull, whichupdate_option()stores as"":The same issue affects
default_comment_status.Impact
ping_status = ""in the database"open"or"closed", so""fails validation with a 400 errorpersistCRDTDoc) round-trips the full entity record through REST on page load, exposing this as a user-visible 400 error (see Gutenberg #77049 / #77050)Column 'ping_status' cannot be null(Trac #51842)The fix
Adds a hidden input before each checkbox so that unchecking submits
"closed"instead of nothing:When the checkbox is checked, its
"open"value overrides the hidden input (standard HTML behavior — later inputs with the same name take precedence). When unchecked,"closed"is submitted.This is the standard pattern used elsewhere in WordPress for checkbox options that need an explicit "off" value.
Testing instructions
SELECT option_value FROM wp_options WHERE option_name IN ('default_ping_status', 'default_comment_status')""(empty string)"closed""open"AI Disclosure
Related