Lately, I’ve written extensively about object-oriented PHP, from class inheritance and visibility, to design patterns and magic methods. In all of these discussions, I’ve talked about classes without taking into account object interfaces. Interfaces, often referred to as contracts or agreements, set up rules for classes in which a class that implements an interface has to follow those specific rules. Interfaces put constraints on your classes that improve your code. In this article, I’m going to discuss what interfaces are and what they can and can’t do. By the end, you will be able to see if you should use interfaces to improve your code. […]
Spy On Your WordPress Site In Real Time With Papertrail
I’m a big fan of doing my WordPress development live and using Xdebug for tracing WordPress’ execution. But, sometimes you need real-time data of what is going on with certain hooks or functions on your site. I recently discovered the app Papertrail which does just that. Though there are several, similar web apps out there, I chose Papertrail for two reasons: The first is because it has a free option. The second reason is because Scott Kingsley Clark wrote an easy-to-use API client for Papertrail as a WordPress plugin. In this article, I’m going to show you how to use Papertrail to […]
The Difference Between Classes and Objects In PHP
The standards for WordPress development are slowly moving from turns of procedural code that lack proper abstraction to more SOLID and object-oriented code. That’s a step in the right direction, but let’s not forget two important things that often get left out of these discussions: putting code in a class does not make it “object-oriented,” and object-oriented PHP is not, by definition better. Today, we will discuss what what an object is and what its role is. Then we can discuss what we mean by “true object-oriented programming” and whether it really matters if your code is “true OOP” or […]
Building Custom REST API Routes Using Object-Oriented PHP
The two things I write most about for Torque are object-oriented PHP and the WordPress REST API. In this article, I will bring them together to show you how to build out a collection of custom REST API routes while applying the principles of object-oriented PHP. One of the great things about inheritance in object-oriented PHP is that it lets us share code between classes. There are a lot of ways to avoid repeating ourselves in our code. Inheritance is one of them and should only be used when two or more classes have similar purposes. If you have a […]
A Guide To WP_Query
When I started out as a WordPress developer, I was working with object-oriented PHP before I even really knew what it was, thanks to WordPress post API class, WP_Query. In that article, I said that PHP has two data types that are considered “compound,” meaning we can store more than one piece of data in them. In PHP, objects and arrays are the only two data types that are actually considered compound. Objects are similar to arrays in that they provide structure for storing data, however, unlike arrays, objects are created with blueprints called classes, which can contain functions. In […]
PHP Fundamentals For WordPress Developers
Like many WordPress developers, the first time I wrote PHP, I didn’t know anything about PHP or software development in general. As I started to tackle more advanced concepts, however, I struggled because I never learned the fundamentals of PHP that were assumed in the materials I encountered. Regardless of your stage in your process of learning PHP as a WordPress developer it’s important to make sure you know the basics. In this article, I will discuss PHP fundamentals: variables, constants, data types, functions, and scope. This knowledge will equip you to learn PHP and other languages, as most of […]
How To Combine Posts From Multiple WordPress Sites Using The REST API
In my last article for Torque, I showed you how to merge multiple sources into one blog post on a static HTML site using the REST API and JavaScript. This time, I will show you how to accomplish something similar using PHP. The last article was written to work on any type of site. In the example, I used a simple HTML site I created for my business. I then used multiple WordPress sites to source content using WordPress REST API. To combine them, I used JavaScript because that side did not use a server-side language like PHP that could […]
How To Combine Posts From Multiple WordPress Sites Using The REST API
The WordPress REST API gives you the ability to combine content from multiple sites. This is extremely helpful as using more than one CMS to serve content to one site can solve a lot of problems. For example, you could solve scaling problems by dedicating one WordPress install to each post type. Or, if your organization has many sites, you can use the REST API to share content between totally separate sites. Recently I faced the challenge of building a site to bring together all of the different brands in my company. We intended to keep each brand on their […]
Basic PHP Design Patterns For WordPress Developers
Software development is about repeating yourself intelligently by using functions to encapsulate repetitve code, saving you the hassle of writing it out each time. This doesn’t just mean finding a repeatable pattern and going with it, it’s important to find the right pattern. That is where PHP design patterns come into play. While we often think of this in terms of choosing to write a function or class, or to import a library, this approach also extends to application architecture. The architecture of a framework, CMS, plugin, theme, class, or system is often described as conforming to a pattern. Being […]
7 Takeaways From WordCamp San Diego 2016
In April I attended WordCamp San Diego at NTC at Liberty Station. In this article, I’m going to share some of my experiences and takeaways from the event. First, let me thank the good people at WordImpress, makers of the Give plugin, for helping to make my trip possible. I’d also like to thank all of the organizers, speakers, and volunteers who made the event possible. WordPress Fandom Is Strong In his keynote, Chris Lema talked about how the WordPress project held a tenth birthday party for WordPress. Not only that, but people actually showed up to the party, and an […]
No Comments
Start the conversation