Over the last few articles I’ve been looking at the benefits of using class autoloaders and namespaces in PHP. Despite the clear benefits of using these features, WordPress developers tend to shy away from them. One of the big reasons for this is because of WordPress’ continued support of PHP 5.2, which reached its end of life years ago. Class autoloaders have been available in various forms since before PHP 5.3. However, the more up-to-date class autoloader — as is generally used in PHP development — require namespaces, a feature added in PHP 5.3. In this article, I will show […]
Using Namespaces In WordPress Development
Namespacing and class autoloaders are two important tools provided by PHP that WordPress developers should take advantage of more frequently. I wrote about why, and provided a brief introduction to both of these tools in my last article for Torque. This article offers an in-depth introduction to namespaces in PHP. Namespaces are the better, more flexible version of using unique preferences in your class names. In addition they help structure your directories and allow you to take full advantage of autoloaders that follow the latest standards, including Composer’s autoloader. This article assumes that you’re already familiar with the basics of object-oriented PHP. If […]
Why And How To Use Class Autoloading and Namespacing To Improve WordPress Development
Chris Aprea recently wrote a great post on why WordPress’ (continued) support of unsupported versions of PHP, especially PHP 5.2, is preventing WordPress developers from taking full advantage of the way the language has evolved over the last 8 years or so. Two of the best features in PHP, which WordPress developers have generally shied away from since they were not fully supported by PHP 5.2, are SPL autoloaders and namespacing. These two complementary features make it easier to use small, more manageable, and more easily reusable classes. Technically, PHP has had autoloading since 5.0, but the addition of namespacing […]
Improved WordPress Front-End AJAX Processing
The “standard” way of processing AJAX requests in WordPress involves using WordPress’ admin AJAX API — whether you’re actually working in the admin or not. For front-end use of AJAX, especially on high-traffic sites, repurposing the admin AJAX API is not a great option. The 10up Engineering Best Practices provides a good breakdown as to why using admin AJAX for the front-end is not a good idea. It points out that using WordPress’ admin AJAX API causes the WordPress admin to be fully bootstrapped and has no built-in caching. For its intended purpose — running the WordPress backend — this […]
Writing about WordPress: Helping yourself by empowering others
Last year, when I attended WordCamp Orlando, I didn’t know anyone in the community, and nobody knew me. At that time, I made it a goal to become a speaker the following year. This year at WordCamp Orlando, not only was I a speaker, but I also knew a lot of the people in the community, and a lot of people either knew me or have read my articles. More importantly, while I was just getting started last year at this time, now I can say that I’ve been published all over the place: I’ve written plugins, contributed to core, […]
Using the WordPress Customizer for Saving User-Specific Options
The WordPress Customizer — which started out as the theme customizer — is currently one of the best options to allow end-users to customize a theme or plugin. The Customizer is rapidly expanding in its feature set, with the new panels in WordPress 4.0 and the work on a complete JavaScript API for the Customizer giving it a better overall UX and making it more useful. Just as the Customizer doesn’t have to be limited to admin use only, it turns out that it doesn’t have to be limited in the use of setting options either. By default, the Customizer stores in […]
What you need to know about authentication for the JSON REST API
Update: For more information, you can download our free ebook, The Ultimate Guide to the WordPress REST API. The new JSON REST API is one of the more exciting developments in the WordPress world. One of the parts of working with the API that has generated the most confusion is authentication. In this article I will give you a brief introduction to how authentication works with the REST API and the authentication system provided by the REST API team. I will also introduce some additional tools that will make using them even easier. Understanding authentication with the REST API How authentication works […]
Improving WordPress plugin development with Composer
I recently released a plugin comprised almost entirely of code pulled from composer libraries. The plugin’s main file (besides the header and license) just includes the composer autoloader and the plugin’s activation function. That’s it. The rest of the plugin’s functionality comes from four composer libraries: three of which I wrote, and all of which are easily reusable in other plugins or other types of projects. That practical level of code reusability is one of the most exciting parts about integrating Composer into my workflow. In a recent article for Torque, I gave a general introduction to using Composer with WordPress. […]
Building the Front-End for the JSON REST API-Powered Single Page Web App
In my last two articles I have discussed how to prepare your WordPress site to act as the backend for a JSON REST-API powered app using a separate, non-WordPress front-end, and I have illustrated how to use Node.js and Express to power that front-end. This article will show you how to get content in and out of the basic HTML layout, and how to use the HTML5 history API to update URLs. As I emphasized in the last article: using a node.js front-end provides a faster front-end experience, which is easier for non-WordPress developers to work with and provides complete separation of concerns for front-end templating. While my example […]
Setting Up a Node Server for a WordPress REST API-Powered Single Page Web App
Update: For more information, you can download our free ebook, The Ultimate Guide to the WordPress REST API. In my last article in this series, I discussed optimizing and preparing your site to serve as the content management system and REST API for a single page web app (SPA) that does not run inside of WordPress. I have packaged those optimizations into a WordPress plugin, called Josie-API, which you can install from WordPress.org. I have also put the complete code that I’ll be walking you through in this article and the next one in a GitHub project called Josie, so if […]
3 Comments
Join the conversation