Skip to content
Docs
Get RestroPress

Function

Templates functions

Updated
On this page

Functions that load templates and print parts of the storefront.

44 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_profile_editor_logged_out()#

Prints a login prompt and the login form on the profile editor for logged-out visitors.

Echoes a 'You need to log in to edit your profile.' paragraph followed by the output of rpress_login_form() filtered through wp_kses. Hooked to the rpress_profile_editor_logged_out action.

rpress_profile_editor_logged_out()

Note: Echoes output instead of returning it

Internal. Defined in includes/template-actions.php, line 21.

rpress_login_form_logged_in()#

Prints an 'already logged in' message on the login form.

Kept mainly for backwards compatibility. Hooked to the rpress_login_form_logged_in action.

rpress_login_form_logged_in()

Note: Echoes output instead of returning it

Internal. Defined in includes/template-actions.php, line 73.

Prints the add-to-cart form after the content of a menu item.

Hooked to rpress_after_fooditem_content. Echoes the result of rpress_get_purchase_link() for the given menu item, filtered through wp_kses, unless the _rpress_hide_purchase_link post meta is set for it.

rpress_append_purchase_link($fooditem_id)

Parameters

ParameterTypeDefaultDescription
$fooditem_idintRequiredMenu item ID.

Note: Echoes output instead of returning it

Internal. Defined in includes/template-functions.php, line 23.

Returns the HTML for a menu item's add-to-cart form.

Builds the form with the Add button, hidden fields and price data attributes for simple or variable pricing. Returns false when no checkout page is set (and prints an error once), when the item does not exist, or when it is unpublished and the current user cannot edit_product it. Uses the current global $post when fooditem_id is not passed. Filters: rpress_purchase_link_defaults, rpress_purchase_link_args, rpress_add_to_cart_text, rpress_not_available, rpress_fooditem_redirect_to_checkout, rpress_purchase_fooditem_form. Actions: rpress_purchase_link_top, rpress_purchase_link_end.

rpress_get_purchase_link($args = array())

Parameters

ParameterTypeDefaultDescription
$argsarrayarray()Display arguments merged over the defaults: fooditem_id, price (bool), price_id (int|false), direct (bool), text, checkout, style, color, class, form_id.

Returns string|false: The form HTML, or false when the form cannot be built.

Example

echo rpress_get_purchase_link( array( 'fooditem_id' => 123 ) );

Note: Returns markup rather than echoing it. Each call for the same menu item gets a unique form ID (suffix -2, -3, ...). Shows the Not Available button when rpress_fooditem_available() is false.

Defined in includes/template-functions.php, line 89.

Returns the HTML for a menu item's add-to-cart form in the grid layout.

Same logic and filters as rpress_get_purchase_link(), but the Add button markup puts the plus icon before the label, and the default style comes from the add_button_style option with a fallback of 'button'. Returns false when no checkout page is set, the item does not exist, or it is unpublished and the user cannot edit_product it.

rpress_get_purchase_link_grid($args = array())

Parameters

ParameterTypeDefaultDescription
$argsarrayarray()Display arguments merged over the defaults. Same keys as rpress_get_purchase_link().

Returns string|false: The form HTML, or false when the form cannot be built.

Example

echo rpress_get_purchase_link_grid( array( 'fooditem_id' => 123 ) );

Note: Returns markup rather than echoing it.

Defined in includes/template-functions.php, line 229.

Prints schema.org Offer microdata (price and currency) for a menu item.

Hooked to rpress_purchase_link_top. Does nothing unless rpress_add_schema_microdata() is true. Uses the lowest price option for variable-priced items, otherwise the item price.

rpress_purchase_link_pricing_schema($fooditem_id = 0, $args = array())

Parameters

ParameterTypeDefaultDescription
$fooditem_idint0Menu item ID.
$argsarrayarray()Purchase link arguments passed by the hook; not used.

Note: Echoes output instead of returning it

Internal. Defined in includes/template-functions.php, line 379.

rpress_before_fooditem_content()#

Prepends the rpress_before_fooditem_content action output to single menu item content.

Filter on the_content. On the main query of a single fooditem post that is not password protected, buffers do_action( 'rpress_before_fooditem_content', $post->ID ) and puts its output before the content.

rpress_before_fooditem_content($content)

Parameters

