Posted inPHP

Create a simple PSR-4 compliant autoloader for any plugin

A lot of PHP developers involved with WordPress projects, especially those developing plugins, opt for using Composer. Not only for requiring libraries they can use, but also for autoloading classes and even files inside the plugin. However, some prefer to keep distance from Composer when dealing with WP coding. No problem, if this is your […]

Posted inIntermediate

Using the singleton pattern to deal with constraints

Almost any WordPress or PHP programmer, even in his early days, has some contact with the Singleton design pattern. For obvious reasons, this is maybe the first PHP pattern learnt from those who study for developing using this language. Regardless any discussion on the “antipattern” aspect of the Singleton, the reality is that most applications […]

Posted inOOP

Creating a custom post type helper class

Custom post types are one of the most crucial feature in WordPress. The way a developer can manipulate the platform’s API is fantastic, and complex systems can be created from developing new types, contents and structures. Having that said, the mechanism for adding and altering post types in WordPress hasn’t changed much over the years. […]

Posted inPHP

Using Symfony and WP_Query to return multiple formats

It’s not rocket science using WP_Query to return objects from posts in WordPress. Also, it’s relatively simple encoding or normalizing the responses to use data as associative arrays or JSON. However, there are many reasons why we could prefer our queries to return in different formats: JSON itself, XML, CSV our even Yaml. I personally […]

Posted inACF

Why using CMB2 over ACF?

Dealing with custom fields and meta fields in WordPress is a daily part of the job for any WordPress developer. Although most devs and that includes some of the houses that sell popular plugins still rely on Advanced Custom Fields to manage custom fields, maybe we should move to CMB2 instead. Don’t take me wrong: […]