arraypress / wp-faker
A lightweight WordPress library for generating fake data for seeding and testing
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/arraypress/wp-faker
Requires
- php: >=7.4
This package is auto-updated.
Last update: 2026-02-04 16:47:59 UTC
README
A lightweight WordPress library for generating fake data for seeding and testing. Built for e-commerce plugins and admin table demos.
Installation
composer require arraypress/wp-faker
Quick Start
use ArrayPress\Faker\Fake; // Generate a customer $customer = [ 'name' => Fake::name(), // "Sarah Johnson" 'email' => Fake::email(), // "sarah.johnson@company.com" 'phone' => Fake::phone(), // "+1 555-234-5678" 'company' => Fake::company(), // "Johnson Technologies" 'country' => Fake::country(), // "us" 'status' => Fake::weighted( [ 'active' => 60, 'pending' => 20, 'inactive' => 20 ] ), 'total_spent' => Fake::price(), // 4999 (cents) 'order_count' => Fake::number( 1, 50 ), 'date_created' => Fake::past_date(), // "2024-03-15 14:22:09" ];
API Reference
People
Fake::first_name(); // "Sarah" Fake::last_name(); // "Johnson" Fake::name(); // "Sarah Johnson" Fake::email(); // "sarah.johnson@company.com" Fake::email( 'Sarah', 'Johnson' ); // Consistent email from name Fake::phone(); // "+1 555-234-5678"
Companies
Fake::company(); // "Johnson Technologies"
Commerce
Fake::price(); // 4999 (cents, $1–$5,000) Fake::price( 500, 10000 ); // Custom range in cents Fake::sku(); // "PRD-45821" Fake::product_name(); // "Premium Widget"
Location
Fake::country(); // "us" (lowercase ISO alpha-2)
Dates
Fake::date_between( '-2 years', 'now' ); // "2024-03-15 14:22:09" Fake::date_between( '-30 days', 'now' ); // Recent date Fake::past_date(); // Random date in last 2 years Fake::past_date( 365 ); // Random date in last year Fake::past_date( 30, 'Y-m-d' ); // Date-only format
Text
Fake::sentence(); // "The customer process would update first." Fake::sentence( 8 ); // Exactly 8 words Fake::paragraph(); // 3-6 random sentences Fake::paragraph( 4 ); // Exactly 4 sentences
WordPress
Fake::user_id(); // 42 (random existing user) Fake::user_id( 'subscriber' ); // Random subscriber Fake::post_id(); // 156 (random published post) Fake::post_id( 'product' ); // Random product post Fake::attachment_id(); // 89 (random attachment) Fake::attachment_id( 'image' ); // Random image attachment Fake::term_id(); // 12 (random category) Fake::term_id( 'post_tag' ); // Random tag
All WordPress methods return null if no matching items exist.
Utilities
// Weighted random selection Fake::weighted( [ 'active' => 60, 'pending' => 20, 'inactive' => 20, ] ); // "active" (60% of the time) // Generate multiple items Fake::many( fn() => Fake::name(), 10 ); // Array of 10 names // Random number Fake::number( 1, 100 ); // Random integer // Random boolean Fake::boolean(); // true/false (50/50) Fake::boolean( 80 ); // true 80% of the time // Pick from any array Fake::random_element( [ 'a', 'b', 'c' ] ); // Random element
Seeding Example
use ArrayPress\Faker\Fake; // Seed 100 customers for ( $i = 0; $i < 100; $i++ ) { $first = Fake::first_name(); $last = Fake::last_name(); $query->add_item( [ 'name' => $first . ' ' . $last, 'email' => Fake::email( $first, $last ), 'phone' => Fake::phone(), 'company' => Fake::company(), 'country' => Fake::country(), 'status' => Fake::weighted( [ 'active' => 60, 'pending' => 20, 'inactive' => 20 ] ), 'total_spent' => Fake::price( 5000, 500000 ), 'order_count' => Fake::number( 1, 50 ), 'notes' => Fake::boolean( 70 ) ? Fake::sentence() : '', 'date_created' => Fake::past_date(), ] ); }
Requirements
- PHP 7.4 or later
- WordPress 6.2 or later (only for the WordPress methods)
License
GPL-2.0-or-later