ParameterTypeDefaultDescription
$contentstringRequiredPost content.

Returns string: The content, with any action output prepended.

Internal. Defined in includes/template-functions.php, line 411.

rpress_after_fooditem_content()#

Appends the rpress_after_fooditem_content action output to single menu item content.

Filter on the_content. On the main query of a single fooditem post that is not password protected, buffers do_action( 'rpress_after_fooditem_content', $post->ID ) and appends its output to the content.

rpress_after_fooditem_content($content)

Parameters

ParameterTypeDefaultDescription
$contentstringRequiredPost content.

Returns string: The content, with any action output appended.

Internal. Defined in includes/template-functions.php, line 434.

rpress_get_button_colors()#

Returns the available button colors.

Each entry is keyed by slug (gray, blue, red, green, yellow, orange, dark-gray, inherit) and holds a label and a hex value. Filterable through rpress_button_colors.

rpress_get_button_colors()

Returns array: Associative array of color slug => array( 'label' => string, 'hex' => string ).

Defined in includes/template-functions.php, line 453.

rpress_get_button_styles()#

Returns the available button styles.

Keys are th-rectangle, th-rounded, th-border-radius and th-plain, with translated labels as values. Filterable through rpress_button_styles.

rpress_get_button_styles()

Returns array: Associative array of style slug => label.

Defined in includes/template-functions.php, line 499.

rpress_get_add_button_styles()#

Returns the available styles for the Add button.

Keys are circle, rounded and rectangle, with translated labels as values. Filterable through rpress_add_button_styles.

rpress_get_add_button_styles()

Returns array: Associative array of style slug => label.

Defined in includes/template-functions.php, line 517.

rpress_is_add_button_visible()#

Checks whether the Add button is shown on the storefront.

Reads the add_button_visibility option (default 'show'); any value other than 'hide' counts as visible. Filterable through rpress_is_add_button_visible.

rpress_is_add_button_visible()

Returns bool: True when the Add button is visible, false when hidden.

Defined in includes/template-functions.php, line 534.

rpress_fooditems_default_excerpt()#

Formats a menu item excerpt with paragraphs and shortcodes.

Default callback for the rpress_fooditems_excerpt filter. Runs wpautop() then do_shortcode() on the excerpt.

rpress_fooditems_default_excerpt($excerpt)

Parameters

ParameterTypeDefaultDescription
$excerptstringRequiredExcerpt before filtering.

Returns string: The formatted excerpt.

Internal. Defined in includes/template-functions.php, line 551.

rpress_fooditems_default_content()#

Formats full menu item content with paragraphs and shortcodes.

Default callback for the rpress_fooditems_content filter. Runs wpautop() then do_shortcode() on the content.

rpress_fooditems_default_content($content)

Parameters

ParameterTypeDefaultDescription
$contentstringRequiredContent before filtering.

Returns string: The formatted content.

Internal. Defined in includes/template-functions.php, line 565.

rpress_get_templates_dir()#

Returns the path to the plugin's templates directory.

Built from RP_PLUGIN_DIR with no trailing slash.

rpress_get_templates_dir()

Returns string: Absolute directory path.

Defined in includes/template-functions.php, line 576.

rpress_get_templates_url()#

Returns the URL of the plugin's templates directory.

Built from RP_PLUGIN_URL with no trailing slash.

rpress_get_templates_url()

Returns string: Templates directory URL.

Defined in includes/template-functions.php, line 586.

rpress_get_template_part()#

Loads a template part, allowing themes to override it.

Fires get_template_part_{slug}, then checks the rpress_allow_template_part_{slug}_{name} filter (return false to skip loading). Looks for {slug}-{name}.php and then {slug}.php through rpress_locate_template(), so a copy in the theme's restropress folder wins over the plugin file. The candidate list can be changed with rpress_get_template_part.

rpress_get_template_part($slug, $name = null, $load = true)

Parameters

ParameterTypeDefaultDescription
$slugstringRequiredTemplate slug, for example 'rpress'.
$namestring|nullnullOptional specialised name appended to the slug.
$loadbooltrueWhether to include the file when found.

Returns string|false: Path of the located template, false when none was found, or an empty string when loading was blocked by the filter.

Example

rpress_get_template_part( 'rpress', 'delivery-steps' );

Note: When $load is true the template is included and its output is printed directly. The template is loaded with require, not require_once.

