Skip to content
Docs
Get RestroPress

Function

Storefront layout functions

Updated
On this page

Functions for the storefront layout engine and template pack components, added in RestroPress 3.5.1.

26 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_pack_component_schema()#

Returns the supported template pack component settings and the type of each.

The result is keyed by component, then setting. A type is css, px, int, bool, or an array of allowed values. Filterable with rpress_pack_component_schema.

rpress_pack_component_schema()

Returns array: Component => setting => type.

Defined in includes/features/storefront-layout/components.php, line 37.

rpress_sanitize_pack_components()#

Removes unknown or invalid template pack component settings.

Checks each value against rpress_pack_component_schema(). CSS values are rejected if empty, longer than 120 characters, containing characters that could end the declaration, or with unbalanced parentheses or quotes. px and int values must be numeric and are passed through absint().

rpress_sanitize_pack_components( $components )

Parameters

ParameterTypeDefaultDescription
$componentsarrayRequiredRaw settings as component => setting => value.

Returns array: Only the valid settings, in the same structure.

Example

$clean = rpress_sanitize_pack_components( array(
	'card' => array( 'radius' => '12px', 'photo_size' => 108 ),
	'tabs' => array( 'style' => 'underline' ),
) );

Defined in includes/features/storefront-layout/components.php, line 112.

rpress_get_pack_components()#

Returns the component settings in effect for a template pack.

Merges the components of each pack in the extends chain, from the furthest ancestor to the pack itself. The merged array goes through the rpress_pack_components filter and is then sanitized.

rpress_get_pack_components( $pack = null )

Parameters

ParameterTypeDefaultDescription
$packarray|nullnullPack array. Null uses the active pack.

Returns array: Component => settings. Empty when there is no pack or no valid settings.

Example

$components = rpress_get_pack_components();
$tab_style  = isset( $components['tabs']['style'] ) ? $components['tabs']['style'] : 'default';

Defined in includes/features/storefront-layout/components.php, line 162.

rpress_pack_components_css()#

Builds the CSS for a set of template pack component settings.

Selectors are prefixed with the given body selector and are deliberately specific, with declarations that override the legacy menu styles. The input is not sanitized here, so pass settings from rpress_get_pack_components().

rpress_pack_components_css( $c, $scope )

Parameters

ParameterTypeDefaultDescription
$carrayRequiredComponent settings, component => setting => value.
$scopestringRequiredBody selector, for example body.rp-pack-onyx.

Returns string: CSS rules separated by newlines, or an empty string.

Internal. Defined in includes/features/storefront-layout/components.php, line 196.

rpress_pack_components_enqueue()#

Adds the active pack's component CSS to menu pages.

Runs on wp_enqueue_scripts. Attaches inline CSS to an empty rpress-pack-components style handle, only when a storefront layout applies and the active pack has component settings.

rpress_pack_components_enqueue()

Internal. Defined in includes/features/storefront-layout/components.php, line 606.

rpress_pack_components_force_list()#

Forces the list menu templates while the active pack defines component settings.

Filters the template option through rpress_get_option_template. A saved value of grid is returned as list when the active pack has component settings. Regular admin screens keep the saved value; the saved option is not changed.

rpress_pack_components_force_list( $value )

Parameters

ParameterTypeDefaultDescription
$valuemixedRequiredSaved template option value (list or grid).

Returns mixed: list when forced, otherwise the original value.

Internal. Defined in includes/features/storefront-layout/components.php, line 638.

rpress_storefront_layout_current()#

Returns the storefront layout for the current menu page.

Returns an empty array in the admin, when the old_ui_ux option is on, or when the current post has neither the [fooditems] shortcode nor the rpress/food-menu block. The result is cached for the request once the wp action has run.

rpress_storefront_layout_current()

Returns array: Layout keys and values, or an empty array when layout components do not apply.

Example

$layout = rpress_storefront_layout_current();
if ( ! empty( $layout['rails'] ) ) {
	// The current menu page shows at least one rail.
}

Defined in includes/features/storefront-layout/functions.php, line 18.

rpress_storefront_layout_is()#

Checks whether the current menu page uses a given layout value.

Both values are compared as strings. Returns false when no layout applies or the key is not set. Use it for scalar layout keys, not the list keys rails and sections.

