Welcome to ManageWP.org

Register to share, discuss and vote for the best WordPress stories every day, find new ideas and inspiration for your business and network with other members of the WordPress community. Join the #1 WordPress news community!

×

Development | carlalexander.ca | Apr. 25, 2016

A look at the modern WordPress server stack

Morning full of great dev posts. Carl Alexander covers a full range of options available to the modern WordPress developer.

A look at the modern WordPress server stack

Development | carlalexander.ca | Apr. 25, 2016

I gave a talk at WordCamp San Diego 2016 on the modern WordPress server stack. This is the companion article that I wrote for it. If you’re just looking for the slides, click here. Do you remember when you could run a “fast” WordPress site with just an Apache server and PHP? Yeah, those were days! Things were a lot less complicated back then.
Now, everything has to load lightning fast! Visitors don’t have the same expectations about loading times as they used to. A slow site can have serious implications for you or your client.
As a consequence, the WordPress server stack has had to evolve over the years to keep up with this need for speed. As part of this evolution, it’s had to add a few gears to its engine. Some of the older gears have had to change as well.
The result is that today the WordPress server stack looks quite different from a few years ago. To better understand it, we’re going to explore this new stack in detail. You’ll see how the various pieces fit together to make your WordPress site fast.
Before we dive in, let’s zoom out and look at the big picture. What does this new WordPress server stack look like? Well, look no further!
Click for full size
The diagram above gives

19 min read Ahmad Awais
Development | carlalexander.ca | Jun. 16, 2016

Designing a class to assemble plugin classes

Most of the time when you are programming with OOP in PHP and following the Single responsibility principle for classes you end with a lots of classes. Here is Carl's idea about how to assemble those into main class.

Designing a class to assemble plugin classes

Development | carlalexander.ca | Jun. 16, 2016

Learning object-oriented programming with WordPress is a lot like embarking on an epic journey. You’ll experience some lows, some highs and some downright frustrating moments. But it’s all part of the learning process. And, so far, we’ve done quite a bit of progress on our journey. We’ve looked at various WordPress problems. And we then solved them using a class or combination of classes.
We call this process “object-oriented design“. It’s been the focus of a lot of the articles on this site. Because of that, there’s a good chance that you’ve begun using it in your own projects. (And if you haven’t, you should try it!)
When that happens, you’ll start to notice that your project has a lot of classes. This tends to become a problem for a lot of developers. They wonder, “How do I assemble all these classes together!?” It’s not unusual for them to revert back to the standard WordPress way of doing things when that happens.
This is the problem that we’re going to explore in this article. We’ll look at how you can solve it using a dedicated class for it. To do this, we’ll start thinking about

15 min read Tom Harrigan
Community | carlalexander.ca | Feb. 12, 2015

The anatomy of WordPress: Loading

Looking at how, what and when files are run by WP in the load process. Understanding this is critical to understanding the code you're developing and how it plays with the code of others.

The anatomy of WordPress: Loading

Community | carlalexander.ca | Feb. 12, 2015

I’m sure you woke up thinking “I wish I knew more about WordPress loading.”. Ok… maybe not (it’s just me isn’t it?). It’s just not something you deal with every day. No, plugins and themes make up your days. That’s what you use to build your custom WordPress solutions. There’s no need to know about the internal process that starts up WordPress.
Yet you can’t ignore it once you start building complex WordPress solutions. Or if you plan on distributing a plugin or theme. That changes the dynamic of things.
Your little world with the plugins and themes you know is gone. You’re in the larger (and messier) WordPress world now. That means you have to play nice with everyone else (damn).
That’s why loading is important
A good understanding of the WordPress loading process helps you navigate these troubled waters. It’s where you can make the changes required to make your plugin play nice with others. You can also use it to detect potential issues that might affect how your plugin works.
The loading process is also the starting point to build advanced functionality into WordPress. Your plugin is preparing to change WordPress in a fundamental way. You can make global changes such as:
Registering

13 min read Ahmad Awais
Community | carlalexander.ca | May. 21, 2015

Thoughts on WordPress and the MVC pattern

Each attempt took the MVC pattern and tried to shoehorn it into WordPress. They didn’t take in consideration how WordPress works. It isn’t something that you can neglect or ignore. Does WP API changes this?

Thoughts on WordPress and the MVC pattern