Defined in includes/template-functions.php, line 607.

rpress_load_verification_template_once()#

Allows the account-pending template part to load only once per request.

Filter callback on rpress_allow_template_part_account_pending. Returns false on every call after the first.

rpress_load_verification_template_once($load_template)

Parameters

ParameterTypeDefaultDescription
$load_templateboolRequiredWhether the template is currently allowed to load.

Returns bool: The incoming value on the first call, false afterwards.

Internal. Defined in includes/template-functions.php, line 632.

rpress_locate_template()#

Finds the highest-priority template file and optionally loads it.

Checks each name in order against the paths from rpress_get_theme_template_paths() (child theme, parent theme, then the plugin templates folder). Leading slashes in names are trimmed.

rpress_locate_template($template_names, $load = false, $require_once = true)

Parameters

ParameterTypeDefaultDescription
$template_namesstring|arrayRequiredTemplate file name or names to search for, in priority order.
$loadboolfalseLoad the file when found.
$require_oncebooltrueUse require_once rather than require. Ignored when $load is false.

Returns string|false: Full path of the located template, or false if none exists.

Example

$file = rpress_locate_template( 'rpress-delivery-steps.php' );

Defined in includes/template-functions.php, line 659.

rpress_get_theme_template_paths()#

Returns the directories searched for template files, in priority order.

Defaults are the child theme, parent theme and plugin templates directories (priorities 1, 10 and 100), each with a trailing slash. Filterable through rpress_template_paths; the result is sorted by key.

rpress_get_theme_template_paths()

Returns array: List of directory paths with trailing slashes.

Defined in includes/template-functions.php, line 691.

rpress_get_theme_template_dir_name()#

Returns the theme subfolder name used for template overrides.

Defaults to 'restropress' with a trailing slash. Filterable through rpress_templates_dir.

rpress_get_theme_template_dir_name()

Returns string: Folder name with a trailing slash.

Defined in includes/template-functions.php, line 712.

rpress_add_schema_microdata()#

Checks whether schema.org microdata may be added.

True only after the wp_head action has run. Filterable through rpress_add_schema_microdata.

rpress_add_schema_microdata()

Returns bool: True when microdata may be output.

Defined in includes/template-functions.php, line 722.

rpress_microdata_title()#

Wraps the title of a single menu item page in a schema.org name span.

Filter on the_title. Applies only when microdata is enabled, the title belongs to the current global post, and it is a single fooditem page.

rpress_microdata_title($title, $id = 0)

Parameters

ParameterTypeDefaultDescription
$titlestringRequiredPost title.
$idint0Post ID.

Returns string: The title, wrapped in a span with itemprop="name" when applicable.

Internal. Defined in includes/template-functions.php, line 737.

rpress_microdata_wrapper_open()#

Opens the schema.org Product wrapper at the start of the single menu item loop.

Hooked to loop_start. Prints an opening span with itemtype http://schema.org/Product, once per request, for the main query of a single fooditem page when microdata is enabled.

rpress_microdata_wrapper_open($query)

Parameters

ParameterTypeDefaultDescription
$queryWP_QueryRequiredThe query that started the loop.

Note: Echoes output instead of returning it

Internal. Defined in includes/template-functions.php, line 757.

rpress_microdata_wrapper_close()#

Closes the schema.org Product wrapper at the end of the single menu item loop.

Hooked to loop_end. Prints the closing span once per request on a single fooditem page when microdata is enabled.

rpress_microdata_wrapper_close()

Note: Echoes output instead of returning it

Internal. Defined in includes/template-functions.php, line 778.

rpress_microdata_description()#

Wraps single menu item content in a schema.org description div.

Filter on the_content. Applies once per request on a single fooditem page when microdata is enabled. The wrapped result passes through the rpress_microdata_wrapper filter.

rpress_microdata_description($content)

Parameters

ParameterTypeDefaultDescription
$contentstringRequiredPost content.

Returns string: The content, wrapped in a div with itemprop="description" when applicable.

Internal. Defined in includes/template-functions.php, line 800.

rpress_checkout_meta_tags()#

Prints noindex and gateway meta tags on checkout and order pages.

Hooked to wp_head. On the checkout page and the pages set as success_page, failure_page or order_history_page, prints a rpress-chosen-gateway meta tag and a robots noindex,nofollow tag.

