jplhomer / fresa
Developing WordPress should be sweet.
v1.2.0
2020-04-18 16:41 UTC
Requires
- illuminate/support: ^5.4
- nesbot/carbon: ^2.32
Requires (Dev)
- phpunit/phpunit: ^7
README
🍓 Developing WordPress should be sweet.
Use Fresa in your plugins and themes to make interacting with the WordPress ecosystem friendly and fast.
Tested on WordPress 4.8 and requires PHP 7+. Your mileage may vary.
use Fresa\PostModel; class Event extends PostModel { $postType = 'my_custom_post_type'; }
Register your custom post types in one line:
Event::register();
Interact with your post in an object-oriented fashion:
$event = new Event; $event->title = 'Hello World.'; $event->venue = 'Times Square'; $event->save(); echo $event->id; // 1 echo $event->venue; // 'Times Square'; // Same as get_post_meta(1, 'venue', true);
And perform queries through a fluent interface:
$event = Event::find(1); $events = Event::where('venue', 'Times Square') ->order('date', 'asc') ->limit(5) ->offset(5) ->get();
Queries return a Collection instance:
$events->each(function($event) { echo $event->title; });
Installation
composer require jplhomer/fresa
Read the full documentation here.
Development
composer install
Running Tests
First, set up the required WordPress testing library on your machine:
# Replace db-name, db-user, db-pass with arguments of a database to be created # If you already have a database, pass `true` to the last argument, e.g. # wptests root '' 127.0.0.1 latest true ./bin/install-wp-tests.sh <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]
Run tests using PHPUnit:
vendor/bin/phpunit