Multiple register settings, with same option name – issue

I already posted this question in wordpress support forums here but I didn’t get any help and nor could I find a solution yet.

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', //option group name
'toolpress_settings', //option name
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?

0

Leave a Comment