Menus
extends AbstractResource
in package
Table of Contents
Properties
Methods
- __construct() : mixed
- all() : PaginatedResponse
- Fetch all items with optional parameters
- buildHierarchy() : array<int, array<string, mixed>>
- Build hierarchical menu structure
- get() : array<string, mixed>
- Fetch a single item by ID
- getBaseUrl() : string
- Get the base URL
- getByLocation() : array<string, mixed>|null
- Get menu by location (e.g., 'primary', 'footer')
- getBySlug() : array<string, mixed>
- Get menu by slug
- getBySlugWithItems() : array{menu: array, items: array}
- Get menu by slug with its items
- getHttpClient() : Client
- Get the HTTP client
- getItems() : array<int, array<string, mixed>>
- Get menu items for a specific menu
- getWithItems() : array{menu: array, items: array}
- Get menu with its items
- language() : QueryBuilder
- Filter by language (WPML support)
- orderBy() : QueryBuilder
- Set order by
- page() : QueryBuilder
- Set page number
- perPage() : QueryBuilder
- Set results per page
- query() : PaginatedResponse
- Custom query with parameters
- search() : QueryBuilder
- Search within the resource
- where() : QueryBuilder
- Start building a query
Properties
$baseUrl
protected
string
$baseUrl
$client
protected
Client
$client
$endpoint
protected
string
$endpoint
Methods
__construct()
public
__construct(Client $client, string $baseUrl, string $endpoint) : mixed
Parameters
- $client : Client
- $baseUrl : string
- $endpoint : string
all()
Fetch all items with optional parameters
public
all([array<string, mixed> $params = [] ]) : PaginatedResponse
Parameters
- $params : array<string, mixed> = []
Return values
PaginatedResponsebuildHierarchy()
Build hierarchical menu structure
public
buildHierarchy(array<int, array<string, mixed>> $items) : array<int, array<string, mixed>>
Organizes flat menu items into a hierarchical tree structure.
Parameters
- $items : array<int, array<string, mixed>>
-
Flat array of menu items
Return values
array<int, array<string, mixed>> —Hierarchical menu structure
get()
Fetch a single item by ID
public
get(int $id) : array<string, mixed>
Parameters
- $id : int
Tags
Return values
array<string, mixed>getBaseUrl()
Get the base URL
public
getBaseUrl() : string
Return values
stringgetByLocation()
Get menu by location (e.g., 'primary', 'footer')
public
getByLocation(string $location) : array<string, mixed>|null
Note: This requires the menu location to be set in WordPress theme.
Parameters
- $location : string
-
Menu location slug
Tags
Return values
array<string, mixed>|nullgetBySlug()
Get menu by slug
public
getBySlug(string $slug) : array<string, mixed>
Parameters
- $slug : string
Tags
Return values
array<string, mixed>getBySlugWithItems()
Get menu by slug with its items
public
getBySlugWithItems(string $slug) : array{menu: array, items: array}
Parameters
- $slug : string
-
Menu slug
Tags
Return values
array{menu: array, items: array}getHttpClient()
Get the HTTP client
public
getHttpClient() : Client
Return values
ClientgetItems()
Get menu items for a specific menu
public
getItems(int $menuId) : array<int, array<string, mixed>>
Parameters
- $menuId : int
-
Menu ID or term_id
Tags
Return values
array<int, array<string, mixed>>getWithItems()
Get menu with its items
public
getWithItems(int $menuId) : array{menu: array, items: array}
This is a convenience method that fetches both the menu and its items.
Parameters
- $menuId : int
-
Menu ID
Tags
Return values
array{menu: array, items: array}language()
Filter by language (WPML support)
public
language(string $languageCode) : QueryBuilder
Parameters
- $languageCode : string
Return values
QueryBuilderorderBy()
Set order by
public
orderBy(string $field[, string $direction = 'asc' ]) : QueryBuilder
Parameters
- $field : string
- $direction : string = 'asc'
Return values
QueryBuilderpage()
Set page number
public
page(int $page) : QueryBuilder
Parameters
- $page : int
Return values
QueryBuilderperPage()
Set results per page
public
perPage(int $perPage) : QueryBuilder
Parameters
- $perPage : int
Return values
QueryBuilderquery()
Custom query with parameters
public
query(array<string, mixed> $params) : PaginatedResponse
Parameters
- $params : array<string, mixed>
Tags
Return values
PaginatedResponsesearch()
Search within the resource
public
search(string $term) : QueryBuilder
Parameters
- $term : string
Return values
QueryBuilderwhere()
Start building a query
public
where(string $key, mixed $value) : QueryBuilder
Parameters
- $key : string
- $value : mixed