Skip to content
Docs
Get RestroPress

Function

Customers and users functions

Updated
On this page

Functions for customers and user accounts, including the customers admin screens.

87 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_edit_customer()#

Updates a customer's name, email, linked user and address from the admin edit form.

Checks capability and the edit-customer nonce, validates the email and user ID, saves the customer and the linked user's _rpress_user_address meta, and propagates a changed email or user ID to the customer's orders. Fires rpress_pre_edit_customer and rpress_post_edit_customer. Hooked to rpress_edit-customer.

rpress_edit_customer( $args )

Parameters

ParameterTypeDefaultDescription
$argsarrayRequiredRequest data, normally $_POST. Needs customerinfo (with id, name, email, user_id, optional address fields) and _wpnonce.

Returns array|false|void: Array with success and customer_info; false if the customer does not exist; nothing if validation errors were set. In AJAX requests it prints JSON and exits.

Note: Calls wp_die() without the capability or a valid nonce. Validation errors are stored with rpress_set_error().

Internal. Defined in includes/admin/customers/customer-actions.php, line 12.

rpress_add_customer_email()#

Adds an additional email address to a customer from the admin and logs a customer note.

Verifies the rpress-add-customer-email nonce, validates the address, optionally makes it primary, and adds notes recording who did it. Fires rpress_post_add_customer_email. Hooked to rpress_customer-add-email.

rpress_add_customer_email( $args )

Parameters

ParameterTypeDefaultDescription
$argsarrayRequiredRequest data with email, customer_id, primary ('true' or 'false') and _wpnonce.

Returns array: Array with success (bool), message and, on success, redirect. In AJAX requests it prints JSON and exits.

Note: Requires the edit_shop_payments capability (filterable with rpress_edit_customers_role) and an admin request; otherwise wp_die() is called.

Internal. Defined in includes/admin/customers/customer-actions.php, line 143.

rpress_remove_customer_email()#

Removes an email address from a customer from the admin, logs a note and redirects.

Reads id, email and _wpnonce from $_GET, verifies the rpress-remove-customer-email nonce, and redirects back to the customer overview with an rpress-message of email-removed or email-remove-failed. Hooked to rpress_customer-remove-email.

rpress_remove_customer_email()

Note: Requires the edit_shop_payments capability (filterable with rpress_edit_customers_role) and an admin request; otherwise wp_die() is called.

Internal. Defined in includes/admin/customers/customer-actions.php, line 220.

rpress_set_customer_primary_email()#

Sets one of a customer's email addresses as primary from the admin and logs a note.

Reads id, email and _wpnonce from $_GET, verifies the rpress-set-customer-primary-email nonce, and redirects with an rpress-message of primary-email-updated or primary-email-failed. Hooked to rpress_customer-primary-email.

rpress_set_customer_primary_email()

Note: Requires the edit_shop_payments capability (filterable with rpress_edit_customers_role) and an admin request; otherwise wp_die() is called.

Internal. Defined in includes/admin/customers/customer-actions.php, line 262.

rpress_customer_save_note()#

Saves a note on a customer record from the admin note form.

Requires the view_shop_reports capability (filterable with rpress_view_customers_role) and the add-customer-note nonce. Fires rpress_pre_insert_customer_note after the note is added. Hooked to rpress_add-customer-note.

rpress_customer_save_note( $args )

Parameters

ParameterTypeDefaultDescription
$argsarrayRequiredRequest data with customer_note, customer_id and add_customer_note_nonce.

Returns string|false|void: The saved note text, or false if it was not saved. Prints markup and exits in AJAX requests.

Internal. Defined in includes/admin/customers/customer-actions.php, line 305.

rpress_trash_customer_record()#

Moves a customer to the trash by setting the _rpress_customer_trashed meta.

Does not delete data or change the customer's orders. Returns true without changes if the customer is already trashed. Performs no capability check.

rpress_trash_customer_record( $customer_id )

Parameters

ParameterTypeDefaultDescription
$customer_idintRequiredCustomer ID.

Returns bool: True if the customer is now trashed, false if the ID is empty or the customer does not exist, or the update failed.

Example

if ( rpress_trash_customer_record( 15 ) ) {
	error_log( 'Customer 15 trashed' );
}

Note: Performs no capability check; the caller must authorize the action.

Defined in includes/admin/customers/customer-actions.php, line 355.

rpress_restore_customer_record()#

Restores a trashed customer by removing the _rpress_customer_trashed meta.

Returns true without changes if the customer is not trashed. Performs no capability check.

rpress_restore_customer_record( $customer_id )

Parameters

ParameterTypeDefaultDescription
$customer_idintRequiredCustomer ID.

Returns bool: True if the customer is no longer trashed, false if the ID is empty, the customer does not exist, or the update failed.

Example

rpress_restore_customer_record( 15 );

Note: Performs no capability check.

Defined in includes/admin/customers/customer-actions.php, line 384.

rpress_delete_customer_record()#

Permanently deletes a customer record and detaches or deletes its orders.

Deletes the row through RPRESS()->customers->delete(). If $remove_data is true each of the customer's orders is deleted with rpress_delete_purchase(); otherwise the orders stay and their _rpress_payment_customer_id meta is set to 0. Performs no capability check.

rpress_delete_customer_record( $customer_id, $remove_data = false )

Parameters

