2

I am developing a custom plugin on a multisite installation that, unfortunately, I am not so use to work with.

Tis is the problem: I need to add a field into che profile page of a user and I need that the value that will be insertered is going to be stored as user meta and also as option (inside the wp_options table).

Everything works fine if I am the Super Admin, the option will be stored and I can use them later in my theme, but when I try to store the values with the update_option() function I am not able to do it and I cannot store the values.

Here you can find my experimenting code but please notice that even if I have no problem with the function update_usermeta() I can't store my info in the wp_options table...

function ohw_update_field( $user_id ){
    $field = 'side_banner_' . $user_id;
    $side_ad = $_POST[ $name ];
    update_usermeta( $user_id, $name, $side_ad );
    update_option( $name, $side_ad );
}

add_action( 'personal_options_update', 'ohw_update_field' );
add_action( 'edit_user_profile_update', 'ohw_update_field' );

As you can see I am trying to use the $user_id in order to create an unique field in the table, probably I'll start to use an array to serialize the information in an unique field but I would like to understand why the admin of a site of the network is not able to save an option...

I mean, as I read on the Codex a user should have the manage_options capability in order to access this database, so why is only the super admin the one who's able to do it?

Thank you in advance for all the answers and have a great day!

1 Answer 1

4
update_option( $name, $side_ad );

Your issue here is that update_option stores the value in the options table of the site. However you're on a multisite, and your install contains multiple sites/blogs, each with their own options tables.

As a result, editing a user on blog/site A will not change the option on blog/site B, in the same way that painting a wall green in your house doesn't make the same wall green in my house. If this wasn't the case then updating the title of one site would update the title of all sites.

So:

I want to store user specific data

Store it in user meta

I want to store blog specific data

Store it in an option. The user edit screen is not an appropriate place for this option, put it on a settings screen under the settings menu.

I want to store data that affects the entire install regardless of blog/user/site

Use update_site_option and check first if it's a multisite using is_multisite(). Do not store a large quantity of data in this way. Again these kinds of options don't belong in an edit/update user page. Don't put the options page under the normal dashboard settings either, put them in the network admin panel

1
  • Thanks a lot for this clarification! I'll try a different solution based on the user specific data ;) Aug 28, 2014 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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