Skip to content
Docs
Get RestroPress

Function

Webhooks functions

Updated
On this page

Functions behind outgoing webhooks, added in RestroPress 3.5.1: endpoints, event payloads, request signing, the delivery queue and log, and the settings screen.

75 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_webhooks_settings_section()#

Adds the Webhooks section to the General settings tab.

Callback for the rpress_settings_sections_general filter.

rpress_webhooks_settings_section( $sections )

Parameters

ParameterTypeDefaultDescription
$sectionsarrayRequiredSettings sections keyed by section slug.

Returns array: The sections with the webhooks entry added.

Internal. Defined in includes/features/webhooks/admin.php, line 30.

rpress_webhooks_register_settings()#

Registers the Endpoints and Delivery log panels of the Webhooks settings section.

Callback for the rpress_settings_general filter. The two panels use the hook field type, so they are drawn by the rpress_webhooks_endpoints_panel and rpress_webhooks_log_panel actions.

rpress_webhooks_register_settings( $settings )

Parameters

ParameterTypeDefaultDescription
$settingsarrayRequiredGeneral tab settings keyed by section.

Returns array: The settings with the webhooks section set.

Internal. Defined in includes/features/webhooks/admin.php, line 42.

rpress_webhooks_is_settings_screen()#

Checks whether the current request is for the Webhooks settings section.

Compares the page and section query arguments with rpress-settings and webhooks. It does not check capabilities.

rpress_webhooks_is_settings_screen()

Returns bool: True on the Webhooks section.

Internal. Defined in includes/features/webhooks/admin.php, line 71.

rpress_webhooks_admin_time()#

Formats a Unix timestamp with the site's date and time formats and timezone.

rpress_webhooks_admin_time( $timestamp )

Parameters

ParameterTypeDefaultDescription
$timestampintRequiredUnix timestamp in seconds.

Returns string: The formatted date and time, or the translated word "Never" when the timestamp is zero or negative.

Internal. Defined in includes/features/webhooks/admin.php, line 85.

rpress_webhooks_status_labels()#

Returns the translated labels for webhook delivery statuses.

rpress_webhooks_status_labels()

Returns array: Labels keyed by pending, sending, retrying, success and failed.

Internal. Defined in includes/features/webhooks/admin.php, line 98.

rpress_webhooks_admin_assets()#

Enqueues the script and stylesheet of the Webhooks settings section.

Hooked to admin_enqueue_scripts. It does nothing outside that section or for users without the manage_shop_settings capability. It also passes the AJAX URL, a nonce and interface strings to the script.

rpress_webhooks_admin_assets()

Internal. Defined in includes/features/webhooks/admin.php, line 114.

rpress_webhooks_render_endpoints()#

Outputs the endpoints panel with the endpoint list and the add or edit fields.

Hooked to the rpress_webhooks_endpoints_panel action. Signing secrets are not printed in the page; the script requests them over AJAX.

rpress_webhooks_render_endpoints()

Note: Echoes output instead of returning it.

Internal. Defined in includes/features/webhooks/admin.php, line 150.

rpress_webhooks_render_log()#

Outputs the webhook delivery log, newest first, 20 rows per page.

Hooked to the rpress_webhooks_log_panel action. Each row has a details view with the URL, event ID, request body and stored response, plus a Resend button. The page number comes from the rpwh_paged query argument.

rpress_webhooks_render_log()

Note: Echoes output instead of returning it.

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

rpress_webhooks_ajax_admin()#

Handles the AJAX actions of the Webhooks settings section.

Handles wp_ajax_rpress_webhooks_admin after checking the nonce and the manage_shop_settings capability. The posted op value can be save_endpoint, toggle_endpoint, delete_endpoint, reveal_secret, send_test or resend.

rpress_webhooks_ajax_admin()

Note: Sends a JSON response and ends the request.

Internal. Defined in includes/features/webhooks/admin.php, line 366.

rpress_webhooks_now()#

Returns the current UTC time, with an optional offset, as a MySQL datetime.

rpress_webhooks_now( $offset = 0 )

Parameters

ParameterTypeDefaultDescription
$offsetint0Seconds to add to the current time. May be negative.

Returns string: Datetime in Y-m-d H:i:s format, in UTC.

Internal. Defined in includes/features/webhooks/delivery.php, line 27.

rpress_webhooks_dispatch()#

Queues a webhook event for every active target that listens to it.

Inserts one row per target in the deliveries table, all sharing one event ID, and schedules the rpress_webhooks_process_queue cron event. It makes no HTTP request. Nothing is written when the event key is unknown, the object ID is empty or no target listens.

rpress_webhooks_dispatch( $event, $object_id, $extra = array() )

Parameters

ParameterTypeDefaultDescription
$eventstringRequiredEvent key listed by rpress_webhooks_events().
$object_idintRequiredID of the order, customer, reservation or menu item the event is about.
$extraarrayarray()Event data stored at trigger time, such as previous_status and status for order.status_changed.

