Skip to content
Docs
Get RestroPress

Function

Account pages functions

Updated
On this page

Functions for the customer account added or changed in RestroPress 3.5.1: section URLs, order cards, account templates and the order history list.

26 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_account_sections()#

Returns the customer account sections in sidebar order.

Core sections are profile, orders and addresses, and extensions can add or change them through the rpress_account_sections filter. Each entry has label, icon, endpoint, callback, visible and legacy_id, with missing keys filled with defaults; slugs pass through the rpress_account_endpoints filter. Hidden sections are included, so check them with rpress_account_section_visible().

rpress_account_sections()

Returns array: Section ID => section settings.

Example

add_filter( 'rpress_account_sections', function ( $sections ) {
	$sections['myplugin_rewards'] = array(
		'label'    => 'Rewards',
		'endpoint' => 'rewards',
		'callback' => function () {
			echo '<p>Your rewards.</p>';
		},
	);
	return $sections;
} );

$all = rpress_account_sections();

Defined in includes/features/account/loader.php, line 33.

rpress_account_filter_slugs()#

Returns the URL slug of each account section after filtering.

Collects the non-empty endpoint values, applies the rpress_account_endpoints filter, runs each slug through sanitize_title() and drops empty results.

rpress_account_filter_slugs( $sections )

Parameters

ParameterTypeDefaultDescription
$sectionsarrayRequiredRaw sections keyed by section ID.

Returns array: Section ID => slug.

Internal. Defined in includes/features/account/loader.php, line 91.

rpress_account_endpoints()#

Returns the URL slug of every account section that has its own URL.

The default Profile section has no slug unless a filter gives it one.

rpress_account_endpoints()

Returns array: Section ID => slug.

Defined in includes/features/account/loader.php, line 113.

rpress_account_register_endpoints()#

Registers the rewrite rule for account section URLs under the account page.

Runs on init. It also flushes the rewrite rules when the slugs, the account page, its path or the plugin version change, tracked in the rpress_account_endpoints_hash option.

rpress_account_register_endpoints()

Internal. Defined in includes/features/account/loader.php, line 127.

rpress_account_query_vars()#

Adds rpress_account_section to the public query vars.

rpress_account_query_vars( $vars )

Parameters

ParameterTypeDefaultDescription
$varsarrayRequiredPublic query vars.

Returns array: Query vars.

Internal. Defined in includes/features/account/loader.php, line 152.

rpress_account_page_id()#

Returns the ID of the published customer dashboard page.

Searches published pages for the [rpress_customer_dashboard] shortcode or the old [customer_dashboard] name, preferring the new one, then the lowest ID. The lookup is cached in a transient for a day and the result is filtered by rpress_account_page_id.

rpress_account_page_id()

Returns int: Page ID, or 0 when none is found.

Defined in includes/features/account/loader.php, line 165.

rpress_account_clear_page_cache()#

Clears the cached account page ID when a page is saved or deleted.

Hooked to save_post and before_delete_post; ignores other post types.

rpress_account_clear_page_cache( $post_id )

Parameters

ParameterTypeDefaultDescription
$post_idintRequiredPost ID.

Internal. Defined in includes/features/account/loader.php, line 188.

rpress_account_page_url()#

Returns the URL of the customer account page.

Filtered by rpress_account_page_url.

rpress_account_page_url()

Returns string: URL, or an empty string when there is no account page.

Defined in includes/features/account/loader.php, line 202.

rpress_account_url()#

Returns the URL of a customer account section.

Uses a pretty URL for the main account page when permalinks allow it. With plain permalinks, on the front page, or for another dashboard page, the slug is added as a query argument. A section without a slug returns the base page URL. Filtered by rpress_account_url.

rpress_account_url( $section = 'profile', $page_id = 0 )

Parameters

ParameterTypeDefaultDescription
$sectionstring'profile'Section ID, such as profile, orders, addresses or reservations.
$page_idint0Account page to build on. 0 uses the detected customer dashboard page.

Returns string: URL, or an empty string when the page has no URL or does not exist.