rpress_storefront_layout_is( $key, $value )

Parameters

ParameterTypeDefaultDescription
$keystringRequiredLayout key, for example nav_media.
$valuemixedRequiredScalar value to compare with.

Returns bool

Example

if ( rpress_storefront_layout_is( 'nav_media', 'images' ) ) {
	// Category navigation shows images.
}

Defined in includes/features/storefront-layout/functions.php, line 46.

rpress_storefront_layout_body_class()#

Adds body classes for storefront layout values that differ from the core defaults.

Callback for the body_class filter. Possible classes start with rp-sf-masthead-, rp-sf-nav-, rp-sf-media-, rp-sf-cols-, rp-sf-card-, rp-sf-cart- and rp-sf-item-, plus rp-sf-noimg when images are off. rp-sf is added with any of them; a band masthead adds no class.

rpress_storefront_layout_body_class( $classes )

Parameters

ParameterTypeDefaultDescription
$classesarrayRequiredBody classes.

Returns array: Body classes.

Internal. Defined in includes/features/storefront-layout/functions.php, line 62.

rpress_storefront_masthead_variant()#

Returns the masthead variant the storefront layout module renders on the current page.

Only cover, strip and editorial are rendered by this module. band and none return an empty string.

rpress_storefront_masthead_variant()

Returns string: cover, strip, editorial, or an empty string.

Defined in includes/features/storefront-layout/functions.php, line 107.

rpress_storefront_cover_image()#

Returns the cover image URL used by the cover masthead.

Reads the store_cover_image option, which may hold an attachment ID or a URL. The result is filtered by rpress_storefront_cover_image.

rpress_storefront_cover_image()

Returns string: Image URL, or an empty string.

Defined in includes/features/storefront-layout/functions.php, line 119.

rpress_storefront_monogram_html()#

Returns the HTML for the store monogram.

Uses the theme's custom logo, then the site icon. If neither produces an image, it shows up to two initials taken from the site name.

rpress_storefront_monogram_html()

Returns string: HTML for a span element.

Defined in includes/features/storefront-layout/functions.php, line 139.

rpress_storefront_render_masthead()#

Outputs the storefront masthead above the menu toolbar.

Hooked to rpress_menu_page_top. Does nothing unless the layout uses a rendered masthead variant. It includes the mobile ordering store card when that is available and enabled, otherwise the site name; the editorial variant has no monogram.

rpress_storefront_render_masthead()

Note: Echoes output.

Internal. Defined in includes/features/storefront-layout/functions.php, line 173.

rpress_storefront_masthead_hides_card()#

Hides the standalone store card when a masthead variant is rendered.

Callback for the rpress_mobile_ordering_show_store_card filter.

rpress_storefront_masthead_hides_card( $show )

Parameters

ParameterTypeDefaultDescription
$showboolRequiredWhether to show the store card.

Returns bool: False when a masthead variant renders, otherwise the incoming value.

Internal. Defined in includes/features/storefront-layout/functions.php, line 218.

rpress_storefront_masthead_replace_band()#

Removes the Modern pack store header when a masthead variant is rendered.

Runs on the wp action and unhooks RPRESS_Template_Packs::render_modern_store_header from rpress_menu_page_top.

rpress_storefront_masthead_replace_band()

Internal. Defined in includes/features/storefront-layout/functions.php, line 230.

rpress_storefront_renders_masthead()#

Checks whether core renders the storefront masthead on the current page.

A template pack that prints its own store header can use this to avoid showing two. It is true only for the cover, strip and editorial masthead layouts.

rpress_storefront_renders_masthead()

Returns bool

Example

if ( ! function_exists( 'rpress_storefront_renders_masthead' ) || ! rpress_storefront_renders_masthead() ) {
	echo '<h2>' . esc_html( get_bloginfo( 'name' ) ) . '</h2>';
}

Defined in includes/features/storefront-layout/functions.php, line 244.

rpress_get_category_image_url()#

Returns the image URL for a menu category.

Uses the term's thumbnail_id meta, then the featured image of one published menu item assigned directly to the category. The result is filtered by rpress_category_image_url and stored in the object cache for up to an hour.

rpress_get_category_image_url( $term_id )

