Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_llms_normalize_endpoint_base_url( string $url, string $endpoint )

Normalize the endpoint base URL.


Description Description

E.g., in the BuddyPress profile’s tab, on my grades, page 2, it’ll look like //example.com/members/admin/courses/my-courses/page/2/

We then need to normalize the endpoint base URL, which means removing /my-courses/ (the endpoint) and the pagination information /page/2/.


Top ↑

Parameters Parameters

$url

(string) (Required) URL to extract the Base URL, to append the endpoint to, from.

$endpoint

(string) (Required) Slug of the endpoint, eg "my-courses".


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/functions/llms.functions.page.php

function _llms_normalize_endpoint_base_url( $url, $endpoint ) {

	$_url = untrailingslashit( $url );

	// Remove pagination.
	global $wp_rewrite;
	$page       = llms_get_paged_query_var();
	$pagination = '/' . $wp_rewrite->pagination_base . '/' . $page;

	if ( $page > 1 && substr( $_url, -1 * strlen( $pagination ) ) === $pagination ) { // PHP8: str_ends_with(string $haystack, string $needle).
		$_url = substr( $_url, 0, -1 * strlen( $pagination ) );
	}

	// Remove the endpoint slug from the URL if it's its last part.
	if ( substr( $_url, -1 * strlen( $endpoint ) ) === $endpoint ) { // PHP8: str_ends_with(string $haystack, string $needle).
		$url = substr( $_url, 0, -1 * strlen( $endpoint ) );
	}

	return $url;

}


Top ↑

Changelog Changelog

Changelog
Version Description
6.3.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.