Returns int: Number of delivery rows queued.

Example

// Queue the order.paid event again for an existing order.
$order_id = 1042;
$queued   = rpress_webhooks_dispatch( 'order.paid', $order_id );

Note: The request body is built later, at the first delivery attempt, so it reflects the object as it is at that time. Built-in listeners already call this for core store activity, so calling it yourself can send an event twice.

Defined in includes/features/webhooks/delivery.php, line 42.

rpress_webhooks_schedule_worker()#

Schedules the delivery worker to run at or before a given time.

Schedules a single rpress_webhooks_process_queue cron event. An already scheduled run that is due at or before the requested time is kept; a later one is replaced. Past timestamps are treated as now.

rpress_webhooks_schedule_worker( $timestamp )

Parameters

ParameterTypeDefaultDescription
$timestampintRequiredUnix timestamp in seconds.

Internal. Defined in includes/features/webhooks/delivery.php, line 96.

rpress_webhooks_row_target()#

Returns the signing secret and active state of the target of a delivery row.

rpress_webhooks_row_target( $row )

Parameters

ParameterTypeDefaultDescription
$rowobjectRequiredDelivery row from the deliveries table.

Returns array|false: Array with secret and active, or false when rpress_webhooks_resolve_target() cannot resolve the target.

Internal. Defined in includes/features/webhooks/delivery.php, line 115.

rpress_webhooks_row_body()#

Returns the JSON request body of a delivery row, building and storing it if needed.

A stored body is reused. Otherwise the body is copied from another row with the same event ID, or built with rpress_webhooks_build_payload(), and saved to the row.

rpress_webhooks_row_body( $row )

Parameters

ParameterTypeDefaultDescription
$rowobjectRequiredDelivery row from the deliveries table.

Returns string|WP_Error: Raw JSON, or an error when the payload cannot be built or encoded.

Internal. Defined in includes/features/webhooks/delivery.php, line 129.

rpress_webhooks_send()#

Sends one signed webhook request by HTTP POST.

Uses wp_safe_remote_post() with redirects disabled and sends the X-RP-Webhook-Event, X-RP-Webhook-Id, X-RP-Webhook-Delivery, X-RP-Webhook-Timestamp and X-RP-Webhook-Signature headers. The timeout, 10 seconds by default, is filtered by rpress_webhooks_request_timeout. It does not write to the delivery log.

rpress_webhooks_send( $url, $body, $secret, $event, $event_id, $delivery_id )

Parameters

ParameterTypeDefaultDescription
$urlstringRequiredTarget URL.
$bodystringRequiredRaw JSON request body.
$secretstringRequiredSigning secret.
$eventstringRequiredEvent key.
$event_idstringRequiredEvent ID of the envelope.
$delivery_idintRequiredDelivery row ID.

Returns array: Array with ok (true for a 2xx response), code (HTTP status, 0 when the request failed) and body (response body or error message).

Internal. Defined in includes/features/webhooks/delivery.php, line 167.

rpress_webhooks_trim_response()#

Returns the first 1000 characters of a response body or error message.

The text is first passed through wp_check_invalid_utf8(). The result is not HTML-escaped.

rpress_webhooks_trim_response( $body )

Parameters

ParameterTypeDefaultDescription
$bodystringRequiredResponse body or error message.

Returns string: The shortened text.

Internal. Defined in includes/features/webhooks/delivery.php, line 221.

rpress_webhooks_finish_row()#

Records the result of a delivery attempt on its log row.

Updates the status, attempt count, response code, shortened response, update time and next attempt time.

rpress_webhooks_finish_row( $id, $status, $attempts, $code, $response, $delay = 0 )

Parameters

ParameterTypeDefaultDescription
$idintRequiredDelivery row ID.
$statusstringRequiredNew status: success, failed or retrying.
$attemptsintRequiredAttempts made so far.
$codeintRequiredLast HTTP status code, 0 for none.
$responsestringRequiredResponse body or error message.
$delayint0Seconds until the next attempt, used when retrying.

Internal. Defined in includes/features/webhooks/delivery.php, line 237.

rpress_webhooks_attempt_row()#

Attempts a claimed delivery row and records the result.

The delivery fails without a request when the target cannot be resolved, is paused or the body cannot be built. A failed request is scheduled for retry until the attempt limit is reached. For an HTTP 410 answer, a target type with a gone callback has that callback called and the delivery is not retried.

rpress_webhooks_attempt_row( $row )

Parameters

ParameterTypeDefaultDescription
$rowobjectRequiredDelivery row already set to the sending status.

Returns string: The resulting status: success, failed or retrying.

Internal. Defined in includes/features/webhooks/delivery.php, line 261.

rpress_webhooks_process_queue()#

Sends the webhook deliveries that are due.

Runs on the rpress_webhooks_process_queue cron hook. It releases rows stuck in sending for more than 5 minutes, claims each row before sending it, and schedules the next run if rows are still waiting. A run handles up to 25 rows (filter rpress_webhooks_batch_size) and starts no new row after 40 seconds.

