The MU forums have moved to WordPress.org

Default widget for new blog in MUWP (10 posts)

  1. benone
    Member
    Posted 5 years ago #

    Hi all!

    Does anybody know how to set up default widgets for new blogs?
    I mean when user is creating new blog specific widgets need to be activated..

    Thank you,
    Kirill.

  2. nicktonic
    Member
    Posted 5 years ago #

    I managed this by writing a little MUplugin (place this in /wp-content/mu-plugins):

    add_action("wpmu_new_blog", "activate_blog");
    
    function activate_blog($blog_id, $user_id, $password, $signup, $meta) {
    
       	update_option("sidebars_widgets",
    		array("sidebar-1" => array("tag_cloud"),
    			 "sidebar-2" => array("archives", "links")));
    
    }

    This activates the given widgets in sidebar-1 and -2. You need to know the internal names of the widgets.

    - Nils

  3. chinafla
    Member
    Posted 5 years ago #

    thanks mark it.

  4. boonika
    Member
    Posted 5 years ago #

    This does not work for me. New blogs are created with no widgets at all and also, main blog widgets disappeared. Is there any other way to do this?

    The code I used:

    add_action("wpmu_new_blog", "activate_blog");
    
    function activate_blog($blog_id, $user_id, $password, $signup, $meta) {
    
       	update_option("sidebars_widgets",
    		array("sidebar-1" => array("widget_pages", "widget_categories")));
    
    }
  5. dsader
    Member
    Posted 5 years ago #

  6. boonika
    Member
    Posted 5 years ago #

    Thanks dsader (as usual) but I'm still using previous MU version.

  7. randyhoyt
    Member
    Posted 5 years ago #

    I'm able to get some widgets to work using this method, but not all. The issue appears to be that some widgets (like Categories) can be added multiple times. The widget is named [categories] but it gets instantiated as [categories-0]. Looking at the URL of the "Add" link of the Categories under "Design" > "Widgets", there are two parameters: [base=categories] and [add=categories-0].

    This code works fine for the pages and archives widgets:

    update_option("sidebars_widgets", array("sidebar-1" => array("pages", "archives")));

    But this code does not work to add the categories widget:

    update_option("sidebars_widgets", array("sidebar-1" => array("categories")));

    Thoughts?
    ~randy

  8. dsader
    Member
    Posted 5 years ago #

    You need a widget option there first with a multi widget.

    Try this: The following spoofs an old widget number to trigger the wp_widget_categories_upgrade function:

    add
    update_option( 'widget_categories', array( 'title' => 'My Categories' ));
    just before
    update_option("sidebars_widgets", array("sidebar-1" => array("categories")));

  9. boonika
    Member
    Posted 5 years ago #

    EDIT: I've removed my comment

  10. boonika
    Member
    Posted 5 years ago #

    For WPMU 2.6:

    <?php
    
     function new_blogs_setting( $blog_id )  {
    
        	add_option( 'widget_categories',
    		array( 'title' => 'My Categories' ));
    
       	add_option("sidebars_widgets",
    		array("sidebar-1" => array("tag_cloud"),
    			 "sidebar-2" => array("pages", "categories", "links")));
    
    }
    add_action('populate_options', 'new_blogs_setting');  
    
    ?>

    This works. But something bothers me. Not a big deal but still... When I'm using a two column theme and using the same exact code as written above, widgets assigned to "sidebar-2" show up inside theme's sidebar. Shouldn't that sidebar be "sidebar-1"?

    Big thanks to dsader and MrBrian.

About this Topic