WXP Restaurant Menu offers filters to change the data of the menu items, the data given to the templates, the icons, the renderer and the stylesheet. It has no action hooks. All names start with wxp_restaurant_menu_.
How to use a hook #
A filter receives a value, can change it and must return it. An action tells you that something happened, and returns nothing. Add your code to the functions.php of your child theme, or to a small plugin of your own. The last number of add_filter() and add_action() is the number of arguments your function receives; ask for as many as you need.
add_filter( 'hook_name', function ( $value, $extra ) {
// Change $value here.
return $value;
}, 10, 2 );
add_action( 'hook_name', function ( $first, $second ) {
// React here.
}, 10, 2 );
Overview #
| Hook | Type | What it does |
|---|---|---|
wxp_restaurant_menu_item_data |
Filter | Changes the template data of one menu item, for example to add fields. The ACF bridge of the plugin adds item.acf here. Twig escapes the values as HTML. |
wxp_restaurant_menu_template_context |
Filter | Changes the data passed to the menu template (the wxp_menu shortcode, block and widget). |
wxp_restaurant_menu_selection_context |
Filter | Changes the data passed to the template of a menu selection (the wxp_menu_selection shortcode, block and widget). |
wxp_restaurant_menu_icon_svg |
Filter | Changes the SVG of an icon reference, for example to support your own icon set. The result is cleaned with the SVG allow list of the plugin. |
wxp_restaurant_menu_renderer |
Filter | Replaces the renderer that is shared by the shortcode and the Elementor widget, for example to use another template engine than Twig. |
wxp_restaurant_menu_template_paths |
Filter | Changes the folders where templates are looked for, in lookup order. The folders of your (child) theme come before the templates folder of the plugin. |
wxp_restaurant_menu_twig_cache |
Filter | Sets a folder for the compiled templates. Caching is off by default, so no files are written. |
wxp_restaurant_menu_load_css |
Filter | Decides whether the plugin loads its own stylesheet. Return false to use your own CSS. |
Data #
wxp_restaurant_menu_item_data #
Filter. Changes the template data of one menu item, for example to add fields. The ACF bridge of the plugin adds item.acf here. Twig escapes the values as HTML.
| Argument | Type | Description |
|---|---|---|
$data |
array | The data of the item. |
$post |
WP_Post | The menu item. |
Return: the data of the item.
add_filter( 'wxp_restaurant_menu_item_data', function ( array $data, WP_Post $post ) {
$data['kitchen_note'] = (string) get_post_meta( $post->ID, 'kitchen_note', true );
return $data;
}, 10, 2 );
// In your template: {{ item.kitchen_note }}
wxp_restaurant_menu_template_context #
Filter. Changes the data passed to the menu template (the wxp_menu shortcode, block and widget).
| Argument | Type | Description |
|---|---|---|
$context |
array | The template data. |
$template |
string | The name of the template. |
$query |
MenuQuery | The selection that is shown. |
Return: the template data.
wxp_restaurant_menu_selection_context #
Filter. Changes the data passed to the template of a menu selection (the wxp_menu_selection shortcode, block and widget).
| Argument | Type | Description |
|---|---|---|
$context |
array | The template data. |
$name |
string | The name of the template, starting with selection-. |
$options |
SelectionOptions | The settings of the selection. |
Return: the template data.
wxp_restaurant_menu_icon_svg #
Filter. Changes the SVG of an icon reference, for example to support your own icon set. The result is cleaned with the SVG allow list of the plugin.
| Argument | Type | Description |
|---|---|---|
$svg |
string | The SVG markup, empty when the icon is unknown. |
$reference |
string | The icon reference. |
Return: the SVG markup.
Renderer, templates and stylesheet #
wxp_restaurant_menu_renderer #
Filter. Replaces the renderer that is shared by the shortcode and the Elementor widget, for example to use another template engine than Twig.
| Argument | Type | Description |
|---|---|---|
$renderer |
MenuRendererInterface | The default Twig renderer. |
Return: an object that implements MenuRendererInterface.
wxp_restaurant_menu_template_paths #
Filter. Changes the folders where templates are looked for, in lookup order. The folders of your (child) theme come before the templates folder of the plugin.
| Argument | Type | Description |
|---|---|---|
$paths |
string[] | Folders. |
Return: the list of folders.
add_filter( 'wxp_restaurant_menu_template_paths', function ( array $paths ) {
array_unshift( $paths, WP_CONTENT_DIR . '/my-menu-templates' );
return $paths;
} );
wxp_restaurant_menu_twig_cache #
Filter. Sets a folder for the compiled templates. Caching is off by default, so no files are written.
| Argument | Type | Description |
|---|---|---|
$cache |
string|false | A folder, or false (default). |
Return: a folder, or false.
wxp_restaurant_menu_load_css #
Filter. Decides whether the plugin loads its own stylesheet. Return false to use your own CSS.
| Argument | Type | Description |
|---|---|---|
$load |
bool | true by default. |
Return: true or false.
add_filter( 'wxp_restaurant_menu_load_css', '__return_false' );
Good to know #
- Own templates: to change the layout, copy a template from the
templatesfolder of the plugin towxp-restaurant-menu/in your (child) theme. You only need a hook when the template needs data that the plugin does not give. - Escaping: Twig escapes everything as HTML, also the values you add with
wxp_restaurant_menu_item_data.