WordPress.org

Support

Support » Multisite » Sub-blogs use the main blog widgets

Sub-blogs use the main blog widgets

  • justinbriggs1

    @justinbriggs1

    Hey everyone, I just had my multisite client give me an unusual request. They want each subblog’s widgets to be controlled by the main blog, i.e. the sub-blog administrator will have no control over the widgets, and they will exactly reflect the widgets on the main one. Is there a way to do this? Thanks,

    Justin

Viewing 15 replies - 1 through 15 (of 20 total)
  • Moderator Ipstenu (Mika Epstein)

    @ipstenu

    Hmm.

    If they’re all using the same theme, the ‘easiest’ way is to hard code the sidebars/widgets. Of course, then you lose flexibility.

    In theory, you should be able to specify which site the widgets come from in the calls for the widget areas, and I swear I’ve seen this mentioned somewhere else before!

    justinbriggs1

    @justinbriggs1

    Hard coding is one option, and would work for most of the sidebar items, but the problem is that they have a couple of plugins, such as the advertising manager, that they want to retain control of, and will update globally across the main blog and all sub blogs. That would mean that I would have to somehow pull only the specified widgets from the main blog, and then hard code the other ones into the sidebar at certain positions.

    I wouldn’t mind taking all of the widget control away from the sub-blog user, which is feasible, but I still don’t know how to display the widgets from the main blog globally.

    Andrea Rennick

    @andrea_r

    Customer Care at Copyblogger Media and Studiopress

    switch_to_blog if you don’t have a large number of sites.

    menus plugins to deny access to backend menus, or knock down the user privs.

    justinbriggs1

    @justinbriggs1

    That’s exactly what I am looking for. I think it will be fine for our needs, I don’t expect a lot of sub-blogs or traffic to any of the sites. I can’t seem to get it to work, however, when I apply it to my dynamic sidebars. I have it set up like this in my sidebar.php file:

    <?php
    switch_to_blog(1);
    dynamic_sidebar( 'global-widget-area' );
    restore_current_blog();
    ?>

    Still getting a blank sidebar on the sub-blog. Any idea why?

    Andrea Rennick

    @andrea_r

    Customer Care at Copyblogger Media and Studiopress

    Is there a dynamic sidebar on the main blog called ‘global-widget-area’ ?

    justinbriggs1

    @justinbriggs1

    Yes, that is one I created myself, and it works on the main blog just fine, but not in the sub blog in this scenario

    Speggey

    @speggey

    I have a similar problem. I want to use a function from a plugin installed on the main blog on the sub blogs.

    switch_to_blog(1);
    wp_bannerize(‘group=right’);
    restore_current_blog();

    It just shows up blank on the sub blogs but works on the main blog.

    justinbriggs1

    @justinbriggs1

    I have found a bunch of other resources and forum posts on this topic since I started this thread. There are several that specifically state that this is possible, but I haven’t seen any evidence that switch_to_blog() works sidebars in this manner. Unless someone has a working example?

    In the following “mu-plugin”(or functions.php of common theme) example, I wanted a text widget and an rss widget as the only widgets on every site’s sidebar. I can dynamically edit the widgets in the usual way on blog 1, yet the remaining blogs can’t undo.

    All sites have same twentyten theme active so all sidebars have same name.

    <?php
    function override_sidebars_widgets() {
    	$bar = get_blog_option('1','sidebars_widgets');
    	return $bar;
    }
    function override_widget_rss() {
    	$bar = get_blog_option('1','widget_rss');
    	return $bar;
    }
    function override_widget_text() {
    	$bar = get_blog_option('1','widget_text');
    	return $bar;
    }
    	global $blog_id;
    	if($blog_id != '1') {
    add_filter( 'pre_option_' . 'sidebars_widgets', 'override_sidebars_widgets' );
    add_filter( 'pre_option_' . 'widget_rss', 'override_widget_rss' );
    add_filter( 'pre_option_' . 'widget_text', 'override_widget_text' );
    	}

    I suspect you could add your wp_bannerize option/widget in the same way.

    Speggey

    @speggey

    Hey, thanks for the reply.
    So I tried that with just a textwidget, couldn’t get the main blogs widgets to show up on the sub blogs though.

    I’ve looked in the codex on “get_blog_option” and can’t find any argument for ‘sidebar_widgets’..

    Any ideas?

    I tried that with just a textwidget

    Both blogs using the same theme?
    The above snippet pasted into the functions.php of that same theme?
    The main blog id is ‘1’?
    You’ve added the text widget to blog 1?

    I just tried these steps again and it works for me with twentyten.

    I’ve looked in the codex on “get_blog_option” and can’t find any argument for ‘sidebar_widgets’.

    get_blog_option is as generic as get_option except you can specify which blog you get the options from. You’ll need to look into your db wp_options table to see what options are there to dupe. Could be thousands to choose from, hundreds anyway.

    Speggey

    @speggey

    Both blogs using the same theme?
    The above snippet pasted into the functions.php of that same theme?
    The main blog id is ‘1’?
    You’ve added the text widget to blog 1?

    I just tried these steps again and it works for me with twentyten.

    Well the sub-blogs uses a child-theme of the main-blog. It’s built on starkers 3 which is built on twenty-ten.
    Main blog id is ‘1’ and I’m adding the text-widget to blog 1.
    Might have something to do with the child-theme? though it should use the same function.php file as I don’t have one in the child-theme, and even if I did it would just extend the main theme functions.php, right?

    get_blog_option is as generic as get_option except you can specify which blog you get the options from. You’ll need to look into your db wp_options table to see what options are there to dupe. Could be thousands to choose from, hundreds anyway.

    Oh ok, I will look into that, thanks!

    Speggey

    @speggey

    Ok so here’s what I’ve tried:

    function override_sidebars_widgets() {
    	$bar = get_blog_option('1','sidebars_widgets');
    	return $bar;
    }
    
    function override_widget_wp_bannerize() {
    	$bar = get_blog_option('1','widget_wp_bannerize');
    	return $bar;
    }
    
    global $blog_id;
    if($blog_id != '1') {
    	add_filter( 'pre_update_option_' . 'sidebars_widgets', 'override_sidebars_widgets' );
    	add_filter( 'pre_option_' . 'widget_wp_bannerize', 'override_widget_wp_bannerize' );
    }

    pre_update_option since I still want to use widgets independently on the sub blogs, right? I’ve also tried with pre_option_ on both but it doesn’t work and all the other widgets of the sub blog disappears.

    So in the main blogs widget_wp_bannerize column is:

    a:4:{i:2;a:0:{}i:3;a:11:{s:5:"title";s:0:"";s:5:"group";s:5:"right";s:6:"random";s:0:"";s:5:"limit";s:2:"10";s:10:"categories";N;s:16:"container_before";s:4:"<ul>";s:15:"container_after";s:5:"</ul>";s:6:"before";s:10:"<li %alt%>";s:5:"after";s:5:"</li>";s:9:"alt_class";s:3:"alt";s:10:"link_class";s:0:"";}i:4;a:11:{s:5:"title";s:0:"";s:5:"group";s:5:"right";s:6:"random";s:0:"";s:5:"limit";s:2:"10";s:10:"categories";N;s:16:"container_before";s:4:"<ul>";s:15:"container_after";s:5:"</ul>";s:6:"before";s:10:"<li %alt%>";s:5:"after";s:5:"</li>";s:9:"alt_class";s:3:"alt";s:10:"link_class";s:0:"";}s:12:"_multiwidget";i:1;}

    And in the sub blogs widget_wp_bannerize is:

    a:2:{i:2;a:0:{}s:12:"_multiwidget";i:1;}

    I’ve put the wp_bannerize widget in a dynamic sidebar called ‘ad-widget-area’ which I’m calling the same way in both the parent and the child theme.

    <?php dynamic_sidebar( 'ad-widget-area' ); ?>

    Should the plugin be activated on the network, separately on each blog or just on the main blog?

    Tried all three however and didn’t work either way.

    Any thoughts on what I’m doing wrong? Thanks a lot!

    Speggey

    @speggey

    Ok, so I’ve got it working with the text-widget but can’t get it to work with the plugin. Guess it doesn’t fetch the banners from the plugin correctly cause the options is there, echoed them with

    <pre><?php print_r(get_blog_option('4','widget_wp_bannerize') );?></pre>

    Did you have any success justinbriggs1?

    justinbriggs1

    @justinbriggs1

    I had success with a few of them, but I ran into a similar problem when I tried to use an ad-manager widget across all blogs. Didn’t work, not sure why. I ended up just using a text widget for the ads, so that sort of solved my problem.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Sub-blogs use the main blog widgets’ is closed to new replies.
Skip to toolbar