WordPress WP API Extending – 404 on Endpoints
-
I’m trying to create a few custom JSON endpoints for my plugin. I installed the WP API plugin and here’s the entire contents of my plugin php.
<?php /** * Plugin Name: Quiz WordPress Plugin * Plugin URI: https://www.domain.com * Description: This plugin handles quiz functionality. * Version: 1.0.0 * Author: Ray Hwang * Author URI: https://www.domain.com * License: private */ function quiz_api_init() { global $quiz_api; $quiz_api = new QUIZ_API(); add_filter( 'json_endpoints', array( $quiz_api, 'register_routes' ) ); } add_action( 'wp_json_server_before_serve', 'quiz_api_init' ); class QUIZ_API { public function register_routes( $routes ) { $routes['/api'] = array( array( array( $this, 'get_quiz'), WP_JSON_Server::READABLE ), array( array( $this, 'new_quiz'), WP_JSON_Server::CREATABLE | WP_JSON_Server::ACCEPT_JSON ), ); return $routes; } public function get_quiz($_headers, $data = ''){ return array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5); } public function new_quiz($_headers, $data = ''){ return array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5); } }
There are no errors when I activate the plugin. When I request the endpoint. I get
Not Found The requested URL /api was not found on this server. Apache/2.4.7 (Ubuntu) Server at ec2-----.compute-1.amazonaws.com Port 80 Does it have something to do with URL rewrite or permalinks?
My permalink settings is set to default https://ec2——–.compute-1.amazonaws.com/?p=123
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘WordPress WP API Extending – 404 on Endpoints’ is closed to new replies.