Skip to content
Docs
Get RestroPress

Function

Other 3.5 additions

Updated
On this page

Other functions added to RestroPress core in 3.5, and core functions whose signature changed.

15 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_settings_display_time()#

Formats a saved time for display in the Store Time Format.

Accepts values such as 23:30, 11:30pm or 9:00 AM and shows them as H:i when the store_time_format setting is 24hrs, otherwise g:ia. Empty or unparseable values are returned unchanged.

rpress_settings_display_time($value)

Parameters

ParameterTypeDefaultDescription
$valuestringRequiredSaved time.

Returns string: Formatted time, or the input when it cannot be parsed.

Example

echo esc_html( rpress_settings_display_time( '11:30pm' ) );

Defined in includes/admin/settings/register-settings.php, line 243.

rpress_get_extra_order_notification_emails()#

Returns extra customer emails listed under Settings > Emails > Order Notifications.

Features add entries through the rpress_order_notification_extra_emails filter, keyed by option name. Entries with an invalid key, a key that is an order status or admin_notification, or a non-array value are dropped. Each kept entry is filled with defaults for label, recipient, enabled, subject, heading and content.

rpress_get_extra_order_notification_emails()

Returns array: Entries keyed by sanitized key, each with label, recipient, enabled, subject, heading and content.

Example

add_filter( 'rpress_order_notification_extra_emails', function ( $emails ) {
	$emails['my_reminder'] = array(
		'label'   => 'Pickup reminder',
		'enabled' => true,
		'subject' => 'Your order is ready',
	);
	return $emails;
} );

Defined in includes/admin/settings/register-settings.php, line 3261.

rpress_discount_date_for_input()#

Converts a stored discount date to the mm/dd/yyyy value used by the date picker.

Returns an empty string for an empty or unparseable date.

rpress_discount_date_for_input( $date )

Parameters

ParameterTypeDefaultDescription
$datestringRequiredStored date in m/d/Y H:i:s format.

Returns string: Date as m/d/Y, or an empty string.

Internal. Defined in includes/discount-functions.php, line 267.

rpress_paypal_amount_in_cents()#

Converts a money amount to whole cents.

Multiplies by 100 and rounds. Used to compare PayPal amounts with order totals without float errors.

rpress_paypal_amount_in_cents($amount)

Parameters

ParameterTypeDefaultDescription
$amountmixedRequiredAmount such as 1234.5 or the string 1234.5.

Returns int: Amount in cents.

Example

$cents = rpress_paypal_amount_in_cents( '12.34' ); // 1234

Defined in includes/gateways/paypal-standard.php, line 1627.

rpress_paypal_pdt_mismatch()#

Checks that a PayPal PDT response belongs to the order it would confirm.

Verifies the gateway is paypal, the custom value equals the order ID, the invoice matches the order key, the currency matches, the receiver matches the configured PayPal ID or email and the transaction is not already linked to another order.

rpress_paypal_pdt_mismatch($data, $payment, $tx)

Parameters

ParameterTypeDefaultDescription
$dataarrayRequiredParsed PDT response.
$paymentRPRESS_PaymentRequiredOrder being confirmed.
$txstringRequiredTransaction ID from the return URL.

Returns string: An empty string when the response matches, otherwise the reason.

Internal. Defined in includes/gateways/paypal-standard.php, line 2068.

rpress_core_stripe_api_request()#

Sends a request to the Stripe API and returns the decoded response.

Authenticates with the stored Stripe secret key. GET parameters go in the query string, other methods send them as the body. Throws an Exception on a missing key, a transport error, an invalid response or a non-2xx status. Since 3.5 an optional fourth argument adds request headers.

rpress_core_stripe_api_request( $method, $endpoint, $params = array(), $extra_headers = array() )

Parameters

ParameterTypeDefaultDescription
$methodstringRequiredHTTP method.
$endpointstringRequiredStripe endpoint relative to the v1 API, such as payment_intents.
$paramsarrayarray()Request parameters.
$extra_headersarrayarray()Extra HTTP headers merged over the default Authorization header, for example Idempotency-Key.

Returns array: Decoded Stripe response.

Example

try {
	$intent = rpress_core_stripe_api_request( 'GET', 'payment_intents/pi_123' );
} catch ( Exception $e ) {
	error_log( $e->getMessage() );
}

Note: Changed in 3.5: added the fourth parameter $extra_headers (default array()). In 3.4.11 the signature was ( $method, $endpoint, $params = array() ). Headers passed in are merged over the Authorization header, so existing calls behave as before. It throws Exception on failure.

Defined in includes/gateways/stripe.php, line 454.

rpress_maybe_record_update()#

Records the stored plugin version after an update and fires rpress_updated.

Runs on admin_init at priority 5. When the stored rpress_version option is lower than RP_VERSION, it saves the old version in rpress_version_upgraded_from, updates rpress_version and fires rpress_updated with the old and new versions. Needed because WordPress updates do not run the activation routine.

rpress_maybe_record_update()

Internal. Defined in includes/install.php, line 530.

rpress_wpml_sync_settings_on_update()#

Registers updated RestroPress settings strings with WPML String Translation.

Hooked to update_option_rpress_settings. Does nothing unless WPML is active and the new value is an array. Registers the email text settings and per-status email subject, heading and content strings, and updates the matching rows in the icl_strings table.

