Wordpress multisite disables all widgets by default when creating a site

I can not find how to disable the default widgets when creating a site. By this, I mean that when I create a site on a multi-network Wordpress network, it does not create sidebar widgets, such as "meta" automatically.

I see plugins that have not been updated for over two years that can help me with this, but I do not want to download anything that is old.

Does anyone know how to do this?

+4
source share
2 answers

The default widgets are calling update_option()in wp_install_defaults()to wp-admin/includes/upgrade.php.

After it wp_install_defaults()was called wpmu_create_blog()in wp-includes/ms-functions.php, the action is wpmu_new_blogstarted.

, wpmu_new_blog , update_option(), sidebar-1.

add_action('wpmu_new_blog', function($blog_id){
    switch_to_blog($blog_id);
    update_option('sidebars_widgets',
        ['wp_inactive_widgets' => [], 'sidebar-1' => [], 'sidebar-2' => [],
         'sidebar-3' => [], 'array_version' => 3]);
    restore_current_blog();
});
0

, unregister_widget - , .

-1

Source: https://habr.com/ru/post/1625204/


All Articles