rpress_webhooks_process_queue()

Returns int: Number of rows attempted.

Internal. Defined in includes/features/webhooks/delivery.php, line 309.

rpress_webhooks_send_test()#

Sends a signed ping event to a saved endpoint immediately and logs it.

The request is made during the current call and is not retried. It works on paused endpoints too. The function does not check capabilities.

rpress_webhooks_send_test( $endpoint_id )

Parameters

ParameterTypeDefaultDescription
$endpoint_idstringRequiredID of a saved endpoint.

Returns array|WP_Error: Array with success, code, message and delivery_id, or an error when the endpoint does not exist.

Example

$endpoint_ids = array_keys( rpress_webhooks_get_endpoints() );
if ( $endpoint_ids ) {
	$result = rpress_webhooks_send_test( $endpoint_ids[0] );
	if ( ! is_wp_error( $result ) ) {
		error_log( $result['message'] );
	}
}

Note: A failed delivery is returned as an array with success set to false, not as a WP_Error.

Defined in includes/features/webhooks/delivery.php, line 366.

rpress_webhooks_resend()#

Queues a copy of a logged webhook delivery.

The new row keeps the event ID, URL and stored body of the original, so receivers can recognise a repeat. It also schedules the delivery worker. The function does not check capabilities.

rpress_webhooks_resend( $delivery_id )

Parameters

ParameterTypeDefaultDescription
$delivery_idintRequiredID of the delivery row to resend.

Returns int|WP_Error: New delivery row ID, or an error when the row or its target no longer exists or the copy cannot be inserted.

Example

$delivery_id = 25;
$new_id      = rpress_webhooks_resend( $delivery_id );
if ( is_wp_error( $new_id ) ) {
	error_log( $new_id->get_error_message() );
}

Note: A paused target is accepted here, but the queued copy is then marked failed without being sent.

Defined in includes/features/webhooks/delivery.php, line 438.

rpress_webhooks_prune_log()#

Deletes delivery log rows older than the retention period.

Hooked to rpress_daily_scheduled_events. The period is 30 days by default, filtered by rpress_webhooks_log_retention_days (minimum 1). Age is measured from the row creation time, whatever its status.

rpress_webhooks_prune_log()

Returns int: Number of rows deleted.

Internal. Defined in includes/features/webhooks/delivery.php, line 487.

rpress_webhooks_events()#

Returns the webhook event keys and their labels.

Covers order, customer and menu item events. reservation.created is included only while reservations are enabled. The ping test event is not listed.

rpress_webhooks_events()

Returns array: Translated labels keyed by event key.

Example

foreach ( rpress_webhooks_events() as $event => $label ) {
	echo esc_html( $event . ': ' . $label ) . '<br>';
}

Defined in includes/features/webhooks/functions.php, line 33.

rpress_webhooks_event_resource()#

Returns the resource type that an event's data carries.

rpress_webhooks_event_resource( $event )

Parameters

ParameterTypeDefaultDescription
$eventstringRequiredEvent key, such as order.paid.

Returns string: order, customer, reservation or menu_item, or an empty string for any other prefix.

Example

$type = rpress_webhooks_event_resource( 'menu_item.sold_out' ); // 'menu_item'

Note: Only the part before the first dot is checked, so it does not confirm that the event key exists.

Defined in includes/features/webhooks/functions.php, line 56.

rpress_webhooks_sanitize_events()#

Filters a list of event keys down to the known ones.

The result follows the order of rpress_webhooks_events() and has no duplicates.

rpress_webhooks_sanitize_events( $events )

Parameters

ParameterTypeDefaultDescription
$eventsmixedRequiredEvent keys, usually an array from a request.

Returns array: List of known event keys.

Example

$events = rpress_webhooks_sanitize_events( array( 'order.paid', 'unknown.event' ) ); // array( 'order.paid' )

Defined in includes/features/webhooks/functions.php, line 67.

rpress_webhooks_sign()#

Returns the HMAC SHA-256 signature of a webhook delivery.

The signed string is the timestamp, a dot and the raw request body. Deliveries send the result in the X-RP-Webhook-Signature header, prefixed with sha256=, and the timestamp in X-RP-Webhook-Timestamp.

rpress_webhooks_sign( $secret, $timestamp, $body )

Parameters

ParameterTypeDefaultDescription
$secretstringRequiredSigning secret of the endpoint or target.
$timestampintRequiredUnix timestamp of the delivery attempt.
$bodystringRequiredRaw request body, exactly as sent.

Returns string: Lowercase hexadecimal signature, without a prefix.

Example

// Verify a delivery received on a WordPress REST route.
function myplugin_verify_webhook( WP_REST_Request $request, $secret ) {
	$timestamp = (int) $request->get_header( 'x_rp_webhook_timestamp' );
	$expected  = 'sha256=' . rpress_webhooks_sign( $secret, $timestamp, $request->get_body() );
	return hash_equals( $expected, (string) $request->get_header( 'x_rp_webhook_signature' ) );
}

