Tribe__REST__Main::get_url( string $path = '/', string $scheme = 'rest', int $blog_id = null )
Retrieves the URL to a TEC REST endpoint on a site.
Contents
Note: The returned URL is NOT escaped.
Parameters
- $path
-
(string) (Optional) TEC REST route.
Default value: '/'
- $scheme
-
(string) (Optional) Sanitization scheme.
Default value: 'rest'
- $blog_id
-
(int) (Optional) Blog ID. Default of null returns URL for current blog.
Default value: null
Return
(string) Full URL to the endpoint.
Source
File: src/Tribe/REST/Main.php
public function get_url( $path = '/', $scheme = 'rest', $blog_id = null ) {
if ( empty( $path ) ) {
$path = '/';
}
$tec_path = '/' . trim( $this->namespace, '/' ) . $this->url_prefix() . '/' . ltrim( $path, '/' );
if ( $this->use_builtin() ) {
$url = get_rest_url( $blog_id, $tec_path, $scheme );
} else {
if ( ( is_multisite() && get_blog_option( $blog_id, 'permalink_structure' ) ) || get_option( 'permalink_structure' ) ) {
global $wp_rewrite;
if ( $wp_rewrite->using_index_permalinks() ) {
$url = get_home_url( $blog_id, $wp_rewrite->index . '/' . self::get_url_prefix(), $scheme );
} else {
$url = get_home_url( $blog_id, self::get_url_prefix(), $scheme );
}
$url .= '/' . ltrim( $path, '/' );
} else {
$url = get_home_url( $blog_id, 'index.php', $scheme );
$url = add_query_arg( 'rest_route', $tec_path, $url );
}
if ( is_ssl() ) {
// If the current host is the same as the REST URL host, force the REST URL scheme to HTTPS.
if ( $_SERVER['SERVER_NAME'] === parse_url( get_home_url( $blog_id ), PHP_URL_HOST ) ) {
$url = set_url_scheme( $url, 'https' );
}
}
}
/**
* Filters The Events Calendar REST URL.
*
* @param string $url TEC REST URL.
* @param string $path REST route.
* @param int $blog_id Blog ID.
* @param string $scheme Sanitization scheme.
*/
return apply_filters( 'tribe_rest_url', $url, $path, $blog_id, $scheme );
}