Community | carlalexander.ca | May. 21, 2015

Getting proficient with object-oriented programming can feel like falling down a rabbit hole. You break down problems into more and more classes. You feel like it’s neverending and that you could go on forever. You need guidance to make sense of it all. This is where architectural patterns come in. They’re similar to software design patterns which you use to solve a specific problem. In contrast, you use an architectural pattern to address a set of them at once.
This confers certain benefits to architectural patterns. You get a higher level view of how your classes interact with each other. You then have an easier time piecing everything together.
This is why it’s not uncommon for developers to skip over software design patterns. Instead, they start looking into architectural patterns right away. This is even something I’m guilty of doing (insert audience gasp).
One of the most important architectural patterns is the “model-view-controller” (known as MVC). It’s used by most modern frameworks from Rails to Angular. But does it have a place in WordPress?
So what is the MVC pattern?
The MVC pattern divides your application into three broad components: Models, Views and Controllers. These

27 min read Josh Pollock
Tutorials | carlalexander.ca | Jan. 22, 2016

Design a system: WordPress event management

Managing WordPress hooks properly with OOP programing is tricky. Carl Alexander shows us smart system for managing the plugins API. #carl2016

Design a system: WordPress event management

Tutorials | carlalexander.ca | Jan. 22, 2016

In a previous article, we went over the concept of events and event listeners. These were classes who were in charge of a specific aspect of an application. This was a more abstract job that touched several parts of an application. We also saw how you could design these event listeners in WordPress. It required that you rethink how you use the plugin API. (Yes, this is going to be another plugin API article :P)
We’re going to keep going with this idea of events and event listeners. We’re going to design a system for them. We’ll call it an “event management” system. It’s an important tool in your journey to master object-oriented programming in WordPress.
Before we begin, let’s do a small recap on the plugin API language. When we talk about the plugin API, we often talk about action hooks and filter hooks. Actions are is a type of signal that the plugin API emits. Anyone can listen for those signals and react to them.
Filters are a bit different. They’re also a type of signal that the plugin API emits. But that signal also contains data that you can change and send back.
Now while those two types of signals do different things, they’re the same under the hood. They use the same system

8 min read Ahmad Awais
Community | carlalexander.ca | Jun. 30, 2015

DebOps for WordPress Give your WordPress client an Apple experience

You don’t have to find any more excuses. You can give yourself and your client a fast and secure server with: Nginx MariaDB (MySQL replacement) HHVM PHP-FPM (automatic fallback) Redis WP-CLI Varnish (optimized for WordPress)

DebOps for WordPress Give your WordPress client an Apple experience

Community | carlalexander.ca | Jun. 30, 2015

Hosting your WordPress site is an annoying problem. You can’t go far to see a discussion about it. Every week, someone asks who’s the best host. And each week, you never know if you’ll see conflicting answers or a consensus. It’s not like you can live without hosting either. That puts you at the mercy of hosting providers. This isn’t to say that hosting providers are evil. I think a lot of them are good and mean well.
It’s just that, regardless of their intentions, it doesn’t change things for you. Hosting is a critical part of your client’s experience with your service. They’ll call you if their site is slow, down or even hacked. They’ll question the quality of your work because of it.
But it’s more often than not a result of their decision. Clients skimp on hosting all the time. It’s one of the aspects of a project that your client tends to neglect the most. You know this. You’ve lived it many times.
Your client thinks: “Why should I pay $50/month (or $100/month with SSL!!) for premium hosting? I can get something for half or a quarter of the price.” Of course, it sounds great to them.
Except you’re left holding the bag when things go wrong.
You need your Apple experience
Apple likes

Plugins | carlalexander.ca | Mar. 13, 2015

Read more code

Level up your game by getting deep into the subject. Want to be a pro-WordPress developer? Start reading WordPress core code.

Read more code

Plugins | carlalexander.ca | Mar. 13, 2015

As developers, programmers, software builders, solution creators, we tend to focus on the output of our work. It’s the code we write. It’s also the outcomes that we create for ourselves, our clients and/or our work. How do we get better at it though? That’s what we care about in the end. The obvious answer is to write more code (duh!). What I’ve learned goes against that common logic.
Here’s what you need to do. You need to read more code. Yup, you heard that right. This is what’ll give you the largest skill gains. That’s the secret sauce.
I can hear your disbelief all the way through the internet! Of course, writing code is necessary. After all, you have to practice what you learn… from reading code.
What are you doing when you’re writing code?
You’re solving a problem. Writing code is just a process that you use to do it. So let’s say you hit a problem you’ve never seen before. What’s your first instinct? You google it, right?
You don’t sit down and write code out of nowhere. That’s because you know there’s a solution out there. You can just use it and move on. It’s just human behaviour.
Why is reading code more useful?
To understand that, we have to take a look at how we (humans)