Defined in includes/features/webhooks/functions.php, line 84.

rpress_webhooks_max_attempts()#

Returns the maximum number of attempts for a delivery, which is 5.

rpress_webhooks_max_attempts()

Returns int: Always 5.

Defined in includes/features/webhooks/functions.php, line 93.

rpress_webhooks_retry_delay()#

Returns the number of seconds to wait after a failed delivery attempt.

The delays after attempts 1 to 4 are 60, 300, 1800 and 7200 seconds.

rpress_webhooks_retry_delay( $attempt )

Parameters

ParameterTypeDefaultDescription
$attemptintRequiredNumber of the attempt that just failed, starting at 1.

Returns int: Delay in seconds, or 0 when no further attempt follows.

Example

$delay = rpress_webhooks_retry_delay( 2 ); // 300

Defined in includes/features/webhooks/functions.php, line 103.

rpress_webhooks_random_hex()#

Returns a cryptographically random hexadecimal string.

rpress_webhooks_random_hex( $bytes )

Parameters

ParameterTypeDefaultDescription
$bytesintRequiredNumber of random bytes, at least 1. The string is twice this length.

Returns string: Hexadecimal string.

Internal. Defined in includes/features/webhooks/functions.php, line 120.

rpress_webhooks_generate_secret()#

Generates a new webhook signing secret.

The secret is whsec_ followed by 34 random hexadecimal characters. It is not stored.

rpress_webhooks_generate_secret()

Returns string: A 40-character secret.

Defined in includes/features/webhooks/functions.php, line 129.

rpress_webhooks_generate_event_id()#

Generates a new webhook event ID.

rpress_webhooks_generate_event_id()

Returns string: evt_ followed by 24 random hexadecimal characters.

Internal. Defined in includes/features/webhooks/functions.php, line 138.

rpress_webhooks_clean_url()#

Validates a webhook target URL.

Accepts http and https URLs with a host, up to 2000 characters, without spaces, quotes, angle brackets or embedded credentials. A URL that esc_url_raw() would change is rejected. The host is not resolved; WordPress's safe HTTP API checks it when the request is sent.

rpress_webhooks_clean_url( $url )

Parameters

ParameterTypeDefaultDescription
$urlmixedRequiredRaw URL.

Returns string: The URL with surrounding whitespace trimmed, or an empty string when it is not accepted.

Example

$url = rpress_webhooks_clean_url( 'https://example.com/hooks/orders' );
if ( '' === $url ) {
	// Reject the input.
}

Defined in includes/features/webhooks/functions.php, line 150.

rpress_webhooks_get_list()#

Returns a stored webhook list from the options table.

Reads the option named rpress_webhooks_ followed by the list name.

rpress_webhooks_get_list( $name )

Parameters

ParameterTypeDefaultDescription
$namestringRequiredList name: endpoints, subscriptions or api_keys.

Returns array: Records keyed by ID, or an empty array.

Internal. Defined in includes/features/webhooks/functions.php, line 180.

rpress_webhooks_save_list()#

Saves a webhook list to the options table.

Replaces the whole rpress_webhooks_ option for the list and sets it not to autoload.

rpress_webhooks_save_list( $name, $list )

Parameters

ParameterTypeDefaultDescription
$namestringRequiredList name: endpoints, subscriptions or api_keys.
$listarrayRequiredRecords keyed by ID.

Internal. Defined in includes/features/webhooks/functions.php, line 192.

rpress_webhooks_get_endpoints()#

Returns the saved webhook endpoints.

rpress_webhooks_get_endpoints()

Returns array: Endpoints keyed by ID, each with id, label, url, events, secret, active and created.

Example

foreach ( rpress_webhooks_get_endpoints() as $id => $endpoint ) {
	error_log( $id . ' ' . $endpoint['url'] );
}

Note: Each record includes the signing secret, so do not output the array as it is.

Defined in includes/features/webhooks/functions.php, line 201.

rpress_webhooks_save_endpoint()#

Creates or updates a webhook endpoint.

The URL must pass rpress_webhooks_clean_url() and at least one known event is required. An empty label is replaced by the URL host, and labels are cut to 100 characters. A new endpoint gets an ID, a signing secret and is active; an update keeps the secret. The function does not check capabilities.

rpress_webhooks_save_endpoint( $data, $id = '' )

Parameters

ParameterTypeDefaultDescription
$dataarrayRequiredKeys label, url, events and optionally active.
$idstring''ID of the endpoint to update, or an empty string to create one.

Returns array|WP_Error: The stored endpoint, or an error for a missing endpoint, invalid URL or empty event list.

Example

$endpoint = rpress_webhooks_save_endpoint(
	array(
		'label'  => 'Kitchen system',
		'url'    => 'https://example.com/hooks/orders',
		'events' => array( 'order.created', 'order.status_changed' ),
	)
);
if ( is_wp_error( $endpoint ) ) {
	error_log( $endpoint->get_error_message() );
}

