Skip to content

Commit d507f27

Browse files
committed
Discussion settings: save 'closed' instead of empty string when pingback/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.
1 parent 609f25f commit d507f27

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

src/wp-admin/options-discussion.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@
5252
<?php _e( 'Attempt to notify any blogs linked to from the post' ); ?></label>
5353
<br />
5454
<label for="default_ping_status">
55+
<input type="hidden" name="default_ping_status" value="closed" />
5556
<input name="default_ping_status" type="checkbox" id="default_ping_status" value="open" <?php checked( 'open', get_option( 'default_ping_status' ) ); ?> />
5657
<?php _e( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new posts' ); ?></label>
5758
<br />
5859
<label for="default_comment_status">
60+
<input type="hidden" name="default_comment_status" value="closed" />
5961
<input name="default_comment_status" type="checkbox" id="default_comment_status" value="open" <?php checked( 'open', get_option( 'default_comment_status' ) ); ?> />
6062
<?php _e( 'Allow people to submit comments on new posts' ); ?></label>
6163
<br />

0 commit comments

Comments
 (0)