ParameterTypeDefaultDescription
$customer_idintRequiredCustomer ID.
$remove_databoolfalseWhether to also delete the customer's orders and related records.

Returns bool: True on success, false if the ID is empty, the customer is missing, or the delete failed.

Example

// Delete the customer but keep the orders.
rpress_delete_customer_record( 15, false );

Note: Irreversible. Performs no capability check.

Defined in includes/admin/customers/customer-actions.php, line 414.

rpress_customer_delete()#

Handles the admin request that moves a customer to the trash.

Checks capability, the delete-customer nonce and the confirm checkbox, fires rpress_pre_delete_customer, trashes the customer with rpress_trash_customer_record() and redirects. Hooked to rpress_delete-customer.

rpress_customer_delete( $args )

Parameters

ParameterTypeDefaultDescription
$argsarrayRequiredRequest data with customer_id, rpress-customer-delete-confirm and _wpnonce.

Note: Requires the edit_shop_payments capability (filterable with rpress_edit_customers_role) and an admin request; otherwise wp_die() is called.

Internal. Defined in includes/admin/customers/customer-actions.php, line 453.

rpress_customer_restore()#

Handles the admin request that restores a trashed customer.

Checks capability and the restore-customer nonce, restores the customer with rpress_restore_customer_record() and redirects to the trash list. Hooked to rpress_restore-customer.

rpress_customer_restore( $args )

Parameters

ParameterTypeDefaultDescription
$argsarrayRequiredRequest data with customer_id and _wpnonce.

Note: Requires the edit_shop_payments capability (filterable with rpress_edit_customers_role) and an admin request; otherwise wp_die() is called.

Internal. Defined in includes/admin/customers/customer-actions.php, line 496.

rpress_customer_delete_permanently()#

Handles the admin request that permanently deletes a customer.

Checks capability, the delete-customer-permanently nonce and the confirm checkbox, fires rpress_pre_delete_customer, and calls rpress_delete_customer_record() with the rpress-customer-delete-records choice. Hooked to rpress_delete-customer-permanently.

rpress_customer_delete_permanently( $args )

Parameters

ParameterTypeDefaultDescription
$argsarrayRequiredRequest data with customer_id, rpress-customer-delete-confirm, rpress-customer-delete-records and _wpnonce.

Note: Requires the edit_shop_payments capability (filterable with rpress_edit_customers_role) and an admin request; otherwise wp_die() is called.

Internal. Defined in includes/admin/customers/customer-actions.php, line 527.

rpress_customers_list_table_process_bulk_actions()#

Processes the delete, restore and delete_permanently bulk actions on the Customers list.

Runs on admin_init for the rpress-customers page, verifies the bulk nonce and capability, applies the action to each selected customer ID, then redirects with an rpress-message. Bulk permanent deletion never removes the customers' orders.

rpress_customers_list_table_process_bulk_actions()

Internal. Defined in includes/admin/customers/customer-actions.php, line 566.

rpress_disconnect_customer_user_id()#

Disconnects the WordPress user from a customer record.

Sets the customer's user_id to 0 and resets _rpress_payment_user_id on the customer's orders. Fires rpress_pre_customer_disconnect_user_id and rpress_post_customer_disconnect_user_id. Hooked to rpress_disconnect-userid.

rpress_disconnect_customer_user_id( $args )

Parameters

ParameterTypeDefaultDescription
$argsarrayRequiredRequest data with customer_id and _wpnonce (the edit-customer nonce).

Returns array|false|void: Array with success; false if the customer does not exist. In AJAX requests it prints JSON and exits.

Note: Requires the edit_shop_payments capability (filterable with rpress_edit_customers_role) and an admin request; otherwise wp_die() is called.

Internal. Defined in includes/admin/customers/customer-actions.php, line 656.

rpress_process_admin_user_verification()#

Marks a customer's linked user account as verified from the admin.

Reads id and _wpnonce from $_GET, verifies the rpress-verify-user nonce, calls rpress_set_user_to_verified() for the customer's user and redirects with the message user-verified. Hooked to rpress_verify_user_admin.

rpress_process_admin_user_verification()

Note: Requires the edit_shop_payments capability (filterable with rpress_edit_customers_role) and an admin request; otherwise wp_die() is called.

Internal. Defined in includes/admin/customers/customer-actions.php, line 707.

rpress_register_batch_single_customer_recount_tool()#

Registers the loader for the single-customer stats recount batch processor.

rpress_register_batch_single_customer_recount_tool()

Internal. Defined in includes/admin/customers/customer-actions.php, line 734.

rpress_include_single_customer_recount_tool_batch_processer()#

Loads the single-customer stats recount batch class when it is requested.

rpress_include_single_customer_recount_tool_batch_processer( $class )

Parameters

ParameterTypeDefaultDescription
$classstringRequiredBatch class name being requested.

Internal. Defined in includes/admin/customers/customer-actions.php, line 745.

rpress_customer_action_calls()#

Hooks customer meta changes to refresh the customers table cache.

Calls set_last_changed on RPRESS()->customers after customer meta is added, updated or deleted.

rpress_customer_action_calls()

Internal. Defined in includes/admin/customers/customer-actions.php, line 757.

rpress_register_default_customer_views()#

Registers the default admin customer views on rpress_customer_views.

rpress_register_default_customer_views( $views )

Parameters

