20
20
/**
21
21
* Register our rewrite rules for the API
22
22
*/
23
- function json_oauth_server_init () {
24
- json_oauth_server_register_rewrites ();
23
+ function rest_oauth1_init () {
24
+ rest_oauth1_register_rewrites ();
25
25
26
26
global $ wp ;
27
- $ wp ->add_query_var ('json_oauth_route ' );
27
+ $ wp ->add_query_var ('rest_oauth1 ' );
28
28
}
29
- add_action ( 'init ' , 'json_oauth_server_init ' );
29
+ add_action ( 'init ' , 'rest_oauth1_init ' );
30
30
31
- function json_oauth_server_register_rewrites () {
32
- add_rewrite_rule ( '^oauth1/authorize/?$ ' ,'index.php?json_oauth_route =authorize ' ,'top ' );
33
- add_rewrite_rule ( '^oauth1/request/?$ ' ,'index.php?json_oauth_route =request ' ,'top ' );
34
- add_rewrite_rule ( '^oauth1/access/?$ ' ,'index.php?json_oauth_route =access ' ,'top ' );
31
+ function rest_oauth1_register_rewrites () {
32
+ add_rewrite_rule ( '^oauth1/authorize/?$ ' ,'index.php?rest_oauth1 =authorize ' ,'top ' );
33
+ add_rewrite_rule ( '^oauth1/request/?$ ' ,'index.php?rest_oauth1 =request ' ,'top ' );
34
+ add_rewrite_rule ( '^oauth1/access/?$ ' ,'index.php?rest_oauth1 =access ' ,'top ' );
35
35
}
36
36
37
- function json_oauth_server_setup_authentication () {
37
+ function rest_oauth1_setup_authentication () {
38
38
register_post_type ( 'json_consumer ' , array (
39
39
'labels ' => array (
40
40
'name ' => __ ( 'Consumer ' ),
@@ -47,30 +47,30 @@ function json_oauth_server_setup_authentication() {
47
47
'query_var ' => false ,
48
48
) );
49
49
}
50
- add_action ( 'init ' , 'json_oauth_server_setup_authentication ' );
50
+ add_action ( 'init ' , 'rest_oauth1_setup_authentication ' );
51
51
52
52
/**
53
53
* Register the authorization page
54
54
*
55
55
* Alas, login_init is too late to register pages, as the action is already
56
56
* sanitized before this.
57
57
*/
58
- function json_oauth_load () {
58
+ function rest_oauth1_load () {
59
59
global $ wp_json_authentication_oauth1 ;
60
60
61
61
$ wp_json_authentication_oauth1 = new WP_JSON_Authentication_OAuth1 ();
62
62
add_filter ( 'determine_current_user ' , array ( $ wp_json_authentication_oauth1 , 'authenticate ' ) );
63
63
add_filter ( 'rest_authentication_errors ' , array ( $ wp_json_authentication_oauth1 , 'get_authentication_errors ' ) );
64
64
}
65
- add_action ( 'init ' , 'json_oauth_load ' );
65
+ add_action ( 'init ' , 'rest_oauth1_load ' );
66
66
67
67
/**
68
68
* Force reauthentication after we've registered our handler
69
69
*
70
70
* We could have checked authentication before OAuth was loaded. If so, let's
71
71
* try and reauthenticate now that OAuth is loaded.
72
72
*/
73
- function json_oauth_force_reauthentication () {
73
+ function rest_oauth1_force_reauthentication () {
74
74
if ( is_user_logged_in () ) {
75
75
// Another handler has already worked successfully, no need to
76
76
// reauthenticate.
@@ -83,17 +83,17 @@ function json_oauth_force_reauthentication() {
83
83
$ current_user = null ;
84
84
get_currentuserinfo ();
85
85
}
86
- add_action ( 'init ' , 'json_oauth_force_reauthentication ' , 100 );
86
+ add_action ( 'init ' , 'rest_oauth1_force_reauthentication ' , 100 );
87
87
88
88
/**
89
89
* Load the JSON API
90
90
*/
91
- function json_oauth_server_loaded () {
92
- if ( empty ( $ GLOBALS ['wp ' ]->query_vars ['json_oauth_route ' ] ) )
91
+ function rest_oauth1_loaded () {
92
+ if ( empty ( $ GLOBALS ['wp ' ]->query_vars ['rest_oauth1 ' ] ) )
93
93
return ;
94
94
95
95
$ authenticator = new WP_JSON_Authentication_OAuth1 ();
96
- $ response = $ authenticator ->dispatch ( $ GLOBALS ['wp ' ]->query_vars ['json_oauth_route ' ] );
96
+ $ response = $ authenticator ->dispatch ( $ GLOBALS ['wp ' ]->query_vars ['rest_oauth1 ' ] );
97
97
98
98
if ( is_wp_error ( $ response ) ) {
99
99
$ error_data = $ response ->get_error_data ();
@@ -117,36 +117,15 @@ function json_oauth_server_loaded() {
117
117
// Finish off our request
118
118
die ();
119
119
}
120
- add_action ( 'template_redirect ' , 'json_oauth_server_loaded ' , -100 );
121
-
122
- /**
123
- * Register v1 API routes
124
- *
125
- * @param array $data Index data
126
- * @return array Filtered data
127
- */
128
- function json_oauth_api_routes ( $ data ) {
129
- if (empty ($ data ['authentication ' ])) {
130
- $ data ['authentication ' ] = array ();
131
- }
132
-
133
- $ data ['authentication ' ]['oauth1 ' ] = array (
134
- 'request ' => home_url ( 'oauth1/request ' ),
135
- 'authorize ' => home_url ( 'oauth1/authorize ' ),
136
- 'access ' => home_url ( 'oauth1/access ' ),
137
- 'version ' => '0.1 ' ,
138
- );
139
- return $ data ;
140
- }
141
- add_filter ( 'json_index ' , 'json_oauth_api_routes ' );
120
+ add_action ( 'template_redirect ' , 'rest_oauth1_loaded ' , -100 );
142
121
143
122
/**
144
123
* Register v2 API routes
145
124
*
146
- * @param object $response_object WP_REST_Response Object
125
+ * @param object $response_object WP_REST_Response Object
147
126
* @return object Filtered WP_REST_Response object
148
127
*/
149
- function json_oauth_api_routes_v2 ( $ response_object ) {
128
+ function rest_oauth1_register_routes ( $ response_object ) {
150
129
if ( empty ( $ response_object ->data ['authentication ' ] ) ) {
151
130
$ response_object ->data ['authentication ' ] = array ();
152
131
}
@@ -159,49 +138,49 @@ function json_oauth_api_routes_v2( $response_object ) {
159
138
);
160
139
return $ response_object ;
161
140
}
162
- add_filter ( 'rest_index ' , 'json_oauth_api_routes_v2 ' );
141
+ add_filter ( 'rest_index ' , 'rest_oauth1_register_routes ' );
163
142
164
143
/**
165
144
* Register the authorization page
166
145
*
167
146
* Alas, login_init is too late to register pages, as the action is already
168
147
* sanitized before this.
169
148
*/
170
- function json_oauth_load_authorize_page () {
149
+ function rest_oauth1_load_authorize_page () {
171
150
$ authorizer = new WP_JSON_Authentication_OAuth1_Authorize ();
172
151
$ authorizer ->register_hooks ();
173
152
}
174
- add_action ( 'init ' , 'json_oauth_load_authorize_page ' );
153
+ add_action ( 'init ' , 'rest_oauth1_load_authorize_page ' );
175
154
176
155
/**
177
156
* Register routes and flush the rewrite rules on activation.
178
157
*/
179
- function json_oauth_server_activation ( $ network_wide ) {
158
+ function rest_oauth1_activation ( $ network_wide ) {
180
159
if ( function_exists ( 'is_multisite ' ) && is_multisite () && $ network_wide ) {
181
160
182
161
$ mu_blogs = wp_get_sites ();
183
162
184
163
foreach ( $ mu_blogs as $ mu_blog ) {
185
164
186
165
switch_to_blog ( $ mu_blog ['blog_id ' ] );
187
- json_oauth_server_register_rewrites ();
166
+ rest_oauth1_register_rewrites ();
188
167
flush_rewrite_rules ();
189
168
}
190
169
191
170
restore_current_blog ();
192
171
193
172
} else {
194
173
195
- json_oauth_server_register_rewrites ();
174
+ rest_oauth1_register_rewrites ();
196
175
flush_rewrite_rules ();
197
176
}
198
177
}
199
- register_activation_hook ( __FILE__ , 'json_oauth_server_activation ' );
178
+ register_activation_hook ( __FILE__ , 'rest_oauth1_activation ' );
200
179
201
180
/**
202
181
* Flush the rewrite rules on deactivation
203
182
*/
204
- function json_oauth_server_deactivation ( $ network_wide ) {
183
+ function rest_oauth1_deactivation ( $ network_wide ) {
205
184
if ( function_exists ( 'is_multisite ' ) && is_multisite () && $ network_wide ) {
206
185
207
186
$ mu_blogs = wp_get_sites ();
@@ -219,4 +198,4 @@ function json_oauth_server_deactivation( $network_wide ) {
219
198
flush_rewrite_rules ();
220
199
}
221
200
}
222
- register_deactivation_hook ( __FILE__ , 'json_oauth_server_deactivation ' );
201
+ register_deactivation_hook ( __FILE__ , 'rest_oauth1_deactivation ' );
0 commit comments