<?php
/*
Plugin Name: Modify Header Links
Description: Examples of how to add, modify, or remove links from the CMS header (Logoff, Help, License, etc).
Version: 1.02
Requires at least: 3.05
Author: Dave E
*/

// NOTE: RENAME this plugin so when you download updates you don't OVERWRITE your changes!!!

addFilter('menulinks_myAccount', 'modifyHeaderLinks');

//
function modifyHeaderLinks($menuArray) {

  // Example of custom menu:
  /*
  $newMenu[] = [
    'menuName'          => t('My Custom Menu'),
    'menuType'          => 'custom',
    'link'              => "?my_custom=link",
    'visibility'        => 'showAlways',                 // options: showAlways, requireLogin, requireAdmin, requireSectionAccess
    'isSelected'        => ($menu === 'my_custom_menu'), // set to true to display this menu as selected on menu
    //'liClass'         => "",                           // optional: add this class to menu <li> tag
    //'linkTarget'      => '_blank',                     // optional: set this to open link in a new tab
    //'br_after'        => true,                         // optional: add line break after menu item instead of separator ("|")
  ];
  */

  // remove license link
  foreach ($menuArray as $index => $menuAttr) {
    if (preg_match("/\b(menu=license)\b/", @$menuAttr['link'])) { unset($menuArray[$index]); }
  }

  // add links to the beginning
  $newMenu = [
    'menuName'          => t('New Menu'),
    'menuType'          => 'custom',
    'link'              => "?menu=new_menu",
    'visibility'        => 'requireLogin',                     // will be displayed in the user is logged in
    'isSelected'        => (@$_REQUEST['menu'] == 'new_menu'), // set to true to show this menu as selected
    'br_after'          => true,                               // optional: add line break after menu item instead of separator ("|")
  ];
  array_unshift($menuArray, $newMenu);

  // add links to the end
  $newMenu = [
    'menuName'          => 'Google', 
    'menuType'          => 'custom',
    'link'              => "https://www.google.com/",
    'isSelected'        => false,                     // set to true to show this menu as selected
    'linkTarget'        => '_blank',                  // optional: set this to open link in a new tab
    'visibility'        => 'showAlways',              // will be displayed always
  ];
  array_push($menuArray, $newMenu);

  return $menuArray;
}

// eof
