Fix 9296: Enable custom Settings API fields in Permalinks page#9199
Conversation
## Problem
The WordPress Permalinks settings page (`options-permalink.php`) was not properly saving custom settings that were registered through the WordPress Settings API. While developers could add custom settings to the page using `register_setting()` with the 'permalink' group, these settings would not persist when the form was submitted.
## Root Cause
The issue stemmed from a mismatch in the settings group parameter check in `options-permalink.php`. The code was checking for `option_args['option_group']`, but WordPress's `register_setting()` function stores this information in `option_args['group']`. This caused the custom settings processing loop to skip over valid settings, resulting in custom fields not being saved.
## Solution
The fix involves a simple but crucial change in `options-permalink.php`:
- Changed the condition from checking `option_args['option_group']` to `option_args['group']`
- Removed debug logging statements that were used during investigation
### Testing
The fix was verified by:
1. Creating a test plugin that registers a custom permalink setting
2. Confirming the setting appears on the Permalinks page
3. Verifying the setting successfully saves to the database
4. Checking that the saved value persists across page reloads
### Example Usage
For developers looking to add custom permalink settings, here's how to properly register a setting:
```php
register_setting(
'permalink', // settings group
'my_custom_setting', // option name
array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'default' => ''
)
);
```
## Impact
This fix enables developers to properly extend the Permalinks settings page using the WordPress Settings API, improving the platform's extensibility while maintaining consistency with WordPress coding standards and best practices.
## Trac Link
- https://core.trac.wordpress.org/ticket/9296
|
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. |
Problem
The WordPress Permalinks settings page (
options-permalink.php) was not processing custom settings that were registered through the WordPress Settings API. While developers could add custom settings to the page usingregister_setting()with the 'permalink' group, these settings would not persist when the form was submitted.Root Cause
The root cause was that
options-permalink.phplacked the necessary code to process and save custom settings registered through the Settings API. While WordPress provides the infrastructure to register settings with the 'permalink' group, the permalinks page wasn't implementing the logic to handle these settings during form submission.Solution
Added code to
options-permalink.phpto properly handle custom settings:This addition:
Example Usage
For developers looking to add custom permalink settings, here's how to properly register a setting:
Impact
This enhancement enables developers to properly extend the Permalinks settings page using the WordPress Settings API, improving the platform's extensibility while maintaining consistency with WordPress coding standards and best practices.
Trac Link