Skip to content

Discussion settings: save 'closed' instead of empty string when pingback/comment checkboxes are unchecked#11446

Open
chubes4 wants to merge 2 commits intoWordPress:trunkfrom
chubes4:fix/discussion-settings-ping-status-empty-string
Open

Discussion settings: save 'closed' instead of empty string when pingback/comment checkboxes are unchecked#11446
chubes4 wants to merge 2 commits intoWordPress:trunkfrom
chubes4:fix/discussion-settings-ping-status-empty-string

Conversation

@chubes4
Copy link
Copy Markdown

@chubes4 chubes4 commented Apr 6, 2026

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_status option is stored as an empty string "" instead of "closed".

This happens because options-discussion.php uses a bare checkbox:

<input name="default_ping_status" type="checkbox" id="default_ping_status" value="open" ... />

When unchecked, HTML forms don't include the field in the submission. The generic handler in options.php saves null, which update_option() stores as "":

$value = null;
if ( isset( $_POST[ $option ] ) ) {
    $value = $_POST[ $option ];
}
update_option( $option, $value );

The same issue affects default_comment_status.

Impact

  • Every new post created after unchecking this setting gets ping_status = "" in the database
  • The REST API schema only accepts "open" or "closed", so "" fails validation with a 400 error
  • Gutenberg's Real-Time Collaboration feature (persistCRDTDoc) round-trips the full entity record through REST on page load, exposing this as a user-visible 400 error (see Gutenberg #77049 / #77050)
  • MySQL strict mode configurations crash with 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:

<input type="hidden" name="default_ping_status" value="closed" />
<input name="default_ping_status" type="checkbox" id="default_ping_status" value="open" ... />

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

  1. Go to Settings → Discussion
  2. Uncheck "Allow link notifications from other blogs (pingbacks and trackbacks) on new posts"
  3. Uncheck "Allow people to submit comments on new posts"
  4. Click Save Changes
  5. Verify in the database: SELECT option_value FROM wp_options WHERE option_name IN ('default_ping_status', 'default_comment_status')
  6. Before fix: Both values are "" (empty string)
  7. After fix: Both values are "closed"
  8. Re-check both checkboxes and save — verify values are "open"

AI Disclosure

AI assistance: Yes
Tool(s): Claude Code (claude-opus-4-6)
Used for: Tracing the root cause from a Gutenberg 400 error through nginx logs, REST API validation, and wp-admin source code. The fix pattern (hidden input before checkbox) and the specific lines to change were identified and validated by AI, then reviewed and tested on a production WordPress multisite by a human contributor.

Related

  • Trac #51842 — Same root cause reported in 2020, closed as worksforme (MySQL crash symptom)
  • Gutenberg #77049 — The collaboration feature that exposes this as a 400 error
  • Gutenberg #77050 — Companion fix to only persist CRDT meta

…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.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props extrachill.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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