Thursday 22 March 2018

Building a Quiz with React and WP REST API: CPT and REST API Routes


We will use the WordPress REST API Routes to retrieve questions and scores used for building our Quiz in React. We need a route to retrieve the questions with their answers and to submit the answers so we can get our result. In this tutorial, we will proceed to our WordPress roadmap and define our custom post type, metabox and also the WordPress REST API Routes. If you have not yet learned about what we are going to build and the roadmap for each part, you can check the last article: Building a Quiz with React and WordPress REST API: Introduction.
The Base Plugin
In the last article, we did not create a base plugin. So let’s do that now. Create a folder in the plugins folder and name it wp-quiz-tut. Create a new php file inside that folder with the same name wp-quiz-tut.php.
Inside that folder create another one and name it inc. We will use that folder for additional files. Create 2 empty php files: class-wpqr-metaboxes.php and class-wpqr-rest-api.php.
This file wp-quiz-tut.php will hold the main class of our plugin that is going to be used when loading the plugin and all the dependencies. Add this code to the file.
<?php
/**
* Plugin Name: WordPress Quiz with React
* Description:
Source: https://managewp.org/articles/17269/building-a-quiz-with-react-and-wp-rest-api-cpt-and-rest-api-routes



source https://williechiu40.wordpress.com/2018/03/22/building-a-quiz-with-react-and-wp-rest-api-cpt-and-rest-api-routes/

No comments:

Post a Comment