Parameters

ParameterTypeDefaultDescription
$term_idintRequiredfood-category term ID.

Returns string: Image URL (medium size unless filtered), or an empty string.

Example

$term = get_term_by( 'slug', 'starters', 'food-category' );
if ( $term ) {
	$url = rpress_get_category_image_url( $term->term_id );
}

Defined in includes/features/storefront-layout/functions.php, line 261.

rpress_storefront_nav_media_html()#

Returns the image tile HTML for a category link in the menu navigation.

Returns an empty string unless the layout's nav_media value is images. A category with no image gets a tile showing the first character of its name.

rpress_storefront_nav_media_html( $cat )

Parameters

ParameterTypeDefaultDescription
$catWP_TermRequiredMenu category term.

Returns string: HTML, or an empty string.

Internal. Defined in includes/features/storefront-layout/functions.php, line 315.

rpress_storefront_rail_items()#

Returns the menu item IDs shown on a storefront rail.

popular lists items with sales, most sold first; deals lists items tagged deals in fooditem_tag; order_again uses the logged-in customer's previously ordered items (payment status complete). Unpublished and unavailable items are removed, so there may be fewer than the limit. Filters: rpress_storefront_rail_limit (default 8), rpress_storefront_deals_tag and rpress_storefront_rail_items.

rpress_storefront_rail_items( $rail )

Parameters

ParameterTypeDefaultDescription
$railstringRequiredRail key: popular, deals or order_again. Other keys start with an empty list that the filter can fill.

Returns int[]: Menu item IDs.

Example

$popular_ids = rpress_storefront_rail_items( 'popular' );

Defined in includes/features/storefront-layout/functions.php, line 342.

rpress_storefront_rail_title()#

Returns the heading for a storefront rail.

Has built-in headings for popular, order_again and deals; other keys start empty. Filtered by rpress_storefront_rail_title.

rpress_storefront_rail_title( $rail )

Parameters

ParameterTypeDefaultDescription
$railstringRequiredRail key.

Returns string

Defined in includes/features/storefront-layout/functions.php, line 428.

rpress_storefront_render_rails()#

Outputs the storefront rails listed in the current layout.

Prints one section for each key in the layout's rails list and skips rails with no menu items. Each card carries the menu item ID in a data-fooditem-id attribute, which the storefront script uses to open the item.

rpress_storefront_render_rails()

Note: Echoes output.

Internal. Defined in includes/features/storefront-layout/functions.php, line 452.

rpress_menu_section_order()#

Returns the order of the rails, category navigation and service row above the menu items.

Starts from the layout's sections value; any part it leaves out is inserted at its default position. The result is filtered by rpress_menu_section_order, after which unknown and duplicate values are removed, so a filter that drops a part removes it from the returned list.

rpress_menu_section_order()

Returns string[]: Values from rails, nav and service, in display order.

Defined in includes/features/storefront-layout/functions.php, line 515.

rpress_menu_rails_first()#

Checks whether the rails come first among the parts above the menu items.

When true, core prints the rails at the top of the menu page; otherwise they print where the menu template fires rpress_menu_section_rails.

rpress_menu_rails_first()

Returns bool

Defined in includes/features/storefront-layout/functions.php, line 541.

rpress_storefront_render_rails_at_top()#

Outputs the rails at the top of the menu page when they come first.

Hooked to rpress_menu_page_top.

rpress_storefront_render_rails_at_top()

Note: Echoes output.

Internal. Defined in includes/features/storefront-layout/functions.php, line 552.

rpress_storefront_render_rails_in_place()#

Outputs the rails inside the menu column when they do not come first.

Hooked to rpress_menu_section_rails.

rpress_storefront_render_rails_in_place()

Note: Echoes output.

Internal. Defined in includes/features/storefront-layout/functions.php, line 565.

rpress_storefront_layout_enqueue()#

Enqueues the storefront layout stylesheet and script on menu pages that need them.

Runs on wp_enqueue_scripts. Loads only when the layout adds the rp-sf body class or has rails, and passes translated strings to the script as rpress_storefront_layout.

rpress_storefront_layout_enqueue()

Internal. Defined in includes/features/storefront-layout/functions.php, line 584.

Was this page helpful?