Sidebars are great.  Multisite is great.  Doing something once so that it can be shared across an entire network is great, too.

So, it should stand to reason that sharing a specific sidebar, or set of sidebars, across an entire multisite network should be just as great (and easy), right?

Well, if it were, we wouldn’t be here right now.

I know what you may be thinking…

Just use switch_to_blog(), ya dingus!

Oh, how I wish it were that easy!  That was our first guess as well, but it unfortunately didn’t do the trick.  Apparently, switch_to_blog() is a trick that does not work when attempting to share a sidebar across a network.  Total bummer.

In our situation, though, we had a set of sidebars in our footer that we wanted the client to be able to manage but also share across every site within their network.  So, hardcoding the widgets in place wouldn’t have been a proper solution; neither would have been telling the client that they would need to manage three sidebars on 300+ sites.  Ouch.

We had our task: allow a set of sidebars to be displayed across the sites in a multisite network.

We had our problem: switch_to_blog() doesn’t work for this, so we needed to figure out another way to accomplish our goal.

Now we have our solution.

The first thing we want to do is build the output of our sidebars. That seems kind of important, right? Can’t see some sidebars if we’re not telling the sidebars to display. We don’t want to just display the sidebars and be done with it, though. What we want to do is store our sidebars in a transient. This transient will be deleted whenever a widget is updated in one of our three sidebars (you’ll see this later, be patient!). In order to store our set of sidebars as a variable, we need to wrap everything in an output buffer.

Sidebars are great.  Multisite is great.  Doing something once so that it can be shared across an entire network is great, too.

So, it should stand to reason that sharing a specific sidebar, or set of sidebars, across an entire multisite network should be just as great (and easy), right?

Well, if it were, we wouldn�t be here right now.

I know what you may be thinking...
<blockquote>Just use switch_to_blog(), ya dingus!</blockquote>
Oh, how I wish it were that easy!  That was our first guess as well, but it unfortunately didn't do the trick.  Apparently, switch_to_blog() is a trick that does not work when attempting to share a sidebar across a network.  Total bummer.

In our situation, though, we had a set of sidebars in our footer that we wanted the client to be able to manage but also share across every site within their network.  So, hardcoding the widgets in place wouldn't have been a proper solution; neither would have been telling the client that they would need to manage three sidebars on 300+ sites.  Ouch.

We had our task: allow a set of sidebars to be displayed across the sites in a multisite network.

We had our problem: switch_to_blog() doesn't work for this, so we needed to figure out another way to accomplish our goal.

Now we have our solution.

The first thing we want to do is build the output of our sidebars. That seems kind of important, right? Can't see some sidebars if we're not telling the sidebars to display. We don't want to just display the sidebars and be done with it, though. What we want to do is store our sidebars in a transient. This transient will be deleted whenever a widget is updated in one of our three sidebars (you'll see this later, be patient!). In order to store our set of sidebars as a variable, we need to wrap everything in an output buffer.

[snippet id=7941]

Next comes our theme's footer. This is a big more straight forward - we want to get the site transient that we established in our functions file above, then display its contents.

[snippet id=7942]

Now we should have our sidebars displaying, but we also want some additional magic to happen. We need to clear our transient when a widget is updated or saved in one of our three footer sidebars.  The first step of this process is to enqueue some scripts that we're going to be using. I'm doing this in a separate file housing all of our AJAX-related commands, ajax-functions.php in our theme's /inc/ directory.

[snippet id=7943]

In the same file, we want to create the AJAX function that runs when updating our sidebars. This function checks to make sure our nonce is present; if it is, it deletes the site transient.

[snippet id=7944]

We'll need a JavaScript file to handle some back-end functionality, and we'll need to localize the script so we can interact with that file.  We're passing a nonce in our script as well; this will ensure that our widget form is being updated properly.

Finally, we want to create the AJAX that is going to listen for an updated widget. With jQuery first, we're listening for a click on the remove, close, or save links on individual widgets within one of our three specific sidebars. If one of those links is clicked and we're in one of our specified sidebars, we want to run our AJAX function.

[snippet id=7945]

And that's about it! Now you can manage a set of sidebars on the main site within your network and pass those sidebars to every site within your network. One set of widgets to manage for an entire network of sites. It wasn't the solution that jumped out at us at first, but it's the one we found and it's the one that works for us. We're pretty happy with the way it turned out, and we think the client is going to be happy only having to edit their widgets once and have those changes visible on 300+ sites.

Next comes our theme’s footer. This is a big more straight forward – we want to get the site transient that we established in our functions file above, then display its contents.

