0

I want to be able to customize my theme from any of my sites (mainsite or any subsite) and have that change impact on the entire network.

Right now when I customize, i.e., my main site it doesn't replicate the changes to the rest of subsites.

I know this data is stored under theme_mods_themename, but I need to "copy and paste" this new values (New values generated when I use the customizer) on every site.

Is there a way to "unify" this setting?

Thank you in advance.

UPDATE (DECEMBER 21 2021):

I've found another thing that was making me lose my mind. At least in my case, theme colors are not stored with the rest of the theme settings in theme_mods_kadence-child, they are stored under kadence_global_palette in the wp-options database table.

Still haven't found a way to "Sync" all customizer settings tho. I've been reading about what Pat J said in the first comment, but couldn't crack it yet.

UPDATE (DECEMBER 23 2021)

I finaly solved it! Answer bellow !

1
  • If I was developing this, I'd start by looking at using the update_option_theme_mods_{$theme} action hook to update a network option when your theme mods are updated, and then pulling that network option's data back out with the theme_mod_{$name} filter.
    – Pat J
    Commented Dec 20, 2021 at 21:45

1 Answer 1

0

Finally Solved it! If you are going to use this code make sure to change the options names to the ones that your theme uses (change "theme_mods_kadence-child" and "kadence_global_palette").

I used get_option to get the recently saved data, then I looped through all sites and used update_option to set the new data on all subsites. Finally I used the customize_save_after action so this function activates just after the new customizer data is saved.

add_action( "customize_save_after", "update_customizer_networkwide");
function update_customizer_networkwide () {
    // Get current theme mods
    $theme_mods_kadence = get_option("theme_mods_kadence-child");
    $global_palette = get_option("kadence_global_palette");


    // loop through all sites and set new theme mods
    $sites = get_sites();
    foreach ($sites as $site) {
        switch_to_blog( $site->blog_id );

        update_option("theme_mods_kadence-child", $theme_mods_kadence);
        update_option("kadence_global_palette", $global_palette);
        
        restore_current_blog();
    }
}

Hope this helps some of you!

2
  • I'm glad you found a solution. Be aware, though, that on a large Multisite installation, switch_to_blog() can start to slow things down. I'd still recommend saving the data in a network option, which can be accessed from any site (see update_site_option() and its relations).
    – Pat J
    Commented Dec 24, 2021 at 0:06
  • 1
    Thank you so much! I will look into it. It should work with update_site_option() and get_site_option(). Commented Dec 25, 2021 at 21:40

Your Answer

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

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