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.
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.
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
thanks mark it.
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")));
}
Hook changed in 2.6:
http://www.ringofblogs.com/2008/07/31/wpmu-new-blog-settings-plugin-updated/
Thanks dsader (as usual) but I'm still using previous MU version.
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
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")));
EDIT: I've removed my comment
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.