rpress_checkout_meta_tags()

Note: Echoes output instead of returning it

Internal. Defined in includes/template-functions.php, line 821.

rpress_version_in_header()#

Prints the RestroPress generator meta tag in the page head.

Hooked to wp_head. Outputs RP_VERSION as the generator meta tag.

rpress_version_in_header()

Note: Echoes output instead of returning it

Internal. Defined in includes/template-functions.php, line 840.

rpress_is_order_history_page()#

Checks whether the current page is the order history page.

Uses the order_history_page option with is_page(). Filterable through rpress_is_order_history_page.

rpress_is_order_history_page()

Returns bool: True on the order history page, false otherwise.

Note: Returns false if no order history page is configured.

Defined in includes/template-functions.php, line 851.

rpress_add_body_classes()#

Adds RestroPress body classes for storefront, checkout and order pages.

Filter on body_class. Adds rpress-add-button-hidden when the Add button is hidden, then one of rpress-checkout, rpress-success, rpress-failed-transaction or rpress-payment-history (each with rpress-page), rpress-test-mode in test mode, or rpress.

rpress_add_body_classes($class)

Parameters

ParameterTypeDefaultDescription
$classstring|arrayRequiredCurrent body classes.

Returns array: De-duplicated list of classes.

Internal. Defined in includes/template-functions.php, line 864.

rpress_add_fooditem_post_classes()#

Adds RestroPress classes to menu item post class lists on the front end.

Filter on post_class. Does nothing in the admin or for other post types. Adds rpress-fooditem, plus rpress-fooditem-cat-{slug} for each term in the addon_category taxonomy and rpress-fooditem-tag-{slug} for each fooditem_tag term.

rpress_add_fooditem_post_classes($classes, $class = '', $post_id = false)

Parameters

ParameterTypeDefaultDescription
$classesarrayRequiredCurrent post classes.
$classstring|array''Classes added through get_post_class(); not used.
$post_idint|falsefalsePost ID.

Returns array: The modified classes.

Note: The cat- classes use the addon_category taxonomy, not the menu category taxonomy.

Internal. Defined in includes/template-functions.php, line 908.

rpress_add_oembed_price()#

Prints the menu item price inside oEmbed output.

Hooked to embed_content. For fooditem posts, prints a price block (a range for variable prices) unless _rpress_hide_purchase_link is set. Filterable through rpress_show_oembed_purchase_links.

rpress_add_oembed_price()

Note: Echoes output instead of returning it

Internal. Defined in includes/template-functions.php, line 944.

rpress_remove_embed_comments_button()#

Removes the comments button from menu item embeds.

Hooked to embed_content_meta at priority 5. For fooditem posts, removes print_embed_comments_button unless the rpress_embed_hide_comments filter returns false.

rpress_remove_embed_comments_button()

Internal. Defined in includes/template-functions.php, line 975.

rpress_get_bundle_item_title()#

Returns the display title of a bundle item, with its price name for variable prices.

Splits the value on an underscore into item ID and optional price ID. When a price ID is present, the price name is appended after ' - '.

rpress_get_bundle_item_title($bundle_item)

Parameters

ParameterTypeDefaultDescription
$bundle_itemstringRequiredBundle item in the form 'ID' or 'ID_priceID'.

Returns string: The item title.

Note: Legacy bundle helper inherited from Easy Digital Downloads. The documented type is array but the code expects the 'ID_priceID' string.

Internal. Defined in includes/template-functions.php, line 992.

rpress_get_bundle_item_id()#

Returns the item ID from a bundle item string.

Takes the part before the first underscore.

rpress_get_bundle_item_id($bundle_item)

Parameters

ParameterTypeDefaultDescription
$bundle_itemstringRequiredBundle item in the form 'ID' or 'ID_priceID'.

Returns string: The item ID.

Note: Legacy bundle helper inherited from Easy Digital Downloads.

Internal. Defined in includes/template-functions.php, line 1012.

rpress_get_bundle_item_price_id()#

Returns the price ID from a bundle item string.

Takes the part after the first underscore.

rpress_get_bundle_item_price_id($bundle_item)

Parameters

ParameterTypeDefaultDescription
$bundle_itemstringRequiredBundle item in the form 'ID' or 'ID_priceID'.

Returns string|null: The price ID, or null when the string has none.

