Skip to content

Commit b2f2ead

Browse files
committed
Merge pull request #75 from JRGould/#74-add-v2-auth-routes
Add filter to `rest_index` to add routes to v2
2 parents 161b675 + ee71f86 commit b2f2ead

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

oauth-server.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function json_oauth_server_loaded() {
117117
add_action( 'template_redirect', 'json_oauth_server_loaded', -100 );
118118

119119
/**
120-
* Register API routes
120+
* Register v1 API routes
121121
*
122122
* @param array $data Index data
123123
* @return array Filtered data
@@ -137,6 +137,27 @@ function json_oauth_api_routes( $data ) {
137137
}
138138
add_filter( 'json_index', 'json_oauth_api_routes' );
139139

140+
/**
141+
* Register v2 API routes
142+
*
143+
* @param object $response_object WP_REST_Response Object
144+
* @return object Filtered WP_REST_Response object
145+
*/
146+
function json_oauth_api_routes_v2( $response_object ) {
147+
if ( empty( $response_object->data['authentication'] ) ) {
148+
$response_object->data['authentication'] = array();
149+
}
150+
151+
$response_object->data['authentication']['oauth1'] = array(
152+
'request' => home_url( 'oauth1/request' ),
153+
'authorize' => home_url( 'oauth1/authorize' ),
154+
'access' => home_url( 'oauth1/access' ),
155+
'version' => '0.1',
156+
);
157+
return $response_object;
158+
}
159+
add_filter( 'rest_index', 'json_oauth_api_routes_v2' );
160+
140161
/**
141162
* Register the authorization page
142163
*

0 commit comments

Comments
 (0)