llms_get_endpoint_url( string $endpoint, string $value = '', string $permalink = '' )
Retrieve the full URL to a LifterLMS endpoint.
Parameters Parameters
- $endpoint
-
(string) (Required) ID of the endpoint, eg "view-courses".
- $value
-
(string) (Optional) Endpoint query parameter value.
Default value: ''
- $permalink
-
(string) (Optional) Base URL to append the endpoint to. Optional, uses the current page when not supplied.
Default value: ''
Return Return
(string)
Source Source
File: includes/functions/llms.functions.page.php
function llms_get_endpoint_url( $endpoint, $value = '', $permalink = '' ) {
// Map endpoint to options.
$vars = llms()->query->get_query_vars();
$endpoint = $vars[ $endpoint ] ?? $endpoint;
/**
* In our dashboard endpoints, get_permalink() always returns the dashboard page permalink:
* something like https://example.com/dashboard/
* which is the base URL to append the endpoint to.
*/
$permalink = $permalink ? $permalink : get_permalink();
$is_base_permalink = true;
/**
* No permalink available, e.g. in BuddyPress profile endpoint.
*
* We need to get the base URL to append the endpoint to, starting from
* the current requested URL.
*/
if ( ! $permalink && ! empty( $_SERVER['REQUEST_URI'] ) ) {
$permalink = home_url( filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_URL ) );
$is_base_permalink = false;
}
if ( get_option( 'permalink_structure' ) ) {
$query_string = '';
if ( false !== strpos( $permalink, '?' ) ) {
$query_string = '?' . wp_parse_url( $permalink, PHP_URL_QUERY );
$permalink = current( explode( '?', $permalink ) );
}
/**
* Normalize the permalink when not referring to the base URL.
*/
if ( ! $is_base_permalink ) {
$permalink = _llms_normalize_endpoint_base_url( $permalink, $endpoint );
}
$url = trailingslashit( $permalink );
if ( $value ) {
$url .= trailingslashit( $endpoint ) . user_trailingslashit( $value );
} else {
$url .= user_trailingslashit( $endpoint );
}
$url .= $query_string;
} else {
$url = add_query_arg( $endpoint, $value, $permalink );
}
/**
* Filter the final endpoint URL.
*
* @since 1.0.0
* @since 5.9.0 Added `$value` and `$permalink` parameters.
*
* @param string $url The endpoint URL.
* @param string $endpoint ID of the endpoint.
* @param string $value Endpoint query parameter value.
* @param string $permalink Base URL to append the endpoint to. Optional, uses the current page when not supplied.
*/
return apply_filters( 'lifterlms_get_endpoint_url', $url, $endpoint, $value, $permalink );
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 6.3.0 | Try to build the correct URL even when get_permalink() returns an empty string (e.g. in BuddyPress profile endpoints). Prefer faster strpos() over strstr() since we only need to know if a substring is contained in a string. |
| 5.9.0 | Update to ensure the generated URL has (or doesn't have) a trailing slash based on the site's permalink settings. |
| 3.26.3 | Unknown. |
| 1.0.0 | Introduced. |