Sidebars are great.  Multisite is great.  Doing something once so that it can be shared across an entire network is great, too.

So, it should stand to reason that sharing a specific sidebar, or set of sidebars, across an entire multisite network should be just as great (and easy), right?

Well, if it were, we wouldn�t be here right now.

I know what you may be thinking...
<blockquote>Just use switch_to_blog(), ya dingus!</blockquote>
Oh, how I wish it were that easy!  That was our first guess as well, but it unfortunately didn't do the trick.  Apparently, switch_to_blog() is a trick that does not work when attempting to share a sidebar across a network.  Total bummer.

In our situation, though, we had a set of sidebars in our footer that we wanted the client to be able to manage but also share across every site within their network.  So, hardcoding the widgets in place wouldn't have been a proper solution; neither would have been telling the client that they would need to manage three sidebars on 300+ sites.  Ouch.

We had our task: allow a set of sidebars to be displayed across the sites in a multisite network.

We had our problem: switch_to_blog() doesn't work for this, so we needed to figure out another way to accomplish our goal.

Now we have our solution.

The first thing we want to do is build the output of our sidebars. That seems kind of important, right? Can't see some sidebars if we're not telling the sidebars to display. We don't want to just display the sidebars and be done with it, though. What we want to do is store our sidebars in a transient. This transient will be deleted whenever a widget is updated in one of our three sidebars (you'll see this later, be patient!). In order to store our set of sidebars as a variable, we need to wrap everything in an output buffer.

[snippet id=7941]

Next comes our theme's footer. This is a big more straight forward - we want to get the site transient that we established in our functions file above, then display its contents.

[snippet id=7942]

Now we should have our sidebars displaying, but we also want some additional magic to happen. We need to clear our transient when a widget is updated or saved in one of our three footer sidebars.  The first step of this process is to enqueue some scripts that we're going to be using. I'm doing this in a separate file housing all of our AJAX-related commands, ajax-functions.php in our theme's /inc/ directory.

[snippet id=7943]

In the same file, we want to create the AJAX function that runs when updating our sidebars. This function checks to make sure our nonce is present; if it is, it deletes the site transient.

[snippet id=7944]

We'll need a JavaScript file to handle some back-end functionality, and we'll need to localize the script so we can interact with that file.  We're passing a nonce in our script as well; this will ensure that our widget form is being updated properly.

Finally, we want to create the AJAX that is going to listen for an updated widget. With jQuery first, we're listening for a click on the remove, close, or save links on individual widgets within one of our three specific sidebars. If one of those links is clicked and we're in one of our specified sidebars, we want to run our AJAX function.

[snippet id=7945]

And that's about it! Now you can manage a set of sidebars on the main site within your network and pass those sidebars to every site within your network. One set of widgets to manage for an entire network of sites. It wasn't the solution that jumped out at us at first, but it's the one we found and it's the one that works for us. We're pretty happy with the way it turned out, and we think the client is going to be happy only having to edit their widgets once and have those changes visible on 300+ sites.

Now we should have our sidebars displaying, but we also want some additional magic to happen. We need to clear our transient when a widget is updated or saved in one of our three footer sidebars.  The first step of this process is to enqueue some scripts that we’re going to be using. I’m doing this in a separate file housing all of our AJAX-related commands, ajax-functions.php in our theme’s /inc/ directory.

Sidebars are great.  Multisite is great.  Doing something once so that it can be shared across an entire network is great, too.

So, it should stand to reason that sharing a specific sidebar, or set of sidebars, across an entire multisite network should be just as great (and easy), right?

Well, if it were, we wouldn�t be here right now.

I know what you may be thinking...
<blockquote>Just use switch_to_blog(), ya dingus!</blockquote>
Oh, how I wish it were that easy!  That was our first guess as well, but it unfortunately didn't do the trick.  Apparently, switch_to_blog() is a trick that does not work when attempting to share a sidebar across a network.  Total bummer.

In our situation, though, we had a set of sidebars in our footer that we wanted the client to be able to manage but also share across every site within their network.  So, hardcoding the widgets in place wouldn't have been a proper solution; neither would have been telling the client that they would need to manage three sidebars on 300+ sites.  Ouch.

We had our task: allow a set of sidebars to be displayed across the sites in a multisite network.

We had our problem: switch_to_blog() doesn't work for this, so we needed to figure out another way to accomplish our goal.

Now we have our solution.

