Nahidul API Fetcher
Fetches data from a remote API and displays it via AJAX, a Gutenberg block, an admin page, and WP-CLI.
by TheNahidul · github.com/thenahidul/nahidul-api-fetcher · 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/thenahidul/nahidul-api-fetcher/archive/refs/heads/main.zipReadme
Nahidul API Fetcher (Awesome Motive Plugin Challenge)
Contributors: TheNahidul Tags: api, gutenberg, block Requires at least: 6.0 Tested up to: 6.8 Requires PHP: 7.4 Stable tag: 1.0.0 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html
Fetches data from a remote API and displays it in a table.
Description
Fetches data from a remote API and displays it via AJAX, a Gutenberg block, an admin page, and WP-CLI.
Features
- Remote API Integration: Fetches data from
https://miusage.com/v1/challenge/1/ - Smart Caching: Implements 1-hour caching to prevent excessive API calls
- AJAX Endpoint: Public WordPress AJAX endpoint for data retrieval
- Custom Gutenberg Block: Display data in a customizable table format
- Admin Dashboard: WordPress admin page with data display and refresh functionality
- WP CLI Command: Command-line interface for forced data refresh
- Internationalization: Full translation support
- Modern PHP Architecture: Object-oriented design with PSR-4 autoloading
Installation
- Download the plugin files
- Upload the
nahidul-api-fetcherfolder to your/wp-content/plugins/directory - Run
composer installin the plugin directory to install dependencies - Activate the plugin through the 'Plugins' menu in WordPress
Requirements
- WordPress 6.0 or higher
- PHP 7.4 or higher
- Composer (for development dependencies)
Usage
Gutenberg Block
- Add a new block in the WordPress editor
- Search for "Nahidul API Fetcher"
- Insert the block to display the fetched data in a table format
- Use block settings to toggle column visibility & refresh data
Admin Dashboard
- Navigate to Dashboard > Nahidul API Fetcher in WordPress admin
- View the fetched data in a formatted table
- Use the "Refresh Data" button to force update the cache
REST Endpoint
The plugin creates a public REST API endpoint accessible at:
/wp-json/nahidul-api-fetcher/v1/data/
/wp-json/nahidul-api-fetcher/v1/data/?refresh=true
WP CLI Command
Get data
wp nahidul-api-fetcher data
wp nahidul-api-fetcher data --force // Clear cached data and get new ones
wp nahidul-api-fetcher data --show_col=name,date // Show specific columns
wp nahidul-api-fetcher data --show_col=name,date // Hide specific columns
Development
Prerequisites
- Composer
- Node.js and npm (for block development)
- WordPress development environment
Setup
- Clone the repository
- Install PHP dependencies:
composer install, composer update,composer dump-autoload(if needed )- Install JavaScript dependencies:
npm install - Build assets:
npm run buildornpm startfor development
Code Standards
- PSR-4 autoloading
- WordPress coding standards
- Modern PHP practices (OOP, namespaces)
- Proper sanitization and validation
- Internationalization ready
Security
- All data is properly sanitized and validated
- Uses WordPress nonces for admin actions
- Implements rate limiting through caching
- Follows WordPress security best practices
Caching
The plugin implements intelligent caching:
- Duration: 1 hour (3600 seconds)
- Storage: WordPress transients
- Override: Available via WP CLI command or admin refresh button
Internationalization
The plugin is fully translatable:
- Text domain:
nahidul-api-fetcher - POT file:
languages/nahidul-api-fetcher.pot - Translation functions:
__(),_e(),esc_html__()
Changelog
1.0.0
- Initial release
- Remote API integration
- Gutenberg block implementation
- Admin dashboard
- WP CLI command
- Caching system
- Internationalization support
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and ensure code standards
- Submit a pull request
License
This plugin is licensed under the GPL v2 or later.
Author
Md Nahidul Islam
- Plugin development with modern WordPress practices
- Focus on performance, security, and user experience