[wp-trac] [WordPress Trac] #39925: Using unset to remove menu items, unset's other than those to be unset
WordPress Trac
noreply at wordpress.org
Tue Feb 21 11:23:05 UTC 2017
#39925: Using unset to remove menu items, unset's other than those to be unset
---------------------------+-----------------------------
Reporter: patriknilsson | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 4.7.2
Severity: normal | Keywords:
Focuses: |
---------------------------+-----------------------------
I have in my Avada child's theme put a functions.php to hide sub-menus
other than that I currently is navigating. See function below.
This function is working as long as I don't use 'unset': Everywhere
"Remove!!" is should be removed.
When 'unset' is active (not commented) other than those with attribute
'$item->attr_title == "swp"' also get removed. It is always the same menu
items that get removed.
[http://www.fia.se/products/pump-systems/syringe-pumps/] hides main menu
"Services" even though it shouldn't.
{{{#!php
add_filter( 'wp_get_nav_menu_items','nav_items', 65535, 3 );
function nav_items( $items, $menu, $args )
{
if( is_admin() )
return $items;
global $wp;
$current_http_request_url =
home_url(add_query_arg(array(),$wp->request));
$current_http_request_path = parse_url($current_http_request_url,
PHP_URL_PATH);
$current_http_request_segments = explode('/',
ltrim(rtrim($current_http_request_path, '/'),'/'));
$bremove = 0;
foreach( $items as $key => $item )
{
$currentprocessing_url=$item->url;
$currentprocessing_path =
parse_url($currentprocessing_url, PHP_URL_PATH);
$currentprocessing_segments = explode('/',
ltrim(rtrim($currentprocessing_path, '/'),'/'));
if ( $item->attr_title == "swp" )
{
$buse = 1;
if ( count ( $current_http_request_segments ) >=
count ( $currentprocessing_segments ) - 1 )
{
for ($i=0; $i < count (
$currentprocessing_segments ) - 1; $i++)
{
if (
$current_http_request_segments [ $i ] != $currentprocessing_segments [ $i
] )
{
$buse = 0;
break;
}
}
}
else
{
$buse = 0;
}
if ( $buse == 0 )
{
$item->title = "Remove!!";
$bremove = 1;
}
}
}
if ( $bremove == 1 )
{
foreach( $items as $key => $item )
{
if ( $items [ $key ]->title == "Remove!!" )
{
unset ( $items [ $key ] );
}
}
}
return $items;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/39925>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list