16 min read Ahmad Awais
Tutorials | carlalexander.ca | Apr. 7, 2015

WordPress for the Adventurous: Rewrite API

Carl explains how Rewrite API serves as a translator between the disney story of WordPress and You.

WordPress for the Adventurous: Rewrite API

Tutorials | carlalexander.ca | Apr. 7, 2015

The story behind rewrite API plays out almost like a Disney movie. You have WordPress and the human (played by you!). Two different worlds. Two different languages. WordPress is a machine and only understands if you talk to it as such. You need to use a cold language of numbers and code so that it can understand you. Do you need to see a WordPress post? You need to ask him using query variables like p=123.
On the other hand, humans are friendly and talkative. They expect to talk to someone using words. They want to see URLs with the post-title and not query variables.
The rewrite API is the translator that brought these two unlikely friends together. Rewrite rules convert your post-title into the p=123 query variable WordPress wants. Both sides get their happy ending (yay!).
How does the rewrite API do this?
At its core, the rewrite API is about rewrite rules. WordPress uses rewrite rules to convert your human-friendly URLs into ones it can use. There’re two components to a rule: a regular expression and a redirect URL.
The regular expression is what makes the rewrite API so complicated (and also intimidating). WordPress attempts to match any URL it receives to a regular expression.

19 min read Matt Cromwell
Tutorials | carlalexander.ca | Oct. 5, 2015

Introduction to WordPress unit testing

Unit Testing is a must for any professional and robust WordPress plugin. Carl walks you through the basics of the How's and Why's of Unit Testing. Great resource for plugin authors.

Introduction to WordPress unit testing

Tutorials | carlalexander.ca | Oct. 5, 2015

I gave a talk at WordCamp Toronto 2015 on WordPress unit testing. This is the companion article that I wrote for it. If you’re just looking for the slides, click here. “But this worked the other day!”
I don’t know about you, but reading that sentence just frustrates me! Don’t you hate when things worked one day and it doesn’t the next. It’s the stuff of (developer) nightmares.
What if there was a way to ward yourself against that evil? Well, you’re in luck because that’s the goal of software testing! It prevents this situation from happening over and over again. On top of that, it helps you improve the quality of the code you write. Awesome!
Now, software testing is a HUGE field. You have a ton of different types of testing. Each with its own purpose (and, sometimes, philosophy). Today, we’re going to focus on just one type of testing. It’s called unit testing.
Well, in the full spectrum of testing, unit testing focuses on testing at the smallest scale. In most cases, that means inputting values into a function (or object method). You then check at what comes out at the other end.
“Checking what comes out at the other end” tends to boil down to two things. You can verify that the function

27 min read Ahmad Awais
Editorials | carlalexander.ca | Sep. 11, 2015

Designing a system: WordPress routing

An object-oriented approach to building a routing system for WordPress by Carl Alexander. Great write up!

Designing a system: WordPress routing

Editorials | carlalexander.ca | Sep. 11, 2015

Developers use WordPress to build all sorts of solutions. They can range from a small website to large application platforms. The larger the project gets, the more common it is to have the need for WordPress to handle custom URLs. You might want to map a custom URL to a new template, a specific hook or both. These situations get more and more common as you work on larger WordPress projects. This type of problem is a bit of a growing up pain with WordPress.
In framework land, there’s a tool that helps you with that problem. It’s called the routing system. It’s a critical component of most frameworks. It lets you map URLs with different parts of your application.
It’s a tough problem to solve, but a good example of object-oriented design. That’s why we’re going to build one. It’ll show you how object-oriented programming helps you solve harder problems.
But isn’t this the job of the rewrite API?
Not quite. (But excellent question!) The rewrite API allows WordPress to understand human-readable URLs. There’s no question that it’s an important task.
That said, a routing system is a large enough problem that it’s made up of smaller sub-problems. Solving these sub-problems is necessary for

