Function
Block storefront functions
On this page
- rpress_block_storefront_blocks()
- rpress_block_storefront_supported()
- rpress_block_storefront_in_post()
- rpress_block_storefront_normalize()
- rpress_block_storefront_price_text()
- rpress_block_storefront_money()
- rpress_block_storefront_store_state()
- rpress_block_storefront_cart_state()
- rpress_block_storefront_seed_state()
- rpress_block_storefront_categories()
- rpress_block_storefront_category_items()
- rpress_block_storefront_add_button()
- rpress_block_storefront_wrapper()
- rpress_block_storefront_fallback()
- rpress_block_storefront_ajax_cart()
- rpress_block_storefront_register()
- rpress_block_storefront_pattern_content()
- rpress_block_storefront_register_pattern()
- rpress_block_storefront_register_template()
Functions and render helpers for the service bar, category navigation, search, item grid and cart panel blocks.
19 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_block_storefront_blocks()#
Returns the storefront block names keyed by their folder under blocks/.
The blocks are category-nav, item-grid, cart-panel, service-bar and menu-search, all in the rpress/ namespace.
rpress_block_storefront_blocks()
Returns string[]: Folder name => block name.
Example
$names = array_values( rpress_block_storefront_blocks() );
Defined in includes/features/block-storefront/functions.php, line 31.
rpress_block_storefront_supported()#
Checks whether the Interactivity API is available for the storefront blocks.
Requires wp_interactivity_state() and wp_register_script_module() (WordPress 6.5+). Without them the blocks fall back to the classic shortcode storefront. Filterable through rpress_block_storefront_supported.
rpress_block_storefront_supported()
Returns bool: True when the Interactivity API is available.
Internal. Defined in includes/features/block-storefront/functions.php, line 49.
rpress_block_storefront_in_post()#
Checks whether a post renders the block storefront.
True when the content references the restropress/storefront pattern, contains any storefront block, or the page uses the rpress-storefront page template.
rpress_block_storefront_in_post( $post = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$post | WP_Post|int|null | null | Post; defaults to the current post. |
Returns bool: True when the post uses the storefront.
Example
if ( rpress_block_storefront_in_post( $post_id ) ) {
// This page uses the block storefront.
}
Defined in includes/features/block-storefront/functions.php, line 64.
rpress_block_storefront_normalize()#
Normalizes text for the live menu search: lowercase, accent-free and without punctuation.
Strips tags, decodes entities, removes accents and collapses whitespace. The view module normalizes the typed query the same way.
rpress_block_storefront_normalize( $text )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$text | string | Required | Text. |
Returns string: The normalized text.
Internal. Defined in includes/features/block-storefront/functions.php, line 94.
rpress_block_storefront_price_text()#
Returns a menu item's price as plain text, following the tax display settings and the item's tax class.
Variable-price items return a low - high range. Otherwise the price is adjusted by prices_include_tax and tax_item at the item's tax percent. Filterable through rpress_block_storefront_price_text for single prices.
rpress_block_storefront_price_text( $fooditem_id )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$fooditem_id | int | Required | Menu item ID. |
Returns string: The formatted price or range.
Example
$price = rpress_block_storefront_price_text( $fooditem_id );
Defined in includes/features/block-storefront/functions.php, line 109.
rpress_block_storefront_money()#
Formats an amount like the cart does and decodes it for use as plain text.
rpress_block_storefront_money( $amount )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$amount | float | Required | Amount. |
Returns string: The formatted amount.
Example
$text = rpress_block_storefront_money( 9.5 );
Defined in includes/features/block-storefront/functions.php, line 139.
rpress_block_storefront_store_state()#
Returns the store open or closed state for the current service.
Uses rpress_get_service_context() for the service type and rpress_is_store_open() for the state. When closed, the message is the store closed message, with the next available time appended when the slot engine has one, tags stripped.
rpress_block_storefront_store_state()
Returns array: Array with open (bool), message (string) and serviceType (string).
Example
$state = rpress_block_storefront_store_state();
if ( ! $state['open'] ) {
echo esc_html( $state['message'] );
}
Defined in includes/features/block-storefront/functions.php, line 149.
rpress_block_storefront_cart_state()#
Returns the cart state the storefront blocks render from.
Built from the cart contents: lines with name, options, quantity and line total, plus item count, subtotal, fees, tax and total as plain text. Filterable through rpress_block_storefront_cart_state.
rpress_block_storefront_cart_state()
Returns array: Array with items, count, hasItems, countLabel, subtotal, fees, tax, showTax, taxLabel and total.
Example
$cart = rpress_block_storefront_cart_state();
$count = $cart['count'];
Defined in includes/features/block-storefront/functions.php, line 180.
rpress_block_storefront_seed_state()#
Seeds the shared Interactivity store once per request.
Called by every block render. Sets the initial query, category, cart, store state, AJAX and checkout URLs, nonces and strings in the restropress namespace. Registers derived category state on WordPress 6.9 and later.
rpress_block_storefront_seed_state()
Internal. Defined in includes/features/block-storefront/functions.php, line 278.
rpress_block_storefront_categories()#
Returns the food categories for a block, honoring include and exclude lists.
Accepts comma separated IDs or slugs, as the fooditems shortcode does, and runs the result through the time_based_menu_rpress_foods filter like the classic menu.
rpress_block_storefront_categories( $include = '', $exclude = '' )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$include | string | '' | Comma separated IDs or slugs. Empty for all. |
$exclude | string | '' | Comma separated IDs or slugs to exclude. |
Returns WP_Term[]: Category terms.
Example
$terms = rpress_block_storefront_categories( '', 'drinks' );
Defined in includes/features/block-storefront/functions.php, line 343.
rpress_block_storefront_category_items()#
Returns the published menu items of one category.
Uses the same rpress_fooditems_query filter as the classic menu and does not include child categories.
rpress_block_storefront_category_items( $term, $orderby = 'title', $order = 'ASC' )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$term | WP_Term | Required | Category. |
$orderby | string | 'title' | Order by. |
$order | string | 'ASC' | ASC or DESC. |
Returns WP_Post[]: Menu item posts.
Example
$term = get_term_by( 'slug', 'starters', 'food-category' );
$items = $term ? rpress_block_storefront_category_items( $term ) : array();
Defined in includes/features/block-storefront/functions.php, line 385.
rpress_block_storefront_add_button()#
Returns the Add button markup for a menu item, with an accessible name.
Reuses rpress_get_purchase_link(), so the click opens the classic item popup. Adds role button and an aria-label to the link.
rpress_block_storefront_add_button( $fooditem_id )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$fooditem_id | int | Required | Menu item ID. |
Returns string: HTML, or an empty string when no link is produced.
Internal. Defined in includes/features/block-storefront/functions.php, line 428.
rpress_block_storefront_wrapper()#
Returns the wrapper attributes string for a storefront block.
Uses get_block_wrapper_attributes() so alignment, spacing and color supports apply, and adds the rpress-sf class plus the given class.
rpress_block_storefront_wrapper( $class, $extra = array() )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$class | string | Required | Extra class. |
$extra | array | array() | Extra attributes. |
Returns string: An attributes string for an HTML tag.
Internal. Defined in includes/features/block-storefront/functions.php, line 454.
rpress_block_storefront_fallback()#
Renders the fallback for WordPress without the Interactivity API.
The item-grid block renders the classic [fooditems] storefront, passing categories and category_exclude attributes; every other block renders nothing.
rpress_block_storefront_fallback( $block, $attributes = array() )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$block | string | Required | Block folder name. |
$attributes | array | array() | Block attributes. |
Returns string: HTML, or an empty string.
Internal. Defined in includes/features/block-storefront/functions.php, line 476.
rpress_block_storefront_ajax_cart()#
Handles the AJAX request that returns the cart and store state for the blocks.
Read-only, available to logged-out visitors. Replies with the cart and store arrays.
rpress_block_storefront_ajax_cart()
Internal. Defined in includes/features/block-storefront/functions.php, line 497.
rpress_block_storefront_register()#
Registers the storefront assets, blocks, pattern and block template.
Runs on init at priority 20. Registers the stylesheet, the editor script and the view script module, then each block type, the pattern and the template.
rpress_block_storefront_register()
Internal. Defined in includes/features/block-storefront/loader.php, line 35.
rpress_block_storefront_pattern_content()#
Returns the block markup of the RestroPress Storefront pattern.
Service bar and category nav on top, search and item grid in the main column, cart panel in a side column.
rpress_block_storefront_pattern_content()
Returns string: Block markup.
Internal. Defined in includes/features/block-storefront/loader.php, line 80.
rpress_block_storefront_register_pattern()#
Registers the RestroPress Storefront block pattern and its pattern category.
rpress_block_storefront_register_pattern()
Internal. Defined in includes/features/block-storefront/loader.php, line 106.
rpress_block_storefront_register_template()#
Registers a selectable RestroPress Storefront page template for block themes.
Does nothing unless register_block_template() exists (WordPress 6.7+) and the active theme is a block theme. It is offered in the page Template picker and never replaces a template on its own.
rpress_block_storefront_register_template()
Internal. Defined in includes/features/block-storefront/loader.php, line 136.
