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/.
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".
Return Return
(string)
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;
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 6.3.0 | Introduced. |