Note: url and events are required when updating too.

Defined in includes/features/webhooks/functions.php, line 212.

rpress_webhooks_delete_endpoint()#

Deletes a saved webhook endpoint.

Delivery log rows are kept. Deliveries still waiting for the endpoint are marked failed when the worker reaches them. The function does not check capabilities.

rpress_webhooks_delete_endpoint( $id )

Parameters

ParameterTypeDefaultDescription
$idstringRequiredEndpoint ID.

Returns bool: True when deleted, false when no endpoint has that ID.

Defined in includes/features/webhooks/functions.php, line 261.

rpress_webhooks_endpoint_targets()#

Returns the active saved endpoints that listen to an event.

This is the targets callback of the built-in endpoint target type.

rpress_webhooks_endpoint_targets( $event )

Parameters

ParameterTypeDefaultDescription
$eventstringRequiredEvent key.

Returns array: List of arrays with id, url and label.

Internal. Defined in includes/features/webhooks/functions.php, line 283.

rpress_webhooks_endpoint_resolve()#

Returns the signing secret and active state of a saved endpoint.

This is the resolve callback of the built-in endpoint target type.

rpress_webhooks_endpoint_resolve( $id )

Parameters

ParameterTypeDefaultDescription
$idstringRequiredEndpoint ID.

Returns array|false: Array with secret and active, or false when the endpoint does not exist.

Internal. Defined in includes/features/webhooks/functions.php, line 304.

rpress_webhooks_register_target_type()#

Registers a delivery target type so an extension can use the webhook queue.

Targets of a registered type share the queue, signing, retries, delivery log and resend of saved endpoints. The targets callback receives an event key and returns a list of arrays with id (up to 32 characters), url and label. The resolve callback receives a target ID and returns secret and active, or false. The optional gone callback is called with the target ID after an HTTP 410 answer.

rpress_webhooks_register_target_type( $type, $args )

Parameters

ParameterTypeDefaultDescription
$typestringRequiredType key of 2 to 20 lowercase letters, digits or underscores, starting with a letter. endpoint is reserved.
$argsarrayRequiredRequired label, targets and resolve, and optional gone.

Returns true|WP_Error: True on success, or an error for an invalid or already registered type or invalid arguments.

Example

add_action( 'init', function () {
	if ( ! function_exists( 'rpress_webhooks_register_target_type' ) ) {
		return;
	}
	rpress_webhooks_register_target_type(
		'myplugin',
		array(
			'label'   => 'My integration',
			'targets' => function ( $event ) {
				if ( 'order.paid' !== $event ) {
					return array();
				}
				return array(
					array( 'id' => 'main', 'url' => 'https://example.com/hooks/rp', 'label' => 'Main' ),
				);
			},
			'resolve' => function ( $id ) {
				$secret = (string) get_option( 'myplugin_webhook_secret', '' );
				if ( 'main' !== $id || '' === $secret ) {
					return false;
				}
				return array( 'secret' => $secret, 'active' => true );
			},
		)
	);
} );

Note: The registration lasts for the current request only, so register on every request, including cron requests.

Defined in includes/features/webhooks/functions.php, line 332.

rpress_webhooks_get_target_types()#

Returns all webhook delivery target types, with the built-in endpoint type first.

rpress_webhooks_get_target_types()

Returns array: Entries keyed by type, each with label, targets, resolve and gone.

Defined in includes/features/webhooks/functions.php, line 367.

rpress_webhooks_resolve_target()#

Returns a delivery target's secret and active state through its type's callback.

A target without an active value counts as active.

rpress_webhooks_resolve_target( $type, $id )

Parameters

ParameterTypeDefaultDescription
$typestringRequiredTarget type key.
$idstringRequiredTarget ID.

Returns array|false: Array with secret and active, or false when the type is not registered or the callback returns no secret.

Internal. Defined in includes/features/webhooks/functions.php, line 389.

rpress_webhooks_targets_for()#

Returns every target of every type that should receive an event.

Calls each type's targets callback. Entries with a missing or non-scalar ID, an ID longer than 32 characters or a URL rejected by rpress_webhooks_clean_url() are skipped. Labels are cut to 190 bytes.

rpress_webhooks_targets_for( $event )

Parameters

ParameterTypeDefaultDescription
$eventstringRequiredEvent key.

Returns array: List of arrays with type, id, label and url.

Internal. Defined in includes/features/webhooks/functions.php, line 413.

rpress_webhooks_user_agent()#

Returns the User-Agent string sent with webhook deliveries.

rpress_webhooks_user_agent()

Returns string: RestroPress-Webhooks/ followed by the plugin version.

Internal. Defined in includes/features/webhooks/functions.php, line 441.

rpress_webhooks_status_change_decision()#

Decides whether a reported order status counts as a change for webhooks.

An empty or unchanged status is ignored. When no earlier status was stored, pending is treated as the starting point and any other status counts as a change with an unknown previous status.