Example

$orders_url = rpress_account_url( 'orders' );
if ( $orders_url ) {
	echo '<a href="' . esc_url( $orders_url ) . '">My orders</a>';
}

Defined in includes/features/account/loader.php, line 216.

rpress_account_current_section()#

Returns the ID of the account section requested on the current page.

Matches the rpress_account_section query var or a query-string key against the section slugs. Falls back to the first section when nothing matches or the matched section is hidden.

rpress_account_current_section()

Returns string: Section ID.

Defined in includes/features/account/loader.php, line 246.

rpress_account_section_visible()#

Checks whether an account section is visible to the current customer.

The section's visible value may be a boolean or a callable; a missing value counts as visible.

rpress_account_section_visible( $section )

Parameters

ParameterTypeDefaultDescription
$sectionarrayRequiredSection settings array, not the section ID.

Returns bool

Example

$sections = rpress_account_sections();
if ( isset( $sections['orders'] ) && rpress_account_section_visible( $sections['orders'] ) ) {
	$url = rpress_account_url( 'orders' );
}

Defined in includes/features/account/loader.php, line 268.

rpress_account_sidebar()#

Outputs the account sidebar links for the visible sections.

Prints one list item per section and marks the current one as active. The surrounding list element is not printed.

rpress_account_sidebar( $current, $page_id )

Parameters

ParameterTypeDefaultDescription
$currentstringRequiredCurrent section ID.
$page_idintRequiredAccount page ID used to build the links.

Note: Echoes output.

Internal. Defined in includes/features/account/loader.php, line 283.

rpress_account_render_section()#

Outputs one account section by calling its callback.

The callback receives the section ID. Nothing happens for an unknown ID or a callback that is not callable. Visibility is not checked here.

rpress_account_render_section( $id )

Parameters

ParameterTypeDefaultDescription
$idstringRequiredSection ID.

Example

if ( is_user_logged_in() ) {
	rpress_account_render_section( 'orders' );
}

Note: Echoes output.

Defined in includes/features/account/loader.php, line 306.

rpress_account_template()#

Loads an account template and makes the given variables available to it.

Looks up account/<name>.php through the RestroPress template loader, so a theme can override it at restropress/account/<name>.php. Array keys become local variables in the template.

rpress_account_template( $name, $args = array() )

Parameters

ParameterTypeDefaultDescription
$namestringRequiredTemplate name without the .php extension.
$argsarrayarray()Variables for the template.

Example

if ( is_user_logged_in() ) {
	rpress_account_template( 'orders' );
}

Note: Echoes whatever the template prints.

Defined in includes/features/account/loader.php, line 320.

rpress_account_render_profile()#

Outputs the Profile account section.

Default callback for the profile section.

rpress_account_render_profile()

Note: Echoes output.

Internal. Defined in includes/features/account/loader.php, line 330.

rpress_account_render_orders()#

Outputs the Orders account section.

Default callback for the orders section.

rpress_account_render_orders()

Note: Echoes output.

Internal. Defined in includes/features/account/loader.php, line 335.

rpress_account_render_addresses()#

Outputs the Addresses account section.

Default callback for the addresses section.

rpress_account_render_addresses()

Note: Echoes output.

Internal. Defined in includes/features/account/loader.php, line 340.

rpress_account_legacy_hash_map()#

Returns a map of old account panel IDs to section URLs.

Used by the dashboard template so that old hash links open the matching section.

rpress_account_legacy_hash_map( $page_id )

Parameters

ParameterTypeDefaultDescription
$page_idintRequiredAccount page ID.

Returns array: Legacy panel ID => section URL.

Internal. Defined in includes/features/account/loader.php, line 352.

rpress_account_orders_per_page()#

Returns the number of orders shown per page in the customer order lists.

Defaults to 10, with a minimum of 1. Filtered by rpress_account_orders_per_page.

rpress_account_orders_per_page()

Returns int

Defined in includes/features/account/orders.php, line 20.

rpress_account_orders_query()#

Queries a customer's orders, newest first.

