Skip to content
Docs
Get RestroPress

Function

Allergens functions

Updated
On this page

Functions for the 14 standard allergens: assigning them to menu items, showing badges and filtering the menu.

34 functions. Each entry shows the signature, parameters, return value and where it is defined. Functions marked internal are hook callbacks, screen renderers and other plumbing that extensions normally do not call.

rpress_allergens_editor_section()#

Prints the Allergens section of the menu item editor.

Shows a Contains multi-select, posted through tax_input so WordPress saves it with its own capability checks, and a May contain traces of multi-select posted as rpress_allergen_traces. Hooked to rpress_fooditem_section_after_category.

rpress_allergens_editor_section( $post )

Parameters

ParameterTypeDefaultDescription
$postWP_PostRequiredMenu item being edited.

Note: Echoes output instead of returning it.

Internal. Defined in includes/features/allergens/admin.php, line 23.

rpress_allergens_save_traces()#

Saves the May contain traces of selection when a menu item is saved in the editor.

Hooked to save_post_fooditem. Runs only when rpress_allergen_traces and the editor nonce are posted, so quick edit and imports do not clear it. Stores valid term IDs in the _rpress_allergen_traces post meta, or deletes the meta when the list is empty.

rpress_allergens_save_traces( $post_id )

Parameters

ParameterTypeDefaultDescription
$post_idintRequiredPost ID.

Internal. Defined in includes/features/allergens/admin.php, line 117.

rpress_allergens_term_add_field()#

Prints the Badge code field on the Add New Allergen form.

rpress_allergens_term_add_field()

Note: Echoes output instead of returning it.

Internal. Defined in includes/features/allergens/admin.php, line 153.

rpress_allergens_term_edit_field()#

Prints the Badge code field on the Edit Allergen form.

rpress_allergens_term_edit_field( $term )

Parameters

ParameterTypeDefaultDescription
$termWP_TermRequiredTerm being edited.

Note: Echoes output instead of returning it.

Internal. Defined in includes/features/allergens/admin.php, line 171.

rpress_allergens_term_save_code()#

Saves the badge code from the allergen term add and edit forms.

Checks the add-tag or update-tag nonce and the taxonomy's edit_terms capability. The code is stripped to letters and digits, cut to three characters and upper-cased, and stored in the rpress_allergen_code term meta. An empty value deletes it.

rpress_allergens_term_save_code( $term_id )

Parameters

ParameterTypeDefaultDescription
$term_idintRequiredTerm ID.

Internal. Defined in includes/features/allergens/admin.php, line 194.

rpress_allergens_term_columns()#

Adds a Badge column after the name in the Allergens term list.

rpress_allergens_term_columns( $columns )

Parameters

ParameterTypeDefaultDescription
$columnsarrayRequiredList table columns.

Returns array: Columns with rpress_allergen_code inserted.

Internal. Defined in includes/features/allergens/admin.php, line 225.

rpress_allergens_term_column_content()#

Returns the badge code for the Badge column of the Allergens term list.

rpress_allergens_term_column_content( $content, $column, $term_id )

Parameters

ParameterTypeDefaultDescription
$contentstringRequiredColumn content.
$columnstringRequiredColumn name.
$term_idintRequiredTerm ID.

Returns string: Escaped badge code for the Badge column, otherwise the incoming content.

Internal. Defined in includes/features/allergens/admin.php, line 246.

rpress_allergens_render_card_badges()#

Prints allergen badges for the current menu item card.

Calls rpress_allergens_render_badges_for() with the current post ID. Hooked to rpress_fooditem_after_title at priority 6.

rpress_allergens_render_card_badges()

Note: Echoes output instead of returning it.

Internal. Defined in includes/features/allergens/frontend.php, line 19.

rpress_allergens_render_badges_for()#

Prints allergen badges for a menu item, unless allergen display is off.

Hooked to rpress_fooditem_after_badges, for template packs that build their own badge row.

rpress_allergens_render_badges_for( $fooditem_id )

Parameters

ParameterTypeDefaultDescription
$fooditem_idintRequiredMenu item (food item) post ID.

Note: Echoes output instead of returning it.

Internal. Defined in includes/features/allergens/frontend.php, line 32.

rpress_allergens_popup_html()#

Prepends the allergen block to the menu item popup body.

Filter callback on rpress_show_products_html. Returns the HTML unchanged when the display mode is off.

rpress_allergens_popup_html( $html, $fooditem_id )

Parameters

ParameterTypeDefaultDescription
$htmlstringRequiredPopup body HTML.
$fooditem_idintRequiredMenu item (food item) post ID.

Returns string: Popup HTML with the allergen block in front.

Internal. Defined in includes/features/allergens/frontend.php, line 49.

rpress_allergens_in_use()#

Returns the allergens assigned to at least one menu item.

Used to decide which allergens the storefront filter offers.

rpress_allergens_in_use()

Returns WP_Term[]: Allergen terms ordered by name; empty array when the taxonomy is missing or the query fails.

