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 working on a new plugin but it's my first to save which will save an option to the database.

Currently I'm using add_option and I assumed that
- activation would fail or - the wrong value would be saved to the wp_blogID_options table

because I wasn't using add_blog_option. All the posts / literature (Wrox, Apress, etc) I've read say I need to use to add_blog_option.

But all my testing (and inspecting the SQL table) are proved me wrong. So ... What is wrong with using add_option instead of add_blog_option when making a plugin (that can be single install or multisite)?

To me ... it seems that add_option (or even get_option) all work fine. I'm guessing the Settings API has some protection wrapper.

However ... that would mean using add_blog_option (or get_blog_option) are only for 'purists'.

share|improve this question
add comment

2 Answers 2

add_blog_option ultimately calls add_option itself to add the option after switching the context to the supplied blog ID. the difference is that add_option will only work in the context of the current blog where add_blog_option lets you specify a blog ID that may be different than the current context.

share|improve this answer
    
so it doesn't matter? - unless im trying to activate a plugin from a different blog. –  Damien Oct 10 '12 at 5:46
add comment
up vote 3 down vote accepted

What I've come to 'learn' is that there are 3 states on plugin activation for a mulitsite setup.

Consider this for a Site Admin who installs a new plugin:

  1. Plugin is network activated - but it needs admin to complete setup (call it stateless)
  2. Plugin activated, no 'unique features' per blog and it doesn't need an admin user to complete setup (call it active)
  3. Plugin activated, has unique features per blog and it does need an admin user to complete setup (call it pending)

Scenario 1: you can safely use 'add_option' on plugin activation (or network activation) as the plugin is stateless.

Scenario 2: you must use 'add_blog_option' and loop through each blog - if you do network activation as the plugin will be active.

Scenario 3: you must use 'add_blog_option' and ideally you don't allow network activation because the plugin is pending.

In my case, my plugin does nothing until the Blog owner creates a page with the shortcode.

share|improve this answer
add comment

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.