WP Manifestindependent plugin directory
manifest / integrations / pmc-product-card

PMC Product Card archived

A WordPress plugin that provides product card functionality with REST API endpoints.

by PMC · github.com/thefrosty/pmc-product-card · website

0stars
0forks

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/thefrosty/pmc-product-card/archive/refs/heads/main.zip

Readme

PMC Product Card

A WordPress plugin that provides product card functionality with REST API endpoints.

Description

PMC Product Card is a lightweight WordPress plugin that creates a REST API endpoint for retrieving product information. The plugin generates dynamic product data based on the requested product ID, making it perfect for testing, prototyping, or demonstration purposes.

Features

  • REST API Endpoint: Simple GET endpoint for retrieving product data
  • Dynamic Product Generation: Creates product data on-the-fly for any positive product ID
  • Consistent Pricing: Price calculation based on product ID (range: $10-$100)
  • WordPress Standards: Follows WordPress coding standards and best practices
  • PHP 7.4+ Compatible: Works with modern PHP versions
  • Internationalization Ready: Prepared for translations

Requirements

  • WordPress 5.0 or higher
  • PHP 7.4 or higher

Installation

  1. Upload the pmc-product-card folder to the /wp-content/plugins/ directory
  2. Activate the plugin through the 'Plugins' menu in WordPress
  3. The REST API endpoint will be automatically available

API Endpoint

Get Product by ID

Endpoint: GET /wp-json/pmc-product-card/v1/product

Parameters:

  • id (required, integer): The product ID to retrieve

URL: /wp-json/pmc-product-card/v1/product?id={product_id}

Example Requests

# Get product with ID 1
GET /wp-json/pmc-product-card/v1/product?id=1

# Get product with ID 42
GET /wp-json/pmc-product-card/v1/product?id=42

# Get product with ID 999
GET /wp-json/pmc-product-card/v1/product?id=999

Example Response

{
  "id": 42,
  "name": "Product 42",
  "description": "This is the description for product 42.",
  "price": 52,
  "created_at": "2023-10-16 12:34:56"
}

Response Fields

  • id (integer): The requested product ID
  • name (string): Product name in format "Product {ID}"
  • description (string): Dynamic description including the product ID
  • price (integer): Price calculated as ($id % 91) + 10 (range: $10-$100)
  • created_at (string): Current timestamp in MySQL format

How It Works

Dynamic Product Generation

The plugin doesn't store any product data in the database. Instead, it generates product information dynamically based on the requested product ID:

  1. Valid IDs: Any positive integer (1, 2, 3, etc.)
  2. Invalid IDs: Zero, negative numbers, or non-numeric values return a 404 error
  3. Price Calculation: Uses modulo arithmetic to keep prices between $10-$100
  4. Consistent Data: Same product ID always returns the same data

Price Calculation Logic

$price = ($product_id % 91) + 10;

This formula ensures:

  • Prices range from $10 to $100
  • Same product ID always has the same price
  • Prices cycle predictably for large IDs

Example Price Calculations

  • Product ID 1: $11
  • Product ID 5: $15
  • Product ID 91: $10
  • Product ID 92: $11
  • Product ID 999: $100

Error Handling

404 - Product Not Found

Returned when:

  • Product ID is 0 or negative
  • Product ID is not provided
  • Product ID is not a valid integer
{
  "code": "product_not_found",
  "message": "Product not found.",
  "data": {
    "status": 404
  }
}

Security

  • Public Access: The GET endpoint allows public access for reading product data
  • Input Validation: All input parameters are validated and sanitized
  • Direct Access Prevention: Plugin files are protected against direct access
  • WordPress Security: Follows WordPress security best practices

Technical Details

Plugin Structure

pmc-product-card/
├── pmc-product-card.php    # Main plugin file
└── README.md               # This documentation

Key Components

  • Singleton Pattern: Ensures only one instance of the plugin class
  • WordPress Hooks: Proper integration with WordPress lifecycle
  • REST API Integration: Uses WordPress REST API framework
  • Internationalization: Text domain setup for translations

Code Standards

  • Follows WordPress Coding Standards
  • Uses modern PHP syntax (array short syntax [])
  • Includes comprehensive PHPDoc comments
  • Implements proper error handling

Development

Extending the Plugin

To modify the product data structure, edit the get_product_by_id() method in the main plugin file:

private function get_product_by_id( int $product_id ) {
    // Custom logic here
    return [
        'id'          => $product_id,
        'name'        => sprintf( 'Product %d', $product_id ),
        'description' => sprintf( 'This is the description for product %d.', $product_id ),
        'price'       => ( $product_id % 91 ) + 10,
        'created_at'  => current_time( 'mysql' ),
        // Add custom fields here
    ];
}

Testing

Test the endpoint using curl, Postman, or your browser:

curl "https://your-wordpress-site.com/wp-json/pmc-product-card/v1/product?id=123"

Changelog

Version 1.0.0

  • Initial release
  • GET endpoint for retrieving products by ID
  • Dynamic product generation
  • Price calculation between $10-$100
  • WordPress coding standards compliance

License

This plugin is licensed under the GPL v2 or later.

Support

For support, feature requests, or bug reports, please contact the development team.

Read the full README on GitHub →

Releases

TagPublished
1.0.0 Oct 17, 2025

These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.