rpress_webhooks_status_change_decision( $stored, $new )

Parameters

ParameterTypeDefaultDescription
$storedstringRequiredLast status seen for the order, or an empty string.
$newstringRequiredReported status.

Returns array: Array with emit (bool) and previous (string or null).

Internal. Defined in includes/features/webhooks/functions.php, line 461.

rpress_webhooks_stock_event()#

Returns the webhook event for a change of a menu item's availability.

Only the value unavailable counts as sold out; any other value, including a missing one, counts as available.

rpress_webhooks_stock_event( $is_fooditem, $new, $old )

Parameters

ParameterTypeDefaultDescription
$is_fooditemboolRequiredWhether the post is a fooditem.
$newstringRequiredNew rp_stock_status value.
$oldmixedRequiredPrevious value, or null when the meta did not exist.

Returns string: menu_item.sold_out, menu_item.back_in_stock, or an empty string for no event.

Internal. Defined in includes/features/webhooks/functions.php, line 493.

rpress_webhooks_iso()#

Formats a Unix timestamp as an ISO 8601 UTC string.

rpress_webhooks_iso( $timestamp )

Parameters

ParameterTypeDefaultDescription
$timestampintRequiredUnix timestamp in seconds.

Returns string|null: A value such as 2026-01-15T18:05:00Z, or null when the timestamp is zero or negative.

Example

$when = rpress_webhooks_iso( time() );

Defined in includes/features/webhooks/functions.php, line 511.

rpress_webhooks_iso_from_mysql()#

Converts a MySQL datetime to an ISO 8601 UTC string.

rpress_webhooks_iso_from_mysql( $mysql, $is_local = false )

Parameters

ParameterTypeDefaultDescription
$mysqlstringRequiredDatetime in Y-m-d H:i:s format.
$is_localboolfalseTrue when the value is in the site timezone, false when it is already UTC.

Returns string|null: The converted value, or null for an empty, zero or unreadable date.

Internal. Defined in includes/features/webhooks/functions.php, line 523.

rpress_webhooks_table()#

Returns the name of the webhook deliveries table, including the site prefix.

rpress_webhooks_table()

Returns string: Table name ending in rpress_webhook_deliveries.

Internal. Defined in includes/features/webhooks/install.php, line 23.

rpress_webhooks_install()#

Creates or upgrades the webhook deliveries table.

Runs dbDelta() and stores the schema version in the rpress_webhooks_db_version option.

rpress_webhooks_install()

Internal. Defined in includes/features/webhooks/install.php, line 33.

rpress_webhooks_maybe_install()#

Installs the deliveries table when the stored schema version differs.

Hooked to admin_init and also called before queue writes and worker runs. The version is checked at most once per request.

rpress_webhooks_maybe_install()

Returns bool: True when the install ran in this call.

Internal. Defined in includes/features/webhooks/install.php, line 76.

rpress_webhooks_wpmu_drop_tables()#

Adds the deliveries table to the tables dropped when a multisite site is deleted.

Callback for the wpmu_drop_tables filter.

rpress_webhooks_wpmu_drop_tables( $tables, $blog_id )

Parameters

ParameterTypeDefaultDescription
$tablesarrayRequiredTable names to drop.
$blog_idintRequiredID of the site being deleted.

Returns array: The table names including the deliveries table.

Internal. Defined in includes/features/webhooks/install.php, line 96.

rpress_webhooks_money()#

Converts an amount to a float rounded to two decimals.

rpress_webhooks_money( $amount )

Parameters

ParameterTypeDefaultDescription
$amountmixedRequiredAmount.

Returns float: The rounded amount.

Internal. Defined in includes/features/webhooks/payloads.php, line 24.

rpress_webhooks_plain_text()#

Decodes HTML entities in a title or term name for use in a payload.

rpress_webhooks_plain_text( $text )

Parameters

ParameterTypeDefaultDescription
$textmixedRequiredText.

Returns string: The decoded text.

Internal. Defined in includes/features/webhooks/payloads.php, line 34.

rpress_webhooks_order_resource()#

Builds the order data used in webhook payloads.

Includes statuses, service type, date and time, totals, discount codes, gateway, note, customer details, delivery address, items with their add-ons and dates. The publish payment status is reported as paid. rpress_webhooks_get_resource() returns the same data for the order type.

rpress_webhooks_order_resource( $order_id )

Parameters

ParameterTypeDefaultDescription
$order_idintRequiredOrder (payment) ID.

Returns array|null: Order data, or null when the order does not exist.

Note: Contains customer personal data.

Internal. Defined in includes/features/webhooks/payloads.php, line 44.

rpress_webhooks_customer_resource()#

Builds the customer data used in webhook payloads.

Includes the ID, user ID, email, name, order count, total spent and creation date.

rpress_webhooks_customer_resource( $customer_id )

Parameters

ParameterTypeDefaultDescription
$customer_idintRequiredCustomer ID from the RestroPress customers table, not a WordPress user ID.