11 min read Ahmad Awais
Plugins | carlalexander.ca | Jan. 27, 2015

Helping WordPress make friends with the decorator pattern

This article showed you how to use of the decorator pattern using object-oriented design. Written by Carl Alexander who is also writing a book about OOP & WP. This upcoming book will help you learn all the fundamental of object-oriented programming.

Helping WordPress make friends with the decorator pattern

Plugins | carlalexander.ca | Jan. 27, 2015

In some plugin circles (also know as the “cool kids club”), the coolest kid on the block is the “wpdb” class. Plugins go out of their way to be his friend. Lucky guy (or class)! One plugin that has to be friends with wpdb is HyperDB. If plugins could talk, it would sound a lot like a scene from kindergarden.
HyperDB: Hey WPDB, wanna be friends? I’ll make you the strongest database class there is!
WPDB: Woah, that sounds awesome. I’m in!
HyperDB: There’s only one catch. You can’t be friends with anyone else.
WPDB: Oh ok. *sad face*
HyperDB uses the proxy pattern to give wpdb his new powers. The “HyperDB” class achieves that by extending the “wpdb” class. This is also a limitation of the proxy pattern.
A class can only extend one class. This means that it can only have one proxy (in practice). Creating a proxy prevents others from creating one. This leaves other plugins like Query Monitor in the wind.
Query Monitor: Hey WPDB, how would you like to know when you’re sick?
WPDB: I’d love to! I hate being sick.
Query Monitor: Great! All you need to do is become my friend and I’ll help you with that.
WPDB: Sorry Query Monitor, I’m already friends with HyperDB…
This situation is unfortunate

32 min read Josh Pollock
Community | carlalexander.ca | Dec. 29, 2015

2015 in review: Teaching everything I know

Carl Alexander shares his year in review -- a great read on the dedication to sharing that powers one of my favorite writers about WordPress.

2015 in review: Teaching everything I know

Community | carlalexander.ca | Dec. 29, 2015

I feel I should have done this a few years ago. I know that it’s pretty common for writers to do these “year in review”. At this point, I think it’s good for me to be open and transparent about what I do. I always admired Buffer and their values so it’s my way to emulate them a bit. That said, it’s also useful that I have something written down. Our memory has a tendency to alter facts when we just tell the story over and over. This creates a historical record that I can refer to. (Why yes, I am a history geek! What makes you think that?)
In order for this review to make sense, I’m going to have to give you a bit of a background on my current situation. I don’t want it to appear to you that I got to where I am overnight. There’s a story and that story will give you some context about where I am today. It’ll also help you understand how I’m reviewing my year.
With that out of the way, let’s begin!
The story so far…
I quit my job in April 2012 to “start my own software business”. That’s a bit more than three and a half years ago. It’s a bit crazy to think that. It feels like it was longer ago (I have a weird perception of time).
The main reason why I did that is because I get bored with

9 min read Matt Cromwell
Tutorials | carlalexander.ca | Oct. 10, 2014

Designing a class: WordPress AJAX handler

Carl Alexander walks you through exactly how to handle AJAX in WordPress while also showing you how to construct your own class to extend.

Designing a class: WordPress AJAX handler

Tutorials | carlalexander.ca | Oct. 10, 2014

Learning object-oriented programming has its fair share of challenges. One of them is the large variety of problems and their solutions. That’s why a lot of solutions revolve around using design patterns. Sometimes a problem has a clear solution like the WordPress API client. Other times it’s more abstract like how to interact with the plugin API. These abstract problems are a lot harder to define and solve.
That’s why I want to share how I’d design a class to solve one of those abstract problems. I decided to look at AJAX communication. You can use AJAX to do anything. This means that we can only create a generic outline of what an AJAX handler class would look like.
Before we go any further, let’s go over the idea behind AJAX. AJAX is a way for a rendered web page to communicate with a server without needing to refresh.
The web page sends a request to a server using JavaScript. That request could also contain data for the server to use. The server can then send a response back with information for the web page to use. This can go back and forth indefinitely. The end result is a more dynamic web experience.
For more details, you should take a look at the codex. It does a good job at

Development | carlalexander.ca | Jul. 7, 2016

Thoughts on teaching object-oriented programming with WordPress and overengineering

I may or not agree with some of Carl's points but I am thankful for the 'strong opinions, weakly held' reference.

