| 1 |
<?php |
| 2 |
|
| 3 |
add_filter( 'wp_get_nav_menu_items', 'bogo_get_nav_menu_items', 10, 3 ); |
| 4 |
|
| 5 |
function bogo_get_nav_menu_items( $items, $menu, $args ) { |
| 6 |
if ( is_admin() ) { |
| 7 |
return $items; |
| 8 |
} |
| 9 |
|
| 10 |
$locale = get_locale(); |
| 11 |
|
| 12 |
foreach ( $items as $key => $item ) { |
| 13 |
if ( ! in_array( $locale, $item->bogo_locales ) ) { |
| 14 |
unset( $items[$key] ); |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
return $items; |
| 19 |
} |
| 20 |
|
| 21 |
add_filter( 'wp_setup_nav_menu_item', 'bogo_setup_nav_menu_item' ); |
| 22 |
|
| 23 |
function bogo_setup_nav_menu_item( $menu_item ) { |
| 24 |
if ( isset( $menu_item->bogo_locales ) ) { |
| 25 |
return $menu_item; |
| 26 |
} |
| 27 |
|
| 28 |
$menu_item->bogo_locales = array(); |
| 29 |
|
| 30 |
if ( isset( $menu_item->post_type ) && 'nav_menu_item' == $menu_item->post_type ) { |
| 31 |
$menu_item->bogo_locales = get_post_meta( $menu_item->ID, '_locale' ); |
| 32 |
} |
| 33 |
|
| 34 |
if ( $menu_item->bogo_locales ) { |
| 35 |
$menu_item->bogo_locales = bogo_filter_locales( $menu_item->bogo_locales ); |
| 36 |
} else { |
| 37 |
$menu_item->bogo_locales = bogo_available_locales(); |
| 38 |
} |
| 39 |
|
| 40 |
return $menu_item; |
| 41 |
} |
| 42 |
|
| 43 |
?> |