- A basic WP plugin as a starting point, framework or boilerplate for conecting with an external API and retrieving the data in a html table and AJAX -
After installation, the plugin will display a table with users information on a custom endpoint
Users are retrieved from an external API for testing purposes: https://jsonplaceholder.typicode.com/users
The default endpoint can be edited on the provided backend options, found on the main WP admin dashboard. Regex validation is applied to the string before being saved on database.
After accessing the endpoint, more details about each user will be displayed when any of the values of table is clicked
The users detail popup works on AJAX request and a new API call is made on each click, using the same class that is used for the users table: ApiCall.php
The table is displayed on a custom template, it is not a post or a page recognized by WP.
Because of this, a class named Prevent404.php
will prevent WP treating the endpoint as a 404 page / error
- Open console
- Open plugins folder of WP installation
https://yourwebsite.com/wp-content/plugins
- Run
git clone https://github.com/sebastopolys/apiusers/
- Enter apiusers plugin folder
https://yourwebsite.com/wp-content/plugins/apiusers
- Run
composer install
- Run
composer update
if necessary
The default Endpoint is named like the plugin name: apiusers
There is no link supplied on the frontend, just access by typing the endpoint after website URL. Or place a link anywere on the frontend
https://yourwebsite.com/apiusers
Use vendor/bin/phpcs --standard="Inpsyde" <path-file>
to run on single files
phpunit is ready to use, and a single test file (/tests/ApiusersTest.php
) will execute all tests:
Usage:
- Create new database for testing purposes
- Install testing environment from console, on the plugin folder
bash bin/install-wp-tests.sh <db-name> <db-user> <db-pass> <db-host> latest
- Run test file using:
vendor/bin/phpunit tests/ApiusersTest.php
Please take in consideration that this testing file is only for demostration purposes and it does not cover all methods, only 4 tests are provided from different classes:
ValidateEndpoint::validateTheEndpoint()
,ApiCall::CallApi(null)
,ApiCall::CallApi(int)
andBackendDashboard::callbackvalidation()
Some backend options are included on the WP admin dashboard.
The WP settings API was used.
- Customize Endpoint: Allows to edit the default endpoint.
- View: Displays integrated with theme or removing header & footer
- Credits: Hide / Display credits below table
- Plugin Author: Sebastian Rossi
- Plugin name: Api Users
- Plugin textdomain: apiusers
- Contact: [email protected]