rpress_wpml_sync_settings_on_update( $old_value, $new_value )

Parameters

ParameterTypeDefaultDescription
$old_valuemixedRequiredPrevious option value.
$new_valuemixedRequiredNew option value.

Internal. Defined in includes/plugin-compatibility.php, line 718.

rpress_calculate_tax()#

Calculates the tax on an amount at the store rate or a given rate.

With taxes disabled or an amount of zero or less the tax is 0. With $ignore_inclusive the tax is the amount times the rate, rounded down to cents. Otherwise it extracts the tax from a tax-inclusive price or adds it to an exclusive one, depending on the prices-include-tax setting. Filter with rpress_taxed_amount.

rpress_calculate_tax( $amount = 0, $country = false, $state = false ,$ignore_inclusive =false, $rate = null )

Parameters

ParameterTypeDefaultDescription
$amountfloat0Amount to calculate tax on.
$countrystring|falsefalseCountry to look the rate up for; the store default when false.
$statestring|falsefalseState to look the rate up for; the store default when false.
$ignore_inclusiveboolfalseTreat the amount as pre-tax even when prices include tax.
$ratefloat|nullnullDecimal rate such as 0.05. When null the rate comes from rpress_get_tax_rate().

Returns float: Tax amount.

Example

$tax = rpress_calculate_tax( 100, false, false, true, 0.05 ); // 5.0

Note: Changed in 3.5: added the fifth parameter $rate (default null) so callers can tax at a tax class rate. In 3.4.11 the signature was ( $amount = 0, $country = false, $state = false, $ignore_inclusive = false ) and the rate always came from rpress_get_tax_rate(); passing null keeps that behaviour. Passing a rate skips the country and state lookup.

Defined in includes/tax-functions.php, line 76.

rpress_get_tax_classes()#

Returns the configured tax classes.

The Standard class always exists; its rate is the tax_rate setting and its code the tax_class_standard_code setting. Other classes come from the rpress_tax_classes option. Filter with rpress_tax_classes.

rpress_get_tax_classes()

Returns array: Classes keyed by slug, each with name, rate (percent) and code.

Example

foreach ( rpress_get_tax_classes() as $slug => $class ) {
	echo esc_html( $class['name'] . ' ' . $class['rate'] . '%' );
}

Defined in includes/tax-functions.php, line 195.

rpress_get_fooditem_tax_class()#

Returns the tax class slug of a menu item.

Order of precedence: the item's _rpress_tax_class meta, the first of its food-category terms with a tax class, then standard. Filter with rpress_fooditem_tax_class.

rpress_get_fooditem_tax_class( $fooditem_id = 0 )

Parameters

ParameterTypeDefaultDescription
$fooditem_idint0Menu item ID.

Returns string: Tax class slug.

Defined in includes/tax-functions.php, line 224.

rpress_get_fooditem_tax_rate()#

Returns the decimal tax rate of a menu item.

A standard-class item uses rpress_get_tax_rate() so its filters apply. Other classes use their percent divided by 100. Filter with rpress_fooditem_tax_rate.

rpress_get_fooditem_tax_rate( $fooditem_id = 0, $country = false, $state = false )

Parameters

ParameterTypeDefaultDescription
$fooditem_idint0Menu item ID.
$countrystring|falsefalseCountry.
$statestring|falsefalseState.

Returns float: Rate as a decimal, 0.05 for 5%.

Example

$rate = rpress_get_fooditem_tax_rate( $fooditem_id );
$tax  = rpress_calculate_tax( 10, false, false, true, $rate );

Defined in includes/tax-functions.php, line 254.

rpress_get_fooditem_tax_percent()#

Returns the tax rate of a menu item in percent for showing its menu price.

A standard-class item returns the raw tax_rate setting, so single-rate stores show unchanged prices.

rpress_get_fooditem_tax_percent( $fooditem_id = 0 )

Parameters

ParameterTypeDefaultDescription
$fooditem_idint0Menu item ID.

Returns float: Rate in percent.

Defined in includes/tax-functions.php, line 275.

rpress_get_tax_breakdown()#

Returns per-class tax totals for a list of cart or order lines.

Lines are grouped by their tax_class, falling back to standard. When $total is given, the rows are scaled and rounded so they add up to it, with the last row taking the rounding remainder. Filter with rpress_tax_breakdown.

rpress_get_tax_breakdown( $lines, $total = null )

Parameters

ParameterTypeDefaultDescription
$linesarrayRequiredLines with tax, and tax_class and tax_rate when known.
$totalfloat|nullnullTax total the rows should add up to.

Returns array: Rows keyed by class slug, each with name, rate (percent), code and tax.

Example

$rows = rpress_get_tax_breakdown( rpress_get_cart_content_details(), rpress_get_cart_tax() );

Defined in includes/tax-functions.php, line 294.

rpress_lines_have_mixed_tax_rates()#

Checks whether cart or order lines are taxed at more than one rate.

Compares the tax_rate values of the lines.

rpress_lines_have_mixed_tax_rates( $lines )

Parameters

ParameterTypeDefaultDescription
$linesarrayRequiredCart or order lines.

Returns bool: True when more than one distinct rate is present.

Defined in includes/tax-functions.php, line 336.

Was this page helpful?