From: Anthony Talarico Date: Tue, 2 Jul 2019 20:40:47 +0000 (-0400) Subject: changing the register route to use class variables and changing class name X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=946107469d80fb5498b83e4a3b2c44426922b141;p=WP-Plugins%2Fglm-member-db-rest-api.git changing the register route to use class variables and changing class name --- diff --git a/setup/routes.php b/setup/routes.php index aa22013..a7bfe34 100644 --- a/setup/routes.php +++ b/setup/routes.php @@ -22,7 +22,7 @@ require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMemberInfo.php'; * 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 @@ -34,7 +34,7 @@ class GLMA_Rest_Api */ public function __construct( $wpdb, $config ) { - $this->namespace = '/glm/v1/'; + $this->namespace = 'glm/v1/'; $this->resource_name = 'members'; // Setup wpdb and config @@ -53,8 +53,8 @@ class GLMA_Rest_Api { // 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, @@ -81,6 +81,7 @@ class GLMA_Rest_Api // Get List of Members $members = $memberData->getList( $where, 'member_name'); + return rest_ensure_response( array_values($members ) ); }, ) @@ -89,8 +90,8 @@ class GLMA_Rest_Api // Member Route register_rest_route( - 'glm/v1', - 'members' . '/(?P[\d]+)', + $this->namespace, + $this->namespace . '/(?P[\d]+)', array( array( 'methods' => WP_REST_Server::READABLE, @@ -100,12 +101,9 @@ class GLMA_Rest_Api ) ) ); - - } - public function get_collection_params() - { + public function get_collection_params(){ return array( 'page' => array( 'description' => 'Current page of the collection', @@ -127,14 +125,12 @@ class GLMA_Rest_Api ); } - public function authorization_status_code() - { + public function authorization_status_code(){ $status = 401; if ( is_user_logged_in() ) { $status = 403; } - return $status; } @@ -146,7 +142,7 @@ class GLMA_Rest_Api 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(); } );