ParameterTypeDefaultDescription
$viewsarrayRequiredExisting views.

Returns array: The views merged with overview, orders, notes, tools and delete, all rendered by rpress_customers_view().

Internal. Defined in includes/admin/customers/customer-functions.php, line 11.

rpress_register_default_customer_tabs()#

Registers the default admin customer tabs on rpress_customer_tabs.

rpress_register_default_customer_tabs( $tabs )

Parameters

ParameterTypeDefaultDescription
$tabsarrayRequiredExisting tabs.

Returns array: The tabs merged with overview, orders, notes and tools.

Internal. Defined in includes/admin/customers/customer-functions.php, line 29.

rpress_register_delete_customer_tab()#

Adds the Delete tab last on the customer admin screen.

rpress_register_delete_customer_tab( $tabs )

Parameters

ParameterTypeDefaultDescription
$tabsarrayRequiredExisting tabs.

Returns array: The tabs with a delete entry added.

Internal. Defined in includes/admin/customers/customer-functions.php, line 46.

Removes the admin bar profile link for users pending verification.

Skipped for users with the manage_shop_settings capability.

rpress_maybe_remove_adminbar_profile_link()

Internal. Defined in includes/admin/customers/customer-functions.php, line 57.

Blocks profile access for users whose account is pending verification.

Runs on admin_init. Skipped for AJAX requests and users with manage_shop_settings. On the profile page it ends the request with a 403 message and a link to resend the activation email; elsewhere it removes the profile menu entries.

rpress_maybe_remove_menu_profile_links()

Internal. Defined in includes/admin/customers/customer-functions.php, line 73.

rpress_customers_admin_legacy_css_version()#

Sets the version query argument of two admin stylesheets to the file modification time.

Applies to the rpress_admin_styles and rpress-admin style handles on style_loader_src.

rpress_customers_admin_legacy_css_version( $src, $handle )

Parameters

ParameterTypeDefaultDescription
$srcstringRequiredStylesheet URL.
$handlestringRequiredStyle handle.

Returns string: The URL, with ver replaced for the matching handles.

Internal. Defined in includes/admin/customers/customers.php, line 5.

rpress_customers_page()#

Renders the Customers admin page, choosing between the list and a single customer view.

Uses the view query argument and the views from rpress_customer_views().

rpress_customers_page()

Internal. Defined in includes/admin/customers/customers.php, line 32.

rpress_customer_views()#

Returns the registered customer admin views.

Applies the rpress_customer_views filter to an empty array.

rpress_customer_views()

Returns array: View slugs mapped to callbacks.

Example

add_filter( 'rpress_customer_views', function ( $views ) {
	$views['loyalty'] = 'my_customer_loyalty_view';
	return $views;
} );

Defined in includes/admin/customers/customers.php, line 47.

rpress_customer_tabs()#

Returns the registered customer admin tabs.

Applies the rpress_customer_tabs filter to an empty array.

rpress_customer_tabs()

Returns array: Tab slugs mapped to tab definitions.

Defined in includes/admin/customers/customers.php, line 57.

rpress_customers_list()#

Renders the Customers list table screen.

Fires rpress_customers_table_top and rpress_customers_table_bottom.

rpress_customers_list()

Internal. Defined in includes/admin/customers/customers.php, line 67.

rpress_render_customer_view()#

Renders the wrapper for a single customer admin view.

Checks the view_shop_reports capability (filterable with rpress_view_customers_role), loads the customer from the id query argument and calls the view callback. Fires rpress_after_customer_details_header.

rpress_render_customer_view( $view, $callbacks )

Parameters

ParameterTypeDefaultDescription
$viewstringRequiredRequested view slug.
$callbacksarrayRequiredRegistered views mapped to callbacks.

Internal. Defined in includes/admin/customers/customers.php, line 103.

rpress_customer_admin_get_payments()#

Returns a customer's orders sorted newest first for the admin screens.

rpress_customer_admin_get_payments( $customer, $limit = 10 )

Parameters

ParameterTypeDefaultDescription
$customerRPRESS_CustomerRequiredCustomer object.
$limitint10Maximum number of orders; 0 or less returns all.

Returns array: Order payment objects, or an empty array.

Internal. Defined in includes/admin/customers/customers.php, line 147.

rpress_customer_admin_get_address()#

Returns a customer's saved address for the admin profile.

Reads _rpress_user_address from the linked user, falling back to _rpress_user_delivery_address. Returns blank defaults when there is no linked user or address.

rpress_customer_admin_get_address( $customer )

Parameters

ParameterTypeDefaultDescription
$customerRPRESS_CustomerRequiredCustomer object.

Returns array: Array with line1, line2, city, state, country and zip.

Internal. Defined in includes/admin/customers/customers.php, line 164.

rpress_customer_admin_format_address()#

Formats an address array as a comma-separated string.

rpress_customer_admin_format_address( $address )

Parameters

ParameterTypeDefaultDescription
$addressarrayRequiredAddress with optional line1, line2, city, state, zip and country keys.

Returns string: The non-empty parts joined with commas, or an empty string.

Internal. Defined in includes/admin/customers/customers.php, line 199.

rpress_customer_admin_get_phone()#

Finds a phone number for a customer.

Uses the linked user's _rpress_phone meta, otherwise the first order payment meta that has a phone.

rpress_customer_admin_get_phone( $customer, $payments = array() )

