Multi-site Network and site-specific plugin options (2 posts)

  1. davehprohoods
    Posted 2 years ago #

    I'm using a plugin that lets the admin user set the database connection details for a separate (non-WordPress) database that we use across all sites, but then we need site-specific settings. I can split the plugin and use Network Activate for the database connection, then activate the other plugin with its own options for each site, but I'm not sure how to access the Network database options from the site-specific plugin.

    So for instance we are doing this on the Network plugin:
    update_option('db_host', 'outside_db_host');
    update_option('db_name', 'outside_db_name');
    update_option('db_user', 'outside_db_user');
    update_option('db_pass', 'outside_db_pass');

    However, when I run get_option('db_host') in the site-specific plugin, it returns empty. I'm not sure how to fetch the Network options.

  2. Curtiss Grymala
    Posted 2 years ago #

    First of all, update_option() is not setting the network option; it's setting the option for that specific site. If you want to set a network option, you need to use update_site_option() instead. Then, you'll use get_site_option() to retrieve that value.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.