A WordPress plugin to manage a collection of books with a custom database table, REST API, and a React-based (TypeScript) admin interface.
- Custom Database Table: Manages book data in a dedicated database table.
- REST API: Provides secure and validated REST endpoints for CRUD operations on books.
- React-based Admin Interface: A dynamic and interactive admin area built with React and TypeScript for managing books. Includes:
- Adding, editing, and deleting books.
- Search functionality by title, author, or description.
- Pagination for browsing large collections.
- Visual status indicators (colored circles).
- Internationalization (i18n): Ready for translation.
- Robust Build Process: Automated build and packaging for production readiness.
- Download the plugin: Obtain the plugin as a ZIP file (e.g., from a release or by building it).
- Upload to WordPress: In your WordPress admin, go to Plugins > Add New.
- Click Upload Plugin and select the downloaded ZIP file.
- Activate the plugin: After successful upload, activate the plugin. Upon activation, a custom database table (
{$wpdb->prefix}library_books) will be created.
This plugin includes a React application for its admin interface, developed with TypeScript, and a Grunt-based build system for packaging.
Ensure you have Node.js and npm installed.
These are for the Grunt build system. Navigate to the plugin's root directory:
cd /path/to/your/wp-content/plugins/library-manager
npm installTo generate a production-ready ZIP file of the entire plugin:
cd /path/to/your/wp-content/plugins/library-manager
npm run buildThis command will:
- Install React app dependencies (if not already installed).
- Compile the TypeScript React application located in
admin/js. - Generate translation files (
.pot). - Copy all necessary plugin files.
- Create a distributable ZIP file (e.g.,
library-manager-1.0.0.zip) in thebuild/directory.
If you wish to develop or modify the React application directly:
- Navigate to the
admin/jsdirectory:cd /path/to/your/wp-content/plugins/library-manager/admin/js - Install its dependencies:
npm install
- You can then run the React development server:
(Note: This is for frontend development purposes only and typically runs on a separate port. For changes to reflect in WordPress, you would need to run
npm start
npm run buildinadmin/jsand thennpm run buildin the plugin root.)
This plugin provides the following WP-CLI commands for command-line management.
- Description: Imports book data from a JSON file into the library.
- Arguments:
<file>(string, required): The absolute or relative path to the JSON file containing book data. The JSON file should contain an array of book objects, each withtitle,author,publication_year, anddescriptionproperties.
- Example:
or (if run from WordPress root):
wp library import /Users/mofizulislam/Sites/wpplugins/wp-content/plugins/library-manager/sample.json
wp library import wp-content/plugins/library-manager/sample.json
/wp-json/library/v1
- Description: Get all books.
- Filters:
status(string):available,borrowed, orunavailableauthor(string): Filter by author name.year(integer): Filter by publication year.search(string): Search bytitle,author, ordescription.
- Pagination:
page(integer): Current page (default: 1).per_page(integer): Items per page (default: 10).
- Description: Get a single book by ID.
- Description: Create a new book.
- Permission:
edit_postscapability. - Body (JSON):
title(string, required)author(string, required)publication_year(integer, required)description(string)status(string):available,borrowed, orunavailable
- Description: Update a book by ID.
- Permission:
edit_postscapability. - Body (JSON): Same as POST.
- Description: Delete a book by ID.
- Permission:
edit_postscapability.
The plugin creates a custom table named {$wpdb->prefix}library_books with the following schema:
idBIGINT unsigned AUTO_INCREMENT PRIMARY KEYtitleVARCHAR(255) NOT NULLdescriptionLONGTEXTauthorVARCHAR(255) NOT NULLpublication_yearINT NOT NULLstatusENUM('available','borrowed','unavailable') DEFAULT 'available'created_atDATETIME DEFAULT CURRENT_TIMESTAMPupdated_atDATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP