Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to approach object-oriented programming with WordPress

How to approach object-oriented programming with WordPress

These are the slides from a talk given at WordCamp Miami 2019.

You're a WordPress developer who wants to use object-oriented programming in their next project. You're already familiar with concepts like inheritance. The issue is that you're not sure how to apply those concepts to design classes that feel useful.

This isn't something to feel ashamed about! In fact, it's a common problem when trying to use object-oriented programming with WordPress. It's hard to know how to design classes that work well with WordPress.

Well, you're in luck! This is what we'll go over during this talk.

We'll start by going over the prevalent class design in the WordPress ecosystem. We'll analyze what it's doing and why it leaves you feeling unsatisfied.

Then we'll look at how object-oriented programming expects you to design classes. We'll finish by looking at strategies that you can use to design classes. This should let you finally design classes that feel meaningful to use!

You can read the companion article at: https://carlalexander.ca/approaching-object-oriented-programming-wordpress

Carl Alexander

March 15, 2019
Tweet

More Decks by Carl Alexander

Other Decks in Technology

Transcript

  1. function get_authors_registered_after($date, $number = 5) { $results = array(); $authors

    = get_users('who=authors'); foreach ($authors as $author) { if ($author->user_registered > $date) { $results[] = $author; } if (count($results) >= $number) { break; } } return $results; }
  2. function get_authors_registered_after($date, $number = 5) { $results = array(); $authors

    = get_users('who=authors'); foreach ($authors as $author) { if ($author->user_registered > $date) { $results[] = $author; } if (count($results) >= $number) { break; } } return $results; }
  3. function get_authors_registered_after($date, $number = 5) { $results = array(); $authors

    = get_users('who=authors'); foreach ($authors as $author) { if ($author->user_registered > $date) { $results[] = $author; } if (count($results) >= $number) { break; } } return $results; }
  4. function get_authors_registered_after($date, $number = 5) { $results = array(); $authors

    = get_users('who=authors'); foreach ($authors as $author) { if ($author->user_registered > $date) { $results[] = $author; } if (count($results) >= $number) { break; } } return $results; }
  5. function get_authors_registered_after($date, $number = 5) { $results = array(); $authors

    = get_users('who=authors'); foreach ($authors as $author) { if ($author->user_registered > $date) { $results[] = $author; } if (count($results) >= $number) { break; } } return $results; }
  6. function get_authors_registered_after($date, $number = 5) { $results = array(); $authors

    = get_users('who=authors'); foreach ($authors as $author) { if ($author->user_registered > $date) { $results[] = $author; } if (count($results) >= $number) { break; } } return $results; }
  7. class Authors { public function get_registered_after($date, $number = 5) {

    $results = array(); $authors = get_users('who=authors'); foreach ($authors->results as $author) { if ($author->user_registered > $date) { $results[] = $author; } if (count($results) >= $number) { break; } } return $results; } }
  8. class Authors { public function get_registered_after($date, $number = 5) {

    $results = array(); $authors = get_users('who=authors'); foreach ($authors->results as $author) { if ($author->user_registered > $date) { $results[] = $author; } if (count($results) >= $number) { break; } } return $results; } }
  9. class Authors { public function get_registered_after($date, $number = 5) {

    $results = array(); $authors = get_users('who=authors'); foreach ($authors->results as $author) { if ($author->user_registered > $date) { $results[] = $author; } if (count($results) >= $number) { break; } } return $results; } }