SLB: Notes – Admin: Menus

By Sol in Lab

Differentiating between custom & default menus

  • Default: Themes, Media, Options, etc.
  • Custom: Added by plugin

Requirements

  • Obvious that the page is added to default or custom menu
    • When defining page
    • Unambiguous
  • Minimize additional text required to indicate default or custom

Implementation (Options)

  1. Reserved words
    • Maintain list (array) or reserved menu names that match default menus
      • Example: [theme, media, ...]
    • Menus will not be created if they match a reserved word (e.g. an existing default menu)
    • + Simple: No overlap
    • - Must maintain parity with default WP menus
      • If WP adds/modifies menu names, conflicts may occur
      • Not future-proof
  2. Check function name
    • Existence of add_{name}_page() function = WP Menu
      • Ex: add_media_page() adds page to default Media menu
    • On demand + cached check
      • Check for function when page added, add to static array for future checks
    • + Simple
    • - Restricted naming of custom menus
      • Cannot use reserved words
      • May create conflict if new menu added to future version of WP that matches custom name
  3. Wrap default names
    • Wrap name of menu in characters to indicate default menu
      • Ex: [theme] indicates that a page should be added to the WP Theme menu (not a custom menu named “theme”)
    • + Clear/obvious default menu is desired
    • - Requires additional characters to define
    • + Allows same names for custom menus (prefixed anyway)
    • + WP menus will get custom methods anyway
      • Wraps core method and passes wrapped name
    • + Only used internally for most part
    • + Pages can be added to WP menus even if custom methods are not defined (e.g. in a future version of WP with new menus)