• As the title says, I am calling register_settings functions multiple times, for different groups of option, but for the same option name, as follows:

    `// Create Basic Settings
    register_setting(
    ‘posttype_basic_group’,
    ‘toolpress_settings’,
    array($this->callbacks, ‘posttype_basic_validate’)
    );

    // Remove Settings
    register_setting(
    ‘posttype_remove_group’,
    ‘toolpress_settings’,
    array($this->callbacks, ‘posttype_remove_validate’)
    );`

    The problem here is that on submission of a form containing only one setting_field call for a selected group, both register_settings callbacks are fired.

    I am guessing that this is happening because I am using the same option name, because if I use different names only one callback is called. But I would like to keep my plugin’s settings under one option and instead add up multidimensional arrays within the same setting.

    Is there a way to stop both validation callbacks from firing, and only fire the callback attached to the registered group?

    I might have a solution for this, I can wrap up the validation code within an if statement and check the $_POST[‘option_page’], which gives me which group is submitted. But does WP has something to go around this properly?

Viewing 1 replies (of 1 total)
  • Thread Starter xikky

    (@xikky)

    My current solution is to use the same callback for both register functions, and inside the callback check the $_POST[‘option_page’] value to validate the appropriate form.

    Any suggestions how I can do this in a better way? I don’t like using the same callback function. This makes the function very long and not tidy. I would really like to have a callback for each register function.

Viewing 1 replies (of 1 total)

The topic ‘Multiple register settings, with same option name – issue’ is closed to new replies.