@@ 1689-1721 (lines=33) @@ | ||
1686 | * @param mixed $args Optional arguments to be appended to URL |
|
1687 | * @return string Endpoint URL |
|
1688 | **/ |
|
1689 | function get_link() { |
|
1690 | $args = func_get_args(); |
|
1691 | $format = array_shift( $args ); |
|
1692 | $base = WPCOM_JSON_API__BASE; |
|
1693 | ||
1694 | $path = array_pop( $args ); |
|
1695 | ||
1696 | if ( $path ) { |
|
1697 | $path = '/' . ltrim( $path, '/' ); |
|
1698 | } |
|
1699 | ||
1700 | $args[] = $path; |
|
1701 | ||
1702 | // Escape any % in args before using sprintf |
|
1703 | $escaped_args = array(); |
|
1704 | foreach ( $args as $arg_key => $arg_value ) { |
|
1705 | $escaped_args[ $arg_key ] = str_replace( '%', '%%', $arg_value ); |
|
1706 | } |
|
1707 | ||
1708 | $relative_path = vsprintf( "$format%s", $escaped_args ); |
|
1709 | ||
1710 | if ( ! wp_startswith( $relative_path, '.' ) ) { |
|
1711 | // Generic version. Match the requested version as best we can |
|
1712 | $api_version = $this->get_closest_version_of_endpoint( $relative_path ); |
|
1713 | $base = substr( $base, 0, - 1 ) . $api_version; |
|
1714 | } |
|
1715 | ||
1716 | // escape any % in the relative path before running it through sprintf again |
|
1717 | $relative_path = str_replace( '%', '%%', $relative_path ); |
|
1718 | // http, WPCOM_JSON_API__BASE, ... , path |
|
1719 | // %s , %s , $format, %s |
|
1720 | return esc_url_raw( sprintf( "%s://%s$relative_path", $this->api->public_api_scheme, $base ) ); |
|
1721 | } |
|
1722 | ||
1723 | function get_me_link( $path = '' ) { |
|
1724 | return $this->get_link( '/me', $path ); |
@@ 32-64 (lines=33) @@ | ||
29 | * @param mixed $args Optional arguments to be appended to URL |
|
30 | * @return string Endpoint URL |
|
31 | **/ |
|
32 | function get_link() { |
|
33 | $args = func_get_args(); |
|
34 | $format = array_shift( $args ); |
|
35 | $base = WPCOM_JSON_API__BASE; |
|
36 | ||
37 | $path = array_pop( $args ); |
|
38 | ||
39 | if ( $path ) { |
|
40 | $path = '/' . ltrim( $path, '/' ); |
|
41 | } |
|
42 | ||
43 | $args[] = $path; |
|
44 | ||
45 | // Escape any % in args before using sprintf |
|
46 | $escaped_args = array(); |
|
47 | foreach ( $args as $arg_key => $arg_value ) { |
|
48 | $escaped_args[ $arg_key ] = str_replace( '%', '%%', $arg_value ); |
|
49 | } |
|
50 | ||
51 | $relative_path = vsprintf( "$format%s", $escaped_args ); |
|
52 | ||
53 | if ( ! wp_startswith( $relative_path, '.' ) ) { |
|
54 | // Generic version. Match the requested version as best we can |
|
55 | $api_version = $this->get_closest_version_of_endpoint( $format, $relative_path ); |
|
56 | $base = substr( $base, 0, - 1 ) . $api_version; |
|
57 | } |
|
58 | ||
59 | // escape any % in the relative path before running it through sprintf again |
|
60 | $relative_path = str_replace( '%', '%%', $relative_path ); |
|
61 | // http, WPCOM_JSON_API__BASE, ... , path |
|
62 | // %s , %s , $format, %s |
|
63 | return esc_url_raw( sprintf( "https://%s$relative_path", $base ) ); |
|
64 | } |
|
65 | ||
66 | function get_me_link( $path = '' ) { |
|
67 | return $this->get_link( '/me', $path ); |