Library Manager
Manages a collection of books with a custom database table, REST API, and a React-based admin interface.
by Mofizul Islam · github.com/mofizul21/library-manager · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/mofizul21/library-manager/archive/refs/heads/main.zipA WordPress plugin to manage a collection of books with a custom database table, REST API, and a React-based (TypeScript) admin interface.
Features
- 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.
Installation
- 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.
Build Process (For Developers)
This plugin includes a React application for its admin interface, developed with TypeScript, and a Grunt-based build system for packaging.
1. Install Global Dependencies (if not already installed)
Ensure you have Node.js and npm installed.
2. Install Plugin Root Dependencies
These are for the Grunt build system. Navigate to the plugin's root directory:
cd /path/to/your/wp-content/plugins/library-manager
npm install
3. Build the Plugin (including React App)
To generate a production-ready ZIP file of the entire plugin:
cd /path/to/your/wp-content/plugins/library-manager
npm run build
This 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.
4. Frontend Development (React App)
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:
npm start(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 run buildinadmin/jsand thennpm run buildin the plugin root.)
WP-CLI Commands
This plugin provides the following WP-CLI commands for command-line management.
wp library import <file>
- 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:
wp library import /Users/mofizulislam/Sites/wpplugins/wp-content/plugins/library-manager/sample.jsonor (if run from WordPress root):
wp library import wp-content/plugins/library-manager/sample.json
REST API Documentation
Base URL
/wp-json/library/v1
Endpoints
GET /books
- 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).
GET /books/{id}
- Description: Get a single book by ID.
POST /books
- 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
PUT /books/{id}
- Description: Update a book by ID.
- Permission:
edit_postscapability. - Body (JSON): Same as POST.
DELETE /books/{id}
- Description: Delete a book by ID.
- Permission:
edit_postscapability.
Table Schema
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