wp-starter/support
Lightweight support utilities for WP Starter projects. Includes helpful helpers, common abstractions, and shared tooling to speed up WordPress development and keep starter-based apps consistent, clean, and easier to maintain.
Installation
composer require wp-starter/support
Verify compatibility with Laravel’s PHP version (7.3+ or 8.0+) and dependencies like wp-starter/collections and nesbot/carbon.
First Use Case: Collections Macros The package likely extends Laravel’s collections with custom macros. Test this by adding a macro:
use Illuminate\Support\Collection;
use WpStarter\Support\Support;
Collection::macro('toSnake', function () {
return $this->map(fn ($item) => Support::snake($item));
});
// Usage:
$snakeCollection = collect(['HelloWorld', 'FooBar'])->toSnake();
Where to Look First
src/Support.php or src/CollectionMacros.php for core functionality.tests/ for usage examples (though minimal due to package age).SupportServiceProvider.php to understand registration.Initial Integration
config/app.php:
'providers' => [
WpStarter\Support\SupportServiceProvider::class,
],
use WpStarter\Support\Facades\Support;
// Example: Format a date with Carbon
$formattedDate = Support::now()->format('Y-m-d');
// Define a macro for ticket categorization
Collection::macro('categorizeTickets', function () {
return $this->groupBy(fn ($ticket) => $ticket['priority']);
});
// Usage in a controller
$tickets = Ticket::all()->categorizeTickets();
use WpStarter\Support\Facades\Support;
$dueDate = Support::now()->addDays(3); // SLA deadline
$isOverdue = $dueDate->isPast();
Ticket):
class Ticket extends Model {
public function isOverdue() {
return $this->due_date->isPast();
}
}
// Convert to human-readable (e.g., "1 ticket" -> "1 Ticket")
$label = Support::humanize(1, 'ticket');
// Snake case conversion
$snake = Support::snake('HelloWorld');
wp-starter/contracts to define interfaces for support services (e.g., TicketRepository).
namespace WpStarter\Support\Contracts;
interface TicketRepository {
public function findByPriority(string $priority);
}
class EloquentTicketRepository implements TicketRepository {
public function findByPriority(string $priority) {
return Ticket::where('priority', $priority)->get();
}
}
Collection::macro('filterByStatus', function ($status) {
return $this->where('status', $status);
});
$openTickets = Ticket::all()->filterByStatus('open');
$overdue = $openTickets->filter(fn ($ticket) => $ticket->due_date->isPast());
$ticketCount = Support::humanize($count, 'ticket');
$translated = Support::translate('support.label.ticket');
$reminder = Support::now()->addHours(1);
$schedule->command('send-overdue-alerts')->hourlyAt($reminder->format('H:i'));
WordPress Legacy Code
WP_ classes, hooks).WP_User_Query → User::query()).Undocumented Macros
CollectionMacros class or tests to infer functionality. Add PHPDoc comments:
/**
* @param Collection $collection
* @return Collection
*/
Collection::macro('toSnake', function ($collection) { ... });
Carbon Version Conflicts
composer.json:
"nesbot/carbon": "^2.55"
No Laravel Service Provider
AppServiceProvider:
public function register() {
if (! app()->bound('support')) {
$this->app->bind('support', function () {
return new \WpStarter\Support\Support();
});
}
}
Lack of Testing
public function testTicketCategorization() {
$tickets = collect([['priority' => 'high'], ['priority' => 'low']]);
$categorized = $tickets->categorizeTickets();
$this->assertArrayHasKey('high', $categorized);
}
Enable Debugging for Macros
Add this to AppServiceProvider to log macro calls:
Collection::macro('debug', function () {
\Log::debug('Collection macro called: ' . debug_backtrace()[1]['function']);
return $this;
});
Check for WordPress Dependencies Run a grep to find non-Laravel classes:
grep -r "WP_" vendor/wp-starter/support
Override Problematic Methods If a method conflicts with Laravel’s, override it in a trait:
namespace App\Support;
use WpStarter\Support\Support as BaseSupport;
class Support extends BaseSupport {
public static function snake($string) {
return Str::snake($string); // Use Laravel's Str
}
}
Add Custom Macros Extend collections globally or per-project:
// Global macro
Collection::macro('toTitleCase', function () {
return $this->map(fn ($item) => ucwords(strtolower($item)));
});
// Project-specific macro (in a service provider)
Collection::macro('filterActive', function () {
return $this->where('is_active', true);
});
Integrate with Eloquent Attach macros to model collections:
class Ticket extends Model {
public function scopeOverdue($query) {
return $query->where('due_date', '<', now());
}
}
// Usage:
$overdue = Ticket::overdue()->get();
Localization Support
If the package lacks Laravel’s trans() integration, create a wrapper:
Support::macro('translate', function ($key, $replace = []) {
return trans($key, $replace);
});
Event Integration
Use Laravel events for support workflows (e.g., TicketCreated):
// In a service provider
Event::listen(TicketCreated::class, function ($ticket) {
// Send notification via Carbon-scheduled job
});
How can I help you explore Laravel packages today?