* Documentation for Wordpress API and adding custom endpoints.
* https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/
*/
-class GLMA_Rest_Api
+class GLMA_Member_Rest_Controller
{
/**
* __construct
*/
public function __construct( $wpdb, $config )
{
- $this->namespace = '/glm/v1/';
+ $this->namespace = 'glm/v1/';
$this->resource_name = 'members';
// Setup wpdb and config
{
// Members Route
register_rest_route(
- 'glm/v1', // namespace
- 'members', // route
+ $this->namespace, // namespace
+ $this->resource_name , // route
array( // array of arrays for multiple methods. Add more arrays for different endpoints.
array( // endpoint for getting members
'methods' => WP_REST_Server::READABLE,
// Get List of Members
$members = $memberData->getList( $where, 'member_name');
+
return rest_ensure_response( array_values($members ) );
},
)
// Member Route
register_rest_route(
- 'glm/v1',
- 'members' . '/(?P<id>[\d]+)',
+ $this->namespace,
+ $this->namespace . '/(?P<id>[\d]+)',
array(
array(
'methods' => WP_REST_Server::READABLE,
)
)
);
-
-
}
- public function get_collection_params()
- {
+ public function get_collection_params(){
return array(
'page' => array(
'description' => 'Current page of the collection',
);
}
- public function authorization_status_code()
- {
+ public function authorization_status_code(){
$status = 401;
if ( is_user_logged_in() ) {
$status = 403;
}
-
return $status;
}
add_action(
'rest_api_init',
function(){
- $controller = new GLMA_Rest_Api( $this->wpdb, $this->config );
+ $controller = new GLMA_Member_Rest_Controller( $this->wpdb, $this->config );
$controller->register_routes();
}
);