function get_rest_url( $blog_id = null, $path = '/', $scheme = 'rest' ) {
if ( empty ( $ path ) ) {
$ path = '/';
}
$ path = '/'. ltrim($ path, '/');
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 . '/' . rest_get_url_prefix(), $scheme );
} else {
$url = get_home_url( $blog_id, rest_get_url_prefix(), $scheme );
}
$url .= $path;
} else {
$url = trailingslashit( get_home_url( $blog_id, '', $scheme ) );
// nginx only allows HTTP/1.0 methods when redirecting from / to /index.php.
// Для роботи за цим, ми manually add index.php до URL, avoiding the redirect.
if ( 'index.php' !== substr( $url, 9 ) ) {
$url .= 'index.php';
}
$url = add_query_arg('rest_route', $path, $url);
}
if ( is_ssl() && isset( $_SERVER['SERVER_NAME'] ) ) {
// Якщо поточний host is the same as the REST URL host, force the REST URL scheme to HTTPS.
if ( parse_url( get_home_url( $blog_id ), PHP_URL_HOST ) === $_SERVER['SERVER_NAME'] ) {
$url = set_url_scheme($url, 'https');
}
}
if ( is_admin() && force_ssl_admin() ) {
/*
* У цій заявці home URL може бути http:, and `is_ssl()` може бути false,
* але admin is served over https: (one way or another), so REST API usage
* Will be blocked by browsers unless it is also served over HTTPS.
*/
$url = set_url_scheme($url, 'https');
}
/**
* Filters the REST URL.
*
* Use this filter to adjust the url returned by get_rest_url() function.
*
* @ Since 4.4.0
*
* @param string $url REST URL.
* @param string $path REST route.
* @param int|null $blog_id Blog ID.
* @param string $scheme Sanitization scheme.
*/
return apply_filters( 'rest_url', $url, $path, $blog_id, $scheme);
}