I'm trying to add settings fields on the permalink page. For some reason, it's the only page that doesn't save the settings. To reproduce:

function add_settings_permalink() {
    register_setting( 'permalink', 'my-settings' );

    add_option_whitelist( array(
        'permalink' => array( 'my-settings' ),
    ) );

    add_settings_field( 'my-settings', 'My settings', 'some_render_function', 'permalink' );

add_action( 'admin_init', 'add_settings_permalink' );

In all pages such as writing or reading, it will work as expected, but when it's set permalink, for some reason it doesn't save.


I discovered that you can save the setting manually to make it happens:

function add_settings_permalink() {
    if ( isset( $_POST['my-settings'] ) ) {
            update_option( 'my-settings', $_POST[ 'my-settings' ]);
add_action( 'load-options-permalink.php', 'save_settings_permalink' );

What i want to know is why it happens and why this is needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.