Advertisement
Guest User

Menu.php

a guest
May 28th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.59 KB | None | 0 0
  1. <?php
  2.  
  3. if ( !defined('ABSPATH') ) exit;
  4.  
  5. class Menu {
  6.  
  7.     private $flat_menu;
  8.     public $items;
  9.  
  10.     public function __construct( $name ) {
  11.  
  12.         $this->flat_menu = wp_get_nav_menu_items($name);
  13.         $this->items = [];
  14.         foreach ($this->flat_menu as $item) {
  15.             if (!$item->menu_item_parent) {
  16.                 array_push($this->items, $item);
  17.             }
  18.         }
  19.     }
  20.  
  21.     public function get_submenu( $item ) {
  22.  
  23.         $this->submenu = [];
  24.         foreach ($this->flat_menu as $subitem) {
  25.             if ($subitem->menu_item_parent == $item->ID) {
  26.                 array_push($this->submenu, $subitem);
  27.             }
  28.         }
  29.  
  30.         return $this->submenu;
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement