Fresa is a better way to develop WordPress

I built and released Fresa – a library for making WordPress development enjoyable.

Check out the screencast above for a quick demo!

Why Fresa?

I’ve been spending a lot of time in Rails and Laravel. Both frameworks provide an abstraction to the database layer through a concept called models.

In Rails, you can define instances of ActiveRecord:

And in Laravel, you can define instances of Eloquent\Model:

I’m originally a WordPress developer. But when I come back to WordPress now, I’m reminded of how much work it takes to do simple things, like:

  • Remember what method to use: get_the_permalink or get_permalink? get_the_post_thumbnail or get_thumbnail?
  • Create and retrieve posts with different methods: wp_insert_post() and get_posts()
  • Set post meta on an object which should be a first-class data citizen. I’m required to use update_post_meta($event_id, 'foo', 'bar') and get_post_meta($event_id, 'foo', true)

WordPress is a complex and mature piece of software – and it’s no surprise that its API patterns have drifted over a literal decade. I’m often reminded of the website PHP Sadness, which highlights some of the consistencies in PHP’s core methods. I feel the same way sometimes about WordPress.

After watching Things Laravel Made Me Believe by Jeffrey Way at Laracon EU 2015, I was inspired to plant my feet and create a better way to develop WordPress.

So I did. And that’s the motivation behind Fresa!

Object-Oriented Goodness

It all starts with the Model class:

After defining your first model, you have a ton of power at your fingertips. A custom post type registration, which normally requires nearly 60 lines of code, can be done in just a couple lines!

In WordPress, creating instances of custom post types with related metadata can be tedious, requiring several functions and different parameters.

With Fresa, you can rely on an expressive, object-oriented pattern to create objects:

The same goes for fetching objects! Here’s a comparison of fetching single models in addition to querying for models using Fresa:

Fresa does a ton of other cool things, too. Check out the Fresa documentation to learn more.

I hope Fresa is useful to you. I’ve already included it in a production application, and I’m excited to find other ways to use it.

  • Farisah Chan

    Many thanks..😄, I just got started learning WordPress, I believe this will be much easier to follow for beginner like me. Though sometimes I felt a bit akward with the way namings/syntaxes etc.. works in WordPress.