Opened 7 years ago
Last modified 7 years ago
#44459 new defect (bug)
Options added to the Permalinks admin page do not get saved
Reported by: | RavanH | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Options, Meta APIs | Keywords: | |
Focuses: | Cc: |
Description
When a new option with matching field is registered to show on the Permalink admin page, it will show there just fine but the setting will never be saved to the database. This seems due to the fact that wp-admin/options-permalink.php submits to itself, not to options.php
To reproduce:
- Register a test option to the permalink group:
function register_test_base_setting() { $args = array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field' ); register_setting( 'permalink', 'test_base', $args ); } add_action( 'admin_init', 'register_test_base_setting' );
- Add settings field to the permalink group, at the optional section:
function add_test_base_settings_field() { add_settings_field( 'test_base', 'Test base', 'test_base_settings_field', 'permalink', 'optional', array( 'label_for' => 'test_base' ) ); } add_action('admin_init', 'add_test_base_settings_field' ); function test_base_settings_field( $args ) { global $blog_prefix; $test_base = get_option( 'test_base' ); echo $blog_prefix; ?><input name="test_base" id="test_base" type="text" value="<?php echo esc_attr($test_base); ?>" class="regular-text code" /></td> <?php }
- Visit Settings > Permalinks and try to set a value and save the setting.
What is expected: the setting gets (a) passed to the sanitize callback and then (b) saved to the DB.
What happens: nothing of these two.
There is really no point of the do_settings_fields('permalink', 'optional')
and do_settings_sections('permalink')
in wp-admin/options-permalink.php if options added though these hooks will never get treated.
Change History (2)
#2
@
7 years ago
Hi @subrataemfluence yes that is what I gather from the code too. At this point I'm wondering if the block that is there to save permalink options in options-permalink.php, could not be moved over (and adapted) to options.php so that the Permalinks form can be submitted to options.php
This would take care of any custom options fields at the same time as being more in the same logic as all other setting pages.
The Permalinks form would need stuff like <?php settings_fields('general'); ?>
added to make it work, and the part where different messages are returned via the 'settings_errors' transient (not just "Settings saved.") would need to be integrated into options.php
Delicate, but possible I would think. I'm prepared to do some work on it :)
If I understand correctly, the form is only submitting to itself, not to
option.php
to save permalink structures and this saves the settings fine.For new options, what I realize from initial look into the code is tag_base and category_base are the two options being considered so far and there is (probably) no room yet for considering a generic option or an additional option.
In
options-permalink.php
options that handled are:Also, in
class-wp-rewrite.php
, functions are specially written to handle the same two options, i.e.and
which are being called back in
wp-admin/options-permalink.php
:I may be entirely wrong in my understanding, but looks like in order to consider "any" custom options in permalink page we need to have generic methods in
class-wp-rewrite.php
as well as modify the logic ofoptions-permalink.php
to deal with dynamic inputs.