Note: Legacy bundle helper inherited from Easy Digital Downloads.

Internal. Defined in includes/template-functions.php, line 1026.

rpress_fooditem_shortcode_item()#

Loads the single-item template for a menu item in the [fooditems] shortcode.

Hooked to rpress_fooditem_shortcode_item. Stores the shortcode attributes and counter in the globals $rpress_fooditem_shortcode_item_atts and $rpress_fooditem_shortcode_item_i, then loads the {template}/single template part, where template is the template option (default 'list').

rpress_fooditem_shortcode_item($atts, $i)

Parameters

ParameterTypeDefaultDescription
$attsarrayRequiredThe [fooditems] shortcode attributes.
$iintRequiredCurrent item count.

Note: Echoes output instead of returning it

Internal. Defined in includes/template-functions.php, line 1045.

rpress_get_category_title()#

Loads the category heading template for the menu item listing.

Hooked to rpress_fooditems_category_title. Sets the globals $fooditem_term_slug and $rpress_fooditem_id and loads the fooditem/category template part. The $var argument is not used.

rpress_get_category_title($term_slug, $id, $var)

Parameters

ParameterTypeDefaultDescription
$term_slugstringRequiredCategory term slug.
$idintRequiredMenu item ID.
$vararrayRequiredUnused.

Note: Echoes output instead of returning it

Internal. Defined in includes/template-functions.php, line 1067.

rpress_get_cart_items()#

Prints the shopping cart by calling rpress_shopping_cart().

Hooked to the rpress_get_cart action.

rpress_get_cart_items()

Note: Echoes output instead of returning it

Internal. Defined in includes/template-functions.php, line 1080.

rpress_get_delivery_steps()#

Returns the delivery step selector HTML, with the menu item ID filled in.

Captures the rpress-delivery-steps template part and replaces the {fooditem_id} placeholder with the given ID, or with an empty string when the ID is falsy.

rpress_get_delivery_steps($fooditem_id)

Parameters

ParameterTypeDefaultDescription
$fooditem_idintRequiredMenu item ID, or 0/empty for none.

Returns string: The template HTML.

Example

echo rpress_get_delivery_steps( 0 );

Note: The output is unescaped template HTML; escape or filter it with wp_kses before printing.

Defined in includes/template-functions.php, line 1092.

rpress_add_delivery_steps()#

Prints the delivery step selector, filtered through wp_kses.

Hooked to the rpress_get_delivery_steps action. Echoes rpress_get_delivery_steps('') restricted to an allow-list of tags and attributes.

rpress_add_delivery_steps()

Note: Echoes output instead of returning it

Internal. Defined in includes/template-functions.php, line 1112.

rpress_radio_image_callback()#

Renders a radio-with-image settings field.

Settings field callback. Prints one radio input per entry in options, each with an image and label. Image falls back to assets/images/{key}.png; label falls back to the capitalised key. The current value comes from rpress_get_option() using id and std, and the input name is rpress_settings[id].

rpress_radio_image_callback($args)

Parameters

ParameterTypeDefaultDescription
$argsarrayRequiredField arguments: id, std, options (key => array with optional img and label), and optional desc.

Note: Echoes output instead of returning it

Internal. Defined in includes/template-functions.php, line 1165.

rpress_get_dietary_labels_html()#

Returns HTML chips for a menu item's dietary labels.

Reads the terms of the dietary taxonomy for the item (the current post when no ID is given) and builds a div with one span per term, classed rpress-dietary-label dietary-{slug}. Filters: rpress_show_dietary_labels (return false to disable) and rpress_dietary_labels_html.

rpress_get_dietary_labels_html($fooditem_id = 0)

Parameters

ParameterTypeDefaultDescription
$fooditem_idint0Menu item ID. Defaults to the current post when 0.

Returns string: The chip HTML, or an empty string when there are no labels or they are disabled.

Example

echo rpress_get_dietary_labels_html( 123 );

Defined in includes/template-functions.php, line 1206.

rpress_render_dietary_labels()#

Prints the dietary labels for the current menu item.

Hooked to rpress_fooditem_after_title at priority 5. Echoes the result of rpress_get_dietary_labels_html() for the current post.

rpress_render_dietary_labels()

Note: Echoes output instead of returning it

Internal. Defined in includes/template-functions.php, line 1248.

Was this page helpful?