Thoughts on teaching object-oriented programming with WordPress and overengineering

Development | carlalexander.ca | Jul. 7, 2016

This site has grown a lot in the last year or so. We’ve spent a lot of time going over object-oriented solutions to WordPress problems. So much so that, we have a small library’s worth of material that you can refer to. With any type of growth, criticism will arise. This is a good thing. I’m a big proponent of “Strong opinions, weakly held“. But this can’t happen without discussion and debate. In the long run, I always feel it leads to a better outcome. (Well, that’s as long you don’t get stuck just debating!)
Recently, there was a debate on the nature of the solutions that you’ll see on this site. They’re overengineered. I think this is a valid criticism and I wanted to share some of my thoughts on the whole thing.
We can’t talk about overengineering without first discussing my current teaching thesis. The thesis attempts to answer these two questions:
Why is it hard to teach object-oriented programming to WordPress developers?
Why have so many tried and failed (in my opinion) at it?
This could have been a post by itself. That said, I don’t think it makes sense to explain why we’re using overengineering without

Tutorials | carlalexander.ca | Nov. 30, 2015

Designing Classes that use the WordPress Plugin API

Carl Alexander delivers again walking developers through the best way to build a class for the WordPress Plugin API.

12 min read Matt Cromwell
Tutorials | carlalexander.ca | Sep. 21, 2014

The mediator pattern in WordPress

Carl Alexander talks details of doing OOP in WordPress, specifically in combination with working with the WordPress Plugin API to avoid coupling and streamline your code. Excellent and highly detailed piece.

The mediator pattern in WordPress

Tutorials | carlalexander.ca | Sep. 21, 2014

Let’s talk about the plugin API. You can’t write a plugin without using it. Well that’s not quite true. You could, but you’d have a hard (and unpleasant) time without it though. That’s because it’s the cornerstone of your interaction with WordPress. This means that you can’t build an object-oriented plugin without taking it in consideration. That’s also when the headaches starts. You try to find a solution to the problem. You often go back to the usual solutions such as:
None of the these are great solutions to the problem (especially that last one). That’s because you’ve been focused on your problems. You want that sweet plugin you’re coding to be object-oriented (who doesn’t?).
Meanwhile, you didn’t stop and think about the plugin API. What does it want?
What does the Plugin API want?
You see the plugin API didn’t just appear there. Someone decided that WordPress needed a way for you to alter its behaviour without “hacking core”. This wasn’t a new requirement either. The ability to add filters was around when Matt forked the b2 project in 2003.
That’s because the ability to extend a platform is what gives it strength. You get a community of developers to build for it. This creates

20 min read Matt Cromwell
Tutorials | carlalexander.ca | Nov. 10, 2015

Designing a class to manage WordPress posts

Creating a class to manage how you query posts makes your work more efficient and flexible. Great tutorial for advanced usage for developers of any skill level.

Designing a class to manage WordPress posts

Tutorials | carlalexander.ca | Nov. 10, 2015

When building a plugin, it’s not uncommon to need to fetch posts from the database. After all, you might be using your own custom post type. Or maybe, you built a special functionality on top of posts and you want to find them that way. Those are just a few reasons why your plugin might need to query WordPress for posts. Regardless of the reason, the standard way of doing that is to use the WP_Query class. This lets us create WordPress queries in a safe way outside the loop. The problem is that they’re not easy to reuse.
For example, let’s say that you want a query to fetch only one result. You’re always going to need to the query variables 'posts_per_page' => 1 and 'no_found_rows' => true. That last one removes the SQL_CALC_FOUND_ROWS query used by WordPress pagination. (You don’t need to paginate one result!) This lets us improve performance a bit by removing the unnecessary query.
Now, you’d need to copy these two query variables whenever you create a query to fetch a single result. This is far from ideal. So let’s look at designing a solution to this problem. Using object-oriented programming, of course!
The job
But first, let’s take a step back for a moment and think about the

23 min read Eusebiu Oprinoiu
Development | carlalexander.ca | Apr. 5, 2016

WordPress for the adventurous: WP_Query class

A great tutorial from Carl Alexander explaining the WP_Query class in depth that will help you understand how the posts data should be accessed.

WordPress for the adventurous: WP_Query class

Development | carlalexander.ca | Apr. 5, 2016

