plugin development - Same headerfooter in Admin, across all network sites in multisite

admin2025-01-07  3

I was kicking around a few ideas to accomplish this and came up with something a little strange...but it works.

I'm creating a theme for Admin, for my multisite network. The users will be exposed to both front-end and back-end pages when they are logged in, so it is important to me to have a consistent look as they traverse both spaces -- I don't want them dropping into the WP "plain old" Admin dashboard.

So, how do you get the base site's themed header/footer to show up on any networked site, when the user is logged in and in the back end?

I was kicking around a few ideas to accomplish this and came up with something a little strange...but it works.

I'm creating a theme for Admin, for my multisite network. The users will be exposed to both front-end and back-end pages when they are logged in, so it is important to me to have a consistent look as they traverse both spaces -- I don't want them dropping into the WP "plain old" Admin dashboard.

So, how do you get the base site's themed header/footer to show up on any networked site, when the user is logged in and in the back end?

Share Improve this question asked Jul 8, 2016 at 14:33 C CC C 1,95818 silver badges31 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Here's what I did:

Inserted ob_start() and ob_get_clean(), at strategic places in header.php and footer.php within a child theme derived from my base site's main theme.

<some header stuff> 
ob_start()  
<header html I want to reuse across network>
<?php $html = ob_get_clean(); echo $html; harvest_html($html, 'header'); ?>

The function harvest_html simply takes the string and writes it out to a file. I do the same thing for the footer. To keep overhead down, I only allow this function to execute when the user is_super_admin(). As long as the super admin logs in at least once, the header/footer will be harvested.

Then, in a simple plugin, I inject the harvested html into Admin by hooking to admin_head and in_admin_footer. Of course, any required CSS or JS needs to be enqueued at that time, too.

It works. Any user who is logged into their subdomain site and goes to any Admin page will get the header/footer of the base site, regardless of the theme they are currently using.

And, it's relatively low maintenance since any changes made to header/footer for the base site will be automatically harvested.

I also handle pieces of header/footer that are dynamic (e.g. if some PHP echoes the user's name or time of day, etc.) by parsing out function calls, identified by a special wrapper I put around them, then eval'ing them back in at the point they are injected in Admin.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736263915a927.html

最新回复(0)