Parameters

ParameterTypeDefaultDescription
$customerRPRESS_CustomerRequiredCustomer object.
$paymentsarrayarray()Order objects to search.

Returns string: The phone number, or an empty string.

Internal. Defined in includes/admin/customers/customers.php, line 214.

rpress_customer_admin_get_service_label()#

Returns the service type label of an order for the admin.

rpress_customer_admin_get_service_label( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder ID.

Returns string: The service label, or 'Not captured' when the order has none.

Internal. Defined in includes/admin/customers/customers.php, line 232.

rpress_customer_admin_get_order_status_tone()#

Maps an order status to a CSS tone class.

rpress_customer_admin_get_order_status_tone( $status )

Parameters

ParameterTypeDefaultDescription
$statusstringRequiredOrder status slug.

Returns string: One of is-warning, is-info, is-success or is-danger; is-info for unknown statuses.

Internal. Defined in includes/admin/customers/customers.php, line 237.

rpress_customer_admin_status_badge()#

Prints an order status badge.

rpress_customer_admin_status_badge( $payment )

Parameters

ParameterTypeDefaultDescription
$paymentobjectRequiredOrder payment object with an ID property.

Internal. Defined in includes/admin/customers/customers.php, line 253.

rpress_customer_admin_empty_state()#

Prints an empty-state block for the customer admin screens.

rpress_customer_admin_empty_state( $title, $description, $icon = 'dashicons-info' )

Parameters

ParameterTypeDefaultDescription
$titlestringRequiredHeading text.
$descriptionstringRequiredDescription text.
$iconstring'dashicons-info'Dashicons class.

Internal. Defined in includes/admin/customers/customers.php, line 269.

rpress_customer_admin_render_order_table()#

Prints a table of a customer's orders.

Fires rpress_customer_recent_purchases_actions for each row.

rpress_customer_admin_render_order_table( $customer, $payments, $compact = false )

Parameters

ParameterTypeDefaultDescription
$customerRPRESS_CustomerRequiredCustomer object.
$paymentsarrayRequiredOrder objects to list.
$compactboolfalseCompact layout flag (unused in the function body).

Internal. Defined in includes/admin/customers/customers.php, line 279.

rpress_customer_admin_render_menu_items()#

Prints a table of the menu items a customer has ordered.

rpress_customer_admin_render_menu_items( $customer )

Parameters

ParameterTypeDefaultDescription
$customerRPRESS_CustomerRequiredCustomer object.

Internal. Defined in includes/admin/customers/customers.php, line 321.

rpress_customer_admin_render_emails()#

Prints the customer's email addresses with their management actions.

rpress_customer_admin_render_emails( $customer )

Parameters

ParameterTypeDefaultDescription
$customerRPRESS_CustomerRequiredCustomer object.

Internal. Defined in includes/admin/customers/customers.php, line 353.

rpress_customer_admin_render_profile_form()#

Prints the customer profile edit form.

Fires rpress_after_customer_edit_link.

rpress_customer_admin_render_profile_form( $customer )

Parameters

ParameterTypeDefaultDescription
$customerRPRESS_CustomerRequiredCustomer object.

Internal. Defined in includes/admin/customers/customers.php, line 419.

rpress_customers_view()#

Renders the customer overview screen.

Fires rpress_customer_card_top, rpress_customer_before_stats, rpress_customer_stats_list, rpress_customer_before_tables_wrapper, rpress_customer_before_tables, rpress_customer_after_tables and rpress_customer_card_bottom.

rpress_customers_view( $customer )

Parameters

ParameterTypeDefaultDescription
$customerRPRESS_CustomerRequiredCustomer object.

Internal. Defined in includes/admin/customers/customers.php, line 536.

rpress_customer_orders_view()#

Renders the customer Orders tab.

rpress_customer_orders_view( $customer )

Parameters

ParameterTypeDefaultDescription
$customerRPRESS_CustomerRequiredCustomer object.

Internal. Defined in includes/admin/customers/customers.php, line 625.

rpress_customer_notes_view()#

Renders the customer Notes tab with the note form.

The page size is filterable with rpress_customer_notes_per_page (default 20).

rpress_customer_notes_view( $customer )

Parameters

ParameterTypeDefaultDescription
$customerRPRESS_CustomerRequiredCustomer object.

Internal. Defined in includes/admin/customers/customers.php, line 651.

rpress_customers_delete_view()#

Renders the customer Delete tab.

Fires rpress_customer_delete_top, rpress_customer_delete_inputs and rpress_customer_delete_bottom.

rpress_customers_delete_view( $customer )

Parameters

ParameterTypeDefaultDescription
$customerRPRESS_CustomerRequiredCustomer object.

Internal. Defined in includes/admin/customers/customers.php, line 811.

rpress_customer_tools_view()#

Renders the customer Tools tab.

Fires rpress_customer_tools_top and rpress_customer_tools_bottom.

rpress_customer_tools_view( $customer )

Parameters

ParameterTypeDefaultDescription
$customerRPRESS_CustomerRequiredCustomer object.

Internal. Defined in includes/admin/customers/customers.php, line 846.

rpress_verify_customer_notice()#

Prints a notice on the customer screen when the linked user is pending verification.

Hooked to rpress_customer_card_top.

rpress_verify_customer_notice( $customer )

Parameters

ParameterTypeDefaultDescription
$customerRPRESS_CustomerRequiredCustomer object.

Internal. Defined in includes/admin/customers/customers.php, line 882.

rpress_get_users_orders()#

Returns a user's orders, by user ID or email, optionally filtered by status and paginated.

Looks up the customer record and uses its order IDs when present. The status 'complete' is mapped to 'publish'; a comma-separated string or an array of statuses is accepted. The query arguments pass through the rpress_get_users_orders_args filter.

rpress_get_users_orders( $user = 0, $number = 20, $pagination = false, $status = 'complete' )

Parameters

ParameterTypeDefaultDescription
$userint|string0User ID or email address. 0 uses the current user.
$numberint20Number of orders to retrieve.
$paginationboolfalseWhether to use the paged query var for pagination; when false all matching orders are returned.
$statusstring|array'complete'Order status, a comma-separated list, or an array of statuses.

Returns WP_Post[]|false: Orders as returned by rpress_get_payments(), or false when there are none or no user can be determined.

Example

$orders = rpress_get_users_orders( get_current_user_id(), 10 );
if ( $orders ) {
	foreach ( $orders as $order ) {
		echo esc_html( $order->ID ) . "\n";
	}
}

Note: When pagination is false the $number limit is replaced by nopaging.

Defined in includes/user-functions.php, line 32.

rpress_get_users_ordered_products()#

Returns the unique menu items a user or customer has ordered.

Reads the customer's orders (filter rpress_users_purchased_products_payments sets the order limit) and fetches the matching fooditem posts. Query arguments pass through rpress_get_users_ordered_products_args; the result passes through rpress_users_purchased_products_list.

rpress_get_users_ordered_products( $user = 0, $status = 'complete' )

Parameters

ParameterTypeDefaultDescription
$userint|string0User ID or email address. 0 uses the current user.
$statusstring|array'complete'Order status to include.

Returns WP_Post[]|false: Array of fooditem posts, or false when none are found.

Example

$items = rpress_get_users_ordered_products( 'jane@example.com' );
if ( $items ) {
	foreach ( $items as $item ) {
		echo esc_html( $item->post_title ) . "\n";
	}
}

Defined in includes/user-functions.php, line 95.

rpress_has_purchases()#

Checks whether a user has at least one completed order.

rpress_has_purchases( $user_id = null )

Parameters

ParameterTypeDefaultDescription
$user_idint|nullnullUser ID. Defaults to the current user.

Returns bool: True if the user has an order.

Example

if ( is_user_logged_in() && rpress_has_purchases() ) {
	// Show reorder prompt.
}

Defined in includes/user-functions.php, line 173.

rpress_get_purchase_stats_by_user()#

Returns the order count and total spent for a customer, by user ID or email.

Result passes through the rpress_purchase_stats_by_user filter.

rpress_get_purchase_stats_by_user( $user = '' )

Parameters

ParameterTypeDefaultDescription
$userint|string''User ID or customer email address.

Returns array: Array with purchases and total_spent, or an empty array when no customer is found.

Example

$stats = rpress_get_purchase_stats_by_user( 'jane@example.com' );
if ( ! empty( $stats ) ) {
	echo $stats['purchases'] . ' orders, ' . $stats['total_spent'];
}

Note: If $user is neither an email nor numeric, the lookup field is undefined and a PHP notice is raised.

Defined in includes/user-functions.php, line 192.

rpress_count_purchases_of_customer()#

Returns the number of orders a customer has made.

rpress_count_purchases_of_customer( $user = null )

Parameters

ParameterTypeDefaultDescription
$userint|string|nullnullUser ID or email. Defaults to the current user.

Returns int: Order count, or 0.

Example

$count = rpress_count_purchases_of_customer( get_current_user_id() );

Defined in includes/user-functions.php, line 216.

rpress_purchase_total_of_user()#

Returns the total amount a customer has spent.

rpress_purchase_total_of_user( $user = null )

Parameters

ParameterTypeDefaultDescription
$userint|string|nullnullUser ID or email.

Returns float|string: The sanitized total spent from rpress_get_purchase_stats_by_user().

Example

$total = rpress_purchase_total_of_user( 'jane@example.com' );

Note: Reads the total_spent key without checking it, so an unknown customer raises a PHP notice and returns null. Unlike related functions it does not default to the current user.

Defined in includes/user-functions.php, line 230.

rpress_count_file_fooditems_of_user()#

Counts file download log entries for a user or, given an email, a customer.

Queries the $rpress_logs global for the file_fooditem log type.

rpress_count_file_fooditems_of_user( $user )

Parameters

ParameterTypeDefaultDescription
$userint|stringRequiredUser ID or email address.

Returns int: The log count.

Note: Inherited from the file-download feature; RestroPress sells menu items, so the count is normally 0.

Internal. Defined in includes/user-functions.php, line 241.

rpress_count_file_fooditems_of_customer()#

Counts file download log entries for a customer.

Queries the $rpress_logs global for the file_fooditem log type.

rpress_count_file_fooditems_of_customer( $customer_id_or_email = '' )

Parameters

ParameterTypeDefaultDescription
$customer_id_or_emailstring|int''Customer ID or email address.

Returns int: The log count.

Note: Inherited from the file-download feature; the count is normally 0.

Internal. Defined in includes/user-functions.php, line 263.

rpress_validate_username()#

Checks whether a string is valid as a username without being altered by sanitizing.

Compares the value to sanitize_user() output. The result passes through the rpress_validate_username filter.

rpress_validate_username( $username )

Parameters

ParameterTypeDefaultDescription
$usernamestringRequiredUsername to validate.

Returns bool: True if the username is valid.

Example

if ( ! rpress_validate_username( $login ) ) {
	rpress_set_error( 'username_invalid', 'Invalid username.' );
}

Defined in includes/user-functions.php, line 281.

rpress_connect_guest_customer_to_existing_user()#

Links a guest customer to an existing WordPress user with the same email and sends a verification email.

Hooked to rpress_customer_post_attach_payment. Does nothing when the customer already has a user or no user matches the email. Otherwise it updates the customer, marks the user pending and sends the verification email.

rpress_connect_guest_customer_to_existing_user( $success, $payment_id, $customer_id, $customer )

Parameters

ParameterTypeDefaultDescription
$successboolRequiredWhether the order was attached.
$payment_idintRequiredOrder ID.
$customer_idintRequiredCustomer ID.
$customerRPRESS_CustomerRequiredCustomer object.

Internal. Defined in includes/user-functions.php, line 301.

rpress_connect_existing_customer_to_new_user()#

Links a newly registered user to an existing customer with the same email.

Hooked to user_register.

rpress_connect_existing_customer_to_new_user( $user_id )

Parameters

ParameterTypeDefaultDescription
$user_idintRequiredNew user ID.

Internal. Defined in includes/user-functions.php, line 322.

rpress_add_past_purchases_to_new_user()#

Attaches earlier guest orders to a newly registered user matching the order email.

Hooked to user_register. When orders match, the user is set to pending verification, a verification email is sent and orders without a user are assigned to the new user.

rpress_add_past_purchases_to_new_user( $user_id )

Parameters

ParameterTypeDefaultDescription
$user_idintRequiredNew user ID.

Internal. Defined in includes/user-functions.php, line 341.

rpress_count_total_customers()#

Returns the total number of customers.

Delegates to RPRESS()->customers->count().

rpress_count_total_customers( $args = array() )

Parameters

ParameterTypeDefaultDescription
$argsarrayarray()Count arguments passed to the customers database class.

Returns int: Customer count.

Example

$total = rpress_count_total_customers();

Defined in includes/user-functions.php, line 371.

rpress_count_total_customers_by_date_range()#

Counts distinct customers with published orders in a date range.

Counts distinct _rpress_payment_customer_id values on published rpress_payment posts between the two dates. Dates default to the current calendar year.

rpress_count_total_customers_by_date_range( $start_date = '', $end_date = '' )

Parameters

ParameterTypeDefaultDescription
$start_datestring''Start date, such as 2025-01-01. Defaults to January 1 of this year.
$end_datestring''End date. Defaults to December 31 of this year.

Returns string|null: The count as returned by wpdb::get_var().

Example

$count = rpress_count_total_customers_by_date_range( '2025-01-01', '2025-03-31' );

Note: The result is a numeric string, and a date-only end date excludes orders placed later that day.

Defined in includes/user-functions.php, line 383.

rpress_count_new_customers_by_date_range()#

Counts customers created in a date range who have at least one order.

Counts rows in the customers table with date_created between the dates and purchase_count above 0.

rpress_count_new_customers_by_date_range( $start_date, $end_date )

Parameters

ParameterTypeDefaultDescription
$start_datestringRequiredStart date/time.
$end_datestringRequiredEnd date/time.

Returns string|null: The count as returned by wpdb::get_var().

Example

$new = rpress_count_new_customers_by_date_range( '2025-01-01 00:00:00', '2025-01-31 23:59:59' );

Defined in includes/user-functions.php, line 422.

rpress_get_customer_address()#

Returns the saved address of a user.

Reads the _rpress_user_address user meta and fills missing keys with empty strings.

rpress_get_customer_address( $user_id = 0 )

Parameters

ParameterTypeDefaultDescription
$user_idint0User ID. 0 uses the current user.

Returns array: Array with line1, line2, city, zip, country and state.

Example

$address = rpress_get_customer_address( get_current_user_id() );
echo esc_html( $address['city'] );

Defined in includes/user-functions.php, line 442.

rpress_new_user_notification()#

Sends the new account emails to the site admin and the new user.

Hooked to rpress_insert_user. Uses the RestroPress email class and filters such as rpress_user_registration_admin_email_subject and rpress_user_registration_email_message. The password is not included.

rpress_new_user_notification( $user_id = 0, $user_data = array() )

Parameters

ParameterTypeDefaultDescription
$user_idint0New user ID.
$user_dataarrayarray()User data with user_login and user_email.

Internal. Defined in includes/user-functions.php, line 472.

rpress_set_user_to_pending()#

Marks a user as pending email verification.

Sets the _rpress_pending_verification user meta. Fires rpress_pre_set_user_to_pending and rpress_post_set_user_to_pending. Pending users cannot view order history.

rpress_set_user_to_pending( $user_id = 0 )

Parameters

ParameterTypeDefaultDescription
$user_idint0User ID.

Returns bool: True if the meta was updated; false for an empty ID or no change.

Example

rpress_set_user_to_pending( $user_id );

Defined in includes/user-functions.php, line 568.

rpress_set_user_to_verified()#

Clears a user's pending verification status.

Deletes the _rpress_pending_verification user meta and fires rpress_pre_set_user_to_active and rpress_post_set_user_to_active.

rpress_set_user_to_verified( $user_id = 0 )

Parameters

ParameterTypeDefaultDescription
$user_idint0User ID.

Returns bool: True if the user was verified; false if the ID is empty, the user was not pending, or the delete failed.

Example

rpress_set_user_to_verified( $user_id );

Defined in includes/user-functions.php, line 584.

rpress_user_pending_verification()#

Checks whether a user account is pending verification.

Result passes through the rpress_user_pending_verification filter.

rpress_user_pending_verification( $user_id = null )

Parameters

ParameterTypeDefaultDescription
$user_idint|nullnullUser ID. Defaults to the current user.

Returns bool: True if the account is pending; false for an empty ID.

Example

if ( rpress_user_pending_verification() ) {
	echo 'Please verify your email address.';
}

Defined in includes/user-functions.php, line 602.

rpress_get_user_verification_url()#

Builds the signed account verification URL for a user.

The URL points to the order history page (or home URL) with rpress_action=verify_user, the user ID, a 24 hour ttl and a token. Passes through rpress_get_user_verification_url.

rpress_get_user_verification_url( $user_id = 0 )

Parameters

ParameterTypeDefaultDescription
$user_idint0User ID.

Returns string|false: The URL, or false if no user ID is given.

Example

$url = rpress_get_user_verification_url( $user_id );

Defined in includes/user-functions.php, line 619.

rpress_get_user_verification_request_url()#

Returns the nonce URL that asks for a new verification email.

Adds rpress_action=send_verification_email to the current URL. Passes through rpress_get_user_verification_request_url.

rpress_get_user_verification_request_url( $user_id = 0 )

Parameters

ParameterTypeDefaultDescription
$user_idint0User ID; defaults to the current user and is only passed to the filter.

Returns string: The escaped URL.

Defined in includes/user-functions.php, line 641.

rpress_send_user_verification_email()#

Emails a user the link to verify their account.

Does nothing if the ID is empty, the user is not pending verification, or the user does not exist. Filters: rpress_user_verification_email_subject, rpress_user_verification_email_heading and rpress_user_verification_email_message.

rpress_send_user_verification_email( $user_id = 0 )

Parameters

ParameterTypeDefaultDescription
$user_idint0User ID.

Example

rpress_set_user_to_pending( $user_id );
rpress_send_user_verification_email( $user_id );

Note: The user must already be marked pending, otherwise no email is sent.

Defined in includes/user-functions.php, line 663.

rpress_get_user_verification_token()#

Generates the signature token for a verification URL.

Hashes the URL path and query together with a secret derived from wp_salt(). The 'o' query argument can bind the token to 'ip' and/or 'ua'. Filters: rpress_get_user_verification_token_algorithm, rpress_get_user_verification_token_secret, rpress_get_user_verification_token_args.

rpress_get_user_verification_token( $url = '' )

Parameters

ParameterTypeDefaultDescription
$urlstring''URL to generate a token for.

Returns string: The token (an MD5 hash).

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

rpress_validate_user_verification_token()#

Checks a verification URL's token and expiry.

If the ttl has passed, fires rpress_user_verification_token_expired and ends the request with a 403 message. Result passes through rpress_validate_user_verification_token.

rpress_validate_user_verification_token( $url = '' )

Parameters

ParameterTypeDefaultDescription
$urlstring''Full URL with token and ttl query arguments.

Returns bool: True if the token matches.

Note: Calls wp_die() when the link has expired.

Defined in includes/user-functions.php, line 762.

rpress_process_user_verification_request()#

Handles the request to resend the verification email.

Hooked to rpress_send_verification_email. Verifies the rpress-request-verification nonce, requires a logged-in, still pending user, sends the email and redirects. The redirect is filterable with rpress_user_account_verification_request_redirect.

rpress_process_user_verification_request()

Internal. Defined in includes/user-functions.php, line 790.

rpress_process_user_account_verification()#

Handles the verification link click and marks the user verified.

Hooked to rpress_verify_user. Validates the token, calls rpress_set_user_to_verified(), fires rpress_user_verification_token_validated (or rpress_invalid_user_verification_token), and redirects using rpress_user_account_verified_redirect.

rpress_process_user_account_verification()

Internal. Defined in includes/user-functions.php, line 816.

rpress_get_user_verification_page()#

Returns the base URL used for account verification links.

Uses the permalink of the order_history_page option, falling back to home_url(). Passes through rpress_user_verification_base_url.

rpress_get_user_verification_page()

Returns string: The base URL.

Defined in includes/user-functions.php, line 849.

rpress_detach_deleted_user()#

Detaches a deleted WordPress user from its customer record.

Hooked to delete_user. Sets the customer's user_id to 0 and fires rpress_detach_deleted_user.

rpress_detach_deleted_user( $user_id )

Parameters

ParameterTypeDefaultDescription
$user_idintRequiredID of the user being deleted.

Returns bool: True if a customer was updated.

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

rpress_user_api_keys_display()#

Prints the API keys section of a user profile.

Prints the key generation checkbox or the keys table, depending on whether keys exist.

rpress_user_api_keys_display( WP_User $profile )

Parameters

ParameterTypeDefaultDescription
$profileWP_UserRequiredUser being edited.

Note: Output is passed through esc_html(), so the table markup is shown as escaped text rather than rendered HTML.

Internal. Defined in includes/user-functions.php, line 880.

rpress_user_api_key_not_generated()#

Builds the Generate API keys checkbox markup for a user profile.

rpress_user_api_key_not_generated( WP_User $profile )

Parameters

ParameterTypeDefaultDescription
$profileWP_UserRequiredUser being edited.

Returns string|null: HTML string, or null if keys already exist.

Internal. Defined in includes/user-functions.php, line 894.

rpress_get_user_all_api_keys()#

Builds the API keys table markup for a user profile.

Shows the private key, public key and token stored in user meta with revoke and refresh checkboxes.

rpress_get_user_all_api_keys( WP_User $profile )

Parameters

ParameterTypeDefaultDescription
$profileWP_UserRequiredUser being edited.

Returns string|null: HTML string, or null if no keys were generated.

Internal. Defined in includes/user-functions.php, line 916.

restropress_update_user_api_key()#

Generates, revokes or refreshes a user's API keys when the profile is saved.

Hooked to personal_options_update and edit_user_profile_update. Reads rp-generate-api-key, rp-api-revoke-keys and rp-api-refresh-keys from $_POST.

restropress_update_user_api_key( int $user_ID )

Parameters

ParameterTypeDefaultDescription
$user_IDintRequiredID of the user being saved.

Internal. Defined in includes/user-functions.php, line 971.

rp_generate_api_secret()#

Generates a random hex API secret.

Uses random_bytes(), falling back to wp_generate_password().

rp_generate_api_secret( int $bytes = 32 )

Parameters

ParameterTypeDefaultDescription
$bytesint32Number of random bytes.

Returns string: A hex string, twice as long as $bytes.

Example

$secret = rp_generate_api_secret( 16 );

Defined in includes/user-functions.php, line 991.

rp_build_user_api_token()#

Builds a signed HS512 JWT for a user's API key.

The payload holds the site host, issue time, a unique ID and the API key and user ID. Expiry comes from the api_expire option when set. The payload passes through rp_api_token_generate_data.

rp_build_user_api_token( string $api_key, int $user_ID )

Parameters

ParameterTypeDefaultDescription
$api_keystringRequiredPublic API key used as the signing key.
$user_IDintRequiredUser ID.

Returns string|WP_Error: The JWT, or a WP_Error with code rp_api_invalid_token_data or rp_api_token_generation_failed.

Internal. Defined in includes/user-functions.php, line 1008.

rp_generate_api_keys()#

Generates API keys for a user when the profile form requested it.

Acts only when rp-generate-api-key is posted. Creates a public key and a private key and stores them with a token.

rp_generate_api_keys( int $user_ID )

Parameters

ParameterTypeDefaultDescription
$user_IDintRequiredUser ID.

Internal. Defined in includes/user-functions.php, line 1064.

rp_user_api_get_token()#

Builds a token and stores the user's API keys in user meta.

Saves _rp_api_user_private_key, _rp_api_user_public_key, _rp_api_user_token_key and _rp_api_keys_generated. Nothing is saved if the token cannot be built.

rp_user_api_get_token( string $private_key, string $public_key, int $user_ID )

Parameters

ParameterTypeDefaultDescription
$private_keystringRequiredPrivate key.
$public_keystringRequiredPublic key.
$user_IDintRequiredUser ID.

Internal. Defined in includes/user-functions.php, line 1083.

rp_user_api_revoke()#

Deletes all of a user's stored API keys.

Deletes the _rp_api_user_private_key, _rp_api_user_public_key, _rp_api_user_token_key and _rp_api_keys_generated user meta.

rp_user_api_revoke( int $user_ID )

Parameters

ParameterTypeDefaultDescription
$user_IDintRequiredUser ID.

Internal. Defined in includes/user-functions.php, line 1105.

rp_user_api_refresh()#

Issues a new public key and token for a user, keeping the private key.

rp_user_api_refresh( int $user_ID )

Parameters

ParameterTypeDefaultDescription
$user_IDintRequiredUser ID.

Internal. Defined in includes/user-functions.php, line 1120.

rpress_get_lostpassword_url()#

Returns the URL of the RestroPress forgot-password page.

Uses the page with slug forgot-password, falling back to site_url('/forgot-password'). A redirect is appended as redirect_to. Passes through rpress_get_lostpassword_url.

rpress_get_lostpassword_url( $redirect = '' )

Parameters

ParameterTypeDefaultDescription
$redirectstring''URL to return to after the reset.

Returns string: The lost password URL.

Example

$url = rpress_get_lostpassword_url( home_url( '/order-history/' ) );

Defined in includes/user-functions.php, line 1138.

rpress_filter_lostpassword_url()#

Replaces the WordPress lost password URL with the RestroPress one.

Hooked to lostpassword_url.

rpress_filter_lostpassword_url( $lostpassword_url, $redirect = '' )

Parameters

ParameterTypeDefaultDescription
$lostpassword_urlstringRequiredDefault WordPress URL (ignored).
$redirectstring''Redirect URL.

Returns string: The URL from rpress_get_lostpassword_url().

Internal. Defined in includes/user-functions.php, line 1163.

Was this page helpful?