Make WordPress Core

Opened 6 years ago

Last modified 6 years ago

#44459 new defect (bug)

Options added to the Permalinks admin page do not get saved

Reported by: ravanh's profile RavanH Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Options, Meta APIs Keywords:
Focuses: Cc:


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:

  1. 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' );
  1. Add settings field to the permalink group, at the optional section:
    function add_test_base_settings_field() {
            'Test base',
            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>
  1. 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)

#1 @subrataemfluence
6 years ago

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:

$category_base   = get_option( 'category_base' );
$tag_base        = get_option( 'tag_base' );

Also, in class-wp-rewrite.php, functions are specially written to handle the same two options, i.e.

public function set_category_base ( $category_base ) {
   if ( $category_base != get_option( 'category_base' ) ) {
      update_option( 'category_base', $category_base );


public function set_tag_base( $tag_base ) {
   if ( $tag_base != get_option( 'tag_base' ) ) {
      update_option( 'tag_base', $tag_base );

which are being called back in wp-admin/options-permalink.php:

$wp_rewrite->set_category_base( $category_base );
$wp_rewrite->set_tag_base( $tag_base );

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 of options-permalink.php to deal with dynamic inputs.

Last edited 6 years ago by subrataemfluence (previous) (diff)

#2 @RavanH
6 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 :)

Note: See TracTickets for help on using tickets.