0

I'm using multisite installation to separate content by city. I considered other options, but multisite is the best for me.

But as there will be many sites, which will differ only by content and user roles, I need to sync all wordpress and plugins settings between all sites.

I found a config hack - you can rewrite users table name, so every site will use same users table. So I thinking of something simmilar to overwrite settings table name. But wordpress holds few fields there which should not be the same: siteurl, home, blogname, blogdescription. Maybe something else. Also there is no hooks to replace settings table name, so I would need to edit wordpress code and that would extreme measures.

Moreover it would be much better to store all settings in a file so it will be stored in version controll.

Is there any solutions? I know there's not many people who use multisite installation, but maybe someone have any thoughts?

0

Update from comments

To convert an array of options to site options, you can try something like this:

add_action( 'init', 'wpse245699_use_site_options' );
function wpse245699_use_site_options() {
    // Uses site options for these options.
    $required_site_options = array(
        'some_option_name',
        'another_option_name',
        'and_another_one',
    );
    foreach( $required_site_options as $option ) {
        add_action( 'update_option_' . $option, 'wpse245699_update_site_option', 10, 3 );
        add_filter( 'pre_option_' . $option, 'wpse245699_get_site_option', 10, 2 );
    }
}

function wpse245699_update_site_option( $old_value, $value, $option ) {
    update_site_option( $option, $value );
}

function wpse245699_get_site_option( $pre_option = false, $option ) {
    return get_site_option( $option );
}

This code is untested.

I wouldn't recommend converting all of WordPress's options to site options; there are a number of core options in use on every site, and setting them all to identical values would most likely end badly.


WordPress Multisite uses one table for all its users already; you shouldn't need any kind of "config hack" to accomplish this. As for plugins and settings: you can Network Activate plugins and they'll run on every site in your Multisite network. And settings (or options -- I assume you're referring to the data stored by the Options API) can be stored and retrieved on a per-site basis (using the *_option() functions) or globally across the network (using the *_site_option() functions).

WordPress stores virtually all its data in the database, so saving and loading options/settings from a file isn't really The WordPress Way.

References

  • _site_options sounds interesting. It would be exact thing I need if only problem was in my own plugin. But I need all plugins I use to store their settings globally. So if only I could hook somewhere and use _site_option inside every _option used by other plugins... – Ilya Dudarev Nov 10 '16 at 15:10
  • I see there is a nice filter for update_option: $value = apply_filters( 'pre_update_option', $value, $option, $old_value ); Which supplies option name and I can use to set option globally. But get_option does not use common filter and uses different one for each option name^ $pre = apply_filters( 'pre_option_' . $option, false, $option ); Is there a way to add filter with prefix and get filter name inside my hook? Something like: add_filter('pre_option_*', 'custom_get_option', 10, 3); – Ilya Dudarev Nov 10 '16 at 15:41
  • I've updated my answer. Also, be aware that WordPress uses a bunch of core options on each site, so changing every single option in a site to use a network-level option probably will not work well. – Pat J Nov 10 '16 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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