[wp-trac] [WordPress Trac] #44459: Options added to the Permalinks admin page do not get saved

WordPress Trac noreply at wordpress.org
Mon Jun 25 17:23:39 UTC 2018


#44459: Options added to the Permalinks admin page do not get saved
--------------------------------+-----------------------------
 Reporter:  RavanH              |      Owner:  (none)
     Type:  defect (bug)        |     Status:  new
 Priority:  normal              |  Milestone:  Awaiting Review
Component:  Options, Meta APIs  |    Version:
 Severity:  normal              |   Keywords:
  Focuses:                      |
--------------------------------+-----------------------------
 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:
 {{{#!php
 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' );
 }}}

 2. Add settings field to the permalink group, at the optional section:
 {{{#!php
 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
 }
 }}}

 3. 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/44459>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list