Defined in includes/features/allergens/frontend.php, line 64.

rpress_get_allergen_filter_html()#

Returns the markup of the Hide items containing storefront filter.

Returns an empty string unless the display mode is all and at least one allergen is in use. Enqueues the filter script as a side effect.

rpress_get_allergen_filter_html()

Returns string: Filter HTML, or an empty string.

Note: Enqueues the rpress-allergens-filter script when it returns markup.

Defined in includes/features/allergens/frontend.php, line 85.

rpress_allergens_render_filter()#

Prints the allergen filter above the menu list.

Hooked to before_fooditems_list at priority 20.

rpress_allergens_render_filter()

Note: Echoes output instead of returning it.

Internal. Defined in includes/features/allergens/frontend.php, line 137.

rpress_allergens_any_assigned()#

Checks whether any menu item has an allergen or a trace assigned.

Lets stores that never use allergens skip loading the stylesheet. The answer is cached in the rpress_allergens_assigned transient for a day and cleared when assignments change. Filter with rpress_allergens_any_assigned.

rpress_allergens_any_assigned()

Returns bool: True when at least one item has an allergen or trace.

Internal. Defined in includes/features/allergens/frontend.php, line 150.

rpress_allergens_flush_assigned()#

Deletes the cached any-allergen-assigned answer.

rpress_allergens_flush_assigned()

Internal. Defined in includes/features/allergens/frontend.php, line 196.

rpress_allergens_flush_on_terms()#

Clears the allergen cache when allergen terms are set on an object.

Hooked to set_object_terms.

rpress_allergens_flush_on_terms( $object_id, $terms, $tt_ids, $taxonomy )

Parameters

ParameterTypeDefaultDescription
$object_idintRequiredObject ID.
$termsarrayRequiredTerms.
$tt_idsarrayRequiredTerm taxonomy IDs.
$taxonomystringRequiredTaxonomy name.

Internal. Defined in includes/features/allergens/frontend.php, line 209.

rpress_allergens_flush_on_term_delete()#

Clears the allergen cache when an allergen term is deleted.

Hooked to delete_term.

rpress_allergens_flush_on_term_delete( $term_id, $tt_id, $taxonomy )

Parameters

ParameterTypeDefaultDescription
$term_idintRequiredTerm ID.
$tt_idintRequiredTerm taxonomy ID.
$taxonomystringRequiredTaxonomy name.

Internal. Defined in includes/features/allergens/frontend.php, line 224.

rpress_allergens_flush_on_meta()#

Clears the allergen cache when the traces meta changes.

Hooked to the added, updated and deleted post meta actions.

rpress_allergens_flush_on_meta( $meta_id, $object_id, $meta_key )

Parameters

ParameterTypeDefaultDescription
$meta_idint|arrayRequiredMeta ID, or IDs on delete.
$object_idintRequiredPost ID.
$meta_keystringRequiredMeta key.

Internal. Defined in includes/features/allergens/frontend.php, line 239.

rpress_allergens_flush_on_status()#

Clears the allergen cache when a menu item changes status.

Hooked to transition_post_status; acts only on the fooditem post type.

rpress_allergens_flush_on_status( $new_status, $old_status, $post )

Parameters

ParameterTypeDefaultDescription
$new_statusstringRequiredNew status.
$old_statusstringRequiredOld status.
$postWP_PostRequiredPost.

Internal. Defined in includes/features/allergens/frontend.php, line 258.

rpress_allergens_enqueue_styles()#

Enqueues the allergen stylesheet when allergens are shown and assigned.

Hooked to wp_enqueue_scripts at priority 20.

rpress_allergens_enqueue_styles()

Internal. Defined in includes/features/allergens/frontend.php, line 271.

rpress_allergens_enqueue_filter_script()#

Enqueues the allergen filter script and its strings.

Registers the rpress-allergens-filter script in the footer and localizes rpressAllergens with the hidden-items messages.

rpress_allergens_enqueue_filter_script()

Internal. Defined in includes/features/allergens/frontend.php, line 290.

rpress_get_fooditem_allergens()#

Returns the allergens a menu item contains.

Results are sorted by name. Filter with rpress_fooditem_allergens.

rpress_get_fooditem_allergens( $fooditem_id )

Parameters

ParameterTypeDefaultDescription
$fooditem_idintRequiredMenu item (food item) post ID.

Returns WP_Term[]: Allergen terms, or an empty array.

Example

$names = wp_list_pluck( rpress_get_fooditem_allergens( $fooditem_id ), 'name' );

Defined in includes/features/allergens/functions.php, line 18.

rpress_get_fooditem_allergen_trace_ids()#

Returns the term IDs stored as may contain traces of for a menu item.

Reads the _rpress_allergen_traces post meta.

rpress_get_fooditem_allergen_trace_ids( $fooditem_id )

Parameters

ParameterTypeDefaultDescription
$fooditem_idintRequiredMenu item (food item) post ID.

