Skip to content

Commit d5e0928

Browse files
committed
Change function prefixes
1 parent 1a910ae commit d5e0928

File tree

1 file changed

+29
-50
lines changed

1 file changed

+29
-50
lines changed

oauth-server.php

Lines changed: 29 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@
2020
/**
2121
* Register our rewrite rules for the API
2222
*/
23-
function json_oauth_server_init() {
24-
json_oauth_server_register_rewrites();
23+
function rest_oauth1_init() {
24+
rest_oauth1_register_rewrites();
2525

2626
global $wp;
27-
$wp->add_query_var('json_oauth_route');
27+
$wp->add_query_var('rest_oauth1');
2828
}
29-
add_action( 'init', 'json_oauth_server_init' );
29+
add_action( 'init', 'rest_oauth1_init' );
3030

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' );
3535
}
3636

37-
function json_oauth_server_setup_authentication() {
37+
function rest_oauth1_setup_authentication() {
3838
register_post_type( 'json_consumer', array(
3939
'labels' => array(
4040
'name' => __( 'Consumer' ),
@@ -47,30 +47,30 @@ function json_oauth_server_setup_authentication() {
4747
'query_var' => false,
4848
) );
4949
}
50-
add_action( 'init', 'json_oauth_server_setup_authentication' );
50+
add_action( 'init', 'rest_oauth1_setup_authentication' );
5151

5252
/**
5353
* Register the authorization page
5454
*
5555
* Alas, login_init is too late to register pages, as the action is already
5656
* sanitized before this.
5757
*/
58-
function json_oauth_load() {
58+
function rest_oauth1_load() {
5959
global $wp_json_authentication_oauth1;
6060

6161
$wp_json_authentication_oauth1 = new WP_JSON_Authentication_OAuth1();
6262
add_filter( 'determine_current_user', array( $wp_json_authentication_oauth1, 'authenticate' ) );
6363
add_filter( 'rest_authentication_errors', array( $wp_json_authentication_oauth1, 'get_authentication_errors' ) );
6464
}
65-
add_action( 'init', 'json_oauth_load' );
65+
add_action( 'init', 'rest_oauth1_load' );
6666

6767
/**
6868
* Force reauthentication after we've registered our handler
6969
*
7070
* We could have checked authentication before OAuth was loaded. If so, let's
7171
* try and reauthenticate now that OAuth is loaded.
7272
*/
73-
function json_oauth_force_reauthentication() {
73+
function rest_oauth1_force_reauthentication() {
7474
if ( is_user_logged_in() ) {
7575
// Another handler has already worked successfully, no need to
7676
// reauthenticate.
@@ -83,17 +83,17 @@ function json_oauth_force_reauthentication() {
8383
$current_user = null;
8484
get_currentuserinfo();
8585
}
86-
add_action( 'init', 'json_oauth_force_reauthentication', 100 );
86+
add_action( 'init', 'rest_oauth1_force_reauthentication', 100 );
8787

8888
/**
8989
* Load the JSON API
9090
*/
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'] ) )
9393
return;
9494

9595
$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'] );
9797

9898
if ( is_wp_error( $response ) ) {
9999
$error_data = $response->get_error_data();
@@ -117,36 +117,15 @@ function json_oauth_server_loaded() {
117117
// Finish off our request
118118
die();
119119
}
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 );
142121

143122
/**
144123
* Register v2 API routes
145124
*
146-
* @param object $response_object WP_REST_Response Object
125+
* @param object $response_object WP_REST_Response Object
147126
* @return object Filtered WP_REST_Response object
148127
*/
149-
function json_oauth_api_routes_v2( $response_object ) {
128+
function rest_oauth1_register_routes( $response_object ) {
150129
if ( empty( $response_object->data['authentication'] ) ) {
151130
$response_object->data['authentication'] = array();
152131
}
@@ -159,49 +138,49 @@ function json_oauth_api_routes_v2( $response_object ) {
159138
);
160139
return $response_object;
161140
}
162-
add_filter( 'rest_index', 'json_oauth_api_routes_v2' );
141+
add_filter( 'rest_index', 'rest_oauth1_register_routes' );
163142

164143
/**
165144
* Register the authorization page
166145
*
167146
* Alas, login_init is too late to register pages, as the action is already
168147
* sanitized before this.
169148
*/
170-
function json_oauth_load_authorize_page() {
149+
function rest_oauth1_load_authorize_page() {
171150
$authorizer = new WP_JSON_Authentication_OAuth1_Authorize();
172151
$authorizer->register_hooks();
173152
}
174-
add_action( 'init', 'json_oauth_load_authorize_page' );
153+
add_action( 'init', 'rest_oauth1_load_authorize_page' );
175154

176155
/**
177156
* Register routes and flush the rewrite rules on activation.
178157
*/
179-
function json_oauth_server_activation( $network_wide ) {
158+
function rest_oauth1_activation( $network_wide ) {
180159
if ( function_exists( 'is_multisite' ) && is_multisite() && $network_wide ) {
181160

182161
$mu_blogs = wp_get_sites();
183162

184163
foreach ( $mu_blogs as $mu_blog ) {
185164

186165
switch_to_blog( $mu_blog['blog_id'] );
187-
json_oauth_server_register_rewrites();
166+
rest_oauth1_register_rewrites();
188167
flush_rewrite_rules();
189168
}
190169

191170
restore_current_blog();
192171

193172
} else {
194173

195-
json_oauth_server_register_rewrites();
174+
rest_oauth1_register_rewrites();
196175
flush_rewrite_rules();
197176
}
198177
}
199-
register_activation_hook( __FILE__, 'json_oauth_server_activation' );
178+
register_activation_hook( __FILE__, 'rest_oauth1_activation' );
200179

201180
/**
202181
* Flush the rewrite rules on deactivation
203182
*/
204-
function json_oauth_server_deactivation( $network_wide ) {
183+
function rest_oauth1_deactivation( $network_wide ) {
205184
if ( function_exists( 'is_multisite' ) && is_multisite() && $network_wide ) {
206185

207186
$mu_blogs = wp_get_sites();
@@ -219,4 +198,4 @@ function json_oauth_server_deactivation( $network_wide ) {
219198
flush_rewrite_rules();
220199
}
221200
}
222-
register_deactivation_hook( __FILE__, 'json_oauth_server_deactivation' );
201+
register_deactivation_hook( __FILE__, 'rest_oauth1_deactivation' );

0 commit comments

Comments
 (0)