Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm tweaking a plugin and I'd like to have an option value different for each backoffice user.

Currently the options are defined using the add_settings_field method that is performed in the admin_init hookup.

My question is, could I register a new set of settings by prefixing my settings using the current user ID?

Such a way, if valid, could help to solve other problems, such:

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Yes, you can and it's easier using a Class. In the admin_init hook (where the Settings API is being registered and defined) set a class property based on the user ID:

$this->prefix = 'uid_' . get_current_user_id() . '_';

Then, in the rest of the code, refer to your option name as $this->prefix . 'option_name'.

The result in the table wp_options will be uid_1_option_name, uid_2_option_name, etc. And each user will have its own settings.

A Gist with a working example.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.