<?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: 3.00
Requires at least: 3.00
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",
    'isSelected'        => ($menu === 'my_custom_menu'), // set to true to display this menu as selected on menu
    //'class'           => "",                           // optional: add this class to menu <li> tag
    //'linkTarget'      => 'target="_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",
    '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'        => 'target="_blank"',            // optional: set this to open link in a new tab
  ];
  array_push($menuArray, $newMenu);

  return $menuArray;
}

// eof
