Skip to content

About

A WordPress plugin that registers a custom post type article and exposes secure REST API endpoints for creating, retrieving, and updating articles. Includes Laravel integration for seamless interaction.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Custom Article API WordPress plugin with Laravel integration:

# 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."}'

Laravel Integration

A sample Laravel service class is included to make HTTP requests to the WordPress API.

Example Usage in Laravel

use App\Services\WordPressArticleService;

$wordpress = new WordPressArticleService();
$response = $wordpress->createArticle([
    'title' => 'Sample Title',
    'content' => 'Sample content body.',
]);

Configuration

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

File Structure

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

About

A WordPress plugin that registers a custom post type article and exposes secure REST API endpoints for creating, retrieving, and updating articles. Includes Laravel integration for seamless interaction.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages