Skip to content

Instantly share code, notes, and snippets.

@thomaswilburn
Created November 19, 2014 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomaswilburn/b98b4f6f5e9ee06855ba to your computer and use it in GitHub Desktop.
Save thomaswilburn/b98b4f6f5e9ee06855ba to your computer and use it in GitHub Desktop.
Multi-site menu attempt
<?php
//the slot is the menu location string you registered for the global menu
$slot = "menu_name_here";
function global_multisite_nav_menu_filter( $content, $args ) {
global $slot;
$registered = get_registered_nav_menus();
if( !isset( $registered[$slot] ) )
return $content;
if( !is_main_site() ) {
$network_menu = get_site_option( 'ra_network_menu' );
if( !empty( $network_menu ) )
return $network_menu;
} elseif( !get_option( 'ra_network_menu' ) ) {
update_option( 'ra_network_menu', '1' );
update_site_option( 'ra_network_menu', $content );
}
return $content;
}
add_filter( 'wp_nav_menu_objects', 'global_multisite_nav_menu_filter', 10, 2 );
function global_multisite_nav_menu_flush( $post_id, $post ) {
if( is_main_site() && $post->post_type == 'nav_menu_item' )
update_option( 'ra_network_menu', '' );
}
add_action( 'save_post', 'global_multisite_nav_menu_flush', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment