Skip to content

Commit f3554f7

Browse files
authored
Merge pull request Tmeister#33 from zagreusinoz/develop
Add filter for the URL prefix
2 parents 3df8b91 + d62baa0 commit f3554f7

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ Endpoint | HTTP Verb
8989
*/wp-json/jwt-auth/v1/token* | POST
9090
*/wp-json/jwt-auth/v1/token/validate* | POST
9191

92+
NOTE: The endpoint prefix (jwt-auth) can be changed with the **jtw_url_prefix** filter.
93+
9294
##Usage
9395
### /wp-json/jwt-auth/v1/token
9496

@@ -319,6 +321,13 @@ $data = array(
319321
);
320322
```
321323

324+
###jwt_url_prefix
325+
The **jwt_url_prefix** filter allows you to change the prefix of the endpoint.
326+
327+
Default value:
328+
```$this->namespace
329+
```
330+
322331
## Testing
323332

324333
Since version **1.1.0** I've added a new test suite to be sure that the basic features of this plugin do what it's expected.

public/class-jwt-auth-public.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,27 @@ public function __construct($plugin_name, $version)
6767
$this->namespace = $this->plugin_name.'/v'.intval($this->version);
6868
}
6969

70+
/**
71+
* Get the URL prefix for the API resource.
72+
*
73+
* @return string Prefix.
74+
*/
75+
76+
function get_url_prefix() {
77+
return apply_filters( 'jwt_url_prefix', $this->namespace );
78+
}
79+
7080
/**
7181
* Add the endpoints to the API
7282
*/
7383
public function add_api_routes()
7484
{
75-
register_rest_route($this->namespace, 'token', [
85+
register_rest_route( get_url_prefix(), 'token', [
7686
'methods' => 'POST',
7787
'callback' => array($this, 'generate_token'),
7888
]);
7989

80-
register_rest_route($this->namespace, 'token/validate', array(
90+
register_rest_route( get_url_prefix(), 'token/validate', array(
8191
'methods' => 'POST',
8292
'callback' => array($this, 'validate_token'),
8393
));

0 commit comments

Comments
 (0)