0

I'm using S2Member + Buddypress on a compatible template. I have 8 menu items and am using the "Menu Items Visibility Control" to limit the 7th for view only to current_user_is(s2member_level1) | in_array('administrator', $GLOBALS['current_user']->roles) This visibility is working correctly.

I'm in need of a way to create a custom menu item that will link to a page containing the following structure:

http://localhost/%%current_user_nicename%%/events/my-events/?action=edit

I don't know how to incorporate the current user name into the URL. I've come across this post:.

*There must be an easy fix, if I leave a custom menu item's URL blank..can I specify the url elsewhere in my code?

closed as off-topic by Pieter Goosen, cybmeta, Mark Kaplun, mor7ifer, Wyck Feb 6 '15 at 22:08

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

1

Congrats on figuring it out. Perhaps this would also work:

function change_menu($items){
  foreach($items as $item){

   if ($item-> post_name == 'the-slug')/*replace "the-slug" with menu item post_name */
        $item->url = bp_loggedin_user_domain() . '/events/my-events/?action=edit';

  }
  return $items;

}
add_filter('wp_nav_menu_objects', 'change_menu');
0

I figured it out with a filter function. This finds the nav menu obj matching the given slug and then modifies it's URL. I left the Menu item with visibility control in my dashboard menu. The URL is initially blank.

Added to functions.php:


function getUN()
{
    global $current_user;
      get_currentuserinfo();

      return  $current_user->user_login;
}

function change_menu($items){
  foreach($items as $item){

if ($item-> post_name == 'the-slug')/*replace "the-slug" with menu item post_name */
{
    $item->url = get_site_url().'/members/'.getUN().'/events/my-events/?action=edit';

  }
  }
  return $items;

}

add_filter('wp_nav_menu_objects', 'change_menu');

Not the answer you're looking for? Browse other questions tagged or ask your own question.