Returns array|null: Customer data, or null when the customer does not exist.

Internal. Defined in includes/features/webhooks/payloads.php, line 164.

rpress_webhooks_reservation_resource()#

Builds the reservation data used in webhook payloads.

The time field is the reservation timestamp as an ISO 8601 UTC string.

rpress_webhooks_reservation_resource( $reservation_id )

Parameters

ParameterTypeDefaultDescription
$reservation_idintRequiredReservation ID.

Returns array|null: Array with id, status, date, time, party, name, phone, email and note, or null when no reservation is found.

Internal. Defined in includes/features/webhooks/payloads.php, line 188.

rpress_webhooks_menu_item_resource()#

Builds the menu item data used in webhook payloads.

Category names come from the food-category taxonomy. A missing availability value is reported as available.

rpress_webhooks_menu_item_resource( $item_id )

Parameters

ParameterTypeDefaultDescription
$item_idintRequiredMenu item (fooditem) post ID.

Returns array|null: Array with id, name, sku, price, stock_status, permalink and categories, or null when the post is not a menu item.

Internal. Defined in includes/features/webhooks/payloads.php, line 212.

rpress_webhooks_get_resource()#

Returns the webhook data object for an order, customer, reservation or menu item.

The result has the same structure as the object carried in webhook payloads. The function does not check capabilities.

rpress_webhooks_get_resource( $type, $object_id )

Parameters

ParameterTypeDefaultDescription
$typestringRequiredorder, customer, reservation or menu_item.
$object_idintRequiredID of the object.

Returns array|null: Resource data, or null for an unknown type or a missing object.

Example

$order = rpress_webhooks_get_resource( 'order', 1042 );
if ( null !== $order ) {
	error_log( $order['number'] . ' ' . $order['total'] );
}

Note: Order, customer and reservation data include personal details.

Defined in includes/features/webhooks/payloads.php, line 244.

rpress_webhooks_envelope()#

Wraps event data in the standard webhook envelope.

The envelope has id, event, api_version (1), created_at, site_url, test and data.

rpress_webhooks_envelope( $event, $data, $extra = array() )

Parameters

ParameterTypeDefaultDescription
$eventstringRequiredEvent key or ping.
$dataarrayRequiredData object of the event.
$extraarrayarray()Optional id, created_at (Unix timestamp) and test. A missing ID is generated and a missing time is set to now.

Returns array: The envelope.

Internal. Defined in includes/features/webhooks/payloads.php, line 266.

rpress_webhooks_build_payload()#

Builds the full webhook payload for an event about one object.

A ping event returns a test message and ignores the object ID. For order.status_changed the data also includes previous_status and status, taken from the extra values; without status the current order status is used. Nothing is queued or sent.

rpress_webhooks_build_payload( $event, $object_id, $extra = array() )

Parameters

ParameterTypeDefaultDescription
$eventstringRequiredEvent key or ping.
$object_idintRequiredID of the order, customer, reservation or menu item.
$extraarrayarray()Optional id, created_at, test, previous_status and status.

Returns array|WP_Error: The payload envelope, or an error for an unknown event or a missing object.

Example

$payload = rpress_webhooks_build_payload( 'order.paid', 1042 );
if ( ! is_wp_error( $payload ) ) {
	$json = wp_json_encode( $payload );
}

Defined in includes/features/webhooks/payloads.php, line 286.

rpress_webhooks_static_resource()#

Returns built-in example data for a webhook resource type.

rpress_webhooks_static_resource( $type )

Parameters

ParameterTypeDefaultDescription
$typestringRequiredorder, customer, reservation or menu_item. Any other value returns the order example.

Returns array: Example resource data.

Internal. Defined in includes/features/webhooks/payloads.php, line 325.

rpress_webhooks_shape_sample()#

Adjusts sample resource data to match the event it illustrates.

Sets the availability for the menu item events. For order.status_changed it also works out a plausible previous status from the order status model.

rpress_webhooks_shape_sample( $event, $resource )

Parameters

ParameterTypeDefaultDescription
$eventstringRequiredEvent key.
$resourcearrayRequiredResource data.

Returns array: Array with resource and extra.

Internal. Defined in includes/features/webhooks/payloads.php, line 422.

rpress_webhooks_static_sample()#

Returns a built-in sample payload for an event.

The envelope is marked as a test and has a fixed ID and creation time.

rpress_webhooks_static_sample( $event )

Parameters

ParameterTypeDefaultDescription
$eventstringRequiredEvent key.

Returns array: Sample envelope.

Internal. Defined in includes/features/webhooks/payloads.php, line 466.

rpress_webhooks_recent_object_ids()#

Returns the IDs of recent records that suit an event.

Records are ordered by ID, newest first. For the paid, refunded and cancelled order events, matching orders are preferred; when there are none, recent orders of any payment status are returned.

rpress_webhooks_recent_object_ids( $event, $limit = 3 )

Parameters

ParameterTypeDefaultDescription
$eventstringRequiredEvent key.
$limitint3Maximum number of IDs.