The first thing we want to do is build the output of our sidebars. That seems kind of important, right? Can't see some sidebars if we're not telling the sidebars to display. We don't want to just display the sidebars and be done with it, though. What we want to do is store our sidebars in a transient. This transient will be deleted whenever a widget is updated in one of our three sidebars (you'll see this later, be patient!). In order to store our set of sidebars as a variable, we need to wrap everything in an output buffer.

[snippet id=7941]

Next comes our theme's footer. This is a big more straight forward - we want to get the site transient that we established in our functions file above, then display its contents.

[snippet id=7942]

Now we should have our sidebars displaying, but we also want some additional magic to happen. We need to clear our transient when a widget is updated or saved in one of our three footer sidebars.  The first step of this process is to enqueue some scripts that we're going to be using. I'm doing this in a separate file housing all of our AJAX-related commands, ajax-functions.php in our theme's /inc/ directory.

[snippet id=7943]

In the same file, we want to create the AJAX function that runs when updating our sidebars. This function checks to make sure our nonce is present; if it is, it deletes the site transient.

[snippet id=7944]

We'll need a JavaScript file to handle some back-end functionality, and we'll need to localize the script so we can interact with that file.  We're passing a nonce in our script as well; this will ensure that our widget form is being updated properly.

Finally, we want to create the AJAX that is going to listen for an updated widget. With jQuery first, we're listening for a click on the remove, close, or save links on individual widgets within one of our three specific sidebars. If one of those links is clicked and we're in one of our specified sidebars, we want to run our AJAX function.

[snippet id=7945]

And that's about it! Now you can manage a set of sidebars on the main site within your network and pass those sidebars to every site within your network. One set of widgets to manage for an entire network of sites. It wasn't the solution that jumped out at us at first, but it's the one we found and it's the one that works for us. We're pretty happy with the way it turned out, and we think the client is going to be happy only having to edit their widgets once and have those changes visible on 300+ sites.

In the same file, we want to create the AJAX function that runs when updating our sidebars. This function checks to make sure our nonce is present; if it is, it deletes the site transient.

Sidebars are great.  Multisite is great.  Doing something once so that it can be shared across an entire network is great, too.

So, it should stand to reason that sharing a specific sidebar, or set of sidebars, across an entire multisite network should be just as great (and easy), right?

Well, if it were, we wouldn�t be here right now.

I know what you may be thinking...
<blockquote>Just use switch_to_blog(), ya dingus!</blockquote>
Oh, how I wish it were that easy!  That was our first guess as well, but it unfortunately didn't do the trick.  Apparently, switch_to_blog() is a trick that does not work when attempting to share a sidebar across a network.  Total bummer.

In our situation, though, we had a set of sidebars in our footer that we wanted the client to be able to manage but also share across every site within their network.  So, hardcoding the widgets in place wouldn't have been a proper solution; neither would have been telling the client that they would need to manage three sidebars on 300+ sites.  Ouch.

We had our task: allow a set of sidebars to be displayed across the sites in a multisite network.

We had our problem: switch_to_blog() doesn't work for this, so we needed to figure out another way to accomplish our goal.

Now we have our solution.

The first thing we want to do is build the output of our sidebars. That seems kind of important, right? Can't see some sidebars if we're not telling the sidebars to display. We don't want to just display the sidebars and be done with it, though. What we want to do is store our sidebars in a transient. This transient will be deleted whenever a widget is updated in one of our three sidebars (you'll see this later, be patient!). In order to store our set of sidebars as a variable, we need to wrap everything in an output buffer.

[snippet id=7941]

Next comes our theme's footer. This is a big more straight forward - we want to get the site transient that we established in our functions file above, then display its contents.

[snippet id=7942]

Now we should have our sidebars displaying, but we also want some additional magic to happen. We need to clear our transient when a widget is updated or saved in one of our three footer sidebars.  The first step of this process is to enqueue some scripts that we're going to be using. I'm doing this in a separate file housing all of our AJAX-related commands, ajax-functions.php in our theme's /inc/ directory.

[snippet id=7943]

In the same file, we want to create the AJAX function that runs when updating our sidebars. This function checks to make sure our nonce is present; if it is, it deletes the site transient.

[snippet id=7944]

We'll need a JavaScript file to handle some back-end functionality, and we'll need to localize the script so we can interact with that file.  We're passing a nonce in our script as well; this will ensure that our widget form is being updated properly.

Finally, we want to create the AJAX that is going to listen for an updated widget. With jQuery first, we're listening for a click on the remove, close, or save links on individual widgets within one of our three specific sidebars. If one of those links is clicked and we're in one of our specified sidebars, we want to run our AJAX function.

