Category: PHP
-
WordPress and Composer TLDR
There’s a few questions I’m commonly asked about using composer + WordPress. Here they are in a super short form FAQ: To install a composer project, run: To update a composer project, run: Install WordPress in a folder or in your composer.json add: Note: This is a subdirectory install, you really don’t want to nest composer packages.…
-
Calling Constructors
Take a look at this code, found inside the Jetpack Post Views plugin: Here an object is calling its own constructor. But what’s wrong with it? The General rule for calling __construct: The only occasion it is okay to call a constructor method directly, is in a child class that needs to call its parent…
-
&$this
Take a look at this code, found inside a PHP class or object: This looks familiar, and can be found in many themes and plugins. But what’s wrong with it? It’s PHP4 code in a PHP5 world. General PHP rule for add_action: When creating a callable, never use &$this, use $this instead There is almost never…
-
ComposerPress
Curious about Composer but already have a WordPress site? Not to worry, I have you covered. Presenting Composerpress: Composerpress is a plugin that analyses your WordPress install, and generates a composer.json file you can then use retro-actively. This file acts as an inventory of dependencies, plugins, etc that are needed to set up a site, and…
-
WP_Query::get_posts()
Every call to retrieve posts goes through WP_Query, and the bulk of the logic is in the method get_posts. Here’s some potentially useful information about the current state of what is arguably the most important function in WordPress. WP_Query::get_posts is 890 lines long, and has a cyclomatic complexity of 256. A good cyclomatic complexity is ~2-6,…
-
WordCamp Lancaster 2013
I’m at WordCamp Lancaster, and I’ve given two talks. Here are my slides, and a selection of photos taken! A big shout out to: Code Deodorant How to determine code quality by scientific means and automation to help. Outside The Bubble What happened outside the WordPress ecosystem with PHP at large A video recording may…