Returns int[]: Allergen term IDs, or an empty array.

Defined in includes/features/allergens/functions.php, line 43.

rpress_get_fooditem_allergen_traces()#

Returns the allergens a menu item may contain traces of.

Allergens the item already contains are removed from the list. Filter with rpress_fooditem_allergen_traces.

rpress_get_fooditem_allergen_traces( $fooditem_id )

Parameters

ParameterTypeDefaultDescription
$fooditem_idintRequiredMenu item (food item) post ID.

Returns WP_Term[]: Allergen terms ordered by name, or an empty array.

Defined in includes/features/allergens/functions.php, line 55.

rpress_allergen_code()#

Returns the short badge code of an allergen.

Uses the rpress_allergen_code term meta, falling back to the upper-cased first two characters of the name. Filter with rpress_allergen_code.

rpress_allergen_code( $term )

Parameters

ParameterTypeDefaultDescription
$termWP_TermRequiredAllergen term.

Returns string: Badge code.

Defined in includes/features/allergens/functions.php, line 85.

rpress_allergens_for_rest()#

Shapes allergen terms for the REST response.

rpress_allergens_for_rest( $terms )

Parameters

ParameterTypeDefaultDescription
$termsWP_Term[]RequiredAllergen terms.

Returns array: List of arrays with id, slug, name and code.

Internal. Defined in includes/features/allergens/functions.php, line 102.

rpress_allergens_display_mode()#

Returns the storefront allergen display mode.

Reads the allergens_display setting; any other value is treated as all. Filter with rpress_allergens_display_mode.

rpress_allergens_display_mode()

Returns string: One of all, badges or off.

Defined in includes/features/allergens/functions.php, line 121.

rpress_get_allergen_badges_html()#

Returns the allergen badge markup for a menu item.

The card context shows compact code badges with full names in screen-reader text. The popup context lists names under Contains and May contain traces of headings with a disclaimer. Filter with rpress_allergen_badges_html.

rpress_get_allergen_badges_html( $fooditem_id, $context = 'card' )

Parameters

ParameterTypeDefaultDescription
$fooditem_idintRequiredMenu item (food item) post ID.
$contextstring'card'Either card or popup; any other value is treated as card.

Returns string: HTML, or an empty string when the item has no allergens or traces.

Example

echo rpress_get_allergen_badges_html( get_the_ID(), 'popup' );

Defined in includes/features/allergens/functions.php, line 142.

rpress_allergens_register_taxonomy()#

Registers the non-public rpress_allergen taxonomy for menu items.

Runs on init at priority 5. Arguments are filterable with rpress_allergen_taxonomy_args. Uses the product term capabilities (manage_product_terms and related).

rpress_allergens_register_taxonomy()

Internal. Defined in includes/features/allergens/loader.php, line 35.

rpress_allergens_default_terms()#

Returns the default allergen set, the 14 EU allergens.

Keyed by slug, each entry has a name and a badge code. Filter with rpress_default_allergens.

rpress_allergens_default_terms()

Returns array: Array keyed by slug of arrays with name and code.

Defined in includes/features/allergens/loader.php, line 93.

rpress_allergens_seed()#

Creates the default allergens once after install or upgrade.

Matches terms by slug so reruns do not duplicate them, and sets the badge code when missing. The rpress_allergens_seeded option stops later runs, so deleted terms are not restored unless forced. Runs on init at priority 12.

rpress_allergens_seed( $force = false )

Parameters

ParameterTypeDefaultDescription
$forceboolfalseRun even when the guard option is set.

Returns int: Number of terms created.

Internal. Defined in includes/features/allergens/loader.php, line 125.

rpress_allergens_register_settings()#

Adds the Allergens on Menu select to the Styles settings.

Places the allergens_display setting after enable_tags_display in the main Styles section.

rpress_allergens_register_settings( $settings )

Parameters

ParameterTypeDefaultDescription
$settingsarrayRequiredRegistered settings.

Returns array: Modified settings.

Internal. Defined in includes/features/allergens/loader.php, line 166.

rpress_allergens_rest_prepare()#

Adds allergens and allergen_traces to the menu item REST response.

Filter callback on rest_prepare_fooditem.

rpress_allergens_rest_prepare( $response, $post )

Parameters

ParameterTypeDefaultDescription
$responseWP_REST_ResponseRequiredResponse.
$postWP_PostRequiredMenu item.

Returns WP_REST_Response: The response with the extra fields.

Internal. Defined in includes/features/allergens/loader.php, line 206.

rpress_allergens_rest_schema()#

Adds the allergens and allergen_traces fields to the menu item REST schema.

Filter callback on rp_rest_api_fooditem_schema.

rpress_allergens_rest_schema( $schema )

Parameters

ParameterTypeDefaultDescription
$schemaarrayRequiredAdditional schema properties.

Returns array: Schema with the two read-only array properties added.

Internal. Defined in includes/features/allergens/loader.php, line 225.

Was this page helpful?