cmatosbc / oopress-menus
Menus OOP structures and better iterators.
1.0.0
2024-11-11 12:27 UTC
Requires
- psr/simple-cache: ^3.0
README
Retrieve WP menus as pure data, as array or JSON. Also allows the data to be passed to a particular template in Wordpress.
Usage
Usage is pretty simple. You need to instantiate the class with the menu ID or slug, then use the method fetch() to access the data. Further, the method getItems() may return the structured menu data as array or JSON (using true). Finally, the method render() passes the menu data through a template part, rendering it (in the template, the menu data can be accessed from $args['data']).
// Create the instance for "menu-1" menu $menuData = (new \Oopress\Menus\Fetcher('testing')) ->fetch() ->getItems(true); // Fetches menu data and returns the data in JSON (or array if not TRUE)