Returns int[]: Record IDs.

Internal. Defined in includes/features/webhooks/payloads.php, line 507.

rpress_webhooks_samples()#

Returns sample payloads for a webhook event.

Builds up to three envelopes from recent records, or one built-in example when none can be built. All are marked with test set to true. Nothing is queued or sent, and capabilities are not checked.

rpress_webhooks_samples( $event )

Parameters

ParameterTypeDefaultDescription
$eventstringRequiredEvent key listed by rpress_webhooks_events().

Returns array: List of envelopes, or an empty array for an event that is not listed, including ping.

Example

$samples = rpress_webhooks_samples( 'order.created' );

Note: Samples built from store records contain real customer data, even though they are marked as tests.

Defined in includes/features/webhooks/payloads.php, line 567.

rpress_webhooks_on_insert_payment()#

Queues the order.created event when a new order is stored.

Hooked to rpress_insert_payment.

rpress_webhooks_on_insert_payment( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.

Internal. Defined in includes/features/webhooks/triggers.php, line 23.

rpress_webhooks_on_payment_status()#

Queues the order.paid or order.refunded event when the payment status changes.

Hooked to rpress_update_payment_status. A change to publish queues order.paid and a change to refunded queues order.refunded.

rpress_webhooks_on_payment_status( $payment_id, $new_status, $old_status )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.
$new_statusstringRequiredNew payment status.
$old_statusstringRequiredPrevious payment status.

Internal. Defined in includes/features/webhooks/triggers.php, line 35.

rpress_webhooks_on_order_status()#

Queues the order status change and cancellation events.

Hooked to rpress_update_order_status. The last seen status is kept in the _rpress_webhooks_last_status order meta. A real change queues order.status_changed, and a change to cancelled also queues order.cancelled.

rpress_webhooks_on_order_status( $payment_id, $new_status )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.
$new_statusstringRequiredNew order status.

Internal. Defined in includes/features/webhooks/triggers.php, line 58.

rpress_webhooks_before_customer_create()#

Records whether a customer email already exists before the customer is created.

Hooked to rpress_customer_pre_create, so that an update of an existing customer does not produce a customer.created event.

rpress_webhooks_before_customer_create( $args )

Parameters

ParameterTypeDefaultDescription
$argsarrayRequiredCustomer data.

Internal. Defined in includes/features/webhooks/triggers.php, line 94.

rpress_webhooks_on_customer_created()#

Queues the customer.created event for a new customer record.

Hooked to rpress_customer_post_create. Nothing is queued when creation failed or the email already existed.

rpress_webhooks_on_customer_created( $created, $args )

Parameters

ParameterTypeDefaultDescription
$createdint|falseRequiredCustomer ID, or false when creation failed.
$argsarrayRequiredCustomer data.

Internal. Defined in includes/features/webhooks/triggers.php, line 109.

rpress_webhooks_on_reservation_created()#

Queues the reservation.created event for a new reservation.

Hooked to rpress_reservation_created. The event is dropped while reservations are disabled.

rpress_webhooks_on_reservation_created( $reservation_id )

Parameters

ParameterTypeDefaultDescription
$reservation_idintRequiredReservation ID.

Internal. Defined in includes/features/webhooks/triggers.php, line 127.

rpress_webhooks_before_stock_update()#

Records a menu item's availability before the rp_stock_status meta is updated.

Hooked to update_post_meta. Other meta keys are ignored.

rpress_webhooks_before_stock_update( $meta_id, $object_id, $meta_key )

Parameters

ParameterTypeDefaultDescription
$meta_idintRequiredMeta row ID.
$object_idintRequiredPost ID.
$meta_keystringRequiredMeta key.

Internal. Defined in includes/features/webhooks/triggers.php, line 139.

rpress_webhooks_on_stock_updated()#

Queues a sold out or back in stock event when rp_stock_status is updated.

Hooked to updated_post_meta. Only posts of type fooditem produce an event.

rpress_webhooks_on_stock_updated( $meta_id, $object_id, $meta_key, $meta_value )

Parameters

ParameterTypeDefaultDescription
$meta_idintRequiredMeta row ID.
$object_idintRequiredPost ID.
$meta_keystringRequiredMeta key.
$meta_valuemixedRequiredNew meta value.

Internal. Defined in includes/features/webhooks/triggers.php, line 156.

rpress_webhooks_on_stock_added()#

Queues a sold out event when rp_stock_status is first saved as unavailable.

Hooked to added_post_meta. A first value other than unavailable produces no event because an item without the meta counts as available.

rpress_webhooks_on_stock_added( $meta_id, $object_id, $meta_key, $meta_value )

Parameters

ParameterTypeDefaultDescription
$meta_idintRequiredMeta row ID.
$object_idintRequiredPost ID.
$meta_keystringRequiredMeta key.
$meta_valuemixedRequiredMeta value.

Internal. Defined in includes/features/webhooks/triggers.php, line 183.

Was this page helpful?