It’s not too far-fetched to see WordPress as a library. You write a post and publish it. Meanwhile, WordPress classifies it and puts it away on its shelves. But how do you find your post again after WordPress shelved it away? You need someone to help you navigate this huge library and find what you’re looking for. You need a librarian!
That’s the job of the WP_Query class in a nutshell. It’s the librarian of the WordPress database. You talk to it when you want to search through the WordPress database. It’ll help you find the information that you need!
It does this without requiring that you know how WordPress stores that information. That means that you don’t have to know how to write MySQL queries. WP_Query takes care of all that for you. (Yay!) It’ll transform your search request into a safe MySQL query and process it for you.
But how does the WP_Query class do this? That’s what we’re going to look at today. We’re going to explore how it works and what it can do for you. This will help you leverage it to the maximum in the future.
MySQL queries are a bit of tricky beast. On one hand, they let you do pretty much anything that you want. That said, in the hands of an inexperienced developer,

20 min read Matt Cromwell
Pro | carlalexander.ca | Aug. 3, 2016

Designing a class to build simple WordPress queries

Carl Alexander walks you through designing a basic Class for WordPress queries. Useful for theme and plugin authors alike, this really helps level up your knowledge not only of WordPress but best practice coding standards as well.

Designing a class to build simple WordPress queries

Pro | carlalexander.ca | Aug. 3, 2016

In a previous article, we looked at how you could create a class to manage WordPress posts. We ended creating a class who’s job it was to interact with the WordPress database. And it did that quite well! As part of its job, our class also had to be able to query the WordPress database. To do that, we made it easier to reuse code around the WP_Query class. We achieved that by creating methods that used predefined query arguments.
But have you ever looked at the codex page for WP_Query? Holy Moley, there are a lot of query parameters in there! It’s pretty intimidating and not always easy to use in practice.
That’s the problem that we’re going to look at in this article. We’ll design a class to simplify how we build WP_Query objects. It’ll handle all the complexity around WP_Query query parameters for you. The result should be an easier way for you for you to create WordPress queries.
Before we proceed any further, we should take a moment to answer this question. Now, we know that the job of the WP_Query class is to do just that. It lets you query the database without the need for you to know any SQL. You just need to fill an array with query arguments

8 min read Ahmad Awais
Community | carlalexander.ca | Feb. 3, 2015

On becoming a WordPress expert

An expert delivers extraordinary outcomes with WordPress That’s the conclusion I came to after going through the thought experiment. You’re not trying to help someone build a site on a budget here. You’re paid a lot because you deliver expert level outcomes.

On becoming a WordPress expert

Community | carlalexander.ca | Feb. 3, 2015

This all started with a thought experiment about WordPress recruiting. Something I’ve done a fair amount of in the past. Let’s say I’m looking to hire a WordPress expert. What defines that person as a top tier WordPress developer? What knowledge or characteristics am I looking for?
WordPress powers a large part of the web. It’s also the livelihood for thousands of developers. Those are amazing things, but it also creates problems. One of them is that it’s hard to evaluate your or someone else’s skill level.
So we’re going to look into that. It’s worth noting that there’s no definitive or objective answer to that question. We’re all biased. We have our own opinions on what it means to be an expert.
That doesn’t mean that you shouldn’t try to answer the question. The goal here is to help you think about where you stand on the topic. It’s also an opportunity to think about where you are and where you’d like to be.
Let’s focus on things you can learn
It’s not that soft skills like a “strong desire to learn” or “problem-solving attitude” aren’t important. They’re mandatory for achieving any mastery (not just WordPress) and employers love them too. They’re just not something you can teach

20 min read Eusebiu Oprinoiu
Pro | carlalexander.ca | Nov. 11, 2016

Mastering the Use of PHP Conditionals

PHP conditionals are so common and easy to use that most of us ignore how easy it is to develop bad habits around them. Luckily, we have Carl Alexander to remind us that "easy to learn" is not always equal to "easy to master".

Mastering the Use of PHP Conditionals

Pro | carlalexander.ca | Nov. 11, 2016

