Inherit plugin settings to new site in Multisite

I use the Breadcrumb NavXT plugin for a WP Multisite. I activated the plugin for all sites so I can use it throughout my network.

My problem is that every time I add a new site I have to change the default settings of the plugin, but I’d like WP to use the settings I already customized for the main site because on all future sites they would be the same.

Is there a way to force WP adopting the plugin settings of the main site?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Nice Question!

But I’ll leave for the asker and for the reader the task of finding the plugin options name.

This can be used for any plugin/theme that relies in a single/serialized value in the wp_options table. If it’s not a single value, it’s another task…

In this example, I’m using WP-Pagenavi option_name.

wp-pagenavi option name

Action hook found inside the function wpmu_create_blog in the file /wp-includes/ms-functions.php.

add_action( 'wpmu_new_blog', 'wpse_70977_copy_main_site_options', 10, 6 );

function wpse_70977_copy_main_site_options( $blog_id, $user_id, $domain, $path, $site_id, $meta )
{
    $mainsite = get_option( 'pagenavi_options' );
    switch_to_blog( $blog_id );
    update_option( 'pagenavi_options', $mainsite );
    restore_current_blog();
}

This code is tested with the plugin being activated on a per site basis, and with the plugin being Network Activated.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x