[snippet id=7945]

And that's about it! Now you can manage a set of sidebars on the main site within your network and pass those sidebars to every site within your network. One set of widgets to manage for an entire network of sites. It wasn't the solution that jumped out at us at first, but it's the one we found and it's the one that works for us. We're pretty happy with the way it turned out, and we think the client is going to be happy only having to edit their widgets once and have those changes visible on 300+ sites.

We’ll need a JavaScript file to handle some back-end functionality, and we’ll need to localize the script so we can interact with that file.  We’re passing a nonce in our script as well; this will ensure that our widget form is being updated properly.

Finally, we want to create the AJAX that is going to listen for an updated widget. With jQuery first, we’re listening for a click on the remove, close, or save links on individual widgets within one of our three specific sidebars. If one of those links is clicked and we’re in one of our specified sidebars, we want to run our AJAX function.

Sidebars are great.  Multisite is great.  Doing something once so that it can be shared across an entire network is great, too.

So, it should stand to reason that sharing a specific sidebar, or set of sidebars, across an entire multisite network should be just as great (and easy), right?

Well, if it were, we wouldn�t be here right now.

I know what you may be thinking...
<blockquote>Just use switch_to_blog(), ya dingus!</blockquote>
Oh, how I wish it were that easy!  That was our first guess as well, but it unfortunately didn't do the trick.  Apparently, switch_to_blog() is a trick that does not work when attempting to share a sidebar across a network.  Total bummer.

In our situation, though, we had a set of sidebars in our footer that we wanted the client to be able to manage but also share across every site within their network.  So, hardcoding the widgets in place wouldn't have been a proper solution; neither would have been telling the client that they would need to manage three sidebars on 300+ sites.  Ouch.

We had our task: allow a set of sidebars to be displayed across the sites in a multisite network.

We had our problem: switch_to_blog() doesn't work for this, so we needed to figure out another way to accomplish our goal.

Now we have our solution.

The first thing we want to do is build the output of our sidebars. That seems kind of important, right? Can't see some sidebars if we're not telling the sidebars to display. We don't want to just display the sidebars and be done with it, though. What we want to do is store our sidebars in a transient. This transient will be deleted whenever a widget is updated in one of our three sidebars (you'll see this later, be patient!). In order to store our set of sidebars as a variable, we need to wrap everything in an output buffer.

[snippet id=7941]

Next comes our theme's footer. This is a big more straight forward - we want to get the site transient that we established in our functions file above, then display its contents.

[snippet id=7942]

Now we should have our sidebars displaying, but we also want some additional magic to happen. We need to clear our transient when a widget is updated or saved in one of our three footer sidebars.  The first step of this process is to enqueue some scripts that we're going to be using. I'm doing this in a separate file housing all of our AJAX-related commands, ajax-functions.php in our theme's /inc/ directory.

[snippet id=7943]

In the same file, we want to create the AJAX function that runs when updating our sidebars. This function checks to make sure our nonce is present; if it is, it deletes the site transient.

[snippet id=7944]

We'll need a JavaScript file to handle some back-end functionality, and we'll need to localize the script so we can interact with that file.  We're passing a nonce in our script as well; this will ensure that our widget form is being updated properly.

Finally, we want to create the AJAX that is going to listen for an updated widget. With jQuery first, we're listening for a click on the remove, close, or save links on individual widgets within one of our three specific sidebars. If one of those links is clicked and we're in one of our specified sidebars, we want to run our AJAX function.

[snippet id=7945]

And that's about it! Now you can manage a set of sidebars on the main site within your network and pass those sidebars to every site within your network. One set of widgets to manage for an entire network of sites. It wasn't the solution that jumped out at us at first, but it's the one we found and it's the one that works for us. We're pretty happy with the way it turned out, and we think the client is going to be happy only having to edit their widgets once and have those changes visible on 300+ sites.

And that’s about it! Now you can manage a set of sidebars on the main site within your network and pass those sidebars to every site within your network. One set of widgets to manage for an entire network of sites. It wasn’t the solution that jumped out at us at first, but it’s the one we found and it’s the one that works for us. We’re pretty happy with the way it turned out, and we think the client is going to be happy only having to edit their widgets once and have those changes visible on 300+ sites.

via WebDevStudios.com http://webdevstudios.com/2013/12/17/sharing-sidebars-across-a-multisite-network/

Article by


Leave a Reply

Your email address will not be published. Required fields are marked *