No set of control structures is more pervasive in programming than if, elseif and else. With a few exceptions, you’ll use at least one per function or method that you write. There’s just no way around it. But conditionals (that’s what we call these control structures) fit in the “easy to learn, hard to master” category. In fact, they’re so easy to use that you can develop some bad habits around them. (This is also a problem with loops.) This can lead to code that’s complex and hard to read or even test.
That said, it’s possible to develop good programming habits with conditionals. This is what this article will try to help you with. We’ll go over some programming techniques that can help make conditionals more manageable.
First, let’s take a look at how PHP evaluates conditionals. This is so often misunderstood when using conditionals. But knowing how PHP evaluates them lets you remove and/or combine conditionals. This, in turn, makes your code simpler.
Evaluation order of a conditional
The first thing that you should always keep in mind is the order that conditionals get evaluated. Most programming languages evaluate conditionals

Tutorials | carlalexander.ca | Jun. 23, 2014

Polymorphism and WordPress: Interfaces

Introducing Carl to the community, we need more of dev gems like this one!

Polymorphism and WordPress: Interfaces

Tutorials | carlalexander.ca | Jun. 23, 2014

Let’s talk about interfaces. As a WordPress developer, how can they be useful to you and your projects? It’s going to be a tough sell because WordPress core doesn’t use them and we’ll see why this is an issue a bit later. That said, you’ll still find this article useful if you’re looking to: Learn more about PHP and not just WordPress
Build strong and extensible PHP code
Reduce bugs in your open source plugins
Use open source PHP frameworks
Like the article on abstract classes, you’ll get a detailed example to explain how interfaces work and how you can use them. You’ll also get a good idea of the design decisions that warrant the use of an interface.
When I discussed inheritance, I described interfaces as a contract. If a class chooses to implement an interface, it agrees to follow its contract. The scope of the contract is quite limited. It can only define:
Public methods
Constants
Below is a small example of an interface and a class implementing it.
/** * Interface for implementing the conversion to an array. */ interface ArrayableInterface { /** * Converts the object to an array. * * @return array */ public function to_array(); } class WP_User implements ArrayableInterface { //

23 min read Ahmad Awais
Development | carlalexander.ca | Aug. 13, 2015

WordPress for the adventurous: Plugin API

An interesting article about how important WordPress Plugin API is, and how it works. Let's discuss Actions and Filters!

WordPress for the adventurous: Plugin API

Development | carlalexander.ca | Aug. 13, 2015

Let’s say that you ran a poll through the WordPress developer community. It asked the following question: “What defines WordPress?”. The odds are that the plugin API would come up near the top. From a developer’s perspective (and for the sake of my introduction), there’s nothing that defines WordPress like it. It’s the workhorse of the WordPress ecosystem. You use to build anything that you want with WordPress.
There are plenty of articles out there that show you how to use it, but little on how it works. That makes it a bit misunderstood and lonely (APIs have feelings you know).
It’s time we showed some love for this hard worker.
Actions vs Filters
The first thing to look at is the concept of Actions and Filters. It’s an important aspect of the plugin API. Actions and Filters serve two different purpose for WordPress. That said, they leverage the same system within it.
Their purpose
Let’s start with the purpose of the “action hook”. When WordPress calls an “action hook”, the plugin API notifies anyone interested in it. Those interested parties can then decide if they’d like do something or not.
That something always relates to how WordPress works. Someone might want to add new functionality

Tutorials | carlalexander.ca | Nov. 13, 2014

Spying on WordPress with the proxy pattern

Carl explains a useful OOP technique that allows you to alter a delegate class in significant ways.

Spying on WordPress with the proxy pattern

Tutorials | carlalexander.ca | Nov. 13, 2014

In a not so distant future, you’ve grown to be quite the WordPress expert. You work for WSIS (WordPress Security Intelligence Service) as an analyst. You’re given your first field mission. You have to get in deep with WordPress. You need to get intimate information about a WordPress object. Information even WordPress doesn’t want to give you. You need to gain access without detection. The last thing you need is WordPress to know you’re listening on things.
How would your future self do it? Well he’d use the proxy pattern (good thing you’re reading this article). The proxy pattern is the equivalent of object-oriented tapping. It’s one way to solve the problem of interacting with a class without it being aware of it.
Let’s look at how it works.
Object-oriented tapping with the proxy pattern
The proxy pattern is about the relationship between two classes. Those two classes are the proxy and the delegate.
The delegate is the class the proxy wants to interact with silently. What the delegate does isn’t important (sorry delegate class). The proxy class is where all the action happens.
The goal of the proxy class is flexible. What defines a proxy class is the idea exerting control on the delegate