cmatosbc/oopress-menus

Menus OOP structures and better iterators.

1.0.0 2024-11-11 12:27 UTC

This package is auto-updated.

Last update: 2024-11-12 09:47:45 UTC


README

Retrieve WP menus as pure data, as array or JSON. Also allows the data to be passed to a particular template in Wordpress.

OOPress

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)