Uses the order IDs linked to the user's customer record. When the record is missing or has no orders, it selects orders authored by the user. Orders of any status registered for any queries are requested, and the arguments are filtered by rpress_account_orders_query_args.

rpress_account_orders_query( $user_id, $paged = 1 )

Parameters

ParameterTypeDefaultDescription
$user_idintRequiredUser ID.
$pagedint1Page number.

Returns WP_Query: Query of rpress_payment posts.

Example

$user_id = get_current_user_id();
if ( $user_id ) {
	$query = rpress_account_orders_query( $user_id, 1 );
	$ids   = wp_list_pluck( $query->posts, 'ID' );
}

Note: Pass the ID of a logged-in customer, for example get_current_user_id() after an is_user_logged_in() check.

Defined in includes/features/account/orders.php, line 34.

rpress_account_order_summary()#

Returns a short list of the items on an order and the count of lines not listed.

Each listed line shows the quantity and the item name taken from the order's cart details.

rpress_account_order_summary( $payment_id, $max = 2 )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.
$maxint2Maximum number of lines to list.

Returns array: lines (string[] of quantity and name) and more (int, remaining line count).

Example

$summary = rpress_account_order_summary( $payment_id, 3 );
echo esc_html( implode( ', ', $summary['lines'] ) );

Defined in includes/features/account/orders.php, line 71.

rpress_account_order_card()#

Outputs the card for one order.

Gathers status, service, item summary, tracking and reorder data, then loads the account/order-card template. Prints nothing if the order does not exist.

rpress_account_order_card( $payment_id, $context = 'account' )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.
$contextstring'account'account (dashboard Orders section) or history (order history list).

Example

$user_id = get_current_user_id();
if ( $user_id && (int) rpress_get_payment_user_id( $payment_id ) === $user_id ) {
	rpress_account_order_card( $payment_id );
}

Note: Echoes output. Pass only orders that belong to the current customer, for example orders returned by rpress_account_orders_query().

Defined in includes/features/account/orders.php, line 96.

rpress_account_service_label()#

Returns the customer-facing name of a service type.

Uses rpress_service_label() when it returns a non-empty string; otherwise the key is capitalized with dashes and underscores replaced by spaces.

rpress_account_service_label( $service )

Parameters

ParameterTypeDefaultDescription
$servicestringRequiredService type key.

Returns string: Label, or an empty string for an empty key.

Example

echo esc_html( rpress_account_service_label( 'delivery' ) );

Defined in includes/features/account/orders.php, line 135.

rpress_account_order_cards()#

Outputs one page of order cards for the current user.

In the history context it fires rpress_order_history_row_start with the payment ID and payment meta before each card.

rpress_account_order_cards( $paged, $context )

Parameters

ParameterTypeDefaultDescription
$pagedintRequiredPage number.
$contextstringRequiredaccount (dashboard Orders section) or history (order history list).

Returns array: count (cards on this page), total (all matching orders) and has_more (bool).

Example

if ( is_user_logged_in() ) {
	$result = rpress_account_order_cards( 1, 'account' );
	if ( $result['has_more'] ) {
		rpress_account_orders_load_more_button( 'account' );
	}
}

Note: Echoes the cards. Call it for a logged-in customer.

Defined in includes/features/account/orders.php, line 156.

rpress_account_orders_load_more_button()#

Outputs the "Load more orders" button for an order card list.

rpress_account_orders_load_more_button( $context )

Parameters

ParameterTypeDefaultDescription
$contextstringRequiredaccount or history.

Note: Echoes output.

Internal. Defined in includes/features/account/orders.php, line 178.

rpress_account_unhook_hub_card_actions()#

Removes the account hub's own order action links from the order lists.

Runs on init. Unhooks rpress_account_hub_tracking_link from rpress_order_after_view_details and rpress_account_hub_dashboard_order_actions from rpress_user_dashboard_order_actions; the hooks themselves remain.

rpress_account_unhook_hub_card_actions()

Internal. Defined in includes/features/account/orders.php, line 190.

Was this page helpful?