# Custom Article API - WordPress Plugin
This plugin provides a custom REST API interface for managing "Articles" within a WordPress site. It includes full CRUD support and is secured via WordPress authentication methods such as Application Passwords or JWT. It also includes a Laravel integration to interact with the API endpoints.
---
## Features
- Custom Post Type: `article`
- Custom REST API Endpoints:
- Create an article: `POST /wp-json/custom-api/v1/article`
- Get an article: `GET /wp-json/custom-api/v1/article/{id}`
- Update an article: `PUT /wp-json/custom-api/v1/article/{id}`
- Secure API access using WordPress authentication
- Laravel service class for easy integration
---
## Installation
1. Clone or Download Plugin
- Place the plugin folder in `wp-content/plugins/`.
2. Activate Plugin
- From the WordPress Admin Dashboard, go to Plugins > Installed Plugins and activate `Custom Article API`.
---
## API Authentication
You must authenticate to access the API endpoints. Supported methods:
- WordPress **Application Passwords**
- JWT Authentication (optional, requires plugin like JWT Authentication for WP REST API)
### Example (Using Application Passwords):
```bash
curl -u your_username:your_application_password \
-X POST https://yourdomain.com/wp-json/custom-api/v1/article \
-H "Content-Type: application/json" \
-d '{"title": "New Article", "content": "This is the article body."}'A sample Laravel service class is included to make HTTP requests to the WordPress API.
use App\Services\WordPressArticleService;
$wordpress = new WordPressArticleService();
$response = $wordpress->createArticle([
'title' => 'Sample Title',
'content' => 'Sample content body.',
]);Update your Laravel .env file with the following:
WP_API_URL=https://yourdomain.com/wp-json/custom-api/v1
WP_USERNAME=your_username
WP_APP_PASSWORD=your_application_password
custom-article-api/
│
├── custom-article-api.php # Main plugin file
├── includes/
│ └── class-custom-api-controller.php # API controller logic
├── readme.md
└── laravel/
└── WordPressArticleService.php # Laravel service class